diff --git a/src/ast/scopes/BlockScope.ts b/src/ast/scopes/BlockScope.ts index c4146818f..ae5701482 100644 --- a/src/ast/scopes/BlockScope.ts +++ b/src/ast/scopes/BlockScope.ts @@ -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; } diff --git a/test/function/samples/ast-validations/redeclare-var-parameter-nested/_config.js b/test/function/samples/ast-validations/redeclare-var-parameter-nested/_config.js new file mode 100644 index 000000000..36a2b6a82 --- /dev/null +++ b/test/function/samples/ast-validations/redeclare-var-parameter-nested/_config.js @@ -0,0 +1,3 @@ +module.exports = defineTest({ + description: 'allows to redeclare parameters with multiple nested vars' +}); diff --git a/test/function/samples/ast-validations/redeclare-var-parameter-nested/main.js b/test/function/samples/ast-validations/redeclare-var-parameter-nested/main.js new file mode 100644 index 000000000..4973c455d --- /dev/null +++ b/test/function/samples/ast-validations/redeclare-var-parameter-nested/main.js @@ -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);