Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es/typescript): Support export type * from "mod" #6867

Merged
merged 5 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace10.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
//// [/b.ts]
export { };
//// [/c.ts]
import { ns } from "./b";
var _ = new ns.A(); // Error
11 changes: 11 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace10.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
//// [/b.ts]
export { };
//// [/c.ts]
import { ns } from "./b";
new ns.A();
14 changes: 14 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace2.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
//// [b.ts]
import * as _a from "./a";
export { _a as a };
//// [c.ts]
export { };
//// [d.ts]
import { a } from "./c";
new a.A(); // Error
14 changes: 14 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace2.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
//// [b.ts]
import * as _a from "./a";
export { _a as a };
//// [c.ts]
export { };
//// [d.ts]
import { a } from "./c";
new a.A();
17 changes: 17 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace4.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [exportNamespace4.ts]
//// [a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
//// [b.ts]
export { };
//// [c.ts]
export { };
//// [d.ts]
import { A } from "./b";
A;
//// [e.ts]
import { ns } from "./c";
ns.A;
16 changes: 16 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace4.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [exportNamespace4.ts]
//// [a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
//// [b.ts]
export { };
//// [c.ts]
export { };
//// [d.ts]
import { A } from "./b";
//// [e.ts]
import { ns } from "./c";
ns.A;
29 changes: 29 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace5.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [exportNamespace5.ts]
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
export var X = function X() {
"use strict";
_class_call_check(this, X);
};
//// [/b.ts]
export { X } from "./a";
//// [/c.ts]
import { A, B as C, X } from "./b";
var _ = new A(); // Error
var __ = new C(); // Error
var ___ = new X(); // Ok
//// [/d.ts]
export * from "./a";
//// [/e.ts]
import { A, B, X } from "./d";
var _ = new A(); // Ok
var __ = new B(); // Ok
var ___ = new X(); // Ok
25 changes: 25 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace5.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [exportNamespace5.ts]
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
export var X = function X() {
"use strict";
_class_call_check(this, X);
};
//// [/b.ts]
export { X } from "./a";
//// [/c.ts]
import { A, B as C, X } from "./b";
new A(), new C(), new X();
//// [/d.ts]
export * from "./a";
//// [/e.ts]
import { A, B, X } from "./d";
new A(), new B(), new X();
18 changes: 18 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace6.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
//// [/b.ts]
export { };
//// [/c.ts]
export * from "./b";
//// [/d.ts]
import { A, B } from "./c";
var _ = new A(); // Error
var __ = new B(); // Error
17 changes: 17 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace6.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
//// [/b.ts]
export { };
//// [/c.ts]
export * from "./b";
//// [/d.ts]
import { A, B } from "./c";
new A(), new B();
32 changes: 32 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace7.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
export var C = function C() {
"use strict";
_class_call_check(this, C);
};
//// [/b.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var C = function C() {
"use strict";
_class_call_check(this, C);
};
//// [/c.ts]
import { A, B, C } from "./b";
var _ = new A(); // Error
var __ = new B(); // Error
var ___ = new C(); // Ok
//// [/d.ts]
export { };
//// [/e.ts]
import { A, B, C } from "./d";
var _ = new A(); // Error
var __ = new B(); // Error
var ___ = new C(); // Error
28 changes: 28 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace7.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
export var C = function C() {
"use strict";
_class_call_check(this, C);
};
//// [/b.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var C = function C() {
"use strict";
_class_call_check(this, C);
};
//// [/c.ts]
import { A, B, C } from "./b";
new A(), new B(), new C();
//// [/d.ts]
export { };
//// [/e.ts]
import { A, B, C } from "./d";
new A(), new B(), new C();
27 changes: 27 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace8.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
//// [/b.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
export var C = function C() {
"use strict";
_class_call_check(this, C);
};
//// [/c.ts]
export * from "./b"; // Collision error
//// [/d.ts]
import { A, B, C } from "./c";
var _ = new A(); // Error
var __ = new B(); // Ok
var ___ = new C(); // Ok
25 changes: 25 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace8.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [/a.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var A = function A() {
"use strict";
_class_call_check(this, A);
};
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
//// [/b.ts]
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs";
export var B = function B() {
"use strict";
_class_call_check(this, B);
};
export var C = function C() {
"use strict";
_class_call_check(this, C);
};
//// [/c.ts]
export * from "./b";
//// [/d.ts]
import { A, B, C } from "./c";
new A(), new B(), new C();
29 changes: 29 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace9.1.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//// [/a.ts]
export { };
//// [/b.ts]
export { };
//// [/c.ts]
//!
//! x the name `A` is defined multiple times
//! ,-[1:1]
//! 1 | import { A } from "./b";
//! : |
//! : `-- previous definition of `A` here
//! 2 | const A = 1;
//! : |
//! : `-- `A` redefined here
//! 3 | export { A };
//! 4 |
//! `----
//// [/d.ts]
import { A } from "./c";
A; // Ok
//// [/e.ts]
export var A = 1;
//// [/f.ts]
export * from "./e";
// Collision error
//// [/g.ts]
import { A } from "./f";
A;
// Follow-on from collision error
25 changes: 25 additions & 0 deletions crates/swc/tests/tsc-references/exportNamespace9.2.minified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [/a.ts]
export { };
//// [/b.ts]
export { };
//// [/c.ts]
//!
//! x the name `A` is defined multiple times
//! ,-[1:1]
//! 1 | import { A } from "./b";
//! : |
//! : `-- previous definition of `A` here
//! 2 | const A = 1;
//! : |
//! : `-- `A` redefined here
//! 3 | export { A };
//! 4 |
//! `----
//// [/d.ts]
import { A } from "./c";
//// [/e.ts]
export var A = 1;
//// [/f.ts]
export * from "./e";
//// [/g.ts]
import { A } from "./f";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//// [exportSpecifiers_js.ts]
//// [./a.js]
var foo = 0;
export { };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//// [exportSpecifiers_js.ts]
//// [./a.js]
export { };
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
//// [namedTupleMembersErrors.ts]
//!
//! x Only named exports may use 'export type'.
//! ,-[12:1]
//! 12 |
//! 13 | export type Trailing = [first: string, rest: ...string[]]; // dots on element disallowed
//! 14 |
//! 15 | export type OptTrailing = [first: string, rest: ...string[]?]; // dots+question on element disallowed
//! : ^^^^^^^^^^^
//! 16 |
//! 17 | export type OptRest = [first: string, ...rest?: string[]]; // rest+optional disallowed
//! `----
//!
//! x Expected '{', got 'OptTrailing'
//! ,-[12:1]
//! 12 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
//// [namedTupleMembersErrors.ts]
//!
//! x Only named exports may use 'export type'.
//! ,-[12:1]
//! 12 |
//! 13 | export type Trailing = [first: string, rest: ...string[]]; // dots on element disallowed
//! 14 |
//! 15 | export type OptTrailing = [first: string, rest: ...string[]?]; // dots+question on element disallowed
//! : ^^^^^^^^^^^
//! 16 |
//! 17 | export type OptRest = [first: string, ...rest?: string[]]; // rest+optional disallowed
//! `----
//!
//! x Expected '{', got 'OptTrailing'
//! ,-[12:1]
//! 12 |
Expand Down
Loading