@babel/plugin-transform-typescript
Advanced tools
Comparing version 7.4.5 to 7.5.0
@@ -58,3 +58,3 @@ "use strict"; | ||
const isGlobal = t.isProgram(path.parent); | ||
path.replaceWith(makeVar(node.id, t, isGlobal ? "var" : "let")); | ||
path.scope.registerDeclaration(path.replaceWith(makeVar(node.id, t, isGlobal ? "var" : "let"))[0]); | ||
} | ||
@@ -61,0 +61,0 @@ |
@@ -38,4 +38,16 @@ "use strict"; | ||
function _helperCreateClassFeaturesPlugin() { | ||
const data = require("@babel/helper-create-class-features-plugin"); | ||
_helperCreateClassFeaturesPlugin = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _enum = _interopRequireDefault(require("./enum")); | ||
var _namespace = _interopRequireDefault(require("./namespace")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -56,11 +68,7 @@ | ||
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(); | ||
const PRAGMA_KEY = "@babel/plugin-transform-typescript/jsxPragma"; | ||
var _default = (0, _helperPluginUtils().declare)((api, { | ||
jsxPragma = "React" | ||
jsxPragma = "React", | ||
allowNamespaces = false | ||
}) => { | ||
@@ -78,7 +86,6 @@ api.assertVersion(7); | ||
Program(path, state) { | ||
state.programPath = path; | ||
state.exportableTSNames = new Set(); | ||
const { | ||
file | ||
} = state; | ||
let fileJsxPragma = null; | ||
@@ -90,3 +97,3 @@ if (file.ast.comments) { | ||
if (jsxMatches) { | ||
file.set(PRAGMA_KEY, jsxMatches[1]); | ||
fileJsxPragma = jsxMatches[1]; | ||
} | ||
@@ -97,18 +104,2 @@ } | ||
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)) { | ||
@@ -125,3 +116,7 @@ if (stmt.node.specifiers.length === 0) { | ||
if (binding && isImportTypeOnly(file, binding, state.programPath)) { | ||
if (binding && isImportTypeOnly({ | ||
binding, | ||
programPath: path, | ||
jsxPragma: fileJsxPragma || jsxPragma | ||
})) { | ||
importsToRemove.push(binding.path); | ||
@@ -144,6 +139,4 @@ } else { | ||
ExportNamedDeclaration(path, { | ||
exportableTSNames | ||
}) { | ||
if (path.node.specifiers.length > 0 && !path.node.specifiers.find(exportSpecifier => !exportableTSNames.has(exportSpecifier.local.name))) { | ||
ExportNamedDeclaration(path) { | ||
if (path.node.specifiers.length > 0 && !path.node.specifiers.find(exportSpecifier => path.scope.hasOwnBinding(exportSpecifier.local.name))) { | ||
path.remove(); | ||
@@ -153,6 +146,4 @@ } | ||
ExportSpecifier(path, { | ||
exportableTSNames | ||
}) { | ||
if (exportableTSNames.has(path.node.local.name)) { | ||
ExportSpecifier(path) { | ||
if (!path.scope.hasOwnBinding(path.node.local.name)) { | ||
path.remove(); | ||
@@ -162,2 +153,8 @@ } | ||
ExportDefaultDeclaration(path) { | ||
if (_core().types.isIdentifier(path.node.declaration) && !path.scope.hasOwnBinding(path.node.declaration.name)) { | ||
path.remove(); | ||
} | ||
}, | ||
TSDeclareFunction(path) { | ||
@@ -242,8 +239,8 @@ path.remove(); | ||
const assigns = parameterProperties.map(p => { | ||
let name; | ||
let id; | ||
if (_core().types.isIdentifier(p)) { | ||
name = p.name; | ||
id = p; | ||
} else if (_core().types.isAssignmentPattern(p) && _core().types.isIdentifier(p.left)) { | ||
name = p.left.name; | ||
id = p.left; | ||
} else { | ||
@@ -253,12 +250,5 @@ throw path.buildCodeFrameError("Parameter properties can not be destructuring patterns."); | ||
const assign = _core().types.assignmentExpression("=", _core().types.memberExpression(_core().types.thisExpression(), _core().types.identifier(name)), _core().types.identifier(name)); | ||
return _core().types.expressionStatement(assign); | ||
return _core().template.statement.ast`this.${id} = ${id}`; | ||
}); | ||
const statements = childNode.body.body; | ||
const first = statements[0]; | ||
const startsWithSuperCall = first !== undefined && _core().types.isExpressionStatement(first) && _core().types.isCallExpression(first.expression) && _core().types.isSuper(first.expression.callee); | ||
childNode.body.body = startsWithSuperCall ? [first, ...assigns, ...statements.slice(1)] : [...assigns, ...statements]; | ||
(0, _helperCreateClassFeaturesPlugin().injectInitialization)(path, child, assigns); | ||
} | ||
@@ -292,7 +282,3 @@ } else if (child.isClassProperty()) { | ||
TSModuleDeclaration(path) { | ||
if (!path.node.declare && path.node.id.type !== "StringLiteral") { | ||
throw path.buildCodeFrameError("Namespaces are not supported."); | ||
} | ||
path.remove(); | ||
(0, _namespace.default)(path, _core().types, allowNamespaces); | ||
}, | ||
@@ -366,3 +352,7 @@ | ||
function isImportTypeOnly(file, binding, programPath) { | ||
function isImportTypeOnly({ | ||
binding, | ||
programPath, | ||
jsxPragma | ||
}) { | ||
for (const path of binding.referencePaths) { | ||
@@ -374,5 +364,3 @@ if (!isInType(path)) { | ||
const fileJsxPragma = file.get(PRAGMA_KEY) || jsxPragma; | ||
if (binding.identifier.name !== fileJsxPragma) { | ||
if (binding.identifier.name !== jsxPragma) { | ||
return true; | ||
@@ -379,0 +367,0 @@ } |
{ | ||
"name": "@babel/plugin-transform-typescript", | ||
"version": "7.4.5", | ||
"version": "7.5.0", | ||
"description": "Transform TypeScript into ES.next", | ||
@@ -16,2 +16,3 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-typescript", | ||
"dependencies": { | ||
"@babel/helper-create-class-features-plugin": "^7.5.0", | ||
"@babel/helper-plugin-utils": "^7.0.0", | ||
@@ -24,6 +25,6 @@ "@babel/plugin-syntax-typescript": "^7.2.0" | ||
"devDependencies": { | ||
"@babel/core": "^7.4.5", | ||
"@babel/core": "^7.5.0", | ||
"@babel/helper-plugin-test-runner": "^7.0.0" | ||
}, | ||
"gitHead": "33ab4f166117e2380de3955a0842985f578b01b8" | ||
"gitHead": "49da9a07c81156e997e60146eb001ea77b7044c4" | ||
} |
21552
6
618
4
1
+ Added@babel/helper-annotate-as-pure@7.24.7(transitive)
+ Added@babel/helper-create-class-features-plugin@7.24.7(transitive)
+ Added@babel/helper-member-expression-to-functions@7.24.7(transitive)
+ Added@babel/helper-optimise-call-expression@7.24.7(transitive)
+ Added@babel/helper-replace-supers@7.24.7(transitive)
+ Added@babel/helper-skip-transparent-expression-wrappers@7.24.7(transitive)