Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babel/plugin-transform-classes

Package Overview
Dependencies
Maintainers
4
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 8.0.0-alpha.5 to 8.0.0-alpha.6

69

lib/index.js

@@ -10,6 +10,9 @@ import { declare } from '@babel/helper-plugin-utils';

import environmentVisitor from '@babel/helper-environment-visitor';
import optimiseCall from '@babel/helper-optimise-call-expression';
const helper = template.statement`
function CREATE_SUPER(Derived) {
function CALL_SUPER(
_this,
derived,
args,
) {
function isNativeReflectConstruct() {

@@ -32,5 +35,4 @@ if (typeof Reflect === "undefined" || !Reflect.construct) return false;

// If the internal slots aren't set, this throws an error similar to
// TypeError: this is not a Date object.
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
return true;
// TypeError: this is not a Boolean object.
return !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}),);
} catch (e) {

@@ -41,17 +43,19 @@ return false;

return function () {
var Super = GET_PROTOTYPE_OF(Derived), result;
if (isNativeReflectConstruct()) {
// NOTE: This doesn't work if this.__proto__.constructor has been modified.
var NewTarget = GET_PROTOTYPE_OF(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return POSSIBLE_CONSTRUCTOR_RETURN(this, result);
}
// Super
derived = GET_PROTOTYPE_OF(derived);
return POSSIBLE_CONSTRUCTOR_RETURN(
_this,
isNativeReflectConstruct()
? // NOTE: This doesn't work if this.__proto__.constructor has been modified.
Reflect.construct(
derived,
args || [],
GET_PROTOTYPE_OF(_this).constructor,
)
: derived.apply(_this, args),
);
}
`;
const helperIDs = new WeakMap();
function addCreateSuperHelper(file) {
function addCallSuperHelper(file) {
if (helperIDs.has(file)) {

@@ -61,8 +65,8 @@ return (types.cloneNode || types.clone)(helperIDs.get(file));

try {
return file.addHelper("createSuper");
return file.addHelper("callSuper");
} catch {}
const id = file.scope.generateUidIdentifier("createSuper");
const id = file.scope.generateUidIdentifier("callSuper");
helperIDs.set(file, id);
const fn = helper({
CREATE_SUPER: id,
CALL_SUPER: id,
GET_PROTOTYPE_OF: file.addHelper("getPrototypeOf"),

@@ -90,3 +94,2 @@ POSSIBLE_CONSTRUCTOR_RETURN: file.addHelper("possibleConstructorReturn")

classRef: undefined,
superFnId: undefined,
superName: null,

@@ -256,3 +259,14 @@ superReturns: [],

} else {
call = optimiseCall(types.cloneNode(classState.superFnId), types.thisExpression(), bareSuperNode.arguments, false);
const args = [types.thisExpression(), types.cloneNode(classState.classRef)];
if (bareSuperNode.arguments?.length) {
const bareSuperNodeArguments = bareSuperNode.arguments;
if (bareSuperNodeArguments.length === 1 && types.isSpreadElement(bareSuperNodeArguments[0]) && types.isIdentifier(bareSuperNodeArguments[0].argument, {
name: "arguments"
})) {
args.push(bareSuperNodeArguments[0].argument);
} else {
args.push(types.arrayExpression(bareSuperNodeArguments));
}
}
call = types.callExpression(addCallSuperHelper(classState.file), args);
}

@@ -449,10 +463,3 @@ if (bareSuper.parentPath.isExpressionStatement() && bareSuper.parentPath.container === body.node.body && body.node.body.length - 1 === bareSuper.parentPath.key) {

if (!classState.isDerived || classState.pushedInherits) return;
const superFnId = path.scope.generateUidIdentifier("super");
setState({
pushedInherits: true,
superFnId
});
if (!assumptions.superIsCallableConstructor) {
classState.body.unshift(types.variableDeclaration("var", [types.variableDeclarator(superFnId, types.callExpression(addCreateSuperHelper(classState.file), [types.cloneNode(classState.classRef)]))]));
}
classState.pushedInherits = true;
classState.body.unshift(types.expressionStatement(types.callExpression(classState.file.addHelper(classState.isLoose ? "inheritsLoose" : "inherits"), [types.cloneNode(classState.classRef), types.cloneNode(classState.superName)])));

@@ -574,3 +581,3 @@ }

var index = declare((api, options) => {
api.assertVersion("8.0.0-alpha.5");
api.assertVersion("8.0.0-alpha.6");
const {

@@ -577,0 +584,0 @@ loose = false

{
"name": "@babel/plugin-transform-classes",
"version": "8.0.0-alpha.5",
"version": "8.0.0-alpha.6",
"description": "Compile ES2015 classes to ES5",

@@ -17,10 +17,9 @@ "repository": {

"dependencies": {
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.5",
"@babel/helper-compilation-targets": "^8.0.0-alpha.5",
"@babel/helper-environment-visitor": "^8.0.0-alpha.5",
"@babel/helper-function-name": "^8.0.0-alpha.5",
"@babel/helper-optimise-call-expression": "^8.0.0-alpha.5",
"@babel/helper-plugin-utils": "^8.0.0-alpha.5",
"@babel/helper-replace-supers": "^8.0.0-alpha.5",
"@babel/helper-split-export-declaration": "^8.0.0-alpha.5",
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.6",
"@babel/helper-compilation-targets": "^8.0.0-alpha.6",
"@babel/helper-environment-visitor": "^8.0.0-alpha.6",
"@babel/helper-function-name": "^8.0.0-alpha.6",
"@babel/helper-plugin-utils": "^8.0.0-alpha.6",
"@babel/helper-replace-supers": "^8.0.0-alpha.6",
"@babel/helper-split-export-declaration": "^8.0.0-alpha.6",
"globals": "^13.5.0"

@@ -32,8 +31,8 @@ },

"peerDependencies": {
"@babel/core": "^8.0.0-alpha.5"
"@babel/core": "^8.0.0-alpha.6"
},
"devDependencies": {
"@babel/core": "^8.0.0-alpha.5",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.5",
"@babel/traverse": "^8.0.0-alpha.5"
"@babel/core": "^8.0.0-alpha.6",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.6",
"@babel/traverse": "^8.0.0-alpha.6"
},

@@ -40,0 +39,0 @@ "engines": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc