Skip to content

Commit 1dbbfd3

Browse files
committed
feat(transformer)!: strip css/style suffixes from variable names in class generation
Class names derived from variable names now omit trailing `css`, `style`, or `styles`, making the output more concise. BREAKING CHANGE: CSS class names generated from variables ending with `/css|styles?/` will now have these suffixes removed.
1 parent ac758be commit 1dbbfd3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/rawstyle/src/transformer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ export const transform = (file: string, source: string): TransformResult => {
3636

3737
TaggedTemplateExpression(node) {
3838
const tag = node.tag
39-
if (tag.type !== 'Identifier' || !/^g?css$/.test(tag.name)) return
39+
if (tag.type !== 'Identifier' || !/^g?css$/.test(tag.name) || !activeVarName) return
4040

4141
const cssTpl = source.slice(node.quasi.start + 1, node.quasi.end - 1)
4242
let rep = ''
4343
if (tag.name === 'gcss') {
4444
css += cssTpl
4545
rep = '""'
4646
} else {
47-
const clName = `${activeVarName}_${fileHash}`
47+
const clName = `${activeVarName.replace(/css|styles?$/i, '')}_${fileHash}`
4848
css += `.${clName} {${cssTpl}}`
49-
rep = `'${activeVarName}_${fileHash}'`
49+
rep = `'${clName}'`
5050
}
5151

5252
replacements.push({ start: node.start, end: node.end, replacement: rep })

0 commit comments

Comments
 (0)