}"
`;
+exports[`cache multiple access > should cache method call with same arguments 1`] = `
+"import { setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
+const t0 = _template("<div></div>")
+
+export function render(_ctx) {
+ const n0 = t0()
+ const n1 = t0()
+ _renderEffect(() => {
+ const _msg_replace_1_2 = _ctx.msg.replace('1', '2')
+ _setProp(n0, "id", _msg_replace_1_2)
+ _setProp(n1, "id", _msg_replace_1_2)
+ })
+ return [n0, n1]
+}"
+`;
+
+exports[`cache multiple access > should not cache method call with different arguments 1`] = `
+"import { setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
+const t0 = _template("<div></div>")
+
+export function render(_ctx) {
+ const n0 = t0()
+ const n1 = t0()
+ _renderEffect(() => {
+ const _msg = _ctx.msg
+ _setProp(n0, "id", _msg.replace('1', '2'))
+ _setProp(n1, "id", _msg.replace('1', '3'))
+ })
+ return [n0, n1]
+}"
+`;
+
exports[`cache multiple access > variable name substring edge cases 1`] = `
"import { setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
const t0 = _template("<div></div>", true)
expect(code).matchSnapshot()
expect(code).not.contains('const _bar = _ctx.bar')
})
+
+ test('should not cache method call with different arguments', () => {
+ const { code } = compileWithVBind(`
+ <div :id="msg.replace('1', '2')"></div>
+ <div :id="msg.replace('1', '3')"></div>
+ `)
+ expect(code).matchSnapshot()
+ expect(code).contains('const _msg = _ctx.msg')
+ expect(code).not.contains('_ctx.msg.replace')
+ })
+
+ test('should cache method call with same arguments', () => {
+ const { code } = compileWithVBind(`
+ <div :id="msg.replace('1', '2')"></div>
+ <div :id="msg.replace('1', '2')"></div>
+ `)
+ expect(code).matchSnapshot()
+ expect(code).contains(`const _msg_replace_1_2 = _ctx.msg.replace('1', '2')`)
+ expect(code).not.contains('const _msg = _ctx.msg')
+ })
})
end: id.end!,
})
})
+
+ const parentOfMemberExp = parentStack[parentStack.length - 2]
+ if (parentOfMemberExp && isCallExpression(parentOfMemberExp)) {
+ return
+ }
+
registerVariable(
memberExp,
exp,
}
}
+const isCallExpression = (node: Node) => {
+ return (
+ node.type === 'CallExpression' || node.type === 'OptionalCallExpression'
+ )
+}
+
const isMemberExpression = (node: Node) => {
return (
node.type === 'MemberExpression' ||