@babel/plugin-transform-typescript
Advanced tools
Comparing version 7.4.4 to 7.4.5
@@ -55,2 +55,6 @@ "use strict"; | ||
function isTSExportableDeclaration(node) { | ||
return _core().types.isTSInterfaceDeclaration(node) || _core().types.isTSTypeAliasDeclaration(node) || _core().types.isTSModuleDeclaration(node) || _core().types.isVariableDeclaration(node) && node.declare || _core().types.isClassDeclaration(node) && node.declare || _core().types.isTSDeclareFunction(node); | ||
} | ||
const PARSED_PARAMS = new WeakSet(); | ||
@@ -74,2 +78,3 @@ const PRAGMA_KEY = "@babel/plugin-transform-typescript/jsxPragma"; | ||
state.programPath = path; | ||
state.exportableTSNames = new Set(); | ||
const { | ||
@@ -90,2 +95,18 @@ file | ||
for (const stmt of path.get("body")) { | ||
if (isTSExportableDeclaration(stmt.node)) { | ||
if (stmt.node.id && stmt.node.id.name) { | ||
state.exportableTSNames.add(stmt.node.id.name); | ||
} else if (stmt.node.declarations && stmt.node.declarations.length > 0) { | ||
for (const declaration of stmt.node.declarations) { | ||
if (declaration.id && declaration.id.name) { | ||
state.exportableTSNames.add(declaration.id.name); | ||
} | ||
} | ||
} | ||
} else if (_core().types.isExportNamedDeclaration(stmt.node) && stmt.node.specifiers.length === 0 && isTSExportableDeclaration(stmt.node.declaration) && stmt.node.declaration.id && stmt.node.declaration.id.name) { | ||
state.exportableTSNames.add(stmt.node.declaration.id.name); | ||
} | ||
} | ||
for (const stmt of path.get("body")) { | ||
if (_core().types.isImportDeclaration(stmt)) { | ||
@@ -120,2 +141,18 @@ if (stmt.node.specifiers.length === 0) { | ||
ExportNamedDeclaration(path, { | ||
exportableTSNames | ||
}) { | ||
if (path.node.specifiers.length > 0 && !path.node.specifiers.find(exportSpecifier => !exportableTSNames.has(exportSpecifier.local.name))) { | ||
path.remove(); | ||
} | ||
}, | ||
ExportSpecifier(path, { | ||
exportableTSNames | ||
}) { | ||
if (exportableTSNames.has(path.node.local.name)) { | ||
path.remove(); | ||
} | ||
}, | ||
TSDeclareFunction(path) { | ||
@@ -122,0 +159,0 @@ path.remove(); |
{ | ||
"name": "@babel/plugin-transform-typescript", | ||
"version": "7.4.4", | ||
"version": "7.4.5", | ||
"description": "Transform TypeScript into ES.next", | ||
@@ -23,6 +23,6 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-typescript", | ||
"devDependencies": { | ||
"@babel/core": "^7.4.4", | ||
"@babel/core": "^7.4.5", | ||
"@babel/helper-plugin-test-runner": "^7.0.0" | ||
}, | ||
"gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba" | ||
"gitHead": "33ab4f166117e2380de3955a0842985f578b01b8" | ||
} |
18345
507