Skip to content

Commit 4f89b57

Browse files
committed
fix(rawstyle): remove leading indentation from extracted CSS templates
Transformer now strips unnecessary left indentation from CSS template strings for cleaner output.
1 parent 73c1386 commit 4f89b57

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/rawstyle/src/transformer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export const transform = (file: string, source: string): TransformResult => {
6363
TaggedTemplateExpression(node) {
6464
const tag = node.tag
6565
if (tag.type !== 'Identifier' || (tag.name !== 'css' && tag.name !== 'gcss')) return
66-
const template = node.quasi.quasis.map(q => q.value.cooked).join('')
66+
const template = node.quasi.quasis.map(q => {
67+
const tpl = q.value.cooked ?? ''
68+
const indent = (/^([^\n]*?)\S/m.exec(tpl))?.[1] ?? ''
69+
return tpl.split('\n').map(line => line.replace(indent, '')).join('\n').trim()
70+
}).join('')
6771
if (!activeRange) return
6872
cssVarDecls.push({ name: currentVarName ?? '', tag: tag.name, template, start: activeRange.start, end: activeRange.end })
6973
replacements.push({ start: activeRange.start, end: activeRange.end, replacement: '' })

0 commit comments

Comments
 (0)