Skip to content

Commit

Permalink
Implement "export type {}" (#11122)
Browse files Browse the repository at this point in the history
* [typescript] Implement "export type {}"

* test: add test on default-type-with-typescript

Co-authored-by: Hu谩ng J霉nli脿ng <jlhwung@gmail.com>
  • Loading branch information
nicolo-ribaudo and JLHwung committed Feb 26, 2020
1 parent ed2af92 commit e9ba981
Show file tree
Hide file tree
Showing 41 changed files with 388 additions and 4 deletions.
@@ -0,0 +1,3 @@
type A = 2;
export type { A };
export type { B } from "./mod";
@@ -0,0 +1,3 @@
type A = 2;
export type { A };
export type { B } from "./mod";
7 changes: 7 additions & 0 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1885,6 +1885,13 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.semicolon();
return this.finishNode(decl, "TSNamespaceExportDeclaration");
} else {
if (this.isContextual("type") && this.lookahead().type === tt.braceL) {
this.next();
node.exportKind = "type";
} else {
node.exportKind = "value";
}

return super.parseExport(node);
}
}
Expand Down
@@ -0,0 +1 @@
export type from 'test';
@@ -0,0 +1,5 @@
{
"plugins": ["exportDefaultFrom", "typescript"],
"sourceType": "module",
"throws": "Unexpected token, expected \"=\" (1:17)"
}
Expand Up @@ -43,6 +43,7 @@
"column": 26
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -110,6 +111,7 @@
"column": 29
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -176,6 +178,7 @@
"column": 16
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -226,6 +229,7 @@
"column": 21
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -291,6 +295,7 @@
"column": 18
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -356,6 +361,7 @@
"column": 21
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -421,6 +427,7 @@
"column": 27
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
Expand Up @@ -43,6 +43,7 @@
"column": 24
}
},
"exportKind": "value",
"declaration": {
"type": "Identifier",
"start": 78,
Expand Down
Expand Up @@ -144,6 +144,7 @@
"column": 27
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -229,6 +230,7 @@
"column": 33
}
},
"exportKind": "value",
"declaration": {
"type": "ClassDeclaration",
"start": 148,
Expand Down Expand Up @@ -296,6 +298,7 @@
"column": 36
}
},
"exportKind": "value",
"declaration": {
"type": "ClassDeclaration",
"start": 182,
Expand Down
Expand Up @@ -43,6 +43,7 @@
"column": 22
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
Expand Up @@ -43,6 +43,7 @@
"column": 30
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
Expand Up @@ -43,6 +43,7 @@
"column": 16
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
Expand Up @@ -43,6 +43,7 @@
"column": 31
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -142,6 +143,7 @@
"column": 34
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -225,6 +227,7 @@
"column": 25
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -292,6 +295,7 @@
"column": 29
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -358,6 +362,7 @@
"column": 31
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -423,6 +428,7 @@
"column": 26
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -489,6 +495,7 @@
"column": 29
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down Expand Up @@ -555,6 +562,7 @@
"column": 26
}
},
"exportKind": "value",
"specifiers": [],
"source": null,
"declaration": {
Expand Down
@@ -0,0 +1 @@
export type { T } from './mod';
@@ -0,0 +1,123 @@
{
"type": "File",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"program": {
"type": "Program",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start": 0,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 31
}
},
"exportKind": "type",
"specifiers": [
{
"type": "ExportSpecifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
}
},
"local": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "T"
},
"name": "T"
},
"exported": {
"type": "Identifier",
"start": 14,
"end": 15,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
},
"identifierName": "T"
},
"name": "T"
}
}
],
"source": {
"type": "StringLiteral",
"start": 23,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 23
},
"end": {
"line": 1,
"column": 30
}
},
"extra": {
"rawValue": "./mod",
"raw": "'./mod'"
},
"value": "./mod"
},
"declaration": null
}
],
"directives": []
}
}
@@ -0,0 +1,2 @@
type A = 2;
export type { A };

0 comments on commit e9ba981

Please sign in to comment.