From e63db8c2ed68b0b12791fdeb1b0c1f55200b7289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= <root@acid-chicken.com> Date: Wed, 31 May 2023 21:48:53 +0900 Subject: [PATCH] fix(#10923): allow literal keys --- .../lib/rollup-plugin-unwind-css-module-class-name.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/frontend/lib/rollup-plugin-unwind-css-module-class-name.ts b/packages/frontend/lib/rollup-plugin-unwind-css-module-class-name.ts index d783507aea..98028f1496 100644 --- a/packages/frontend/lib/rollup-plugin-unwind-css-module-class-name.ts +++ b/packages/frontend/lib/rollup-plugin-unwind-css-module-class-name.ts @@ -80,8 +80,9 @@ export function unwindCssModuleClassName(ast: estree.Node): void { if (cssModuleTreeNode.declarations[0].init?.type !== 'ObjectExpression') return; const moduleTree = new Map(cssModuleTreeNode.declarations[0].init.properties.flatMap((property) => { if (property.type !== 'Property') return []; - if (property.key.type !== 'Identifier') return []; - if (property.value.type === 'Literal') return [[property.key.name, property.value.value as string]]; + const actualKey = property.key.type === 'Identifier' ? property.key.name : property.key.type === 'Literal' ? property.key.value : null; + if (typeof actualKey !== 'string') return []; + if (property.value.type === 'Literal') return [[actualKey, property.value.value as string]]; if (property.value.type !== 'Identifier') return []; const labelledValue = property.value.name; const actualValue = parent.body.find((x) => { @@ -92,7 +93,7 @@ export function unwindCssModuleClassName(ast: estree.Node): void { return true; }) as unknown as estree.VariableDeclaration; if (actualValue.declarations[0].init?.type !== 'Literal') return []; - return [[property.key.name, actualValue.declarations[0].init.value as string]]; + return [[actualKey, actualValue.declarations[0].init.value as string]]; })); (walk as typeof estreeWalker.walk)(render.argument.body, { enter(childNode) {