@babel/plugin-transform-typescript
Advanced tools
Comparing version
@@ -242,3 +242,3 @@ "use strict"; | ||
value = computeConstantValue(bindingInitPath, undefined, seen); | ||
prevMembers == null ? void 0 : prevMembers.set(name, value); | ||
prevMembers == null || prevMembers.set(name, value); | ||
return value; | ||
@@ -245,0 +245,0 @@ } |
@@ -12,2 +12,3 @@ "use strict"; | ||
var _enum = require("./enum.js"); | ||
var _globalTypes = require("./global-types.js"); | ||
var _namespace = require("./namespace.js"); | ||
@@ -28,16 +29,4 @@ function isInType(path) { | ||
} | ||
const GLOBAL_TYPES = new WeakMap(); | ||
const NEEDS_EXPLICIT_ESM = new WeakMap(); | ||
const PARSED_PARAMS = new WeakSet(); | ||
function isGlobalType({ | ||
scope | ||
}, name) { | ||
if (scope.hasBinding(name)) return false; | ||
if (GLOBAL_TYPES.get(scope).has(name)) return true; | ||
console.warn(`The exported identifier "${name}" is not declared in Babel's scope tracker\n` + `as a JavaScript value binding, and "@babel/plugin-transform-typescript"\n` + `never encountered it as a TypeScript type declaration.\n` + `It will be treated as a JavaScript value.\n\n` + `This problem is likely caused by another plugin injecting\n` + `"${name}" without registering it in the scope tracker. If you are the author\n` + ` of that plugin, please use "scope.registerDeclaration(declarationPath)".`); | ||
return false; | ||
} | ||
function registerGlobalType(programScope, name) { | ||
GLOBAL_TYPES.get(programScope).add(name); | ||
} | ||
function safeRemove(path) { | ||
@@ -60,3 +49,3 @@ const ids = path.getBindingIdentifiers(); | ||
} | ||
var _default = (0, _helperPluginUtils.declare)((api, opts) => { | ||
var _default = exports.default = (0, _helperPluginUtils.declare)((api, opts) => { | ||
const { | ||
@@ -174,4 +163,4 @@ types: t, | ||
const programScope = path.scope; | ||
if (!GLOBAL_TYPES.has(programScope)) { | ||
GLOBAL_TYPES.set(programScope, new Set()); | ||
if (!_globalTypes.GLOBAL_TYPES.has(programScope)) { | ||
_globalTypes.GLOBAL_TYPES.set(programScope, new Set()); | ||
} | ||
@@ -205,3 +194,3 @@ if (file.ast.comments) { | ||
for (const specifier of stmt.node.specifiers) { | ||
registerGlobalType(programScope, specifier.local.name); | ||
(0, _globalTypes.registerGlobalType)(programScope, specifier.local.name); | ||
} | ||
@@ -216,3 +205,3 @@ stmt.remove(); | ||
if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") { | ||
registerGlobalType(programScope, specifier.local.name); | ||
(0, _globalTypes.registerGlobalType)(programScope, specifier.local.name); | ||
const binding = stmt.scope.getBinding(specifier.local.name); | ||
@@ -263,3 +252,3 @@ if (binding) { | ||
for (const name of Object.keys(stmt.getBindingIdentifiers())) { | ||
registerGlobalType(programScope, name); | ||
(0, _globalTypes.registerGlobalType)(programScope, name); | ||
} | ||
@@ -273,3 +262,3 @@ } else if (stmt.isTSTypeAliasDeclaration() || stmt.isTSDeclareFunction() && stmt.get("id").isIdentifier() || stmt.isTSInterfaceDeclaration() || stmt.isClassDeclaration({ | ||
}) && stmt.get("id").isIdentifier()) { | ||
registerGlobalType(programScope, stmt.node.id.name); | ||
(0, _globalTypes.registerGlobalType)(programScope, stmt.node.id.name); | ||
} | ||
@@ -296,3 +285,3 @@ } | ||
} | ||
if (!path.node.source && path.node.specifiers.length > 0 && path.node.specifiers.every(specifier => t.isExportSpecifier(specifier) && isGlobalType(path, specifier.local.name))) { | ||
if (!path.node.source && path.node.specifiers.length > 0 && path.node.specifiers.every(specifier => t.isExportSpecifier(specifier) && (0, _globalTypes.isGlobalType)(path, specifier.local.name))) { | ||
path.remove(); | ||
@@ -322,3 +311,3 @@ return; | ||
const parent = path.parent; | ||
if (!parent.source && isGlobalType(path, path.node.local.name) || path.node.exportKind === "type") { | ||
if (!parent.source && (0, _globalTypes.isGlobalType)(path, path.node.local.name) || path.node.exportKind === "type") { | ||
path.remove(); | ||
@@ -331,3 +320,3 @@ } | ||
} | ||
if (t.isIdentifier(path.node.declaration) && isGlobalType(path, path.node.declaration.name)) { | ||
if (t.isIdentifier(path.node.declaration) && (0, _globalTypes.isGlobalType)(path, path.node.declaration.name)) { | ||
path.remove(); | ||
@@ -504,4 +493,3 @@ return; | ||
}); | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
@@ -8,2 +8,3 @@ "use strict"; | ||
var _core = require("@babel/core"); | ||
var _globalTypes = require("./global-types.js"); | ||
function transpileNamespace(path, allowNamespaces) { | ||
@@ -20,2 +21,4 @@ if (path.node.declare || path.node.id.type === "StringLiteral") { | ||
if (value === null) { | ||
const program = path.findParent(p => p.isProgram()); | ||
(0, _globalTypes.registerGlobalType)(program.scope, name); | ||
path.remove(); | ||
@@ -22,0 +25,0 @@ } else if (path.scope.hasOwnBinding(name)) { |
{ | ||
"name": "@babel/plugin-transform-typescript", | ||
"version": "7.22.15", | ||
"version": "7.23.3", | ||
"description": "Transform TypeScript into ES.next", | ||
@@ -23,3 +23,3 @@ "repository": { | ||
"@babel/helper-plugin-utils": "^7.22.5", | ||
"@babel/plugin-syntax-typescript": "^7.22.5" | ||
"@babel/plugin-syntax-typescript": "^7.23.3" | ||
}, | ||
@@ -30,6 +30,6 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.22.15", | ||
"@babel/core": "^7.23.3", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
"@babel/traverse": "^7.22.15", | ||
"@babel/types": "^7.22.15" | ||
"@babel/traverse": "^7.23.3", | ||
"@babel/types": "^7.23.3" | ||
}, | ||
@@ -36,0 +36,0 @@ "homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-typescript", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
132066
1.36%13
18.18%1022
1.09%1
-50%