Skip to content

Support @import parsing#27

Merged
nzakas merged 5 commits intohumanwhocodes:mainfrom
jrmajor:import
Sep 1, 2025
Merged

Support @import parsing#27
nzakas merged 5 commits intohumanwhocodes:mainfrom
jrmajor:import

Conversation

@jrmajor
Copy link
Copy Markdown
Contributor

@jrmajor jrmajor commented Aug 1, 2025

Fixes #16, fixes #10 for real this time, replaces #21.

If I understand correctly, #10 wasn't actually fixed by #14, it just introduced a test that confirmed that @import 'tailwindcss' prefix(tw) is parsed as Raw node, which is interpreted by @eslint/css as parse error. It also added that test to TW3 test, which I removed, since this syntax was introduced in v4.

Comment on lines +61 to +63
if (node.type !== 'Raw' || node.value !== '') {
children.push(node);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I noticed this logic in a few places. CSSTree inserts Raw nodes where it can't figure out how to parse the source. I'm not sure we should exclude them here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It also looks strange to me, but that's how it was in https://github.com/eslint/csstree/blob/1d74355c1960315bf55a33b0652d13f97ebb1ba2/lib/syntax/atrule/import.js. I don't understand it that well, so I decided that it's better to leave it as close to the original as possible :)

Comment thread src/atrule/tailwind-import.js Outdated
Comment on lines +157 to +172
if (
this.tokenType === tokenTypes.Function &&
this.cmpStr(this.tokenStart, this.tokenEnd, 'source(')
) {
children.push(this.Function(null, parseFunctions));
matched = true;
} else if (
this.tokenType === tokenTypes.Function &&
this.cmpStr(this.tokenStart, this.tokenEnd, 'prefix(')
) {
children.push(this.Function(null, parseFunctions));
matched = true;
} else if (
this.tokenType === tokenTypes.Function &&
this.cmpStr(this.tokenStart, this.tokenEnd, 'layer(')
) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These are all checking if the tokenType is a function. Can we reduce the number of times we're doing that check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Also replaced matched = false with break to simplify further.

Copy link
Copy Markdown
Contributor

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Apologies for the delay, this looks good to me. Thanks!

@nzakas nzakas merged commit 4276b2e into humanwhocodes:main Sep 1, 2025
13 checks passed
@jrmajor
Copy link
Copy Markdown
Contributor Author

jrmajor commented Sep 1, 2025

Thanks, I appreciate all your work on CSS support in ESLint!

@jrmajor jrmajor deleted the import branch September 1, 2025 21:10
@nzakas
Copy link
Copy Markdown
Contributor

nzakas commented Sep 1, 2025

Don't panic, just have to revert and re-add to generate the release.

nzakas added a commit that referenced this pull request Sep 1, 2025
nzakas added a commit that referenced this pull request Sep 1, 2025
Revert "Support `@import` parsing (#27)"

This reverts commit 4276b2e.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error parsing @import source(none) Bug: Error parsing import with prefix function

2 participants