diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap index 504c866e128..434ebcbcf2f 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap @@ -13,3 +13,45 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) { return (_openBlock(), _createElementBlock(\\"div\\", null, _toDisplayString($props.props) + \\" \\" + _toDisplayString($setup.setup) + \\" \\" + _toDisplayString($data.data) + \\" \\" + _toDisplayString($options.options) + \\" \\" + _toDisplayString($setup.isNaN), 1 /* TEXT */)) }" `; + +exports[`compiler: expression transform > bindingMetadata > should not prefix temp variable of for loop 1`] = ` +"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue + +return function render(_ctx, _cache, $props, $setup, $data, $options) { + return (_openBlock(), _createElementBlock(\\"div\\", { + onClick: () => { + for (let i = 0; i < _ctx.list.length; i++) { + _ctx.log(i) + } + } + }, null, 8 /* PROPS */, [\\"onClick\\"])) +}" +`; + +exports[`compiler: expression transform > bindingMetadata > should not prefix temp variable of for...in 1`] = ` +"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue + +return function render(_ctx, _cache, $props, $setup, $data, $options) { + return (_openBlock(), _createElementBlock(\\"div\\", { + onClick: () => { + for (const x in _ctx.list) { + _ctx.log(x) + } + } + }, null, 8 /* PROPS */, [\\"onClick\\"])) +}" +`; + +exports[`compiler: expression transform > bindingMetadata > should not prefix temp variable of for...of 1`] = ` +"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue + +return function render(_ctx, _cache, $props, $setup, $data, $options) { + return (_openBlock(), _createElementBlock(\\"div\\", { + onClick: () => { + for (const x of _ctx.list) { + _ctx.log(x) + } + } + }, null, 8 /* PROPS */, [\\"onClick\\"])) +}" +`; diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts index f8b82396b08..16229113656 100644 --- a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts @@ -534,6 +534,42 @@ describe('compiler: expression transform', () => { expect(code).toMatchSnapshot() }) + test('should not prefix temp variable of for...in', () => { + const { code } = compileWithBindingMetadata( + `