Skip to content

Commit

Permalink
postcss-bundler: fix import parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Nov 28, 2024
1 parent 0633b0a commit eaeacd2
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions plugin-packs/postcss-bundler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to PostCSS Bundler

### Unreleased (patch)

- Fix import parsing so that `@import "foo.css" layer()` is considered invalid syntax and emits warnings.

### 2.0.5

_November 1, 2024_
Expand Down
2 changes: 1 addition & 1 deletion plugin-packs/postcss-bundler/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin-packs/postcss-bundler/dist/index.mjs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export function parseAtImport(params: string): false | { uri: string; fullUri: s
return false;
}

if (!componentValue.value.some((x) => !isWhiteSpaceOrCommentNode(x))) {
return false;
}

layer = stringify([componentValue.value]);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion plugin-packs/postcss-bundler/test/_tape.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const testCases = {
},
'ignore': {
message: 'ignores incorrect syntax',
warnings: 4,
warnings: 5,
},
'layer-before-external': {
message: 'correctly handles layer statements before external resources',
Expand Down
1 change: 1 addition & 0 deletions plugin-packs/postcss-bundler/test/ignore.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
@import supports(foo) "imports/basic.css";
@import url('imports/basic.css' url-mod);
@import url('imports/basic.css' 'imports/basic.css');
@import url('imports/basic.css') layer();
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### Unreleased (patch)

- Fix import parsing so that `@import "foo.css" layer()` is considered invalid syntax and ignored.

### 3.0.4

_November 1, 2024_
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isCommentNode, isFunctionNode, isTokenNode, isWhitespaceNode, parseListOfComponentValues, stringify, sourceIndices } from '@csstools/css-parser-algorithms';
import { isCommentNode, isFunctionNode, isTokenNode, isWhitespaceNode, parseListOfComponentValues, stringify, sourceIndices, isWhiteSpaceOrCommentNode } from '@csstools/css-parser-algorithms';
import { TokenType, tokenize } from '@csstools/css-tokenizer';

const IS_LAYER = /^layer$/i;
Expand Down Expand Up @@ -100,6 +100,10 @@ export function parseAtImport(params) {
return false;
}

if (!componentValue.value.some((x) => !isWhiteSpaceOrCommentNode(x))) {
return false;
}

layer = stringify([componentValue.value]);
layerSourceIndices = sourceIndices(componentValue);
continue;
Expand Down

0 comments on commit eaeacd2

Please sign in to comment.