New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-aexpr-source-transformation

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-aexpr-source-transformation - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

104

dist/index.js

@@ -45,2 +45,3 @@ "use strict";

return file.declarations[name] = file.addImport("aexpr-source-transformation-propagation", name, name);
var ref = customTemplates[name];

@@ -72,9 +73,104 @@ console.log(file.addImport("aexpr-source-transformation-propagation", "aexpr"));

return {
pre: function pre(file) {
console.log("fff", file);
},
visitor: {
Program: {
enter: function enter(path, state) {
console.log("file", path);
//state.file.addImport("aexpr-source-transformation-propagation21", "aexpr");
path.traverse({
Identifier: function Identifier(path) {
console.log(path.node.name);
// Check for a call to aexpr:
if (t.isCallExpression(path.parent) && path.node.name === AEXPR_IDENTIFIER_NAME && !path.scope.hasBinding(AEXPR_IDENTIFIER_NAME)) {
path.replaceWith(addCustomTemplate(state.file, AEXPR_IDENTIFIER_NAME));
return;
}
return;
//if(RESERVED_IDENTIFIERS.includes(path.node.name)) { return; }
if (t.isClassDeclaration(path.parent)) {
console.log("classDecl", path.node.name);
return;
}
if (t.isClassMethod(path.parent)) {
console.log("classMethod", path.node.name);
return;
}
if (t.isObjectMethod(path.parent)) {
console.log("objectMethod", path.node.name);
return;
}
if (t.isVariableDeclarator(path.parent)) {
console.log("varDecl", path.node.name);
return;
}
// is this correct here?
// TODO: is it correct for the locals plugin?
if (!path.isReferencedIdentifier()) {
console.log("def", path.node.name);
return;
}
// is locally defined variable?
if (path.scope.hasBinding(path.node.name)) {
console.log("local", path.node.name);
} else {
// we have a global
console.log("global", path.node.name);
}
},
AssignmentExpression: function AssignmentExpression(path) {
// check, whether we assign to a member (no support for pattern right now)
if (!t.isMemberExpression(path.node.left)) {
return;
}
if (isGenerated(path)) {
return;
}
//state.file.addImport
path.replaceWith(t.callExpression(addCustomTemplate(state.file, SET_MEMBER), [path.node.left.object, getPropertyFromMemberExpression(path.node.left), t.stringLiteral(path.node.operator), path.node.right]));
},
MemberExpression: function MemberExpression(path) {
// lval (left values) are ignored for now
if (t.isAssignmentExpression(path.parent) && path.key === 'left') {
return;
}
if (isGenerated(path)) {
return;
}
path.replaceWith(t.callExpression(addCustomTemplate(state.file, GET_MEMBER), [path.node.object, getPropertyFromMemberExpression(path.node)]));
},
CallExpression: function CallExpression(path) {
if (isGenerated(path)) {
return;
}
// check whether we call a MemberExpression
if (t.isMemberExpression(path.node.callee)) {
path.replaceWith(t.callExpression(addCustomTemplate(state.file, GET_AND_CALL_MEMBER), [path.node.callee.object, getPropertyFromMemberExpression(path.node.callee), t.arrayExpression(path.node.arguments)]));
} else {
if (t.isIdentifier(path.node.callee) && true) {}
}
}
});
}
},
// TODO: also
Identifier: function Identifier(path, state) {
//console.log(state);
// Check for a call to aexpr:
if (t.isCallExpression(path.parent) && path.node.name === AEXPR_IDENTIFIER_NAME && !path.scope.hasBinding(AEXPR_IDENTIFIER_NAME)) {
//path.replaceWith(
addCustomTemplate(state.file, AEXPR_IDENTIFIER_NAME);
//addCustomTemplate(state.file, AEXPR_IDENTIFIER_NAME)
//);

@@ -135,3 +231,3 @@ return;

// t.callExpression(
addCustomTemplate(state.file, SET_MEMBER); //,
//addCustomTemplate(state.file, SET_MEMBER)//,
// [

@@ -157,3 +253,3 @@ // path.node.left.object,

// t.callExpression(
addCustomTemplate(state.file, GET_MEMBER); //,
//addCustomTemplate(state.file, GET_MEMBER)//,
// [

@@ -175,3 +271,3 @@ // path.node.object,

// t.callExpression(
addCustomTemplate(state.file, GET_AND_CALL_MEMBER); //,
//addCustomTemplate(state.file, GET_AND_CALL_MEMBER)//,
// [

@@ -178,0 +274,0 @@ // path.node.callee.object,

@@ -63,2 +63,3 @@ const AEXPR_IDENTIFIER_NAME = "aexpr";

return file.declarations[name] = file.addImport("aexpr-source-transformation-propagation", name, name);
let ref = customTemplates[name];

@@ -90,5 +91,126 @@ console.log(file.addImport("aexpr-source-transformation-propagation", "aexpr"));

return {
pre(file) {
console.log("fff", file)
},
visitor: {
Program: {
enter(path, state) {
console.log("file", path);
//state.file.addImport("aexpr-source-transformation-propagation21", "aexpr");
path.traverse({
Identifier(path) {
console.log(path.node.name)
// Check for a call to aexpr:
if(
t.isCallExpression(path.parent) &&
path.node.name === AEXPR_IDENTIFIER_NAME &&
!path.scope.hasBinding(AEXPR_IDENTIFIER_NAME)
) {
path.replaceWith(
addCustomTemplate(state.file, AEXPR_IDENTIFIER_NAME)
);
return;
}
return;
//if(RESERVED_IDENTIFIERS.includes(path.node.name)) { return; }
if(t.isClassDeclaration(path.parent)) {
console.log("classDecl", path.node.name);
return;
}
if(t.isClassMethod(path.parent)) {
console.log("classMethod", path.node.name);
return;
}
if(t.isObjectMethod(path.parent)) {
console.log("objectMethod", path.node.name);
return;
}
if(t.isVariableDeclarator(path.parent)) {
console.log("varDecl", path.node.name);
return;
}
// is this correct here?
// TODO: is it correct for the locals plugin?
if (!path.isReferencedIdentifier()) {
console.log("def", path.node.name);
return;
}
// is locally defined variable?
if (path.scope.hasBinding(path.node.name)) {
console.log("local", path.node.name);
} else {
// we have a global
console.log("global", path.node.name);
}
},
AssignmentExpression(path) {
// check, whether we assign to a member (no support for pattern right now)
if(!t.isMemberExpression(path.node.left)) { return; }
if(isGenerated(path)) { return; }
//state.file.addImport
path.replaceWith(
t.callExpression(
addCustomTemplate(state.file, SET_MEMBER),
[
path.node.left.object,
getPropertyFromMemberExpression(path.node.left),
t.stringLiteral(path.node.operator),
path.node.right
]
)
);
},
MemberExpression(path) {
// lval (left values) are ignored for now
if(t.isAssignmentExpression(path.parent) && path.key === 'left') { return; }
if(isGenerated(path)) { return; }
path.replaceWith(
t.callExpression(
addCustomTemplate(state.file, GET_MEMBER),
[
path.node.object,
getPropertyFromMemberExpression(path.node)
]
)
);
},
CallExpression(path) {
if(isGenerated(path)) { return; }
// check whether we call a MemberExpression
if(t.isMemberExpression(path.node.callee)) {
path.replaceWith(
t.callExpression(
addCustomTemplate(state.file, GET_AND_CALL_MEMBER),
[
path.node.callee.object,
getPropertyFromMemberExpression(path.node.callee),
t.arrayExpression(path.node.arguments)
]
)
)
} else {
if(t.isIdentifier(path.node.callee) && true) {
}
}
}
});
}
},
// TODO: also
Identifier(path, state) {
//console.log(state);
// Check for a call to aexpr:

@@ -101,3 +223,3 @@ if(

//path.replaceWith(
addCustomTemplate(state.file, AEXPR_IDENTIFIER_NAME)
//addCustomTemplate(state.file, AEXPR_IDENTIFIER_NAME)
//);

@@ -155,3 +277,3 @@ return;

// t.callExpression(
addCustomTemplate(state.file, SET_MEMBER)//,
//addCustomTemplate(state.file, SET_MEMBER)//,
// [

@@ -174,3 +296,3 @@ // path.node.left.object,

// t.callExpression(
addCustomTemplate(state.file, GET_MEMBER)//,
//addCustomTemplate(state.file, GET_MEMBER)//,
// [

@@ -191,3 +313,3 @@ // path.node.object,

// t.callExpression(
addCustomTemplate(state.file, GET_AND_CALL_MEMBER)//,
//addCustomTemplate(state.file, GET_AND_CALL_MEMBER)//,
// [

@@ -194,0 +316,0 @@ // path.node.callee.object,

2

package.json
{
"name": "babel-plugin-aexpr-source-transformation",
"version": "2.0.2",
"version": "2.1.0",
"description": "3rd implementation strategy of active expressions, via a babel transformation",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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