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

[ts] Support export type * from #15381

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,5 @@
export type * from './mod';
export type * as ns from './mod';
// Note: TSC doesn't support string module specifiers yet,
// but it's easier for us to support it that not.
nicolo-ribaudo marked this conversation as resolved.
Show resolved Hide resolved
export type * as "ns2" from './mod';
@@ -0,0 +1,5 @@
export type * from './mod';
export type * as ns from './mod';
// Note: TSC doesn't support string module specifiers yet,
// but it's easier for us to support it that not.
export type * as "ns2" from './mod';
16 changes: 8 additions & 8 deletions packages/babel-parser/src/plugins/typescript/index.ts
Expand Up @@ -2716,14 +2716,14 @@ export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
this.semicolon();
return this.finishNode(decl, "TSNamespaceExportDeclaration");
} else {
if (
this.isContextual(tt._type) &&
this.lookahead().type === tt.braceL
) {
this.next();
node.exportKind = "type";
} else {
node.exportKind = "value";
node.exportKind = "value";

if (this.isContextual(tt._type)) {
const ch = this.lookaheadCharCode();
if (ch === charCodes.leftCurlyBrace || ch === charCodes.asterisk) {
this.next();
node.exportKind = "type";
}
}

return super.parseExport(
Expand Down
@@ -0,0 +1,5 @@
export type * from './mod';
export type * as ns from './mod';
// Note: TSC doesn't support string module specifiers yet,
// but it's easier for us to support it that not.
export type * as "ns2" from './mod';
@@ -0,0 +1,117 @@
{
"type": "File",
"start":0,"end":207,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":36,"index":207}},
"program": {
"type": "Program",
"start":0,"end":207,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":5,"column":36,"index":207}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportAllDeclaration",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":27,"index":27}},
"exportKind": "type",
"source": {
"type": "StringLiteral",
"start":19,"end":26,"loc":{"start":{"line":1,"column":19,"index":19},"end":{"line":1,"column":26,"index":26}},
"extra": {
"rawValue": "./mod",
"raw": "'./mod'"
},
"value": "./mod"
}
},
{
"type": "ExportNamedDeclaration",
"start":28,"end":61,"loc":{"start":{"line":2,"column":0,"index":28},"end":{"line":2,"column":33,"index":61}},
"exportKind": "type",
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
"start":40,"end":47,"loc":{"start":{"line":2,"column":12,"index":40},"end":{"line":2,"column":19,"index":47}},
"exported": {
"type": "Identifier",
"start":45,"end":47,"loc":{"start":{"line":2,"column":17,"index":45},"end":{"line":2,"column":19,"index":47},"identifierName":"ns"},
"name": "ns"
}
}
],
"source": {
"type": "StringLiteral",
"start":53,"end":60,"loc":{"start":{"line":2,"column":25,"index":53},"end":{"line":2,"column":32,"index":60}},
"extra": {
"rawValue": "./mod",
"raw": "'./mod'"
},
"value": "./mod"
},
"trailingComments": [
{
"type": "CommentLine",
"value": " Note: TSC doesn't support string module specifiers yet,",
"start":62,"end":120,"loc":{"start":{"line":3,"column":0,"index":62},"end":{"line":3,"column":58,"index":120}}
},
{
"type": "CommentLine",
"value": " but it's easier for us to support it that not.",
"start":121,"end":170,"loc":{"start":{"line":4,"column":0,"index":121},"end":{"line":4,"column":49,"index":170}}
}
]
},
{
"type": "ExportNamedDeclaration",
"start":171,"end":207,"loc":{"start":{"line":5,"column":0,"index":171},"end":{"line":5,"column":36,"index":207}},
"exportKind": "type",
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
"start":183,"end":193,"loc":{"start":{"line":5,"column":12,"index":183},"end":{"line":5,"column":22,"index":193}},
"exported": {
"type": "StringLiteral",
"start":188,"end":193,"loc":{"start":{"line":5,"column":17,"index":188},"end":{"line":5,"column":22,"index":193}},
"extra": {
"rawValue": "ns2",
"raw": "\"ns2\""
},
"value": "ns2"
}
}
],
"source": {
"type": "StringLiteral",
"start":199,"end":206,"loc":{"start":{"line":5,"column":28,"index":199},"end":{"line":5,"column":35,"index":206}},
"extra": {
"rawValue": "./mod",
"raw": "'./mod'"
},
"value": "./mod"
},
"leadingComments": [
{
"type": "CommentLine",
"value": " Note: TSC doesn't support string module specifiers yet,",
"start":62,"end":120,"loc":{"start":{"line":3,"column":0,"index":62},"end":{"line":3,"column":58,"index":120}}
},
{
"type": "CommentLine",
"value": " but it's easier for us to support it that not.",
"start":121,"end":170,"loc":{"start":{"line":4,"column":0,"index":121},"end":{"line":4,"column":49,"index":170}}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentLine",
"value": " Note: TSC doesn't support string module specifiers yet,",
"start":62,"end":120,"loc":{"start":{"line":3,"column":0,"index":62},"end":{"line":3,"column":58,"index":120}}
},
{
"type": "CommentLine",
"value": " but it's easier for us to support it that not.",
"start":121,"end":170,"loc":{"start":{"line":4,"column":0,"index":121},"end":{"line":4,"column":49,"index":170}}
}
]
}
4 changes: 4 additions & 0 deletions packages/babel-plugin-transform-typescript/src/index.ts
Expand Up @@ -444,6 +444,10 @@ export default declare((api, opts: Options) => {
NEEDS_EXPLICIT_ESM.set(state.file.ast.program, false);
},

ExportAllDeclaration(path) {
if (path.node.exportKind === "type") path.remove();
},

ExportSpecifier(path) {
// remove type exports
type Parent = t.ExportDeclaration & { source?: t.StringLiteral };
Expand Down
@@ -0,0 +1,7 @@
export type * from './mod';
export type * as ns from './mod';
// Note: TSC doesn't support string module specifiers yet,
// but it's easier for us to support it that not.
export type * as "ns2" from './mod';

;
@@ -0,0 +1,5 @@
// Note: TSC doesn't support string module specifiers yet,
// but it's easier for us to support it that not.

;
export {};