🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@babel/plugin-transform-typescript

Package Overview
Dependencies
Maintainers
4
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-typescript - npm Package Compare versions

Comparing version

to
7.18.6

2

lib/index.js

@@ -418,3 +418,3 @@ "use strict";

TSModuleDeclaration(path) {
(0, _namespace.default)(path, _core.types, allowNamespaces);
(0, _namespace.default)(path, allowNamespaces);
},

@@ -421,0 +421,0 @@

@@ -10,3 +10,3 @@ "use strict";

function transpileNamespace(path, t, allowNamespaces) {
function transpileNamespace(path, allowNamespaces) {
if (path.node.declare || path.node.id.type === "StringLiteral") {

@@ -18,7 +18,7 @@ path.remove();

if (!allowNamespaces) {
throw path.hub.file.buildCodeFrameError(path.node.id, "Namespace not marked type-only declare." + " Non-declarative namespaces are only supported experimentally in Babel." + " To enable and review caveats see:" + " https://babeljs.io/docs/en/babel-plugin-transform-typescript");
throw path.get("id").buildCodeFrameError("Namespace not marked type-only declare." + " Non-declarative namespaces are only supported experimentally in Babel." + " To enable and review caveats see:" + " https://babeljs.io/docs/en/babel-plugin-transform-typescript");
}
const name = path.node.id.name;
const value = handleNested(path, t, t.cloneDeep(path.node));
const value = handleNested(path, _core.types.cloneNode(path.node, true));
const bound = path.scope.hasOwnBinding(name);

@@ -29,3 +29,3 @@

path.parentPath.insertAfter(value);
path.replaceWith(getDeclaration(t, name));
path.replaceWith(getDeclaration(name));
path.scope.registerDeclaration(path.parentPath);

@@ -38,12 +38,12 @@ } else {

} else {
path.scope.registerDeclaration(path.replaceWithMultiple([getDeclaration(t, name), value])[0]);
path.scope.registerDeclaration(path.replaceWithMultiple([getDeclaration(name), value])[0]);
}
}
function getDeclaration(t, name) {
return t.variableDeclaration("let", [t.variableDeclarator(t.identifier(name))]);
function getDeclaration(name) {
return _core.types.variableDeclaration("let", [_core.types.variableDeclarator(_core.types.identifier(name))]);
}
function getMemberExpression(t, name, itemName) {
return t.memberExpression(t.identifier(name), t.identifier(itemName));
function getMemberExpression(name, itemName) {
return _core.types.memberExpression(_core.types.identifier(name), _core.types.identifier(itemName));
}

@@ -62,3 +62,3 @@

for (const declarator of declarations) {
declarator.init = _core.types.assignmentExpression("=", getMemberExpression(_core.types, name, declarator.id.name), declarator.init);
declarator.init = _core.types.assignmentExpression("=", getMemberExpression(name, declarator.id.name), declarator.init);
}

@@ -74,3 +74,3 @@

for (const idName in bindingIdentifiers) {
assignments.push(_core.types.assignmentExpression("=", getMemberExpression(_core.types, name, idName), _core.types.cloneNode(bindingIdentifiers[idName])));
assignments.push(_core.types.assignmentExpression("=", getMemberExpression(name, idName), _core.types.cloneNode(bindingIdentifiers[idName])));
}

@@ -85,8 +85,10 @@

function handleNested(path, t, node, parentExport) {
function handleNested(path, node, parentExport) {
const names = new Set();
const realName = node.id;
t.assertIdentifier(realName);
_core.types.assertIdentifier(realName);
const name = path.scope.generateUid(realName.name);
const namespaceTopLevel = t.isTSModuleBlock(node.body) ? node.body.body : [t.exportNamedDeclaration(node.body)];
const namespaceTopLevel = _core.types.isTSModuleBlock(node.body) ? node.body.body : [_core.types.exportNamedDeclaration(node.body)];

@@ -99,7 +101,7 @@ for (let i = 0; i < namespaceTopLevel.length; i++) {

{
if (!t.isIdentifier(subNode.id)) {
if (!_core.types.isIdentifier(subNode.id)) {
throw buildNestedAmbiendModuleError(path, subNode);
}
const transformed = handleNested(path, t, subNode);
const transformed = handleNested(path, subNode);
const moduleName = subNode.id.name;

@@ -111,3 +113,3 @@

names.add(moduleName);
namespaceTopLevel.splice(i++, 1, getDeclaration(t, moduleName), transformed);
namespaceTopLevel.splice(i++, 1, getDeclaration(moduleName), transformed);
}

@@ -126,3 +128,3 @@

{
for (const name in t.getBindingIdentifiers(subNode)) {
for (const name in _core.types.getBindingIdentifiers(subNode)) {
names.add(name);

@@ -147,3 +149,3 @@ }

names.add(itemName);
namespaceTopLevel.splice(i++, 1, subNode.declaration, t.expressionStatement(t.assignmentExpression("=", getMemberExpression(t, name, itemName), t.identifier(itemName))));
namespaceTopLevel.splice(i++, 1, subNode.declaration, _core.types.expressionStatement(_core.types.assignmentExpression("=", getMemberExpression(name, itemName), _core.types.identifier(itemName))));
break;

@@ -162,7 +164,7 @@ }

{
if (!t.isIdentifier(subNode.declaration.id)) {
if (!_core.types.isIdentifier(subNode.declaration.id)) {
throw buildNestedAmbiendModuleError(path, subNode.declaration);
}
const transformed = handleNested(path, t, subNode.declaration, t.identifier(name));
const transformed = handleNested(path, subNode.declaration, _core.types.identifier(name));
const moduleName = subNode.declaration.id.name;

@@ -174,3 +176,3 @@

names.add(moduleName);
namespaceTopLevel.splice(i++, 1, getDeclaration(t, moduleName), transformed);
namespaceTopLevel.splice(i++, 1, getDeclaration(moduleName), transformed);
}

@@ -181,9 +183,10 @@ }

let fallthroughValue = t.objectExpression([]);
let fallthroughValue = _core.types.objectExpression([]);
if (parentExport) {
const memberExpr = t.memberExpression(parentExport, realName);
const memberExpr = _core.types.memberExpression(parentExport, realName);
fallthroughValue = _core.template.expression.ast`
${t.cloneNode(memberExpr)} ||
(${t.cloneNode(memberExpr)} = ${fallthroughValue})
${_core.types.cloneNode(memberExpr)} ||
(${_core.types.cloneNode(memberExpr)} = ${fallthroughValue})
`;

@@ -193,6 +196,6 @@ }

return _core.template.statement.ast`
(function (${t.identifier(name)}) {
(function (${_core.types.identifier(name)}) {
${namespaceTopLevel}
})(${realName} || (${t.cloneNode(realName)} = ${fallthroughValue}));
})(${realName} || (${_core.types.cloneNode(realName)} = ${fallthroughValue}));
`;
}
{
"name": "@babel/plugin-transform-typescript",
"version": "7.18.4",
"version": "7.18.6",
"description": "Transform TypeScript into ES.next",

@@ -20,5 +20,5 @@ "repository": {

"dependencies": {
"@babel/helper-create-class-features-plugin": "^7.18.0",
"@babel/helper-plugin-utils": "^7.17.12",
"@babel/plugin-syntax-typescript": "^7.17.12"
"@babel/helper-create-class-features-plugin": "^7.18.6",
"@babel/helper-plugin-utils": "^7.18.6",
"@babel/plugin-syntax-typescript": "^7.18.6"
},

@@ -29,6 +29,6 @@ "peerDependencies": {

"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/helper-plugin-test-runner": "^7.16.7",
"@babel/traverse": "^7.18.2",
"@babel/types": "^7.18.4"
"@babel/core": "^7.18.6",
"@babel/helper-plugin-test-runner": "^7.18.6",
"@babel/traverse": "^7.18.6",
"@babel/types": "^7.18.6"
},

@@ -39,3 +39,4 @@ "homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-typescript",

},
"author": "The Babel Team (https://babel.dev/team)"
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
}