diff --git a/src/compile/nodes/shared/Expression.ts b/src/compile/nodes/shared/Expression.ts index e97cc610fa..30c6ccbc34 100644 --- a/src/compile/nodes/shared/Expression.ts +++ b/src/compile/nodes/shared/Expression.ts @@ -377,6 +377,7 @@ export default class Expression { code.appendLeft(node.end, `; ${insert}`); } + component.has_reactive_assignments = true; pending_assignments = new Set(); } } diff --git a/src/utils/annotateWithScopes.ts b/src/utils/annotateWithScopes.ts index 0ea4f60068..96459e1ede 100644 --- a/src/utils/annotateWithScopes.ts +++ b/src/utils/annotateWithScopes.ts @@ -30,7 +30,7 @@ export function createScopes(expression: Node) { scope.declarations.set(name, node); }); }); - } else if (/For(?:In|Of)Statement/.test(node.type)) { + } else if (/For(?:In|Of)?Statement/.test(node.type)) { scope = new Scope(scope, true); map.set(node, scope); } else if (node.type === 'BlockStatement') { diff --git a/test/runtime/samples/instrumentation-script-loop-scope/_config.js b/test/runtime/samples/instrumentation-script-loop-scope/_config.js new file mode 100644 index 0000000000..1195055c45 --- /dev/null +++ b/test/runtime/samples/instrumentation-script-loop-scope/_config.js @@ -0,0 +1,17 @@ +export default { + html: ` + +

x: 0

+ `, + + async test({ assert, component, target, window }) { + const buttons = target.querySelectorAll('button'); + const click = new window.MouseEvent('click'); + + await buttons[0].dispatchEvent(click); + assert.htmlEqual(target.innerHTML, ` + +

x: 42

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/instrumentation-script-loop-scope/main.html b/test/runtime/samples/instrumentation-script-loop-scope/main.html new file mode 100644 index 0000000000..d2ca75a82d --- /dev/null +++ b/test/runtime/samples/instrumentation-script-loop-scope/main.html @@ -0,0 +1,14 @@ + + + + +

x: {x}

\ No newline at end of file diff --git a/test/runtime/samples/instrumentation-template-loop-scope/_config.js b/test/runtime/samples/instrumentation-template-loop-scope/_config.js new file mode 100644 index 0000000000..a2726934be --- /dev/null +++ b/test/runtime/samples/instrumentation-template-loop-scope/_config.js @@ -0,0 +1,21 @@ +export default { + html: ` + + + +

x: 0

+ `, + + async test({ assert, component, target, window }) { + const buttons = target.querySelectorAll('button'); + const click = new window.MouseEvent('click'); + + await buttons[0].dispatchEvent(click); + assert.htmlEqual(target.innerHTML, ` + + + +

x: 42

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/instrumentation-template-loop-scope/main.html b/test/runtime/samples/instrumentation-template-loop-scope/main.html new file mode 100644 index 0000000000..6032067ff0 --- /dev/null +++ b/test/runtime/samples/instrumentation-template-loop-scope/main.html @@ -0,0 +1,12 @@ + + + + +

x: {x}

\ No newline at end of file