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