Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-typescript

Package Overview
Dependencies
Maintainers
6
Versions
132
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 7.0.0-beta.43 to 7.0.0-beta.44

81

lib/enum.js

@@ -9,5 +9,5 @@ "use strict";

function _assert() {
const data = _interopRequireDefault(require("assert"));
var data = _interopRequireDefault(require("assert"));
_assert = function () {
_assert = function _assert() {
return data;

@@ -20,5 +20,5 @@ };

function _core() {
const data = require("@babel/core");
var data = require("@babel/core");
_core = function () {
_core = function _core() {
return data;

@@ -33,5 +33,3 @@ };

function transpileEnum(path, t) {
const {
node
} = path;
var node = path.node;

@@ -47,4 +45,4 @@ if (node.declare) {

const name = node.id.name;
const fill = enumFill(path, t, node.id);
var name = node.id.name;
var fill = enumFill(path, t, node.id);

@@ -61,3 +59,3 @@ switch (path.parent.type) {

} else {
const isGlobal = t.isProgram(path.parent);
var isGlobal = t.isProgram(path.parent);
path.replaceWith(makeVar(node.id, t, isGlobal ? "var" : "let"));

@@ -70,3 +68,3 @@ }

default:
throw new Error(`Unexpected enum parent '${path.parent.type}`);
throw new Error("Unexpected enum parent '" + path.parent.type);
}

@@ -92,23 +90,21 @@

const buildEnumWrapper = (0, _core().template)(`
(function (ID) {
ASSIGNMENTS;
})(ID || (ID = {}));
`);
const buildStringAssignment = (0, _core().template)(`
ENUM["NAME"] = VALUE;
`);
const buildNumericAssignment = (0, _core().template)(`
ENUM[ENUM["NAME"] = VALUE] = "NAME";
`);
var buildEnumWrapper = (0, _core().template)("\n (function (ID) {\n ASSIGNMENTS;\n })(ID || (ID = {}));\n");
var buildStringAssignment = (0, _core().template)("\n ENUM[\"NAME\"] = VALUE;\n");
var buildNumericAssignment = (0, _core().template)("\n ENUM[ENUM[\"NAME\"] = VALUE] = \"NAME\";\n");
const buildEnumMember = (isString, options) => (isString ? buildStringAssignment : buildNumericAssignment)(options);
var buildEnumMember = function buildEnumMember(isString, options) {
return (isString ? buildStringAssignment : buildNumericAssignment)(options);
};
function enumFill(path, t, id) {
const x = translateEnumValues(path, t);
const assignments = x.map(([memberName, memberValue]) => buildEnumMember(t.isStringLiteral(memberValue), {
ENUM: t.cloneNode(id),
NAME: memberName,
VALUE: memberValue
}));
var x = translateEnumValues(path, t);
var assignments = x.map(function (_ref) {
var memberName = _ref[0],
memberValue = _ref[1];
return buildEnumMember(t.isStringLiteral(memberValue), {
ENUM: t.cloneNode(id),
NAME: memberName,
VALUE: memberValue
});
});
return buildEnumWrapper({

@@ -121,11 +117,11 @@ ID: t.cloneNode(id),

function translateEnumValues(path, t) {
const seen = Object.create(null);
let prev = -1;
return path.node.members.map(member => {
const name = t.isIdentifier(member.id) ? member.id.name : member.id.value;
const initializer = member.initializer;
let value;
var seen = Object.create(null);
var prev = -1;
return path.node.members.map(function (member) {
var name = t.isIdentifier(member.id) ? member.id.name : member.id.value;
var initializer = member.initializer;
var value;
if (initializer) {
const constValue = evaluate(initializer, seen);
var constValue = evaluate(initializer, seen);

@@ -190,7 +186,6 @@ if (constValue !== undefined) {

function evalUnaryExpression({
argument,
operator
}) {
const value = evalConstant(argument);
function evalUnaryExpression(_ref2) {
var argument = _ref2.argument,
operator = _ref2.operator;
var value = evalConstant(argument);

@@ -217,3 +212,3 @@ if (value === undefined) {

function evalBinaryExpression(expr) {
const left = evalConstant(expr.left);
var left = evalConstant(expr.left);

@@ -224,3 +219,3 @@ if (left === undefined) {

const right = evalConstant(expr.right);
var right = evalConstant(expr.right);

@@ -227,0 +222,0 @@ if (right === undefined) {

@@ -9,5 +9,5 @@ "use strict";

function _helperPluginUtils() {
const data = require("@babel/helper-plugin-utils");
var data = require("@babel/helper-plugin-utils");
_helperPluginUtils = function () {
_helperPluginUtils = function _helperPluginUtils() {
return data;

@@ -20,5 +20,5 @@ };

function _pluginSyntaxTypescript() {
const data = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
var data = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
_pluginSyntaxTypescript = function () {
_pluginSyntaxTypescript = function _pluginSyntaxTypescript() {
return data;

@@ -31,5 +31,5 @@ };

function _core() {
const data = require("@babel/core");
var data = require("@babel/core");
_core = function () {
_core = function _core() {
return data;

@@ -58,3 +58,3 @@ };

var _default = (0, _helperPluginUtils().declare)(api => {
var _default = (0, _helperPluginUtils().declare)(function (api) {
api.assertVersion(7);

@@ -67,8 +67,6 @@ return {

RestElement: visitPattern,
Program(path, state) {
Program: function Program(path, state) {
state.programPath = path;
},
ImportDeclaration(path, state) {
ImportDeclaration: function ImportDeclaration(path, state) {
if (path.node.specifiers.length === 0) {

@@ -78,8 +76,20 @@ return;

let allElided = true;
const importsToRemove = [];
var allElided = true;
var importsToRemove = [];
for (const specifier of path.node.specifiers) {
const binding = path.scope.getBinding(specifier.local.name);
for (var _iterator = path.node.specifiers, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var specifier = _ref;
var binding = path.scope.getBinding(specifier.local.name);
if (binding && isImportTypeOnly(binding, state.programPath)) {

@@ -95,3 +105,4 @@ importsToRemove.push(binding.path);

} else {
for (const importPath of importsToRemove) {
for (var _i2 = 0; _i2 < importsToRemove.length; _i2++) {
var importPath = importsToRemove[_i2];
importPath.remove();

@@ -101,25 +112,17 @@ }

},
TSDeclareFunction(path) {
TSDeclareFunction: function TSDeclareFunction(path) {
path.remove();
},
TSDeclareMethod(path) {
TSDeclareMethod: function TSDeclareMethod(path) {
path.remove();
},
VariableDeclaration(path) {
VariableDeclaration: function VariableDeclaration(path) {
if (path.node.declare) path.remove();
},
VariableDeclarator({
node
}) {
VariableDeclarator: function VariableDeclarator(_ref2) {
var node = _ref2.node;
if (node.definite) node.definite = null;
},
ClassMethod(path) {
const {
node
} = path;
ClassMethod: function ClassMethod(path) {
var node = path.node;
if (node.accessibility) node.accessibility = null;

@@ -133,5 +136,18 @@ if (node.abstract) node.abstract = null;

const parameterProperties = [];
var parameterProperties = [];
for (const param of node.params) {
for (var _iterator2 = node.params, _isArray2 = Array.isArray(_iterator2), _i3 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref3;
if (_isArray2) {
if (_i3 >= _iterator2.length) break;
_ref3 = _iterator2[_i3++];
} else {
_i3 = _iterator2.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var param = _ref3;
if (param.type === "TSParameterProperty") {

@@ -146,4 +162,4 @@ parameterProperties.push(param.parameter);

const assigns = parameterProperties.map(p => {
let name;
var assigns = parameterProperties.map(function (p) {
var name;

@@ -158,23 +174,19 @@ if (_core().types.isIdentifier(p)) {

const assign = _core().types.assignmentExpression("=", _core().types.memberExpression(_core().types.thisExpression(), _core().types.identifier(name)), _core().types.identifier(name));
var assign = _core().types.assignmentExpression("=", _core().types.memberExpression(_core().types.thisExpression(), _core().types.identifier(name)), _core().types.identifier(name));
return _core().types.expressionStatement(assign);
});
const statements = node.body.body;
const first = statements[0];
var statements = node.body.body;
var first = statements[0];
const startsWithSuperCall = first !== undefined && _core().types.isExpressionStatement(first) && _core().types.isCallExpression(first.expression) && _core().types.isSuper(first.expression.callee);
var startsWithSuperCall = first !== undefined && _core().types.isExpressionStatement(first) && _core().types.isCallExpression(first.expression) && _core().types.isSuper(first.expression.callee);
node.body.body = startsWithSuperCall ? [first, ...assigns, ...statements.slice(1)] : [...assigns, ...statements];
node.body.body = startsWithSuperCall ? [first].concat(assigns, statements.slice(1)) : assigns.concat(statements);
},
TSParameterProperty(path) {
TSParameterProperty: function TSParameterProperty(path) {
path.replaceWith(path.node.parameter);
},
ClassProperty: function ClassProperty(path) {
var node = path.node;
ClassProperty(path) {
const {
node
} = path;
if (!node.value) {

@@ -192,12 +204,8 @@ path.remove();

},
TSIndexSignature(path) {
TSIndexSignature: function TSIndexSignature(path) {
path.remove();
},
ClassDeclaration: function ClassDeclaration(path) {
var node = path.node;
ClassDeclaration(path) {
const {
node
} = path;
if (node.declare) {

@@ -210,6 +218,4 @@ path.remove();

},
Class({
node
}) {
Class: function Class(_ref4) {
var node = _ref4.node;
if (node.typeParameters) node.typeParameters = null;

@@ -219,9 +225,7 @@ if (node.superTypeParameters) node.superTypeParameters = null;

},
Function({
node
}) {
Function: function Function(_ref5) {
var node = _ref5.node;
if (node.typeParameters) node.typeParameters = null;
if (node.returnType) node.returnType = null;
const p0 = node.params[0];
var p0 = node.params[0];

@@ -232,4 +236,3 @@ if (p0 && _core().types.isIdentifier(p0) && p0.name === "this") {

},
TSModuleDeclaration(path) {
TSModuleDeclaration: function TSModuleDeclaration(path) {
if (!path.node.declare && path.node.id.type !== "StringLiteral") {

@@ -241,49 +244,37 @@ throw path.buildCodeFrameError("Namespaces are not supported.");

},
TSInterfaceDeclaration(path) {
TSInterfaceDeclaration: function TSInterfaceDeclaration(path) {
path.remove();
},
TSTypeAliasDeclaration(path) {
TSTypeAliasDeclaration: function TSTypeAliasDeclaration(path) {
path.remove();
},
TSEnumDeclaration(path) {
TSEnumDeclaration: function TSEnumDeclaration(path) {
(0, _enum.default)(path, _core().types);
},
TSImportEqualsDeclaration(path) {
TSImportEqualsDeclaration: function TSImportEqualsDeclaration(path) {
throw path.buildCodeFrameError("`import =` is not supported by @babel/plugin-transform-typescript\n" + "Please consider using " + "`import <moduleName> from '<moduleName>';` alongside " + "Typescript's --allowSyntheticDefaultImports option.");
},
TSExportAssignment(path) {
TSExportAssignment: function TSExportAssignment(path) {
throw path.buildCodeFrameError("`export =` is not supported by @babel/plugin-transform-typescript\n" + "Please consider using `export <value>;`.");
},
TSTypeAssertion(path) {
TSTypeAssertion: function TSTypeAssertion(path) {
path.replaceWith(path.node.expression);
},
TSAsExpression(path) {
TSAsExpression: function TSAsExpression(path) {
path.replaceWith(path.node.expression);
},
TSNonNullExpression(path) {
TSNonNullExpression: function TSNonNullExpression(path) {
path.replaceWith(path.node.expression);
},
CallExpression(path) {
CallExpression: function CallExpression(path) {
path.node.typeParameters = null;
},
NewExpression(path) {
NewExpression: function NewExpression(path) {
path.node.typeParameters = null;
}
}
};
function visitPattern({
node
}) {
function visitPattern(_ref6) {
var node = _ref6.node;
if (node.typeAnnotation) node.typeAnnotation = null;

@@ -294,3 +285,16 @@ if (_core().types.isIdentifier(node) && node.optional) node.optional = null;

function isImportTypeOnly(binding, programPath) {
for (const path of binding.referencePaths) {
for (var _iterator3 = binding.referencePaths, _isArray3 = Array.isArray(_iterator3), _i4 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref7;
if (_isArray3) {
if (_i4 >= _iterator3.length) break;
_ref7 = _iterator3[_i4++];
} else {
_i4 = _iterator3.next();
if (_i4.done) break;
_ref7 = _i4.value;
}
var path = _ref7;
if (!isInType(path)) {

@@ -305,8 +309,7 @@ return false;

let sourceFileHasJsx = false;
var sourceFileHasJsx = false;
programPath.traverse({
JSXElement() {
JSXElement: function JSXElement() {
sourceFileHasJsx = true;
}
});

@@ -313,0 +316,0 @@ return !sourceFileHasJsx;

{
"name": "@babel/plugin-transform-typescript",
"version": "7.0.0-beta.43",
"version": "7.0.0-beta.44",
"description": "Transform TypeScript into ES.next",

@@ -13,12 +13,12 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-typescript",

"dependencies": {
"@babel/helper-plugin-utils": "7.0.0-beta.43",
"@babel/plugin-syntax-typescript": "7.0.0-beta.43"
"@babel/helper-plugin-utils": "7.0.0-beta.44",
"@babel/plugin-syntax-typescript": "7.0.0-beta.44"
},
"peerDependencies": {
"@babel/core": "7.0.0-beta.43"
"@babel/core": "7.0.0-beta.44"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.43",
"@babel/helper-plugin-test-runner": "7.0.0-beta.43"
"@babel/core": "7.0.0-beta.44",
"@babel/helper-plugin-test-runner": "7.0.0-beta.44"
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc