Skip to content

Commit

Permalink
fix: Persist filename in postcss syntax (#634)
Browse files Browse the repository at this point in the history
* fix: Persist filename in postcss syntax

Persists the correct filename during postcss parsing so that any
resulting error messages will have the correct filename path instead of
an autogenerated `<input cdfsdf/>` -like hash

* Change files
  • Loading branch information
ling1726 authored Jan 2, 2025
1 parent 9282f82 commit 1c399b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Persist filename in postcss syntax",
"packageName": "@griffel/postcss-syntax",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 2 additions & 0 deletions packages/postcss-syntax/src/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const useStyles = makeStyles({
end: { line: 13, column: 3, index: 208 },
});
});

expect(root.source?.input.file?.endsWith('fixture.styles.ts')).toBe(true);
});

it('should handle different module source', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-syntax/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const parse = (css: string | { toString(): string }, opts?: ParserOptions
cssRules.push(cssRule);
});

const root = postcss.parse(cssRules.join('\n'));
const root = postcss.parse(cssRules.join('\n'), { from: filename });
root.walk(node => {
if (!node.source || node.source.start === undefined) {
return;
Expand Down

0 comments on commit 1c399b0

Please sign in to comment.