From: patak Date: Thu, 15 Jul 2021 20:45:37 +0000 (+0200) Subject: fix(compiler-sfc): duplicated injected css var with repeated vars in style (#2802) X-Git-Tag: v3.1.5~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=29010501cc9611eb9cacb99a24827053ced3e018;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-sfc): duplicated injected css var with repeated vars in style (#2802) --- diff --git a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap index a5effc3530..44eb668d49 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/cssVars.spec.ts.snap @@ -66,6 +66,25 @@ return { color } }" `; +exports[`CSS vars injection codegen w/ \n` + + `` + ) + // color should only be injected once, even if it is twice in style + expect(content).toMatch(`_useCssVars(_ctx => ({ + "${mockId}-color": (color) +})`) + assertCode(content) + }) }) }) diff --git a/packages/compiler-sfc/src/cssVars.ts b/packages/compiler-sfc/src/cssVars.ts index 021724fd19..884742f297 100644 --- a/packages/compiler-sfc/src/cssVars.ts +++ b/packages/compiler-sfc/src/cssVars.ts @@ -37,7 +37,10 @@ export function parseCssVars(sfc: SFCDescriptor): string[] { sfc.styles.forEach(style => { let match while ((match = cssVarRE.exec(style.content))) { - vars.push(match[1] || match[2] || match[3]) + const variable = match[1] || match[2] || match[3] + if (!vars.includes(variable)) { + vars.push(variable) + } } }) return vars