diff --git a/src/babel/generation/generators/statements.js b/src/babel/generation/generators/statements.js index 5a9b0067d6..81ba6f2c83 100644 --- a/src/babel/generation/generators/statements.js +++ b/src/babel/generation/generators/statements.js @@ -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 += " "; diff --git a/src/babel/transformation/file/index.js b/src/babel/transformation/file/index.js index ad8f851e83..27f0453ed8 100644 --- a/src/babel/transformation/file/index.js +++ b/src/babel/transformation/file/index.js @@ -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); } } diff --git a/src/babel/transformation/helpers/build-binary-assignment-operator-transformer.js b/src/babel/transformation/helpers/build-binary-assignment-operator-transformer.js index 45a6d812c5..04ffc4c1b3 100644 --- a/src/babel/transformation/helpers/build-binary-assignment-operator-transformer.js +++ b/src/babel/transformation/helpers/build-binary-assignment-operator-transformer.js @@ -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; diff --git a/src/babel/transformation/helpers/build-react-transformer.js b/src/babel/transformation/helpers/build-react-transformer.js index 46a9bdfef7..c63bd60882 100644 --- a/src/babel/transformation/helpers/build-react-transformer.js +++ b/src/babel/transformation/helpers/build-react-transformer.js @@ -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(); diff --git a/src/babel/transformation/index.js b/src/babel/transformation/index.js index 442ed37849..11b0780fd1 100644 --- a/src/babel/transformation/index.js +++ b/src/babel/transformation/index.js @@ -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); // diff --git a/src/babel/transformation/templates/helper-ludicrous-in.js b/src/babel/transformation/templates/helper-ludicrous-in.js deleted file mode 100644 index 80348f0da7..0000000000 --- a/src/babel/transformation/templates/helper-ludicrous-in.js +++ /dev/null @@ -1 +0,0 @@ -Object(RIGHT)[LEFT] !== undefined; diff --git a/src/babel/transformation/templates/helper-ludicrous-proxy-create.js b/src/babel/transformation/templates/helper-ludicrous-proxy-create.js deleted file mode 100644 index 8ecc6af771..0000000000 --- a/src/babel/transformation/templates/helper-ludicrous-proxy-create.js +++ /dev/null @@ -1,4 +0,0 @@ -(function (proxy, directory) { - directory.push(proxy); - return proxy; -}) diff --git a/src/babel/transformation/templates/helper-ludicrous-proxy-directory.js b/src/babel/transformation/templates/helper-ludicrous-proxy-directory.js deleted file mode 100644 index 5e1ab7855e..0000000000 --- a/src/babel/transformation/templates/helper-ludicrous-proxy-directory.js +++ /dev/null @@ -1 +0,0 @@ -[]; diff --git a/src/babel/transformation/transformer-pass.js b/src/babel/transformation/transformer-pass.js index 38c3e8ef8c..62e91cd7ca 100644 --- a/src/babel/transformation/transformer-pass.js +++ b/src/babel/transformation/transformer-pass.js @@ -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; } diff --git a/src/babel/transformation/transformer.js b/src/babel/transformation/transformer.js index 3e12abcf1d..3f700974d9 100644 --- a/src/babel/transformation/transformer.js +++ b/src/babel/transformation/transformer.js @@ -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 { diff --git a/src/babel/transformation/transformers/es3/member-expression-literals.js b/src/babel/transformation/transformers/es3/member-expression-literals.js index 9b6b30bff7..af026a5171 100644 --- a/src/babel/transformation/transformers/es3/member-expression-literals.js +++ b/src/babel/transformation/transformers/es3/member-expression-literals.js @@ -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; + } } -} +}; diff --git a/src/babel/transformation/transformers/es3/property-literals.js b/src/babel/transformation/transformers/es3/property-literals.js index 0c9b26a9cd..ffb13ddc64 100644 --- a/src/babel/transformation/transformers/es3/property-literals.js +++ b/src/babel/transformation/transformers/es3/property-literals.js @@ -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); + } } -} +}; diff --git a/src/babel/transformation/transformers/es5/properties.mutators.js b/src/babel/transformation/transformers/es5/properties.mutators.js index 9b1deb2870..a3161efae8 100644 --- a/src/babel/transformation/transformers/es5/properties.mutators.js +++ b/src/babel/transformation/transformers/es5/properties.mutators.js @@ -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; diff --git a/src/babel/transformation/transformers/es6/arrow-functions.js b/src/babel/transformation/transformers/es6/arrow-functions.js index d40d436727..39d93f829a 100644 --- a/src/babel/transformation/transformers/es6/arrow-functions.js +++ b/src/babel/transformation/transformers/es6/arrow-functions.js @@ -1,7 +1,5 @@ import * as t from "../../../types"; -export var shouldVisit = t.isArrowFunctionExpression; - export function ArrowFunctionExpression(node) { t.ensureBlock(node); diff --git a/src/babel/transformation/transformers/es6/block-scoping.js b/src/babel/transformation/transformers/es6/block-scoping.js index 1b81d95232..8d1a5948a3 100644 --- a/src/babel/transformation/transformers/es6/block-scoping.js +++ b/src/babel/transformation/transformers/es6/block-scoping.js @@ -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); } } diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index 670a18b5fb..90ca984e7f 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -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)) diff --git a/src/babel/transformation/transformers/es6/constants.js b/src/babel/transformation/transformers/es6/constants.js index b8df344bfb..4125b68d10 100644 --- a/src/babel/transformation/transformers/es6/constants.js +++ b/src/babel/transformation/transformers/es6/constants.js @@ -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()) { diff --git a/src/babel/transformation/transformers/es6/destructuring.js b/src/babel/transformation/transformers/es6/destructuring.js index 5dd84da762..5c779cac21 100644 --- a/src/babel/transformation/transformers/es6/destructuring.js +++ b/src/babel/transformation/transformers/es6/destructuring.js @@ -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) { diff --git a/src/babel/transformation/transformers/es6/for-of.js b/src/babel/transformation/transformers/es6/for-of.js index 7d007d6465..b986492da9 100644 --- a/src/babel/transformation/transformers/es6/for-of.js +++ b/src/babel/transformation/transformers/es6/for-of.js @@ -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); diff --git a/src/babel/transformation/transformers/es6/modules.js b/src/babel/transformation/transformers/es6/modules.js index 5abf2b1af4..688fcf2baa 100644 --- a/src/babel/transformation/transformers/es6/modules.js +++ b/src/babel/transformation/transformers/es6/modules.js @@ -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; diff --git a/src/babel/transformation/transformers/es6/object-super.js b/src/babel/transformation/transformers/es6/object-super.js index b261520da2..10d01e09f8 100644 --- a/src/babel/transformation/transformers/es6/object-super.js +++ b/src/babel/transformation/transformers/es6/object-super.js @@ -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; diff --git a/src/babel/transformation/transformers/es6/parameters.default.js b/src/babel/transformation/transformers/es6/parameters.default.js index 56345ee839..165c177844 100644 --- a/src/babel/transformation/transformers/es6/parameters.default.js +++ b/src/babel/transformation/transformers/es6/parameters.default.js @@ -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(); }; diff --git a/src/babel/transformation/transformers/es6/parameters.rest.js b/src/babel/transformation/transformers/es6/parameters.rest.js index 631701a766..6b57c156a3 100644 --- a/src/babel/transformation/transformers/es6/parameters.rest.js +++ b/src/babel/transformation/transformers/es6/parameters.rest.js @@ -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(); }; diff --git a/src/babel/transformation/transformers/es6/properties.computed.js b/src/babel/transformation/transformers/es6/properties.computed.js index e846e4d2a6..9c477f8348 100644 --- a/src/babel/transformation/transformers/es6/properties.computed.js +++ b/src/babel/transformation/transformers/es6/properties.computed.js @@ -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; -} +}; diff --git a/src/babel/transformation/transformers/es6/properties.shorthand.js b/src/babel/transformation/transformers/es6/properties.shorthand.js index 5f6830cfb7..b5140ac364 100644 --- a/src/babel/transformation/transformers/es6/properties.shorthand.js +++ b/src/babel/transformation/transformers/es6/properties.shorthand.js @@ -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; diff --git a/src/babel/transformation/transformers/es6/regex.sticky.js b/src/babel/transformation/transformers/es6/regex.sticky.js index 3227c59635..e298e0501b 100644 --- a/src/babel/transformation/transformers/es6/regex.sticky.js +++ b/src/babel/transformation/transformers/es6/regex.sticky.js @@ -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"), [ diff --git a/src/babel/transformation/transformers/es6/regex.unicode.js b/src/babel/transformation/transformers/es6/regex.unicode.js index 58471da84a..a914f2b529 100644 --- a/src/babel/transformation/transformers/es6/regex.unicode.js +++ b/src/babel/transformation/transformers/es6/regex.unicode.js @@ -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); diff --git a/src/babel/transformation/transformers/es6/spec.block-scoping.js b/src/babel/transformation/transformers/es6/spec.block-scoping.js index 43699b2b1b..f7fc4ff0ab 100644 --- a/src/babel/transformation/transformers/es6/spec.block-scoping.js +++ b/src/babel/transformation/transformers/es6/spec.block-scoping.js @@ -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 }; diff --git a/src/babel/transformation/transformers/es6/spread.js b/src/babel/transformation/transformers/es6/spread.js index a856453ed0..e7c403588a 100644 --- a/src/babel/transformation/transformers/es6/spread.js +++ b/src/babel/transformation/transformers/es6/spread.js @@ -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; diff --git a/src/babel/transformation/transformers/es6/tail-call.js b/src/babel/transformation/transformers/es6/tail-call.js index 12fb5a8a8d..4da3e46365 100644 --- a/src/babel/transformation/transformers/es6/tail-call.js +++ b/src/babel/transformation/transformers/es6/tail-call.js @@ -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); diff --git a/src/babel/transformation/transformers/es6/template-literals.js b/src/babel/transformation/transformers/es6/template-literals.js index 10128abaf7..912fcdbbdf 100644 --- a/src/babel/transformation/transformers/es6/template-literals.js +++ b/src/babel/transformation/transformers/es6/template-literals.js @@ -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 = []; diff --git a/src/babel/transformation/transformers/es7/async-functions.js b/src/babel/transformation/transformers/es7/async-functions.js index df6bc46bd4..5059fdd666 100644 --- a/src/babel/transformation/transformers/es7/async-functions.js +++ b/src/babel/transformation/transformers/es7/async-functions.js @@ -1,7 +1,3 @@ export var metadata = { stage: 1 }; - -export function shouldVisit() { - return false; -} diff --git a/src/babel/transformation/transformers/es7/class-properties.js b/src/babel/transformation/transformers/es7/class-properties.js index 9c08f42ae1..ca95104fab 100644 --- a/src/babel/transformation/transformers/es7/class-properties.js +++ b/src/babel/transformation/transformers/es7/class-properties.js @@ -1,7 +1,4 @@ export var metadata = { - stage: 0 + stage: 0, + dependencies: ["es6.classes"] }; - -export function shouldVisit() { - return false; -} diff --git a/src/babel/transformation/transformers/es7/decorators.js b/src/babel/transformation/transformers/es7/decorators.js index a67843cf3d..aaa54b0ee2 100644 --- a/src/babel/transformation/transformers/es7/decorators.js +++ b/src/babel/transformation/transformers/es7/decorators.js @@ -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++) { diff --git a/src/babel/transformation/transformers/es7/do-expressions.js b/src/babel/transformation/transformers/es7/do-expressions.js index 8f1e18875f..efefe06ba2 100644 --- a/src/babel/transformation/transformers/es7/do-expressions.js +++ b/src/babel/transformation/transformers/es7/do-expressions.js @@ -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) { diff --git a/src/babel/transformation/transformers/es7/export-extensions.js b/src/babel/transformation/transformers/es7/export-extensions.js index 80a11c34ab..77880f3a10 100644 --- a/src/babel/transformation/transformers/es7/export-extensions.js +++ b/src/babel/transformation/transformers/es7/export-extensions.js @@ -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; diff --git a/src/babel/transformation/transformers/es7/object-rest-spread.js b/src/babel/transformation/transformers/es7/object-rest-spread.js index e6fe46b993..7b9f448f9c 100644 --- a/src/babel/transformation/transformers/es7/object-rest-spread.js +++ b/src/babel/transformation/transformers/es7/object-rest-spread.js @@ -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])) { diff --git a/src/babel/transformation/transformers/es7/trailing-function-commas.js b/src/babel/transformation/transformers/es7/trailing-function-commas.js index df6bc46bd4..5059fdd666 100644 --- a/src/babel/transformation/transformers/es7/trailing-function-commas.js +++ b/src/babel/transformation/transformers/es7/trailing-function-commas.js @@ -1,7 +1,3 @@ export var metadata = { stage: 1 }; - -export function shouldVisit() { - return false; -} diff --git a/src/babel/transformation/transformers/index.js b/src/babel/transformation/transformers/index.js index 05f7c47c41..93551c5181 100644 --- a/src/babel/transformation/transformers/index.js +++ b/src/babel/transformation/transformers/index.js @@ -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"), }; diff --git a/src/babel/transformation/transformers/internal/block-hoist.js b/src/babel/transformation/transformers/internal/block-hoist.js index b732e2b2f3..934d21b1e2 100644 --- a/src/babel/transformation/transformers/internal/block-hoist.js +++ b/src/babel/transformation/transformers/internal/block-hoist.js @@ -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 diff --git a/src/babel/transformation/transformers/internal/hoist-directives.js b/src/babel/transformation/transformers/internal/hoist-directives.js new file mode 100644 index 0000000000..a3dbe27811 --- /dev/null +++ b/src/babel/transformation/transformers/internal/hoist-directives.js @@ -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 }; diff --git a/src/babel/transformation/transformers/internal/module-formatter.js b/src/babel/transformation/transformers/internal/module-formatter.js index 92ef7baab2..36f6206d72 100644 --- a/src/babel/transformation/transformers/internal/module-formatter.js +++ b/src/babel/transformation/transformers/internal/module-formatter.js @@ -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); + } } -} +}; diff --git a/src/babel/transformation/transformers/internal/modules.js b/src/babel/transformation/transformers/internal/modules.js index 5953072c27..ac64b0e455 100644 --- a/src/babel/transformation/transformers/internal/modules.js +++ b/src/babel/transformation/transformers/internal/modules.js @@ -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) { diff --git a/src/babel/transformation/transformers/internal/shadow-functions.js b/src/babel/transformation/transformers/internal/shadow-functions.js index 4eb4e5e375..92ab2f9687 100644 --- a/src/babel/transformation/transformers/internal/shadow-functions.js +++ b/src/babel/transformation/transformers/internal/shadow-functions.js @@ -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 () { diff --git a/src/babel/transformation/transformers/internal/strict.js b/src/babel/transformation/transformers/internal/strict.js deleted file mode 100644 index afc820c665..0000000000 --- a/src/babel/transformation/transformers/internal/strict.js +++ /dev/null @@ -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(); -} diff --git a/src/babel/transformation/transformers/internal/validation.js b/src/babel/transformation/transformers/internal/validation.js index 8fab413fdd..626c236fee 100644 --- a/src/babel/transformation/transformers/internal/validation.js +++ b/src/babel/transformation/transformers/internal/validation.js @@ -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 }; diff --git a/src/babel/transformation/transformers/minification/dead-code-elimination.js b/src/babel/transformation/transformers/minification/dead-code-elimination.js index 2d840f991e..8f17b338df 100644 --- a/src/babel/transformation/transformers/minification/dead-code-elimination.js +++ b/src/babel/transformation/transformers/minification/dead-code-elimination.js @@ -18,7 +18,8 @@ function toStatements(node) { } export var metadata = { - optional: true + optional: true, + group: "builtin-setup" }; export function Identifier(node, parent, scope) { diff --git a/src/babel/transformation/transformers/minification/member-expression-literals.js b/src/babel/transformation/transformers/minification/member-expression-literals.js index 2038c70d4b..877a924b11 100644 --- a/src/babel/transformation/transformers/minification/member-expression-literals.js +++ b/src/babel/transformation/transformers/minification/member-expression-literals.js @@ -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; + } } -} +}; diff --git a/src/babel/transformation/transformers/minification/property-literals.js b/src/babel/transformation/transformers/minification/property-literals.js index 84902d2b94..c6cf4e7538 100644 --- a/src/babel/transformation/transformers/minification/property-literals.js +++ b/src/babel/transformation/transformers/minification/property-literals.js @@ -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; + } } -} +}; diff --git a/src/babel/transformation/transformers/optimisation/flow.for-of.js b/src/babel/transformation/transformers/optimisation/flow.for-of.js index f69525e307..0f031a9b51 100644 --- a/src/babel/transformation/transformers/optimisation/flow.for-of.js +++ b/src/babel/transformation/transformers/optimisation/flow.for-of.js @@ -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 }; diff --git a/src/babel/transformation/transformers/other/async-to-generator.js b/src/babel/transformation/transformers/other/async-to-generator.js index 7789fd2506..b5a54b478d 100644 --- a/src/babel/transformation/transformers/other/async-to-generator.js +++ b/src/babel/transformation/transformers/other/async-to-generator.js @@ -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) { diff --git a/src/babel/transformation/transformers/other/bluebird-coroutines.js b/src/babel/transformation/transformers/other/bluebird-coroutines.js index cb4f99e09a..2d1c467edd 100644 --- a/src/babel/transformation/transformers/other/bluebird-coroutines.js +++ b/src/babel/transformation/transformers/other/bluebird-coroutines.js @@ -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) { diff --git a/src/babel/transformation/transformers/other/flow.js b/src/babel/transformation/transformers/other/flow.js index b3a963e3cc..14fc5bcbc4 100644 --- a/src/babel/transformation/transformers/other/flow.js +++ b/src/babel/transformation/transformers/other/flow.js @@ -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) { diff --git a/src/babel/transformation/transformers/other/ludicrous.js b/src/babel/transformation/transformers/other/ludicrous.js deleted file mode 100644 index d2c56bb118..0000000000 --- a/src/babel/transformation/transformers/other/ludicrous.js +++ /dev/null @@ -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 - } -} diff --git a/src/babel/transformation/transformers/other/regenerator.js b/src/babel/transformation/transformers/other/regenerator.js index 7c109a92a5..957fc6af94 100644 --- a/src/babel/transformation/transformers/other/regenerator.js +++ b/src/babel/transformation/transformers/other/regenerator.js @@ -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); +} diff --git a/src/babel/transformation/transformers/other/runtime/index.js b/src/babel/transformation/transformers/other/runtime/index.js index 972701e099..27dd6c7a15 100644 --- a/src/babel/transformation/transformers/other/runtime/index.js +++ b/src/babel/transformation/transformers/other/runtime/index.js @@ -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 + ); + } }; diff --git a/src/babel/transformation/transformers/other/strict.js b/src/babel/transformation/transformers/other/strict.js index 1c8acc2651..1889800b11 100644 --- a/src/babel/transformation/transformers/other/strict.js +++ b/src/babel/transformation/transformers/other/strict.js @@ -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) { diff --git a/src/babel/transformation/transformers/spec/block-scoped-functions.js b/src/babel/transformation/transformers/spec/block-scoped-functions.js index b5327d8c0f..ae16f05fcb 100644 --- a/src/babel/transformation/transformers/spec/block-scoped-functions.js +++ b/src/babel/transformation/transformers/spec/block-scoped-functions.js @@ -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; diff --git a/src/babel/transformation/transformers/spec/function-name.js b/src/babel/transformation/transformers/spec/function-name.js index bf31ee407a..2b384fcddb 100644 --- a/src/babel/transformation/transformers/spec/function-name.js +++ b/src/babel/transformation/transformers/spec/function-name.js @@ -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"; diff --git a/src/babel/transformation/transformers/utility/inline-environment-variables.js b/src/babel/transformation/transformers/utility/inline-environment-variables.js index 97725fbc51..e40ed44d17 100644 --- a/src/babel/transformation/transformers/utility/inline-environment-variables.js +++ b/src/babel/transformation/transformers/utility/inline-environment-variables.js @@ -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"); diff --git a/src/babel/transformation/transformers/utility/inline-expressions.js b/src/babel/transformation/transformers/utility/inline-expressions.js index 437cce640d..858a696a90 100644 --- a/src/babel/transformation/transformers/utility/inline-expressions.js +++ b/src/babel/transformation/transformers/utility/inline-expressions.js @@ -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) { diff --git a/src/babel/transformation/transformers/utility/remove-console.js b/src/babel/transformation/transformers/utility/remove-console.js index 317840ce3e..cdbeb53a38 100644 --- a/src/babel/transformation/transformers/utility/remove-console.js +++ b/src/babel/transformation/transformers/utility/remove-console.js @@ -1,7 +1,8 @@ import * as t from "../../../types"; export var metadata = { - optional: true + optional: true, + group: "builtin-setup" }; export function CallExpression(node, parent) { diff --git a/src/babel/transformation/transformers/utility/remove-debugger.js b/src/babel/transformation/transformers/utility/remove-debugger.js index f7d84d0e81..e2d8c7dbe1 100644 --- a/src/babel/transformation/transformers/utility/remove-debugger.js +++ b/src/babel/transformation/transformers/utility/remove-debugger.js @@ -1,7 +1,8 @@ import * as t from "../../../types"; export var metadata = { - optional: true + optional: true, + group: "builtin-setup" }; export function ExpressionStatement(node) { diff --git a/src/babel/transformation/transformers/validation/react.js b/src/babel/transformation/transformers/validation/react.js index 5666f8c299..536aff1768 100644 --- a/src/babel/transformation/transformers/validation/react.js +++ b/src/babel/transformation/transformers/validation/react.js @@ -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)) { diff --git a/src/babel/transformation/transformers/validation/undeclared-variable-check.js b/src/babel/transformation/transformers/validation/undeclared-variable-check.js index 01f1f4a86c..f8d3b25a78 100644 --- a/src/babel/transformation/transformers/validation/undeclared-variable-check.js +++ b/src/babel/transformation/transformers/validation/undeclared-variable-check.js @@ -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) { diff --git a/src/babel/traversal/index.js b/src/babel/traversal/index.js index 1f2ccccf12..80cb1f0c93 100644 --- a/src/babel/traversal/index.js +++ b/src/babel/traversal/index.js @@ -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]; diff --git a/src/babel/traversal/path/index.js b/src/babel/traversal/path/index.js index 14b801de53..bf9dd5688f 100644 --- a/src/babel/traversal/path/index.js +++ b/src/babel/traversal/path/index.js @@ -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 { diff --git a/src/babel/traversal/visitors.js b/src/babel/traversal/visitors.js index 8e994c1ccb..f922351d1f 100644 --- a/src/babel/traversal/visitors.js +++ b/src/babel/traversal/visitors.js @@ -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]); } diff --git a/test/core/fixtures/transformation/es6.arrow-functions/arguments/expected.js b/test/core/fixtures/transformation/es6.arrow-functions/arguments/expected.js index b8104fab4d..3ddd69015f 100644 --- a/test/core/fixtures/transformation/es6.arrow-functions/arguments/expected.js +++ b/test/core/fixtures/transformation/es6.arrow-functions/arguments/expected.js @@ -66,4 +66,4 @@ function six(obj) { }; return fn(); } -six(); \ No newline at end of file +six(); diff --git a/test/core/fixtures/transformation/es6.modules-system/exports-default/expected.js b/test/core/fixtures/transformation/es6.modules-system/exports-default/expected.js index 453baf6142..7854fc3ce8 100644 --- a/test/core/fixtures/transformation/es6.modules-system/exports-default/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/exports-default/expected.js @@ -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); } }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/exports-from/expected.js b/test/core/fixtures/transformation/es6.modules-system/exports-from/expected.js index c1eaca763d..b7b8242360 100644 --- a/test/core/fixtures/transformation/es6.modules-system/exports-from/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/exports-from/expected.js @@ -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 () {} }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/exports-named/expected.js b/test/core/fixtures/transformation/es6.modules-system/exports-named/expected.js index 410345bcfa..86487ee2f5 100644 --- a/test/core/fixtures/transformation/es6.modules-system/exports-named/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/exports-named/expected.js @@ -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); } }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/exports-variable/expected.js b/test/core/fixtures/transformation/es6.modules-system/exports-variable/expected.js index c5ab473b75..bc93dd73b5 100644 --- a/test/core/fixtures/transformation/es6.modules-system/exports-variable/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/exports-variable/expected.js @@ -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); } }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js b/test/core/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js index 0f7fc369ae..0def1f9524 100644 --- a/test/core/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/get-module-name-option/expected.js @@ -1,8 +1,8 @@ System.register("my custom module name", [], function (_export) { + "use strict"; + return { setters: [], - execute: function () { - "use strict"; - } + execute: function () {} }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js b/test/core/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js index 4056aa7a5e..ad3421dd2e 100644 --- a/test/core/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/hoist-function-exports/expected.js @@ -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); } }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/imports-default/expected.js b/test/core/fixtures/transformation/es6.modules-system/imports-default/expected.js index 2cb90409c2..16a71b2ed4 100644 --- a/test/core/fixtures/transformation/es6.modules-system/imports-default/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/imports-default/expected.js @@ -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 () {} }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/imports-glob/expected.js b/test/core/fixtures/transformation/es6.modules-system/imports-glob/expected.js index 67e60e45ca..5df9008d7c 100644 --- a/test/core/fixtures/transformation/es6.modules-system/imports-glob/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/imports-glob/expected.js @@ -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 () {} }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/imports-mixing/expected.js b/test/core/fixtures/transformation/es6.modules-system/imports-mixing/expected.js index 9ac0cd5ce2..786d2e6869 100644 --- a/test/core/fixtures/transformation/es6.modules-system/imports-mixing/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/imports-mixing/expected.js @@ -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 () {} }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/imports-named/expected.js b/test/core/fixtures/transformation/es6.modules-system/imports-named/expected.js index b66550bded..e6704667be 100644 --- a/test/core/fixtures/transformation/es6.modules-system/imports-named/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/imports-named/expected.js @@ -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 () {} }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/imports/expected.js b/test/core/fixtures/transformation/es6.modules-system/imports/expected.js index 2b02e610fc..005c4b922f 100644 --- a/test/core/fixtures/transformation/es6.modules-system/imports/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/imports/expected.js @@ -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 () {} }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/overview/expected.js b/test/core/fixtures/transformation/es6.modules-system/overview/expected.js index b4b80d7d38..c818618f83 100644 --- a/test/core/fixtures/transformation/es6.modules-system/overview/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/overview/expected.js @@ -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); } }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es6.modules-system/remap/expected.js b/test/core/fixtures/transformation/es6.modules-system/remap/expected.js index c0922ff2b4..7bedb706ab 100644 --- a/test/core/fixtures/transformation/es6.modules-system/remap/expected.js +++ b/test/core/fixtures/transformation/es6.modules-system/remap/expected.js @@ -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)); } }; -}); \ No newline at end of file +}); diff --git a/test/core/fixtures/transformation/es7.decorators/class-getter-and-setter/expected.js b/test/core/fixtures/transformation/es7.decorators/class-getter-and-setter/expected.js index 73f0d1d146..8aa07f0846 100644 --- a/test/core/fixtures/transformation/es7.decorators/class-getter-and-setter/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class-getter-and-setter/expected.js @@ -12,4 +12,4 @@ var Foo = (function () { set: function (bar) {} }]); return Foo; -})(); \ No newline at end of file +})(); diff --git a/test/core/fixtures/transformation/es7.decorators/class-getter/expected.js b/test/core/fixtures/transformation/es7.decorators/class-getter/expected.js index 3beba2e582..8c7d3a793d 100644 --- a/test/core/fixtures/transformation/es7.decorators/class-getter/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class-getter/expected.js @@ -11,4 +11,4 @@ var Foo = (function () { get: function () {} }]); return Foo; -})(); \ No newline at end of file +})(); diff --git a/test/core/fixtures/transformation/es7.decorators/class-init-instance-props/expected.js b/test/core/fixtures/transformation/es7.decorators/class-init-instance-props/expected.js index 6753403675..db03a7b153 100644 --- a/test/core/fixtures/transformation/es7.decorators/class-init-instance-props/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class-init-instance-props/expected.js @@ -17,4 +17,4 @@ var Foo = (function () { enumerable: true }], null, _instanceInitializers); return Foo; -})(); \ No newline at end of file +})(); diff --git a/test/core/fixtures/transformation/es7.decorators/class-init-static-props/expected.js b/test/core/fixtures/transformation/es7.decorators/class-init-static-props/expected.js index c365832ed7..6c0c573906 100644 --- a/test/core/fixtures/transformation/es7.decorators/class-init-static-props/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class-init-static-props/expected.js @@ -17,4 +17,4 @@ var Foo = (function () { }], null, _staticInitializers); babelHelpers.defineDecoratedPropertyDescriptor(Foo, "foo", _staticInitializers); return Foo; -})(); \ No newline at end of file +})(); diff --git a/test/core/fixtures/transformation/es7.decorators/class-setter/expected.js b/test/core/fixtures/transformation/es7.decorators/class-setter/expected.js index ece61ab6e1..7b9537b539 100644 --- a/test/core/fixtures/transformation/es7.decorators/class-setter/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/class-setter/expected.js @@ -11,4 +11,4 @@ var Foo = (function () { set: function (arg) {} }]); return Foo; -})(); \ No newline at end of file +})(); diff --git a/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/actual.js b/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/actual.js index 772c63c875..37a0b6a98f 100644 --- a/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/actual.js +++ b/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/actual.js @@ -5,7 +5,7 @@ var obj = { }, @foo - set foo() { + set foo(bar) { } }; diff --git a/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/expected.js b/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/expected.js index 117515628e..68c9af550f 100644 --- a/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/object-getter-and-setter/expected.js @@ -3,6 +3,6 @@ var obj = babelHelpers.createDecoratedObject([{ key: "foo", decorators: [foo, foo], - get: function get() {}, - set: function set() {} + get: function () {}, + set: function (bar) {} }]); diff --git a/test/core/fixtures/transformation/es7.decorators/object-getter/expected.js b/test/core/fixtures/transformation/es7.decorators/object-getter/expected.js index bb651cf283..e0aa727de6 100644 --- a/test/core/fixtures/transformation/es7.decorators/object-getter/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/object-getter/expected.js @@ -3,5 +3,5 @@ var obj = babelHelpers.createDecoratedObject([{ key: "foo", decorators: [foo], - get: function get() {} + get: function () {} }]); diff --git a/test/core/fixtures/transformation/es7.decorators/object-setter/actual.js b/test/core/fixtures/transformation/es7.decorators/object-setter/actual.js index ec760bb339..52eb95db88 100644 --- a/test/core/fixtures/transformation/es7.decorators/object-setter/actual.js +++ b/test/core/fixtures/transformation/es7.decorators/object-setter/actual.js @@ -1,6 +1,6 @@ var obj = { @foo - set foo() { + set foo(bar) { } }; diff --git a/test/core/fixtures/transformation/es7.decorators/object-setter/expected.js b/test/core/fixtures/transformation/es7.decorators/object-setter/expected.js index 6b16d5c65c..ee3dc12281 100644 --- a/test/core/fixtures/transformation/es7.decorators/object-setter/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/object-setter/expected.js @@ -3,5 +3,5 @@ var obj = babelHelpers.createDecoratedObject([{ key: "foo", decorators: [foo], - set: function set() {} + set: function (bar) {} }]); diff --git a/test/core/fixtures/transformation/es7.decorators/object/expected.js b/test/core/fixtures/transformation/es7.decorators/object/expected.js index b6259d0cdc..7a7cc30560 100644 --- a/test/core/fixtures/transformation/es7.decorators/object/expected.js +++ b/test/core/fixtures/transformation/es7.decorators/object/expected.js @@ -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"; } -}]); \ No newline at end of file +}]); diff --git a/test/core/fixtures/transformation/flow/strip-type-annotations/expected.js b/test/core/fixtures/transformation/flow/strip-type-annotations/expected.js index 6a52c762fc..277f1ad2f0 100644 --- a/test/core/fixtures/transformation/flow/strip-type-annotations/expected.js +++ b/test/core/fixtures/transformation/flow/strip-type-annotations/expected.js @@ -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) {} diff --git a/test/core/fixtures/transformation/runtime/full/expected.js b/test/core/fixtures/transformation/runtime/full/expected.js index 2f08b10a1c..d83975b0db 100644 --- a/test/core/fixtures/transformation/runtime/full/expected.js +++ b/test/core/fixtures/transformation/runtime/full/expected.js @@ -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; \ No newline at end of file +bar; diff --git a/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js b/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js index 1a55265b4c..0980420528 100644 --- a/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js +++ b/test/core/fixtures/transformation/spec.proto-to-assign/assignment-expression/expected.js @@ -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)); \ No newline at end of file +console.log((_foo$bar2 = foo[bar()], _defaults(_foo$bar2, bar), _foo$bar2));