Compare commits

...

65 Commits

Author SHA1 Message Date
Sebastian McKenzie
b1252b865b v4.7.4 2015-03-10 03:29:47 +11:00
Sebastian McKenzie
068b1341d9 fix erroneous whitespace 2015-03-10 03:28:36 +11:00
Sebastian McKenzie
20eb143915 remove Number from the list of valid runtime constructors - fixes #981 2015-03-10 03:27:13 +11:00
Sebastian McKenzie
1302a86bf2 scope -> scopable class alias key 2015-03-10 03:22:55 +11:00
Sebastian McKenzie
b7831f1d7b prepend mocha command with node 2015-03-10 03:15:31 +11:00
Sebastian McKenzie
e46cabb21f remove code coverage from travis make task 2015-03-10 03:12:50 +11:00
Sebastian McKenzie
fff06a047e Revert "delegate node path removal to after call"
This reverts commit 5e0236d9a7.
2015-03-10 02:50:43 +11:00
Sebastian McKenzie
6b0320fc83 disable test262 tests by default 2015-03-10 02:34:35 +11:00
Sebastian McKenzie
5dde63fa0a more elaborate tests for #980 2015-03-10 02:13:00 +11:00
Sebastian McKenzie
672118149a hoist all directives - fixes #980 2015-03-10 01:53:51 +11:00
Sebastian McKenzie
5e0236d9a7 delegate node path removal to after call 2015-03-10 01:44:58 +11:00
Sebastian McKenzie
5101664e7d update 4.7.4 changelog 2015-03-10 01:44:44 +11:00
Sebastian McKenzie
2d684a06d3 update changelog version to 4.7.4 2015-03-10 01:23:24 +11:00
Sebastian McKenzie
e31bad8f42 add 4.7.3 changelog 2015-03-10 01:17:14 +11:00
Sebastian McKenzie
644b4373fc rewrite named function expressions in async function transformers - fixes #979 2015-03-10 01:16:38 +11:00
Sebastian McKenzie
62f37c1e62 fix util.booleanify 2015-03-10 01:10:58 +11:00
Sebastian McKenzie
fc0e89463b use flow types for annotations - goodbye JSDoc! 2015-03-10 00:35:52 +11:00
Sebastian McKenzie
56b6a795a4 remove path.refreshScope until i'm more confident on it's functionality so it doesn't break peopls stuff 2015-03-09 23:09:22 +11:00
Sebastian McKenzie
17b34a2959 dynamic scope tracking, toot toot - fixes #957 2015-03-09 22:07:05 +11:00
Sebastian McKenzie
c4da0253c5 move flattenable keys to types 2015-03-09 16:55:00 +11:00
Sebastian McKenzie
5f2df40f6d consistent whitespace in patch 2015-03-09 16:54:50 +11:00
Sebastian McKenzie
7d20a9b882 add traversal path todos 2015-03-09 16:54:41 +11:00
Sebastian McKenzie
ee0ac9f149 use spread in messages 2015-03-09 16:54:30 +11:00
Sebastian McKenzie
c5d3f42d8a alias core-js/library in babel-runtime - closes #965 2015-03-09 16:54:19 +11:00
Sebastian McKenzie
d162919a53 update symols transformer name 2015-03-09 03:39:30 +11:00
Sebastian McKenzie
d1f712344d add istanbul auxiliary comment task to makefile 2015-03-09 03:38:39 +11:00
Sebastian McKenzie
e985912b54 add Binary node cleanup 2015-03-09 03:38:27 +11:00
Sebastian McKenzie
97a21e4a34 update spec.typeofSymbol references to es6.symbols 2015-03-09 03:38:13 +11:00
Sebastian McKenzie
d8fb7812f7 more utility.removeConsole tests 2015-03-09 03:37:42 +11:00
Sebastian McKenzie
bfe63f5885 rename spec.typeofSymbol transformer to es6.symbols 2015-03-09 03:37:26 +11:00
Sebastian McKenzie
44ca6873a3 add super to contextVariables 2015-03-09 03:37:05 +11:00
Sebastian McKenzie
2f66ea7338 4.7.3 2015-03-08 04:33:50 +11:00
Sebastian McKenzie
70967cf53c v4.7.3 2015-03-08 04:32:46 +11:00
Sebastian McKenzie
dc117a74ae both -> inline - thanks @dkieks 2015-03-08 04:29:48 +11:00
Sebastian McKenzie
b0f32a822d pass file.addImport a name instead of an identifier 2015-03-08 04:10:53 +11:00
Sebastian McKenzie
fd99ea1749 Merge branch 'master' of github.com:babel/babel 2015-03-08 04:05:44 +11:00
Sebastian McKenzie
572129542d fallback to current parentPath if none was provided 2015-03-08 04:04:48 +11:00
Sebastian McKenzie
6f53980bfc move runtime helpers to separate modules - babel/ember-cli-babel#24 2015-03-08 04:04:40 +11:00
Sebastian McKenzie
348af1990d Merge pull request #972 from neVERberleRfellerER/node-external-helpers-tests
add tests for babel-external-helpers
2015-03-08 03:50:28 +11:00
Ondrej Kraus
bd5f350728 add tests for babel-external-helpers 2015-03-07 17:46:40 +01:00
Sebastian McKenzie
958fa282f4 4.7.2 2015-03-08 03:12:09 +11:00
Sebastian McKenzie
31e6b18346 v4.7.2 2015-03-08 03:09:43 +11:00
Sebastian McKenzie
d17ac92a3f fix changelog version 2015-03-08 03:06:46 +11:00
Sebastian McKenzie
188bcb70f7 add 4.7.1 changelog 2015-03-08 03:03:17 +11:00
Sebastian McKenzie
b8bd11a0e7 fix incorrect builder reference 2015-03-08 03:02:19 +11:00
Sebastian McKenzie
45bc74efe7 use a lookup table instead of an if - #945 2015-03-08 02:57:37 +11:00
Sebastian McKenzie
7eb169a894 Merge pull request #945 from neVERberleRfellerER/helper-globals-fix
Add choice of output format to babel-external-helpers
2015-03-08 02:56:30 +11:00
Sebastian McKenzie
eed4f312d8 add sourceMap both option - closes #966 2015-03-08 02:54:23 +11:00
Sebastian McKenzie
44e4dc970f more es6 2015-03-08 02:52:23 +11:00
Sebastian McKenzie
5d32432e67 split up export variable declarations - fixes #939, fixes #964 2015-03-08 02:52:10 +11:00
Sebastian McKenzie
9c9af6dbbd add utility.removeClass tests and move parentPath setting to setContext - fixes #967 2015-03-08 02:49:58 +11:00
Sebastian McKenzie
70cd650e10 remove dead t.isFalsyExpression and ignore private properties in t.cloneDeep - fixes #962 2015-03-08 02:45:14 +11:00
Sebastian McKenzie
c7bb00d58d ignore case breaks - fixes #963 2015-03-07 17:41:56 +11:00
Ondrej Kraus
623be068c4 add unsupportedOutputType to messages.js 2015-03-07 01:53:34 +01:00
Ondrej Kraus
71f5c9791d replace switch with if-else chain 2015-03-07 01:50:50 +01:00
Ondrej Kraus
3e6e86d073 order template keys by length 2015-03-07 01:50:49 +01:00
Ondrej Kraus
a0fb398ca2 add possibility to select format of external helpers 2015-03-07 01:50:49 +01:00
Ondrej Kraus
71b9f19e6a change to normal UMD (fixes bug with leaking variable in AMD mode) 2015-03-07 01:50:48 +01:00
Ondrej Kraus
c45ce58f0c stop assigning to global in generated helpers code 2015-03-07 01:50:48 +01:00
Sebastian McKenzie
d32f587e3c expose dynamicImports when es6.modules is blacklisted babel/ember-cli-babel#24 2015-03-07 03:31:24 +11:00
Sebastian McKenzie
9e1874ba89 4.7.1 2015-03-07 03:31:05 +11:00
Sebastian McKenzie
35fdc5c5d8 v4.7.1 2015-03-07 02:52:17 +11:00
Sebastian McKenzie
a4035fc257 use convert-source-map package - closes #960 2015-03-07 02:46:15 +11:00
Sebastian McKenzie
42e3dc7a70 inherit all options from input source map 2015-03-07 02:28:33 +11:00
Sebastian McKenzie
cdccf24515 4.7.0 2015-03-07 02:04:58 +11:00
114 changed files with 970 additions and 587 deletions

2
.gitignore vendored
View File

