fix(sfc/style-vars): improve ignore style variable bindings in comments (#4202)

This commit is contained in:
edison
2021-07-28 22:51:25 +08:00
committed by GitHub
parent 204e194d2b
commit 771635b72a
3 changed files with 17 additions and 8 deletions

View File

@@ -12,8 +12,7 @@ import { PluginCreator } from 'postcss'
import hash from 'hash-sum'
export const CSS_VARS_HELPER = `useCssVars`
export const cssVarRE =
/\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g
export const cssVarRE = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g
export function genCssVarsFromList(
vars: string[],
@@ -38,7 +37,7 @@ export function parseCssVars(sfc: SFCDescriptor): string[] {
sfc.styles.forEach(style => {
let match
// ignore v-bind() in comments /* ... */
const content = style.content.replace(/\/\*[\s\S]*\*\//g, '')
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '')
while ((match = cssVarRE.exec(content))) {
const variable = match[1] || match[2] || match[3]
if (!vars.includes(variable)) {