Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(postcss-syntax): throw error when parsing TS (#553)
* add presets/plugins to transform * Change files * transform source * lint
- Loading branch information
1 parent
2cb5dd0
commit 1767ae3
Showing
4 changed files
with
79 additions
and
23 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@griffel-postcss-syntax-720ba521-03ed-452a-a58e-df0e483e8c6b.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "fix: use plugins/presets from options.babelOptions to transform source.", | ||
"packageName": "@griffel/postcss-syntax", | ||
"email": "yuanboxue@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import transformSync, { type TransformOptions } from './transform-sync'; | ||
|
||
describe('transformSync', () => { | ||
it('should parse TS and return metadata that contains css location', () => { | ||
const sourceCode = ` | ||
import type { GriffelStyle } from '@griffel/react' | ||
import { makeStyles } from '@griffel/react'; | ||
const mixin = (): GriffelStyle => ({ | ||
marginTop: '4px', | ||
}) | ||
export const useStyles = makeStyles({ | ||
root: { | ||
color: 'red', | ||
backgroundColor: 'green', | ||
...mixin() | ||
} | ||
}) | ||
`; | ||
const options: TransformOptions = { | ||
filename: 'test.styles.ts', | ||
pluginOptions: { | ||
babelOptions: { | ||
presets: ['@babel/preset-typescript'], | ||
}, | ||
generateMetadata: true, | ||
}, | ||
}; | ||
|
||
const result = transformSync(sourceCode, options); | ||
|
||
expect(result.metadata.cssEntries).toMatchInlineSnapshot(` | ||
Object { | ||
"useStyles": Object { | ||
"root": Array [ | ||
".fe3e8s9{color:red;}", | ||
".fcnqdeg{background-color:green;}", | ||
".fvjh0tl{margin-top:4px;}", | ||
], | ||
}, | ||
} | ||
`); | ||
expect(result.metadata.locations).toMatchInlineSnapshot(` | ||
Object { | ||
"useStyles": Object { | ||
"root": Object { | ||
"end": Position { | ||
"column": 7, | ||
"index": 317, | ||
"line": 14, | ||
}, | ||
"filename": undefined, | ||
"identifierName": undefined, | ||
"start": Position { | ||
"column": 6, | ||
"index": 227, | ||
"line": 10, | ||
}, | ||
}, | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters