Skip to content

Commit

Permalink
binding voilations check during es2015 transform[fix #630] (#633)
Browse files Browse the repository at this point in the history
* binding voilations check during es2015 transform[fix #630]

* add tests along with es2015

* fix dev deps
  • Loading branch information
vigneshshanmugam authored and boopathi committed Jul 17, 2017
1 parent 6f0c1dc commit 123eaf5
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"babel-jest": "^20.0.3",
"babel-plugin-transform-es2015-block-scoping": "^6.24.1",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-traverse": "^6.25.0",
"butternut": "^0.4.6",
"bytes": "^2.5.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-plugin-transform-remove-undefined/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function hasViolation(declarator, scope, start) {
const scopeParent = declarator.getFunctionParent();

const violation = binding.constantViolations.some(v => {
// https://github.com/babel/babili/issues/630
if (!v.node) {
return false;
}
// return 'true' if we cannot guarantee the violation references
// the initialized identifier after
const violationStart = v.node.start;
Expand Down
29 changes: 29 additions & 0 deletions packages/babel-preset-babili/__tests__/babili-es2015-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
jest.autoMockOff();

const es2015 = require("babel-preset-es2015");
const babili = require("../src/index");

const thePlugin = require("../../../utils/test-transform")(null, {
plugins: [],
minified: false,
presets: [babili, es2015]
});

describe("preset along with es2015", () => {
thePlugin(
"should fix issue #630",
`
const obj = {cat: 'dog'};
let cat;
({cat} = obj);
`,
`
'use strict';
var cat,
obj = { cat: 'dog' },
_obj = obj;
cat = _obj.cat, _obj;
`
);
});
4 changes: 1 addition & 3 deletions packages/babel-preset-babili/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"author": "amasad",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"babel-preset"
],
"keywords": ["babel-preset"],
"dependencies": {
"babel-plugin-minify-builtins": "^0.1.3",
"babel-plugin-minify-constant-folding": "^0.1.3",
Expand Down
Loading

0 comments on commit 123eaf5

Please sign in to comment.