exports[`scopeId compiler support should push scopeId for hoisted nodes 1`] = `
"import { createVNode as _createVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from \\"vue\\"
-const _withId = /*#__PURE__*/ _withScopeId(\\"test\\")
+const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
_pushScopeId(\\"test\\")
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"div\\", null, \\"hello\\", -1 /* HOISTED */)
-const _hoisted_2 = /*#__PURE__*/ _createVNode(\\"div\\", null, \\"world\\", -1 /* HOISTED */)
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"div\\", null, \\"hello\\", -1 /* HOISTED */)
+const _hoisted_2 = /*#__PURE__*/_createVNode(\\"div\\", null, \\"world\\", -1 /* HOISTED */)
_popScopeId()
-export const render = /*#__PURE__*/ _withId(function render(_ctx, _cache) {
+export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
return (_openBlock(), _createBlock(\\"div\\", null, [
_hoisted_1,
_createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */),
exports[`scopeId compiler support should wrap default slot 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
-const _withId = /*#__PURE__*/ _withScopeId(\\"test\\")
+const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
-export const render = /*#__PURE__*/ _withId(function render(_ctx, _cache) {
+export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
const _component_Child = _resolveComponent(\\"Child\\")
return (_openBlock(), _createBlock(_component_Child, null, {
exports[`scopeId compiler support should wrap dynamic slots 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, renderList as _renderList, createSlots as _createSlots, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
-const _withId = /*#__PURE__*/ _withScopeId(\\"test\\")
+const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
-export const render = /*#__PURE__*/ _withId(function render(_ctx, _cache) {
+export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
const _component_Child = _resolveComponent(\\"Child\\")
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _: 1 }, [
exports[`scopeId compiler support should wrap named slots 1`] = `
"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createVNode as _createVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
-const _withId = /*#__PURE__*/ _withScopeId(\\"test\\")
+const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
-export const render = /*#__PURE__*/ _withId(function render(_ctx, _cache) {
+export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
const _component_Child = _resolveComponent(\\"Child\\")
return (_openBlock(), _createBlock(_component_Child, null, {
exports[`scopeId compiler support should wrap render function 1`] = `
"import { createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
-const _withId = /*#__PURE__*/ _withScopeId(\\"test\\")
+const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
-export const render = /*#__PURE__*/ _withId(function render(_ctx, _cache) {
+export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
return (_openBlock(), _createBlock(\\"div\\"))
})"
`;
scopeId: 'test'
})
expect(ast.helpers).toContain(WITH_SCOPE_ID)
- expect(code).toMatch(`const _withId = /*#__PURE__*/ _withScopeId("test")`)
+ expect(code).toMatch(`const _withId = /*#__PURE__*/_withScopeId("test")`)
expect(code).toMatch(
- `export const render = /*#__PURE__*/ _withId(function render(`
+ `export const render = /*#__PURE__*/_withId(function render(`
)
expect(code).toMatchSnapshot()
})
expect(code).toMatch(
[
`_pushScopeId("test")`,
- `const _hoisted_1 = /*#__PURE__*/ _createVNode("div", null, "hello", ${genFlagText(
+ `const _hoisted_1 = /*#__PURE__*/_createVNode("div", null, "hello", ${genFlagText(
PatchFlags.HOISTED
)})`,
- `const _hoisted_2 = /*#__PURE__*/ _createVNode("div", null, "world", ${genFlagText(
+ `const _hoisted_2 = /*#__PURE__*/_createVNode("div", null, "world", ${genFlagText(
PatchFlags.HOISTED
)})`,
`_popScopeId()`
"const _Vue = Vue
const { createVNode: _createVNode } = _Vue
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"div\\", { key: \\"foo\\" }, null, -1 /* HOISTED */)
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"div\\", { key: \\"foo\\" }, null, -1 /* HOISTED */)
return function render(_ctx, _cache) {
with (_ctx) {
"const _Vue = Vue
const { createVNode: _createVNode } = _Vue
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"p\\", null, [
- _createVNode(\\"span\\"),
- _createVNode(\\"span\\")
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"p\\", null, [
+ /*#__PURE__*/_createVNode(\\"span\\"),
+ /*#__PURE__*/_createVNode(\\"span\\")
], -1 /* HOISTED */)
return function render(_ctx, _cache) {
"const _Vue = Vue
const { createVNode: _createVNode, createCommentVNode: _createCommentVNode } = _Vue
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"div\\", null, [
- _createCommentVNode(\\"comment\\")
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"div\\", null, [
+ /*#__PURE__*/_createCommentVNode(\\"comment\\")
], -1 /* HOISTED */)
return function render(_ctx, _cache) {
"const _Vue = Vue
const { createVNode: _createVNode } = _Vue
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"span\\", null, null, -1 /* HOISTED */)
-const _hoisted_2 = /*#__PURE__*/ _createVNode(\\"div\\", null, null, -1 /* HOISTED */)
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"span\\", null, null, -1 /* HOISTED */)
+const _hoisted_2 = /*#__PURE__*/_createVNode(\\"div\\", null, null, -1 /* HOISTED */)
return function render(_ctx, _cache) {
with (_ctx) {
"const _Vue = Vue
const { createVNode: _createVNode } = _Vue
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"span\\", { class: \\"inline\\" }, \\"hello\\", -1 /* HOISTED */)
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"span\\", { class: \\"inline\\" }, \\"hello\\", -1 /* HOISTED */)
return function render(_ctx, _cache) {
with (_ctx) {
"const _Vue = Vue
const { createVNode: _createVNode } = _Vue
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"span\\", null, \\"foo \\" + _toDisplayString(1) + \\" \\" + _toDisplayString(true), -1 /* HOISTED */)
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"span\\", null, \\"foo \\" + /*#__PURE__*/_toDisplayString(1) + \\" \\" + /*#__PURE__*/_toDisplayString(true), -1 /* HOISTED */)
return function render(_ctx, _cache) {
with (_ctx) {
"const _Vue = Vue
const { createVNode: _createVNode } = _Vue
-const _hoisted_1 = /*#__PURE__*/ _createVNode(\\"span\\", { foo: 0 }, _toDisplayString(1), -1 /* HOISTED */)
+const _hoisted_1 = /*#__PURE__*/_createVNode(\\"span\\", { foo: 0 }, /*#__PURE__*/_toDisplayString(1), -1 /* HOISTED */)
return function render(_ctx, _cache) {
with (_ctx) {
const { createVNode: _createVNode } = _Vue
const _hoisted_1 = { id: \\"foo\\" }
-const _hoisted_2 = /*#__PURE__*/ _createVNode(\\"span\\", null, null, -1 /* HOISTED */)
+const _hoisted_2 = /*#__PURE__*/_createVNode(\\"span\\", null, null, -1 /* HOISTED */)
return function render(_ctx, _cache) {
with (_ctx) {
key: 0,
id: \\"foo\\"
}
-const _hoisted_2 = /*#__PURE__*/ _createVNode(\\"span\\", null, null, -1 /* HOISTED */)
+const _hoisted_2 = /*#__PURE__*/_createVNode(\\"span\\", null, null, -1 /* HOISTED */)
return function render(_ctx, _cache) {
with (_ctx) {
} from './runtimeHelpers'
import { ImportItem } from './transform'
+const PURE_ANNOTATION = `/*#__PURE__*/`
+
type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode
export interface CodegenResult {
column: number
offset: number
indentLevel: number
+ pure: boolean
map?: SourceMapGenerator
helper(key: symbol): string
push(code: string, node?: CodegenNode): void
line: 1,
offset: 0,
indentLevel: 0,
+ pure: false,
map: undefined,
helper(key) {
return `_${helperNameMap[key]}`
// enter render function
if (genScopeId && !ssr) {
- push(`const render = /*#__PURE__*/ _withId(`)
+ push(`const render = ${PURE_ANNOTATION}_withId(`)
}
if (!ssr) {
push(`function render(_ctx, _cache) {`)
}
if (genScopeId) {
- push(`const _withId = /*#__PURE__*/ ${helper(WITH_SCOPE_ID)}("${scopeId}")`)
+ push(
+ `const _withId = ${PURE_ANNOTATION}${helper(WITH_SCOPE_ID)}("${scopeId}")`
+ )
newline()
}
if (!hoists.length) {
return
}
+ context.pure = true
const { push, newline, helper, scopeId, mode } = context
const genScopeId = !__BROWSER__ && scopeId != null && mode !== 'function'
newline()
hoists.forEach((exp, i) => {
push(`const _hoisted_${i + 1} = `)
- // make hosit function calls tree-shakable
- if (
- exp.type === NodeTypes.VNODE_CALL ||
- exp.type === NodeTypes.JS_CALL_EXPRESSION
- ) {
- push(`/*#__PURE__*/ `)
- }
genNode(exp, context)
newline()
})
push(`${helper(POP_SCOPE_ID)}()`)
newline()
}
+ context.pure = false
}
function genImports(importsOptions: ImportItem[], context: CodegenContext) {
}
function genInterpolation(node: InterpolationNode, context: CodegenContext) {
- const { push, helper } = context
+ const { push, helper, pure } = context
+ if (pure) push(PURE_ANNOTATION)
push(`${helper(TO_DISPLAY_STRING)}(`)
genNode(node.content, context)
push(`)`)
function genComment(node: CommentNode, context: CodegenContext) {
if (__DEV__) {
- const { push, helper } = context
+ const { push, helper, pure } = context
+ if (pure) {
+ push(PURE_ANNOTATION)
+ }
push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node)
}
}
function genVNodeCall(node: VNodeCall, context: CodegenContext) {
- const { push, helper } = context
+ const { push, helper, pure } = context
const {
tag,
props,
if (isBlock) {
push(`(${helper(OPEN_BLOCK)}(${isForBlock ? `true` : ``}), `)
}
+ if (pure) {
+ push(PURE_ANNOTATION)
+ }
push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node)
genNodeList(
genNullableArgs([tag, props, children, patchFlag, dynamicProps]),
// JavaScript
function genCallExpression(node: CallExpression, context: CodegenContext) {
- const callee = isString(node.callee)
- ? node.callee
- : context.helper(node.callee)
- context.push(callee + `(`, node)
+ const { push, helper, pure } = context
+ const callee = isString(node.callee) ? node.callee : helper(node.callee)
+ if (pure) {
+ push(PURE_ANNOTATION)
+ }
+ push(callee + `(`, node)
genNodeList(node.arguments, context)
- context.push(`)`)
+ push(`)`)
}
function genObjectExpression(node: ObjectExpression, context: CodegenContext) {