mirror of https://github.com/vuejs/core.git
refactor(compiler-sfc): parse css vars directly as part of sfc descriptor
This commit is contained in:
parent
95ae73c58c
commit
bb343383f2
|
@ -24,12 +24,7 @@ import {
|
||||||
} from '@babel/types'
|
} from '@babel/types'
|
||||||
import { walk } from 'estree-walker'
|
import { walk } from 'estree-walker'
|
||||||
import { RawSourceMap } from 'source-map'
|
import { RawSourceMap } from 'source-map'
|
||||||
import {
|
import { CSS_VARS_HELPER, genCssVarsCode, injectCssVarsCalls } from './cssVars'
|
||||||
CSS_VARS_HELPER,
|
|
||||||
parseCssVars,
|
|
||||||
genCssVarsCode,
|
|
||||||
injectCssVarsCalls
|
|
||||||
} from './cssVars'
|
|
||||||
import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate'
|
import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate'
|
||||||
import { warnOnce } from './warn'
|
import { warnOnce } from './warn'
|
||||||
|
|
||||||
|
@ -99,7 +94,7 @@ export function compileScript(
|
||||||
}
|
}
|
||||||
|
|
||||||
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
|
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
|
||||||
const cssVars = parseCssVars(sfc)
|
const cssVars = sfc.cssVars
|
||||||
const scriptLang = script && script.lang
|
const scriptLang = script && script.lang
|
||||||
const scriptSetupLang = scriptSetup && scriptSetup.lang
|
const scriptSetupLang = scriptSetup && scriptSetup.lang
|
||||||
const isTS = scriptLang === 'ts' || scriptSetupLang === 'ts'
|
const isTS = scriptLang === 'ts' || scriptSetupLang === 'ts'
|
||||||
|
|
|
@ -26,7 +26,7 @@ export function generateCssVars(
|
||||||
id: string,
|
id: string,
|
||||||
isProd: boolean
|
isProd: boolean
|
||||||
): string {
|
): string {
|
||||||
return genCssVarsFromList(parseCssVars(sfc), id, isProd)
|
return genCssVarsFromList(sfc.cssVars, id, isProd)
|
||||||
}
|
}
|
||||||
|
|
||||||
function genCssVarsFromList(
|
function genCssVarsFromList(
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as CompilerDOM from '@vue/compiler-dom'
|
||||||
import { RawSourceMap, SourceMapGenerator } from 'source-map'
|
import { RawSourceMap, SourceMapGenerator } from 'source-map'
|
||||||
import { TemplateCompiler } from './compileTemplate'
|
import { TemplateCompiler } from './compileTemplate'
|
||||||
import { Statement } from '@babel/types'
|
import { Statement } from '@babel/types'
|
||||||
|
import { parseCssVars } from './cssVars'
|
||||||
|
|
||||||
export interface SFCParseOptions {
|
export interface SFCParseOptions {
|
||||||
filename?: string
|
filename?: string
|
||||||
|
@ -56,6 +57,7 @@ export interface SFCDescriptor {
|
||||||
scriptSetup: SFCScriptBlock | null
|
scriptSetup: SFCScriptBlock | null
|
||||||
styles: SFCStyleBlock[]
|
styles: SFCStyleBlock[]
|
||||||
customBlocks: SFCBlock[]
|
customBlocks: SFCBlock[]
|
||||||
|
cssVars: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SFCParseResult {
|
export interface SFCParseResult {
|
||||||
|
@ -96,7 +98,8 @@ export function parse(
|
||||||
script: null,
|
script: null,
|
||||||
scriptSetup: null,
|
scriptSetup: null,
|
||||||
styles: [],
|
styles: [],
|
||||||
customBlocks: []
|
customBlocks: [],
|
||||||
|
cssVars: []
|
||||||
}
|
}
|
||||||
|
|
||||||
const errors: (CompilerError | SyntaxError)[] = []
|
const errors: (CompilerError | SyntaxError)[] = []
|
||||||
|
@ -209,6 +212,9 @@ export function parse(
|
||||||
descriptor.customBlocks.forEach(genMap)
|
descriptor.customBlocks.forEach(genMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse CSS vars
|
||||||
|
descriptor.cssVars = parseCssVars(descriptor)
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
descriptor,
|
descriptor,
|
||||||
errors
|
errors
|
||||||
|
|
Loading…
Reference in New Issue