further work splitting up transformers into their own "category" in order of what they need and what they actually do
This commit is contained in:
parent
b376b6b33b
commit
8f9d02d689
@ -1,7 +1,7 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-cleanup"
|
||||
category: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var MemberExpression = {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-cleanup"
|
||||
category: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var Property = {
|
||||
|
||||
@ -1,26 +1,24 @@
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var ObjectExpression = {
|
||||
exit(node, parent, scope, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
defineMap.push(mutatorMap, prop, prop.kind, file);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.kind === "get" || prop.kind === "set") {
|
||||
hasAny = true;
|
||||
defineMap.push(mutatorMap, prop, prop.kind, file);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasAny) return;
|
||||
if (!hasAny) return;
|
||||
|
||||
return t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
|
||||
[node, defineMap.toDefineObject(mutatorMap)]
|
||||
);
|
||||
}
|
||||
};
|
||||
return t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
|
||||
[node, defineMap.toDefineObject(mutatorMap)]
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
|
||||
|
||||
@ -67,8 +67,8 @@ export var ObjectExpression = {
|
||||
exit(node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
|
||||
for (var prop of (node.properties: Array)) {
|
||||
hasComputed = t.isProperty(prop, { computed: true, kind: "init" });
|
||||
if (hasComputed) break;
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,10 @@ import * as util from "../../../util";
|
||||
import map from "lodash/collection/map";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-trailing"
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
if (node.generator || node.async) return;
|
||||
var tailCall = new TailCallTransformer(this, scope, file);
|
||||
|
||||
@ -1,20 +1,24 @@
|
||||
export default {
|
||||
// builtin-basic
|
||||
//- builtin-setup
|
||||
_validation: require("./internal/validation"),
|
||||
"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"),
|
||||
"spec.functionName": require("./spec/function-name"),
|
||||
"es6.arrowFunctions": require("./es6/arrow-functions"),
|
||||
"spec.blockScopedFunctions": require("./spec/block-scoped-functions"),
|
||||
"optimisation.react.constantElements": require("./optimisation/react.constant-elements"),
|
||||
@ -41,30 +45,37 @@ export default {
|
||||
"es6.parameters.rest": require("./es6/parameters.rest"),
|
||||
"es6.spread": require("./es6/spread"),
|
||||
"es6.parameters.default": require("./es6/parameters.default"),
|
||||
"es6.destructuring": require("./es6/destructuring"),
|
||||
"es6.tailCall": require("./es6/tail-call"),
|
||||
"es7.exportExtensions": require("./es7/export-extensions"),
|
||||
"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"),
|
||||
jscript: require("./other/jscript"),
|
||||
flow: require("./other/flow"),
|
||||
_hoistDirectives: require("./internal/hoist-directives"),
|
||||
|
||||
// builtin-modules
|
||||
"es6.modules": require("./es6/modules"),
|
||||
regenerator: require("./other/regenerator"),
|
||||
runtime: require("./other/runtime"),
|
||||
_moduleFormatter: require("./internal/module-formatter"),
|
||||
|
||||
// builtin-advanced
|
||||
//- builtin-advanced
|
||||
"es6.destructuring": require("./es6/destructuring"),
|
||||
"es6.blockScoping": require("./es6/block-scoping"),
|
||||
"es6.spec.blockScoping": require("./es6/spec.block-scoping"),
|
||||
|
||||
// builtin-cleanup
|
||||
// es6 syntax transformation is **forbidden** past this point since regenerator will chuck a massive
|
||||
// hissy fit
|
||||
|
||||
//- regenerator
|
||||
regenerator: require("./other/regenerator"),
|
||||
|
||||
//- builtin-modules
|
||||
runtime: require("./other/runtime"),
|
||||
"es6.modules": require("./es6/modules"),
|
||||
_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"),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import sortBy from "lodash/collection/sortBy";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-cleanup"
|
||||
category: "builtin-trailing"
|
||||
};
|
||||
|
||||
// Priority:
|
||||
|
||||
@ -6,6 +6,10 @@
|
||||
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ImportDeclaration(node, parent, scope, file) {
|
||||
if (node.source) {
|
||||
node.source.value = file.resolveModuleSource(node.source.value);
|
||||
|
||||
@ -86,7 +86,7 @@ function aliasFunction(getBody, path, scope) {
|
||||
// crawling the entire function tree
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-cleanup"
|
||||
category: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var Program = {
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
|
||||
@ -18,7 +18,8 @@ function toStatements(node) {
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
export function Identifier(node, parent, scope) {
|
||||
|
||||
@ -2,7 +2,7 @@ import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
category: "builtin-cleanup"
|
||||
category: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var MemberExpression = {
|
||||
|
||||
@ -2,7 +2,7 @@ import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
category: "builtin-cleanup"
|
||||
category: "builtin-trailing"
|
||||
};
|
||||
|
||||
export var Property = {
|
||||
|
||||
@ -2,11 +2,9 @@ import regenerator from "regenerator";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
category: "builtin-modules"
|
||||
category: "regenerator"
|
||||
};
|
||||
|
||||
export var Program = {
|
||||
exit(ast) {
|
||||
regenerator.transform(ast);
|
||||
}
|
||||
};
|
||||
export function Program(ast) {
|
||||
regenerator.transform(ast);
|
||||
}
|
||||
|
||||
@ -11,10 +11,10 @@ const RUNTIME_MODULE_NAME = "babel-runtime";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
category: "builtin-modules"
|
||||
category: "builtin-post-modules"
|
||||
};
|
||||
|
||||
export function Program(node, parent, scope, file) {
|
||||
export function pre(file) {
|
||||
file.set("helperGenerator", function (name) {
|
||||
return file.addImport(`${RUNTIME_MODULE_NAME}/helpers/${name}`, name, "absoluteDefault");
|
||||
});
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
export var metadata = {
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
export {
|
||||
bare as FunctionExpression,
|
||||
bare as ArrowFunctionExpression
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
var match = t.buildMatchMemberExpression("process.env");
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
export function Expression(node, parent, scope) {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
export function CallExpression(node, parent) {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
category: "builtin-setup"
|
||||
};
|
||||
|
||||
export function ExpressionStatement(node) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user