Skip to content
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

Closed
wants to merge 13 commits into from
Closed

Conversation

faga295
Copy link
Contributor

@faga295 faga295 commented Jun 24, 2024

#14893 after icss import #18568 is supported, @value import can continue

What 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

Copy link

linux-foundation-easycla bot commented Jun 24, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

@faga295 faga295 changed the title feat: css value replace implement feat: css at value support Jun 24, 2024
@faga295 faga295 changed the title feat: css at value support feat: css at_value support Jun 24, 2024
@alexander-akait
Copy link
Member

Let's add more tests like I written in slack

@faga295 faga295 marked this pull request as ready for review July 20, 2024 10:21
pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
if (pos === input.length) return pos;
let value;
[pos, value] = eatText(input, pos, eatUntil(":{};/"));
Copy link
Member

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)?

Copy link
Contributor Author

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 ';'

Copy link
Contributor Author

@faga295 faga295 Jul 25, 2024

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

--color1: v-empty;
--color2: v-empty-1;
--color3: v-empty-2;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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]);
Copy link
Member

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

Copy link
Contributor Author

@faga295 faga295 Aug 15, 2024

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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.

@@ -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
);
Copy link
Member

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

@alexander-akait
Copy link
Member

Done here - #18945

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants