a var declared again: its declarator has the binding, and an initializer there reassigns

goodbye-acorn
Nic 2 weeks ago
parent bc75f67b03
commit 2dd7f7824f

@ -1183,7 +1183,21 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
]); ]);
} }
for (const reference of answer.references) { for (const reference of answer.references) {
if (reference.declares) continue; if (reference.declares) {
// `var x` again: the declarator declares the binding the first one made
const ours = reference.binding === null ? undefined : from_parser.get(reference.binding);
/** @type {any} */
let declarator = parentOf(reference.node);
while (declarator && /Pattern$|^Property$|^RestElement$/.test(declarator.type)) {
declarator = parentOf(declarator);
}
if (ours && declarator?.type === 'VariableDeclarator') {
declarators.push([declarator, ours]);
// an initializer there assigns again, so the first one is not the value
if (reference.write) ours.reassigned = true;
}
continue;
}
const binding = reference.binding === null ? undefined : from_parser.get(reference.binding); const binding = reference.binding === null ? undefined : from_parser.get(reference.binding);
entries.push([ entries.push([
reference.node, reference.node,

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: '<p>42 3 4</p>'
});

@ -0,0 +1,9 @@
<script>
var test = "";
var test = 42;
var { a, b: [c] } = { a: 1, b: [2] };
var { a, b: [c] } = { a: 3, b: [4] };
</script>
<p>{test} {a} {c}</p>
Loading…
Cancel
Save