Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c79290bb2 | ||
|
|
cfdf6b7385 | ||
|
|
907e0e0f86 | ||
|
|
f3bd9cbcb8 | ||
|
|
3bd14f9e07 | ||
|
|
102b4b3d1e | ||
|
|
6564f1ff76 | ||
|
|
58d7a5e069 | ||
|
|
f5db53cebe | ||
|
|
2da010fcae | ||
|
|
52b99bdf93 | ||
|
|
9d7e953451 | ||
|
|
b1252b865b | ||
|
|
068b1341d9 | ||
|
|
20eb143915 | ||
|
|
1302a86bf2 | ||
|
|
b7831f1d7b | ||
|
|
e46cabb21f | ||
|
|
fff06a047e | ||
|
|
6b0320fc83 | ||
|
|
5dde63fa0a | ||
|
|
672118149a | ||
|
|
5e0236d9a7 | ||
|
|
5101664e7d | ||
|
|
2d684a06d3 | ||
|
|
e31bad8f42 | ||
|
|
644b4373fc | ||
|
|
62f37c1e62 | ||
|
|
fc0e89463b | ||
|
|
56b6a795a4 | ||
|
|
17b34a2959 | ||
|
|
c4da0253c5 | ||
|
|
5f2df40f6d | ||
|
|
7d20a9b882 | ||
|
|
ee0ac9f149 | ||
|
|
c5d3f42d8a | ||
|
|
d162919a53 | ||
|
|
d1f712344d | ||
|
|
e985912b54 | ||
|
|
97a21e4a34 | ||
|
|
d8fb7812f7 | ||
|
|
bfe63f5885 | ||
|
|
44ca6873a3 | ||
|
|
2f66ea7338 |
@@ -1,7 +1,6 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
|
||||
|
||||
16
CHANGELOG.md
16
CHANGELOG.md
@@ -13,6 +13,22 @@ _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.5
|
||||
|
||||
* **Bug Fix**
|
||||
* Don't remap` break`s to call the iterator return.
|
||||
* **Polish**
|
||||
* Use a different helper for computed classes for much nicer output. Also fixes a bug in symbols being non-enumerable so they wouldn't be set on the class.
|
||||
|
||||
## 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**
|
||||
|
||||
18
Makefile
18
Makefile
@@ -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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "4.7.3",
|
||||
"version": "4.7.5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "4.7.2",
|
||||
"version": "4.7.4",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
"core-js": "^0.6.1"
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ var compile = function (filename) {
|
||||
var opts = extend({}, transformOpts);
|
||||
resolveRc(filename, opts);
|
||||
|
||||
var cacheKey = `${filename}:${JSON.stringify(opts)}`;
|
||||
var cacheKey = `${filename}:${JSON.stringify(opts)}:${babel.version}`;
|
||||
|
||||
if (cache) {
|
||||
var cached = cache[cacheKey];
|
||||
|
||||
@@ -40,7 +40,15 @@ export default function (opts, code, callback) {
|
||||
message += frame;
|
||||
}
|
||||
|
||||
if (err.stack) err.stack = err.stack.replace(err.message, message);
|
||||
if (err.stack) {
|
||||
var newStack = err.stack.replace(err.message, message);
|
||||
try {
|
||||
err.stack = newStack;
|
||||
} catch (e) {
|
||||
// `err.stack` may be a readonly property in some environments
|
||||
}
|
||||
}
|
||||
|
||||
err.message = message;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,10 @@ export var messages = {
|
||||
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) {
|
||||
@@ -39,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();
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -50,6 +50,7 @@ export default class File {
|
||||
"inherits",
|
||||
"defaults",
|
||||
"create-class",
|
||||
"create-computed-class",
|
||||
"apply-constructor",
|
||||
"tagged-template-literal",
|
||||
"tagged-template-literal-loose",
|
||||
@@ -121,7 +122,7 @@ export default class File {
|
||||
"accept"
|
||||
];
|
||||
|
||||
normalizeOptions(opts) {
|
||||
normalizeOptions(opts: Object) {
|
||||
opts = assign({}, opts);
|
||||
|
||||
for (var key in opts) {
|
||||
@@ -227,7 +228,7 @@ export default class File {
|
||||
return opts;
|
||||
};
|
||||
|
||||
isLoose(key) {
|
||||
isLoose(key: string) {
|
||||
return includes(this.opts.loose, key);
|
||||
}
|
||||
|
||||
@@ -259,13 +260,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,7 +281,7 @@ export default class File {
|
||||
return new ModuleFormatter(this);
|
||||
}
|
||||
|
||||
parseInputSourceMap(code) {
|
||||
parseInputSourceMap(code: string) {
|
||||
var opts = this.opts;
|
||||
|
||||
var inputMap = convertSourceMap.fromSource(code);
|
||||
@@ -292,7 +293,7 @@ export default class File {
|
||||
return code;
|
||||
}
|
||||
|
||||
parseShebang(code) {
|
||||
parseShebang(code: string) {
|
||||
var shebangMatch = shebangRegex.exec(code);
|
||||
|
||||
if (shebangMatch) {
|
||||
@@ -305,15 +306,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 +326,7 @@ export default class File {
|
||||
}
|
||||
}
|
||||
|
||||
addImport(source, name, noDefault) {
|
||||
addImport(source: string, name?: string, noDefault?: boolean): Object {
|
||||
name ||= source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
@@ -349,11 +350,11 @@ export default class File {
|
||||
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 ||= [];
|
||||
@@ -365,7 +366,7 @@ export default class File {
|
||||
return node;
|
||||
}
|
||||
|
||||
addHelper(name) {
|
||||
addHelper(name: string): Object {
|
||||
if (!includes(File.helpers, name)) {
|
||||
throw new ReferenceError(`Unknown helper ${name}`);
|
||||
}
|
||||
@@ -408,14 +409,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;
|
||||
@@ -452,7 +453,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;
|
||||
@@ -480,7 +481,7 @@ export default class File {
|
||||
});
|
||||
}
|
||||
|
||||
mergeSourceMap(map) {
|
||||
mergeSourceMap(map: Object) {
|
||||
var opts = this.opts;
|
||||
|
||||
var inputMap = opts.inputSourceMap;
|
||||
@@ -502,7 +503,11 @@ export default class File {
|
||||
return map;
|
||||
}
|
||||
|
||||
generate() {
|
||||
generate(): {
|
||||
code: string;
|
||||
map?: Object;
|
||||
ast?: Object;
|
||||
} {
|
||||
var opts = this.opts;
|
||||
var ast = this.ast;
|
||||
|
||||
|
||||
@@ -5,33 +5,40 @@ import has from "lodash/object/has";
|
||||
import t from "../../types";
|
||||
|
||||
export function push(mutatorMap, key, kind, computed, value) {
|
||||
var alias;
|
||||
var alias = t.toKeyAlias({ computed }, key);
|
||||
|
||||
if (t.isIdentifier(key)) {
|
||||
alias = key.name;
|
||||
if (computed) alias = `computed:${alias}`;
|
||||
} else if (t.isLiteral(key)) {
|
||||
alias = String(key.value);
|
||||
} else {
|
||||
alias = JSON.stringify(traverse.removeProperties(t.cloneDeep(key)));
|
||||
}
|
||||
|
||||
var map;
|
||||
if (has(mutatorMap, alias)) {
|
||||
map = mutatorMap[alias];
|
||||
} else {
|
||||
map = {};
|
||||
}
|
||||
var map = {};
|
||||
if (has(mutatorMap, alias)) map = mutatorMap[alias];
|
||||
mutatorMap[alias] = map;
|
||||
|
||||
map._key = key;
|
||||
if (computed) {
|
||||
map._computed = true;
|
||||
}
|
||||
if (computed) map._computed = true;
|
||||
|
||||
map[kind] = value;
|
||||
}
|
||||
|
||||
export function hasComputed(mutatorMap) {
|
||||
for (var key in mutatorMap) {
|
||||
if (mutatorMap[key]._computed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function toComputedObjectFromClass(obj) {
|
||||
var objExpr = t.arrayExpression([]);
|
||||
|
||||
for (var i = 0; i < obj.properties.length; i++) {
|
||||
var prop = obj.properties[i];
|
||||
var val = prop.value;
|
||||
val.properties.unshift(t.property("init", t.identifier("key"), t.toComputedKey(prop)));
|
||||
objExpr.elements.push(val);
|
||||
}
|
||||
|
||||
return objExpr;
|
||||
}
|
||||
|
||||
export function toClassObject(mutatorMap) {
|
||||
var objExpr = t.objectExpression([]);
|
||||
|
||||
@@ -49,6 +56,7 @@ export function toClassObject(mutatorMap) {
|
||||
var prop = t.property("init", t.identifier(key), node);
|
||||
t.inheritsComments(prop, inheritNode);
|
||||
t.removeComments(inheritNode);
|
||||
|
||||
mapNode.properties.push(prop);
|
||||
});
|
||||
|
||||
@@ -59,35 +67,11 @@ export function toClassObject(mutatorMap) {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
return toClassObject(mutatorMap);
|
||||
}
|
||||
|
||||
@@ -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 = {
|
||||
}
|
||||
};
|
||||
|
||||
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 @@ export default 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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
18
src/babel/transformation/templates/create-computed-class.js
Normal file
18
src/babel/transformation/templates/create-computed-class.js
Normal file
@@ -0,0 +1,18 @@
|
||||
(function() {
|
||||
function defineProperties(target, rawProps) {
|
||||
var props = {};
|
||||
for (var i = 0; i < rawProps.length; i ++) {
|
||||
var prop = rawProps[i];
|
||||
prop.configurable = true;
|
||||
if (prop.value) prop.writable = true;
|
||||
props[prop.key] = prop;
|
||||
}
|
||||
Object.defineProperties(target, props);
|
||||
}
|
||||
|
||||
return function (Constructor, protoProps, staticProps) {
|
||||
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
};
|
||||
})()
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"selfContained": "runtime",
|
||||
"unicode-regex": "regex.unicode",
|
||||
"spec.typeofSymbol": "es6.symbols",
|
||||
|
||||
"minification.deadCodeElimination": "utility.deadCodeElimination",
|
||||
"minification.removeConsoleCalls": "utility.removeConsole",
|
||||
|
||||
@@ -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", [
|
||||
|
||||
@@ -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;
|
||||
@@ -222,6 +217,7 @@ class ClassTransformer {
|
||||
|
||||
var instanceProps;
|
||||
var staticProps;
|
||||
var classHelper = "create-class";
|
||||
|
||||
if (this.hasInstanceMutators) {
|
||||
instanceProps = defineMap.toClassObject(this.instanceMutatorMap);
|
||||
@@ -232,24 +228,28 @@ class ClassTransformer {
|
||||
}
|
||||
|
||||
if (instanceProps || staticProps) {
|
||||
if (defineMap.hasComputed(this.instanceMutatorMap) || defineMap.hasComputed(this.staticMutatorMap)) {
|
||||
if (instanceProps) instanceProps = defineMap.toComputedObjectFromClass(instanceProps);
|
||||
if (staticProps) staticProps = defineMap.toComputedObjectFromClass(staticProps);
|
||||
classHelper = "create-computed-class";
|
||||
}
|
||||
|
||||
instanceProps ||= t.literal(null);
|
||||
|
||||
var args = [this.classRef, instanceProps];
|
||||
if (staticProps) args.push(staticProps);
|
||||
|
||||
body.push(t.expressionStatement(
|
||||
t.callExpression(this.file.addHelper("create-class"), args)
|
||||
t.callExpression(this.file.addHelper(classHelper), args)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
verifyConstructor(node) {
|
||||
verifyConstructor(node: Object) {
|
||||
return; // enable this for the next major
|
||||
|
||||
var state = {
|
||||
@@ -267,11 +267,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 +306,9 @@ class ClassTransformer {
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Node} node
|
||||
*/
|
||||
|
||||
pushProperty(node) {
|
||||
pushProperty(node: Object) {
|
||||
if (!node.value) return;
|
||||
|
||||
var key;
|
||||
@@ -332,11 +328,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"));
|
||||
}
|
||||
|
||||
@@ -135,10 +135,7 @@ export function AssignmentExpression(node, parent, scope, file) {
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
var ref = scope.generateUidIdentifier("temp");
|
||||
scope.push({
|
||||
key: ref.name,
|
||||
id: ref
|
||||
});
|
||||
scope.push({ id: ref });
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(t.assignmentExpression("=", ref, node.right));
|
||||
|
||||
@@ -39,33 +39,6 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
}
|
||||
}
|
||||
|
||||
var breakVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isLoop()) {
|
||||
state.ignoreLabeless = true;
|
||||
scope.traverse(node, breakVisitor, state);
|
||||
state.ignoreLabeless = false;
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
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")), [])
|
||||
);
|
||||
ret = state.wrapReturn(ret);
|
||||
|
||||
this.skip();
|
||||
return [ret, node];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var loose = function (node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
var declar, id;
|
||||
@@ -102,23 +75,6 @@ var loose = function (node, parent, scope, file) {
|
||||
|
||||
//
|
||||
|
||||
scope.traverse(node, breakVisitor, {
|
||||
iteratorKey: iteratorKey,
|
||||
label: t.isLabeledStatement(parent) && parent.label.name,
|
||||
|
||||
wrapReturn(node) {
|
||||
return t.ifStatement(
|
||||
t.logicalExpression(
|
||||
"&&",
|
||||
t.unaryExpression("!", isArrayKey, true),
|
||||
t.memberExpression(iteratorKey, t.identifier("return")
|
||||
)
|
||||
), node);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
return {
|
||||
declar: declar,
|
||||
node: loop,
|
||||
@@ -170,17 +126,6 @@ var spec = function (node, parent, scope, file) {
|
||||
|
||||
//
|
||||
|
||||
scope.traverse(node, breakVisitor, {
|
||||
iteratorKey: iteratorKey,
|
||||
label: isLabeledParent && parent.label.name,
|
||||
|
||||
wrapReturn(node) {
|
||||
return t.ifStatement(t.memberExpression(iteratorKey, t.identifier("return")), node);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
return {
|
||||
replaceParent: isLabeledParent,
|
||||
declar: declar,
|
||||
|
||||
@@ -40,10 +40,7 @@ export function ObjectExpression(node, parent, scope, file) {
|
||||
}
|
||||
|
||||
if (objectRef) {
|
||||
scope.push({
|
||||
id: objectRef
|
||||
});
|
||||
|
||||
scope.push({ id: objectRef });
|
||||
return t.assignmentExpression("=", objectRef, node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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,25 +44,26 @@ 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)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -16,8 +16,7 @@ var ALIASABLE_CONSTRUCTORS = [
|
||||
"Map",
|
||||
"WeakMap",
|
||||
"Set",
|
||||
"WeakSet",
|
||||
"Number"
|
||||
"WeakSet"
|
||||
];
|
||||
|
||||
var astVisitor = {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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) {
|
||||
@@ -42,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]);
|
||||
}
|
||||
|
||||
@@ -57,9 +57,8 @@ export default class TraversalPath {
|
||||
}
|
||||
|
||||
setContext(parentPath, context, key) {
|
||||
this.shouldRemove = false;
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.context = context;
|
||||
@@ -71,8 +70,9 @@ export default class TraversalPath {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -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)) {
|
||||
@@ -531,16 +581,16 @@ export default class Scope {
|
||||
block = block.body;
|
||||
}
|
||||
|
||||
if (t.isBlockStatement(block) || t.isProgram(block)) {
|
||||
block._declarations ||= {};
|
||||
block._declarations[opts.key] = {
|
||||
kind: opts.kind || "var",
|
||||
id: opts.id,
|
||||
init: opts.init
|
||||
};
|
||||
} else {
|
||||
throw new TypeError(`cannot add a declaration here in node type ${block.type}`);
|
||||
if (!t.isBlockStatement(block) && !t.isProgram(block)) {
|
||||
block = this.getBlockParent().block;
|
||||
}
|
||||
|
||||
block._declarations ||= {};
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"],
|
||||
|
||||
@@ -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,12 +124,9 @@ 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 = node.key): Object {
|
||||
if (!node.computed) {
|
||||
if (t.isIdentifier(key)) key = t.literal(key.name);
|
||||
}
|
||||
@@ -151,12 +140,9 @@ t.toComputedKey = function (node, key) {
|
||||
* 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) {
|
||||
@@ -168,7 +154,6 @@ t.toSequenceExpression = function (nodes, scope) {
|
||||
each(node.declarations, function (declar) {
|
||||
scope.push({
|
||||
kind: node.kind,
|
||||
key: declar.id.name,
|
||||
id: declar.id
|
||||
});
|
||||
exprs.push(t.assignmentExpression("=", declar.id, declar.init));
|
||||
@@ -185,13 +170,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++) {
|
||||
@@ -207,14 +188,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;
|
||||
@@ -223,26 +199,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
|
||||
@@ -346,36 +314,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 + "";
|
||||
@@ -400,24 +358,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;
|
||||
@@ -428,12 +379,9 @@ 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) {
|
||||
@@ -461,13 +409,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) {
|
||||
@@ -517,12 +461,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;
|
||||
}
|
||||
@@ -559,12 +501,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;
|
||||
}
|
||||
@@ -584,13 +523,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;
|
||||
}
|
||||
@@ -617,12 +552,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();
|
||||
|
||||
@@ -657,7 +589,9 @@ t.getBindingIdentifiers.keys = {
|
||||
ImportBatchSpecifier: ["name"],
|
||||
VariableDeclarator: ["id"],
|
||||
FunctionDeclaration: ["id"],
|
||||
FunctionExpression: ["id"],
|
||||
ClassDeclaration: ["id"],
|
||||
ClassExpression: ["id"],
|
||||
SpreadElement: ["argument"],
|
||||
RestElement: ["argument"],
|
||||
UpdateExpression: ["argument"],
|
||||
@@ -675,34 +609,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;
|
||||
};
|
||||
|
||||
@@ -712,12 +637,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];
|
||||
});
|
||||
@@ -726,13 +648,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])));
|
||||
});
|
||||
@@ -741,13 +659,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;
|
||||
@@ -764,12 +678,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) {
|
||||
@@ -792,23 +703,34 @@ t.getLastStatements = function (node) {
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param {Object} specifier
|
||||
* @returns {String}
|
||||
*/
|
||||
|
||||
t.getSpecifierName = function (specifier) {
|
||||
t.toKeyAlias = function (node: Object, key: Object = node.key) {
|
||||
var alias;
|
||||
if (t.isIdentifier(key)) {
|
||||
alias = key.name;
|
||||
} else if (t.isLiteral(key)) {
|
||||
alias = JSON.stringify(key.value);
|
||||
} else {
|
||||
alias = JSON.stringify(traverse.removeProperties(t.cloneDeep(key)));
|
||||
}
|
||||
if (node.computed) alias = `[${alias}]`;
|
||||
return alias;
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
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 {
|
||||
@@ -818,24 +740,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;
|
||||
@@ -851,12 +766,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
|
||||
@@ -894,12 +806,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;
|
||||
};
|
||||
@@ -917,12 +826,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);
|
||||
@@ -1014,12 +920,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");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
5
test/fixtures/transformation/async-to-generator/named-expression/actual.js
vendored
Normal file
5
test/fixtures/transformation/async-to-generator/named-expression/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var foo = async function bar() {
|
||||
console.log(bar);
|
||||
};
|
||||
|
||||
foo();
|
||||
9
test/fixtures/transformation/async-to-generator/named-expression/expected.js
vendored
Normal file
9
test/fixtures/transformation/async-to-generator/named-expression/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var _bar;
|
||||
|
||||
var foo = _bar = babelHelpers.asyncToGenerator(function* () {
|
||||
console.log(_bar);
|
||||
});
|
||||
|
||||
foo();
|
||||
5
test/fixtures/transformation/bluebird-coroutines/named-expression/actual.js
vendored
Normal file
5
test/fixtures/transformation/bluebird-coroutines/named-expression/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var foo = async function bar() {
|
||||
console.log(bar);
|
||||
};
|
||||
|
||||
foo();
|
||||
11
test/fixtures/transformation/bluebird-coroutines/named-expression/expected.js
vendored
Normal file
11
test/fixtures/transformation/bluebird-coroutines/named-expression/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var _bluebird = require("bluebird");
|
||||
|
||||
var _bar;
|
||||
|
||||
var foo = _bar = _bluebird.coroutine(function* () {
|
||||
console.log(_bar);
|
||||
});
|
||||
|
||||
foo();
|
||||
5
test/fixtures/transformation/es6-classes/computed-methods/actual.js
vendored
Normal file
5
test/fixtures/transformation/es6-classes/computed-methods/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
foo() {}
|
||||
"foo"() {}
|
||||
[bar]() {}
|
||||
}
|
||||
17
test/fixtures/transformation/es6-classes/computed-methods/exec.js
vendored
Normal file
17
test/fixtures/transformation/es6-classes/computed-methods/exec.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
const sym = Symbol();
|
||||
|
||||
class Foo {
|
||||
[sym] () {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
class Bar extends Foo {
|
||||
[sym] () {
|
||||
return super[sym]() + 2;
|
||||
}
|
||||
}
|
||||
|
||||
let i = new Bar();
|
||||
|
||||
assert.equal(i[sym](), 3);
|
||||
19
test/fixtures/transformation/es6-classes/computed-methods/expected.js
vendored
Normal file
19
test/fixtures/transformation/es6-classes/computed-methods/expected.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
}
|
||||
|
||||
babelHelpers.createComputedClass(Foo, [{
|
||||
key: "foo",
|
||||
value: function foo() {}
|
||||
}, {
|
||||
key: "foo",
|
||||
value: function foo() {}
|
||||
}, {
|
||||
key: bar,
|
||||
value: function () {}
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
22
test/fixtures/transformation/es6-classes/preserves-directives/actual.js
vendored
Normal file
22
test/fixtures/transformation/es6-classes/preserves-directives/actual.js
vendored
Normal 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";
|
||||
}
|
||||
}
|
||||
21
test/fixtures/transformation/es6-classes/preserves-directives/expected.js
vendored
Normal file
21
test/fixtures/transformation/es6-classes/preserves-directives/expected.js
vendored
Normal 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";
|
||||
};
|
||||
@@ -1,29 +0,0 @@
|
||||
// labels
|
||||
|
||||
foo: for (let x of foo()) {
|
||||
while (true) {
|
||||
break foo;
|
||||
}
|
||||
}
|
||||
|
||||
foo: for (let x of foo()) {
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foo: for (let x of foo()) {
|
||||
break foo;
|
||||
}
|
||||
|
||||
// basic
|
||||
|
||||
for (let x of foo()) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (let x of foo()) {
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// labels
|
||||
|
||||
foo: 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 x = _ref;
|
||||
|
||||
while (true) {
|
||||
if (!_isArray && _iterator["return"]) _iterator["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
}
|
||||
|
||||
foo: for (var _iterator2 = foo(), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var _ref2;
|
||||
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var x = _ref2;
|
||||
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foo: for (var _iterator3 = foo(), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||
var _ref3;
|
||||
|
||||
if (_isArray3) {
|
||||
if (_i3 >= _iterator3.length) break;
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if (_i3.done) break;
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var x = _ref3;
|
||||
if (!_isArray3 && _iterator3["return"]) _iterator3["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
|
||||
// basic
|
||||
|
||||
for (var _iterator4 = foo(), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
|
||||
var _ref4;
|
||||
|
||||
if (_isArray4) {
|
||||
if (_i4 >= _iterator4.length) break;
|
||||
_ref4 = _iterator4[_i4++];
|
||||
} else {
|
||||
_i4 = _iterator4.next();
|
||||
if (_i4.done) break;
|
||||
_ref4 = _i4.value;
|
||||
}
|
||||
|
||||
var x = _ref4;
|
||||
if (!_isArray4 && _iterator4["return"]) _iterator4["return"]();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
for (var _iterator5 = foo(), _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
|
||||
var _ref5;
|
||||
|
||||
if (_isArray5) {
|
||||
if (_i5 >= _iterator5.length) break;
|
||||
_ref5 = _iterator5[_i5++];
|
||||
} else {
|
||||
_i5 = _iterator5.next();
|
||||
if (_i5.done) break;
|
||||
_ref5 = _i5.value;
|
||||
}
|
||||
|
||||
var x = _ref5;
|
||||
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
// labels
|
||||
|
||||
foo: for (let x of foo()) {
|
||||
while (true) {
|
||||
break foo;
|
||||
}
|
||||
}
|
||||
|
||||
foo: for (let x of foo()) {
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foo: for (let x of foo()) {
|
||||
break foo;
|
||||
}
|
||||
|
||||
// basic
|
||||
|
||||
for (let x of foo()) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (let x of foo()) {
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// labels
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
foo: for (var _iterator = foo()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var x = _step.value;
|
||||
|
||||
while (true) {
|
||||
if (_iterator["return"]) _iterator["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"]) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
foo: for (var _iterator2 = foo()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var x = _step2.value;
|
||||
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2["return"]) {
|
||||
_iterator2["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
foo: for (var _iterator3 = foo()[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
var x = _step3.value;
|
||||
if (_iterator3["return"]) _iterator3["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3["return"]) {
|
||||
_iterator3["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// basic
|
||||
|
||||
var _iteratorNormalCompletion4 = true;
|
||||
var _didIteratorError4 = false;
|
||||
var _iteratorError4 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator4 = foo()[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
||||
var x = _step4.value;
|
||||
if (_iterator4["return"]) _iterator4["return"]();
|
||||
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError4 = true;
|
||||
_iteratorError4 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion4 && _iterator4["return"]) {
|
||||
_iterator4["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError4) {
|
||||
throw _iteratorError4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion5 = true;
|
||||
var _didIteratorError5 = false;
|
||||
var _iteratorError5 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator5 = foo()[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
||||
var x = _step5.value;
|
||||
|
||||
while (true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError5 = true;
|
||||
_iteratorError5 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion5 && _iterator5["return"]) {
|
||||
_iterator5["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError5) {
|
||||
throw _iteratorError5;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
test/fixtures/transformation/es6.symbols/options.json
vendored
Normal file
3
test/fixtures/transformation/es6.symbols/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"optional": ["es6.symbols"]
|
||||
}
|
||||
@@ -5,17 +5,17 @@ var Foo = (function () {
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(Foo, babelHelpers.defineProperty({
|
||||
bar: {
|
||||
get: function () {
|
||||
return babelHelpers.defineProperty(this, "bar", complex()).bar;
|
||||
}
|
||||
babelHelpers.createComputedClass(Foo, [{
|
||||
key: "bar",
|
||||
get: function () {
|
||||
return babelHelpers.defineProperty(this, "bar", complex()).bar;
|
||||
}
|
||||
}, bar, {
|
||||
}, {
|
||||
key: bar,
|
||||
get: function () {
|
||||
return babelHelpers.defineProperty(this, bar, complex())[bar];
|
||||
}
|
||||
}));
|
||||
}]);
|
||||
return Foo;
|
||||
})();
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"optional": ["spec.typeofSymbol"]
|
||||
}
|
||||
4
test/fixtures/transformation/utility.remove-console/expression-nested/actual.js
vendored
Normal file
4
test/fixtures/transformation/utility.remove-console/expression-nested/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
function foo() {
|
||||
true && console.log("foo");
|
||||
blah();
|
||||
}
|
||||
6
test/fixtures/transformation/utility.remove-console/expression-nested/expected.js
vendored
Normal file
6
test/fixtures/transformation/utility.remove-console/expression-nested/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
true;
|
||||
blah();
|
||||
}
|
||||
2
test/fixtures/transformation/utility.remove-console/expression-top-level/actual.js
vendored
Normal file
2
test/fixtures/transformation/utility.remove-console/expression-top-level/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
true && console.log("foo");
|
||||
blah();
|
||||
4
test/fixtures/transformation/utility.remove-console/expression-top-level/expected.js
vendored
Normal file
4
test/fixtures/transformation/utility.remove-console/expression-top-level/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
true;
|
||||
blah();
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {}
|
||||
@@ -1,3 +1,4 @@
|
||||
function foo() {
|
||||
console.log("foo");
|
||||
blah();
|
||||
}
|
||||
5
test/fixtures/transformation/utility.remove-console/statement-nested/expected.js
vendored
Normal file
5
test/fixtures/transformation/utility.remove-console/statement-nested/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
blah();
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
console.log("foo");
|
||||
blah();
|
||||
@@ -1 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
blah();
|
||||
@@ -48,7 +48,7 @@ suite("kangax/compat-table", function () {
|
||||
code = transform(code, {
|
||||
filename: key,
|
||||
blacklist: ["strict"],
|
||||
optional: ["spec.typeofSymbol", "es6.blockScopingTDZ"]
|
||||
optional: ["es6.symbols", "es6.blockScopingTDZ"]
|
||||
}).code;
|
||||
|
||||
code = '"use strict";\n' + code;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if (process.env.SIMPLE_BABEL_TESTS) return;
|
||||
if (!process.env.ALL_BABEL_TESTS) return;
|
||||
|
||||
require("./_helper").assertVendor("test262");
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ require("./_transformation-helper")({
|
||||
"Syntax/StrictKeywords"
|
||||
]
|
||||
}, {
|
||||
optional: ["spec.typeofSymbol"],
|
||||
optional: ["es6.symbols"],
|
||||
experimental: true
|
||||
}, function (opts, task) {
|
||||
if (!_.contains(task.exec.loc, "module.js")) {
|
||||
|
||||
Reference in New Issue
Block a user