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

babel-plugin-transform-currency-operators

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-currency-operators - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

2

package.json
{
"name": "babel-plugin-transform-currency-operators",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"homepage": "An experimental babel plugin for transforming currency.js operators",

@@ -5,0 +5,0 @@ "description": "https://github.com/scurker/babel-plugin-transform-currency-operators",

@@ -50,8 +50,8 @@ const arithmeticOperators = {

return t.isIdentifier(node) && identifiers.includes(node.name);
return t.isIdentifier(node) && identifiers.has(node.name);
}
function expressionContainsCurrency(path, methodName) {
let { node } = path
, currencyVariables = [methodName];
function pathContainsCurrency(refPath, methodName) {
let { node } = refPath
, currencyVariables = new Set([methodName]);

@@ -63,11 +63,17 @@ const Visitors = {

node.body.body.find(n => t.isReturnStatement(n)),
[methodName, ...currencyVariables]
currencyVariables
)
) {
currencyVariables.push(node.id.name);
currencyVariables.add(node.id.name);
}
},
VariableDeclarator({ node }) {
VariableDeclarator({ scope, node }) {
if (expressionCallsCurrency(node.init, currencyVariables)) {
currencyVariables.push(node.id.name);
let binding = scope.bindings[node.id.name] || {};
if (
binding.kind !== 'let' ||
(binding.kind === 'let' && binding.scope === refPath.scope)
) {
currencyVariables.add(node.id.name);
}
}

@@ -78,5 +84,5 @@ },

if (!expressionCallsCurrency(right, currencyVariables)) {
currencyVariables = currencyVariables.filter(x => x !== left.name);
currencyVariables.delete(left.name);
} else {
currencyVariables.push(left.name);
currencyVariables.add(left.name);
}

@@ -87,3 +93,3 @@ },

// Attempt to find any currency variables in scope
let currentPath = path.parentPath;
let currentPath = refPath.parentPath;
while (currentPath) {

@@ -122,3 +128,3 @@ currentPath.traverse(Visitors);

t.memberExpression(left, t.identifier('value')),
expressionContainsCurrency(path.get('right'), methodName)
pathContainsCurrency(path.get('right'), methodName)
? t.memberExpression(right, t.identifier('value'))

@@ -166,3 +172,3 @@ : right

opts.hasCurrency &&
expressionContainsCurrency(path.get('left'), opts.methodName)
pathContainsCurrency(path.get('left'), opts.methodName)
) {

@@ -169,0 +175,0 @@ // Prevent replacement nodes from being visited multiple times

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