Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-typescript

Package Overview
Dependencies
61
Maintainers
4
Versions
123
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.21.4-esm.4 to 7.22.0

12

lib/const-enum.js

@@ -1,3 +0,9 @@

import { translateEnumValues } from "./enum.js";
export default function transpileConstEnum(path, t) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = transpileConstEnum;
var _enum = require("./enum");
function transpileConstEnum(path, t) {
const {

@@ -13,3 +19,3 @@ name

enumValues: entries
} = translateEnumValues(path, t);
} = (0, _enum.translateEnumValues)(path, t);
if (isExported) {

@@ -16,0 +22,0 @@ const obj = t.objectExpression(entries.map(([name, value]) => t.objectProperty(t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name), value)));

@@ -1,6 +0,13 @@

import { template, types as t } from "@babel/core";
import assert from "assert";
import annotateAsPure from "@babel/helper-annotate-as-pure";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = transpileEnum;
exports.translateEnumValues = translateEnumValues;
var _core = require("@babel/core");
var _assert = require("assert");
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
const ENUMS = new WeakMap();
const buildEnumWrapper = template.expression(`
const buildEnumWrapper = _core.template.expression(`
(function (ID) {

@@ -11,3 +18,3 @@ ASSIGNMENTS;

`);
export default function transpileEnum(path, t) {
function transpileEnum(path, t) {
const {

@@ -41,3 +48,3 @@ node,

}));
if (isPure) annotateAsPure(enumIIFE);
if (isPure) (0, _helperAnnotateAsPure.default)(enumIIFE);
if (isSeen) {

@@ -67,6 +74,6 @@ const toReplace = parentPath.isExportDeclaration() ? parentPath : path;

}
const buildStringAssignment = template(`
const buildStringAssignment = (0, _core.template)(`
ENUM["NAME"] = VALUE;
`);
const buildNumericAssignment = template(`
const buildNumericAssignment = (0, _core.template)(`
ENUM[ENUM["NAME"] = VALUE] = "NAME";

@@ -110,3 +117,3 @@ `);

};
export function translateEnumValues(path, t) {
function translateEnumValues(path, t) {
const seen = new Map();

@@ -129,3 +136,3 @@ let constValue = -1;

} else {
assert(typeof constValue === "string");
_assert(typeof constValue === "string");
value = t.stringLiteral(constValue);

@@ -217,3 +224,3 @@ }

const prop = expr.property;
if (!t.isIdentifier(obj) || (expr.computed ? !t.isStringLiteral(prop) : !t.isIdentifier(prop))) {
if (!_core.types.isIdentifier(obj) || (expr.computed ? !_core.types.isStringLiteral(prop) : !_core.types.isIdentifier(prop))) {
return;

@@ -220,0 +227,0 @@ }

@@ -1,7 +0,13 @@

import { declare } from "@babel/helper-plugin-utils";
import syntaxTypeScript from "@babel/plugin-syntax-typescript";
import { injectInitialization } from "@babel/helper-create-class-features-plugin";
import transpileConstEnum from "./const-enum.js";
import transpileEnum from "./enum.js";
import transpileNamespace from "./namespace.js";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _pluginSyntaxTypescript = require("@babel/plugin-syntax-typescript");
var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin");
var _constEnum = require("./const-enum");
var _enum = require("./enum");
var _namespace = require("./namespace");
function isInType(path) {

@@ -47,3 +53,8 @@ switch (path.parent.type) {

}
export default declare((api, opts) => {
function assertCjsTransformEnabled(path, pass, wrong, suggestion, extra = "") {
if (pass.file.get("@babel/plugin-transform-modules-*") !== "commonjs") {
throw path.buildCodeFrameError(`\`${wrong}\` is only supported when compiling modules to CommonJS.\n` + `Please consider using \`${suggestion}\`${extra}, or add ` + `@babel/plugin-transform-modules-commonjs to your Babel config.`);
}
}
var _default = (0, _helperPluginUtils.declare)((api, opts) => {
const {

@@ -143,3 +154,3 @@ types: t,

}
injectInitialization(classPath, path, assigns);
(0, _helperCreateClassFeaturesPlugin.injectInitialization)(classPath, path, assigns);
}

@@ -149,3 +160,3 @@ };

name: "transform-typescript",
inherits: syntaxTypeScript,
inherits: _pluginSyntaxTypescript.default,
visitor: {

@@ -366,3 +377,3 @@ Pattern: visitPattern,

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

@@ -377,16 +388,28 @@ TSInterfaceDeclaration(path) {

if (optimizeConstEnums && path.node.const) {
transpileConstEnum(path, t);
(0, _constEnum.default)(path, t);
} else {
transpileEnum(path, t);
(0, _enum.default)(path, t);
}
},
TSImportEqualsDeclaration(path) {
if (t.isTSExternalModuleReference(path.node.moduleReference)) {
throw path.buildCodeFrameError(`\`import ${path.node.id.name} = require('${path.node.moduleReference.expression.value}')\` ` + "is not supported by @babel/plugin-transform-typescript\n" + "Please consider using " + `\`import ${path.node.id.name} from '${path.node.moduleReference.expression.value}';\` alongside ` + "Typescript's --allowSyntheticDefaultImports option.");
TSImportEqualsDeclaration(path, pass) {
const {
id,
moduleReference
} = path.node;
let init;
let varKind;
if (t.isTSExternalModuleReference(moduleReference)) {
assertCjsTransformEnabled(path, pass, `import ${id.name} = require(...);`, `import ${id.name} from '...';`, " alongside Typescript's --allowSyntheticDefaultImports option");
init = t.callExpression(t.identifier("require"), [moduleReference.expression]);
varKind = "const";
} else {
init = entityNameToExpr(moduleReference);
varKind = "var";
}
path.replaceWith(t.variableDeclaration("var", [t.variableDeclarator(path.node.id, entityNameToExpr(path.node.moduleReference))]));
path.replaceWith(t.variableDeclaration(varKind, [t.variableDeclarator(id, init)]));
path.scope.registerDeclaration(path);
},
TSExportAssignment(path) {
throw path.buildCodeFrameError("`export =` is not supported by @babel/plugin-transform-typescript\n" + "Please consider using `export <value>;`.");
TSExportAssignment(path, pass) {
assertCjsTransformEnabled(path, pass, `export = <value>;`, `export default <value>;`);
path.replaceWith(template.statement.ast`module.exports = ${path.node.expression}`);
},

@@ -461,3 +484,4 @@ TSTypeAssertion(path) {

});
exports.default = _default;
//# sourceMappingURL=index.js.map

@@ -1,3 +0,9 @@

import { template, types as t } from "@babel/core";
export default function transpileNamespace(path, allowNamespaces) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = transpileNamespace;
var _core = require("@babel/core");
function transpileNamespace(path, allowNamespaces) {
if (path.node.declare || path.node.id.type === "StringLiteral") {

@@ -11,3 +17,3 @@ path.remove();

const name = path.node.id.name;
const value = handleNested(path, t.cloneNode(path.node, true));
const value = handleNested(path, _core.types.cloneNode(path.node, true));
const bound = path.scope.hasOwnBinding(name);

@@ -29,6 +35,6 @@ if (path.parent.type === "ExportNamedDeclaration") {

function getDeclaration(name) {
return t.variableDeclaration("let", [t.variableDeclarator(t.identifier(name))]);
return _core.types.variableDeclaration("let", [_core.types.variableDeclarator(_core.types.identifier(name))]);
}
function getMemberExpression(name, itemName) {
return t.memberExpression(t.identifier(name), t.identifier(itemName));
return _core.types.memberExpression(_core.types.identifier(name), _core.types.identifier(itemName));
}

@@ -42,14 +48,14 @@ function handleVariableDeclaration(node, name, hub) {

} = node;
if (declarations.every(declarator => t.isIdentifier(declarator.id))) {
if (declarations.every(declarator => _core.types.isIdentifier(declarator.id))) {
for (const declarator of declarations) {
declarator.init = t.assignmentExpression("=", getMemberExpression(name, declarator.id.name), declarator.init);
declarator.init = _core.types.assignmentExpression("=", getMemberExpression(name, declarator.id.name), declarator.init);
}
return [node];
}
const bindingIdentifiers = t.getBindingIdentifiers(node);
const bindingIdentifiers = _core.types.getBindingIdentifiers(node);
const assignments = [];
for (const idName in bindingIdentifiers) {
assignments.push(t.assignmentExpression("=", getMemberExpression(name, idName), t.cloneNode(bindingIdentifiers[idName])));
assignments.push(_core.types.assignmentExpression("=", getMemberExpression(name, idName), _core.types.cloneNode(bindingIdentifiers[idName])));
}
return [node, t.expressionStatement(t.sequenceExpression(assignments))];
return [node, _core.types.expressionStatement(_core.types.sequenceExpression(assignments))];
}

@@ -62,5 +68,5 @@ function buildNestedAmbientModuleError(path, node) {

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)];
for (let i = 0; i < namespaceTopLevel.length; i++) {

@@ -71,3 +77,3 @@ const subNode = namespaceTopLevel[i];

{
if (!t.isIdentifier(subNode.id)) {
if (!_core.types.isIdentifier(subNode.id)) {
throw buildNestedAmbientModuleError(path, subNode);

@@ -92,3 +98,3 @@ }

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

@@ -112,3 +118,3 @@ }

names.add(itemName);
namespaceTopLevel.splice(i++, 1, subNode.declaration, t.expressionStatement(t.assignmentExpression("=", getMemberExpression(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;

@@ -125,6 +131,6 @@ }

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

@@ -140,14 +146,14 @@ if (names.has(moduleName)) {

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

@@ -154,0 +160,0 @@ }

@@ -1,1 +0,1 @@

{ "type": "module" }
{ "type": "script" }
{
"name": "@babel/plugin-transform-typescript",
"version": "7.21.4-esm.4",
"version": "7.22.0",
"description": "Transform TypeScript into ES.next",

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

"dependencies": {
"@babel/helper-annotate-as-pure": "7.21.4-esm.4",
"@babel/helper-create-class-features-plugin": "7.21.4-esm.4",
"@babel/helper-plugin-utils": "7.21.4-esm.4",
"@babel/plugin-syntax-typescript": "7.21.4-esm.4"
"@babel/helper-annotate-as-pure": "^7.18.6",
"@babel/helper-create-class-features-plugin": "^7.22.0",
"@babel/helper-plugin-utils": "^7.21.5",
"@babel/plugin-syntax-typescript": "^7.21.4"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0 || ^7.21.4-esm.2"
"@babel/core": "^7.0.0-0"
},
"devDependencies": {
"@babel/core": "7.21.4-esm.4",
"@babel/helper-plugin-test-runner": "7.21.4-esm.4",
"@babel/traverse": "7.21.4-esm.4",
"@babel/types": "7.21.4-esm.4"
"@babel/core": "^7.22.0",
"@babel/helper-plugin-test-runner": "^7.18.6",
"@babel/traverse": "^7.22.0",
"@babel/types": "^7.22.0"
},

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

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc