enable es6.spec.symbols by default

This commit is contained in:
Sebastian McKenzie
2015-06-05 08:43:41 +01:00
parent 35ab4ffaab
commit f3acedbf08
12 changed files with 50 additions and 44 deletions

View File

@@ -2,11 +2,11 @@
"selfContained": "runtime",
"unicode-regex": "regex.unicode",
"spec.typeofSymbol": "es6.spec.symbols",
"es6.symbols": "es6.spec.symbols",
"es6.spec.symbols": "es6.symbols",
"es6.blockScopingTDZ": "es6.spec.blockScoping",
"utility.inlineExpressions": "minification.constantFolding",
"utility.deadCodeElimination": "minification.deadCodeElimination",
"utility.removeConsoleCalls": "minification.removeConsole",
"utility.removeDebugger": "minification.removeDebugger"
"utility.removeDebugger": "minification.removeDebugger",
}

View File

@@ -1,37 +0,0 @@
import * as t from "../../../types";
export var metadata = {
optional: true
};
export function UnaryExpression(node, parent, scope, file) {
if (node._ignoreSpecSymbols) return;
if (node.operator === "typeof") {
var call = t.callExpression(file.addHelper("typeof"), [node.argument]);
if (this.get("argument").isIdentifier()) {
var undefLiteral = t.literal("undefined");
var unary = t.unaryExpression("typeof", node.argument);
unary._ignoreSpecSymbols = true;
return t.conditionalExpression(
t.binaryExpression("===", unary, undefLiteral),
undefLiteral,
call
);
} else {
return call;
}
}
}
export function BinaryExpression(node, parent, scope, file) {
if (node.operator === "instanceof") {
return t.callExpression(file.addHelper("instanceof"), [node.left, node.right]);
}
}
export function VariableDeclaration(node) {
if (node._generated) this.skip();
}
export { VariableDeclaration as FunctionDeclaration };

View File

@@ -0,0 +1,44 @@
import * as t from "../../../types";
export var metadata = {
group: "builtin-pre"
};
const BINARY_COMPARISON_OPERATORS = ["!=", "==", "!==", "==="];
export function UnaryExpression(node, parent, scope, file) {
if (node._ignoreSpecSymbols || node.operator !== "typeof") return;
if (t.isBinaryExpression(parent) && BINARY_COMPARISON_OPERATORS.indexOf(parent.operator) >= 0 && t.isLiteral(parent.right)) {
// don't touch binary comparisons with a string that doesn't equal symbol, we can statically determine
// that this condition will never be met which means faster code!
if (parent.right.value !== "symbol") return;
}
var call = t.callExpression(file.addHelper("typeof"), [node.argument]);
if (this.get("argument").isIdentifier()) {
var undefLiteral = t.literal("undefined");
var unary = t.unaryExpression("typeof", node.argument);
unary._ignoreSpecSymbols = true;
return t.conditionalExpression(
t.binaryExpression("===", unary, undefLiteral),
undefLiteral,
call
);
} else {
return call;
}
}
export function BinaryExpression(node, parent, scope, file) {
if (node.operator === "instanceof") {
return t.callExpression(file.addHelper("instanceof"), [node.left, node.right]);
}
}
export function VariableDeclaration(node) {
if (node._generated) this.skip();
}
export { VariableDeclaration as FunctionDeclaration };

View File

@@ -16,6 +16,7 @@ export default {
"spec.functionName": require("./spec/function-name"),
"es6.spec.templateLiterals": require("./es6/spec.template-literals"),
"es6.templateLiterals": require("./es6/template-literals"),
"es6.symbols": require("./es6/symbols"),
//- builtin-basic
// this is where the bulk of the ES6 transformations take place, none of them require traversal state
@@ -51,7 +52,6 @@ export default {
"es7.exportExtensions": require("./es7/export-extensions"),
"spec.protoToAssign": require("./spec/proto-to-assign"),
"es7.doExpressions": require("./es7/do-expressions"),
"es6.spec.symbols": require("./es6/spec.symbols"),
"es7.functionBind": require("./es7/function-bind"),
"spec.undefinedToVoid": require("./spec/undefined-to-void"),