Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2 to 2.0.0

9

changelog.md

@@ -0,1 +1,10 @@

# v2.0.0
Upgraded dependencies to support babel 7.x.
Changed custom currency option to be a options object instead of a string. ([#28](https://github.com/scurker/babel-plugin-transform-currency-operators/issues/28) thanks [@TeNNoX](https://github.com/TeNNoX))
# v1.0.2
Set peer dependency to `babel-cli`@`6.x`
# v1.0.1

@@ -2,0 +11,0 @@

86

dist/index.js

@@ -7,11 +7,42 @@ 'use strict';

function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var rootPath = process.cwd();
function resolveRelativePath(currentFile, importPath) {
var absolutePath = path.resolve(rootPath, importPath),
relativePathToImport = path.relative(path.dirname(currentFile), absolutePath);
relativePathToImport = path.relative(path.dirname(currentFile), absolutePath); // Check to see if path is relative to currentFile's folder
// Check to see if path is relative to currentFile's folder
if (relativePathToImport.indexOf('../') !== 0) {
relativePathToImport = './' + relativePathToImport;
relativePathToImport = "./".concat(relativePathToImport);
}

@@ -22,4 +53,2 @@

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var arithmeticOperators = {

@@ -31,5 +60,3 @@ '+': 'add',

};
var compareOperators = ['===', '==', '>', '<', '>=', '<=', '!=', '!=='];
function transformCurrencyOperators(_ref) {

@@ -81,4 +108,2 @@ var t = _ref.types;

currencyVariables = new Set([methodName]);
var Visitors = {

@@ -100,2 +125,3 @@ FunctionDeclaration: function FunctionDeclaration(_ref2) {

var binding = scope.bindings[node.id.name] || {};
if (binding.kind !== 'let' || binding.kind === 'let' && binding.scope === refPath.scope) {

@@ -112,3 +138,3 @@ currencyVariables.add(node.id.name);

if (!expressionCallsCurrency(right, currencyVariables)) {
currencyVariables.delete(left.name);
currencyVariables["delete"](left.name);
} else {

@@ -118,6 +144,6 @@ currencyVariables.add(left.name);

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

@@ -131,4 +157,4 @@ currentPath.traverse(Visitors);

function buildExpression(path$$1, methodName) {
var node = path$$1.node,
function buildExpression(path, methodName) {
var node = path.node,
operator = node.operator,

@@ -138,5 +164,4 @@ left = node.left,

if (t.isBinaryExpression(left)) {
left = buildExpression(path$$1.get('left'));
left = buildExpression(path.get('left'));
}

@@ -149,3 +174,3 @@

} else if (compareOperators.includes(operator) && !t.isMemberExpression(node.left)) {
return t.binaryExpression(operator, t.memberExpression(left, t.identifier('value')), pathContainsCurrency(path$$1.get('right'), methodName) ? t.memberExpression(right, t.identifier('value')) : right);
return t.binaryExpression(operator, t.memberExpression(left, t.identifier('value')), pathContainsCurrency(path.get('right'), methodName) ? t.memberExpression(right, t.identifier('value')) : right);
} else {

@@ -160,10 +185,10 @@ return node;

var filename = opts.filename,
paths = Array.isArray(this.opts) ? this.opts.map(function (path$$1) {
return resolveRelativePath(filename, path$$1);
}) : [];
this.currencyResolution = new Set(['currency.js'].concat(_toConsumableArray(paths)));
pluginOptions = this.opts,
paths = Array.isArray(pluginOptions.customCurrency) ? pluginOptions.customCurrency.filter(function (path) {
return typeof path === 'string';
}) : typeof pluginOptions.customCurrency === 'string' ? [pluginOptions.customCurrency] : [];
this.currencyResolution = new Set(['currency.js'].concat(_toConsumableArray(paths.map(function (path) {
return resolveRelativePath(filename, path);
}))));
},
visitor: {

@@ -176,3 +201,2 @@ VariableDeclarator: function VariableDeclarator(_ref6, _ref7) {

if (t.isCallExpression(init) && init.callee.name === 'require' && currencyResolution.has(init.arguments[0].value)) {

@@ -192,3 +216,2 @@ opts.hasCurrency = true;

if (currencyResolution.has(source.value)) {

@@ -204,10 +227,9 @@ var defaultImport = specifiers.find(function (specifier) {

},
BinaryExpression: function BinaryExpression(path$$1, _ref10) {
BinaryExpression: function BinaryExpression(path, _ref10) {
var opts = _ref10.opts;
if (opts.hasCurrency && pathContainsCurrency(path$$1.get('left'), opts.methodName)) {
if (opts.hasCurrency && pathContainsCurrency(path.get('left'), opts.methodName)) {
// Prevent replacement nodes from being visited multiple times
path$$1.stop();
path$$1.replaceWith(buildExpression(path$$1, opts.methodName));
path.stop();
path.replaceWith(buildExpression(path, opts.methodName));
return;

@@ -214,0 +236,0 @@ }

{
"name": "babel-plugin-transform-currency-operators",
"version": "1.0.2",
"version": "2.0.0",
"homepage": "An experimental babel plugin for transforming currency.js operators",

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

"build": "rollup -c",
"coverage": "BABEL_ENV=test nyc mocha --require babel-core/register ./test/index.js",
"coverage": "BABEL_ENV=test nyc mocha --require @babel/register ./test/index.js",
"report:html": "nyc report --reporter=html",

@@ -16,3 +16,3 @@ "report:text-lcov": "nyc report --reporter=text-lcov",

"prepublish": "npm run build",
"test": "BABEL_ENV=test mocha --require babel-core/register"
"test": "BABEL_ENV=test mocha --require @babel/register"
},

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

"peerDependencies": {
"babel-core": "6.x"
"@babel/core": "7.x"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-tester": "^5.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"eslint": "^6.7.2",
"mocha": "^5.0.0",
"nyc": "^11.8.0",
"prettier": "^1.13.3",
"rollup": "^0.59.0",
"rollup-plugin-babel": "^3.0.2"
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/register": "^7.9.0",
"babel-plugin-tester": "^9.1.0",
"eslint": "^7.0.0",
"mocha": "^7.1.2",
"nyc": "^15.0.1",
"prettier": "^2.0.5",
"rollup": "^2.10.7",
"rollup-plugin-babel": "^4.4.0"
}
}

@@ -105,3 +105,3 @@ # babel-plugin-transform-currency-operators [![Build Status](https://travis-ci.org/scurker/babel-plugin-transform-currency-operators.svg?branch=master)](https://travis-ci.org/scurker/babel-plugin-transform-currency-operators) [![Coverage Status](https://coveralls.io/repos/github/scurker/babel-plugin-transform-currency-operators/badge.svg?branch=master)](https://coveralls.io/github/scurker/babel-plugin-transform-currency-operators?branch=master) [![npm](https://img.shields.io/npm/v/babel-plugin-transform-currency-operators.svg?style=flat)](https://www.npmjs.com/package/babel-plugin-transform-currency-operators)

{
"plugins": ["transform-currency-operators", ['./path/to/custom/currency']]
"plugins": ["transform-currency-operators", { customCurrency: './path/to/custom/currency' }]
}

@@ -108,0 +108,0 @@ ```

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