Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
175aa88
Replace `x != undefined` with `x != null`
j-f1 Jun 7, 2017
9801c15
Create eqnull-test.js
j-f1 Jun 8, 2017
f2b350b
Minify `null != null`, `undefined == null`, etc.
j-f1 Jun 8, 2017
e9d86bc
Test undefined == undefined
j-f1 Jun 8, 2017
4d27ae8
Include babel-types
j-f1 Jun 8, 2017
fa02b57
Fix a typo
j-f1 Jun 8, 2017
6e5adfd
Semicolons in tests
j-f1 Jun 8, 2017
e9a6a72
Remove unused require
j-f1 Jun 8, 2017
e0bc92b
Node 4 support
j-f1 Jun 8, 2017
387de4f
npm run format
j-f1 Jun 8, 2017
df499a3
Remove unwanted transform
j-f1 Jun 10, 2017
0f6b6d8
🔥 unused variable
j-f1 Jun 10, 2017
9a92d0e
`void <something>` is `undefined` too
j-f1 Jun 13, 2017
a6a37ba
Restore eqnull-test.js
j-f1 Jun 13, 2017
7be00f7
Only include pure `void` expressions
j-f1 Jun 13, 2017
4599d9d
Fix scope
j-f1 Jun 13, 2017
fc230db
npm run format
j-f1 Jun 13, 2017
ce25575
Remove unused `unpad`
j-f1 Jun 29, 2017
3d40ba5
Transform `undefined` to `null` on both sides of the ==
j-f1 Aug 7, 2017
7c4ea21
Merge remote-tracking branch 'babel/master' into patch-1
j-f1 Aug 17, 2017
5389834
thePlugin
j-f1 Aug 17, 2017
fa150db
Check if there’s a variable named `undefined` before transforming
j-f1 Aug 17, 2017
cb20df5
t.isFoo(path.node) → path.isFoo()
j-f1 Aug 17, 2017
4abca15
npm run format
j-f1 Aug 17, 2017
92de46d
🔥 undefinedToNull returns
j-f1 Aug 17, 2017
d61ccaa
Merge remote-tracking branch 'upstream/master' into patch-1
j-f1 Nov 18, 2017
6b921fe
Move the feature to simplify
j-f1 Nov 18, 2017
68e21f9
Use test fixtures
j-f1 Nov 18, 2017
4e96f58
Merge branch 'master' into patch-1
j-f1 Apr 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x == undefined;
x == void 0;
x === undefined;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x == null, x == null, x === undefined;
24 changes: 24 additions & 0 deletions packages/babel-plugin-minify-simplify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ module.exports = ({ types: t }) => {
]
},

BinaryExpression(path) {
if (["!=", "=="].indexOf(path.node.operator) !== -1) {
undefinedToNull(path.get("left"));
undefinedToNull(path.get("right"));
}
},

LogicalExpression: {
exit: logicalExpression.simplifyPatterns
},
Expand Down Expand Up @@ -1141,4 +1148,21 @@ module.exports = ({ types: t }) => {
function isAncestor(path1, path2) {
return !!path2.findParent(parent => parent === path1);
}

function isPureVoid(path) {
return path.isUnaryExpression({ operator: "void" }) && path.isPure();
}

function isGlobalUndefined(path) {
return (
path.isIdentifier({ name: "undefined" }) &&
!path.scope.getBinding("undefined")
);
}

function undefinedToNull(path) {
if (isGlobalUndefined(path) || isPureVoid(path)) {
path.replaceWith(t.nullLiteral());
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = function({ types: t }) {
BinaryExpression(path) {
const { node } = path;
const op = node.operator;

if (op !== "===" && op !== "!==") {
return;
}
Expand Down