-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: css at_value support #18535
feat: css at_value support #18535
Conversation
For maintainers only:
|
Let's add more tests like I written in slack |
6b83bd2
to
1ee76dc
Compare
lib/css/CssParser.js
Outdated
pos = walkCssTokens.eatWhitespaceAndComments(input, pos); | ||
if (pos === input.length) return pos; | ||
let value; | ||
[pos, value] = eatText(input, pos, eatUntil(":{};/")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be only ;
here? Do we really need parse it? Maybe we can parse eveyrything to ;
/from
(future improvement)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if only eat until ;
, then how to solve the situation where user wirtes unexpected cahracter or the user forgets to write ';'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean eat until ";" and collect the string between @value
and ";" and then use a regex to match to key
and value
like postcss-modules-values
, this would be more flexible, but maybe a little inappropriate
1a0053b
to
6507aea
Compare
--color1: v-empty; | ||
--color2: v-empty-1; | ||
--color3: v-empty-2; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more tests here https://github.com/css-modules/postcss-modules-values/blob/master/test/index.test.js, please add all of them
lib/css/CssParser.js
Outdated
@@ -658,6 713,11 @@ class CssParser extends Parser { | |||
modeData = isLocalMode() ? "local" : "global"; | |||
isNextRulePrelude = true; | |||
return end; | |||
} else if (name === "@value") { | |||
const pos = parseModulesValues(input, end); | |||
const dep = new ConstDependency("", [start, pos]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to implement other dep, because @value
can have url - @value blue, red from "./colors.css
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to implement @value
import using :import
, like css loader
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should implement :import
firstly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they will use different dependecies, because @value
-> :import {}
-> dependecy is not good for perf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can separate @value
into value definition
and value imports
, similar to postModulesValues
. This PR currently only implements value definition
, which can be handled using ConstDependency
. value imports
can be managed through a dependency, perhaps called CssIcssImportDependency
, which deals with the :import
functionality.
lib/css/CssParser.js
Outdated
@@ -821,6 881,13 @@ class CssParser extends Parser { | |||
identifier: (input, start, end) => { | |||
switch (scope) { | |||
case CSS_MODE_IN_BLOCK: { | |||
const item = modulesValues.find( | |||
item => input.slice(start, end) === item.key | |||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Map (or WeakMap with Map using parser as a key for weak map and input.slice(start, end)
as a key for Map), it will be very fast and effective
d98332d
to
9cb3e97
Compare
52baef3
to
41ec556
Compare
Done here - #18945 |
#14893 after
icss import
#18568 is supported,@value
import can continueWhat kind of change does this PR introduce?
feature
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
What needs to be documented once your changes are merged?
Nothing