Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-typescript

Package Overview
Dependencies
55
Maintainers
4
Versions
128
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.0 to 7.1.0

103

lib/index.js

@@ -55,2 +55,4 @@ "use strict";

const PARSED_PARAMS = new WeakSet();
var _default = (0, _helperPluginUtils().declare)((api, {

@@ -73,3 +75,3 @@ jsxPragma = "React"

if (stmt.node.specifiers.length === 0) {
return;
continue;
}

@@ -126,46 +128,4 @@

if (node.optional) node.optional = null;
if (node.kind !== "constructor") {
return;
}
const parameterProperties = [];
for (const param of node.params) {
if (param.type === "TSParameterProperty") {
parameterProperties.push(param.parameter);
}
}
if (!parameterProperties.length) {
return;
}
const assigns = parameterProperties.map(p => {
let name;
if (_core().types.isIdentifier(p)) {
name = p.name;
} else if (_core().types.isAssignmentPattern(p) && _core().types.isIdentifier(p.left)) {
name = p.left.name;
} else {
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);
});
const statements = node.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);
node.body.body = startsWithSuperCall ? [first, ...assigns, ...statements.slice(1)] : [...assigns, ...statements];
},
TSParameterProperty(path) {
path.replaceWith(path.node.parameter);
},
ClassProperty(path) {

@@ -208,6 +168,43 @@ const {

path.get("body.body").forEach(child => {
if (child.isClassProperty()) {
child.node.typeAnnotation = null;
const childNode = child.node;
if (!child.node.value && !child.node.decorators) {
if (_core().types.isClassMethod(childNode, {
kind: "constructor"
})) {
const parameterProperties = [];
for (const param of childNode.params) {
if (param.type === "TSParameterProperty" && !PARSED_PARAMS.has(param.parameter)) {
PARSED_PARAMS.add(param.parameter);
parameterProperties.push(param.parameter);
}
}
if (parameterProperties.length) {
const assigns = parameterProperties.map(p => {
let name;
if (_core().types.isIdentifier(p)) {
name = p.name;
} else if (_core().types.isAssignmentPattern(p) && _core().types.isIdentifier(p.left)) {
name = p.left.name;
} else {
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);
});
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];
}
} else if (child.isClassProperty()) {
childNode.typeAnnotation = null;
if (!childNode.value && !childNode.decorators) {
child.remove();

@@ -229,2 +226,6 @@ }

}
node.params = node.params.map(p => {
return p.type === "TSParameterProperty" ? p.parameter : p;
});
},

@@ -265,3 +266,11 @@

TSAsExpression(path) {
path.replaceWith(path.node.expression);
let {
node
} = path;
do {
node = node.expression;
} while (_core().types.isTSAsExpression(node));
path.replaceWith(node);
},

@@ -268,0 +277,0 @@

{
"name": "@babel/plugin-transform-typescript",
"version": "7.0.0",
"version": "7.1.0",
"description": "Transform TypeScript into ES.next",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-typescript",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",

@@ -8,0 +11,0 @@ "keywords": [

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