@@ -11,6 +11,6 @@ test/tmp
coverage
dist
.package.json
packages/babel-runtime/*.js
packages/babel-runtime/helpers/*.js
packages/babel-runtime/regenerator/*.js
lib

View File

@@ -13,6 +13,40 @@ _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.4
* **Bug Fix**
* Rewrite named function expressions in optional async function transformers.
* Hoist directives.
* Remove `Number` from the list of valid `runtime` constructors.
* **Internal**
* `spec.typeofSymbol` transformer has been renamed to `es6.symbols`.
## 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**

View File

@@ -8,11 +8,14 @@ BABEL_CMD = node_modules/babel/bin/babel
export NODE_ENV = test
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core
.PHONY: clean test test-cov test-clean test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core build-core-test
build-core:
node $(BABEL_CMD) src --out-dir lib --copy-files
build-core-test:
node $(BABEL_CMD) src --out-dir lib --copy-files --auxiliary-comment "istanbul ignore next"
watch-core:
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
@@ -40,26 +43,19 @@ test-clean:
rm -rf test/tmp
test:
$(MOCHA_CMD)
node $(MOCHA_CMD)
make test-clean
test-simple:
# excludes test262
export SIMPLE_BABEL_TESTS=1; \
make test
test-all:
export ALL_BABEL_TESTS=1; \
make test
test-cov:
rm -rf coverage
export SIMPLE_BABEL_TESTS=1; \
make build-core-test
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
test-travis: bootstrap build
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
test-travis: bootstrap build test
test-browser:
mkdir -p dist

View File

@@ -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));

View File

@@ -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 {

View File

@@ -1,7 +1,7 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "4.7.0",
"version": "4.7.4",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"repository": "babel/babel",

View File

@@ -0,0 +1 @@
module.exports = require("core-js/library");

View File

View File

@@ -1,7 +1,10 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "4.6.6",
"version": "4.7.3",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>"
}
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"dependencies": {
"core-js": "^0.6.1"
}
}

View File

@@ -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")));

View File

@@ -57,7 +57,7 @@ var compile = function (filename) {
if (!result) {
result = babel.transformFileSync(filename, extend(opts, {
sourceMap: true,
sourceMap: "both",
ast: false
}));
}

View File

@@ -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;
};

View File

@@ -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))
));
});
};

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -1,3 +1,3 @@
module.exports = function () {
export default function () {
return Object.create(null);
};

View File

@@ -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 = [];

View File

@@ -20,17 +20,14 @@ export var messages = {
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.",
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues"
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) {
export function get(key: String, ...args) {
var msg = messages[key];
if (!msg) throw new ReferenceError(`Unknown message ${JSON.stringify(key)}`);
var args = [];
for (var i = 1; i < arguments.length; i++) {
args.push(arguments[i]);
}
args = parseArgs(args);
return msg.replace(/\$(\d+)/g, function (str, i) {
@@ -38,7 +35,7 @@ export function get(key) {
});
}
export function parseArgs(args) {
export function parseArgs(args: Array<any>) {
return args.map(function (val) {
if (val != null && val.inspect) {
return val.inspect();

View File

@@ -9,8 +9,8 @@ extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
// regenerator-babel/ast-types
var def = types.Type.def;
var or = types.Type.or;
var def = types.Type.def;
var or = types.Type.or;
def("File")
.bases("Node")

View File

@@ -121,7 +121,7 @@ export default class File {
"accept"
];
normalizeOptions(opts) {
normalizeOptions(opts: Object) {
opts = assign({}, opts);
for (var key in opts) {
@@ -227,7 +227,7 @@ export default class File {
return opts;
};
isLoose(key) {
isLoose(key: string) {
return includes(this.opts.loose, key);
}
@@ -259,13 +259,13 @@ export default class File {
this.transformers = transformers;
}
debug(msg) {
debug(msg?: string) {
var parts = this.opts.filename;
if (msg) parts += `: ${msg}`;
util.debug(parts);
}
getModuleFormatter(type) {
getModuleFormatter(type: string) {
var ModuleFormatter = isFunction(type) ? type : transform.moduleFormatters[type];
if (!ModuleFormatter) {
@@ -280,19 +280,19 @@ export default class File {
return new ModuleFormatter(this);
}
parseInputSourceMap(code) {
parseInputSourceMap(code: string) {
var opts = this.opts;
var inputMap = convertSourceMap.fromSource(code);
if (inputMap) {
opts.inputSourceMap = inputMap;
opts.inputSourceMap = inputMap.toObject();
code = convertSourceMap.removeComments(code);
}
return code;
}
parseShebang(code) {
parseShebang(code: string) {
var shebangMatch = shebangRegex.exec(code);
if (shebangMatch) {
@@ -305,15 +305,15 @@ export default class File {
return code;
}
set(key, val) {
set(key: string, val): any {
return this.data[key] = val;
};
setDynamic(key, fn) {
setDynamic(key: string, fn: Function) {
this.dynamicData[key] = fn;
}
get(key) {
get(key: string): any {
var data = this.data[key];
if (data) {
return data;
@@ -325,7 +325,7 @@ export default class File {
}
}
addImport(source, name, noDefault) {
addImport(source: string, name?: string, noDefault?: boolean): Object {
name ||= source;
var id = this.dynamicImportIds[name];
@@ -339,17 +339,21 @@ 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;
}
isConsequenceExpressionStatement(node) {
isConsequenceExpressionStatement(node: Object): boolean {
return t.isExpressionStatement(node) && this.lastStatements.indexOf(node) >= 0;
}
attachAuxiliaryComment(node) {
attachAuxiliaryComment(node: Object): Object {
var comment = this.opts.auxiliaryComment;
if (comment) {
node.leadingComments ||= [];
@@ -361,7 +365,7 @@ export default class File {
return node;
}
addHelper(name) {
addHelper(name: string): Object {
if (!includes(File.helpers, name)) {
throw new ReferenceError(`Unknown helper ${name}`);
}
@@ -373,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;
@@ -401,14 +408,14 @@ export default class File {
return err;
}
addCode(code) {
addCode(code: string) {
code = (code || "") + "";
code = this.parseInputSourceMap(code);
this.code = code;
return this.parseShebang(code);
}
parse(code) {
parse(code: string) {
code = this.addCode(code);
var opts = this.opts;
@@ -445,7 +452,7 @@ export default class File {
this.call("post");
}
call(key) {
call(key: string) {
var stack = this.transformerStack;
for (var i = 0; i < stack.length; i++) {
var transformer = stack[i].transformer;
@@ -473,27 +480,33 @@ export default class File {
});
}
mergeSourceMap(map) {
mergeSourceMap(map: Object) {
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 = map.sources
mergedMap.file = map.file;
mergedMap.sources = inputMap.sources
mergedMap.file = inputMap.file;
return mergedMap;
}
return map;
}
generate() {
generate(): {
code: string;
map?: Object;
ast?: Object;
} {
var opts = this.opts;
var ast = this.ast;
@@ -521,8 +534,11 @@ export default class File {
result.map = this.mergeSourceMap(result.map);
if (opts.sourceMap === "inline") {
if (opts.sourceMap === "inline" || opts.sourceMap === "both") {
result.code += "\n" + convertSourceMap.fromObject(result.map).toComment();
}
if (opts.sourceMap === "inline") {
result.map = null;
}

View File

@@ -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 + "=";
};

View File

@@ -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])
);
};
}

View File

@@ -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);
};

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,7 +1,7 @@
import t from "../../types";
var visitor = {
enter(node) {
var awaitVisitor = {
enter(node, parent, scope, state) {
if (t.isFunction(node)) this.skip();
if (t.isAwaitExpression(node)) {
@@ -16,13 +16,23 @@ var visitor = {
}
};
module.exports = function (node, callId, scope) {
var referenceVisitor = {
enter(node, parent, scope, state) {
var name = state.id.name;
if (t.isReferencedIdentifier(node, parent, { name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
return state.ref ||= scope.generateUidIdentifier(name);
}
}
};
export default function (node, callId, scope) {
node.async = false;
node.generator = true;
scope.traverse(node, visitor);
scope.traverse(node, awaitVisitor, state);
var call = t.callExpression(callId, [node]);
var id = node.id;
node.id = null;
@@ -33,6 +43,16 @@ module.exports = function (node, callId, scope) {
declar._blockHoist = true;
return declar;
} else {
if (id) {
var state = { id: id };
scope.traverse(node, referenceVisitor, state);
if (state.ref) {
scope.parent.push({ id: state.ref });
return t.assignmentExpression("=", state.ref, call);
}
}
return call;
}
};

View File

@@ -47,12 +47,9 @@ export default class ReplaceSupers {
/**
* Description
*
* @param {Object} opts
* @param {Boolean} [inClass]
*/
constructor(opts, inClass) {
constructor(opts: Object, inClass?: boolean = false) {
this.topLevelThisReference = opts.topLevelThisReference;
this.methodNode = opts.methodNode;
this.superRef = opts.superRef;
@@ -76,15 +73,9 @@ export default class ReplaceSupers {
*
* _set(Object.getPrototypeOf(CLASS.prototype), "METHOD", "VALUE", this)
*
* @param {Node} property
* @param {Node} value
* @param {Boolean} isComputed
* @param {Node} thisExpression
*
* @returns {Node}
*/
setSuperProperty(property, value, isComputed, thisExpression) {
setSuperProperty(property: Object, value: Object, isComputed: boolean, thisExpression: Object): Object {
return t.callExpression(
this.file.addHelper("set"),
[
@@ -108,14 +99,9 @@ export default class ReplaceSupers {
*
* _get(Object.getPrototypeOf(CLASS.prototype), "METHOD", this)
*
* @param {Node} property
* @param {Boolean} isComputed
* @param {Node} thisExpression
*
* @returns {Node}
*/
getSuperProperty(property, isComputed, thisExpression) {
getSuperProperty(property: Object, isComputed: boolean, thisExpression: Object): Object {
return t.callExpression(
this.file.addHelper("get"),
[
@@ -141,12 +127,9 @@ export default class ReplaceSupers {
/**
* Description
*
* @param {Object} node
* @param {Boolean} topLevel
*/
traverseLevel(node, topLevel) {
traverseLevel(node: Object, topLevel: boolean) {
var state = { self: this, topLevel: topLevel };
this.scope.traverse(node, visitor, state);
}
@@ -169,14 +152,9 @@ export default class ReplaceSupers {
/**
* Description
*
* @param {Object} node
* @param {Object} id
* @param {Object} parent
* @returns {Object}
*/
getLooseSuperProperty(id, parent) {
getLooseSuperProperty(id: Object, parent: Object) {
var methodNode = this.methodNode;
var methodName = methodNode.key;
var superRef = this.superRef || t.identifier("Function");
@@ -211,13 +189,9 @@ export default class ReplaceSupers {
/**
* Description
*
* @param {Function} getThisReference
* @param {Object} node
* @param {Object} parent
*/
looseHandle(getThisReference, node, parent) {
looseHandle(getThisReference: Function, node: Object, parent: Object) {
if (t.isIdentifier(node, { name: "super" })) {
this.hasSuper = true;
return this.getLooseSuperProperty(node, parent);
@@ -235,13 +209,9 @@ export default class ReplaceSupers {
/**
* Description
*
* @param {Function} getThisReference
* @param {Object} node
* @param {Object} parent
*/
specHandle(getThisReference, node, parent) {
specHandle(getThisReference: Function, node: Object, parent: Object) {
var methodNode = this.methodNode;
var property;
var computed;

View File

@@ -4,7 +4,7 @@ import object from "../helpers/object";
import File from "./file";
import each from "lodash/collection/each";
export default function transform(code, opts) {
export default function transform(code: code, opts?: Object) {
var file = new File(opts);
return file.parse(code);
}
@@ -18,7 +18,7 @@ transform.fromAst = function (ast, code, opts) {
return file.generate();
};
transform._ensureTransformerNames = function (type, rawKeys) {
transform._ensureTransformerNames = function (type: string, rawKeys: Array<string>) {
var keys = [];
for (var i = 0; i < rawKeys.length; i++) {

View File

@@ -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)) {

View File

@@ -1,4 +1,4 @@
module.exports = {
export default {
commonStrict: require("./common-strict"),
amdStrict: require("./amd-strict"),
umdStrict: require("./umd-strict"),

View File

@@ -1,2 +1,2 @@
var helpers = exports.default = {};
exports.default = HELPER;
exports.__esModule = true;

View 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
});

View File

@@ -6,14 +6,14 @@ import includes from "lodash/collection/includes";
*/
export default class TransformerPass {
constructor(file, transformer) {
constructor(file: File, transformer: Transformer) {
this.transformer = transformer;
this.shouldRun = !transformer.check;
this.handlers = transformer.handlers;
this.file = file;
}
canRun() {
canRun(): boolean {
var transformer = this.transformer;
var opts = this.file.opts;
@@ -42,7 +42,7 @@ export default class TransformerPass {
return true;
}
checkNode(node) {
checkNode(node: Object): boolean {
var check = this.transformer.check;
if (check) {
return this.shouldRun = check(node);

View File

@@ -12,7 +12,7 @@ import each from "lodash/collection/each";
*/
export default class Transformer {
constructor(transformerKey, transformer, opts) {
constructor(transformerKey: key, transformer: Object, opts: Object) {
transformer = assign({}, transformer);
var take = function (key) {
@@ -36,7 +36,7 @@ export default class Transformer {
this.key = transformerKey;
}
normalize(transformer) {
normalize(transformer: Object): Object {
if (isFunction(transformer)) {
transformer = { ast: transformer };
}
@@ -65,7 +65,7 @@ export default class Transformer {
return transformer;
}
buildPass(file) {
buildPass(file: File): TransformerPass {
return new TransformerPass(file, this);
}
}

View File

@@ -1,6 +1,7 @@
{
"selfContained": "runtime",
"unicode-regex": "regex.unicode",
"spec.typeofSymbol": "es6.symbols",
"minification.deadCodeElimination": "utility.deadCodeElimination",
"minification.removeConsoleCalls": "utility.removeConsole",

View File

@@ -75,7 +75,7 @@ export function Loop(node, parent, scope, file) {
export function BlockStatement(block, parent, scope, file) {
if (!t.isLoop(parent)) {
var blockScoping = new BlockScoping(false, block, parent, scope, file);
var blockScoping = new BlockScoping(null, block, parent, scope, file);
blockScoping.run();
}
}
@@ -222,15 +222,9 @@ class BlockScoping {
/**
* Description
*
* @param {Boolean|Node} loopParent
* @param {Node} block
* @param {Node} parent
* @param {Scope} scope
* @param {File} file
*/
constructor(loopParent, block, parent, scope, file) {
constructor(loopParent?: Object, block: Object, parent: Object, scope: Scope, file: File) {
this.loopParent = loopParent;
this.parent = parent;
this.scope = scope;
@@ -466,12 +460,9 @@ class BlockScoping {
/**
* Turn a `VariableDeclaration` into an array of `AssignmentExpressions` with
* their declarations hoisted to before the closure wrapper.
*
* @param {Node} node VariableDeclaration
* @returns {Array}
*/
pushDeclar(node) {
pushDeclar(node: { type: "VariableDeclaration" }): Array<Object> {
this.body.push(t.variableDeclaration(node.kind, node.declarations.map(function (declar) {
return t.variableDeclarator(declar.id);
})));
@@ -491,12 +482,9 @@ class BlockScoping {
/**
* Push the closure to the body.
*
* @param {Node} ret Identifier
* @param {Node} call CallExpression
*/
build(ret, call) {
build(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
var has = this.has;
if (has.hasReturn || has.hasBreakContinue) {
this.buildHas(ret, call);
@@ -507,12 +495,9 @@ class BlockScoping {
/**
* Description
*
* @param {Node} ret Identifier
* @param {Node} call CallExpression
*/
buildHas(ret, call) {
buildHas(ret: { type: "Identifier" }, call: { type: "CallExpression" }) {
var body = this.body;
body.push(t.variableDeclaration("var", [

View File

@@ -56,14 +56,9 @@ class ClassTransformer {
/**
* Description
*
* @param {Node} node
* @param {Node} parent
* @param {Scope} scope
* @param {File} file
*/
constructor(node, parent, scope, file) {
constructor(node: Object, parent: Object, scope: Scope, file: File) {
this.parent = parent;
this.scope = scope;
this.node = node;
@@ -245,11 +240,9 @@ class ClassTransformer {
/**
* Description
*
* @param {Node} node
*/
verifyConstructor(node) {
verifyConstructor(node: Object) {
return; // enable this for the next major
var state = {
@@ -267,11 +260,9 @@ class ClassTransformer {
/**
* Push a method to its respective mutatorMap.
*
* @param {Node} node MethodDefinition
*/
pushMethod(node) {
pushMethod(node: { type: "MethodDefinition" }) {
var methodName = node.key;
var kind = node.kind;
@@ -308,11 +299,9 @@ class ClassTransformer {
/**
* Description
*
* @param {Node} node
*/
pushProperty(node) {
pushProperty(node: Object) {
if (!node.value) return;
var key;
@@ -332,11 +321,9 @@ class ClassTransformer {
/**
* Replace the constructor body of our class.
*
* @param {Node} method MethodDefinition
*/
pushConstructor(method) {
pushConstructor(method: { type: "MethodDefinition" }) {
if (method.kind) {
throw this.file.errorWithNode(method, messages.get("classesIllegalConstructorKind"));
}

View File

@@ -52,6 +52,9 @@ var breakVisitor = {
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")), [])
);

View File

@@ -94,7 +94,7 @@ export default {
_aliasFunctions: require("./internal/alias-functions"),
"spec.typeofSymbol": require("./spec/typeof-symbol"),
"es6.symbols": require("./es6/symbols"),
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
_strict: require("./internal/strict"),

View File

@@ -13,3 +13,18 @@ export var ExpressionStatement = {
if (!node.expression) this.remove();
}
};
export var Binary = {
exit(node) {
var right = node.right;
var left = node.left;
if (!left && !right) {
this.remove();
} else if (!left) {
return right;
} else if (!right) {
return left;
}
}
};

View File

@@ -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);
}

View File

@@ -32,9 +32,11 @@ export function ExportDeclaration(node, parent, scope) {
if (node.default) {
if (t.isClassDeclaration(declar)) {
// export default class Foo {};
this.node = [getDeclar(), node];
node.declaration = declar.id;
return [getDeclar(), node];
} else if (t.isClassExpression(declar)) {
// export default class {};
var temp = scope.generateUidIdentifier("default");
declar = t.variableDeclaration("var", [
t.variableDeclarator(temp, declar)
@@ -42,16 +44,27 @@ export function ExportDeclaration(node, parent, scope) {
node.declaration = temp;
return [getDeclar(), node];
} else if (t.isFunctionDeclaration(declar)) {
// export default function Foo() {}
node._blockHoist = 2;
node.declaration = declar.id;
return [getDeclar(), node];
}
} else {
if (t.isFunctionDeclaration(declar)) {
// export function Foo() {}
node.specifiers = [t.importSpecifier(declar.id, declar.id)];
node.declaration = null;
node._blockHoist = 2;
return [getDeclar(), node];
} else if (t.isVariableDeclaration(declar)) {
// export var foo = "bar";
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)];
}
}
}

View File

@@ -25,3 +25,16 @@ export function Property(node, parent, scope, file) {
}
export { Property as MethodDefinition };
export function BlockStatement(node) {
for (var i = 0; i < node.body.length; i++) {
var bodyNode = node.body[i];
if (t.isExpressionStatement(bodyNode) && t.isLiteral(bodyNode.expression)) {
bodyNode._blockHoist = Infinity;
} else {
return;
}
}
}
export { BlockStatement as Program };

View File

@@ -16,8 +16,7 @@ var ALIASABLE_CONSTRUCTORS = [
"Map",
"WeakMap",
"Set",
"WeakSet",
"Number"
"WeakSet"
];
var astVisitor = {
@@ -81,8 +80,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 () {

View File

@@ -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) {

View File

@@ -1,15 +1,15 @@
import TraversalPath from "./path";
import flatten from "lodash/array/flatten";
import compact from "lodash/array/compact";
import t from "../types";
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() {
@@ -43,7 +43,7 @@ export default class TraversalContext {
if (this.shouldFlatten) {
node[key] = flatten(node[key]);
if (key === "body" || key === "expressions") {
if (t.FLATTENABLE_KEYS.indexOf(key) >= 0) {
// we can safely compact this
node[key] = compact(node[key]);
}

View File

@@ -4,11 +4,10 @@ import Scope from "./scope";
import t from "../types";
export default class TraversalPath {
constructor(parentPath, parent, container) {
this.parentPath = parentPath;
this.container = container;
this.parent = parent;
this.data = {};
constructor(parent, container) {
this.container = container;
this.parent = parent;
this.data = {};
}
static get(parentPath, context, parent, container, key) {
@@ -25,11 +24,11 @@ export default class TraversalPath {
}
if (!path) {
path = new TraversalPath(parentPath, parent, container);
path = new TraversalPath(parent, container);
paths.push(path);
}
path.setContext(context, key);
path.setContext(parentPath, context, key);
return path;
}
@@ -57,22 +56,23 @@ export default class TraversalPath {
this.scope = TraversalPath.getScope(this.node, this.parent, this.context.scope);
}
setContext(context, key) {
this.shouldRemove = false;
this.shouldSkip = false;
this.shouldStop = false;
setContext(parentPath, context, key) {
this.shouldSkip = false;
this.shouldStop = false;
this.context = context;
this.state = context.state;
this.opts = context.opts;
this.key = key;
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;
this._refresh(this.node, []);
this.container[this.key] = null;
this.flatten();
}
skip() {
@@ -88,30 +88,43 @@ export default class TraversalPath {
this.context.flatten();
}
_refresh(oldNode, newNodes) {
// todo
}
refresh() {
var node = this.node;
this._refresh(node, [node]);
}
get node() {
return this.container[this.key];
}
set node(replacement) {
var isArray = Array.isArray(replacement);
if (!replacement) return this.remove();
var oldNode = this.node;
var isArray = Array.isArray(replacement);
var replacements = isArray ? replacement : [replacement];
// inherit comments from original node to the first replacement node
var inheritTo = replacement;
if (isArray) inheritTo = replacement[0];
if (inheritTo) t.inheritsComments(inheritTo, this.node);
var inheritTo = replacements[0];
if (inheritTo) t.inheritsComments(inheritTo, oldNode);
// replace the node
this.container[this.key] = replacement;
// potentially create new scope
this.setScope();
// refresh scope with new/removed bindings
this._refresh(oldNode, replacements);
var file = this.scope && this.scope.file;
if (file) {
if (isArray) {
for (var i = 0; i < replacement.length; i++) {
file.checkNode(replacement[i], this.scope);
}
} else {
file.checkNode(replacement, this.scope);
for (var i = 0; i < replacements.length; i++) {
file.checkNode(replacements[i], this.scope);
}
}
@@ -123,6 +136,7 @@ export default class TraversalPath {
}
this.flatten();
// TODO: duplicate internal path metadata across the new node paths
}
}
@@ -139,11 +153,6 @@ export default class TraversalPath {
if (replacement) {
this.node = replacement;
}
if (this.shouldRemove) {
this.container[this.key] = null;
this.flatten();
}
}
isBlacklisted() {
@@ -163,16 +172,17 @@ export default class TraversalPath {
var node = this.node;
var opts = this.opts;
if (Array.isArray(node)) {
// traverse over these replacement nodes we purposely don't call exitNode
// as the original node has been destroyed
for (var i = 0; i < node.length; i++) {
traverse.node(node[i], opts, this.scope, this.state, this);
if (node) {
if (Array.isArray(node)) {
// traverse over these replacement nodes we purposely don't call exitNode
// as the original node has been destroyed
for (var i = 0; i < node.length; i++) {
traverse.node(node[i], opts, this.scope, this.state, this);
}
} else {
traverse.node(node, opts, this.scope, this.state, this);
this.call("exit");
}
} else {
traverse.node(node, opts, this.scope, this.state, this);
this.call("exit");
}
return this.shouldStop;

View File

@@ -9,7 +9,6 @@ import object from "../helpers/object";
import each from "lodash/collection/each";
import t from "../types";
var functionVariableVisitor = {
enter(node, parent, scope, state) {
if (t.isFor(node)) {
@@ -64,14 +63,9 @@ export default class Scope {
/**
* This searches the current "scope" and collects all references/bindings
* within.
*
* @param {Node} block
* @param {Node} parentBlock
* @param {Scope} [parent]
* @param {File} [file]
*/
constructor(block, parentBlock, parent, file) {
constructor(block: Object, parentBlock: Object, parent?: Scope, file?: File) {
this.parent = parent;
this.file = parent ? parent.file : file;
@@ -82,28 +76,22 @@ export default class Scope {
}
static globals = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys));
static contextVariables = ["this", "arguments"];
static contextVariables = ["this", "arguments", "super"];
/**
* Description
*
* @param {Object} node
* @param {Object} opts
* @param [state]
*/
traverse(node, opts, state) {
traverse(node: Object, opts: Object, state?) {
traverse(node, opts, this, state);
}
/**
* Description
*
* @param {String} [name="temp"]
*/
generateTemp(name) {
var id = this.generateUidIdentifier(name || "temp");
generateTemp(name: string = "temp") {
var id = this.generateUidIdentifier(name);
this.push({
key: id.name,
id: id
@@ -113,11 +101,9 @@ export default class Scope {
/**
* Description
*
* @param {String} name
*/
generateUidIdentifier(name) {
generateUidIdentifier(name: string) {
var id = t.identifier(this.generateUid(name));
this.getFunctionParent().registerBinding("uid", id);
return id;
@@ -125,11 +111,9 @@ export default class Scope {
/**
* Description
*
* @param {String} name
*/
generateUid(name) {
generateUid(name: string) {
name = t.toIdentifier(name).replace(/^_+/, "");
var uid;
@@ -149,12 +133,9 @@ export default class Scope {
/*
* Description
*
* @param {Object} parent
* @returns {Object}
*/
generateUidBasedOnNode(parent) {
generateUidBasedOnNode(parent: Object): Object {
var node = parent;
if (t.isAssignmentExpression(parent)) {
@@ -190,12 +171,9 @@ export default class Scope {
/**
* Description
*
* @param {Object} node
* @returns {Object}
*/
generateTempBasedOnNode(node) {
generateTempBasedOnNode(node: Object): ?Object {
if (t.isIdentifier(node) && this.hasBinding(node.name)) {
return null;
}
@@ -208,7 +186,11 @@ export default class Scope {
return id;
}
checkBlockScopedCollisions(kind, name, id) {
/**
* Description
*/
checkBlockScopedCollisions(kind: string, name: string, id: Object) {
var local = this.getOwnBindingInfo(name);
if (!local) return;
@@ -220,7 +202,11 @@ export default class Scope {
}
}
rename(oldName, newName) {
/**
* Description
*/
rename(oldName: string, newName: string) {
newName ||= this.generateUidIdentifier(oldName).name;
var info = this.getBindingInfo(oldName);
@@ -246,13 +232,17 @@ export default class Scope {
}
});
this.clearOwnBinding(oldName);
scope.removeOwnBinding(oldName);
scope.bindings[newName] = info;
binding.name = newName;
}
inferType(node) {
/**
* Description
*/
inferType(node: Object) {
var target;
if (t.isVariableDeclarator(node)) {
@@ -284,7 +274,11 @@ export default class Scope {
}
}
isTypeGeneric(name, genericName) {
/**
* Description
*/
isTypeGeneric(name: string, genericName: string) {
var info = this.getBindingInfo(name);
if (!info) return false;
@@ -292,18 +286,30 @@ export default class Scope {
return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, { name: genericName });
}
assignTypeGeneric(name, type) {
/**
* Description
*/
assignTypeGeneric(name: string, type: Object) {
this.assignType(name, t.genericTypeAnnotation(t.identifier(type)));
}
assignType(name, type) {
/**
* Description
*/
assignType(name: string, type: Object) {
var info = this.getBindingInfo(name);
if (!info) return;
info.typeAnnotation = type;
}
getTypeAnnotation(name, id, node) {
/**
* Description
*/
getTypeAnnotation(id: Object, node: Object): Object {
var info = {
annotation: null,
inferred: false
@@ -328,7 +334,11 @@ export default class Scope {
return info;
}
toArray(node, i) {
/**
* Description
*/
toArray(node: Object, i?: number) {
var file = this.file;
if (t.isIdentifier(node) && this.isTypeGeneric(node.name, "Array")) {
@@ -354,11 +364,25 @@ export default class Scope {
return t.callExpression(file.addHelper(helperName), args);
}
clearOwnBinding(name) {
delete this.bindings[name];
/**
* Description
*/
refreshDeclaration(node: Object) {
if (t.isBlockScoped(node)) {
this.getBlockParent().registerDeclaration(node);
} else if (t.isVariableDeclaration(node, { kind: "var" })) {
this.getFunctionParent().registerDeclaration(node);
} else if (node === this.block) {
this.recrawl();
}
}
registerDeclaration(node) {
/**
* Description
*/
registerDeclaration(node: Object) {
if (t.isFunctionDeclaration(node)) {
this.registerBinding("hoisted", node);
} else if (t.isVariableDeclaration(node)) {
@@ -374,7 +398,11 @@ export default class Scope {
}
}
registerBindingReassignment(node) {
/**
* Description
*/
registerBindingReassignment(node: Object) {
var ids = t.getBindingIdentifiers(node);
for (var name in ids) {
var info = this.getBindingInfo(name);
@@ -389,7 +417,11 @@ export default class Scope {
}
}
registerBinding(kind, node) {
/**
* Description
*/
registerBinding(kind: string, node: Object) {
if (!kind) throw new ReferenceError("no `kind`");
var ids = t.getBindingIdentifiers(node);
@@ -399,7 +431,7 @@ export default class Scope {
this.checkBlockScopedCollisions(kind, name, id);
var typeInfo = this.getTypeAnnotation(name, id, node);
var typeInfo = this.getTypeAnnotation(id, node);
this.bindings[name] = {
typeAnnotationInferred: typeInfo.inferred,
@@ -413,18 +445,19 @@ export default class Scope {
}
}
registerVariableDeclaration(declar) {
var declars = declar.declarations;
for (var i = 0; i < declars.length; i++) {
this.registerBinding(declar.kind, declars[i]);
}
/**
* Description
*/
addGlobal(node: Object) {
this.globals[node.name] = node;
}
addGlobal(node) {
this.globals[node.name] = node;
};
/**
* Description
*/
hasGlobal(name) {
hasGlobal(name: string): boolean {
var scope = this;
do {
@@ -434,6 +467,19 @@ export default class Scope {
return false;
}
/**
* Description
*/
recrawl() {
this.block._scopeInfo = null;
this.crawl();
}
/**
* Description
*/
crawl() {
var block = this.block;
var i;
@@ -474,6 +520,12 @@ export default class Scope {
}
}
// Class
if (t.isClass(block) && block.id) {
this.registerBinding("var", block.id);
}
// Function - params, rest
if (t.isFunction(block)) {
@@ -519,11 +571,9 @@ export default class Scope {
/**
* Description
*
* @param {Object} opts
*/
push(opts) {
push(opts: Object) {
var block = this.block;
if (t.isLoop(block) || t.isCatchClause(block) || t.isFunction(block)) {
@@ -533,7 +583,7 @@ export default class Scope {
if (t.isBlockStatement(block) || t.isProgram(block)) {
block._declarations ||= {};
block._declarations[opts.key] = {
block._declarations[opts.key || opts.id.name] = {
kind: opts.kind || "var",
id: opts.id,
init: opts.init
@@ -557,12 +607,23 @@ export default class Scope {
}
/**
* Walks the scope tree and gathers **all** bindings.
*
* @returns {Object}
* Walk up the scope tree until we hit either a BlockStatement/Loop or reach the
* very top and hit Program.
*/
getAllBindings() {
getBlockParent() {
var scope = this;
while (scope.parent && !t.isFunction(scope.block) && !t.isLoop(scope.block) && !t.isFunction(scope.block)) {
scope = scope.parent;
}
return scope;
}
/**
* Walks the scope tree and gathers **all** bindings.
*/
getAllBindings(): Object {
var ids = object();
var scope = this;
@@ -576,12 +637,9 @@ export default class Scope {
/**
* Walks the scope tree and gathers all declarations of `kind`.
*
* @param {String} kind
* @returns {Object}
*/
getAllBindingsOfKind(kind) {
getAllBindingsOfKind(kind: string): Object {
var ids = object();
var scope = this;
@@ -596,15 +654,19 @@ export default class Scope {
return ids;
}
// misc
/**
* Description
*/
bindingIdentifierEquals(name, node) {
bindingIdentifierEquals(name: string, node: Object): boolean {
return this.getBindingIdentifier(name) === node;
}
// get
/**
* Description
*/
getBindingInfo(name) {
getBindingInfo(name: string) {
var scope = this;
do {
@@ -613,26 +675,45 @@ export default class Scope {
} while (scope = scope.parent);
}
getOwnBindingInfo(name) {
/**
* Description
*/
getOwnBindingInfo(name: string) {
return this.bindings[name];
}
getBindingIdentifier(name) {
/**
* Description
*/
getBindingIdentifier(name: string) {
var info = this.getBindingInfo(name);
return info && info.identifier;
}
getOwnBindingIdentifier(name) {
/**
* Description
*/
getOwnBindingIdentifier(name: string) {
var binding = this.bindings[name];
return binding && binding.identifier;
}
/**
* Description
*/
getOwnImmutableBindingValue(name) {
getOwnImmutableBindingValue(name: string) {
return this._immutableBindingInfoToValue(this.getOwnBindingInfo(name));
}
getImmutableBindingValue(name) {
/**
* Description
*/
getImmutableBindingValue(name: string) {
return this._immutableBindingInfoToValue(this.getBindingInfo(name));
}
@@ -658,13 +739,19 @@ export default class Scope {
}
}
// has
/**
* Description
*/
hasOwnBinding(name) {
hasOwnBinding(name: string) {
return !!this.getOwnBindingInfo(name);
}
hasBinding(name) {
/**
* Description
*/
hasBinding(name: string) {
if (!name) return false;
if (this.hasOwnBinding(name)) return true;
if (this.parentHasBinding(name)) return true;
@@ -673,7 +760,28 @@ export default class Scope {
return false;
}
parentHasBinding(name) {
/**
* Description
*/
parentHasBinding(name: string) {
return this.parent && this.parent.hasBinding(name);
}
/**
* Description
*/
removeOwnBinding(name: string) {
this.bindings[name] = null;
}
/**
* Description
*/
removeBinding(name: string) {
var info = this.getBindingInfo(name);
if (info) info.scope.removeOwnBinding(name);
}
}

View File

@@ -25,7 +25,7 @@
"ImportSpecifier": ["ModuleSpecifier"],
"ExportSpecifier": ["ModuleSpecifier"],
"BlockStatement": ["Statement", "Scopable"],
"BlockStatement": ["Scopable", "Statement"],
"Program": ["Scopable"],
"CatchClause": ["Scopable"],
@@ -36,8 +36,8 @@
"SpreadProperty": ["UnaryLike"],
"SpreadElement": ["UnaryLike"],
"ClassDeclaration": ["Statement", "Declaration", "Class"],
"ClassExpression": ["Class", "Expression"],
"ClassDeclaration": ["Scopable", "Class", "Statement", "Declaration"],
"ClassExpression": ["Scopable", "Class", "Expression"],
"ForOfStatement": ["Scopable", "Statement", "For", "Loop"],
"ForInStatement": ["Scopable", "Statement", "For", "Loop"],

View File

@@ -16,12 +16,9 @@ export default t;
/**
* Registers `is[Type]` and `assert[Type]` generated functions for a given `type`.
* Pass `skipAliasCheck` to force it to directly compare `node.type` with `type`.
*
* @param {String} type
* @param {Boolean?} skipAliasCheck
*/
function registerType(type, skipAliasCheck) {
function registerType(type: string, skipAliasCheck?: boolean) {
var is = t[`is${type}`] = function (node, opts) {
return t.is(type, node, opts, skipAliasCheck);
};
@@ -36,6 +33,7 @@ function registerType(type, skipAliasCheck) {
t.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
t.NATIVE_TYPE_NAMES = ["Array", "Object", "Number", "Boolean", "Date", "Array", "String"];
t.FLATTENABLE_KEYS = ["body", "expressions"];
t.FOR_INIT_KEYS = ["left", "init"];
t.VISITOR_KEYS = require("./visitor-keys");
@@ -66,15 +64,9 @@ t.TYPES = Object.keys(t.VISITOR_KEYS).concat(Object.keys(t.FLIPPED_ALIAS_KEYS));
*
* For better performance, use this instead of `is[Type]` when `type` is unknown.
* Optionally, pass `skipAliasCheck` to directly compare `node.type` with `type`.
*
* @param {String} type
* @param {Node} node
* @param {Object?} opts
* @param {Boolean?} skipAliasCheck
* @returns {Boolean} isOfType
*/
t.is = function (type, node, opts, skipAliasCheck) {
t.is = function (type: string, node: Object, opts?: Object, skipAliasCheck?: boolean): boolean {
if (!node) return false;
var typeMatches = type === node.type;
@@ -132,34 +124,15 @@ each(t.BUILDER_KEYS, function (keys, type) {
/**
* Description
*
* @param {Object} node
* @returns {Object}
*/
t.toComputedKey = function (node, key) {
t.toComputedKey = function (node: Object, key: Object): Object {
if (!node.computed) {
if (t.isIdentifier(key)) key = t.literal(key.name);
}
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`.
*
@@ -167,12 +140,9 @@ t.isFalsyExpression = function (node) {
* declarations hoisted to the top of the current scope.
*
* Expression statements are just resolved to their standard expression.
*
* @param {Array} nodes
* @param {Scope} scope
*/
t.toSequenceExpression = function (nodes, scope) {
t.toSequenceExpression = function (nodes: Array<Object>, scope: Scope): Object {
var exprs = [];
each(nodes, function (node) {
@@ -201,13 +171,9 @@ t.toSequenceExpression = function (nodes, scope) {
/*
* Description
*
* @param {Object} actual
* @param {Object} expected
* @returns {Boolean}
*/
t.shallowEqual = function (actual, expected) {
t.shallowEqual = function (actual: Object, expected: Object): boolean {
var keys = Object.keys(expected);
for (var i = 0; i < keys.length; i++) {
@@ -223,14 +189,9 @@ t.shallowEqual = function (actual, expected) {
/**
* Description
*
* @param {Object} member
* @param {Object} append
* @param {Boolean} [computed]
* @returns {Object} member
*/
t.appendToMemberExpression = function (member, append, computed) {
t.appendToMemberExpression = function (member: Object, append: Object, computed?: boolean): Object {
member.object = t.memberExpression(member.object, member.property, member.computed);
member.property = append;
member.computed = !!computed;
@@ -239,26 +200,18 @@ t.appendToMemberExpression = function (member, append, computed) {
/**
* Description
*
* @param {Object} member
* @param {Object} append
* @returns {Object} member
*/
t.prependToMemberExpression = function (member, append) {
t.prependToMemberExpression = function (member: Object, append: Object): Object {
member.object = t.memberExpression(append, member.object);
return member;
};
/**
* Check if the input `node` is a reference to a bound variable.
*
* @param {Object} node
* @param {Object} parent
* @returns {Boolean}
*/
t.isReferenced = function (node, parent) {
t.isReferenced = function (node: Object, parent: Object): boolean {
// yes: PARENT[NODE]
// yes: NODE.child
// no: parent.CHILD
@@ -362,36 +315,26 @@ t.isReferenced = function (node, parent) {
/**
* Check if the input `node` is an `Identifier` and `isReferenced`.
*
* @param {Node} node
* @parma {Node} parent
* @returns {Boolean}
*/
t.isReferencedIdentifier = function (node, parent, opts) {
t.isReferencedIdentifier = function (node: Object, parent: Object, opts?: Object): boolean {
return t.isIdentifier(node, opts) && t.isReferenced(node, parent);
};
/**
* Check if the input `name` is a valid identifier name
* and isn't a reserved word.
*
* @param {String} name
* @returns {Boolean}
*/
t.isValidIdentifier = function (name) {
t.isValidIdentifier = function (name: string): boolean {
return isString(name) && esutils.keyword.isIdentifierName(name) && !esutils.keyword.isReservedWordES6(name, true);
};
/*
* Description
*
* @param {String} name
* @returns {String}
*/
t.toIdentifier = function (name) {
t.toIdentifier = function (name: string): string {
if (t.isIdentifier(name)) return name.name;
name = name + "";
@@ -416,24 +359,17 @@ t.toIdentifier = function (name) {
/**
* Description
*
* @param {Object} node
* @param {String=} key
*/
t.ensureBlock = function (node, key) {
key ||= "body";
t.ensureBlock = function (node: Object, key: string = "body") {
return node[key] = t.toBlock(node[key], node);
};
/**
* Description
*
* @param {Object} node
* @returns {Object}
*/
t.clone = function (node) {
t.clone = function (node: Object): Object {
var newNode = {};
for (var key in node) {
if (key[0] === "_") continue;
@@ -444,15 +380,14 @@ t.clone = function (node) {
/**
* Description
*
* @param {Object} node
* @returns {Object}
*/
t.cloneDeep = function (node) {
t.cloneDeep = function (node: Object): Object {
var newNode = {};
for (var key in node) {
if (key[0] === "_") continue;
var val = node[key];
if (val) {
@@ -475,13 +410,9 @@ t.cloneDeep = function (node) {
*
* For example, given the match `React.createClass` it would match the
* parsed nodes of `React.createClass` and `React["createClass"]`.
*
* @param {String} match Dot-delimited string
* @param {Boolean} [allowPartial] Allow a partial match
* @returns {Function}
*/
t.buildMatchMemberExpression = function (match, allowPartial) {
t.buildMatchMemberExpression = function (match:string, allowPartial?: boolean): Function {
var parts = match.split(".");
return function (member) {
@@ -531,12 +462,10 @@ t.buildMatchMemberExpression = function (match, allowPartial) {
/**
* Description
*
* @param {Object} node
* @param {Boolean} [ignore]
* @returns {Object|Boolean}
*/
t.toStatement = function (node, ignore) {
t.toStatement = function (node: Object, ignore?: boolean) {
if (t.isStatement(node)) {
return node;
}
@@ -573,12 +502,9 @@ t.toStatement = function (node, ignore) {
/**
* Description
*
* @param {Object} node
* @returns {Object}
*/
t.toExpression = function (node) {
t.toExpression = function (node: Object): Object {
if (t.isExpressionStatement(node)) {
node = node.expression;
}
@@ -598,13 +524,9 @@ t.toExpression = function (node) {
/**
* Description
*
* @param {Object} node
* @param {Object} parent
* @returns {Object}
*/
t.toBlock = function (node, parent) {
t.toBlock = function (node: Object, parent: Object): Object {
if (t.isBlockStatement(node)) {
return node;
}
@@ -631,12 +553,9 @@ t.toBlock = function (node, parent) {
/**
* Return a list of binding identifiers associated with
* the input `node`.
*
* @param {Object} node
* @returns {Array|Object}
*/
t.getBindingIdentifiers = function (node) {
t.getBindingIdentifiers = function (node: Object): Object {
var search = [].concat(node);
var ids = object();
@@ -671,7 +590,9 @@ t.getBindingIdentifiers.keys = {
ImportBatchSpecifier: ["name"],
VariableDeclarator: ["id"],
FunctionDeclaration: ["id"],
FunctionExpression: ["id"],
ClassDeclaration: ["id"],
ClassExpression: ["id"],
SpreadElement: ["argument"],
RestElement: ["argument"],
UpdateExpression: ["argument"],
@@ -689,34 +610,25 @@ t.getBindingIdentifiers.keys = {
/**
* Description
*
* @param {Object} node
* @returns {Boolean}
*/
t.isLet = function (node) {
t.isLet = function (node: Object): boolean {
return t.isVariableDeclaration(node) && (node.kind !== "var" || node._let);
};
/**
* Description
*
* @param {Object} node
* @returns {Boolean}
*/
t.isBlockScoped = function (node) {
t.isBlockScoped = function (node: Object): boolean {
return t.isFunctionDeclaration(node) || t.isClassDeclaration(node) || t.isLet(node);
};
/**
* Description
*
* @param {Object} node
* @returns {Boolean}
*/
t.isVar = function (node) {
t.isVar = function (node: Object): boolean {
return t.isVariableDeclaration(node, { kind: "var" }) && !node._let;
};
@@ -726,12 +638,9 @@ t.COMMENT_KEYS = ["leadingComments", "trailingComments"];
/**
* Description
*
* @param {Object} child
* @returns {Object} child
*/
t.removeComments = function (child) {
t.removeComments = function (child: Object): Object {
each(t.COMMENT_KEYS, function (key) {
delete child[key];
});
@@ -740,13 +649,9 @@ t.removeComments = function (child) {
/**
* Description
*
* @param {Object} child
* @param {Object} parent
* @returns {Object} child
*/
t.inheritsComments = function (child, parent) {
t.inheritsComments = function (child: Object, parent: Object): Object {
each(t.COMMENT_KEYS, function (key) {
child[key] = uniq(compact([].concat(child[key], parent[key])));
});
@@ -755,13 +660,9 @@ t.inheritsComments = function (child, parent) {
/**
* Description
*
* @param {Object} child
* @param {Object} parent
* @returns {Object} child
*/
t.inherits = function (child, parent) {
t.inherits = function (child: Object, parent: Object): Object {
child._declarations = parent._declarations;
child._scopeInfo = parent._scopeInfo;
child.range = parent.range;
@@ -778,12 +679,9 @@ t.inherits = function (child, parent) {
/**
* Description
*
* @param {Object} node
* @returns {Array}
*/
t.getLastStatements = function (node) {
t.getLastStatements = function (node: Object): Array<Object> {
var nodes = [];
var add = function (node) {
@@ -806,23 +704,17 @@ t.getLastStatements = function (node) {
/**
* Description
*
* @param {Object} specifier
* @returns {String}
*/
t.getSpecifierName = function (specifier) {
t.getSpecifierName = function (specifier: Object): Object {
return specifier.name || specifier.id;
};
/**
* Description
*
* @param {Object} specifier
* @returns {String}
*/
t.getSpecifierId = function (specifier) {
t.getSpecifierId = function (specifier: Object): Object {
if (specifier.default) {
return t.identifier("default");
} else {
@@ -832,24 +724,17 @@ t.getSpecifierId = function (specifier) {
/**
* Description
*
* @param {Object} specifier
* @returns {Boolean}
*/
t.isSpecifierDefault = function (specifier) {
t.isSpecifierDefault = function (specifier: Object): boolean {
return specifier.default || t.isIdentifier(specifier.id) && specifier.id.name === "default";
};
/**
* Description
*
* @param {Node} node
* @param {Node} parent
* @returns {Boolean}
*/
t.isScope = function (node, parent) {
t.isScope = function (node: Object, parent: Object): boolean {
if (t.isBlockStatement(node)) {
if (t.isLoop(parent.block, { body: node })) {
return false;
@@ -865,12 +750,9 @@ t.isScope = function (node, parent) {
/**
* Description
*
* @param {Node} node
* @returns {Boolean}
*/
t.isImmutable = function (node) {
t.isImmutable = function (node: Object): boolean {
if (t.isLiteral(node)) {
if (node.regex) {
// regexes are mutable
@@ -908,12 +790,9 @@ t.isImmutable = function (node) {
*
* if (!t.evaluateTruthy(node)) falsyLogic();
*
* @param {Node} node
* @param {Scope} scope
* @returns {Boolean}
*/
t.evaluateTruthy = function (node, scope) {
t.evaluateTruthy = function (node: Object, scope: Scope): boolean {
var res = t.evaluate(node, scope);
if (res.confident) return !!res.value;
};
@@ -931,12 +810,9 @@ t.evaluateTruthy = function (node, scope) {
* t.evaluate(parse("!true")) // { confident: true, value: false }
* t.evaluate(parse("foo + foo")) // { confident: false, value: undefined }
*
* @param {Node} node
* @param {Scope} scope
* @returns {Object}
*/
t.evaluate = function (node, scope) {
t.evaluate = function (node: Object, scope: Scope): { confident: boolean; value: any } {
var confident = true;
var value = evaluate(node);
@@ -1028,12 +904,9 @@ t.evaluate = function (node, scope) {
/**
* Description
*
* @param value
* @returns {Node}
*/
t.valueToNode = function (value) {
t.valueToNode = function (value: any): Object {
if (value === undefined) {
return t.identifier("undefined");
}

View File

@@ -20,7 +20,7 @@ export { inherits, inspect } from "util";
export var debug = buildDebug("babel");
export function canCompile(filename, altExts) {
export function canCompile(filename: string, altExts?: Array<string>) {
var exts = altExts || canCompile.EXTENSIONS;
var ext = path.extname(filename);
return contains(exts, ext);
@@ -28,7 +28,7 @@ export function canCompile(filename, altExts) {
canCompile.EXTENSIONS = [".js", ".jsx", ".es6", ".es"];
export function resolve(loc) {
export function resolve(loc: string) {
try {
return require.resolve(loc);
} catch (err) {
@@ -36,11 +36,11 @@ export function resolve(loc) {
}
}
export function list(val) {
export function list(val: string): Array<string> {
return val ? val.split(",") : [];
}
export function regexify(val) {
export function regexify(val: any): RegExp {
if (!val) return new RegExp(/.^/);
if (Array.isArray(val)) val = val.join("|");
if (isString(val)) return new RegExp(val);
@@ -48,7 +48,7 @@ export function regexify(val) {
throw new TypeError("illegal type for regexify");
}
export function arrayify(val) {
export function arrayify(val: any): Array {
if (!val) return [];
if (isBoolean(val)) return [val];
if (isString(val)) return list(val);
@@ -56,7 +56,7 @@ export function arrayify(val) {
throw new TypeError("illegal type for arrayify");
}
export function booleanify(val) {
export function booleanify(val: any): boolean {
if (val === "true") return true;
if (val === "false") return false;
return val;
@@ -76,7 +76,7 @@ var templateVisitor = {
//
export function template(name, nodes, keepExpression) {
export function template(name: string, nodes?: Array<Object>, keepExpression?: boolean): Object {
var ast = exports.templates[name];
if (!ast) throw new ReferenceError(`unknown template ${name}`);
@@ -102,7 +102,7 @@ export function template(name, nodes, keepExpression) {
}
}
export function parseTemplate(loc, code) {
export function parseTemplate(loc: string, code: string): Object {
var ast = parse({ filename: loc }, code).program;
ast = traverse.removeProperties(ast);
return ast;

View File

@@ -86,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);

View File

@@ -0,0 +1,3 @@
{
"args": ["--whitelist", "nonexistent"]
}

View File

@@ -0,0 +1,3 @@
(function (global) {
var babelHelpers = global.babelHelpers = {};
})(typeof global === "undefined" ? self : global);

View File

@@ -0,0 +1,3 @@
{
"args": ["--whitelist", "nonexistent", "--output-type", "umd"]
}

View 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;
})

View File

@@ -0,0 +1,3 @@
{
"args": ["--whitelist", "nenexistent", "--output-type", "var"]
}

View File

@@ -0,0 +1 @@
var babelHelpers = {};

View File

@@ -0,0 +1,3 @@
{
"args": ["--whitelist", "slice,has-own"]
}

View 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);

View File

@@ -0,0 +1,5 @@
var foo = async function bar() {
console.log(bar);
};
foo();

View File

@@ -0,0 +1,9 @@
"use strict";
var _bar;
var foo = _bar = babelHelpers.asyncToGenerator(function* () {
console.log(_bar);
});
foo();

View File

@@ -0,0 +1,5 @@
var foo = async function bar() {
console.log(bar);
};
foo();

View File

@@ -0,0 +1,11 @@
"use strict";
var _bluebird = require("bluebird");
var _bar;
var foo = _bar = _bluebird.coroutine(function* () {
console.log(_bar);
});
foo();

View File

@@ -0,0 +1,2 @@
a;
export const a = 1;

View File

@@ -0,0 +1,2 @@
export const a = 1;
a;

View File

@@ -0,0 +1,22 @@
class MyCtrl {
constructor(a) {
"any directive prologue";
foo;
}
}
class MyCtrl2 {
constructor(a) {
"a";
"b";
foo;
}
}
class MyCtrl3 {
constructor(a) {
"a";
foo;
"b";
}
}

View File

@@ -0,0 +1,21 @@
"use strict";
var MyCtrl = function MyCtrl(a) {
"any directive prologue";
babelHelpers.classCallCheck(this, MyCtrl);
foo;
};
var MyCtrl2 = function MyCtrl2(a) {
"a";
"b";
babelHelpers.classCallCheck(this, MyCtrl2);
foo;
};
var MyCtrl3 = function MyCtrl3(a) {
"a";
babelHelpers.classCallCheck(this, MyCtrl3);
foo;
"b";
};

View File

@@ -0,0 +1,6 @@
for (var i of foo) {
switch (i) {
case 1:
break;
}
}

View File

@@ -0,0 +1,21 @@
"use strict";
for (var _iterator = foo, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var i = _ref;
switch (i) {
case 1:
break;
}
}

View File

@@ -0,0 +1,6 @@
for (var i of foo) {
switch (i) {
case 1:
break;
}
}

View File

@@ -0,0 +1,29 @@
"use strict";
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = foo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var i = _step.value;
switch (i) {
case 1:
break;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"]) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

View File

@@ -4,14 +4,22 @@ define(["exports"], function (exports) {
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
exports.foo7 = foo7;
var foo = exports.foo = 1;
var foo = exports.foo = 1;
var bar = exports.bar = 2;
var foo2 = exports.foo2 = function foo2() {};
var foo3 = exports.foo3 = undefined;
var foo4 = exports.foo4 = 2;
var foo5 = exports.foo5 = undefined;
var foo6 = exports.foo6 = 3;
var foo = 1;
exports.foo = foo;
var foo = 1,
bar = 2;
exports.foo = foo;
exports.bar = bar;
var foo2 = function foo2() {};
exports.foo2 = foo2;
var foo3;
exports.foo3 = foo3;
var foo4 = 2;
exports.foo4 = foo4;
var foo5 = undefined;
exports.foo5 = foo5;
var foo6 = 3;
exports.foo6 = foo6;
function foo7() {}

View File

@@ -8,11 +8,12 @@ define(["exports", "./evens"], function (exports, _evens) {
return isEven(n) ? n + 1 : n + 2;
}
var isOdd = exports.isOdd = (function (isEven) {
var isOdd = (function (isEven) {
return function (n) {
return !isEven(n);
};
})(isEven);
exports.isOdd = isOdd;
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -9,8 +9,9 @@ define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports,
var bar = _foo.bar;
var bar2 = _foo.foo;
exports.test = test;
var test2 = exports.test2 = 5;
var test2 = 5;
exports.test2 = test2;
exports["default"] = test;
Object.defineProperty(exports, "__esModule", {
value: true

View File

@@ -1,7 +1,8 @@
define(["exports"], function (exports) {
"use strict";
var test = exports.test = 2;
var test = 2;
exports.test = test;
test = exports.test = 5;
test = exports.test += 1;

View File

@@ -3,14 +3,22 @@
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
exports.foo7 = foo7;
var foo = exports.foo = 1;
var foo = exports.foo = 1;
var bar = exports.bar = 2;
var foo2 = exports.foo2 = function foo2() {};
var foo3 = exports.foo3 = undefined;
var foo4 = exports.foo4 = 2;
var foo5 = exports.foo5 = undefined;
var foo6 = exports.foo6 = 3;
var foo = 1;
exports.foo = foo;
var foo = 1,
bar = 2;
exports.foo = foo;
exports.bar = bar;
var foo2 = function foo2() {};
exports.foo2 = foo2;
var foo3;
exports.foo3 = foo3;
var foo4 = 2;
exports.foo4 = foo4;
var foo5 = undefined;
exports.foo5 = foo5;
var foo6 = 3;
exports.foo6 = foo6;
function foo7() {}

View File

@@ -8,11 +8,12 @@ function nextOdd(n) {
return isEven(n) ? n + 1 : n + 2;
}
var isOdd = exports.isOdd = (function (isEven) {
var isOdd = (function (isEven) {
return function (n) {
return !isEven(n);
};
})(isEven);
exports.isOdd = isOdd;
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -1,4 +1,5 @@
"use strict";
var foo = exports.foo = 5;
exports.__esModule = true;
var foo = 5;
exports.foo = foo;
exports.__esModule = true;

View File

@@ -19,7 +19,8 @@ var bar = require("foo4").bar;
var bar2 = require("foo5").foo;
exports.test = test;
var test = exports.test = 5;
var test = 5;
exports.test = test;
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -1,6 +1,7 @@
"use strict";
var test = exports.test = 2;
var test = 2;
exports.test = test;
test = exports.test = 5;
test = exports.test += 1;

View File

@@ -6,7 +6,7 @@ var foo = 1;
var foo = 1,
bar = 2;
var foo2 = function foo2() {};
var foo3 = undefined;
var foo3;
var foo4 = 2;
var foo5 = undefined;
var foo6 = 3;

View File

@@ -12,12 +12,28 @@ System.register([], function (_export) {
_classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
foo = _export("foo", 1);
foo2 = _export("foo2", function foo2() {});
foo3 = _export("foo3", undefined);
foo4 = _export("foo4", 2);
foo5 = _export("foo5", undefined);
foo6 = _export("foo6", 3);
foo = 1;
_export("foo", foo);
foo2 = function foo2() {};
_export("foo2", foo2);
_export("foo3", foo3);
foo4 = 2;
_export("foo4", foo4);
foo5 = undefined;
_export("foo5", foo5);
foo6 = 3;
_export("foo6", foo6);
foo8 = _export("foo8", function foo8() {
_classCallCheck(this, foo8);
});

View File

@@ -14,12 +14,17 @@ System.register(["./evens"], function (_export) {
execute: function () {
"use strict";
p = _export("p", 5);
isOdd = _export("isOdd", (function (isEven) {
p = 5;
_export("p", p);
isOdd = (function (isEven) {
return function (n) {
return !isEven(n);
};
})(isEven));
})(isEven);
_export("isOdd", isOdd);
}
};
});

View File

@@ -12,7 +12,9 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
_export("test", test);
test2 = _export("test2", 5);
test2 = 5;
_export("test2", test2);
_export("default", test);
}

View File

@@ -5,7 +5,9 @@ System.register([], function (_export) {
execute: function () {
"use strict";
test = _export("test", 2);
test = 2;
_export("test", test);
_export("test", test = 5);
_export("test", test += 1);

View File

@@ -10,14 +10,22 @@
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
exports.foo7 = foo7;
var foo = exports.foo = 1;
var foo = exports.foo = 1;
var bar = exports.bar = 2;
var foo2 = exports.foo2 = function foo2() {};
var foo3 = exports.foo3 = undefined;
var foo4 = exports.foo4 = 2;
var foo5 = exports.foo5 = undefined;
var foo6 = exports.foo6 = 3;
var foo = 1;
exports.foo = foo;
var foo = 1,
bar = 2;
exports.foo = foo;
exports.bar = bar;
var foo2 = function foo2() {};
exports.foo2 = foo2;
var foo3;
exports.foo3 = foo3;
var foo4 = 2;
exports.foo4 = foo4;
var foo5 = undefined;
exports.foo5 = foo5;
var foo6 = 3;
exports.foo6 = foo6;
function foo7() {}

View File

@@ -14,11 +14,12 @@
return isEven(n) ? n + 1 : n + 2;
}
var isOdd = exports.isOdd = (function (isEven) {
var isOdd = (function (isEven) {
return function (n) {
return !isEven(n);
};
})(isEven);
exports.isOdd = isOdd;
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -15,8 +15,9 @@
var bar = _foo.bar;
var bar2 = _foo.foo;
exports.test = test;
var test2 = exports.test2 = 5;
var test2 = 5;
exports.test2 = test2;
exports["default"] = test;
Object.defineProperty(exports, "__esModule", {
value: true

View File

@@ -7,7 +7,8 @@
})(function (exports) {
"use strict";
var test = exports.test = 2;
var test = 2;
exports.test = test;
test = exports.test = 5;
test = exports.test += 1;

View File

@@ -0,0 +1,3 @@
{
"optional": ["es6.symbols"]
}

View File

@@ -4,7 +4,9 @@ var _core = require("babel-runtime/core-js")["default"];
var _regeneratorRuntime = require("babel-runtime/regenerator")["default"];
var _babelHelpers = require("babel-runtime/helpers")["default"];
var _interopRequire = require("babel-runtime/helpers/interop-require")["default"];
var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"];
var giveWord = _regeneratorRuntime.mark(function giveWord() {
return _regeneratorRuntime.wrap(function giveWord$(context$1$0) {
@@ -24,11 +26,12 @@ exports.giveWord = giveWord;
var _someModule = require("someModule");
var foo = _babelHelpers.interopRequire(_someModule);
var foo = _interopRequire(_someModule);
var bar = _babelHelpers.interopRequireWildcard(_someModule);
var bar = _interopRequireWildcard(_someModule);
var myWord = exports.myWord = _core.Symbol("abc");
var myWord = _core.Symbol("abc");
exports.myWord = myWord;
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -1,7 +1,7 @@
define(["exports", "foo", "babel-runtime/helpers"], function (exports, _foo, _babelRuntimeHelpers) {
define(["exports", "foo", "babel-runtime/helpers/interop-require"], function (exports, _foo, _babelRuntimeHelpersInteropRequire) {
"use strict";
var _babelHelpers = _babelRuntimeHelpers["default"];
var _interopRequire = _babelRuntimeHelpersInteropRequire["default"];
var foo = _babelHelpers.interopRequire(_foo);
var foo = _interopRequire(_foo);
});

View File

@@ -1,5 +1,5 @@
"use strict";
var _babelHelpers = require("babel-runtime/helpers")["default"];
var _interopRequire = require("babel-runtime/helpers/interop-require")["default"];
var foo = _babelHelpers.interopRequire(require("foo"));
var foo = _interopRequire(require("foo"));

View File

@@ -1,14 +1,14 @@
System.register(["babel-runtime/helpers"], function (_export) {
var _babelHelpers;
System.register(["babel-runtime/helpers/to-consumable-array"], function (_export) {
var _toConsumableArray;
return {
setters: [function (_babelRuntimeHelpers) {
_babelHelpers = _babelRuntimeHelpers["default"];
setters: [function (_babelRuntimeHelpersToConsumableArray) {
_toConsumableArray = _babelRuntimeHelpersToConsumableArray["default"];
}],
execute: function () {
"use strict";
foo.apply(undefined, _babelHelpers.toConsumableArray(bar));
foo.apply(undefined, _toConsumableArray(bar));
}
};
});

Some files were not shown because too many files have changed in this diff Show More