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

babel-plugin-macros

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-macros - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

test/fixtures/execution-order-in-expression.js

7

lib/index.js

@@ -271,3 +271,2 @@ 'use strict';

}
node._processedByMacro = true;
}

@@ -279,3 +278,3 @@ if (t.isMemberExpression(node.callee)) {

var tailId = node.callee.property;
node.arguments.unshift(head); //TODO - so slow. meybe is ecponent slow ?
node.arguments.unshift(head); //TODO - so slow. maybe is exponent slow ?
var macro = getMacro(tailId, path.scope, state);

@@ -292,2 +291,6 @@ if (macro) {

}
if (state[$macroState].macrosDefined) {
node._processedByMacro = true;
}
}

@@ -294,0 +297,0 @@ },

{
"name": "babel-plugin-macros",
"version": "1.0.5",
"version": "1.0.6",
"description": "Macros for JavaScript via a babel plugin.",

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

@@ -6,2 +6,3 @@ # Babel Macros

[![Build Status](https://travis-ci.org/codemix/babel-plugin-macros.svg)](https://travis-ci.org/codemix/babel-plugin-macros)
[![NPM](https://nodei.co/npm-dl/babel-plugin-macros.png?months=1)](https://nodei.co/npm/babel-plugin-macros/)

@@ -105,2 +106,4 @@ > Note: Now requires Babel 6.

fix combining more than 2 macros
- **1.0.5** optimization. Replacement `traverse` to `get` to find the desired node
- **1.0.6** honest exception for infinite recursion in macros

@@ -107,0 +110,0 @@ # License

@@ -241,3 +241,2 @@ import _ from 'lodash';

}
node._processedByMacro = true;
}

@@ -253,3 +252,3 @@ if (t.isMemberExpression(node.callee)) {

const tailId = node.callee.property;
node.arguments.unshift(head);//TODO - so slow. meybe is ecponent slow ?
node.arguments.unshift(head);//TODO - so slow. maybe is exponent slow ?
const macro = getMacro(tailId, path.scope, state);

@@ -267,2 +266,6 @@ if (macro) {

}
if(state[$macroState].macrosDefined) {
node._processedByMacro = true;
}
}

@@ -269,0 +272,0 @@ },

@@ -1,7 +0,6 @@

DEFINE_MACRO(FOO, () => (
["foo", BAR()]
));
DEFINE_MACRO(BAR, () => "bar");
DEFINE_MACRO(FOO, () => ["foo"].concat(BAR()));
DEFINE_MACRO(BAR, () => ["bar"].concat(BAZ()));
DEFINE_MACRO(BAZ, () => ["baz"]);
export default function demo() {
return FOO();
}
DEFINE_MACRO(FOO, () => {
DEFINE_MACRO(BAR, () => "bar");
return ["foo", BAR()];
DEFINE_MACRO(BAR, () => {
DEFINE_MACRO(BAZ, () => "baz");
return ["bar"].concat(BAZ());
});
return ["foo"].concat(BAR());
});

@@ -5,0 +8,0 @@

@@ -17,6 +17,14 @@ function f1() {

}
function f3() {
return QWE(()=>ASD());
function QWE(fn) {
return ["qwe", ASD(), fn()];
DEFINE_MACRO(ASD, () => "asd");
}
DEFINE_MACRO(ASD, () => "quux");
}
export default function demo() {
return [f1(), f2()];
return [f1(), f2(), f3()];
}

@@ -12,20 +12,24 @@ import Plugin from '../src';

function runTest (basename: string, expectedResult: mixed, args: Array = []): void {
const source = load(basename);
const transformed = transform(source, {"presets": ["es2015"], plugins: [Plugin]});
//console.log(transformed.code);
const context = {
exports: {}
};
const loaded = new Function('module', 'exports', transformed.code);
loaded(context, context.exports);
var result;
try {
result = typeof context.exports.default === 'function' ? context.exports.default(...args) : context.exports.default;
const source = load(basename);
const transformed = transform(source, {"presets": ["es2015"], plugins: [Plugin]});
//console.log(transformed.code);
const context = {
exports: {}
};
const loaded = new Function('module', 'exports', transformed.code);
loaded(context, context.exports);
const result = typeof context.exports.default === 'function' ? context.exports.default(...args) : context.exports.default;
if(expectedResult instanceof Error) {
throw new Error('expected error, but got result ' + JSON.stringify(result));
}
result.should.eql(expectedResult);
} catch(e) {
result = e;
if(expectedResult instanceof Error) {
e.message.should.eql(expectedResult.message);
}
else {
throw e;
}
}
if(expectedResult instanceof Error)
result.message.should.eql(expectedResult.message);
else
result.should.eql(expectedResult);
}

@@ -77,8 +81,14 @@

run("different-levels", ["same level used", "parent level used", "parent-parent level used", "child level cannot used", "child level cannot used"]);
run("macro-call-in-macro", ["foo", "bar"]);
run("macro-defined-in-macro", ["foo", "bar"]);
run("macro-call-in-macro", ["foo", "bar", "baz"]);
run("macro-defined-in-macro", ["foo", "bar", "baz"]);
run("wrong-scoped", new Error('BAR is not defined'));
run("redefine-submacro-in-call-scope", [["foo", "bar", "quux"], ["baz", "bat", "quux"]]);
run("redefine-submacro-in-call-scope", [["foo", "bar", "quux"], ["baz", "bat", "quux"], ["qwe", "asd", "quux"]]);
run("define-after-using-scoped", ["inner", "inner"]);
run("infinite-recursion-call", new Error('unknown: Maximum call stack size exceeded'));
run("self-recursion-call", new Error('unknown: Maximum call stack size exceeded'));
run("recursive-call", ["foo", "bar"]);
run("no-conflict-define-scope-with-call-scope", ["foo", "bar"]);
// @todo fix in https://github.com/codemix/babel-plugin-macros/issues/8
//run("execution-order-in-expression", [[1, 2], [1, 2], [1, 2]]);
});

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