frappe_docker/frappe-bench/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js
2017-07-31 15:51:51 +05:30

26 lines
No EOL
662 B
JavaScript

"use strict";
module.exports = function () {
return {
name: "transform-simplify-comparison-operators",
visitor: {
// simplify comparison operations if we're 100% certain
// that each value will always be of the same type
BinaryExpression(path) {
var node = path.node;
var op = node.operator;
if (op !== "===" && op !== "!==") {
return;
}
var left = path.get("left");
var right = path.get("right");
var strictMatch = left.baseTypeStrictlyMatches(right);
if (strictMatch) {
node.operator = node.operator.slice(0, -1);
}
}
}
};
};