${repeat(
`
foo`,
@@ -195,7 +200,7 @@ describe('stringify static html', () => {
'_imports_0_',
false,
node.loc,
- ConstantTypes.CAN_HOIST,
+ ConstantTypes.CAN_CACHE,
)
node.props[0] = {
type: NodeTypes.DIRECTIVE,
@@ -210,17 +215,7 @@ describe('stringify static html', () => {
],
},
)
- expect(ast.hoists).toMatchObject([
- {
- // the expression and the tree are still hoistable
- // but should stay NodeTypes.VNODE_CALL
- // if it's stringified it will be NodeTypes.JS_CALL_EXPRESSION
- type: NodeTypes.VNODE_CALL,
- },
- {
- type: NodeTypes.JS_ARRAY_EXPRESSION,
- },
- ])
+ expect(ast.cached).toMatchObject([cachedArrayBailedMatcher()])
expect(code).toMatchSnapshot()
})
@@ -258,35 +253,19 @@ describe('stringify static html', () => {
],
},
)
- expect(ast.hoists).toMatchObject([
- {
- // the hoisted node should be NodeTypes.JS_CALL_EXPRESSION
- // of `createStaticVNode()` instead of dynamic NodeTypes.VNODE_CALL
- type: NodeTypes.JS_CALL_EXPRESSION,
- },
- {
- type: NodeTypes.JS_ARRAY_EXPRESSION,
- },
- ])
+ expect(ast.cached).toMatchObject([cachedArraySuccessMatcher()])
expect(code).toMatchSnapshot()
})
// #1128
- test('should bail on non attribute bindings', () => {
+ test('should bail on non-attribute bindings', () => {
const { ast } = compileWithStringify(
`
`,
)
- expect(ast.hoists).toMatchObject([
- {
- type: NodeTypes.VNODE_CALL, // not CALL_EXPRESSION
- },
- {
- type: NodeTypes.JS_ARRAY_EXPRESSION,
- },
- ])
+ expect(ast.cached).toMatchObject([cachedArrayBailedMatcher()])
const { ast: ast2 } = compileWithStringify(
`
`,
)
- expect(ast2.hoists).toMatchObject([
- {
- type: NodeTypes.VNODE_CALL, // not CALL_EXPRESSION
- },
- {
- type: NodeTypes.JS_ARRAY_EXPRESSION,
- },
- ])
- })
+ expect(ast2.cached).toMatchObject([cachedArrayBailedMatcher()])
- test('should bail on non attribute bindings', () => {
- const { ast } = compileWithStringify(
+ const { ast: ast3 } = compileWithStringify(
`
`,
)
- expect(ast.hoists).toMatchObject([
- {
- type: NodeTypes.VNODE_CALL, // not CALL_EXPRESSION
- },
- {
- type: NodeTypes.JS_ARRAY_EXPRESSION,
- },
- ])
+ expect(ast3.cached).toMatchObject([cachedArrayBailedMatcher()])
- const { ast: ast2 } = compileWithStringify(
+ const { ast: ast4 } = compileWithStringify(
`
`,
)
- expect(ast2.hoists).toMatchObject([
- {
- type: NodeTypes.VNODE_CALL, // not CALL_EXPRESSION
- },
- {
- type: NodeTypes.JS_ARRAY_EXPRESSION,
- },
- ])
+ expect(ast4.cached).toMatchObject([cachedArrayBailedMatcher()])
})
test('should bail on tags that has placement constraints (eg.tables related tags)', () => {
@@ -343,14 +299,7 @@ describe('stringify static html', () => {
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
)}`,
)
- expect(ast.hoists).toMatchObject([
- {
- type: NodeTypes.VNODE_CALL, // not CALL_EXPRESSION
- },
- {
- type: NodeTypes.JS_ARRAY_EXPRESSION,
- },
- ])
+ expect(ast.cached).toMatchObject([cachedArrayBailedMatcher()])
})
test('should bail inside slots', () => {
@@ -360,14 +309,9 @@ describe('stringify static html', () => {
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
)}`,
)
- expect(ast.hoists.length).toBe(
- StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
- )
- ast.hoists.forEach(node => {
- expect(node).toMatchObject({
- type: NodeTypes.VNODE_CALL, // not CALL_EXPRESSION
- })
- })
+ expect(ast.cached).toMatchObject([
+ cachedArrayBailedMatcher(StringifyThresholds.ELEMENT_WITH_BINDING_COUNT),
+ ])
const { ast: ast2 } = compileWithStringify(
`
${repeat(
@@ -375,14 +319,9 @@ describe('stringify static html', () => {
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
)}`,
)
- expect(ast2.hoists.length).toBe(
- StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
- )
- ast2.hoists.forEach(node => {
- expect(node).toMatchObject({
- type: NodeTypes.VNODE_CALL, // not CALL_EXPRESSION
- })
- })
+ expect(ast2.cached).toMatchObject([
+ cachedArrayBailedMatcher(StringifyThresholds.ELEMENT_WITH_BINDING_COUNT),
+ ])
})
test('should remove attribute for `null`', () => {
@@ -392,19 +331,13 @@ describe('stringify static html', () => {
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
)}
`,
)
- expect(ast.hoists[0]).toMatchObject({
- type: NodeTypes.JS_CALL_EXPRESSION,
- callee: CREATE_STATIC,
- arguments: [
- JSON.stringify(
- `${repeat(
- `
`,
- StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
- )}`,
- ),
- '5',
- ],
- })
+
+ expect(ast.cached).toMatchObject([
+ cachedArrayStaticNodeMatcher(
+ repeat(`
`, StringifyThresholds.ELEMENT_WITH_BINDING_COUNT),
+ StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
+ ),
+ ])
})
// #6617
@@ -415,19 +348,24 @@ describe('stringify static html', () => {
StringifyThresholds.NODE_COUNT,
)}`,
)
- expect(ast.hoists[0]).toMatchObject({
- type: NodeTypes.JS_CALL_EXPRESSION,
- callee: CREATE_STATIC,
- arguments: [
- JSON.stringify(
- `
`,
- StringifyThresholds.NODE_COUNT,
- )}`,
- ),
- '21',
- ],
- })
+ expect(ast.cached).toMatchObject([
+ {
+ type: NodeTypes.JS_CACHE_EXPRESSION,
+ value: {
+ type: NodeTypes.JS_CALL_EXPRESSION,
+ callee: CREATE_STATIC,
+ arguments: [
+ JSON.stringify(
+ `
`,
+ StringifyThresholds.NODE_COUNT,
+ )}`,
+ ),
+ '21',
+ ],
+ },
+ },
+ ])
})
test('should stringify svg', () => {
@@ -439,19 +377,16 @@ describe('stringify static html', () => {
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT,
)}