-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/lints): Detect duplicate bindings in export defaults (#8760)
**Description:** add DefaultDecl's FnExpr and ClassExpr's ident to bindings. because all of them should be treated as hoisted Fn/Class Declare ```txt × the name `x` is defined multiple times ╭─[examples/all.js:1:1] 1 │ export default class x{} · ┬ · ╰── previous definition of `x` here 2 │ 3 │ let x = 1; · ┬ · ╰── `x` redefined here 4 │ let t = function x(){}; ╰──── ``` **Related issue:** - Closes #8755
- Loading branch information
1 parent
2067677
commit c9c971a
Showing
10 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
crates/swc/tests/errors/lints/duplicate-bindings/module/export-default-class-expr/input.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 @@ | ||
export default class Foo{} | ||
let Foo = 1; // error |
10 changes: 10 additions & 0 deletions
10
.../tests/errors/lints/duplicate-bindings/module/export-default-class-expr/output.swc-stderr
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 @@ | ||
|
||
x the name `Foo` is defined multiple times | ||
,-[1:1] | ||
1 | export default class Foo{} | ||
: ^|^ | ||
: `-- previous definition of `Foo` here | ||
2 | let Foo = 1; // error | ||
: ^|^ | ||
: `-- `Foo` redefined here | ||
`---- |
2 changes: 2 additions & 0 deletions
2
crates/swc/tests/errors/lints/duplicate-bindings/module/export-default-fn-expr/input.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 @@ | ||
export default function foo(){} | ||
let foo = 1; // error |
10 changes: 10 additions & 0 deletions
10
...swc/tests/errors/lints/duplicate-bindings/module/export-default-fn-expr/output.swc-stderr
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 @@ | ||
|
||
x the name `foo` is defined multiple times | ||
,-[1:1] | ||
1 | export default function foo(){} | ||
: ^|^ | ||
: `-- previous definition of `foo` here | ||
2 | let foo = 1; // error | ||
: ^|^ | ||
: `-- `foo` redefined here | ||
`---- |
14 changes: 14 additions & 0 deletions
14
crates/swc/tests/tsc-references/multipleDefaultExports03.1.normal.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
14 changes: 14 additions & 0 deletions
14
crates/swc/tests/tsc-references/multipleDefaultExports03.2.minified.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
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
2 changes: 2 additions & 0 deletions
2
crates/swc_ecma_lints/tests/pass/export/export_default_class_expr/1/input.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 @@ | ||
export default class Foo{}; | ||
let bar = function Foo(){}; |
2 changes: 2 additions & 0 deletions
2
crates/swc_ecma_lints/tests/pass/export/export_default_fn_expr/1/input.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 @@ | ||
export default function foo(){}; | ||
let bar = function foo(){}; |
2 changes: 2 additions & 0 deletions
2
crates/swc_ecma_lints/tests/pass/export/export_default_fn_expr/2/input.ts
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 @@ | ||
export default function foo(); | ||
let foo = 1; |