Merge pull request #1472 from babel/single-pass
Merge internal transformers into single traversal pass
This commit is contained in:
commit
61ba8ad997
@ -191,7 +191,7 @@ export function VariableDeclaration(node, print, parent) {
|
||||
}
|
||||
|
||||
var sep = ",";
|
||||
if (!this.format.compact && hasInits && !this.format.retainLines) {
|
||||
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) {
|
||||
sep += `\n${repeating(" ", node.kind.length + 1)}`;
|
||||
} else {
|
||||
sep += " ";
|
||||
|
||||
@ -4,6 +4,7 @@ import moduleFormatters from "../modules";
|
||||
import PluginManager from "./plugin-manager";
|
||||
import shebangRegex from "shebang-regex";
|
||||
import TraversalPath from "../../traversal/path";
|
||||
import Transformer from "../transformer";
|
||||
import isFunction from "lodash/lang/isFunction";
|
||||
import isAbsolute from "path-is-absolute";
|
||||
import resolveRc from "../../tools/resolve-rc";
|
||||
@ -26,21 +27,10 @@ import path from "path";
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../../types";
|
||||
|
||||
var checkTransformerVisitor = {
|
||||
exit(node, parent, scope, state) {
|
||||
checkPath(state.stack, this);
|
||||
}
|
||||
};
|
||||
|
||||
function checkPath(stack, path) {
|
||||
each(stack, function (pass) {
|
||||
if (pass.shouldRun || pass.ran) return;
|
||||
pass.checkPath(path);
|
||||
});
|
||||
}
|
||||
|
||||
export default class File {
|
||||
constructor(opts = {}, pipeline) {
|
||||
this.transformerDependencies = {};
|
||||
|
||||
this.dynamicImportTypes = {};
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImports = [];
|
||||
@ -96,10 +86,7 @@ export default class File {
|
||||
"interop-require",
|
||||
];
|
||||
|
||||
static soloHelpers = [
|
||||
"ludicrous-proxy-create",
|
||||
"ludicrous-proxy-directory"
|
||||
];
|
||||
static soloHelpers = [];
|
||||
|
||||
static options = require("./options");
|
||||
|
||||
@ -233,8 +220,55 @@ export default class File {
|
||||
}
|
||||
stack = beforePlugins.concat(stack, afterPlugins);
|
||||
|
||||
// register
|
||||
this.transformerStack = stack.concat(secondaryStack);
|
||||
// build transformer stack
|
||||
this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack);
|
||||
|
||||
// build dependency graph
|
||||
for (var pass of (stack: Array)) {
|
||||
for (var dep of (pass.transformer.dependencies: Array)) {
|
||||
this.transformerDependencies[dep] = pass.key;
|
||||
}
|
||||
}
|
||||
|
||||
// collapse stack categories
|
||||
this.transformerStack = this.collapseStack(stack);
|
||||
}
|
||||
|
||||
collapseStack(_stack) {
|
||||
var stack = [];
|
||||
var ignore = [];
|
||||
|
||||
for (let pass of (_stack: Array)) {
|
||||
// been merged
|
||||
if (ignore.indexOf(pass) >= 0) continue;
|
||||
|
||||
var group = pass.transformer.metadata.group;
|
||||
|
||||
// can't merge
|
||||
if (!pass.canTransform() || !group) {
|
||||
stack.push(pass);
|
||||
continue;
|
||||
}
|
||||
|
||||
var mergeStack = [];
|
||||
for (let pass of (_stack: Array)) {
|
||||
if (pass.transformer.metadata.group === group) {
|
||||
mergeStack.push(pass);
|
||||
ignore.push(pass);
|
||||
}
|
||||
}
|
||||
|
||||
var visitors = [];
|
||||
for (let pass of (mergeStack: Array)) {
|
||||
visitors.push(pass.handlers);
|
||||
}
|
||||
var visitor = traverse.visitors.merge(visitors);
|
||||
var mergeTransformer = new Transformer(group, visitor);
|
||||
//console.log(mergeTransformer);
|
||||
stack.push(mergeTransformer.buildPass(this));
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
set(key: string, val): any {
|
||||
@ -358,23 +392,6 @@ export default class File {
|
||||
return err;
|
||||
}
|
||||
|
||||
checkPath(path) {
|
||||
if (Array.isArray(path)) {
|
||||
for (var i = 0; i < path.length; i++) {
|
||||
this.checkPath(path[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var stack = this.transformerStack;
|
||||
|
||||
checkPath(stack, path);
|
||||
|
||||
path.traverse(checkTransformerVisitor, {
|
||||
stack: stack
|
||||
});
|
||||
}
|
||||
|
||||
mergeSourceMap(map: Object) {
|
||||
var opts = this.opts;
|
||||
|
||||
@ -462,10 +479,6 @@ export default class File {
|
||||
this._addAst(ast);
|
||||
this.log.debug("End set AST");
|
||||
|
||||
this.log.debug("Start prepass");
|
||||
this.checkPath(this.path);
|
||||
this.log.debug("End prepass");
|
||||
|
||||
this.log.debug("Start module formatter init");
|
||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
||||
@ -541,10 +554,8 @@ export default class File {
|
||||
}
|
||||
|
||||
call(key: string) {
|
||||
var stack = this.transformerStack;
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
var transformer = stack[i].transformer;
|
||||
var fn = transformer[key];
|
||||
for (var pass of (this.uncollapsedTransformerStack: Array)) {
|
||||
var fn = pass.transformer[key];
|
||||
if (fn) fn(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,10 +10,6 @@ export default function (exports, opts) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
};
|
||||
|
||||
exports.shouldVisit = function (node) {
|
||||
return node.operator && (node.operator === opts.operator || node.operator === opts.operator + "=");
|
||||
};
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
// hit the `AssignmentExpression` one below
|
||||
if (this.isCompletionRecord()) return;
|
||||
|
||||
@ -10,12 +10,6 @@ import * as react from "./react";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (exports, opts) {
|
||||
exports.shouldVisit = function (node) {
|
||||
if (t.isJSX(node)) return true;
|
||||
if (react.isCreateClass(node)) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.JSXIdentifier = function (node, parent) {
|
||||
if (node.name === "this" && this.isReferenced()) {
|
||||
return t.thisExpression();
|
||||
|
||||
@ -5,6 +5,13 @@ var pipeline = new Pipeline;
|
||||
//
|
||||
|
||||
import transformers from "./transformers";
|
||||
|
||||
for (var key in transformers) {
|
||||
var transformer = transformers[key];
|
||||
var metadata = transformer.metadata = transformer.metadata || {};
|
||||
metadata.group = metadata.group || "builtin-basic";
|
||||
}
|
||||
|
||||
pipeline.addTransformers(transformers);
|
||||
|
||||
//
|
||||
|
||||
@ -1 +0,0 @@
|
||||
Object(RIGHT)[LEFT] !== undefined;
|
||||
@ -1,4 +0,0 @@
|
||||
(function (proxy, directory) {
|
||||
directory.push(proxy);
|
||||
return proxy;
|
||||
})
|
||||
@ -1 +0,0 @@
|
||||
[];
|
||||
@ -8,34 +8,26 @@ import traverse from "../traversal";
|
||||
|
||||
export default class TransformerPass {
|
||||
constructor(file: File, transformer: Transformer) {
|
||||
this.shouldTransform = !transformer.shouldVisit;
|
||||
this.transformer = transformer;
|
||||
this.handlers = transformer.handlers;
|
||||
this.skipKey = transformer.skipKey;
|
||||
this.file = file;
|
||||
this.ran = false;
|
||||
this.transformer = transformer;
|
||||
this.handlers = transformer.handlers;
|
||||
this.file = file;
|
||||
this.ran = false;
|
||||
this.key = transformer.key;
|
||||
}
|
||||
|
||||
canTransform(): boolean {
|
||||
return this.file.pipeline.canTransform(this.transformer, this.file.opts);
|
||||
}
|
||||
|
||||
checkPath(path: TraversalPath): boolean {
|
||||
if (this.shouldTransform || this.ran) return;
|
||||
|
||||
this.shouldTransform = this.transformer.shouldVisit(path.node);
|
||||
return this.file.transformerDependencies[this.key] ||
|
||||
this.file.pipeline.canTransform(this.transformer, this.file.opts);
|
||||
}
|
||||
|
||||
transform() {
|
||||
if (!this.shouldTransform) return;
|
||||
|
||||
var file = this.file;
|
||||
|
||||
file.log.debug(`Start transformer ${this.transformer.key}`);
|
||||
file.log.debug(`Start transformer ${this.key}`);
|
||||
|
||||
traverse(file.ast, this.handlers, file.scope, file);
|
||||
|
||||
file.log.debug(`Finish transformer ${this.transformer.key}`);
|
||||
file.log.debug(`Finish transformer ${this.key}`);
|
||||
|
||||
this.ran = true;
|
||||
}
|
||||
|
||||
@ -25,8 +25,8 @@ export default class Transformer {
|
||||
};
|
||||
|
||||
this.manipulateOptions = take("manipulateOptions");
|
||||
this.shouldVisit = take("shouldVisit");
|
||||
this.metadata = take("metadata") || {};
|
||||
this.dependencies = this.metadata.dependencies || [];
|
||||
this.parser = take("parser");
|
||||
this.post = take("post");
|
||||
this.pre = take("pre");
|
||||
@ -41,18 +41,6 @@ export default class Transformer {
|
||||
|
||||
this.handlers = this.normalize(transformer);
|
||||
this.key = transformerKey;
|
||||
|
||||
//
|
||||
|
||||
if (!this.shouldVisit && !this.handlers.enter && !this.handlers.exit) {
|
||||
var types = Object.keys(this.handlers);
|
||||
this.shouldVisit = function (node) {
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
if (node.type === types[i]) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
normalize(transformer: Object): Object {
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function MemberExpression(node) {
|
||||
var prop = node.property;
|
||||
if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
||||
// foo.default -> foo["default"]
|
||||
node.property = t.literal(prop.name);
|
||||
node.computed = true;
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var MemberExpression = {
|
||||
exit(node) {
|
||||
var prop = node.property;
|
||||
if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
||||
// foo.default -> foo["default"]
|
||||
node.property = t.literal(prop.name);
|
||||
node.computed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function Property(node) {
|
||||
var key = node.key;
|
||||
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||
// default: "bar" -> "default": "bar"
|
||||
node.key = t.literal(key.name);
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var Property = {
|
||||
exit(node) {
|
||||
var key = node.key;
|
||||
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||
// default: "bar" -> "default": "bar"
|
||||
node.key = t.literal(key.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isProperty(node) && (node.kind === "get" || node.kind === "set");
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isArrowFunctionExpression;
|
||||
|
||||
export function ArrowFunctionExpression(node) {
|
||||
t.ensureBlock(node);
|
||||
|
||||
|
||||
@ -37,9 +37,9 @@ function standardizeLets(declars) {
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind === "let" || node.kind === "const");
|
||||
}
|
||||
export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function VariableDeclaration(node, parent, scope, file) {
|
||||
if (!isLet(node, parent)) return;
|
||||
@ -233,6 +233,7 @@ var loopVisitor = {
|
||||
|
||||
if (replace) {
|
||||
replace = t.returnStatement(replace);
|
||||
this.skip();
|
||||
return t.inherits(replace, node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,8 +11,6 @@ import * as t from "../../../types";
|
||||
|
||||
const PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties";
|
||||
|
||||
export var shouldVisit = t.isClass;
|
||||
|
||||
export function ClassDeclaration(node, parent, scope, file) {
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isVariableDeclaration(node, { kind: "const" }) || t.isImportDeclaration(node);
|
||||
}
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isAssignmentExpression() || this.isUpdateExpression()) {
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isPattern;
|
||||
export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
@ -83,7 +85,6 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
export function CatchClause(node, parent, scope, file) {
|
||||
@ -104,8 +105,6 @@ export function CatchClause(node, parent, scope, file) {
|
||||
destructuring.init(pattern, ref);
|
||||
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
|
||||
this.checkSelf();
|
||||
}
|
||||
|
||||
export function ExpressionStatement(node, parent, scope, file) {
|
||||
|
||||
@ -2,8 +2,6 @@ import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isForOfStatement;
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
if (this.get("right").isArrayExpression()) {
|
||||
return _ForOfStatementArray.call(this, node, scope, file);
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export { shouldVisit } from "../internal/modules";
|
||||
|
||||
function keepBlockHoist(node, nodes) {
|
||||
if (node._blockHoist) {
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
@ -10,6 +8,10 @@ function keepBlockHoist(node, nodes) {
|
||||
}
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-modules"
|
||||
};
|
||||
|
||||
export function ImportDeclaration(node, parent, scope, file) {
|
||||
// flow type
|
||||
if (node.isType) return;
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import ReplaceSupers from "../../helpers/replace-supers";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isSuper;
|
||||
|
||||
function Property(path, node, scope, getObjectRef, file) {
|
||||
if (!node.method) return;
|
||||
|
||||
|
||||
@ -3,10 +3,6 @@ import * as util from "../../../util";
|
||||
import traverse from "../../../traversal";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isFunction(node) && hasDefaults(node);
|
||||
}
|
||||
|
||||
var hasDefaults = function (node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
if (!t.isIdentifier(node.params[i])) return true;
|
||||
@ -96,6 +92,4 @@ exports.Function = function (node, parent, scope, file) {
|
||||
} else {
|
||||
node.body.body = body.concat(node.body.body);
|
||||
}
|
||||
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
@ -2,8 +2,6 @@ import isNumber from "lodash/lang/isNumber";
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isRestElement;
|
||||
|
||||
var memberExpressionOptimisationVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// check if this scope has a local binding that will shadow the rest parameter
|
||||
@ -96,7 +94,6 @@ exports.Function = function (node, parent, scope, file) {
|
||||
candidate.replaceWith(argsId);
|
||||
optimizeMemberExpression(candidate.parent, node.params.length);
|
||||
}
|
||||
this.checkSelf();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -138,5 +135,4 @@ exports.Function = function (node, parent, scope, file) {
|
||||
});
|
||||
loop._blockHoist = node.params.length + 1;
|
||||
node.body.body.unshift(loop);
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
@ -63,42 +63,40 @@ function spec(node, body, objId, initProps, file) {
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isProperty(node) && node.computed;
|
||||
}
|
||||
export var ObjectExpression = {
|
||||
exit(node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
for (var prop of (node.properties: Array)) {
|
||||
hasComputed = t.isProperty(prop, { computed: true, kind: "init" });
|
||||
if (hasComputed) break;
|
||||
}
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
|
||||
if (hasComputed) break;
|
||||
if (!hasComputed) return;
|
||||
|
||||
var initProps = [];
|
||||
var objId = scope.generateUidBasedOnNode(parent);
|
||||
|
||||
//
|
||||
|
||||
var body = [];
|
||||
|
||||
//
|
||||
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.properties.computed")) callback = loose;
|
||||
|
||||
var result = callback(node, body, objId, initProps, file);
|
||||
if (result) return result;
|
||||
|
||||
//
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, t.objectExpression(initProps))
|
||||
]));
|
||||
|
||||
body.push(t.expressionStatement(objId));
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
if (!hasComputed) return;
|
||||
|
||||
var initProps = [];
|
||||
var objId = scope.generateUidBasedOnNode(parent);
|
||||
|
||||
//
|
||||
|
||||
var body = [];
|
||||
|
||||
//
|
||||
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.properties.computed")) callback = loose;
|
||||
|
||||
var result = callback(node, body, objId, initProps, file);
|
||||
if (result) return result;
|
||||
|
||||
//
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, t.objectExpression(initProps))
|
||||
]));
|
||||
|
||||
body.push(t.expressionStatement(objId));
|
||||
|
||||
return body;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isProperty(node) && (node.method || node.shorthand);
|
||||
}
|
||||
|
||||
export function Property(node) {
|
||||
if (node.method) {
|
||||
node.method = false;
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import * as regex from "../../helpers/regex";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return regex.is(node, "y");
|
||||
}
|
||||
|
||||
export function Literal(node) {
|
||||
if (!regex.is(node, "y")) return;
|
||||
return t.newExpression(t.identifier("RegExp"), [
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import rewritePattern from "regexpu/rewrite-pattern";
|
||||
import * as regex from "../../helpers/regex";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return regex.is(node, "u");
|
||||
}
|
||||
|
||||
export function Literal(node) {
|
||||
if (!regex.is(node, "u")) return;
|
||||
node.regex.pattern = rewritePattern(node.regex.pattern, node.regex.flags);
|
||||
|
||||
@ -28,17 +28,20 @@ var visitor = traverse.explode({
|
||||
});
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function BlockStatement(node, parent, scope, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
export var BlockStatement = {
|
||||
exit(node, parent, scope, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
|
||||
this.traverse(visitor, {
|
||||
letRefs: letRefs,
|
||||
file: file
|
||||
});
|
||||
}
|
||||
this.traverse(visitor, {
|
||||
letRefs: letRefs,
|
||||
file: file
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export { BlockStatement as Program, BlockStatement as Loop };
|
||||
|
||||
@ -44,8 +44,6 @@ function build(props, scope) {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
export var shouldVisit = t.isSpreadElement;
|
||||
|
||||
export function ArrayExpression(node, parent, scope) {
|
||||
var elements = node.elements;
|
||||
if (!hasSpread(elements)) return;
|
||||
|
||||
@ -6,6 +6,10 @@ import * as util from "../../../util";
|
||||
import map from "lodash/collection/map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
if (node.generator || node.async) return;
|
||||
var tailCall = new TailCallTransformer(this, scope, file);
|
||||
|
||||
@ -4,10 +4,6 @@ var buildBinaryExpression = function (left, right) {
|
||||
return t.binaryExpression("+", left, right);
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isTemplateLiteral(node) || t.isTaggedTemplateExpression(node);
|
||||
}
|
||||
|
||||
export function TaggedTemplateExpression(node, parent, scope, file) {
|
||||
var quasi = node.quasi;
|
||||
var args = [];
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
export var metadata = {
|
||||
stage: 0
|
||||
stage: 0,
|
||||
dependencies: ["es6.classes"]
|
||||
};
|
||||
|
||||
export function shouldVisit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3,14 +3,11 @@ import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
dependencies: ["es6.classes"],
|
||||
optional: true,
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return !!node.decorators;
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var hasDecorators = false;
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
|
||||
@ -5,8 +5,6 @@ export var metadata = {
|
||||
stage: 0
|
||||
};
|
||||
|
||||
export var shouldVisit = t.isDoExpression;
|
||||
|
||||
export function DoExpression(node) {
|
||||
var body = node.body.body;
|
||||
if (body.length) {
|
||||
|
||||
@ -6,10 +6,6 @@ export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isExportDefaultSpecifier(node) || t.isExportNamespaceSpecifier(node);
|
||||
}
|
||||
|
||||
function build(node, nodes, scope) {
|
||||
var first = node.specifiers[0];
|
||||
if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
|
||||
|
||||
@ -3,13 +3,10 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
stage: 1
|
||||
stage: 1,
|
||||
dependencies: ["es6.destructuring"]
|
||||
};
|
||||
|
||||
export function manipulateOptions(opts) {
|
||||
if (opts.whitelist) opts.whitelist.push("es6.destructuring");
|
||||
}
|
||||
|
||||
var hasSpread = function (node) {
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
if (t.isSpreadProperty(node.properties[i])) {
|
||||
|
||||
@ -1,7 +1,3 @@
|
||||
export var metadata = {
|
||||
stage: 1
|
||||
};
|
||||
|
||||
export function shouldVisit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,124 +1,84 @@
|
||||
export default {
|
||||
//- builtin-setup
|
||||
_validation: require("./internal/validation"),
|
||||
_hoistDirectives: require("./internal/hoist-directives"),
|
||||
"utility.removeDebugger": require("./utility/remove-debugger"),
|
||||
"utility.removeConsole": require("./utility/remove-console"),
|
||||
|
||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
||||
|
||||
"minification.deadCodeElimination": require("./minification/dead-code-elimination"),
|
||||
|
||||
_modules: require("./internal/modules"),
|
||||
"spec.functionName": require("./spec/function-name"),
|
||||
|
||||
//- builtin-basic
|
||||
// this is where the bulk of the ES6 transformations take place, none of them require traversal state
|
||||
// so they can all be concatenated together for performance
|
||||
"es7.classProperties": require("./es7/class-properties"),
|
||||
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
|
||||
"es7.asyncFunctions": require("./es7/async-functions"),
|
||||
"es7.decorators": require("./es7/decorators"),
|
||||
|
||||
strict: require("./other/strict"),
|
||||
|
||||
_validation: require("./internal/validation"),
|
||||
|
||||
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
|
||||
"validation.react": require("./validation/react"),
|
||||
|
||||
// this goes at the start so we only transform the original user code
|
||||
"spec.functionName": require("./spec/function-name"),
|
||||
|
||||
// needs to be before `_shadowFunctions`
|
||||
"es6.arrowFunctions": require("./es6/arrow-functions"),
|
||||
|
||||
"spec.blockScopedFunctions": require("./spec/block-scoped-functions"),
|
||||
|
||||
"optimisation.react.constantElements": require("./optimisation/react.constant-elements"),
|
||||
"optimisation.react.inlineElements": require("./optimisation/react.inline-elements"),
|
||||
reactCompat: require("./other/react-compat"),
|
||||
react: require("./other/react"),
|
||||
|
||||
// needs to be before `regenerator` due to generator comprehensions
|
||||
// needs to be before `_shadowFunctions`
|
||||
"es7.comprehensions": require("./es7/comprehensions"),
|
||||
|
||||
"es6.classes": require("./es6/classes"),
|
||||
|
||||
asyncToGenerator: require("./other/async-to-generator"),
|
||||
bluebirdCoroutines: require("./other/bluebird-coroutines"),
|
||||
|
||||
"es6.objectSuper": require("./es6/object-super"),
|
||||
"es7.objectRestSpread": require("./es7/object-rest-spread"),
|
||||
"es7.exponentiationOperator": require("./es7/exponentiation-operator"),
|
||||
|
||||
"es6.spec.templateLiterals": require("./es6/spec.template-literals"),
|
||||
"es6.templateLiterals": require("./es6/template-literals"),
|
||||
|
||||
"es5.properties.mutators": require("./es5/properties.mutators"),
|
||||
"es6.properties.shorthand": require("./es6/properties.shorthand"),
|
||||
|
||||
// needs to be before `_shadowFunctions` due to define property closure
|
||||
"es6.properties.computed": require("./es6/properties.computed"),
|
||||
|
||||
"optimisation.flow.forOf": require("./optimisation/flow.for-of"),
|
||||
"es6.forOf": require("./es6/for-of"),
|
||||
|
||||
"es6.regex.sticky": require("./es6/regex.sticky"),
|
||||
"es6.regex.unicode": require("./es6/regex.unicode"),
|
||||
|
||||
"es6.constants": require("./es6/constants"),
|
||||
|
||||
// needs to be before `es6.parameters.default` as default parameters will destroy the rest param
|
||||
"es6.parameters.rest": require("./es6/parameters.rest"),
|
||||
|
||||
// needs to be after `es6.parameters.rest` as we use `toArray` and avoid turning an already known array into one
|
||||
"es6.spread": require("./es6/spread"),
|
||||
|
||||
// needs to be before `es6.blockScoping` as default parameters have a TDZ
|
||||
"es6.parameters.default": require("./es6/parameters.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"),
|
||||
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
|
||||
jscript: require("./other/jscript"),
|
||||
flow: require("./other/flow"),
|
||||
|
||||
// needs to be before `es6.blockScoping` as let variables may be produced
|
||||
//- builtin-advanced
|
||||
"es6.destructuring": require("./es6/destructuring"),
|
||||
|
||||
// needs to be before `_shadowFunctions` due to block scopes sometimes being wrapped in a
|
||||
// closure
|
||||
"es6.blockScoping": require("./es6/block-scoping"),
|
||||
|
||||
// needs to be after `es6.blockScoping` due to needing `letReferences` set on blocks
|
||||
"es6.spec.blockScoping": require("./es6/spec.block-scoping"),
|
||||
|
||||
// needs to be after `es6.parameters.*` and `es6.blockScoping` due to needing pure
|
||||
// identifiers in parameters and variable declarators
|
||||
"es6.tailCall": require("./es6/tail-call"),
|
||||
// es6 syntax transformation is **forbidden** past this point since regenerator will chuck a massive
|
||||
// hissy fit
|
||||
|
||||
//- regenerator
|
||||
regenerator: require("./other/regenerator"),
|
||||
|
||||
// needs to be after `regenerator` due to needing `regeneratorRuntime` references
|
||||
// needs to be after `es6.forOf` due to needing `Symbol.iterator` references
|
||||
// needs to be before `es6.modules` due to dynamic imports
|
||||
runtime: require("./other/runtime"),
|
||||
|
||||
// needs to be before `_blockHoist` due to function hoisting etc
|
||||
"es7.exportExtensions": require("./es7/export-extensions"),
|
||||
//- builtin-modules
|
||||
runtime: require("./other/runtime"),
|
||||
"es6.modules": require("./es6/modules"),
|
||||
|
||||
_blockHoist: require("./internal/block-hoist"),
|
||||
|
||||
"spec.protoToAssign": require("./spec/proto-to-assign"),
|
||||
|
||||
_shadowFunctions: require("./internal/shadow-functions"),
|
||||
|
||||
"es7.doExpressions": require("./es7/do-expressions"),
|
||||
|
||||
"es6.spec.symbols": require("./es6/spec.symbols"),
|
||||
ludicrous: require("./other/ludicrous"),
|
||||
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
|
||||
|
||||
_strict: require("./internal/strict"),
|
||||
_moduleFormatter: require("./internal/module-formatter"),
|
||||
|
||||
//- builtin-trailing
|
||||
// these clean up the output and do finishing up transformations, it's important to note that by this
|
||||
// stage you can't import any new modules or insert new ES6 as all those transformers have already
|
||||
// been ran
|
||||
"es6.tailCall": require("./es6/tail-call"),
|
||||
_shadowFunctions: require("./internal/shadow-functions"),
|
||||
"es3.propertyLiterals": require("./es3/property-literals"),
|
||||
"es3.memberExpressionLiterals": require("./es3/member-expression-literals"),
|
||||
|
||||
"minification.memberExpressionLiterals": require("./minification/member-expression-literals"),
|
||||
"minification.propertyLiterals": require("./minification/property-literals"),
|
||||
|
||||
jscript: require("./other/jscript"),
|
||||
flow: require("./other/flow")
|
||||
_blockHoist: require("./internal/block-hoist"),
|
||||
};
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import sortBy from "lodash/collection/sortBy";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
// Priority:
|
||||
//
|
||||
// - 0 We want this to be at the **very** bottom
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export var BlockStatement = {
|
||||
exit(node) {
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) {
|
||||
bodyNode._blockHoist = Infinity;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export { BlockStatement as Program };
|
||||
@ -1,15 +1,24 @@
|
||||
import * as strict from "../../helpers/strict";
|
||||
|
||||
export function Program(program, parent, scope, file) {
|
||||
this.stop();
|
||||
export var metadata = {
|
||||
group: "builtin-modules"
|
||||
};
|
||||
|
||||
strict.wrap(program, function () {
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
export var Program = {
|
||||
exit(program, parent, scope, file) {
|
||||
strict.wrap(program, function () {
|
||||
// ensure that these are at the top, just like normal imports
|
||||
for (var node of (file.dynamicImports: Array)) {
|
||||
node._blockHoist = 3;
|
||||
}
|
||||
|
||||
if (!file.transformers["es6.modules"].canTransform()) return;
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(program);
|
||||
if (!file.transformers["es6.modules"].canTransform()) return;
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(program);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isImportDeclaration(node) || t.isExportDeclaration(node);
|
||||
}
|
||||
export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ImportDeclaration(node, parent, scope, file) {
|
||||
if (node.source) {
|
||||
|
||||
@ -82,15 +82,18 @@ function aliasFunction(getBody, path, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return true;
|
||||
}
|
||||
// todo: on all `this` and `arguments`, walk UP the tree instead of
|
||||
// crawling the entire function tree
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export function Program(node, parent, scope) {
|
||||
aliasFunction(function () {
|
||||
return node.body;
|
||||
}, this, scope);
|
||||
};
|
||||
}
|
||||
|
||||
export function FunctionDeclaration(node, parent, scope) {
|
||||
aliasFunction(function () {
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function Program(program, parent, scope, file) {
|
||||
if (file.transformers.strict.canTransform()) {
|
||||
var directive = file.get("existingStrictDirective");
|
||||
|
||||
if (!directive) {
|
||||
directive = t.expressionStatement(t.literal("use strict"));
|
||||
var first = program.body[0];
|
||||
if (first) {
|
||||
directive.leadingComments = first.leadingComments;
|
||||
first.leadingComments = [];
|
||||
}
|
||||
}
|
||||
|
||||
this.unshiftContainer("body", [directive]);
|
||||
}
|
||||
this.stop();
|
||||
}
|
||||
@ -2,7 +2,7 @@ import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
readOnly: true
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
@ -43,16 +43,3 @@ export function Property(node, parent, scope, file) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function BlockStatement(node) {
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) {
|
||||
bodyNode._blockHoist = Infinity;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { BlockStatement as Program };
|
||||
|
||||
@ -18,7 +18,8 @@ function toStatements(node) {
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function Identifier(node, parent, scope) {
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export function MemberExpression(node) {
|
||||
var prop = node.property;
|
||||
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
|
||||
// foo["bar"] => foo.bar
|
||||
node.property = t.identifier(prop.value);
|
||||
node.computed = false;
|
||||
export var MemberExpression = {
|
||||
exit(node) {
|
||||
var prop = node.property;
|
||||
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
|
||||
// foo["bar"] => foo.bar
|
||||
node.property = t.identifier(prop.value);
|
||||
node.computed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export function Property(node) {
|
||||
var key = node.key;
|
||||
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
|
||||
// "foo": "bar" -> foo: "bar"
|
||||
node.key = t.identifier(key.value);
|
||||
node.computed = false;
|
||||
export var Property = {
|
||||
exit(node) {
|
||||
var key = node.key;
|
||||
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
|
||||
// "foo": "bar" -> foo: "bar"
|
||||
node.key = t.identifier(key.value);
|
||||
node.computed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { _ForOfStatementArray } from "../es6/for-of";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isForOfStatement;
|
||||
export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
@ -3,7 +3,8 @@ import remapAsyncToGenerator from "../../helpers/remap-async-to-generator";
|
||||
export { manipulateOptions } from "./bluebird-coroutines";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
@ -2,12 +2,12 @@ import remapAsyncToGenerator from "../../helpers/remap-async-to-generator";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function manipulateOptions(opts) {
|
||||
opts.optional.push("es7.asyncFunctions");
|
||||
opts.blacklist.push("regenerator");
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
@ -1,16 +1,11 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return node.isType || node.optional || node.implements || node.typeAnnotation || t.isFlow(node);
|
||||
}
|
||||
|
||||
export function Flow(node) {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
export function ClassProperty(node) {
|
||||
node.typeAnnotation = null;
|
||||
if (!node.value) this.remove();
|
||||
}
|
||||
|
||||
export function Class(node) {
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
import * as t from "../../../types";
|
||||
import * as util from "../../../util";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
// foo in bar
|
||||
export function BinaryExpression(node) {
|
||||
if (node.operator === "in") {
|
||||
return util.template("ludicrous-in", {
|
||||
LEFT: node.left,
|
||||
RIGHT: node.right
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// { 1: "foo" }
|
||||
export function Property(node) {
|
||||
var key = node.key;
|
||||
if (t.isLiteral(key) && typeof key.value === "number") {
|
||||
key.value = "" + key.value;
|
||||
}
|
||||
}
|
||||
|
||||
// /foobar/g
|
||||
export function Literal(node) {
|
||||
if (node.regex) {
|
||||
node.regex.pattern = "foobar";
|
||||
node.regex.flags = "";
|
||||
}
|
||||
}
|
||||
|
||||
// foo.bar
|
||||
export function MemberExpression(node) {
|
||||
|
||||
}
|
||||
|
||||
// Object.setPrototypeOf
|
||||
// Object.preventExtensions
|
||||
// Object.keys
|
||||
// Object.isExtensible
|
||||
// Object.getOwnPropertyDescriptor
|
||||
// Object.defineProperty
|
||||
export function CallExpression(node) {
|
||||
|
||||
}
|
||||
|
||||
// delete foo.bar
|
||||
export function UnaryExpression(node) {
|
||||
|
||||
}
|
||||
|
||||
// foo.bar = bar;
|
||||
export function AssignmentExpression(node) {
|
||||
|
||||
}
|
||||
|
||||
// new Proxy
|
||||
export function NewExpression(node, parent, scope, file) {
|
||||
if (this.get("callee").isIdentifier({ name: "Proxy" })) {
|
||||
return t.callExpression(file.addHelper("proxy-create"), [node.arguments[0], file.addHelper("proxy-directory")]);
|
||||
} else {
|
||||
// possible proxy constructor
|
||||
}
|
||||
}
|
||||
@ -1,14 +1,10 @@
|
||||
import regenerator from "regenerator";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isFunction(node) && (node.async || node.generator);
|
||||
}
|
||||
|
||||
export var Program = {
|
||||
enter(ast) {
|
||||
regenerator.transform(ast);
|
||||
this.stop();
|
||||
this.checkSelf();
|
||||
}
|
||||
export var metadata = {
|
||||
group: "regenerator"
|
||||
};
|
||||
|
||||
export function Program(ast) {
|
||||
regenerator.transform(ast);
|
||||
}
|
||||
|
||||
@ -9,98 +9,12 @@ var isSymbolIterator = t.buildMatchMemberExpression("Symbol.iterator");
|
||||
|
||||
const RUNTIME_MODULE_NAME = "babel-runtime";
|
||||
|
||||
var astVisitor = traverse.explode({
|
||||
Identifier(node, parent, scope, file) {
|
||||
if (!this.isReferenced()) return;
|
||||
if (t.isMemberExpression(parent)) return;
|
||||
if (!has(definitions.builtins, node.name)) return;
|
||||
if (scope.getBindingIdentifier(node.name)) return;
|
||||
|
||||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
|
||||
var modulePath = definitions.builtins[node.name];
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, node.name, "absoluteDefault");
|
||||
},
|
||||
|
||||
CallExpression(node, parent, scope, file) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
var callee = node.callee;
|
||||
if (node.arguments.length) return;
|
||||
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (!callee.computed) return;
|
||||
|
||||
var prop = callee.property;
|
||||
if (!isSymbolIterator(prop)) return;
|
||||
|
||||
return t.callExpression(file.addImport(`${RUNTIME_MODULE_NAME}/core-js/get-iterator`, "getIterator", "absoluteDefault"), [callee.object]);
|
||||
},
|
||||
|
||||
BinaryExpression(node, parent, scope, file) {
|
||||
// Symbol.iterator in arr -> core.$for.isIterable(arr)
|
||||
|
||||
if (node.operator !== "in") return;
|
||||
|
||||
var left = node.left;
|
||||
if (!isSymbolIterator(left)) return;
|
||||
|
||||
return t.callExpression(
|
||||
file.addImport(`${RUNTIME_MODULE_NAME}/core-js/is-iterable`, "isIterable", "absoluteDefault"),
|
||||
[node.right]
|
||||
);
|
||||
},
|
||||
|
||||
MemberExpression: {
|
||||
enter(node, parent, scope, file) {
|
||||
// Array.from -> _core.Array.from
|
||||
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
var obj = node.object;
|
||||
var prop = node.property;
|
||||
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
if (node.computed) return;
|
||||
|
||||
if (!has(definitions.methods, obj.name)) return;
|
||||
|
||||
var methods = definitions.methods[obj.name];
|
||||
if (!has(methods, prop.name)) return;
|
||||
|
||||
if (scope.getBindingIdentifier(obj.name)) return;
|
||||
|
||||
var modulePath = methods[prop.name];
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}$${prop.name}`, "absoluteDefault");
|
||||
},
|
||||
|
||||
exit(node, parent, scope, file) {
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
var prop = node.property;
|
||||
var obj = node.object;
|
||||
|
||||
if (!has(definitions.builtins, obj.name)) return;
|
||||
if (scope.getBindingIdentifier(obj.name)) return;
|
||||
|
||||
var modulePath = definitions.builtins[obj.name];
|
||||
return t.memberExpression(
|
||||
file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}`, "absoluteDefault"),
|
||||
prop
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
exports.metadata = {
|
||||
optional: true
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
group: "builtin-post-modules"
|
||||
};
|
||||
|
||||
exports.Program = function (node, parent, scope, file) {
|
||||
this.traverse(astVisitor, file);
|
||||
};
|
||||
|
||||
exports.pre = function (file) {
|
||||
export function pre(file) {
|
||||
file.set("helperGenerator", function (name) {
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/helpers/${name}`, name, "absoluteDefault");
|
||||
});
|
||||
@ -108,10 +22,84 @@ exports.pre = function (file) {
|
||||
file.setDynamic("regeneratorIdentifier", function () {
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/regenerator`, "regeneratorRuntime", "absoluteDefault");
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.Identifier = function (node, parent, scope, file) {
|
||||
if (this.isReferencedIdentifier({ name: "regeneratorRuntime" })) {
|
||||
export function ReferencedIdentifier(node, parent, scope, file) {
|
||||
if (node.name === "regeneratorRuntime") {
|
||||
return file.get("regeneratorIdentifier");
|
||||
}
|
||||
|
||||
if (t.isMemberExpression(parent)) return;
|
||||
if (!has(definitions.builtins, node.name)) return;
|
||||
if (scope.getBindingIdentifier(node.name)) return;
|
||||
|
||||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
|
||||
var modulePath = definitions.builtins[node.name];
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, node.name, "absoluteDefault");
|
||||
}
|
||||
|
||||
export function CallExpression(node, parent, scope, file) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
if (node.arguments.length) return;
|
||||
|
||||
var callee = node.callee;
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (!callee.computed) return;
|
||||
if (!this.get("callee.property").matchesPattern("Symbol.iterator")) return;
|
||||
|
||||
return t.callExpression(file.addImport(`${RUNTIME_MODULE_NAME}/core-js/get-iterator`, "getIterator", "absoluteDefault"), [callee.object]);
|
||||
}
|
||||
|
||||
export function BinaryExpression(node, parent, scope, file) {
|
||||
// Symbol.iterator in arr -> core.$for.isIterable(arr)
|
||||
|
||||
if (node.operator !== "in") return;
|
||||
if (!this.get("left").matchesPattern("Symbol.iterator")) return;
|
||||
|
||||
return t.callExpression(
|
||||
file.addImport(`${RUNTIME_MODULE_NAME}/core-js/is-iterable`, "isIterable", "absoluteDefault"),
|
||||
[node.right]
|
||||
);
|
||||
}
|
||||
|
||||
export var MemberExpression = {
|
||||
enter(node, parent, scope, file) {
|
||||
// Array.from -> _core.Array.from
|
||||
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
var obj = node.object;
|
||||
var prop = node.property;
|
||||
|
||||
if (!t.isReferenced(obj, node)) return;
|
||||
|
||||
if (node.computed) return;
|
||||
|
||||
if (!has(definitions.methods, obj.name)) return;
|
||||
|
||||
var methods = definitions.methods[obj.name];
|
||||
if (!has(methods, prop.name)) return;
|
||||
|
||||
if (scope.getBindingIdentifier(obj.name)) return;
|
||||
|
||||
var modulePath = methods[prop.name];
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}$${prop.name}`, "absoluteDefault");
|
||||
},
|
||||
|
||||
exit(node, parent, scope, file) {
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
var prop = node.property;
|
||||
var obj = node.object;
|
||||
|
||||
if (!has(definitions.builtins, obj.name)) return;
|
||||
if (scope.getBindingIdentifier(obj.name)) return;
|
||||
|
||||
var modulePath = definitions.builtins[obj.name];
|
||||
return t.memberExpression(
|
||||
file.addImport(`${RUNTIME_MODULE_NAME}/core-js/${modulePath}`, `${obj.name}`, "absoluteDefault"),
|
||||
prop
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,22 +1,33 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function Program(program, parent, scope, file) {
|
||||
var first = program.body[0];
|
||||
if (t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" })) {
|
||||
file.set("existingStrictDirective", program.body.shift());
|
||||
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassExpression", "ClassDeclaration"];
|
||||
|
||||
export var Program = {
|
||||
enter(program, parent, scope, file) {
|
||||
var first = program.body[0];
|
||||
|
||||
var directive;
|
||||
if (t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" })) {
|
||||
directive = first;
|
||||
} else {
|
||||
directive = t.expressionStatement(t.literal("use strict"));
|
||||
this.unshiftContainer("body", directive);
|
||||
if (first) {
|
||||
directive.leadingComments = first.leadingComments;
|
||||
first.leadingComments = [];
|
||||
}
|
||||
}
|
||||
directive._blockHoist = Infinity;
|
||||
}
|
||||
}
|
||||
|
||||
export function FunctionExpression() {
|
||||
this.skip();
|
||||
}
|
||||
|
||||
export { FunctionExpression as FunctionDeclaration };
|
||||
export { FunctionExpression as Class };
|
||||
|
||||
export function ThisExpression() {
|
||||
return t.identifier("undefined");
|
||||
if (!this.findParent(function (node) {
|
||||
return !node.shadow && THIS_BREAK_KEYS.indexOf(node.type) >= 0;
|
||||
})) {
|
||||
return t.identifier("undefined");
|
||||
}
|
||||
}
|
||||
|
||||
export function CallExpression(node, parent, scope, file) {
|
||||
|
||||
@ -23,21 +23,6 @@ function statementList(key, path, file) {
|
||||
}
|
||||
}
|
||||
|
||||
export function shouldVisit(node) {
|
||||
var body;
|
||||
if (node.type === "SwitchCase") {
|
||||
body = node.consequent;
|
||||
} else if (node.type === "BlockStatement") {
|
||||
body = node.body;
|
||||
}
|
||||
if (body) {
|
||||
for (var i = 0; i < body.length; i++) {
|
||||
if (body[i].type === "FunctionDeclaration") return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function BlockStatement(node, parent, scope, file) {
|
||||
if ((t.isFunction(parent) && parent.body === node) || t.isExportDeclaration(parent)) {
|
||||
return;
|
||||
|
||||
@ -1 +1,8 @@
|
||||
export { bare as FunctionExpression, bare as ArrowFunctionExpression } from "../../helpers/name-method";
|
||||
export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export {
|
||||
bare as FunctionExpression,
|
||||
bare as ArrowFunctionExpression
|
||||
} from "../../helpers/name-method";
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
var match = t.buildMatchMemberExpression("process.env");
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function Expression(node, parent, scope) {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function CallExpression(node, parent) {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ExpressionStatement(node) {
|
||||
|
||||
@ -1,14 +1,6 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
readOnly: true
|
||||
};
|
||||
|
||||
export function shouldVisit(node) {
|
||||
return t.isModuleDeclaration(node) || (t.isCallExpression(node) && t.isIdentifier(node.callee, { name: "require" }));
|
||||
}
|
||||
|
||||
// check if the input Literal `source` is an alternate casing of "react"
|
||||
function check(source, file) {
|
||||
if (t.isLiteral(source)) {
|
||||
|
||||
@ -2,8 +2,7 @@ import levenshtein from "leven";
|
||||
import * as messages from "../../../messages";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
readOnly: true
|
||||
optional: true
|
||||
};
|
||||
|
||||
export function Identifier(node, parent, scope, file) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import TraversalContext from "./context";
|
||||
import { explode, verify } from "./visitors";
|
||||
import * as visitors from "./visitors";
|
||||
import * as messages from "../messages";
|
||||
import includes from "lodash/collection/includes";
|
||||
import * as t from "../types";
|
||||
@ -14,7 +14,7 @@ export default function traverse(parent, opts, scope, state, parentPath) {
|
||||
}
|
||||
|
||||
if (!opts) opts = {};
|
||||
verify(opts);
|
||||
visitors.verify(opts);
|
||||
|
||||
// array of nodes
|
||||
if (Array.isArray(parent)) {
|
||||
@ -26,8 +26,9 @@ export default function traverse(parent, opts, scope, state, parentPath) {
|
||||
}
|
||||
}
|
||||
|
||||
traverse.verify = verify;
|
||||
traverse.explode = explode;
|
||||
traverse.visitors = visitors;
|
||||
traverse.verify = visitors.verify;
|
||||
traverse.explode = visitors.explode;
|
||||
|
||||
traverse.node = function (node, opts, scope, state, parentPath) {
|
||||
var keys = t.VISITOR_KEYS[node.type];
|
||||
|
||||
@ -107,12 +107,59 @@ export default class TraversalPath {
|
||||
return ancestry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
inType(types) {
|
||||
if (!Array.isArray(types)) types = [types];
|
||||
|
||||
var path = this;
|
||||
while (path) {
|
||||
for (var type of (types: Array)) {
|
||||
if (path.node.type === type) return true;
|
||||
}
|
||||
path = path.parentPath;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this node was a part of the original AST.
|
||||
*/
|
||||
|
||||
isUser() {
|
||||
return this.node && !!this.node.loc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this node was generated by us and not a part of the original AST.
|
||||
*/
|
||||
|
||||
isGenerated() {
|
||||
return !this.isUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
findParent(callback) {
|
||||
var path = this;
|
||||
while (path) {
|
||||
if (callback(path.node)) return path.node;
|
||||
path = path.parentPath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
queueNode(path) {
|
||||
if (this.context) {
|
||||
if (this.context && this.context.queue) {
|
||||
this.context.queue.push(path);
|
||||
}
|
||||
}
|
||||
@ -136,7 +183,6 @@ export default class TraversalPath {
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.checkSelf();
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
@ -163,8 +209,6 @@ export default class TraversalPath {
|
||||
paths.push(TraversalPath.get(this, null, node, this.container, to));
|
||||
}
|
||||
}
|
||||
|
||||
this.checkPaths(paths);
|
||||
}
|
||||
|
||||
_containerInsertBefore(nodes) {
|
||||
@ -234,7 +278,6 @@ export default class TraversalPath {
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.unshift(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.checkSelf();
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
@ -528,7 +571,7 @@ export default class TraversalPath {
|
||||
}
|
||||
|
||||
if (this.node === replacement) {
|
||||
return this.checkSelf();
|
||||
return;
|
||||
}
|
||||
|
||||
// normalise inserting an entire AST
|
||||
@ -572,26 +615,6 @@ export default class TraversalPath {
|
||||
|
||||
// potentially create new scope
|
||||
this.setScope();
|
||||
|
||||
this.checkSelf();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
checkSelf() {
|
||||
this.checkPaths(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
checkPaths(paths) {
|
||||
var scope = this.scope;
|
||||
var file = scope && scope.file;
|
||||
if (file) file.checkPath(paths);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -689,11 +712,23 @@ export default class TraversalPath {
|
||||
for (var fn of (fns: Array)) {
|
||||
if (!fn) continue;
|
||||
|
||||
var node = this.node;
|
||||
if (!node) return;
|
||||
|
||||
// call the function with the params (node, parent, scope, state)
|
||||
var replacement = fn.call(this, node, this.parent, this.scope, this.state);
|
||||
if (replacement) this.replaceWith(replacement, true);
|
||||
var previousType = this.type;
|
||||
|
||||
if (this.shouldStop) break;
|
||||
if (replacement) {
|
||||
this.replaceWith(replacement, true);
|
||||
}
|
||||
|
||||
if (this.shouldStop || this.shouldSkip || this.removed) return;
|
||||
|
||||
if (replacement && previousType !== this.type) {
|
||||
this.queueNode(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -784,8 +819,7 @@ export default class TraversalPath {
|
||||
|
||||
_getPattern(parts) {
|
||||
var path = this;
|
||||
for (var i = 0; i > parts.length; i++) {
|
||||
var part = parts[i];
|
||||
for (var part of (parts: Array)) {
|
||||
if (part === ".") {
|
||||
path = path.parentPath;
|
||||
} else {
|
||||
|
||||
@ -36,12 +36,12 @@ export function explode(visitor, mergeConflicts) {
|
||||
if (wrapper.type) {
|
||||
// merge the visitor if necessary or just put it back in
|
||||
if (visitor[wrapper.type]) {
|
||||
merge(visitor[wrapper.type], fns);
|
||||
mergePair(visitor[wrapper.type], fns);
|
||||
} else {
|
||||
visitor[wrapper.type] = fns;
|
||||
}
|
||||
} else {
|
||||
merge(visitor, fns);
|
||||
mergePair(visitor, fns);
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ export function explode(visitor, mergeConflicts) {
|
||||
var existing = visitor[alias];
|
||||
if (existing) {
|
||||
if (mergeConflicts) {
|
||||
merge(existing, fns);
|
||||
mergePair(existing, fns);
|
||||
}
|
||||
} else {
|
||||
visitor[alias] = fns;
|
||||
@ -105,6 +105,19 @@ export function verify(visitor) {
|
||||
visitor._verified = true;
|
||||
}
|
||||
|
||||
export function merge(visitors) {
|
||||
var rootVisitor = {};
|
||||
|
||||
for (var visitor of (visitors: Array)) {
|
||||
for (var type in visitor) {
|
||||
var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
|
||||
mergePair(nodeVisitor, visitor[type]);
|
||||
}
|
||||
}
|
||||
|
||||
return rootVisitor;
|
||||
}
|
||||
|
||||
function ensureEntranceObjects(obj) {
|
||||
for (let key in obj) {
|
||||
if (shouldIgnoreKey(key)) continue;
|
||||
@ -135,7 +148,7 @@ function addSelector(visitor, selector, fns) {
|
||||
};
|
||||
}
|
||||
|
||||
merge(visitor, fns);
|
||||
mergePair(visitor, fns);
|
||||
}
|
||||
|
||||
function wrapCheck(wrapper, fn) {
|
||||
@ -159,7 +172,7 @@ function shouldIgnoreKey(key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function merge(dest, src) {
|
||||
function mergePair(dest, src) {
|
||||
for (var key in src) {
|
||||
dest[key] = (dest[key] || []).concat(src[key]);
|
||||
}
|
||||
|
||||
@ -66,4 +66,4 @@ function six(obj) {
|
||||
};
|
||||
return fn();
|
||||
}
|
||||
six();
|
||||
six();
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
System.register([], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var _default, Foo;
|
||||
|
||||
_export("default", foo);
|
||||
@ -10,8 +12,6 @@ System.register([], function (_export) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
_export("default", 42);
|
||||
|
||||
_export("default", {});
|
||||
@ -39,4 +39,4 @@ System.register([], function (_export) {
|
||||
_export("default", Foo);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
System.register(["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
for (var _key in _foo) {
|
||||
@ -19,8 +21,6 @@ System.register(["foo"], function (_export) {
|
||||
|
||||
_export("bar", _foo.bar);
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
System.register([], function (_export) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
_export("foo", foo);
|
||||
|
||||
_export("foo", foo);
|
||||
@ -19,4 +19,4 @@ System.register([], function (_export) {
|
||||
_export("bar", bar);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
System.register([], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var foo, foo2, foo3, foo4, foo5, foo6, foo8;
|
||||
|
||||
_export("foo7", foo7);
|
||||
@ -10,8 +12,6 @@ System.register([], function (_export) {
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
foo = 1;
|
||||
|
||||
_export("foo", foo);
|
||||
@ -43,4 +43,4 @@ System.register([], function (_export) {
|
||||
_export("foo3", foo3 = 5);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
System.register("my custom module name", [], function (_export) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
System.register(["./evens"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var isEven, p, isOdd;
|
||||
|
||||
_export("nextOdd", nextOdd);
|
||||
@ -12,8 +14,6 @@ System.register(["./evens"], function (_export) {
|
||||
isEven = _evens.isEven;
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
p = 5;
|
||||
|
||||
_export("p", p);
|
||||
@ -27,4 +27,4 @@ System.register(["./evens"], function (_export) {
|
||||
_export("isOdd", isOdd);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
System.register(["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var foo, foo2;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
foo = _foo["default"];
|
||||
foo2 = _foo["default"];
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
System.register(["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var foo;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
foo = _foo;
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
System.register(["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var foo, xyz;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
foo = _foo["default"];
|
||||
xyz = _foo.baz;
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
System.register(["foo"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var bar, bar2, baz, baz2, baz3, xyz;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
@ -9,8 +11,6 @@ System.register(["foo"], function (_export) {
|
||||
baz3 = _foo.bar;
|
||||
xyz = _foo.xyz;
|
||||
}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
setters: [function (_foo) {}, function (_fooBar) {}, function (_directoryFooBar) {}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
}
|
||||
execute: function () {}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var foo, foo2, bar, bar2, test2;
|
||||
return {
|
||||
setters: [function (_foo) {
|
||||
@ -8,8 +10,6 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
bar2 = _foo.foo;
|
||||
}, function (_fooBar) {}, function (_directoryFooBar) {}],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
_export("test", test);
|
||||
|
||||
test2 = 5;
|
||||
@ -19,4 +19,4 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
|
||||
_export("default", test);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
System.register([], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var test, a, b, d;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
"use strict";
|
||||
|
||||
test = 2;
|
||||
|
||||
_export("test", test);
|
||||
@ -39,4 +39,4 @@ System.register([], function (_export) {
|
||||
_export("f", _export("e", d = 4));
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,4 +12,4 @@ var Foo = (function () {
|
||||
set: function (bar) {}
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@ -11,4 +11,4 @@ var Foo = (function () {
|
||||
get: function () {}
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@ -17,4 +17,4 @@ var Foo = (function () {
|
||||
enumerable: true
|
||||
}], null, _instanceInitializers);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@ -17,4 +17,4 @@ var Foo = (function () {
|
||||
}], null, _staticInitializers);
|
||||
babelHelpers.defineDecoratedPropertyDescriptor(Foo, "foo", _staticInitializers);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@ -11,4 +11,4 @@ var Foo = (function () {
|
||||
set: function (arg) {}
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
})();
|
||||
|
||||
@ -5,7 +5,7 @@ var obj = {
|
||||
},
|
||||
|
||||
@foo
|
||||
set foo() {
|
||||
set foo(bar) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -3,6 +3,6 @@
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "foo",
|
||||
decorators: [foo, foo],
|
||||
get: function get() {},
|
||||
set: function set() {}
|
||||
get: function () {},
|
||||
set: function (bar) {}
|
||||
}]);
|
||||
|
||||
@ -3,5 +3,5 @@
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "foo",
|
||||
decorators: [foo],
|
||||
get: function get() {}
|
||||
get: function () {}
|
||||
}]);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
var obj = {
|
||||
@foo
|
||||
set foo() {
|
||||
set foo(bar) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -3,5 +3,5 @@
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "foo",
|
||||
decorators: [foo],
|
||||
set: function set() {}
|
||||
set: function (bar) {}
|
||||
}]);
|
||||
|
||||
@ -3,18 +3,18 @@
|
||||
var obj = babelHelpers.createDecoratedObject([{
|
||||
key: "bar",
|
||||
decorators: [foo],
|
||||
initializer: function initializer() {
|
||||
return function () {};
|
||||
initializer: function () {
|
||||
return function bar() {};
|
||||
}
|
||||
}, {
|
||||
key: "foo",
|
||||
decorators: [bar],
|
||||
initializer: function initializer() {
|
||||
initializer: function () {
|
||||
return "lol";
|
||||
}
|
||||
}, {
|
||||
key: "yes",
|
||||
initializer: function initializer() {
|
||||
initializer: function () {
|
||||
return "wow";
|
||||
}
|
||||
}]);
|
||||
}]);
|
||||
|
||||
@ -64,8 +64,14 @@ class Foo8 {
|
||||
"bar"() {}
|
||||
}
|
||||
function foo(requiredParam, optParam) {}
|
||||
class Foo9 {}
|
||||
class Foo10 {}
|
||||
class Foo9 {
|
||||
prop1;
|
||||
prop2;
|
||||
}
|
||||
class Foo10 {
|
||||
static prop1;
|
||||
prop2;
|
||||
}
|
||||
var x = 4;
|
||||
class Array {
|
||||
concat(items) {}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var _regeneratorRuntime = require("babel-runtime/regenerator")["default"];
|
||||
|
||||
var _Object$defineProperty = require("babel-runtime/core-js/object/define-property")["default"];
|
||||
|
||||
var _Symbol = require("babel-runtime/core-js/symbol")["default"];
|
||||
|
||||
var _regeneratorRuntime = require("babel-runtime/regenerator")["default"];
|
||||
|
||||
var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"];
|
||||
|
||||
var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"];
|
||||
@ -41,4 +41,4 @@ function giveWord() {
|
||||
}
|
||||
|
||||
_someModule2["default"];
|
||||
bar;
|
||||
bar;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||
|
||||
var _foo, _foo$bar, _foo$bar2;
|
||||
|
||||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||
|
||||
console.log((_foo = foo, _defaults(_foo, bar), _foo));
|
||||
|
||||
console.log((_foo$bar = foo[bar], _defaults(_foo$bar, bar), _foo$bar));
|
||||
|
||||
console.log((_foo$bar2 = foo[bar()], _defaults(_foo$bar2, bar), _foo$bar2));
|
||||
console.log((_foo$bar2 = foo[bar()], _defaults(_foo$bar2, bar), _foo$bar2));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user