Socket
Socket
Sign inDemoInstall

@babel/helper-replace-supers

Package Overview
Dependencies
Maintainers
4
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/helper-replace-supers - npm Package Compare versions

Comparing version 8.0.0-alpha.11 to 8.0.0-alpha.12

59

lib/index.js

@@ -1,9 +0,8 @@

import environmentVisitor from '@babel/helper-environment-visitor';
import memberExpressionToFunctions from '@babel/helper-member-expression-to-functions';
import optimiseCall from '@babel/helper-optimise-call-expression';
import { traverse, types, template } from '@babel/core';
import { types, template } from '@babel/core';
import { visitors } from '@babel/traverse';
const {
assignmentExpression,
booleanLiteral,
callExpression,

@@ -17,8 +16,3 @@ cloneNode,

} = types;
function getPrototypeOfExpression(objectRef, isStatic, file, isPrivateMethod) {
objectRef = cloneNode(objectRef);
const targetRef = isStatic || isPrivateMethod ? objectRef : memberExpression(objectRef, identifier("prototype"));
return callExpression(file.addHelper("getPrototypeOf"), [targetRef]);
}
const visitor = traverse.visitors.merge([environmentVisitor, {
const visitor = visitors.environmentVisitor({
Super(path, state) {

@@ -34,4 +28,4 @@ const {

}
}]);
const unshadowSuperBindingVisitor = traverse.visitors.merge([environmentVisitor, {
});
const unshadowSuperBindingVisitor = visitors.environmentVisitor({
Scopable(path, {

@@ -45,3 +39,3 @@ refName

}
}]);
});
const specHandlers = {

@@ -79,19 +73,28 @@ memoise(superMember, count) {

},
_getPrototypeOfExpression() {
const objectRef = cloneNode(this.getObjectRef());
const targetRef = this.isStatic || this.isPrivateMethod ? objectRef : memberExpression(objectRef, identifier("prototype"));
return callExpression(this.file.addHelper("getPrototypeOf"), [targetRef]);
},
get(superMember) {
return this._get(superMember, this._getThisRefs());
const objectRef = cloneNode(this.getObjectRef());
return callExpression(this.file.addHelper("superPropGet"), [this.isDerivedConstructor ? sequenceExpression([thisExpression(), objectRef]) : objectRef, this.prop(superMember), thisExpression(), ...(this.isStatic || this.isPrivateMethod ? [] : [types.numericLiteral(1)])]);
},
_get(superMember, thisRefs) {
const proto = getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file, this.isPrivateMethod);
return callExpression(this.file.addHelper("get"), [thisRefs.needAccessFirst ? sequenceExpression([thisRefs.this, proto]) : proto, this.prop(superMember), thisRefs.this]);
_call(superMember, args, optional) {
const objectRef = cloneNode(this.getObjectRef());
let argsNode;
if (args.length === 1 && types.isSpreadElement(args[0]) && (types.isIdentifier(args[0].argument) || types.isArrayExpression(args[0].argument))) {
argsNode = args[0].argument;
} else {
argsNode = types.arrayExpression(args);
}
const call = types.callExpression(this.file.addHelper("superPropGet"), [this.isDerivedConstructor ? sequenceExpression([thisExpression(), objectRef]) : objectRef, this.prop(superMember), thisExpression(), types.numericLiteral(2 | (this.isStatic || this.isPrivateMethod ? 0 : 1))]);
if (optional) {
return types.optionalCallExpression(call, [argsNode], true);
}
return callExpression(call, [argsNode]);
},
_getThisRefs() {
return {
needAccessFirst: this.isDerivedConstructor,
this: thisExpression()
};
},
set(superMember, value) {
const thisRefs = this._getThisRefs();
const proto = getPrototypeOfExpression(this.getObjectRef(), this.isStatic, this.file, this.isPrivateMethod);
return callExpression(this.file.addHelper("set"), [thisRefs.needAccessFirst ? sequenceExpression([thisRefs.this, proto]) : proto, this.prop(superMember), value, thisRefs.this, booleanLiteral(superMember.isInStrictMode())]);
const objectRef = cloneNode(this.getObjectRef());
return callExpression(this.file.addHelper("superPropSet"), [this.isDerivedConstructor ? sequenceExpression([thisExpression(), objectRef]) : objectRef, this.prop(superMember), value, thisExpression(), types.numericLiteral(superMember.isInStrictMode() ? 1 : 0), ...(this.isStatic || this.isPrivateMethod ? [] : [types.numericLiteral(1)])]);
},

@@ -102,8 +105,6 @@ destructureSet(superMember) {

call(superMember, args) {
const thisRefs = this._getThisRefs();
return optimiseCall(this._get(superMember, thisRefs), cloneNode(thisRefs.this), args, false);
return this._call(superMember, args, false);
},
optionalCall(superMember, args) {
const thisRefs = this._getThisRefs();
return optimiseCall(this._get(superMember, thisRefs), cloneNode(thisRefs.this), args, true);
return this._call(superMember, args, true);
},

@@ -110,0 +111,0 @@ delete(superMember) {

{
"name": "@babel/helper-replace-supers",
"version": "8.0.0-alpha.11",
"version": "8.0.0-alpha.12",
"description": "Helper function to replace supers",

@@ -17,11 +17,11 @@ "repository": {

"dependencies": {
"@babel/helper-environment-visitor": "^8.0.0-alpha.11",
"@babel/helper-member-expression-to-functions": "^8.0.0-alpha.11",
"@babel/helper-optimise-call-expression": "^8.0.0-alpha.11"
"@babel/helper-member-expression-to-functions": "^8.0.0-alpha.12",
"@babel/helper-optimise-call-expression": "^8.0.0-alpha.12",
"@babel/traverse": "^8.0.0-alpha.12"
},
"devDependencies": {
"@babel/core": "^8.0.0-alpha.11"
"@babel/core": "^8.0.0-alpha.12"
},
"peerDependencies": {
"@babel/core": "^8.0.0-alpha.11"
"@babel/core": "^8.0.0-alpha.12"
},

@@ -28,0 +28,0 @@ "engines": {

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc