Skip to content

Commit

Permalink
Allow to redeclare parameters multiple times in nested scopes (#5276)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert authored Nov 30, 2023
1 parent b3132dd commit 0bf5199
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ast/scopes/BlockScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export default class BlockScope extends ChildScope {
const existingVariable =
this.hoistedVariables?.get(name) || (this.variables.get(name) as LocalVariable | undefined);
if (existingVariable) {
if (existingVariable.kind === VariableKind.var) {
if (
existingVariable.kind === VariableKind.var ||
(kind === VariableKind.var && existingVariable.kind === VariableKind.parameter)
) {
existingVariable.addDeclaration(identifier, init);
return existingVariable;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = defineTest({
description: 'allows to redeclare parameters with multiple nested vars'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function f(val) {
{
var val = 1;
var val = 2;
}
assert.equal(val, 2);
}
f(0);

export function g(val) {
{
{
var val = 1;
}
{
var val = 2;
}
}
assert.equal(val, 2);
}
g(0);

0 comments on commit 0bf5199

Please sign in to comment.