-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow functions to redeclare vars and functions in function scopes
- Loading branch information
1 parent
53d6360
commit a2e2593
Showing
8 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/function/samples/ast-validations/redeclare-top-level-function-function/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const path = require('node:path'); | ||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
|
||
module.exports = defineTest({ | ||
description: 'throws when redeclaring a top-level function binding as a function', | ||
error: { | ||
code: 'REDECLARATION_ERROR', | ||
frame: ` | ||
1: function foo() {} | ||
2: function foo() {} | ||
^`, | ||
id: ID_MAIN, | ||
loc: { | ||
column: 9, | ||
file: ID_MAIN, | ||
line: 2 | ||
}, | ||
message: 'Identifier "foo" has already been declared', | ||
pos: 27, | ||
watchFiles: [ID_MAIN] | ||
} | ||
}); |
2 changes: 2 additions & 0 deletions
2
test/function/samples/ast-validations/redeclare-top-level-function-function/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
function foo() {} | ||
function foo() {} |
22 changes: 22 additions & 0 deletions
22
test/function/samples/ast-validations/redeclare-top-level-var-function/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const path = require('node:path'); | ||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
|
||
module.exports = defineTest({ | ||
description: 'throws when redeclaring a top-level var binding as a function', | ||
error: { | ||
code: 'REDECLARATION_ERROR', | ||
frame: ` | ||
1: var foo; | ||
2: function foo() {} | ||
^`, | ||
id: ID_MAIN, | ||
loc: { | ||
column: 9, | ||
file: ID_MAIN, | ||
line: 2 | ||
}, | ||
message: 'Identifier "foo" has already been declared', | ||
pos: 18, | ||
watchFiles: [ID_MAIN] | ||
} | ||
}); |
2 changes: 2 additions & 0 deletions
2
test/function/samples/ast-validations/redeclare-top-level-var-function/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var foo; | ||
function foo() {} |
3 changes: 3 additions & 0 deletions
3
test/function/samples/ast-validations/redeclare-var-function/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = defineTest({ | ||
description: 'allows to redeclare vars and functions as vars and functions in function scopes' | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/function/samples/ast-validations/redeclare-var-function/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function foo() { | ||
var fn = 1; | ||
function fn() {} | ||
function fn() {} | ||
var fn = 2; | ||
|
||
assert.equal(fn, 2); | ||
} | ||
|
||
foo(); |