mirror of https://github.com/vuejs/core.git
feat(compiler-sfc): respect vapor attr
This commit is contained in:
parent
8bd92c9bfc
commit
b640bb70fc
|
@ -153,7 +153,7 @@ export function compileScript(
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctx = new ScriptCompileContext(sfc, options)
|
const ctx = new ScriptCompileContext(sfc, options)
|
||||||
const { script, scriptSetup, source, filename } = sfc
|
const { script, scriptSetup, source, filename, vapor } = sfc
|
||||||
const hoistStatic = options.hoistStatic !== false && !script
|
const hoistStatic = options.hoistStatic !== false && !script
|
||||||
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
|
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
|
||||||
const scriptLang = script && script.lang
|
const scriptLang = script && script.lang
|
||||||
|
@ -961,6 +961,7 @@ export function compileScript(
|
||||||
startOffset,
|
startOffset,
|
||||||
`\n${genDefaultAs} /*#__PURE__*/${ctx.helper(
|
`\n${genDefaultAs} /*#__PURE__*/${ctx.helper(
|
||||||
`defineComponent`,
|
`defineComponent`,
|
||||||
|
vapor,
|
||||||
)}({${def}${runtimeOptions}\n ${
|
)}({${def}${runtimeOptions}\n ${
|
||||||
hasAwait ? `async ` : ``
|
hasAwait ? `async ` : ``
|
||||||
}setup(${args}) {\n${exposeCall}`,
|
}setup(${args}) {\n${exposeCall}`,
|
||||||
|
@ -996,6 +997,13 @@ export function compileScript(
|
||||||
.join(', ')} } from 'vue'\n`,
|
.join(', ')} } from 'vue'\n`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (ctx.vaporHelperImports.size > 0) {
|
||||||
|
ctx.s.prepend(
|
||||||
|
`import { ${[...ctx.vaporHelperImports]
|
||||||
|
.map(h => `${h} as _${h}`)
|
||||||
|
.join(', ')} } from 'vue/vapor'\n`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...scriptSetup,
|
...scriptSetup,
|
||||||
|
|
|
@ -85,6 +85,8 @@ export interface SFCDescriptor {
|
||||||
*/
|
*/
|
||||||
slotted: boolean
|
slotted: boolean
|
||||||
|
|
||||||
|
vapor: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* compare with an existing descriptor to determine whether HMR should perform
|
* compare with an existing descriptor to determine whether HMR should perform
|
||||||
* a reload vs. re-render.
|
* a reload vs. re-render.
|
||||||
|
@ -147,6 +149,7 @@ export function parse(
|
||||||
customBlocks: [],
|
customBlocks: [],
|
||||||
cssVars: [],
|
cssVars: [],
|
||||||
slotted: false,
|
slotted: false,
|
||||||
|
vapor: false,
|
||||||
shouldForceReload: prevImports => hmrShouldReload(prevImports, descriptor),
|
shouldForceReload: prevImports => hmrShouldReload(prevImports, descriptor),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +209,10 @@ export function parse(
|
||||||
case 'script':
|
case 'script':
|
||||||
const scriptBlock = createBlock(node, source, pad) as SFCScriptBlock
|
const scriptBlock = createBlock(node, source, pad) as SFCScriptBlock
|
||||||
const isSetup = !!scriptBlock.attrs.setup
|
const isSetup = !!scriptBlock.attrs.setup
|
||||||
|
const isVapor = !!scriptBlock.attrs.vapor
|
||||||
|
if (isVapor) {
|
||||||
|
descriptor.vapor = true
|
||||||
|
}
|
||||||
if (isSetup && !descriptor.scriptSetup) {
|
if (isSetup && !descriptor.scriptSetup) {
|
||||||
descriptor.scriptSetup = scriptBlock
|
descriptor.scriptSetup = scriptBlock
|
||||||
break
|
break
|
||||||
|
|
|
@ -62,8 +62,9 @@ export class ScriptCompileContext {
|
||||||
// codegen
|
// codegen
|
||||||
bindingMetadata: BindingMetadata = {}
|
bindingMetadata: BindingMetadata = {}
|
||||||
helperImports: Set<string> = new Set()
|
helperImports: Set<string> = new Set()
|
||||||
helper(key: string): string {
|
vaporHelperImports: Set<string> = new Set()
|
||||||
this.helperImports.add(key)
|
helper(key: string, vapor?: boolean): string {
|
||||||
|
;(vapor ? this.vaporHelperImports : this.helperImports).add(key)
|
||||||
return `_${key}`
|
return `_${key}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue