Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70967cf53c | ||
|
|
dc117a74ae | ||
|
|
b0f32a822d | ||
|
|
fd99ea1749 | ||
|
|
572129542d | ||
|
|
6f53980bfc | ||
|
|
348af1990d | ||
|
|
bd5f350728 | ||
|
|
958fa282f4 | ||
|
|
31e6b18346 | ||
|
|
d17ac92a3f | ||
|
|
188bcb70f7 | ||
|
|
b8bd11a0e7 | ||
|
|
45bc74efe7 | ||
|
|
7eb169a894 | ||
|
|
eed4f312d8 | ||
|
|
44e4dc970f | ||
|
|
5d32432e67 | ||
|
|
9c9af6dbbd | ||
|
|
70cd650e10 | ||
|
|
c7bb00d58d | ||
|
|
623be068c4 | ||
|
|
71f5c9791d | ||
|
|
3e6e86d073 | ||
|
|
a0fb398ca2 | ||
|
|
71b9f19e6a | ||
|
|
c45ce58f0c | ||
|
|
d32f587e3c | ||
|
|
9e1874ba89 | ||
|
|
35fdc5c5d8 | ||
|
|
a4035fc257 | ||
|
|
42e3dc7a70 | ||
|
|
cdccf24515 | ||
|
|
c8cd5c108b | ||
|
|
2b95b876e1 | ||
|
|
f801772fc2 | ||
|
|
8ad678e5bc | ||
|
|
35c49dbef7 | ||
|
|
119314df74 | ||
|
|
51e336b037 | ||
|
|
7d446807a9 | ||
|
|
8afdeaf557 | ||
|
|
4df50954a2 | ||
|
|
70b6317865 | ||
|
|
5ebdc44297 | ||
|
|
a4659fd239 | ||
|
|
19bfa4a35b | ||
|
|
f7fff7d35e | ||
|
|
130e0ebe6b | ||
|
|
69c836fc8d | ||
|
|
f62a3ef394 | ||
|
|
7a6e568940 | ||
|
|
65998c3437 | ||
|
|
160de340b0 | ||
|
|
76ca40f698 | ||
|
|
01ed824b5c | ||
|
|
6b0dbc4486 | ||
|
|
2648268f30 | ||
|
|
8cf5bf7037 | ||
|
|
60961bc3ff | ||
|
|
df16bc17e7 | ||
|
|
5337ab5a08 | ||
|
|
2eaeebcce4 | ||
|
|
ad71010144 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,5 +12,6 @@ coverage
|
||||
dist
|
||||
.package.json
|
||||
packages/babel-runtime/*.js
|
||||
packages/babel-runtime/helpers/*.js
|
||||
packages/babel-runtime/regenerator/*.js
|
||||
lib
|
||||
|
||||
25
CHANGELOG.md
25
CHANGELOG.md
@@ -13,6 +13,31 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 4.7.2
|
||||
|
||||
* **New Feature**
|
||||
* `"both"` option for `sourceMap`.
|
||||
* Add output types to external helpers. Thanks [@neVERberleRfellerER](https://github.com/neVERberleRfellerER)!
|
||||
* **Bug Fix**
|
||||
* Fix node duplication sometimes resulting in a recursion error.
|
||||
* Ignore `break`s within cases inside `for...of`.
|
||||
* **Polish**
|
||||
* Split up variable declarations and export declarations to allow easier transformation.
|
||||
|
||||
## 4.7.0
|
||||
|
||||
* **Bug Fix**
|
||||
* Add `alternate` to list of `STATEMENT_OR_BLOCK` keys.
|
||||
* Add support for module specifiers to `t.isReferenced`.
|
||||
* **New Feature**
|
||||
* Add `inputSourceMap` option.
|
||||
* **Polish**
|
||||
* Throw an error on different `babel` and `babel-runtime` versions.
|
||||
* Replicate module environment for `babel-node` eval.
|
||||
* Clean up classes output.
|
||||
* **Spec Compliancy**
|
||||
* Make it illegal to use a rest parameter on a setter.
|
||||
|
||||
## 4.6.6
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
@@ -60,7 +60,18 @@ if (program.eval || program.print) {
|
||||
var code = program.eval;
|
||||
if (!code || code === true) code = program.print;
|
||||
|
||||
var result = _eval(code, "eval");
|
||||
global.__filename = "[eval]";
|
||||
global.__dirname = process.cwd();
|
||||
|
||||
var module = new Module(global.__filename);
|
||||
module.filename = global.__filename;
|
||||
module.paths = Module._nodeModulePaths(global.__dirname);
|
||||
|
||||
global.exports = module.exports;
|
||||
global.module = module;
|
||||
global.require = module.require.bind(module);
|
||||
|
||||
var result = _eval(code, global.__filename);
|
||||
if (program.print) console.log(result);
|
||||
} else {
|
||||
if (program.args.length) {
|
||||
@@ -88,7 +99,7 @@ if (program.eval || program.print) {
|
||||
args = args.slice(i);
|
||||
|
||||
// make the filename absolute
|
||||
var filename = args[0]
|
||||
var filename = args[0];
|
||||
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var util = require("../lib/babel/util");
|
||||
var runtime = require("../lib/babel/build-external-helpers");
|
||||
console.log(runtime());
|
||||
|
||||
commander.option("-l, --whitelist [whitelist]", "Whitelist of helpers to ONLY include", util.list);
|
||||
commander.option("-t, --output-type [type]", "Type of output (global|umd|var)", "global");
|
||||
|
||||
commander.usage("[options]");
|
||||
commander.parse(process.argv);
|
||||
|
||||
console.log(runtime(commander.whitelist, commander.outputType));
|
||||
|
||||
@@ -7,7 +7,17 @@
|
||||
|
||||
var args = [__dirname + "/_babel-node"];
|
||||
|
||||
process.argv.slice(2).forEach(function(arg){
|
||||
var babelArgs = process.argv.slice(2);
|
||||
var userArgs;
|
||||
|
||||
// separate node arguments from script arguments
|
||||
var argSeparator = babelArgs.indexOf("--");
|
||||
if (argSeparator > -1) {
|
||||
userArgs = babelArgs.slice(argSeparator); // including the --
|
||||
babelArgs = babelArgs.slice(0, argSeparator);
|
||||
}
|
||||
|
||||
babelArgs.forEach(function(arg){
|
||||
var flag = arg.split("=")[0];
|
||||
|
||||
switch (flag) {
|
||||
@@ -49,6 +59,11 @@ process.argv.slice(2).forEach(function(arg){
|
||||
}
|
||||
});
|
||||
|
||||
// append arguments passed after --
|
||||
if (argSeparator > -1) {
|
||||
args = args.concat(userArgs);
|
||||
}
|
||||
|
||||
try {
|
||||
var kexec = require("kexec");
|
||||
kexec(process.argv[0], args);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var sourceMapToComment = require("source-map-to-comment");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var convertSourceMap = require("convert-source-map");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames) {
|
||||
var results = [];
|
||||
@@ -42,7 +42,7 @@ module.exports = function (commander, filenames) {
|
||||
});
|
||||
|
||||
if (commander.sourceMapsInline || (!commander.outFile && commander.sourceMaps)) {
|
||||
code += "\n" + sourceMapToComment(map);
|
||||
code += "\n" + convertSourceMap.fromObject(map).toComment();
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "4.6.6",
|
||||
"version": "4.7.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -37,10 +37,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-babel": "0.11.1-37",
|
||||
"ast-types": "~0.6.1",
|
||||
"ast-types": "~0.7.0",
|
||||
"chalk": "^1.0.0",
|
||||
"chokidar": "^0.12.6",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^0.5.0",
|
||||
"core-js": "^0.6.1",
|
||||
"debug": "^2.1.1",
|
||||
"detect-indent": "^3.0.0",
|
||||
@@ -56,14 +57,14 @@
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"private": "^0.1.6",
|
||||
"regenerator-babel": "0.8.13-1",
|
||||
"regenerator-babel": "0.8.13-2",
|
||||
"regexpu": "^1.1.2",
|
||||
"repeating": "^1.1.2",
|
||||
"shebang-regex": "^1.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.4.0",
|
||||
"source-map-support": "^0.2.9",
|
||||
"source-map-to-comment": "^1.0.0",
|
||||
"to-fast-properties": "^1.0.0",
|
||||
"trim-right": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
0
packages/babel-runtime/helpers/.gitkeep
Normal file
0
packages/babel-runtime/helpers/.gitkeep
Normal file
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "4.6.5",
|
||||
"version": "4.7.2",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var transform = require("../lib/babel/transformation");
|
||||
var buildHelpers = require("../lib/babel/build-helpers");
|
||||
var util = require("../lib/babel/util");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/babel/types");
|
||||
var _ = require("lodash");
|
||||
var transform = require("../lib/babel/transformation");
|
||||
var each = require("lodash/collection/each");
|
||||
var File = require("../lib/babel/transformation/file");
|
||||
var util = require("../lib/babel/util");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/babel/types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var relative = function (filename) {
|
||||
return __dirname + "/babel-runtime/" + filename;
|
||||
@@ -39,22 +40,26 @@ var updatePackage = function () {
|
||||
|
||||
var selfContainify = function (code) {
|
||||
return transform(code, {
|
||||
optional: ["selfContained"]
|
||||
optional: ["runtime"]
|
||||
}).code;
|
||||
};
|
||||
|
||||
var buildHelpers2 = function () {
|
||||
var body = util.template("self-contained-helpers-head");
|
||||
var tree = t.program(body);
|
||||
|
||||
buildHelpers(body, t.identifier("helpers"));
|
||||
var buildHelper = function (helperName) {
|
||||
var tree = t.program(
|
||||
util.template("self-contained-helpers-head", {
|
||||
HELPER: util.template(helperName)
|
||||
})
|
||||
);
|
||||
|
||||
return transform.fromAst(tree, null, {
|
||||
optional: ["selfContained"]
|
||||
optional: ["runtime"]
|
||||
}).code;
|
||||
};
|
||||
|
||||
writeFile("helpers.js", buildHelpers2());
|
||||
each(File.helpers, function (helperName) {
|
||||
writeFile("helpers/" + helperName + ".js", buildHelper(helperName));
|
||||
});
|
||||
|
||||
writeFile("core-js.js", readFile("core-js/library", true));
|
||||
writeFile("regenerator/index.js", readFile("regenerator-babel/runtime-module", true));
|
||||
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator-babel/runtime")));
|
||||
|
||||
@@ -57,7 +57,7 @@ var compile = function (filename) {
|
||||
|
||||
if (!result) {
|
||||
result = babel.transformFileSync(filename, extend(opts, {
|
||||
sourceMap: true,
|
||||
sourceMap: "both",
|
||||
ast: false
|
||||
}));
|
||||
}
|
||||
@@ -153,3 +153,16 @@ export default function (opts = {}) {
|
||||
|
||||
extend(transformOpts, opts);
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
try {
|
||||
var runtimePackage = require("babel-runtime/package");
|
||||
var version = require("../../package").version;
|
||||
if (runtimePackage.version !== version) {
|
||||
throw new ReferenceError(`The verison of babel-runtime of ${runtimePackage.runtime} that you have installed does not match the babel verison of ${version}`);
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import buildHelpers from "./build-helpers";
|
||||
import generator from "./generation";
|
||||
import * as messages from "./messages";
|
||||
import * as util from "./util";
|
||||
import File from "./transformation/file";
|
||||
import each from "lodash/collection/each";
|
||||
import t from "./types";
|
||||
|
||||
export default function (whitelist) {
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
function buildGlobal(namespace, builder) {
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, [util.template("self-global")]))]);
|
||||
@@ -17,7 +17,70 @@ export default function (whitelist) {
|
||||
)
|
||||
]));
|
||||
|
||||
buildHelpers(body, namespace, whitelist);
|
||||
builder(body);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
function buildUmd(namespace, builder) {
|
||||
var body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(namespace, t.identifier("global"))
|
||||
]));
|
||||
|
||||
builder(body);
|
||||
|
||||
var container = util.template("umd-commonjs-strict", {
|
||||
FACTORY_PARAMETERS: t.identifier("global"),
|
||||
BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression({})),
|
||||
COMMON_ARGUMENTS: t.identifier("exports"),
|
||||
AMD_ARGUMENTS: t.arrayExpression([t.literal("exports")]),
|
||||
FACTORY_BODY: body,
|
||||
UMD_ROOT: t.identifier("this")
|
||||
});
|
||||
return t.program([container]);
|
||||
}
|
||||
|
||||
function buildVar(namespace, builder) {
|
||||
var body = [];
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(namespace, t.objectExpression({}))
|
||||
]));
|
||||
builder(body);
|
||||
return t.program(body);
|
||||
}
|
||||
|
||||
function buildHelpers(body, namespace, whitelist = []) {
|
||||
each(File.helpers, function (name) {
|
||||
if (whitelist.length && whitelist.indexOf(name) === -1) return;
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
export default function (whitelist, outputType = "global") {
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
var builder = function (body) {
|
||||
return buildHelpers(body, namespace, whitelist);
|
||||
};
|
||||
|
||||
var tree;
|
||||
|
||||
var build = {
|
||||
global: buildGlobal,
|
||||
umd: buildUmd,
|
||||
var: buildVar
|
||||
}[outputType];
|
||||
|
||||
if (build) {
|
||||
tree = build(namespace, builder);
|
||||
} else {
|
||||
throw new Error(messages.get("unsupportedOutputType", outputType));
|
||||
}
|
||||
|
||||
return generator(tree).code;
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import File from "./transformation/file";
|
||||
import * as util from "./util";
|
||||
import each from "lodash/collection/each";
|
||||
import t from "./types";
|
||||
|
||||
export default function (body, namespace, whitelist = []) {
|
||||
each(File.helpers, function (name) {
|
||||
if (whitelist.length && whitelist.indexOf(name) === -1) return;
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", t.memberExpression(namespace, key), util.template(name))
|
||||
));
|
||||
});
|
||||
};
|
||||
@@ -55,7 +55,7 @@ var highlight = function (text) {
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = function (lines, lineNumber, colNumber) {
|
||||
export default function (lines, lineNumber, colNumber) {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
if (chalk.supportsColor) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import t from "../types";
|
||||
|
||||
module.exports = function (ast, comments, tokens) {
|
||||
export default function (ast, comments, tokens) {
|
||||
if (ast && ast.type === "Program") {
|
||||
return t.file(ast, comments || [], tokens || []);
|
||||
} else {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module.exports = function () {
|
||||
export default function () {
|
||||
return Object.create(null);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import estraverse from "estraverse";
|
||||
import codeFrame from "./code-frame";
|
||||
import acorn from "acorn-babel";
|
||||
|
||||
module.exports = function (opts, code, callback) {
|
||||
export default function (opts, code, callback) {
|
||||
try {
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* A trick from Bluebird to force V8 to use fast properties for an object.
|
||||
* Read more: http://stackoverflow.com/questions/24987896/
|
||||
*
|
||||
* Use %HasFastProperties(obj) and --allow-natives-syntax to check whether
|
||||
* a particular object already has fast properties.
|
||||
*/
|
||||
|
||||
module.exports = function toFastProperties(obj) {
|
||||
/*jshint -W027*/
|
||||
function f() {}
|
||||
f.prototype = obj;
|
||||
return f;
|
||||
eval(obj);
|
||||
};
|
||||
@@ -10,6 +10,7 @@ export var messages = {
|
||||
undeclaredVariable: "Reference to undeclared variable $1",
|
||||
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
|
||||
settersInvalidParamLength: "Setters must have exactly one parameter",
|
||||
settersNoRest: "Setters aren't allowed to have a rest",
|
||||
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
|
||||
expectedMemberExpressionOrIdentifier: "Expected type MemeberExpression or Identifier",
|
||||
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
|
||||
@@ -18,7 +19,9 @@ export var messages = {
|
||||
unknownForHead: "Unknown node type $1 in ForStatement",
|
||||
didYouMean: "Did you mean $1?",
|
||||
evalInStrictMode: "eval is not allowed in strict mode",
|
||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2."
|
||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2.",
|
||||
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||
unsupportedOutputType: "Unsupported output type $1"
|
||||
};
|
||||
|
||||
export function get(key) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import sourceMapToComment from "source-map-to-comment";
|
||||
import convertSourceMap from "convert-source-map";
|
||||
import shebangRegex from "shebang-regex";
|
||||
import isFunction from "lodash/lang/isFunction";
|
||||
import sourceMap from "source-map";
|
||||
import transform from "./index";
|
||||
import generate from "../generation";
|
||||
import defaults from "lodash/object/defaults";
|
||||
@@ -48,7 +49,7 @@ export default class File {
|
||||
static helpers = [
|
||||
"inherits",
|
||||
"defaults",
|
||||
"prototype-properties",
|
||||
"create-class",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
"tagged-template-literal-loose",
|
||||
@@ -77,34 +78,41 @@ export default class File {
|
||||
static validOptions = [
|
||||
"filename",
|
||||
"filenameRelative",
|
||||
|
||||
"blacklist",
|
||||
"whitelist",
|
||||
"loose",
|
||||
"optional",
|
||||
|
||||
"loose",
|
||||
"playground",
|
||||
"experimental",
|
||||
|
||||
"modules",
|
||||
"moduleIds",
|
||||
"moduleId",
|
||||
"resolveModuleSource",
|
||||
"keepModuleIdExtensions",
|
||||
|
||||
"code",
|
||||
"ast",
|
||||
|
||||
"comments",
|
||||
"compact",
|
||||
|
||||
"auxiliaryComment",
|
||||
"externalHelpers",
|
||||
"returnUsedHelpers",
|
||||
|
||||
"inputSourceMap",
|
||||
"sourceMap",
|
||||
"sourceMapName",
|
||||
"sourceFileName",
|
||||
"sourceRoot",
|
||||
"moduleRoot",
|
||||
"moduleIds",
|
||||
"comments",
|
||||
"reactCompat",
|
||||
"keepModuleIdExtensions",
|
||||
"code",
|
||||
"ast",
|
||||
"playground",
|
||||
"experimental",
|
||||
"externalHelpers",
|
||||
"auxiliaryComment",
|
||||
"compact",
|
||||
"returnUsedHelpers",
|
||||
|
||||
"resolveModuleSource",
|
||||
"moduleId",
|
||||
|
||||
// legacy
|
||||
"format",
|
||||
"reactCompat",
|
||||
|
||||
// these are used by plugins
|
||||
"ignore",
|
||||
@@ -128,6 +136,7 @@ export default class File {
|
||||
returnUsedHelpers: false,
|
||||
externalHelpers: false,
|
||||
auxilaryComment: "",
|
||||
inputSourceMap: false,
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
@@ -145,6 +154,10 @@ export default class File {
|
||||
ast: true
|
||||
});
|
||||
|
||||
if (opts.inputSourceMap) {
|
||||
opts.sourceMap = true;
|
||||
}
|
||||
|
||||
// normalize windows path separators to unix
|
||||
opts.filename = slash(opts.filename);
|
||||
if (opts.sourceRoot) {
|
||||
@@ -267,6 +280,18 @@ export default class File {
|
||||
return new ModuleFormatter(this);
|
||||
}
|
||||
|
||||
parseInputSourceMap(code) {
|
||||
var opts = this.opts;
|
||||
|
||||
var inputMap = convertSourceMap.fromSource(code);
|
||||
if (inputMap) {
|
||||
opts.inputSourceMap = inputMap.toObject();
|
||||
code = convertSourceMap.removeComments(code);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
parseShebang(code) {
|
||||
var shebangMatch = shebangRegex.exec(code);
|
||||
|
||||
@@ -314,7 +339,11 @@ export default class File {
|
||||
this.dynamicImported.push(declar);
|
||||
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
||||
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
if (this.transformers["es6.modules"].canRun()) {
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
} else {
|
||||
this.dynamicImports.push(declar);
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
@@ -348,10 +377,13 @@ export default class File {
|
||||
|
||||
this.usedHelpers[name] = true;
|
||||
|
||||
var generator = this.get("helperGenerator");
|
||||
var runtime = this.get("helpersNamespace");
|
||||
if (runtime) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, name);
|
||||
if (generator) {
|
||||
return generator(name);
|
||||
} else if (runtime) {
|
||||
var id = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, id);
|
||||
} else {
|
||||
var ref = util.template(name);
|
||||
ref._compact = true;
|
||||
@@ -378,6 +410,7 @@ export default class File {
|
||||
|
||||
addCode(code) {
|
||||
code = (code || "") + "";
|
||||
code = this.parseInputSourceMap(code);
|
||||
this.code = code;
|
||||
return this.parseShebang(code);
|
||||
}
|
||||
@@ -447,6 +480,28 @@ export default class File {
|
||||
});
|
||||
}
|
||||
|
||||
mergeSourceMap(map) {
|
||||
var opts = this.opts;
|
||||
|
||||
var inputMap = opts.inputSourceMap;
|
||||
|
||||
if (inputMap) {
|
||||
map.sources[0] = inputMap.file;
|
||||
|
||||
var inputMapConsumer = new sourceMap.SourceMapConsumer(inputMap);
|
||||
var outputMapConsumer = new sourceMap.SourceMapConsumer(map);
|
||||
var outputMapGenerator = sourceMap.SourceMapGenerator.fromSourceMap(outputMapConsumer);
|
||||
outputMapGenerator.applySourceMap(inputMapConsumer);
|
||||
|
||||
var mergedMap = outputMapGenerator.toJSON();
|
||||
mergedMap.sources = inputMap.sources
|
||||
mergedMap.file = inputMap.file;
|
||||
return mergedMap;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
generate() {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
@@ -473,8 +528,13 @@ export default class File {
|
||||
result.code = `${this.shebang}\n${result.code}`;
|
||||
}
|
||||
|
||||
result.map = this.mergeSourceMap(result.map);
|
||||
|
||||
if (opts.sourceMap === "inline" || opts.sourceMap === "both") {
|
||||
result.code += "\n" + convertSourceMap.fromObject(result.map).toComment();
|
||||
}
|
||||
|
||||
if (opts.sourceMap === "inline") {
|
||||
result.code += "\n" + sourceMapToComment(result.map);
|
||||
result.map = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import explode from "./explode-assignable-expression";
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (exports, opts) {
|
||||
export default function (exports, opts) {
|
||||
var isAssignment = function (node) {
|
||||
return node.operator === opts.operator + "=";
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function build(node, buildBody) {
|
||||
export default function build(node, buildBody) {
|
||||
var self = node.blocks.shift();
|
||||
if (!self) return;
|
||||
|
||||
@@ -20,4 +20,4 @@ module.exports = function build(node, buildBody) {
|
||||
self.right,
|
||||
t.blockStatement([child])
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import explode from "./explode-assignable-expression";
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (exports, opts) {
|
||||
export default function (exports, opts) {
|
||||
var buildAssignment = function (left, right) {
|
||||
return t.assignmentExpression("=", left, right);
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ import esutils from "esutils";
|
||||
import * as react from "./react";
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (exports, opts) {
|
||||
export default function (exports, opts) {
|
||||
exports.check = function (node) {
|
||||
if (t.isJSX(node)) return true;
|
||||
if (react.isCreateClass(node)) return true;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import traverse from "../../traversal";
|
||||
import clone from "lodash/lang/clone";
|
||||
import each from "lodash/collection/each";
|
||||
import has from "lodash/object/has";
|
||||
import t from "../../types";
|
||||
@@ -14,7 +13,7 @@ export function push(mutatorMap, key, kind, computed, value) {
|
||||
} else if (t.isLiteral(key)) {
|
||||
alias = String(key.value);
|
||||
} else {
|
||||
alias = JSON.stringify(traverse.removeProperties(cloneDeep(key)));
|
||||
alias = JSON.stringify(traverse.removeProperties(t.cloneDeep(key)));
|
||||
}
|
||||
|
||||
var map;
|
||||
@@ -33,7 +32,7 @@ export function push(mutatorMap, key, kind, computed, value) {
|
||||
map[kind] = value;
|
||||
}
|
||||
|
||||
export function build(mutatorMap) {
|
||||
export function toClassObject(mutatorMap) {
|
||||
var objExpr = t.objectExpression([]);
|
||||
|
||||
each(mutatorMap, function (map) {
|
||||
@@ -41,22 +40,43 @@ export function build(mutatorMap) {
|
||||
|
||||
var propNode = t.property("init", map._key, mapNode, map._computed);
|
||||
|
||||
if (!map.get && !map.set) {
|
||||
map.writable = t.literal(true);
|
||||
}
|
||||
|
||||
if (map.enumerable === false) {
|
||||
delete map.enumerable;
|
||||
} else {
|
||||
map.enumerable = t.literal(true);
|
||||
}
|
||||
|
||||
map.configurable = t.literal(true);
|
||||
|
||||
each(map, function (node, key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
node = clone(node);
|
||||
var inheritNode = node;
|
||||
if (t.isMethodDefinition(node)) node = node.value;
|
||||
|
||||
var prop = t.property("init", t.identifier(key), node);
|
||||
t.inheritsComments(prop, inheritNode);
|
||||
t.removeComments(inheritNode);
|
||||
mapNode.properties.push(prop);
|
||||
});
|
||||
|
||||
objExpr.properties.push(propNode);
|
||||
});
|
||||
|
||||
return objExpr;
|
||||
}
|
||||
|
||||
export function toDefineObject(mutatorMap) {
|
||||
var objExpr = t.objectExpression([]);
|
||||
|
||||
each(mutatorMap, function (map) {
|
||||
var mapNode = t.objectExpression([]);
|
||||
|
||||
var propNode = t.property("init", map._key, mapNode, map._computed);
|
||||
|
||||
if (map.value) {
|
||||
map.writable = t.literal(true);
|
||||
}
|
||||
|
||||
map.configurable = t.literal(true);
|
||||
map.enumerable = t.literal(true);
|
||||
|
||||
each(map, function (node, key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
node = t.clone(node);
|
||||
var inheritNode = node;
|
||||
if (t.isMethodDefinition(node)) node = node.value;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ var getPropRef = function (node, nodes, file, scope) {
|
||||
return temp;
|
||||
};
|
||||
|
||||
module.exports = function (node, nodes, file, scope, allowedSingleIdent) {
|
||||
export default function (node, nodes, file, scope, allowedSingleIdent) {
|
||||
var obj;
|
||||
if (t.isIdentifier(node) && allowedSingleIdent) {
|
||||
obj = node;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (node) {
|
||||
export default function (node) {
|
||||
var lastNonDefault = 0;
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
if (!t.isAssignmentPattern(node.params[i])) lastNonDefault = i + 1;
|
||||
|
||||
@@ -6,7 +6,7 @@ var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// check if this node is a referenced identifier that matches the same as our
|
||||
// function id
|
||||
if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;
|
||||
if (!this.isReferencedIdentifier({ name: state.name })) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
@@ -89,6 +89,11 @@ var visit = function (node, name, scope) {
|
||||
return state;
|
||||
};
|
||||
|
||||
export function custom(node, id, scope) {
|
||||
var state = visit(node, id.name, scope);
|
||||
return wrap(state, node, id, scope);
|
||||
}
|
||||
|
||||
export function property(node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
@@ -103,7 +108,7 @@ export function property(node, file, scope) {
|
||||
|
||||
export function bare(node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
if (node.id) return node;
|
||||
|
||||
var id;
|
||||
if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) {
|
||||
@@ -113,10 +118,10 @@ export function bare(node, parent, scope) {
|
||||
// var foo = function () {};
|
||||
id = parent.id;
|
||||
} else {
|
||||
return;
|
||||
return node;
|
||||
}
|
||||
|
||||
if (!t.isIdentifier(id)) return;
|
||||
if (!t.isIdentifier(id)) return node;
|
||||
|
||||
var name = t.toIdentifier(id.name);
|
||||
id = t.identifier(name);
|
||||
|
||||
@@ -16,7 +16,7 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function (node, callId, scope) {
|
||||
export default function (node, callId, scope) {
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = function (node, callId, scope) {
|
||||
|
||||
var call = t.callExpression(callId, [node]);
|
||||
var id = node.id;
|
||||
delete node.id;
|
||||
node.id = null;
|
||||
|
||||
if (t.isFunctionDeclaration(node)) {
|
||||
var declar = t.variableDeclaration("let", [
|
||||
|
||||
@@ -55,14 +55,18 @@ export default class ReplaceSupers {
|
||||
constructor(opts, inClass) {
|
||||
this.topLevelThisReference = opts.topLevelThisReference;
|
||||
this.methodNode = opts.methodNode;
|
||||
this.className = opts.className;
|
||||
this.superName = opts.superName;
|
||||
this.superRef = opts.superRef;
|
||||
this.isStatic = opts.isStatic;
|
||||
this.hasSuper = false;
|
||||
this.inClass = inClass;
|
||||
this.isLoose = opts.isLoose;
|
||||
this.scope = opts.scope;
|
||||
this.file = opts.file;
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
getObjectRef() {
|
||||
return this.opts.objectRef || this.opts.getObjectRef();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +91,7 @@ export default class ReplaceSupers {
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
|
||||
[
|
||||
this.isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
|
||||
this.isStatic ? this.getObjectRef() : t.memberExpression(this.getObjectRef(), t.identifier("prototype"))
|
||||
]
|
||||
),
|
||||
isComputed ? property : t.literal(property.name),
|
||||
@@ -118,7 +122,7 @@ export default class ReplaceSupers {
|
||||
t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
|
||||
[
|
||||
this.isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
|
||||
this.isStatic ? this.getObjectRef() : t.memberExpression(this.getObjectRef(), t.identifier("prototype"))
|
||||
]
|
||||
),
|
||||
isComputed ? property : t.literal(property.name),
|
||||
@@ -175,19 +179,19 @@ export default class ReplaceSupers {
|
||||
getLooseSuperProperty(id, parent) {
|
||||
var methodNode = this.methodNode;
|
||||
var methodName = methodNode.key;
|
||||
var superName = this.superName || t.identifier("Function");
|
||||
var superRef = this.superRef || t.identifier("Function");
|
||||
|
||||
if (parent.property === id) {
|
||||
return;
|
||||
} else if (t.isCallExpression(parent, { callee: id })) {
|
||||
// super(); -> ClassName.prototype.MethodName.call(this);
|
||||
// super(); -> objectRef.prototype.MethodName.call(this);
|
||||
parent.arguments.unshift(t.thisExpression());
|
||||
|
||||
if (methodName.name === "constructor") {
|
||||
// constructor() { super(); }
|
||||
return t.memberExpression(superName, t.identifier("call"));
|
||||
return t.memberExpression(superRef, t.identifier("call"));
|
||||
} else {
|
||||
id = superName;
|
||||
id = superRef;
|
||||
|
||||
// foo() { super(); }
|
||||
if (!methodNode.static) {
|
||||
@@ -198,10 +202,10 @@ export default class ReplaceSupers {
|
||||
return t.memberExpression(id, t.identifier("call"));
|
||||
}
|
||||
} else if (t.isMemberExpression(parent) && !methodNode.static) {
|
||||
// super.test -> ClassName.prototype.test
|
||||
return t.memberExpression(superName, t.identifier("prototype"));
|
||||
// super.test -> objectRef.prototype.test
|
||||
return t.memberExpression(superRef, t.identifier("prototype"));
|
||||
} else {
|
||||
return superName;
|
||||
return superRef;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +226,7 @@ export default class ReplaceSupers {
|
||||
if (!t.isMemberExpression(callee)) return;
|
||||
if (callee.object.name !== "super") return;
|
||||
|
||||
// super.test(); -> ClassName.prototype.MethodName.call(this);
|
||||
// super.test(); -> objectRef.prototype.MethodName.call(this);
|
||||
this.hasSuper = true;
|
||||
t.appendToMemberExpression(callee, t.identifier("call"));
|
||||
node.arguments.unshift(getThisReference());
|
||||
@@ -251,7 +255,7 @@ export default class ReplaceSupers {
|
||||
if (t.isCallExpression(node)) {
|
||||
var callee = node.callee;
|
||||
if (isSuper(callee, node)) {
|
||||
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
|
||||
// super(); -> _get(Object.getPrototypeOf(objectRef), "MethodName", this).call(this);
|
||||
property = methodNode.key;
|
||||
computed = methodNode.computed;
|
||||
args = node.arguments;
|
||||
@@ -264,17 +268,17 @@ export default class ReplaceSupers {
|
||||
throw this.file.errorWithNode(node, messages.get("classesIllegalSuperCall", methodName));
|
||||
}
|
||||
} else if (t.isMemberExpression(callee) && isSuper(callee.object, callee)) {
|
||||
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
|
||||
// super.test(); -> _get(Object.getPrototypeOf(objectRef.prototype), "test", this).call(this);
|
||||
property = callee.property;
|
||||
computed = callee.computed;
|
||||
args = node.arguments;
|
||||
}
|
||||
} else if (t.isMemberExpression(node) && isSuper(node.object, node)) {
|
||||
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
// super.name; -> _get(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
||||
property = node.property;
|
||||
computed = node.computed;
|
||||
} else if (t.isAssignmentExpression(node) && isSuper(node.left.object, node.left) && methodNode.kind === "set") {
|
||||
// super.name = "val"; -> _set(Object.getPrototypeOf(ClassName.prototype), "name", this);
|
||||
// super.name = "val"; -> _set(Object.getPrototypeOf(objectRef.prototype), "name", this);
|
||||
this.hasSuper = true;
|
||||
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ var remapVisitor = {
|
||||
};
|
||||
|
||||
var importsVisitor = {
|
||||
enter(node, parent, scope, formatter) {
|
||||
if (t.isImportDeclaration(node)) {
|
||||
ImportDeclaration: {
|
||||
enter(node, parent, scope, formatter) {
|
||||
formatter.hasLocalImports = true;
|
||||
extend(formatter.localImports, t.getBindingIdentifiers(node));
|
||||
formatter.bumpImportOccurences(node);
|
||||
@@ -52,9 +52,9 @@ var importsVisitor = {
|
||||
};
|
||||
|
||||
var exportsVisitor = {
|
||||
enter(node, parent, scope, formatter) {
|
||||
var declar = node && node.declaration;
|
||||
if (t.isExportDeclaration(node)) {
|
||||
ExportDeclaration: {
|
||||
enter(node, parent, scope, formatter) {
|
||||
var declar = node.declaration;
|
||||
formatter.hasLocalImports = true;
|
||||
|
||||
if (declar && t.isStatement(declar)) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
commonStrict: require("./common-strict"),
|
||||
amdStrict: require("./amd-strict"),
|
||||
umdStrict: require("./umd-strict"),
|
||||
|
||||
@@ -142,9 +142,9 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
|
||||
return t.arrayExpression(map(this.ids, function (uid, source) {
|
||||
var state = {
|
||||
hoistDeclarators: hoistDeclarators,
|
||||
source: source,
|
||||
nodes: [],
|
||||
hoistDeclarators: hoistDeclarators
|
||||
nodes: []
|
||||
};
|
||||
|
||||
scope.traverse(block, runnerSettersVisitor, state);
|
||||
@@ -161,11 +161,11 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
var block = t.blockStatement(program.body);
|
||||
|
||||
var runner = util.template("system", {
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
|
||||
EXECUTE: t.functionExpression(null, [], block)
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
|
||||
EXECUTE: t.functionExpression(null, [], block)
|
||||
}, true);
|
||||
|
||||
var handlerBody = runner.expression.arguments[2].body.body;
|
||||
|
||||
16
src/babel/transformation/templates/create-class.js
Normal file
16
src/babel/transformation/templates/create-class.js
Normal file
@@ -0,0 +1,16 @@
|
||||
(function() {
|
||||
function defineProperties(target, props) {
|
||||
for (var key in props) {
|
||||
var prop = props[key];
|
||||
prop.configurable = true;
|
||||
if (prop.value) prop.writable = true;
|
||||
}
|
||||
Object.defineProperties(target, props);
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
})()
|
||||
@@ -1,4 +0,0 @@
|
||||
(function (child, staticProps, instanceProps) {
|
||||
if (staticProps) Object.defineProperties(child, staticProps);
|
||||
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||
})
|
||||
@@ -1,2 +1,2 @@
|
||||
var helpers = exports.default = {};
|
||||
exports.default = HELPER;
|
||||
exports.__esModule = true;
|
||||
|
||||
11
src/babel/transformation/templates/umd-commonjs-strict.js
Normal file
11
src/babel/transformation/templates/umd-commonjs-strict.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(AMD_ARGUMENTS, factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
factory(COMMON_ARGUMENTS);
|
||||
} else {
|
||||
factory(BROWSER_ARGUMENTS);
|
||||
}
|
||||
})(UMD_ROOT, function (FACTORY_PARAMETERS) {
|
||||
FACTORY_BODY
|
||||
});
|
||||
@@ -23,6 +23,6 @@ export function ObjectExpression(node) {
|
||||
|
||||
return t.callExpression(
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
|
||||
[node, defineMap.build(mutatorMap)]
|
||||
[node, defineMap.toDefineObject(mutatorMap)]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import t from "../../../types";
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
|
||||
var declared = state.letRefs[node.name];
|
||||
if (!declared) return;
|
||||
|
||||
@@ -109,7 +109,7 @@ function traverseReplace(node, parent, scope, remaps) {
|
||||
|
||||
var letReferenceBlockVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) {
|
||||
if (this.isFunction()) {
|
||||
scope.traverse(node, letReferenceFunctionVisitor, state);
|
||||
return this.skip();
|
||||
}
|
||||
@@ -119,7 +119,7 @@ var letReferenceBlockVisitor = {
|
||||
var letReferenceFunctionVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// not a direct reference
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
|
||||
// this scope has a variable with the same name so it couldn't belong
|
||||
// to our let scope
|
||||
@@ -134,17 +134,17 @@ var letReferenceFunctionVisitor = {
|
||||
|
||||
var hoistVarDeclarationsVisitor = {
|
||||
enter(node, parent, scope, self) {
|
||||
if (t.isForStatement(node)) {
|
||||
if (this.isForStatement()) {
|
||||
if (isVar(node.init, node)) {
|
||||
node.init = t.sequenceExpression(self.pushDeclar(node.init));
|
||||
}
|
||||
} else if (t.isFor(node)) {
|
||||
} else if (this.isFor()) {
|
||||
if (isVar(node.left, node)) {
|
||||
node.left = node.left.declarations[0].id;
|
||||
}
|
||||
} else if (isVar(node, parent)) {
|
||||
return self.pushDeclar(node).map(t.expressionStatement);
|
||||
} else if (t.isFunction(node)) {
|
||||
} else if (this.isFunction()) {
|
||||
return this.skip();
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ var hoistVarDeclarationsVisitor = {
|
||||
|
||||
var loopLabelVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isLabeledStatement(node)) {
|
||||
if (this.isLabeledStatement()) {
|
||||
state.innerLabels.push(node.label.name);
|
||||
}
|
||||
}
|
||||
@@ -170,13 +170,13 @@ var loopVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
var replace;
|
||||
|
||||
if (t.isLoop(node)) {
|
||||
if (this.isLoop()) {
|
||||
state.ignoreLabeless = true;
|
||||
scope.traverse(node, loopVisitor, state);
|
||||
state.ignoreLabeless = false;
|
||||
}
|
||||
|
||||
if (t.isFunction(node) || t.isLoop(node)) {
|
||||
if (this.isFunction() || this.isLoop()) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ var loopVisitor = {
|
||||
replace = t.literal(loopText);
|
||||
}
|
||||
|
||||
if (t.isReturnStatement(node)) {
|
||||
if (this.isReturnStatement()) {
|
||||
state.hasReturn = true;
|
||||
replace = t.objectExpression([
|
||||
t.property("init", t.identifier("v"), node.argument || t.identifier("undefined"))
|
||||
|
||||
@@ -3,29 +3,54 @@ import * as nameMethod from "../../helpers/name-method";
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import traverse from "../../../traversal";
|
||||
import t from "../../../types";
|
||||
|
||||
export var check = t.isClass;
|
||||
|
||||
export function ClassDeclaration(node, parent, scope, file) {
|
||||
return new ClassTransformer(node, file, scope, true).run();
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
}
|
||||
|
||||
export function ClassExpression(node, parent, scope, file) {
|
||||
if (!node.id) {
|
||||
if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) {
|
||||
// var o = { foo: class {} };
|
||||
node.id = parent.key;
|
||||
}
|
||||
return new ClassTransformer(node, parent, scope, file).run();
|
||||
}
|
||||
|
||||
if (t.isVariableDeclarator(parent) && t.isIdentifier(parent.id)) {
|
||||
// var foo = class {};
|
||||
node.id = parent.id;
|
||||
var verifyConstructorVisitor = traverse.explode({
|
||||
MethodDefinition: {
|
||||
enter() {
|
||||
this.skip();
|
||||
}
|
||||
},
|
||||
|
||||
Property: {
|
||||
enter(node) {
|
||||
if (node.method) this.skip();
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression: {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isIdentifier(node.callee, { name: "super" })) {
|
||||
state.hasBareSuper = true;
|
||||
|
||||
if (!state.hasSuper) {
|
||||
throw state.file.errorWithNode(node, "super call is only allowed in derived constructor");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
ThisExpression: {
|
||||
enter(node, parent, scope, state) {
|
||||
if (state.hasSuper && !state.hasBareSuper) {
|
||||
throw state.file.errorWithNode(node, "'this' is not allowed before super()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ClassTransformer(node, file, scope, false).run();
|
||||
}
|
||||
});
|
||||
|
||||
class ClassTransformer {
|
||||
|
||||
@@ -33,27 +58,31 @@ class ClassTransformer {
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
* @param {File} file
|
||||
* @param {Node} parent
|
||||
* @param {Scope} scope
|
||||
* @param {Boolean} isStatement
|
||||
* @param {File} file
|
||||
*/
|
||||
|
||||
constructor(node, file, scope, isStatement) {
|
||||
this.isStatement = isStatement;
|
||||
this.scope = scope;
|
||||
this.node = node;
|
||||
this.file = file;
|
||||
constructor(node, parent, scope, file) {
|
||||
this.parent = parent;
|
||||
this.scope = scope;
|
||||
this.node = node;
|
||||
this.file = file;
|
||||
|
||||
this.hasInstanceMutators = false;
|
||||
this.hasStaticMutators = false;
|
||||
|
||||
this.instanceMutatorMap = {};
|
||||
this.staticMutatorMap = {};
|
||||
this.hasConstructor = false;
|
||||
this.className = node.id || scope.generateUidIdentifier("class");
|
||||
this.superName = node.superClass || t.identifier("Function");
|
||||
this.hasSuper = !!node.superClass;
|
||||
this.isLoose = file.isLoose("es6.classes");
|
||||
|
||||
this.hasConstructor = false;
|
||||
this.className = node.id;
|
||||
this.classRef = node.id || scope.generateUidIdentifier("class");
|
||||
|
||||
this.superName = node.superClass || t.identifier("Function");
|
||||
this.hasSuper = !!node.superClass;
|
||||
|
||||
this.isLoose = file.isLoose("es6.classes");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,39 +95,35 @@ class ClassTransformer {
|
||||
var superName = this.superName;
|
||||
var className = this.className;
|
||||
var classBody = this.node.body.body;
|
||||
var classRef = this.classRef;
|
||||
var file = this.file;
|
||||
|
||||
//
|
||||
|
||||
var body = this.body = [];
|
||||
|
||||
//
|
||||
|
||||
var constructorBody = t.blockStatement([
|
||||
t.expressionStatement(t.callExpression(file.addHelper("class-call-check"), [
|
||||
t.thisExpression(),
|
||||
className
|
||||
classRef
|
||||
]))
|
||||
]);
|
||||
|
||||
var constructor;
|
||||
if (this.node.id) {
|
||||
constructor = t.functionDeclaration(className, [], constructorBody);
|
||||
|
||||
if (this.className) {
|
||||
constructor = t.functionDeclaration(this.className, [], constructorBody);
|
||||
body.push(constructor);
|
||||
} else {
|
||||
var constructorName = null;
|
||||
// when a class has no parent and there is only a constructor or no body
|
||||
// then the constructor is not wrapped in a closure and needs to be named
|
||||
var containsOnlyConstructor = classBody.length === 1 && classBody[0].key.name === "constructor";
|
||||
if (!this.hasSuper && (classBody.length === 0 || containsOnlyConstructor)) {
|
||||
constructorName = className;
|
||||
}
|
||||
|
||||
constructor = t.functionExpression(constructorName, [], constructorBody);
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(className, constructor)
|
||||
]));
|
||||
constructor = t.functionExpression(null, [], constructorBody);
|
||||
}
|
||||
|
||||
this.constructor = constructor;
|
||||
|
||||
//
|
||||
|
||||
var closureParams = [];
|
||||
var closureArgs = [];
|
||||
|
||||
@@ -107,40 +132,40 @@ class ClassTransformer {
|
||||
if (this.hasSuper) {
|
||||
closureArgs.push(superName);
|
||||
|
||||
if (!t.isIdentifier(superName)) {
|
||||
superName = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
}
|
||||
|
||||
superName = this.scope.generateUidBasedOnNode(superName, this.file);
|
||||
closureParams.push(superName);
|
||||
|
||||
this.superName = superName;
|
||||
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
|
||||
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [classRef, superName])));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
this.buildBody();
|
||||
|
||||
t.inheritsComments(body[0], this.node);
|
||||
|
||||
var init;
|
||||
|
||||
if (body.length === 1) {
|
||||
// only a constructor so no need for a closure container
|
||||
init = t.toExpression(constructor);
|
||||
if (this.className) {
|
||||
// named class with only a constructor
|
||||
if (body.length === 1) return t.toExpression(body[0]);
|
||||
} else {
|
||||
body.push(t.returnStatement(className));
|
||||
init = t.callExpression(
|
||||
t.functionExpression(null, closureParams, t.blockStatement(body)),
|
||||
closureArgs
|
||||
);
|
||||
// infer class name if this is a nameless class expression
|
||||
constructor = nameMethod.bare(constructor, this.parent, this.scope);
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(classRef, constructor)
|
||||
]));
|
||||
|
||||
t.inheritsComments(body[0], this.node);
|
||||
}
|
||||
|
||||
if (this.isStatement) {
|
||||
return t.variableDeclaration("let", [
|
||||
t.variableDeclarator(className, init)
|
||||
]);
|
||||
} else {
|
||||
return init;
|
||||
}
|
||||
//
|
||||
|
||||
body.push(t.returnStatement(classRef));
|
||||
|
||||
return t.callExpression(
|
||||
t.functionExpression(null, closureParams, t.blockStatement(body)),
|
||||
closureArgs
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,18 +182,22 @@ class ClassTransformer {
|
||||
for (var i = 0; i < classBody.length; i++) {
|
||||
var node = classBody[i];
|
||||
if (t.isMethodDefinition(node)) {
|
||||
var isConstructor = (!node.computed && t.isIdentifier(node.key, { name: "constructor" })) || t.isLiteral(node.key, { value: "constructor" });
|
||||
if (isConstructor) this.verifyConstructor(node);
|
||||
|
||||
var replaceSupers = new ReplaceSupers({
|
||||
methodNode: node,
|
||||
className: this.className,
|
||||
superName: this.superName,
|
||||
objectRef: this.classRef,
|
||||
superRef: this.superName,
|
||||
isStatic: node.static,
|
||||
isLoose: this.isLoose,
|
||||
scope: this.scope,
|
||||
file: this.file
|
||||
}, true);
|
||||
|
||||
replaceSupers.replace();
|
||||
|
||||
if ((!node.computed && t.isIdentifier(node.key, { name: "constructor" })) || t.isLiteral(node.key, { value: "constructor" })) {
|
||||
if (isConstructor) {
|
||||
this.pushConstructor(node);
|
||||
} else {
|
||||
this.pushMethod(node);
|
||||
@@ -195,25 +224,47 @@ class ClassTransformer {
|
||||
var staticProps;
|
||||
|
||||
if (this.hasInstanceMutators) {
|
||||
instanceProps = defineMap.build(this.instanceMutatorMap);
|
||||
instanceProps = defineMap.toClassObject(this.instanceMutatorMap);
|
||||
}
|
||||
|
||||
if (this.hasStaticMutators) {
|
||||
staticProps = defineMap.build(this.staticMutatorMap);
|
||||
staticProps = defineMap.toClassObject(this.staticMutatorMap);
|
||||
}
|
||||
|
||||
if (instanceProps || staticProps) {
|
||||
staticProps ||= t.literal(null);
|
||||
instanceProps ||= t.literal(null);
|
||||
|
||||
var args = [className, staticProps];
|
||||
if (instanceProps) args.push(instanceProps);
|
||||
var args = [this.classRef, instanceProps];
|
||||
if (staticProps) args.push(staticProps);
|
||||
|
||||
body.push(t.expressionStatement(
|
||||
t.callExpression(this.file.addHelper("prototype-properties"), args)
|
||||
t.callExpression(this.file.addHelper("create-class"), args)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
verifyConstructor(node) {
|
||||
return; // enable this for the next major
|
||||
|
||||
var state = {
|
||||
hasBareSuper: false,
|
||||
hasSuper: this.hasSuper,
|
||||
file: this.file
|
||||
};
|
||||
|
||||
traverse(node, verifyConstructorVisitor, this.scope, state);
|
||||
|
||||
if (!state.hasBareSuper && this.hasSuper) {
|
||||
throw this.file.errorWithNode(node, "Derived constructor must call super()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a method to its respective mutatorMap.
|
||||
*
|
||||
@@ -231,9 +282,9 @@ class ClassTransformer {
|
||||
if (this.isLoose) {
|
||||
// use assignments instead of define properties for loose classes
|
||||
|
||||
var className = this.className;
|
||||
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
|
||||
methodName = t.memberExpression(className, methodName, node.computed);
|
||||
var classRef = this.classRef;
|
||||
if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
|
||||
methodName = t.memberExpression(classRef, methodName, node.computed);
|
||||
|
||||
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
|
||||
t.inheritsComments(expr, node);
|
||||
@@ -253,7 +304,6 @@ class ClassTransformer {
|
||||
}
|
||||
|
||||
defineMap.push(mutatorMap, methodName, kind, node.computed, node);
|
||||
defineMap.push(mutatorMap, methodName, "enumerable", node.computed, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,7 +318,7 @@ class ClassTransformer {
|
||||
var key;
|
||||
|
||||
if (node.static) {
|
||||
key = t.memberExpression(this.className, node.key);
|
||||
key = t.memberExpression(this.classRef, node.key);
|
||||
this.body.push(
|
||||
t.expressionStatement(t.assignmentExpression("=", key, node.value))
|
||||
);
|
||||
@@ -301,6 +351,8 @@ class ClassTransformer {
|
||||
|
||||
construct._ignoreUserWhitespace = true;
|
||||
construct.params = fn.params;
|
||||
construct.body.body = construct.body.body.concat(fn.body.body);
|
||||
|
||||
t.inherits(construct.body, fn.body);
|
||||
construct.body.body = construct.body.body.concat(fn.body.body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ export function check(node) {
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isAssignmentExpression(node) || t.isUpdateExpression(node)) {
|
||||
var ids = t.getBindingIdentifiers(node);
|
||||
if (this.isAssignmentExpression() || this.isUpdateExpression()) {
|
||||
var ids = this.getBindingIdentifiers();
|
||||
|
||||
for (var name in ids) {
|
||||
var id = ids[name];
|
||||
@@ -30,7 +30,7 @@ var visitor = {
|
||||
|
||||
throw state.file.errorWithNode(id, messages.get("readOnly", name));
|
||||
}
|
||||
} else if (t.isScope(node, parent)) {
|
||||
} else if (this.isScope()) {
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ export function VariableDeclaration(node, parent, scope, file) {
|
||||
}
|
||||
|
||||
return nodes;
|
||||
};
|
||||
}
|
||||
|
||||
var hasRest = function (pattern) {
|
||||
for (var i = 0; i < pattern.elements.length; i++) {
|
||||
|
||||
@@ -41,17 +41,20 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
|
||||
var breakVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isLoop(node)) {
|
||||
if (this.isLoop()) {
|
||||
state.ignoreLabeless = true;
|
||||
scope.traverse(node, breakVisitor, state);
|
||||
state.ignoreLabeless = false;
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
if (t.isBreakStatement(node)) {
|
||||
if (this.isBreakStatement()) {
|
||||
if (!node.label && state.ignoreLabeless) return;
|
||||
if (node.label && node.label.name !== state.label) return;
|
||||
|
||||
// break statements mean something different in this context
|
||||
if (t.isSwitchCase(parent)) return;
|
||||
|
||||
var ret = t.expressionStatement(
|
||||
t.callExpression(t.memberExpression(state.iteratorKey, t.identifier("return")), [])
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ export function check(node) {
|
||||
return t.isIdentifier(node, { name: "super" });
|
||||
}
|
||||
|
||||
export function Property(node, parent, scope, file) {
|
||||
function Property(node, scope, getObjectRef, file) {
|
||||
if (!node.method) return;
|
||||
|
||||
var value = node.value;
|
||||
@@ -13,8 +13,8 @@ export function Property(node, parent, scope, file) {
|
||||
|
||||
var replaceSupers = new ReplaceSupers({
|
||||
topLevelThisReference: thisExpr,
|
||||
getObjectRef: getObjectRef,
|
||||
methodNode: node,
|
||||
className: thisExpr,
|
||||
isStatic: true,
|
||||
scope: scope,
|
||||
file: file
|
||||
@@ -30,3 +30,20 @@ export function Property(node, parent, scope, file) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var objectRef;
|
||||
var getObjectRef = () => objectRef ||= scope.generateUidIdentifier("obj");
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
Property(node.properties[i], scope, getObjectRef, file);
|
||||
}
|
||||
|
||||
if (objectRef) {
|
||||
scope.push({
|
||||
id: objectRef
|
||||
});
|
||||
|
||||
return t.assignmentExpression("=", objectRef, node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ var hasDefaults = function (node) {
|
||||
|
||||
var iifeVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
if (!state.scope.hasOwnBinding(node.name)) return;
|
||||
if (state.scope.bindingIdentifierEquals(node.name, node)) return;
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ export var check = t.isRestElement;
|
||||
var memberExpressionOptimisationVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// check if this scope has a local binding that will shadow the rest parameter
|
||||
if (t.isScope(node, parent) && !scope.bindingIdentifierEquals(state.name, state.outerBinding)) {
|
||||
if (this.isScope() && !scope.bindingIdentifierEquals(state.name, state.outerBinding)) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
// skip over functions as whatever `arguments` we reference inside will refer
|
||||
// to the wrong function
|
||||
if (t.isFunctionDeclaration(node) || t.isFunctionExpression(node)) {
|
||||
if (this.isFunctionDeclaration() || this.isFunctionExpression()) {
|
||||
state.noOptimise = true;
|
||||
scope.traverse(node, memberExpressionOptimisationVisitor, state);
|
||||
state.noOptimise = false;
|
||||
@@ -21,7 +21,7 @@ var memberExpressionOptimisationVisitor = {
|
||||
}
|
||||
|
||||
// is this a referenced identifier and is it referencing the rest parameter?
|
||||
if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;
|
||||
if (!this.isReferencedIdentifier({ name: state.name })) return;
|
||||
|
||||
if (!state.noOptimise && t.isMemberExpression(parent) && parent.computed) {
|
||||
// if we know that this member expression is referencing a number then we can safely
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import clone from "lodash/lang/clone";
|
||||
import t from "../../../types";
|
||||
|
||||
export function check(node) {
|
||||
@@ -12,6 +11,6 @@ export function Property(node) {
|
||||
|
||||
if (node.shorthand) {
|
||||
node.shorthand = false;
|
||||
node.key = t.removeComments(clone(node.key));
|
||||
node.key = t.removeComments(t.clone(node.key));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ function returnBlock(expr) {
|
||||
// looks for and replaces tail recursion calls
|
||||
var firstPass = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isIfStatement(node)) {
|
||||
if (this.isIfStatement()) {
|
||||
if (t.isReturnStatement(node.alternate)) {
|
||||
t.ensureBlock(node, "alternate");
|
||||
}
|
||||
@@ -25,7 +25,7 @@ var firstPass = {
|
||||
if (t.isReturnStatement(node.consequent)) {
|
||||
t.ensureBlock(node, "consequent");
|
||||
}
|
||||
} else if (t.isReturnStatement(node)) {
|
||||
} else if (this.isReturnStatement()) {
|
||||
this.skip();
|
||||
return state.subTransform(node.argument);
|
||||
} else if (t.isTryStatement(parent)) {
|
||||
@@ -34,9 +34,9 @@ var firstPass = {
|
||||
} else if (parent.finalizer && node !== parent.finalizer) {
|
||||
this.skip();
|
||||
}
|
||||
} else if (t.isFunction(node)) {
|
||||
} else if (this.isFunction()) {
|
||||
this.skip();
|
||||
} else if (t.isVariableDeclaration(node)) {
|
||||
} else if (this.isVariableDeclaration()) {
|
||||
this.skip();
|
||||
state.vars.push(node);
|
||||
}
|
||||
@@ -47,15 +47,15 @@ var firstPass = {
|
||||
// them as needed
|
||||
var secondPass = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isThisExpression(node)) {
|
||||
if (this.isThisExpression()) {
|
||||
state.needsThis = true;
|
||||
return state.getThisId();
|
||||
} else if (t.isReferencedIdentifier(node, parent, { name: "arguments" })) {
|
||||
} else if (this.isReferencedIdentifier({ name: "arguments" })) {
|
||||
state.needsArguments = true;
|
||||
return state.getArgumentsId();
|
||||
} else if (t.isFunction(node)) {
|
||||
} else if (this.isFunction()) {
|
||||
this.skip();
|
||||
if (t.isFunctionDeclaration(node)) {
|
||||
if (this.isFunctionDeclaration()) {
|
||||
node = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
@@ -69,7 +69,7 @@ var secondPass = {
|
||||
// optimizes recursion by removing `this` and `arguments` if they aren't used
|
||||
var thirdPass = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!t.isExpressionStatement(node)) return;
|
||||
if (!this.isExpressionStatement()) return;
|
||||
|
||||
var expr = node.expression;
|
||||
if (!t.isAssignmentExpression(expr)) return;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export default {
|
||||
strict: require("./other/strict"),
|
||||
|
||||
_validation: require("./internal/validation"),
|
||||
|
||||
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
|
||||
"validation.noForInOfAssignment": require("./validation/no-for-in-of-assignment"),
|
||||
"validation.setters": require("./validation/setters"),
|
||||
"validation.react": require("./validation/react"),
|
||||
|
||||
// this goes at the start so we only transform the original user code
|
||||
|
||||
@@ -2,7 +2,7 @@ import t from "../../../types";
|
||||
|
||||
var functionChildrenVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node) && !node._aliasFunction) {
|
||||
if (this.isFunction() && !node._aliasFunction) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
@@ -10,22 +10,22 @@ var functionChildrenVisitor = {
|
||||
|
||||
var getId;
|
||||
|
||||
if (t.isIdentifier(node) && node.name === "arguments") {
|
||||
if (this.isIdentifier() && node.name === "arguments") {
|
||||
getId = state.getArgumentsId;
|
||||
} else if (t.isThisExpression(node)) {
|
||||
} else if (this.isThisExpression()) {
|
||||
getId = state.getThisId;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (t.isReferenced(node, parent)) return getId();
|
||||
if (this.isReferenced()) return getId();
|
||||
}
|
||||
};
|
||||
|
||||
var functionVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!node._aliasFunction) {
|
||||
if (t.isFunction(node)) {
|
||||
if (this.isFunction()) {
|
||||
// stop traversal of this node as it'll be hit again by this transformer
|
||||
return this.skip();
|
||||
} else {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as strict from "../../helpers/strict";
|
||||
|
||||
export function Program(program, parent, scope, file) {
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
strict.wrap(program, function () {
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(program);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export function check(node) {
|
||||
export function ImportDeclaration(node, parent, scope, file) {
|
||||
var resolveModuleSource = file.opts.resolveModuleSource;
|
||||
if (node.source && resolveModuleSource) {
|
||||
node.source.value = resolveModuleSource(node.source.value);
|
||||
node.source.value = resolveModuleSource(node.source.value, file.opts.filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,16 @@ export function ExportDeclaration(node, parent, scope) {
|
||||
node.declaration = null;
|
||||
node._blockHoist = 2;
|
||||
return [getDeclar(), node];
|
||||
} else if (t.isVariableDeclaration(declar)) {
|
||||
var specifiers = [];
|
||||
|
||||
var bindings = t.getBindingIdentifiers(declar);
|
||||
for (var key in bindings) {
|
||||
var id = bindings[key];
|
||||
specifiers.push(t.exportSpecifier(id, id));
|
||||
}
|
||||
|
||||
return [declar, t.exportDeclaration(null, specifiers)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
src/babel/transformation/transformers/internal/validation.js
Normal file
27
src/babel/transformation/transformers/internal/validation.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
var declar = left.declarations[0];
|
||||
if (declar.init) throw file.errorWithNode(declar, messages.get("noAssignmentsInForHead"));
|
||||
}
|
||||
}
|
||||
|
||||
export { ForOfStatement as ForInStatement };
|
||||
|
||||
export function Property(node, parent, scope, file) {
|
||||
if (node.kind === "set") {
|
||||
if (node.value.params.length !== 1) {
|
||||
throw file.errorWithNode(node.value, messages.get("settersInvalidParamLength"));
|
||||
}
|
||||
|
||||
var first = node.value.params[0];
|
||||
if (t.isRestElement(first)) {
|
||||
throw file.errorWithNode(first, messages.get("settersNoRest"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { Property as MethodDefinition };
|
||||
@@ -16,14 +16,15 @@ var ALIASABLE_CONSTRUCTORS = [
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"Set",
|
||||
"WeakSet"
|
||||
"WeakSet",
|
||||
"Number"
|
||||
];
|
||||
|
||||
var astVisitor = {
|
||||
enter(node, parent, scope, file) {
|
||||
var prop;
|
||||
|
||||
if (t.isMemberExpression(node) && t.isReferenced(node, parent)) {
|
||||
if (this.isMemberExpression() && this.isReferenced()) {
|
||||
// Array.from -> _core.Array.from
|
||||
var obj = node.object;
|
||||
prop = node.property;
|
||||
@@ -34,10 +35,10 @@ var astVisitor = {
|
||||
this.skip();
|
||||
return t.prependToMemberExpression(node, file.get("coreIdentifier"));
|
||||
}
|
||||
} else if (t.isReferencedIdentifier(node, parent) && !t.isMemberExpression(parent) && includes(ALIASABLE_CONSTRUCTORS, node.name) && !scope.getBindingIdentifier(node.name)) {
|
||||
} else if (this.isReferencedIdentifier() && !t.isMemberExpression(parent) && includes(ALIASABLE_CONSTRUCTORS, node.name) && !scope.getBindingIdentifier(node.name)) {
|
||||
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
|
||||
return t.memberExpression(file.get("coreIdentifier"), node);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
} else if (this.isCallExpression()) {
|
||||
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
|
||||
|
||||
var callee = node.callee;
|
||||
@@ -53,7 +54,7 @@ var astVisitor = {
|
||||
CORE_ID: file.get("coreIdentifier"),
|
||||
VALUE: callee.object
|
||||
});
|
||||
} else if (t.isBinaryExpression(node)) {
|
||||
} else if (this.isBinaryExpression()) {
|
||||
// Symbol.iterator in arr -> core.$for.isIterable(arr)
|
||||
|
||||
if (node.operator !== "in") return;
|
||||
@@ -80,8 +81,8 @@ export function Program(node, parent, scope, file) {
|
||||
}
|
||||
|
||||
export function pre(file) {
|
||||
file.setDynamic("helpersNamespace", function () {
|
||||
return file.addImport("babel-runtime/helpers", "babelHelpers");
|
||||
file.set("helperGenerator", function (name) {
|
||||
return file.addImport("babel-runtime/helpers/" + name, name);
|
||||
});
|
||||
|
||||
file.setDynamic("coreIdentifier", function () {
|
||||
@@ -94,7 +95,7 @@ export function pre(file) {
|
||||
}
|
||||
|
||||
export function Identifier(node, parent, scope, file) {
|
||||
if (t.isReferencedIdentifier(node, parent, { name: "regeneratorRuntime" })) {
|
||||
if (this.isReferencedIdentifier({ name: "regeneratorRuntime" })) {
|
||||
return file.get("regeneratorIdentifier");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ export var playground = true;
|
||||
|
||||
build(exports, {
|
||||
is(node, file) {
|
||||
var is = t.isAssignmentExpression(node) && node.operator === "||=";
|
||||
if (is) {
|
||||
if (t.isAssignmentExpression(node, { operator: "||=" })) {
|
||||
var left = node.left;
|
||||
if (!t.isMemberExpression(left) && !t.isIdentifier(left)) {
|
||||
throw file.errorWithNode(left, messages.get("expectedMemberExpressionOrIdentifier"));
|
||||
|
||||
@@ -5,7 +5,7 @@ export var playground = true;
|
||||
|
||||
build(exports, {
|
||||
is(node) {
|
||||
var is = t.isAssignmentExpression(node) && node.operator === "?=";
|
||||
var is = t.isAssignmentExpression(node, { operator: "?=" });
|
||||
if (is) t.assertMemberExpression(node.left);
|
||||
return is;
|
||||
},
|
||||
|
||||
@@ -4,9 +4,9 @@ export var playground = true;
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) return this.skip();
|
||||
if (this.isFunction()) return this.skip();
|
||||
|
||||
if (t.isReturnStatement(node) && node.argument) {
|
||||
if (this.isReturnStatement() && node.argument) {
|
||||
node.argument = t.memberExpression(t.callExpression(state.file.addHelper("define-property"), [
|
||||
t.thisExpression(),
|
||||
state.key,
|
||||
|
||||
@@ -3,7 +3,7 @@ import t from "../../../types";
|
||||
export var optional = true;
|
||||
|
||||
export function Identifier(node, parent) {
|
||||
if (node.name === "undefined" && t.isReferenced(node, parent)) {
|
||||
if (node.name === "undefined" && this.isReferenced()) {
|
||||
return t.unaryExpression("void", t.literal(0), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import t from "../../../types";
|
||||
export var optional = true;
|
||||
|
||||
export function ExpressionStatement(node) {
|
||||
if (t.isIdentifier(node.expression, { name: "debugger" })) {
|
||||
if (this.get("expression").isIdentifier({ name: "debugger" })) {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
export { isFor as check } from "../../../types";
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
var declar = left.declarations[0];
|
||||
if (declar.init) throw file.errorWithNode(declar, messages.get("noAssignmentsInForHead"));
|
||||
}
|
||||
}
|
||||
|
||||
export { ForOfStatement as ForInStatement };
|
||||
@@ -2,7 +2,7 @@ import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
// check if the input Literal `source` is an alternate casing of "react"
|
||||
var check = function (source, file) {
|
||||
function check(source, file) {
|
||||
if (t.isLiteral(source)) {
|
||||
var name = source.value;
|
||||
var lower = name.toLowerCase();
|
||||
@@ -11,7 +11,7 @@ var check = function (source, file) {
|
||||
throw file.errorWithNode(source, messages.get("didYouMean", "react"));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function CallExpression(node, parent, scope, file) {
|
||||
if (t.isIdentifier(node.callee, { name: "require" }) && node.arguments.length === 1) {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import * as messages from "../../../messages";
|
||||
|
||||
export function check(node) {
|
||||
return node.kind === "set";
|
||||
}
|
||||
|
||||
export function Property(node, parent, scope, file) {
|
||||
if (node.kind === "set" && node.value.params.length !== 1) {
|
||||
throw file.errorWithNode(node.value, messages.get("settersInvalidParamLength"));
|
||||
}
|
||||
}
|
||||
|
||||
export { Property as MethodDefinition };
|
||||
@@ -1,11 +1,10 @@
|
||||
import levenshtein from "leven";
|
||||
import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
export var optional = true;
|
||||
|
||||
export function Identifier(node, parent, scope, file) {
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
if (!this.isReferenced()) return;
|
||||
if (scope.hasBinding(node.name)) return;
|
||||
|
||||
// get the closest declaration to offer as a suggestion
|
||||
|
||||
@@ -2,14 +2,13 @@ import TraversalPath from "./path";
|
||||
import flatten from "lodash/array/flatten";
|
||||
import compact from "lodash/array/compact";
|
||||
|
||||
export default class TraversalConext {
|
||||
export default class TraversalContext {
|
||||
constructor(scope, opts, state, parentPath) {
|
||||
this.shouldFlatten = false;
|
||||
this.parentPath = parentPath;
|
||||
|
||||
this.scope = scope;
|
||||
this.state = state;
|
||||
this.opts = opts;
|
||||
this.scope = scope;
|
||||
this.state = state;
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
flatten() {
|
||||
@@ -17,7 +16,7 @@ export default class TraversalConext {
|
||||
}
|
||||
|
||||
visitNode(node, obj, key) {
|
||||
var iteration = new TraversalPath(this, node, obj, key);
|
||||
var iteration = TraversalPath.get(this.parentPath, this, node, obj, key);
|
||||
return iteration.visit();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,13 +42,14 @@ traverse.node = function (node, opts, scope, state, parentPath) {
|
||||
function clearNode(node) {
|
||||
node._declarations = null;
|
||||
node.extendedRange = null;
|
||||
node._scopeInfo = null;
|
||||
node.tokens = null;
|
||||
node.range = null;
|
||||
node.start = null;
|
||||
node.end = null;
|
||||
node.loc = null;
|
||||
node.raw = null;
|
||||
node._scopeInfo = null;
|
||||
node._paths = null;
|
||||
node.tokens = null;
|
||||
node.range = null;
|
||||
node.start = null;
|
||||
node.end = null;
|
||||
node.loc = null;
|
||||
node.raw = null;
|
||||
|
||||
if (Array.isArray(node.trailingComments)) {
|
||||
clearComments(node.trailingComments);
|
||||
@@ -57,11 +58,18 @@ function clearNode(node) {
|
||||
if (Array.isArray(node.leadingComments)) {
|
||||
clearComments(node.leadingComments);
|
||||
}
|
||||
|
||||
for (var key in node) {
|
||||
var val = node[key];
|
||||
if (Array.isArray(val)) {
|
||||
delete val._paths;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var clearVisitor = {
|
||||
noScope: true,
|
||||
enter: clearNode
|
||||
exit: clearNode
|
||||
};
|
||||
|
||||
function clearComments(comments) {
|
||||
@@ -71,8 +79,8 @@ function clearComments(comments) {
|
||||
}
|
||||
|
||||
traverse.removeProperties = function (tree) {
|
||||
clearNode(tree);
|
||||
traverse(tree, clearVisitor);
|
||||
clearNode(tree);
|
||||
|
||||
return tree;
|
||||
};
|
||||
|
||||
@@ -4,23 +4,33 @@ import Scope from "./scope";
|
||||
import t from "../types";
|
||||
|
||||
export default class TraversalPath {
|
||||
constructor(context, parent, container, key) {
|
||||
this.shouldRemove = false;
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
|
||||
this.parentPath = context.parentPath;
|
||||
this.context = context;
|
||||
this.state = this.context.state;
|
||||
this.opts = this.context.opts;
|
||||
|
||||
constructor(parent, container) {
|
||||
this.container = container;
|
||||
this.key = key;
|
||||
this.parent = parent;
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
this.parent = parent;
|
||||
this.state = context.state;
|
||||
static get(parentPath, context, parent, container, key) {
|
||||
var targetNode = container[key];
|
||||
var paths = container._paths ||= [];
|
||||
var path;
|
||||
|
||||
this.setScope();
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var pathCheck = paths[i];
|
||||
if (pathCheck.node === targetNode) {
|
||||
path = pathCheck;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
path = new TraversalPath(parent, container);
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
path.setContext(parentPath, context, key);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
static getScope(node, parent, scope) {
|
||||
@@ -34,10 +44,32 @@ export default class TraversalPath {
|
||||
return ourScope;
|
||||
}
|
||||
|
||||
setData(key, val) {
|
||||
return this.data[key] = val;
|
||||
}
|
||||
|
||||
getData(key) {
|
||||
return this.data[key];
|
||||
}
|
||||
|
||||
setScope() {
|
||||
this.scope = TraversalPath.getScope(this.node, this.parent, this.context.scope);
|
||||
}
|
||||
|
||||
setContext(parentPath, context, key) {
|
||||
this.shouldRemove = false;
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.context = context;
|
||||
this.state = context.state;
|
||||
this.opts = context.opts;
|
||||
this.key = key;
|
||||
|
||||
this.setScope();
|
||||
}
|
||||
|
||||
remove() {
|
||||
this.shouldRemove = true;
|
||||
this.shouldSkip = true;
|
||||
@@ -114,14 +146,13 @@ export default class TraversalPath {
|
||||
}
|
||||
}
|
||||
|
||||
visit() {
|
||||
var opts = this.opts;
|
||||
var node = this.node;
|
||||
isBlacklisted() {
|
||||
var blacklist = this.opts.blacklist;
|
||||
return blacklist && blacklist.indexOf(this.node.type) > -1;
|
||||
}
|
||||
|
||||
// type is blacklisted
|
||||
if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) {
|
||||
return false;
|
||||
}
|
||||
visit() {
|
||||
if (this.isBlacklisted()) return false;
|
||||
|
||||
this.call("enter");
|
||||
|
||||
@@ -129,7 +160,8 @@ export default class TraversalPath {
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
node = this.node;
|
||||
var node = this.node;
|
||||
var opts = this.opts;
|
||||
|
||||
if (Array.isArray(node)) {
|
||||
// traverse over these replacement nodes we purposely don't call exitNode
|
||||
@@ -139,13 +171,38 @@ export default class TraversalPath {
|
||||
}
|
||||
} else {
|
||||
traverse.node(node, opts, this.scope, this.state, this);
|
||||
|
||||
this.call("exit");
|
||||
}
|
||||
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
isReferencedIdentifier() {
|
||||
return t.isReferencedIdentifier(this.node);
|
||||
get(key) {
|
||||
return TraversalPath.get(this, this.context, this.node, this.node, key);
|
||||
}
|
||||
|
||||
isReferencedIdentifier(opts) {
|
||||
return t.isReferencedIdentifier(this.node, this.parent, opts);
|
||||
}
|
||||
|
||||
isReferenced() {
|
||||
return t.isReferenced(this.node, this.parent);
|
||||
}
|
||||
|
||||
isScope() {
|
||||
return t.isScope(this.node, this.parent);
|
||||
}
|
||||
|
||||
getBindingIdentifiers() {
|
||||
return t.getBindingIdentifiers(this.node);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < t.TYPES.length; i++) {
|
||||
let type = t.TYPES[i];
|
||||
let typeKey = `is${type}`;
|
||||
TraversalPath.prototype[typeKey] = function (opts) {
|
||||
return t[typeKey](this.node, opts);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ export default class Scope {
|
||||
}
|
||||
|
||||
static globals = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys));
|
||||
static contextVariables = ["this", "arguments"];
|
||||
|
||||
/**
|
||||
* Description
|
||||
@@ -533,7 +534,7 @@ export default class Scope {
|
||||
if (t.isBlockStatement(block) || t.isProgram(block)) {
|
||||
block._declarations ||= {};
|
||||
block._declarations[opts.key] = {
|
||||
kind: opts.kind,
|
||||
kind: opts.kind || "var",
|
||||
id: opts.id,
|
||||
init: opts.init
|
||||
};
|
||||
@@ -668,6 +669,7 @@ export default class Scope {
|
||||
if (this.hasOwnBinding(name)) return true;
|
||||
if (this.parentHasBinding(name)) return true;
|
||||
if (includes(Scope.globals, name)) return true;
|
||||
if (includes(Scope.contextVariables, name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import toFastProperties from "../helpers/to-fast-properties";
|
||||
import toFastProperties from "to-fast-properties";
|
||||
import isPlainObject from "lodash/lang/isPlainObject";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import isRegExp from "lodash/lang/isRegExp";
|
||||
@@ -6,6 +6,7 @@ import isString from "lodash/lang/isString";
|
||||
import compact from "lodash/array/compact";
|
||||
import esutils from "esutils";
|
||||
import object from "../helpers/object";
|
||||
import clone from "lodash/lang/clone";
|
||||
import each from "lodash/collection/each";
|
||||
import uniq from "lodash/array/uniq";
|
||||
|
||||
@@ -33,7 +34,7 @@ function registerType(type, skipAliasCheck) {
|
||||
};
|
||||
}
|
||||
|
||||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body"];
|
||||
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
|
||||
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"];
|
||||
t.FOR_INIT_KEYS = ["left", "init"];
|
||||
|
||||
@@ -48,7 +49,7 @@ each(t.VISITOR_KEYS, function (keys, type) {
|
||||
|
||||
each(t.ALIAS_KEYS, function (aliases, type) {
|
||||
each(aliases, function (alias) {
|
||||
var types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || [];
|
||||
var types = t.FLIPPED_ALIAS_KEYS[alias] ||= [];
|
||||
types.push(type);
|
||||
});
|
||||
});
|
||||
@@ -58,6 +59,8 @@ each(t.FLIPPED_ALIAS_KEYS, function (types, type) {
|
||||
registerType(type, false);
|
||||
});
|
||||
|
||||
t.TYPES = Object.keys(t.VISITOR_KEYS).concat(Object.keys(t.FLIPPED_ALIAS_KEYS));
|
||||
|
||||
/**
|
||||
* Returns whether `node` is of given `type`.
|
||||
*
|
||||
@@ -141,22 +144,6 @@ t.toComputedKey = function (node, key) {
|
||||
return key;
|
||||
};
|
||||
|
||||
/*
|
||||
* Shallowly checks to see if the passed `node` is falsy.
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.isFalsyExpression = function (node) {
|
||||
if (t.isLiteral(node)) {
|
||||
return !node.value;
|
||||
} else if (t.isIdentifier(node)) {
|
||||
return node.name === "undefined";
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn an array of statement `nodes` into a `SequenceExpression`.
|
||||
*
|
||||
@@ -292,6 +279,16 @@ t.isReferenced = function (node, parent) {
|
||||
return parent.id !== node;
|
||||
}
|
||||
|
||||
// no: export { foo as NODE };
|
||||
if (t.isExportSpecifier(parent, { name: node })) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// no: import { NODE as foo } from "foo";
|
||||
if (t.isImportSpecifier(parent, { id: node })) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// no: class NODE {}
|
||||
if (t.isClass(parent)) {
|
||||
return parent.id !== node;
|
||||
@@ -413,6 +410,51 @@ t.ensureBlock = function (node, key) {
|
||||
return node[key] = t.toBlock(node[key], node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.clone = function (node) {
|
||||
var newNode = {};
|
||||
for (var key in node) {
|
||||
if (key[0] === "_") continue;
|
||||
newNode[key] = node[key];
|
||||
}
|
||||
return newNode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.cloneDeep = function (node) {
|
||||
var newNode = {};
|
||||
|
||||
for (var key in node) {
|
||||
if (key[0] === "_") continue;
|
||||
|
||||
var val = node[key];
|
||||
|
||||
if (val) {
|
||||
if (val.type) {
|
||||
val = t.cloneDeep(val);
|
||||
} else if (Array.isArray(val)) {
|
||||
val = val.map(t.cloneDeep);
|
||||
}
|
||||
}
|
||||
|
||||
newNode[key] = val;
|
||||
}
|
||||
|
||||
return newNode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build a function that when called will return whether or not the
|
||||
* input `node` `MemberExpression` matches the input `match`.
|
||||
|
||||
@@ -3,6 +3,7 @@ import "./patch";
|
||||
import buildDebug from "debug/node";
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import * as messages from "./messages";
|
||||
import contains from "lodash/collection/contains";
|
||||
import traverse from "./traversal";
|
||||
import isString from "lodash/lang/isString";
|
||||
@@ -71,7 +72,9 @@ var templateVisitor = {
|
||||
return nodes[node.name];
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
export function template(name, nodes, keepExpression) {
|
||||
var ast = exports.templates[name];
|
||||
@@ -101,7 +104,8 @@ export function template(name, nodes, keepExpression) {
|
||||
|
||||
export function parseTemplate(loc, code) {
|
||||
var ast = parse({ filename: loc }, code).program;
|
||||
return traverse.removeProperties(ast);
|
||||
ast = traverse.removeProperties(ast);
|
||||
return ast;
|
||||
}
|
||||
|
||||
function loadTemplates() {
|
||||
@@ -109,9 +113,7 @@ function loadTemplates() {
|
||||
|
||||
var templatesLoc = path.join(__dirname, "transformation/templates");
|
||||
if (!fs.existsSync(templatesLoc)) {
|
||||
throw new Error("no templates directory - this is most likely the " +
|
||||
"result of a broken `npm publish`. Please report to " +
|
||||
"https://github.com/babel/babel/issues");
|
||||
throw new ReferenceError(messages.get("missingTemplatesDirectory"));
|
||||
}
|
||||
|
||||
each(fs.readdirSync(templatesLoc), function (name) {
|
||||
@@ -131,6 +133,5 @@ try {
|
||||
exports.templates = require("../../templates.json");
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") throw err;
|
||||
|
||||
exports.templates = loadTemplates();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
var genHelpers = require("./_generator-helpers");
|
||||
var transform = require("../lib/babel/transformation");
|
||||
var sourceMap = require("source-map");
|
||||
var codeFrame = require("../lib/babel/helpers/code-frame");
|
||||
var Module = require("module");
|
||||
var helper = require("./_helper");
|
||||
var assert = require("assert");
|
||||
var chai = require("chai");
|
||||
var path = require("path");
|
||||
var util = require("../lib/babel/util");
|
||||
var _ = require("lodash");
|
||||
var genHelpers = require("./_generator-helpers");
|
||||
var transform = require("../lib/babel/transformation");
|
||||
var buildExernalHelpers = require("../lib/babel/build-external-helpers");
|
||||
var sourceMap = require("source-map");
|
||||
var codeFrame = require("../lib/babel/helpers/code-frame");
|
||||
var Module = require("module");
|
||||
var helper = require("./_helper");
|
||||
var assert = require("assert");
|
||||
var chai = require("chai");
|
||||
var path = require("path");
|
||||
var util = require("../lib/babel/util");
|
||||
var _ = require("lodash");
|
||||
|
||||
require("../lib/babel/polyfill");
|
||||
|
||||
eval(buildExernalHelpers());
|
||||
|
||||
global.assertNoOwnProperties = function (obj) {
|
||||
assert.equal(Object.getOwnPropertyNames(obj).length, 0);
|
||||
};
|
||||
@@ -83,8 +86,8 @@ var run = function (task, done) {
|
||||
}
|
||||
};
|
||||
|
||||
var fn = new Function("require", "done", execCode);
|
||||
fn.call(global, fakeRequire, chai.assert, done);
|
||||
var fn = new Function("require", "done", "exports", execCode);
|
||||
fn.call(global, fakeRequire, chai.assert, {}, done);
|
||||
} catch (err) {
|
||||
err.message = exec.loc + ": " + err.message;
|
||||
err.message += codeFrame(execCode);
|
||||
|
||||
3
test/fixtures/bin/babel-external-helpers/--output-type global/options.json
vendored
Normal file
3
test/fixtures/bin/babel-external-helpers/--output-type global/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "nonexistent"]
|
||||
}
|
||||
3
test/fixtures/bin/babel-external-helpers/--output-type global/stdout.txt
vendored
Normal file
3
test/fixtures/bin/babel-external-helpers/--output-type global/stdout.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
(function (global) {
|
||||
var babelHelpers = global.babelHelpers = {};
|
||||
})(typeof global === "undefined" ? self : global);
|
||||
3
test/fixtures/bin/babel-external-helpers/--output-type umd/options.json
vendored
Normal file
3
test/fixtures/bin/babel-external-helpers/--output-type umd/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "nonexistent", "--output-type", "umd"]
|
||||
}
|
||||
11
test/fixtures/bin/babel-external-helpers/--output-type umd/stdout.txt
vendored
Normal file
11
test/fixtures/bin/babel-external-helpers/--output-type umd/stdout.txt
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
define(["exports"], factory);
|
||||
} else if (typeof exports === "object") {
|
||||
factory(exports);
|
||||
} else {
|
||||
factory(root.babelHelpers = {});
|
||||
}
|
||||
})(this, function (global) {
|
||||
var babelHelpers = global;
|
||||
})
|
||||
3
test/fixtures/bin/babel-external-helpers/--output-type var/options.json
vendored
Normal file
3
test/fixtures/bin/babel-external-helpers/--output-type var/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "nenexistent", "--output-type", "var"]
|
||||
}
|
||||
1
test/fixtures/bin/babel-external-helpers/--output-type var/stdout.txt
vendored
Normal file
1
test/fixtures/bin/babel-external-helpers/--output-type var/stdout.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var babelHelpers = {};
|
||||
3
test/fixtures/bin/babel-external-helpers/--whitelist/options.json
vendored
Normal file
3
test/fixtures/bin/babel-external-helpers/--whitelist/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["--whitelist", "slice,has-own"]
|
||||
}
|
||||
5
test/fixtures/bin/babel-external-helpers/--whitelist/stdout.txt
vendored
Normal file
5
test/fixtures/bin/babel-external-helpers/--whitelist/stdout.txt
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
(function (global) {
|
||||
var babelHelpers = global.babelHelpers = {};
|
||||
babelHelpers.hasOwn = Object.prototype.hasOwnProperty;
|
||||
babelHelpers.slice = Array.prototype.slice;
|
||||
})(typeof global === "undefined" ? self : global);
|
||||
@@ -1,25 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
|
||||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
_classCallCheck(this, Foo);
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
}
|
||||
|
||||
_prototypeProperties(Foo, null, {
|
||||
babelHelpers.createClass(Foo, {
|
||||
foo: {
|
||||
value: _asyncToGenerator(function* () {
|
||||
value: babelHelpers.asyncToGenerator(function* () {
|
||||
var wat = yield bar();
|
||||
}),
|
||||
writable: true,
|
||||
configurable: true
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
return Foo;
|
||||
})();
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
|
||||
var foo = _asyncToGenerator(function* () {
|
||||
var foo = babelHelpers.asyncToGenerator(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"externalHelpers": true,
|
||||
"noCheckAst": true,
|
||||
"optional": ["asyncToGenerator"]
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
|
||||
var foo = _asyncToGenerator(function* () {
|
||||
var foo = babelHelpers.asyncToGenerator(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
var _bluebird = require("bluebird");
|
||||
|
||||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
@@ -11,13 +11,11 @@ var Foo = (function () {
|
||||
_classCallCheck(this, Foo);
|
||||
}
|
||||
|
||||
_prototypeProperties(Foo, null, {
|
||||
_createClass(Foo, {
|
||||
foo: {
|
||||
value: _bluebird.coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
}),
|
||||
writable: true,
|
||||
configurable: true
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,4 +4,4 @@ var _bluebird = require("bluebird");
|
||||
|
||||
var foo = _bluebird.coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
});
|
||||
@@ -4,4 +4,4 @@ var _bluebird = require("bluebird");
|
||||
|
||||
var foo = _bluebird.coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
});
|
||||
@@ -8,7 +8,7 @@ var obj = Object.defineProperties({}, {
|
||||
set: function (value) {
|
||||
this._foo = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@ var obj = Object.defineProperties({}, {
|
||||
get: function () {
|
||||
return 5 + 5;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@ var obj = Object.defineProperties({}, {
|
||||
set: function (value) {
|
||||
this._foo = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
}
|
||||
});
|
||||
});
|
||||
2
test/fixtures/transformation/es6-block-scoping-tdz-fail/export.js
vendored
Normal file
2
test/fixtures/transformation/es6-block-scoping-tdz-fail/export.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
a;
|
||||
export const a = 1;
|
||||
2
test/fixtures/transformation/es6-block-scoping-tdz-pass/export.js
vendored
Normal file
2
test/fixtures/transformation/es6-block-scoping-tdz-pass/export.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export const a = 1;
|
||||
a;
|
||||
9
test/fixtures/transformation/es6-classes-exec/declaration-binding.js
vendored
Normal file
9
test/fixtures/transformation/es6-classes-exec/declaration-binding.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
bar() {
|
||||
return Foo;
|
||||
}
|
||||
}
|
||||
|
||||
var Bar = Foo;
|
||||
Foo = 5;
|
||||
assert.equal((new Bar).bar(), Bar);
|
||||
9
test/fixtures/transformation/es6-classes-exec/expression-binding.js
vendored
Normal file
9
test/fixtures/transformation/es6-classes-exec/expression-binding.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
var Foo = class Foo {
|
||||
bar() {
|
||||
return Foo;
|
||||
}
|
||||
}
|
||||
|
||||
var Bar = Foo;
|
||||
Foo = 5;
|
||||
assert.equal((new Bar).bar(), Bar);
|
||||
11
test/fixtures/transformation/es6-classes-exec/retain-no-call-on-reassign.js
vendored
Normal file
11
test/fixtures/transformation/es6-classes-exec/retain-no-call-on-reassign.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
bar() {
|
||||
return Foo;
|
||||
}
|
||||
}
|
||||
|
||||
var Bar = Foo;
|
||||
Foo = 5;
|
||||
assert.throws(function () {
|
||||
Bar.call(6);
|
||||
}, /Cannot call a class as a function/);
|
||||
@@ -1,45 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
|
||||
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = (function (_Foo) {
|
||||
function Test() {
|
||||
var _Foo$prototype$test, _Foo$prototype$test2;
|
||||
|
||||
_classCallCheck(this, Test);
|
||||
babelHelpers.classCallCheck(this, Test);
|
||||
|
||||
woops["super"].test();
|
||||
Foo.call(this);
|
||||
Foo.prototype.test.call(this);
|
||||
_Foo.call(this);
|
||||
_Foo.prototype.test.call(this);
|
||||
|
||||
Foo.call.apply(Foo, [this].concat(_slice.call(arguments)));
|
||||
Foo.call.apply(Foo, [this, "test"].concat(_slice.call(arguments)));
|
||||
_Foo.call.apply(_Foo, [this].concat(babelHelpers.slice.call(arguments)));
|
||||
_Foo.call.apply(_Foo, [this, "test"].concat(babelHelpers.slice.call(arguments)));
|
||||
|
||||
(_Foo$prototype$test = Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test = _Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(babelHelpers.slice.call(arguments)));
|
||||
(_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments)));
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
babelHelpers.inherits(Test, _Foo);
|
||||
|
||||
Test.prototype.test = function test() {
|
||||
var _Foo$prototype$test, _Foo$prototype$test2;
|
||||
|
||||
Foo.prototype.test.call(this);
|
||||
(_Foo$prototype$test = Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$prototype$test2 = Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments)));
|
||||
_Foo.prototype.test.call(this);
|
||||
(_Foo$prototype$test = _Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(babelHelpers.slice.call(arguments)));
|
||||
(_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments)));
|
||||
};
|
||||
|
||||
Test.foo = function foo() {
|
||||
var _Foo$foo, _Foo$foo2;
|
||||
|
||||
Foo.foo.call(this);
|
||||
(_Foo$foo = Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
|
||||
(_Foo$foo2 = Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
|
||||
_Foo.foo.call(this);
|
||||
(_Foo$foo = _Foo.foo).call.apply(_Foo$foo, [this].concat(babelHelpers.slice.call(arguments)));
|
||||
(_Foo$foo2 = _Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(babelHelpers.slice.call(arguments)));
|
||||
};
|
||||
|
||||
return Test;
|
||||
})(Foo);
|
||||
})(Foo);
|
||||
@@ -1,5 +1,6 @@
|
||||
class Test extends Foo {
|
||||
constructor() {
|
||||
super();
|
||||
super.test;
|
||||
super.test.whatever;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = (function (_Foo) {
|
||||
function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
babelHelpers.classCallCheck(this, Test);
|
||||
|
||||
Foo.prototype.test;
|
||||
Foo.prototype.test.whatever;
|
||||
_Foo.call(this);
|
||||
_Foo.prototype.test;
|
||||
_Foo.prototype.test.whatever;
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
|
||||
babelHelpers.inherits(Test, _Foo);
|
||||
return Test;
|
||||
})(Foo);
|
||||
@@ -1,5 +1,6 @@
|
||||
class Test extends Foo {
|
||||
constructor() {
|
||||
super();
|
||||
super.test.whatever();
|
||||
super.test();
|
||||
}
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
|
||||
|
||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
||||
|
||||
var Test = (function (Foo) {
|
||||
var Test = (function (_Foo) {
|
||||
function Test() {
|
||||
_classCallCheck(this, Test);
|
||||
babelHelpers.classCallCheck(this, Test);
|
||||
|
||||
Foo.prototype.test.whatever();
|
||||
Foo.prototype.test.call(this);
|
||||
_Foo.call(this);
|
||||
_Foo.prototype.test.whatever();
|
||||
_Foo.prototype.test.call(this);
|
||||
}
|
||||
|
||||
_inherits(Test, Foo);
|
||||
babelHelpers.inherits(Test, _Foo);
|
||||
|
||||
Test.test = function test() {
|
||||
return Foo.wow.call(this);
|
||||
return _Foo.wow.call(this);
|
||||
};
|
||||
|
||||
return Test;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user