Skip to content

Commit

Permalink
fix(es/lints): Ignore TS module declare blocks (#5363)
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari authored Aug 2, 2022
1 parent 1ec9819 commit daaa8b5
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,3 @@
import a from "a";
a();
// @filename: external.d.ts
//!
//! x the name `default` is exported multiple times
//! ,-[6:9]
//! 6 | export { _a as default };
//! : ^^^|^^^
//! : `-- previous exported here
//! 7 | }
//! 8 | export default a;
//! : ^^^^^^^^|^^^^^^^^
//! : `-- exported more than once
//! `----
//!
//!Error:
//! > Exported identifiers must be unique
//!
//! x An export assignment cannot be used in a module with other exported elements.
//! ,----
//! 13 | export = a;
//! : ^^^^^^^^^^^
//! `----
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
import a from "a";
a();
// @filename: external.d.ts
//!
//! x the name `default` is exported multiple times
//! ,-[6:9]
//! 6 | export { _a as default };
//! : ^^^|^^^
//! : `-- previous exported here
//! 7 | }
//! 8 | export default a;
//! : ^^^^^^^^|^^^^^^^^
//! : `-- exported more than once
//! `----
//!
//!Error:
//! > Exported identifiers must be unique
//!
//! x An export assignment cannot be used in a module with other exported elements.
//! ,----
//! 13 | export = a;
//! : ^^^^^^^^^^^
//! `----
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,3 @@
import a from "a";
a();
// @filename: external.d.ts
//!
//! x the name `default` is exported multiple times
//! ,-[6:9]
//! 6 | export { _a as default };
//! : ^^^|^^^
//! : `-- previous exported here
//! 7 | }
//! 8 | export default a;
//! : ^^^^^^^^|^^^^^^^^
//! : `-- exported more than once
//! `----
//!
//!Error:
//! > Exported identifiers must be unique
//!
//! x An export assignment cannot be used in a module with other exported elements.
//! ,----
//! 13 | export = a;
//! : ^^^^^^^^^^^
//! `----
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
import a from "a";
a();
// @filename: external.d.ts
//!
//! x the name `default` is exported multiple times
//! ,-[6:9]
//! 6 | export { _a as default };
//! : ^^^|^^^
//! : `-- previous exported here
//! 7 | }
//! 8 | export default a;
//! : ^^^^^^^^|^^^^^^^^
//! : `-- exported more than once
//! `----
//!
//!Error:
//! > Exported identifiers must be unique
//!
//! x An export assignment cannot be used in a module with other exported elements.
//! ,----
//! 13 | export = a;
//! : ^^^^^^^^^^^
//! `----
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
//@jsx: preserve
//@target: ES5
//@Filename: react.d.ts
//!
//! x multiple `export =` found
//! ,-[4:5]
//! 4 | export = x;
//! : ^^^^^|^^^^^
//! : `-- previous `export =` declared here
//! 5 | }
//! 6 |
//! 7 | declare module ReactRouter {
//! 8 | var Route: any;
//! 9 | interface Thing { }
//! 10 | }
//! 11 | declare module 'react-router' {
//! 12 | export = ReactRouter;
//! : ^^^^^^^^^^^^^^^^^^^^^
//! `----
//@Filename: test.tsx
// Should emit 'react-router' in the AMD dependency list
const React = require('react');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
//@Filename: react.d.ts
//!
//! x multiple `export =` found
//! ,-[4:5]
//! 4 | export = x;
//! : ^^^^^|^^^^^
//! : `-- previous `export =` declared here
//! 5 | }
//! 6 |
//! 7 | declare module ReactRouter {
//! 8 | var Route: any;
//! 9 | interface Thing { }
//! 10 | }
//! 11 | declare module 'react-router' {
//! 12 | export = ReactRouter;
//! : ^^^^^^^^^^^^^^^^^^^^^
//! `----
var M;
require('react');
let ReactRouter = require('react-router');
Expand Down
16 changes: 0 additions & 16 deletions crates/swc/tests/tsc-references/tsxPreserveEmit1_es5.1.normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
//@jsx: preserve
//@target: ES5
//@Filename: react.d.ts
//!
//! x multiple `export =` found
//! ,-[4:5]
//! 4 | export = x;
//! : ^^^^^|^^^^^
//! : `-- previous `export =` declared here
//! 5 | }
//! 6 |
//! 7 | declare module ReactRouter {
//! 8 | var Route: any;
//! 9 | interface Thing { }
//! 10 | }
//! 11 | declare module 'react-router' {
//! 12 | export = ReactRouter;
//! : ^^^^^^^^^^^^^^^^^^^^^
//! `----
//@Filename: test.tsx
// Should emit 'react-router' in the AMD dependency list
var React = require("react");
Expand Down
17 changes: 0 additions & 17 deletions crates/swc/tests/tsc-references/tsxPreserveEmit1_es5.2.minified.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
//@Filename: react.d.ts
//!
//! x multiple `export =` found
//! ,-[4:5]
//! 4 | export = x;
//! : ^^^^^|^^^^^
//! : `-- previous `export =` declared here
//! 5 | }
//! 6 |
//! 7 | declare module ReactRouter {
//! 8 | var Route: any;
//! 9 | interface Thing { }
//! 10 | }
//! 11 | declare module 'react-router' {
//! 12 | export = ReactRouter;
//! : ^^^^^^^^^^^^^^^^^^^^^
//! `----
var M;
require("react"), require("react-router").Route, function(M) {
var X1;
Expand Down
6 changes: 6 additions & 0 deletions crates/swc_ecma_lints/src/rules/duplicate_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ impl DuplicateExports {
impl Visit for DuplicateExports {
noop_visit_type!();

fn visit_ts_module_decl(&mut self, d: &TsModuleDecl) {
if !d.declare {
d.visit_children_with(self);
}
}

fn visit_export_default_decl(&mut self, d: &ExportDefaultDecl) {
if matches!(
d.decl,
Expand Down

1 comment on commit daaa8b5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: daaa8b5 Previous: 27cdc65 Ratio
es/full/minify/libraries/antd 1813581502 ns/iter (± 106750103) 1768673065 ns/iter (± 129292983) 1.03
es/full/minify/libraries/d3 396120999 ns/iter (± 8316479) 415635018 ns/iter (± 6618789) 0.95
es/full/minify/libraries/echarts 1535258765 ns/iter (± 164903332) 1547056653 ns/iter (± 126098811) 0.99
es/full/minify/libraries/jquery 96940477 ns/iter (± 1635609) 110740581 ns/iter (± 4312617) 0.88
es/full/minify/libraries/lodash 123456291 ns/iter (± 3565693) 138614456 ns/iter (± 2976341) 0.89
es/full/minify/libraries/moment 62036012 ns/iter (± 6982853) 63786200 ns/iter (± 4971221) 0.97
es/full/minify/libraries/react 20086452 ns/iter (± 1925103) 20270511 ns/iter (± 1550152) 0.99
es/full/minify/libraries/terser 334480838 ns/iter (± 22119047) 330461768 ns/iter (± 32173775) 1.01
es/full/minify/libraries/three 578036380 ns/iter (± 81714498) 590180861 ns/iter (± 48925192) 0.98
es/full/minify/libraries/typescript 3641071016 ns/iter (± 129452488) 3611911670 ns/iter (± 155086739) 1.01
es/full/minify/libraries/victory 792759241 ns/iter (± 28919613) 800643770 ns/iter (± 70904952) 0.99
es/full/minify/libraries/vue 141214183 ns/iter (± 20560684) 159984157 ns/iter (± 11974250) 0.88
es/full/codegen/es3 33266 ns/iter (± 933) 35048 ns/iter (± 4222) 0.95
es/full/codegen/es5 33359 ns/iter (± 880) 35604 ns/iter (± 5364) 0.94
es/full/codegen/es2015 33336 ns/iter (± 796) 34729 ns/iter (± 7306) 0.96
es/full/codegen/es2016 33464 ns/iter (± 895) 34818 ns/iter (± 4709) 0.96
es/full/codegen/es2017 33560 ns/iter (± 2168) 34681 ns/iter (± 3418) 0.97
es/full/codegen/es2018 33511 ns/iter (± 755) 35526 ns/iter (± 3839) 0.94
es/full/codegen/es2019 34022 ns/iter (± 1770) 34906 ns/iter (± 4236) 0.97
es/full/codegen/es2020 33383 ns/iter (± 1822) 35054 ns/iter (± 6131) 0.95
es/full/all/es3 233462438 ns/iter (± 27365764) 235235904 ns/iter (± 23776373) 0.99
es/full/all/es5 181918852 ns/iter (± 11462971) 218798430 ns/iter (± 20959199) 0.83
es/full/all/es2015 147907908 ns/iter (± 12241199) 174294691 ns/iter (± 19440001) 0.85
es/full/all/es2016 147519675 ns/iter (± 12409387) 171708674 ns/iter (± 14228366) 0.86
es/full/all/es2017 146666008 ns/iter (± 11285355) 171584508 ns/iter (± 23979211) 0.85
es/full/all/es2018 144447304 ns/iter (± 11351566) 172741057 ns/iter (± 18268206) 0.84
es/full/all/es2019 146779751 ns/iter (± 10019883) 170686842 ns/iter (± 16258666) 0.86
es/full/all/es2020 139987877 ns/iter (± 11257626) 163098050 ns/iter (± 11534552) 0.86
es/full/parser 779159 ns/iter (± 59933) 788375 ns/iter (± 79680) 0.99
es/full/base/fixer 29391 ns/iter (± 1918) 31275 ns/iter (± 8440) 0.94
es/full/base/resolver_and_hygiene 87616 ns/iter (± 6785) 89920 ns/iter (± 8801) 0.97
serialization of ast node 212 ns/iter (± 3) 216 ns/iter (± 3) 0.98
serialization of serde 237 ns/iter (± 6) 240 ns/iter (± 25) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.