Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fea487bf91 | ||
|
|
ff2cbd5a2e | ||
|
|
12e01f9e71 | ||
|
|
f62436909d | ||
|
|
e42c1adeb6 | ||
|
|
e30dbbab94 | ||
|
|
e3daa28e60 | ||
|
|
9e5d94126c | ||
|
|
95798bee0b | ||
|
|
63f25ab038 | ||
|
|
27a8f2d2ea | ||
|
|
78434bb404 | ||
|
|
82833a8901 | ||
|
|
93d5288d71 | ||
|
|
5d3074b460 | ||
|
|
a57475abc9 | ||
|
|
09e68d8d46 | ||
|
|
ee850c3aeb | ||
|
|
ff5a149cec | ||
|
|
957118fb41 | ||
|
|
e7ad0a9741 | ||
|
|
24f4b041c7 | ||
|
|
4c77d04b56 | ||
|
|
e945f0d10f | ||
|
|
fb04b2561f | ||
|
|
a4f8b41507 | ||
|
|
1fb6018e9c | ||
|
|
bca233d22c | ||
|
|
c78703e194 | ||
|
|
43fdbe3d6c | ||
|
|
8650ca7d55 | ||
|
|
3a0c226a34 | ||
|
|
73e8bdd048 | ||
|
|
e7c52a734e |
28
CHANGELOG.md
28
CHANGELOG.md
@@ -13,6 +13,34 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 4.6.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `arguments` being incorrectly aliased in arrow function rest parameter optimisation.
|
||||
* Make deoptimisation trigger safer.
|
||||
* **New Feature**
|
||||
* Flow types are now retained when blacklisting the `flow` transformer.
|
||||
|
||||
## 4.6.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix generators in template directory being transformed.
|
||||
* Fix exposure of `util` for plugins.
|
||||
|
||||
## 4.6.0
|
||||
|
||||
* **New Feature**
|
||||
* Desugar sticky regexes to a new constructor expression so it can be handled by a polyfill.
|
||||
* **Spec Compliancy**
|
||||
* `for...of` now outputs in a lengthy `try...catch` this is to ensure spec compliancy in regards to iterator returns and abrupt completions. See [google/traceur-compiler#1773](https://github.com/google/traceur-compiler/issues/1773) and [babel/babel/#838](https://github.com/babel/babel/issues/838) for more information.
|
||||
* **Polish**
|
||||
* Rest parameters that are only refered to via number properties on member expressions are desugared into a direct `arguments` reference. Thanks [@neVERberleRfellerER](https://github.com/neVERberleRfellerER)!
|
||||
* `$ babel` no longer exits on syntax errors.
|
||||
* **Internal**
|
||||
* Upgrade `browserify`.
|
||||
* Upgrade `source-map`.
|
||||
* Publicly expose more internals.
|
||||
|
||||
## 4.5.5
|
||||
|
||||
* **Polish**
|
||||
|
||||
@@ -31,6 +31,14 @@ module.exports = function (commander, filenames, opts) {
|
||||
console.log(src + " -> " + dest);
|
||||
};
|
||||
|
||||
var handleFile = function (src, filename) {
|
||||
if (util.canCompile(filename)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
}
|
||||
};
|
||||
|
||||
var handle = function (filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
|
||||
@@ -41,11 +49,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
_.each(util.readdir(dirname), function (filename) {
|
||||
var src = path.join(dirname, filename);
|
||||
if (util.canCompile(filename)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
}
|
||||
handleFile(src, filename);
|
||||
});
|
||||
} else {
|
||||
write(filename, filename);
|
||||
@@ -65,7 +69,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
watcher.on(type, function (filename) {
|
||||
var relative = path.relative(dirname, filename) || filename;
|
||||
try {
|
||||
if (util.canCompile(filename)) write(filename, relative);
|
||||
handleFile(filename, relative);
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
|
||||
10
package.json
10
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "4.6.0",
|
||||
"version": "4.6.4",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -36,7 +36,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-babel": "0.11.1-35",
|
||||
"acorn-babel": "0.11.1-37",
|
||||
"ast-types": "~0.6.1",
|
||||
"chalk": "^1.0.0",
|
||||
"chokidar": "^0.12.6",
|
||||
@@ -57,7 +57,7 @@
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"private": "^0.1.6",
|
||||
"regenerator-babel": "0.8.13-1",
|
||||
"regexpu": "^1.1.1",
|
||||
"regexpu": "^1.1.2",
|
||||
"repeating": "^1.1.2",
|
||||
"shebang-regex": "^1.0.0",
|
||||
"slash": "^1.0.0",
|
||||
@@ -67,11 +67,11 @@
|
||||
"trim-right": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "4.5.1",
|
||||
"babel": "4.6.0",
|
||||
"browserify": "^9.0.3",
|
||||
"chai": "^2.0.0",
|
||||
"eslint": "^0.15.1",
|
||||
"babel-eslint": "^1.0.0",
|
||||
"babel-eslint": "^1.0.1",
|
||||
"esvalid": "^1.1.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"matcha": "^0.6.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "4.5.5",
|
||||
"version": "4.6.3",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -2,8 +2,11 @@ import isFunction from "lodash/lang/isFunction";
|
||||
import transform from "../transformation";
|
||||
import fs from "fs";
|
||||
|
||||
import * as util from "../util";
|
||||
export { util as _util };
|
||||
export { canCompile } from "../util";
|
||||
|
||||
export { default as acorn } from "acorn-babel";
|
||||
export { default as _util, canCompile } from "../util";
|
||||
export { default as transform } from "../transformation";
|
||||
export { default as traverse } from "../traversal";
|
||||
export { default as buildExternalHelpers } from "../build-external-helpers";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
exports.ClassExpression =
|
||||
exports.ClassDeclaration = function (node, print) {
|
||||
export function ClassDeclaration(node, print) {
|
||||
this.push("class");
|
||||
|
||||
if (node.id) {
|
||||
@@ -7,14 +6,24 @@ exports.ClassDeclaration = function (node, print) {
|
||||
print(node.id);
|
||||
}
|
||||
|
||||
print(node.typeParameters);
|
||||
|
||||
if (node.superClass) {
|
||||
this.push(" extends ");
|
||||
print(node.superClass);
|
||||
print(node.superTypeParameters);
|
||||
}
|
||||
|
||||
if (node.implements) {
|
||||
this.push(" implements ");
|
||||
print.join(node.implements, { separator: ", " });
|
||||
}
|
||||
|
||||
this.space();
|
||||
print(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
export { ClassDeclaration as ClassExpression };
|
||||
|
||||
export function ClassBody(node, print) {
|
||||
if (node.body.length === 0) {
|
||||
|
||||
@@ -1,34 +1,226 @@
|
||||
exports.AnyTypeAnnotation =
|
||||
exports.ArrayTypeAnnotation =
|
||||
exports.BooleanTypeAnnotation =
|
||||
exports.ClassProperty =
|
||||
exports.DeclareClass =
|
||||
exports.DeclareFunction =
|
||||
exports.DeclareModule =
|
||||
exports.DeclareVariable =
|
||||
exports.FunctionTypeAnnotation =
|
||||
exports.FunctionTypeParam =
|
||||
exports.GenericTypeAnnotation =
|
||||
exports.InterfaceExtends =
|
||||
exports.InterfaceDeclaration =
|
||||
exports.IntersectionTypeAnnotation =
|
||||
exports.NullableTypeAnnotation =
|
||||
exports.NumberTypeAnnotation =
|
||||
exports.StringLiteralTypeAnnotation =
|
||||
exports.StringTypeAnnotation =
|
||||
exports.TupleTypeAnnotation =
|
||||
exports.TypeofTypeAnnotation =
|
||||
exports.TypeAlias =
|
||||
exports.TypeAnnotation =
|
||||
exports.TypeParameterDeclaration =
|
||||
exports.TypeParameterInstantiation =
|
||||
exports.ObjectTypeAnnotation =
|
||||
exports.ObjectTypeCallProperty =
|
||||
exports.ObjectTypeIndexer =
|
||||
exports.ObjectTypeProperty =
|
||||
exports.QualifiedTypeIdentifier =
|
||||
exports.UnionTypeAnnotation =
|
||||
exports.TypeCastExpression =
|
||||
exports.VoidTypeAnnotation = function () {
|
||||
// todo: implement these once we have a `--keep-types` option
|
||||
};
|
||||
import t from "../../types";
|
||||
|
||||
export function AnyTypeAnnotation() {
|
||||
this.push("any");
|
||||
}
|
||||
|
||||
export function ArrayTypeAnnotation(node, print) {
|
||||
print(node.elementType);
|
||||
this.push("[");
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
export function BooleanTypeAnnotation(node) {
|
||||
this.push("bool");
|
||||
}
|
||||
|
||||
export function ClassProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.key);
|
||||
print(node.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function DeclareClass(node, print) {
|
||||
this.push("declare class ");
|
||||
this._interfaceish(node, print);
|
||||
}
|
||||
|
||||
export function DeclareFunction(node, print) {
|
||||
this.push("declare function ");
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function DeclareModule(node, print) {
|
||||
this.push("declare module ");
|
||||
print(node.id);
|
||||
this.space();
|
||||
print(node.body);
|
||||
}
|
||||
|
||||
export function DeclareVariable(node, print) {
|
||||
this.push("declare var ");
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function FunctionTypeAnnotation(node, print, parent) {
|
||||
print(node.typeParameters);
|
||||
this.push("(");
|
||||
print.list(node.params);
|
||||
|
||||
if (node.rest) {
|
||||
if (node.params.length) {
|
||||
this.push(",");
|
||||
this.space();
|
||||
}
|
||||
this.push("...");
|
||||
print(node.rest);
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
|
||||
// this node type is overloaded, not sure why but it makes it EXTREMELY annoying
|
||||
if (parent.type === "ObjectTypeProperty" || parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction") {
|
||||
this.push(":");
|
||||
} else {
|
||||
this.space();
|
||||
this.push("=>");
|
||||
}
|
||||
|
||||
this.space();
|
||||
print(node.returnType);
|
||||
}
|
||||
|
||||
export function FunctionTypeParam(node, print) {
|
||||
print(node.name);
|
||||
if (node.optional) this.push("?");
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function InterfaceExtends(node, print) {
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
}
|
||||
|
||||
export { InterfaceExtends as ClassImplements, InterfaceExtends as GenericTypeAnnotation };
|
||||
|
||||
export function _interfaceish(node, print) {
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
if (node.extends.length) {
|
||||
this.push(" extends ");
|
||||
print.join(node.extends, { separator: ", " });
|
||||
}
|
||||
this.space();
|
||||
print(node.body);
|
||||
}
|
||||
|
||||
export function InterfaceDeclaration(node, print) {
|
||||
this.push("interface ");
|
||||
this._interfaceish(node, print);
|
||||
}
|
||||
|
||||
export function IntersectionTypeAnnotation(node, print) {
|
||||
print.join(node.types, { separator: " & " });
|
||||
}
|
||||
|
||||
export function NullableTypeAnnotation(node, print) {
|
||||
this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function NumberTypeAnnotation() {
|
||||
this.push("number");
|
||||
}
|
||||
|
||||
export function StringLiteralTypeAnnotation(node) {
|
||||
this._stringLiteral(node.value);
|
||||
}
|
||||
|
||||
export function StringTypeAnnotation() {
|
||||
this.push("string");
|
||||
}
|
||||
|
||||
export function TupleTypeAnnotation(node, print) {
|
||||
this.push("[");
|
||||
print.join(node.types, { separator: ", " });
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
export function TypeofTypeAnnotation(node, print) {
|
||||
this.push("typeof ");
|
||||
print(node.argument);
|
||||
}
|
||||
|
||||
export function TypeAlias(node, print) {
|
||||
this.push("type ");
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
print(node.right);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function TypeAnnotation(node, print) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
if (node.optional) this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function TypeParameterInstantiation(node, print) {
|
||||
this.push("<");
|
||||
print.join(node.params, { separator: ", " });
|
||||
this.push(">");
|
||||
}
|
||||
|
||||
export { TypeParameterInstantiation as TypeParameterDeclaration };
|
||||
|
||||
export function ObjectTypeAnnotation(node, print) {
|
||||
this.push("{");
|
||||
var props = node.properties.concat(node.callProperties, node.indexers);
|
||||
if (props.length) {
|
||||
this.space();
|
||||
print.list(props, { indent: true, separator: "; " });
|
||||
this.space();
|
||||
}
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
export function ObjectTypeCallProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.value);
|
||||
}
|
||||
|
||||
export function ObjectTypeIndexer(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
this.push("[");
|
||||
print(node.id);
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.key);
|
||||
this.push("]");
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.value);
|
||||
}
|
||||
|
||||
export function ObjectTypeProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.key);
|
||||
if (node.optional) this.push("?");
|
||||
if (!t.isFunctionTypeAnnotation(node.value)) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
}
|
||||
print(node.value);
|
||||
}
|
||||
|
||||
export function QualifiedTypeIdentifier(node, print) {
|
||||
print(node.qualification);
|
||||
this.push(".");
|
||||
print(node.id);
|
||||
}
|
||||
|
||||
export function UnionTypeAnnotation(node, print) {
|
||||
print.join(node.types, { separator: " | " });
|
||||
}
|
||||
|
||||
export function TypeCastExpression(node, print) {
|
||||
this.push("(");
|
||||
print(node.expression);
|
||||
print(node.typeAnnotation);
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
export function VoidTypeAnnotation(node) {
|
||||
this.push("void");
|
||||
}
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import t from "../../types";
|
||||
|
||||
export function _params(node, print) {
|
||||
print(node.typeParameters);
|
||||
this.push("(");
|
||||
print.list(node.params);
|
||||
print.list(node.params, {
|
||||
iterator: (node) =>{
|
||||
if (node.optional) this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
});
|
||||
this.push(")");
|
||||
|
||||
if (node.returnType) {
|
||||
print(node.returnType);
|
||||
}
|
||||
}
|
||||
|
||||
export function _method(node, print) {
|
||||
|
||||
@@ -211,13 +211,12 @@ export function PrivateDeclaration(node, print) {
|
||||
}
|
||||
|
||||
export function VariableDeclarator(node, print) {
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation);
|
||||
if (node.init) {
|
||||
print(node.id);
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
print(node.init);
|
||||
} else {
|
||||
print(node.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,14 +83,7 @@ export function Literal(node) {
|
||||
var type = typeof val;
|
||||
|
||||
if (type === "string") {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
// escape illegal js but valid json unicode characters
|
||||
val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) {
|
||||
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
this._stringLiteral(val);
|
||||
} else if (type === "number") {
|
||||
this.push(val + "");
|
||||
} else if (type === "boolean") {
|
||||
@@ -101,3 +94,14 @@ export function Literal(node) {
|
||||
this.push("null");
|
||||
}
|
||||
}
|
||||
|
||||
export function _stringLiteral(val) {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
// escape illegal js but valid json unicode characters
|
||||
val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) {
|
||||
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class CodeGenerator {
|
||||
}
|
||||
|
||||
print(node, parent, opts = {}) {
|
||||
if (!node) return "";
|
||||
if (!node) return;
|
||||
|
||||
if (parent && parent._compact) {
|
||||
node._compact = true;
|
||||
|
||||
@@ -21,6 +21,12 @@ each([
|
||||
});
|
||||
});
|
||||
|
||||
export function NullableTypeAnnotation(node, parent) {
|
||||
return t.isArrayTypeAnnotation(parent);
|
||||
}
|
||||
|
||||
export { NullableTypeAnnotation as FunctionTypeAnnotation };
|
||||
|
||||
export function UpdateExpression(node, parent) {
|
||||
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||
// (foo++).test()
|
||||
@@ -139,8 +145,7 @@ export function FunctionExpression(node, parent) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.AssignmentExpression =
|
||||
exports.ConditionalExpression = function (node, parent) {
|
||||
export function ConditionalExpression(node, parent) {
|
||||
if (t.isUnaryLike(parent)) {
|
||||
return true;
|
||||
}
|
||||
@@ -164,4 +169,6 @@ exports.ConditionalExpression = function (node, parent) {
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
export { ConditionalExpression as AssignmentExpression };
|
||||
|
||||
@@ -20,12 +20,12 @@ var checkTransformerVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
var checkNode = function (stack, node, scope) {
|
||||
function checkNode(stack, node, scope) {
|
||||
each(stack, function (pass) {
|
||||
if (pass.shouldRun) return;
|
||||
pass.checkNode(node, scope);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default class File {
|
||||
constructor(opts) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import isString from "lodash/lang/isString";
|
||||
import * as messages from "../../messages";
|
||||
import esutils from "esutils";
|
||||
import react from "./react";
|
||||
import * as react from "./react";
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (exports, opts) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import each from "lodash/collection/each";
|
||||
import has from "lodash/object/has";
|
||||
import t from "../../types";
|
||||
|
||||
exports.push = function (mutatorMap, key, kind, computed, value) {
|
||||
export function push(mutatorMap, key, kind, computed, value) {
|
||||
var alias;
|
||||
|
||||
if (t.isIdentifier(key)) {
|
||||
@@ -31,9 +31,9 @@ exports.push = function (mutatorMap, key, kind, computed, value) {
|
||||
}
|
||||
|
||||
map[kind] = value;
|
||||
};
|
||||
}
|
||||
|
||||
exports.build = function (mutatorMap) {
|
||||
export function build(mutatorMap) {
|
||||
var objExpr = t.objectExpression([]);
|
||||
|
||||
each(mutatorMap, function (map) {
|
||||
@@ -70,4 +70,4 @@ exports.build = function (mutatorMap) {
|
||||
});
|
||||
|
||||
return objExpr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ var visit = function (node, name, scope) {
|
||||
return state;
|
||||
};
|
||||
|
||||
exports.property = function (node, file, scope) {
|
||||
export function property(node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
|
||||
@@ -99,9 +99,9 @@ exports.property = function (node, file, scope) {
|
||||
var method = node.value;
|
||||
var state = visit(method, name, scope);
|
||||
node.value = wrap(state, method, id, scope);
|
||||
};
|
||||
}
|
||||
|
||||
exports.bare = function (node, parent, scope) {
|
||||
export function bare(node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
|
||||
@@ -123,4 +123,4 @@ exports.bare = function (node, parent, scope) {
|
||||
|
||||
var state = visit(node, name, scope);
|
||||
return wrap(state, node, id, scope);
|
||||
};
|
||||
}
|
||||
|
||||
10
src/babel/transformation/helpers/react.js
vendored
10
src/babel/transformation/helpers/react.js
vendored
@@ -2,7 +2,7 @@ import t from "../../types";
|
||||
|
||||
var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
|
||||
|
||||
exports.isCreateClass = function (node) {
|
||||
export function isCreateClass(node) {
|
||||
if (!node || !t.isCallExpression(node)) return false;
|
||||
|
||||
// not React.createClass call member object
|
||||
@@ -17,10 +17,10 @@ exports.isCreateClass = function (node) {
|
||||
if (!t.isObjectExpression(first)) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
exports.isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
export var isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
|
||||
exports.isCompatTag = function (tagName) {
|
||||
export function isCompatTag(tagName) {
|
||||
return tagName && /^[a-z]|\-/.test(tagName);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import t from "../../types";
|
||||
|
||||
exports.has = function (node) {
|
||||
export function has(node) {
|
||||
var first = node.body[0];
|
||||
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
|
||||
};
|
||||
}
|
||||
|
||||
exports.wrap = function (node, callback) {
|
||||
export function wrap(node, callback) {
|
||||
var useStrictNode;
|
||||
if (exports.has(node)) {
|
||||
useStrictNode = node.body.shift();
|
||||
@@ -16,4 +16,4 @@ exports.wrap = function (node, callback) {
|
||||
if (useStrictNode) {
|
||||
node.body.unshift(useStrictNode);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"blacklist": ["useStrict", "es6.blockScoping"]
|
||||
"blacklist": ["useStrict", "es6.blockScoping", "regenerator"]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"selfContained": "runtime",
|
||||
"unicode-regex": "regex.unicode"
|
||||
"unicode-regex": "regex.unicode",
|
||||
|
||||
"minification.deadCodeElimination": "utility.deadCodeElimination",
|
||||
"minification.removeConsoleCalls": "utility.removeConsole",
|
||||
"minification.removeDebugger": "utility.removeDebugger"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import defineMap from "../../helpers/define-map";
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import t from "../../../types";
|
||||
|
||||
export function check(node) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isArrowFunctionExpression;
|
||||
export var check = t.isArrowFunctionExpression;
|
||||
|
||||
export function ArrowFunctionExpression(node) {
|
||||
t.ensureBlock(node);
|
||||
|
||||
@@ -26,11 +26,9 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
export var optional = true;
|
||||
|
||||
exports.Loop =
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (node, parent, scope, file) {
|
||||
export function BlockStatement(node, parent, scope, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
|
||||
@@ -40,4 +38,6 @@ exports.BlockStatement = function (node, parent, scope, file) {
|
||||
};
|
||||
|
||||
scope.traverse(node, visitor, state);
|
||||
};
|
||||
}
|
||||
|
||||
export { BlockStatement as Program, BlockStatement as Loop };
|
||||
|
||||
@@ -5,11 +5,7 @@ import t from "../../../types";
|
||||
import values from "lodash/object/values";
|
||||
import extend from "lodash/object/extend";
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind === "let" || node.kind === "const");
|
||||
};
|
||||
|
||||
var isLet = function (node, parent) {
|
||||
function isLet(node, parent) {
|
||||
if (!t.isVariableDeclaration(node)) return false;
|
||||
if (node._let) return true;
|
||||
if (node.kind !== "let") return false;
|
||||
@@ -25,23 +21,27 @@ var isLet = function (node, parent) {
|
||||
node._let = true;
|
||||
node.kind = "var";
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
var isLetInitable = function (node, parent) {
|
||||
function isLetInitable(node, parent) {
|
||||
return !t.isFor(parent) || !t.isFor(parent, { left: node });
|
||||
};
|
||||
}
|
||||
|
||||
var isVar = function (node, parent) {
|
||||
function isVar(node, parent) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent);
|
||||
};
|
||||
}
|
||||
|
||||
var standardizeLets = function (declars) {
|
||||
function standardizeLets(declars) {
|
||||
for (var i = 0; i < declars.length; i++) {
|
||||
delete declars[i]._let;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
export function check(node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind === "let" || node.kind === "const");
|
||||
}
|
||||
|
||||
export function VariableDeclaration(node, parent, scope, file) {
|
||||
if (!isLet(node, parent)) return;
|
||||
|
||||
if (isLetInitable(node) && file.transformers["es6.blockScopingTDZ"].canRun()) {
|
||||
@@ -61,9 +61,9 @@ exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
|
||||
return nodes;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.Loop = function (node, parent, scope, file) {
|
||||
export function Loop(node, parent, scope, file) {
|
||||
var init = node.left || node.init;
|
||||
if (isLet(init, node)) {
|
||||
t.ensureBlock(node);
|
||||
@@ -71,15 +71,16 @@ exports.Loop = function (node, parent, scope, file) {
|
||||
}
|
||||
var blockScoping = new BlockScoping(node, node.body, parent, scope, file);
|
||||
blockScoping.run();
|
||||
};
|
||||
}
|
||||
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (block, parent, scope, file) {
|
||||
export function BlockStatement(block, parent, scope, file) {
|
||||
if (!t.isLoop(parent)) {
|
||||
var blockScoping = new BlockScoping(false, block, parent, scope, file);
|
||||
blockScoping.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { BlockStatement as Program };
|
||||
|
||||
function replace(node, parent, scope, remaps) {
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
@@ -326,7 +327,7 @@ class BlockScoping {
|
||||
for (var name in outsideRefs) {
|
||||
var id = outsideRefs[name];
|
||||
|
||||
if (this.scope.hasGlobal(id.name)) {
|
||||
if (this.scope.hasGlobal(id.name) || this.scope.parentHasBinding(id.name)) {
|
||||
delete outsideRefs[id.name];
|
||||
delete this.letReferences[id.name];
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import ReplaceSupers from "../../helpers/replace-supers";
|
||||
import nameMethod from "../../helpers/name-method";
|
||||
import defineMap from "../../helpers/define-map";
|
||||
import * as nameMethod from "../../helpers/name-method";
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isClass;
|
||||
export var check = t.isClass;
|
||||
|
||||
exports.ClassDeclaration = function (node, parent, scope, file) {
|
||||
export function ClassDeclaration(node, parent, scope, file) {
|
||||
return new ClassTransformer(node, file, scope, true).run();
|
||||
};
|
||||
}
|
||||
|
||||
exports.ClassExpression = function (node, parent, scope, file) {
|
||||
export function ClassExpression(node, parent, scope, file) {
|
||||
if (!node.id) {
|
||||
if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) {
|
||||
// var o = { foo: class {} };
|
||||
@@ -25,7 +25,7 @@ exports.ClassExpression = function (node, parent, scope, file) {
|
||||
}
|
||||
|
||||
return new ClassTransformer(node, file, scope, false).run();
|
||||
};
|
||||
}
|
||||
|
||||
class ClassTransformer {
|
||||
|
||||
@@ -182,7 +182,7 @@ class ClassTransformer {
|
||||
}
|
||||
|
||||
// we have no constructor, we have a super, and the super doesn't appear to be falsy
|
||||
if (!this.hasConstructor && this.hasSuper && !t.isFalsyExpression(superName)) {
|
||||
if (!this.hasConstructor && this.hasSuper && t.evaluateTruthy(superName) !== false) {
|
||||
var helperName = "class-super-constructor-call";
|
||||
if (this.isLoose) helperName += "-loose";
|
||||
constructor.body.body.push(util.template(helperName, {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = function (node) {
|
||||
export function check(node) {
|
||||
return t.isVariableDeclaration(node, { kind: "const" });
|
||||
};
|
||||
}
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -36,13 +36,13 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Scopable = function (node, parent, scope, file) {
|
||||
export function Scopable(node, parent, scope, file) {
|
||||
scope.traverse(node, visitor, {
|
||||
constants: scope.getAllBindingsOfKind("const"),
|
||||
file: file
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node) {
|
||||
export function VariableDeclaration(node) {
|
||||
if (node.kind === "const") node.kind = "let";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isPattern;
|
||||
export var check = t.isPattern;
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
|
||||
if (t.isPattern(left)) {
|
||||
@@ -50,7 +49,9 @@ exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
}
|
||||
|
||||
export { ForOfStatement as ForInStatement };
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
@@ -83,7 +84,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.CatchClause = function (node, parent, scope, file) {
|
||||
export function CatchClause(node, parent, scope, file) {
|
||||
var pattern = node.param;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
@@ -103,9 +104,9 @@ exports.CatchClause = function (node, parent, scope, file) {
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
export function ExpressionStatement(node, parent, scope, file) {
|
||||
var expr = node.expression;
|
||||
if (expr.type !== "AssignmentExpression") return;
|
||||
if (!t.isPattern(expr.left)) return;
|
||||
@@ -127,9 +128,9 @@ exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
destructuring.init(expr.left, ref);
|
||||
|
||||
return nodes;
|
||||
};
|
||||
}
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
export function AssignmentExpression(node, parent, scope, file) {
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
var ref = scope.generateUidIdentifier("temp");
|
||||
@@ -152,18 +153,18 @@ exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
nodes.push(ref);
|
||||
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
};
|
||||
}
|
||||
|
||||
var variableDeclarationHasPattern = function (node) {
|
||||
function variableDeclarationHasPattern(node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
if (t.isPattern(node.declarations[i].id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
export function VariableDeclaration(node, parent, scope, file) {
|
||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||
if (!variableDeclarationHasPattern(node)) return;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isForOfStatement;
|
||||
export var check = t.isForOfStatement;
|
||||
|
||||
exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.forOf")) callback = loose;
|
||||
|
||||
@@ -32,8 +32,12 @@ exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
// todo: find out why this is necessary? #538
|
||||
loop._scopeInfo = node._scopeInfo;
|
||||
|
||||
return build.node;
|
||||
};
|
||||
if (build.replaceParent) {
|
||||
this.parentPath.node = build.node;
|
||||
} else {
|
||||
return build.node;
|
||||
}
|
||||
}
|
||||
|
||||
var breakVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -97,7 +101,9 @@ var loose = function (node, parent, scope, file) {
|
||||
|
||||
scope.traverse(node, breakVisitor, {
|
||||
iteratorKey: iteratorKey,
|
||||
wrapReturn: function (node) {
|
||||
label: t.isLabeledStatement(parent) && parent.label.name,
|
||||
|
||||
wrapReturn: function (node) {
|
||||
return t.ifStatement(
|
||||
t.logicalExpression(
|
||||
"&&",
|
||||
@@ -105,8 +111,7 @@ var loose = function (node, parent, scope, file) {
|
||||
t.memberExpression(iteratorKey, t.identifier("return")
|
||||
)
|
||||
), node);
|
||||
},
|
||||
label: t.isLabeledStatement(parent) && parent.label.name
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
@@ -119,6 +124,8 @@ var loose = function (node, parent, scope, file) {
|
||||
};
|
||||
|
||||
var spec = function (node, parent, scope, file) {
|
||||
|
||||
|
||||
var left = node.left;
|
||||
var declar;
|
||||
|
||||
@@ -151,14 +158,22 @@ var spec = function (node, parent, scope, file) {
|
||||
BODY: null
|
||||
});
|
||||
|
||||
var loop = template[3].block.body[0];
|
||||
var isLabeledParent = t.isLabeledStatement(parent);
|
||||
|
||||
var tryBody = template[3].block.body;
|
||||
var loop = tryBody[0];
|
||||
|
||||
if (isLabeledParent) {
|
||||
tryBody[0] = t.labeledStatement(parent.label, loop);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
scope.traverse(node, breakVisitor, {
|
||||
iteratorKey: iteratorKey,
|
||||
label: t.isLabeledStatement(parent) && parent.label.name,
|
||||
wrapReturn: function (node) {
|
||||
label: isLabeledParent && parent.label.name,
|
||||
|
||||
wrapReturn: function (node) {
|
||||
return t.ifStatement(t.memberExpression(iteratorKey, t.identifier("return")), node);
|
||||
}
|
||||
});
|
||||
@@ -166,8 +181,9 @@ var spec = function (node, parent, scope, file) {
|
||||
//
|
||||
|
||||
return {
|
||||
declar: declar,
|
||||
loop: loop,
|
||||
node: template
|
||||
replaceParent: isLabeledParent,
|
||||
declar: declar,
|
||||
loop: loop,
|
||||
node: template
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import isNumber from "lodash/lang/isNumber";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isRestElement;
|
||||
export var check = t.isRestElement;
|
||||
|
||||
var memberExpressionOptimisationVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -28,26 +28,24 @@ var memberExpressionOptimisationVisitor = {
|
||||
// optimise it
|
||||
var prop = parent.property;
|
||||
if (isNumber(prop.value) || t.isUnaryExpression(prop) || t.isBinaryExpression(prop)) {
|
||||
optimizeMemberExpression(node, parent, state.method.params.length);
|
||||
state.hasShorthand = true;
|
||||
state.candidates.push(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
state.longForm = true;
|
||||
state.canOptimise = false;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
|
||||
function optimizeMemberExpression(node, parent, offset) {
|
||||
function optimizeMemberExpression(parent, offset) {
|
||||
var newExpr;
|
||||
var prop = parent.property;
|
||||
|
||||
if (t.isLiteral(prop)) {
|
||||
node.name = "arguments";
|
||||
prop.value += offset;
|
||||
prop.raw = String(prop.value);
|
||||
} else { // // UnaryExpression, BinaryExpression
|
||||
node.name = "arguments";
|
||||
newExpr = t.binaryExpression("+", prop, t.literal(offset));
|
||||
parent.property = newExpr;
|
||||
}
|
||||
@@ -82,16 +80,23 @@ exports.Function = function (node, parent, scope) {
|
||||
|
||||
var state = {
|
||||
outerBinding: scope.getBindingIdentifier(rest.name),
|
||||
hasShorthand: true,
|
||||
longForm: false,
|
||||
canOptimise: true,
|
||||
candidates: [],
|
||||
method: node,
|
||||
name: rest.name,
|
||||
name: rest.name
|
||||
};
|
||||
|
||||
scope.traverse(node, memberExpressionOptimisationVisitor, state);
|
||||
|
||||
// we only have shorthands and there's no other references
|
||||
if (!state.longForm && state.hasShorthand) return;
|
||||
if (state.canOptimise && state.candidates.length) {
|
||||
for (var i = 0; i < state.candidates.length; i++) {
|
||||
var candidate = state.candidates[i];
|
||||
candidate.node = argsId;
|
||||
optimizeMemberExpression(candidate.parent, node.params.length);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import includes from "lodash/collection/includes";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isSpreadElement;
|
||||
|
||||
function getSpreadLiteral(spread, scope) {
|
||||
return scope.toArray(spread.argument, true);
|
||||
}
|
||||
@@ -42,6 +40,8 @@ function build(props, scope) {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
export var check = t.isSpreadElement;
|
||||
|
||||
export function ArrayExpression(node, parent, scope) {
|
||||
var elements = node.elements;
|
||||
if (!hasSpread(elements)) return;
|
||||
|
||||
@@ -103,10 +103,12 @@ export default {
|
||||
"es3.propertyLiterals": require("./es3/property-literals"),
|
||||
"es3.memberExpressionLiterals": require("./es3/member-expression-literals"),
|
||||
|
||||
"minification.removeDebugger": require("./minification/remove-debugger"),
|
||||
"minification.removeConsoleCalls": require("./minification/remove-console-calls"),
|
||||
"minification.deadCodeElimination": require("./minification/dead-code-elimination"),
|
||||
"minification.renameLocalVariables": require("./minification/rename-local-variables"),
|
||||
"utility.removeDebugger": require("./utility/remove-debugger"),
|
||||
"utility.removeConsole": require("./utility/remove-console"),
|
||||
|
||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
||||
"utility.deadCodeElimination": require("./utility/dead-code-elimination"),
|
||||
|
||||
_cleanUp: require("./internal/cleanup")
|
||||
};
|
||||
|
||||
@@ -76,16 +76,17 @@ var go = function (getBody, node, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Program = function (node, parent, scope) {
|
||||
export function Program(node, parent, scope) {
|
||||
go(function () {
|
||||
return node.body;
|
||||
}, node, scope);
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, parent, scope) {
|
||||
export function FunctionDeclaration(node, parent, scope) {
|
||||
go(function () {
|
||||
t.ensureBlock(node);
|
||||
return node.body.body;
|
||||
}, node, scope);
|
||||
};
|
||||
}
|
||||
|
||||
export { FunctionDeclaration as FunctionExpression };
|
||||
|
||||
@@ -9,8 +9,7 @@ import values from "lodash/object/values";
|
||||
// - 2 Priority over normal nodes
|
||||
// - 3 We want this to be at the **very** top
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = {
|
||||
export var BlockStatement = {
|
||||
exit(node) {
|
||||
var hasChange = false;
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
@@ -29,3 +28,5 @@ exports.Program = {
|
||||
node.body = flatten(values(nodePriorities).reverse());
|
||||
}
|
||||
};
|
||||
|
||||
export { BlockStatement as Program };
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
export function SequenceExpression(node) {
|
||||
if (node.expressions.length === 1) {
|
||||
return node.expressions[0];
|
||||
export var SequenceExpression = {
|
||||
exit(node) {
|
||||
if (node.expressions.length === 1) {
|
||||
return node.expressions[0];
|
||||
} else if (!node.expressions.length) {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export var ExpressionStatement = {
|
||||
exit(node) {
|
||||
if (!node.expression) this.remove();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import useStrict from "../../helpers/use-strict";
|
||||
import * as useStrict from "../../helpers/use-strict";
|
||||
import t from "../../../types";
|
||||
|
||||
export var secondPass = true;
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = function (node, parent, scope, file) {
|
||||
export function BlockStatement(node, parent, scope, file) {
|
||||
if (!node._declarations) return;
|
||||
|
||||
useStrict.wrap(node, function () {
|
||||
@@ -31,4 +30,6 @@ exports.Program = function (node, parent, scope, file) {
|
||||
|
||||
node._declarations = null;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export { BlockStatement as Program };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import useStrict from "../../helpers/use-strict";
|
||||
import * as useStrict from "../../helpers/use-strict";
|
||||
|
||||
export function Program(program, parent, scope, file) {
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
//import t from "../../../types";
|
||||
|
||||
export var optional = true;
|
||||
|
||||
export function Scopable() {
|
||||
//for (var name in scope.bindings) {
|
||||
// scope.rename(name, scope.generateUidIdentifier("a").name);
|
||||
//}
|
||||
}
|
||||
@@ -1,5 +1,25 @@
|
||||
import t from "../../../types";
|
||||
|
||||
export function Flow(node) {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
export function ClassProperty(node) {
|
||||
node.typeAnnotation = null;
|
||||
if (!node.value) this.remove();
|
||||
}
|
||||
|
||||
export function Class(node) {
|
||||
node.implements = null;
|
||||
}
|
||||
|
||||
export function Function(node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
var param = node.params[i];
|
||||
param.optional = false;
|
||||
}
|
||||
}
|
||||
|
||||
export function TypeCastExpression(node) {
|
||||
return node.expression;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import react from "../../helpers/react";
|
||||
import * as react from "../../helpers/react";
|
||||
import t from "../../../types";
|
||||
|
||||
export function manipulateOptions(opts) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import react from "../../helpers/react";
|
||||
import * as react from "../../helpers/react";
|
||||
import t from "../../../types";
|
||||
|
||||
var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
|
||||
|
||||
@@ -8,10 +8,11 @@ export function Program(program) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function () {
|
||||
export function FunctionExpression() {
|
||||
this.skip();
|
||||
};
|
||||
}
|
||||
|
||||
export { FunctionExpression as FunctionDeclaration };
|
||||
|
||||
export function ThisExpression() {
|
||||
return t.identifier("undefined");
|
||||
|
||||
@@ -16,8 +16,7 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Property =
|
||||
exports.MethodDefinition = function (node, parent, scope, file) {
|
||||
export function MethodDefinition(node, parent, scope, file) {
|
||||
if (node.kind !== "memo") return;
|
||||
node.kind = "get";
|
||||
|
||||
@@ -38,4 +37,6 @@ exports.MethodDefinition = function (node, parent, scope, file) {
|
||||
scope.traverse(value, visitor, state);
|
||||
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
export { MethodDefinition as Property };
|
||||
|
||||
@@ -1,31 +1,41 @@
|
||||
import t from "../../../types";
|
||||
|
||||
function toStatements(node) {
|
||||
if (t.isBlockStatement(node)) {
|
||||
var hasBlockScoped = false;
|
||||
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isBlockScoped(bodyNode)) hasBlockScoped = true;
|
||||
}
|
||||
|
||||
if (!hasBlockScoped) {
|
||||
return node.body;
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
export var optional = true;
|
||||
|
||||
export function ExpressionStatement(node) {
|
||||
// remove consequence-less expressions such as local variables and literals
|
||||
// note: will remove directives
|
||||
//
|
||||
// var foo = true; foo; -> var foo = true;
|
||||
// "foo"; ->
|
||||
//
|
||||
|
||||
var expr = node.expression;
|
||||
if (t.isLiteral(expr) || (t.isIdentifier(node) && t.hasBinding(node.name))) {
|
||||
this.remove();
|
||||
export function ConditionalExpression(node) {
|
||||
var evaluateTest = t.evaluateTruthy(node.test);
|
||||
if (evaluateTest === true) {
|
||||
return node.consequent;
|
||||
} else if (evaluateTest === false) {
|
||||
return node.alternate;
|
||||
}
|
||||
}
|
||||
|
||||
export var IfStatement = {
|
||||
exit(node) {
|
||||
// todo: in scenarios where we can just return the consequent or
|
||||
// alternate we should drop the block statement if it contains no
|
||||
// block scoped variables
|
||||
|
||||
var consequent = node.consequent;
|
||||
var alternate = node.alternate;
|
||||
var test = node.test;
|
||||
|
||||
var evaluateTest = t.evaluateTruthy(test);
|
||||
|
||||
// we can check if a test will be truthy 100% and if so then we can inline
|
||||
// the consequent and completely ignore the alternate
|
||||
//
|
||||
@@ -33,8 +43,8 @@ export var IfStatement = {
|
||||
// if ("foo") { foo; } -> { foo; }
|
||||
//
|
||||
|
||||
if (t.isLiteral(test) && test.value) {
|
||||
return consequent;
|
||||
if (evaluateTest === true) {
|
||||
return toStatements(consequent);
|
||||
}
|
||||
|
||||
// we can check if a test will be falsy 100% and if so we can inline the
|
||||
@@ -44,9 +54,9 @@ export var IfStatement = {
|
||||
// if ("") { bar; } ->
|
||||
//
|
||||
|
||||
if (t.isFalsyExpression(test)) {
|
||||
if (evaluateTest === false) {
|
||||
if (alternate) {
|
||||
return alternate;
|
||||
return toStatements(alternate);
|
||||
} else {
|
||||
return this.remove();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import t from "../../../types";
|
||||
|
||||
export var optional = true;
|
||||
|
||||
var match = t.buildMatchMemberExpression("process.env");
|
||||
|
||||
export function MemberExpression(node) {
|
||||
if (match(node.object)) {
|
||||
var key = t.toComputedKey(node, node.property);
|
||||
if (t.isLiteral(key)) {
|
||||
return t.valueToNode(process.env[key.value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import t from "../../../types";
|
||||
|
||||
export var optional = true;
|
||||
|
||||
export function Expression(node) {
|
||||
var res = t.evaluate(node);
|
||||
if (res.confident) return t.valueToNode(res.value);
|
||||
}
|
||||
@@ -3,11 +3,12 @@ import t from "../../../types";
|
||||
|
||||
export { isFor as check } from "../../../types";
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
var declar = left.declarations[0];
|
||||
if (declar.init) throw file.errorWithNode(declar, messages.get("noAssignmentsInForHead"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { ForOfStatement as ForInStatement };
|
||||
|
||||
@@ -4,9 +4,10 @@ export function check(node) {
|
||||
return node.kind === "set";
|
||||
}
|
||||
|
||||
exports.MethodDefinition =
|
||||
exports.Property = function (node, parent, scope, file) {
|
||||
export function Property(node, parent, scope, file) {
|
||||
if (node.kind === "set" && node.value.params.length !== 1) {
|
||||
throw file.errorWithNode(node.value, messages.get("settersInvalidParamLength"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { Property as MethodDefinition };
|
||||
|
||||
@@ -43,7 +43,7 @@ export default class TraversalConext {
|
||||
if (this.shouldFlatten) {
|
||||
node[key] = flatten(node[key]);
|
||||
|
||||
if (key === "body") {
|
||||
if (key === "body" || key === "expressions") {
|
||||
// we can safely compact this
|
||||
node[key] = compact(node[key]);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ traverse.explode = function (obj) {
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
for (var i = 0; i < aliases.length; i++) {
|
||||
obj[aliases[i]] = fns;
|
||||
obj[aliases[i]] ||= fns;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ export default class Scope {
|
||||
var info = this.getBindingInfo(name);
|
||||
if (!info) return;
|
||||
|
||||
info.identifier.typeAnnotation = info.typeAnnotation = type;
|
||||
info.typeAnnotation = type;
|
||||
}
|
||||
|
||||
getTypeAnnotation(name, id, node) {
|
||||
|
||||
@@ -71,6 +71,39 @@
|
||||
"JSXMemberExpression": ["Expression"],
|
||||
"YieldExpression": ["Expression"],
|
||||
|
||||
"AnyTypeAnnotation": ["Flow"],
|
||||
"ArrayTypeAnnotation": ["Flow"],
|
||||
"BooleanTypeAnnotation": ["Flow"],
|
||||
"ClassImplements": ["Flow"],
|
||||
"DeclareClass": ["Flow"],
|
||||
"DeclareFunction": ["Flow"],
|
||||
"DeclareModule": ["Flow"],
|
||||
"DeclareVariable": ["Flow"],
|
||||
"FunctionTypeAnnotation": ["Flow"],
|
||||
"FunctionTypeParam": ["Flow"],
|
||||
"GenericTypeAnnotation": ["Flow"],
|
||||
"InterfaceExtends": ["Flow"],
|
||||
"InterfaceDeclaration": ["Flow"],
|
||||
"IntersectionTypeAnnotation": ["Flow"],
|
||||
"NullableTypeAnnotation": ["Flow"],
|
||||
"NumberTypeAnnotation": ["Flow"],
|
||||
"StringLiteralTypeAnnotation": ["Flow"],
|
||||
"StringTypeAnnotation": ["Flow"],
|
||||
"TupleTypeAnnotation": ["Flow"],
|
||||
"TypeofTypeAnnotation": ["Flow"],
|
||||
"TypeAlias": ["Flow"],
|
||||
"TypeAnnotation": ["Flow"],
|
||||
"TypeCastExpression": ["Flow"],
|
||||
"TypeParameterDeclaration": ["Flow"],
|
||||
"TypeParameterInstantiation": ["Flow"],
|
||||
"ObjectTypeAnnotation": ["Flow"],
|
||||
"ObjectTypeCallProperty": ["Flow"],
|
||||
"ObjectTypeIndexer": ["Flow"],
|
||||
"ObjectTypeProperty": ["Flow"],
|
||||
"QualifiedTypeIdentifier": ["Flow"],
|
||||
"UnionTypeAnnotation": ["Flow"],
|
||||
"VoidTypeAnnotation": ["Flow"],
|
||||
|
||||
"JSXAttribute": ["JSX"],
|
||||
"JSXClosingElement": ["JSX"],
|
||||
"JSXElement": ["JSX", "Expression"],
|
||||
|
||||
@@ -84,6 +84,11 @@
|
||||
"name": null
|
||||
},
|
||||
|
||||
"LabeledStatement": {
|
||||
"label": null,
|
||||
"body": null
|
||||
},
|
||||
|
||||
"Literal": {
|
||||
"value": null
|
||||
},
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import toFastProperties from "../helpers/to-fast-properties";
|
||||
import isPlainObject from "lodash/lang/isPlainObject";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import isRegExp from "lodash/lang/isRegExp";
|
||||
import isString from "lodash/lang/isString";
|
||||
import compact from "lodash/array/compact";
|
||||
import esutils from "esutils";
|
||||
@@ -709,6 +712,10 @@ t.inherits = function (child, parent) {
|
||||
child.start = parent.start;
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
|
||||
child.typeAnnotation = parent.typeAnnotation;
|
||||
child.returnType = parent.returnType;
|
||||
|
||||
t.inheritsComments(child, parent);
|
||||
return child;
|
||||
};
|
||||
@@ -800,5 +807,178 @@ t.isScope = function (node, parent) {
|
||||
return t.isScopable(node);
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk the input `node` and statically evaluate if it's truthy.
|
||||
*
|
||||
* Returning `true` when we're sure that the expression will evaluate to a
|
||||
* truthy value, `false` if we're sure that it will evaluate to a falsy
|
||||
* value and `undefined` if we aren't sure. Because of this please do not
|
||||
* rely on coercion when using this method and check with === if it's false.
|
||||
*
|
||||
* For example do:
|
||||
*
|
||||
* if (t.evaluateTruthy(node) === false) falsyLogic();
|
||||
*
|
||||
* **AND NOT**
|
||||
*
|
||||
* if (!t.evaluateTruthy(node)) falsyLogic();
|
||||
*
|
||||
* @param {Node} node
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
t.evaluateTruthy = function (node) {
|
||||
var res = t.evaluate(node);
|
||||
if (res.confident) return !!res.value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walk the input `node` and statically evaluate it.
|
||||
*
|
||||
* Returns an pbject in the form `{ confident, value }`. `confident` indicates
|
||||
* whether or not we had to drop out of evaluating the expression because of
|
||||
* hitting an unknown node that we couldn't confidently find the value of.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* t.evaluate(parse("5 + 5")) // { confident: true, value: 10 }
|
||||
* t.evaluate(parse("!true")) // { confident: true, value: false }
|
||||
* t.evaluate(parse("foo + foo")) // { confident: false, value: undefined }
|
||||
*
|
||||
* @param {Node} node
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
t.evaluate = function (node) {
|
||||
var confident = true;
|
||||
|
||||
var value = evaluate(node);
|
||||
if (!confident) value = undefined;
|
||||
return {
|
||||
confident: confident,
|
||||
value: value
|
||||
};
|
||||
|
||||
function evaluate(node) {
|
||||
if (!confident) return;
|
||||
|
||||
if (t.isSequenceExpression(node)) {
|
||||
return evaluate(node.expressions[node.expressions.length - 1]);
|
||||
}
|
||||
|
||||
if (t.isLiteral(node)) {
|
||||
if (node.regex && node.value === null) {
|
||||
// we have a regex and we can't represent it natively
|
||||
} else {
|
||||
return node.value;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isConditionalExpression(node)) {
|
||||
if (evaluate(node.test)) {
|
||||
return evaluate(node.consequent);
|
||||
} else {
|
||||
return evaluate(node.alternate);
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node, { name: "undefined" })) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (t.isUnaryExpression(node, { prefix: true })) {
|
||||
switch (node.operator) {
|
||||
case "void": return undefined;
|
||||
case "!": return !evaluate(node.argument);
|
||||
case "+": return +evaluate(node.argument);
|
||||
case "-": return -evaluate(node.argument);
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isArrayExpression(node)) {
|
||||
// possible perf issues - could deopt on X elements
|
||||
var values = [];
|
||||
for (var i = 0; i < node.elements.length; i++) {
|
||||
values.push(evaluate(node.elements[i]));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
if (t.isObjectExpression(node)) {
|
||||
// todo: deopt on mutable computed property keys etc
|
||||
}
|
||||
|
||||
if (t.isLogicalExpression(node)) {
|
||||
var left = evaluate(node.left);
|
||||
var right = evaluate(node.right);
|
||||
|
||||
switch (node.operator) {
|
||||
case "||": return left || right;
|
||||
case "&&": return left && right;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isBinaryExpression(node)) {
|
||||
var left = evaluate(node.left);
|
||||
var right = evaluate(node.right);
|
||||
|
||||
switch (node.operator) {
|
||||
case "-": return left - right;
|
||||
case "+": return left + right;
|
||||
case "/": return left / right;
|
||||
case "*": return left * right;
|
||||
case "%": return left % right;
|
||||
case "<": return left < right;
|
||||
case ">": return left > right;
|
||||
case "<=": return left <= right;
|
||||
case ">=": return left >= right;
|
||||
case "==": return left == right;
|
||||
case "!=": return left != right;
|
||||
case "===": return left === right;
|
||||
case "!==": return left !== right;
|
||||
}
|
||||
}
|
||||
|
||||
confident = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @param value
|
||||
* @returns {Node}
|
||||
*/
|
||||
|
||||
t.valueToNode = function (value) {
|
||||
if (value === undefined) {
|
||||
return t.identifier("undefined");
|
||||
}
|
||||
|
||||
if (value === true || value === false || value === null || isString(value) || isNumber(value) || isRegExp(value)) {
|
||||
return t.literal(value);
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return t.arrayExpression(value.map(t.valueToNode));
|
||||
}
|
||||
|
||||
if (isPlainObject(value)) {
|
||||
var props = [];
|
||||
for (var key in value) {
|
||||
var nodeKey;
|
||||
if (t.isValidIdentifier(key)) {
|
||||
nodeKey = t.identifier(key);
|
||||
} else {
|
||||
nodeKey = t.literal(key);
|
||||
}
|
||||
props.push(t.property("init", nodeKey, t.valueToNode(value[key])));
|
||||
}
|
||||
return t.objectExpression(props);
|
||||
}
|
||||
|
||||
throw new Error("don't know how to turn this value into a node");
|
||||
};
|
||||
|
||||
toFastProperties(t);
|
||||
toFastProperties(t.VISITOR_KEYS);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ArrayExpression": ["elements"],
|
||||
"ArrayPattern": ["elements"],
|
||||
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
|
||||
"ArrayPattern": ["elements", "typeAnnotation"],
|
||||
"ArrowFunctionExpression": ["params", "defaults", "rest", "body", "returnType"],
|
||||
"AssignmentExpression": ["left", "right"],
|
||||
"AssignmentPattern": ["left", "right"],
|
||||
"AwaitExpression": ["argument"],
|
||||
@@ -13,8 +13,8 @@
|
||||
"CallExpression": ["callee", "arguments"],
|
||||
"CatchClause": ["param", "body"],
|
||||
"ClassBody": ["body"],
|
||||
"ClassDeclaration": ["id", "body", "superClass"],
|
||||
"ClassExpression": ["id", "body", "superClass"],
|
||||
"ClassDeclaration": ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements"],
|
||||
"ClassExpression": ["id", "body", "superClass", "typeParameters", "superTypeParameters", "implements"],
|
||||
"ComprehensionBlock": ["left", "right", "body"],
|
||||
"ComprehensionExpression": ["filter", "blocks", "body"],
|
||||
"ConditionalExpression": ["test", "consequent", "alternate"],
|
||||
@@ -30,9 +30,9 @@
|
||||
"ForInStatement": ["left", "right", "body"],
|
||||
"ForOfStatement": ["left", "right", "body"],
|
||||
"ForStatement": ["init", "test", "update", "body"],
|
||||
"FunctionDeclaration": ["id", "params", "defaults", "rest", "body"],
|
||||
"FunctionExpression": ["id", "params", "defaults", "rest", "body"],
|
||||
"Identifier": [],
|
||||
"FunctionDeclaration": ["id", "params", "defaults", "rest", "body", "returnType", "typeParameters"],
|
||||
"FunctionExpression": ["id", "params", "defaults", "rest", "body", "returnType", "typeParameters"],
|
||||
"Identifier": ["typeAnnotation"],
|
||||
"IfStatement": ["test", "consequent", "alternate"],
|
||||
"ImportBatchSpecifier": ["id"],
|
||||
"ImportDeclaration": ["specifiers", "source"],
|
||||
@@ -44,11 +44,11 @@
|
||||
"MethodDefinition": ["key", "value"],
|
||||
"NewExpression": ["callee", "arguments"],
|
||||
"ObjectExpression": ["properties"],
|
||||
"ObjectPattern": ["properties"],
|
||||
"ObjectPattern": ["properties", "typeAnnotation"],
|
||||
"PrivateDeclaration": ["declarations"],
|
||||
"Program": ["body"],
|
||||
"Property": ["key", "value"],
|
||||
"RestElement": ["argument"],
|
||||
"RestElement": ["argument", "typeAnnotation"],
|
||||
"ReturnStatement": ["argument"],
|
||||
"SequenceExpression": ["expressions"],
|
||||
"SpreadElement": ["argument"],
|
||||
@@ -71,36 +71,37 @@
|
||||
"YieldExpression": ["argument"],
|
||||
|
||||
"AnyTypeAnnotation": [],
|
||||
"ArrayTypeAnnotation": [],
|
||||
"ArrayTypeAnnotation": ["elementType"],
|
||||
"BooleanTypeAnnotation": [],
|
||||
"ClassProperty": ["key", "value"],
|
||||
"DeclareClass": [],
|
||||
"DeclareFunction": [],
|
||||
"DeclareModule": [],
|
||||
"DeclareVariable": [],
|
||||
"FunctionTypeAnnotation": [],
|
||||
"FunctionTypeParam": [],
|
||||
"GenericTypeAnnotation": [],
|
||||
"InterfaceExtends": [],
|
||||
"InterfaceDeclaration": [],
|
||||
"IntersectionTypeAnnotation": [],
|
||||
"NullableTypeAnnotation": [],
|
||||
"ClassImplements": ["id", "typeParameters"],
|
||||
"ClassProperty": ["key", "value", "typeAnnotation"],
|
||||
"DeclareClass": ["id", "typeParameters", "extends", "body"],
|
||||
"DeclareFunction": ["id"],
|
||||
"DeclareModule": ["id", "body"],
|
||||
"DeclareVariable": ["id"],
|
||||
"FunctionTypeAnnotation": ["typeParameters", "params", "rest", "returnType"],
|
||||
"FunctionTypeParam": ["name", "typeAnnotation"],
|
||||
"GenericTypeAnnotation": ["id", "typeParameters"],
|
||||
"InterfaceExtends": ["id", "typeParameters"],
|
||||
"InterfaceDeclaration": ["id", "typeParameters", "extends", "body"],
|
||||
"IntersectionTypeAnnotation": ["types"],
|
||||
"NullableTypeAnnotation": ["typeAnnotation"],
|
||||
"NumberTypeAnnotation": [],
|
||||
"StringLiteralTypeAnnotation": [],
|
||||
"StringTypeAnnotation": [],
|
||||
"TupleTypeAnnotation": [],
|
||||
"TypeofTypeAnnotation": [],
|
||||
"TypeAlias": [],
|
||||
"TypeAnnotation": [],
|
||||
"TupleTypeAnnotation": ["types"],
|
||||
"TypeofTypeAnnotation": ["argument"],
|
||||
"TypeAlias": ["id", "typeParameters", "right"],
|
||||
"TypeAnnotation": ["typeAnnotation"],
|
||||
"TypeCastExpression": ["expression"],
|
||||
"TypeParameterDeclaration": [],
|
||||
"TypeParameterInstantiation": [],
|
||||
"ObjectTypeAnnotation": [],
|
||||
"ObjectTypeCallProperty": [],
|
||||
"ObjectTypeIndexer": [],
|
||||
"ObjectTypeProperty": [],
|
||||
"QualifiedTypeIdentifier": [],
|
||||
"UnionTypeAnnotation": [],
|
||||
"TypeParameterDeclaration": ["params"],
|
||||
"TypeParameterInstantiation": ["params"],
|
||||
"ObjectTypeAnnotation": ["key", "value"],
|
||||
"ObjectTypeCallProperty": ["value"],
|
||||
"ObjectTypeIndexer": ["id", "key", "value"],
|
||||
"ObjectTypeProperty": ["key", "value"],
|
||||
"QualifiedTypeIdentifier": ["id", "qualification"],
|
||||
"UnionTypeAnnotation": ["types"],
|
||||
"VoidTypeAnnotation": [],
|
||||
|
||||
"JSXAttribute": ["name", "value"],
|
||||
|
||||
@@ -15,7 +15,7 @@ import has from "lodash/object/has";
|
||||
import fs from "fs";
|
||||
import t from "./types";
|
||||
|
||||
export { inherits } from "util";
|
||||
export { inherits, inspect } from "util";
|
||||
|
||||
export var debug = buildDebug("babel");
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.esvalid = function (ast, code, loc) {
|
||||
if (errors.length) {
|
||||
var msg = [];
|
||||
_.each(errors, function (err) {
|
||||
msg.push(err.message + " - " + JSON.stringify(err.node));
|
||||
msg.push(err.message + " - " + util.inspect(err.node));
|
||||
});
|
||||
throw new Error(loc + ": " + msg.join(". ") + "\n" + code);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ var run = function (task, done) {
|
||||
if (!execCode || actualCode) {
|
||||
result = transform(actualCode, getOpts(actual));
|
||||
checkAst(result, actual);
|
||||
actualCode = result.code;
|
||||
actualCode = result.code.trim();
|
||||
|
||||
try {
|
||||
chai.expect(actualCode).to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
|
||||
|
||||
6
test/fixtures/generation/flow/array-types/actual.js
vendored
Normal file
6
test/fixtures/generation/flow/array-types/actual.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a: number[];
|
||||
var a: ?number[];
|
||||
var a: (?number)[];
|
||||
var a: () => number[];
|
||||
var a: (() => number)[];
|
||||
var a: typeof A[];
|
||||
6
test/fixtures/generation/flow/array-types/expected.js
vendored
Normal file
6
test/fixtures/generation/flow/array-types/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a: number[];
|
||||
var a: ?number[];
|
||||
var a: (?number)[];
|
||||
var a: () => number[];
|
||||
var a: (() => number)[];
|
||||
var a: typeof A[];
|
||||
5
test/fixtures/generation/flow/call-properties/actual.js
vendored
Normal file
5
test/fixtures/generation/flow/call-properties/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var a: { (): number };
|
||||
var a: { (): number; };
|
||||
var a: { (): number; y: string; (x: string): string };
|
||||
var a: { <T>(x: T): number; };
|
||||
interface A { (): number; };
|
||||
5
test/fixtures/generation/flow/call-properties/expected.js
vendored
Normal file
5
test/fixtures/generation/flow/call-properties/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var a: { (): number };
|
||||
var a: { (): number };
|
||||
var a: { y: string; (): number; (x: string): string };
|
||||
var a: { <T>(x: T): number };
|
||||
interface A { (): number };
|
||||
5
test/fixtures/generation/flow/declare-module/actual.js
vendored
Normal file
5
test/fixtures/generation/flow/declare-module/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module A {}
|
||||
declare module "./a/b.js" {}
|
||||
declare module A { declare var x: number; }
|
||||
declare module A { declare function foo(): number; }
|
||||
declare module A { declare class B { foo(): number; } }
|
||||
11
test/fixtures/generation/flow/declare-module/expected.js
vendored
Normal file
11
test/fixtures/generation/flow/declare-module/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare module A {}
|
||||
declare module "./a/b.js" {}
|
||||
declare module A {
|
||||
declare var x: number;
|
||||
}
|
||||
declare module A {
|
||||
declare function foo(): number;
|
||||
}
|
||||
declare module A {
|
||||
declare class B { foo(): number }
|
||||
}
|
||||
11
test/fixtures/generation/flow/declare-statements/actual.js
vendored
Normal file
11
test/fixtures/generation/flow/declare-statements/actual.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare var foo
|
||||
declare var foo;
|
||||
declare function foo(): void
|
||||
declare function foo(): void;
|
||||
declare function foo<T>(): void;
|
||||
declare function foo(x: number, y: string): void;
|
||||
declare class A {}
|
||||
declare class A<T> extends B<T> { x: number }
|
||||
declare class A { static foo(): number; static x : string }
|
||||
declare class A { static [ indexer: number]: string }
|
||||
declare class A { static () : number }
|
||||
11
test/fixtures/generation/flow/declare-statements/expected.js
vendored
Normal file
11
test/fixtures/generation/flow/declare-statements/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare var foo;
|
||||
declare var foo;
|
||||
declare function foo(): void;
|
||||
declare function foo(): void;
|
||||
declare function foo<T>(): void;
|
||||
declare function foo(x: number, y: string): void;
|
||||
declare class A {}
|
||||
declare class A<T> extends B<T> { x: number }
|
||||
declare class A { static foo(): number; static x: string }
|
||||
declare class A { static [indexer: number]: string }
|
||||
declare class A { static (): number }
|
||||
9
test/fixtures/generation/flow/interfaces-module-and-script/actual.js
vendored
Normal file
9
test/fixtures/generation/flow/interfaces-module-and-script/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
interface A {};
|
||||
interface A extends B {};
|
||||
interface A<T> extends B<T>, C<T> {};
|
||||
interface A { foo: () => number; };
|
||||
interface Dictionary { [index: string]: string; length: number; };
|
||||
class Foo implements Bar {}
|
||||
class Foo extends Bar implements Bat, Man<number> {}
|
||||
class Foo extends class Bar implements Bat {} {}
|
||||
class Foo extends class Bar implements Bat {} implements Man {}
|
||||
9
test/fixtures/generation/flow/interfaces-module-and-script/expected.js
vendored
Normal file
9
test/fixtures/generation/flow/interfaces-module-and-script/expected.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
interface A {};
|
||||
interface A extends B {};
|
||||
interface A<T> extends B<T>, C<T> {};
|
||||
interface A { foo(): number };
|
||||
interface Dictionary { length: number; [index: string]: string };
|
||||
class Foo implements Bar {}
|
||||
class Foo extends Bar implements Bat, Man<number> {}
|
||||
class Foo extends class Bar implements Bat {} {}
|
||||
class Foo extends class Bar implements Bat {} implements Man {}
|
||||
4
test/fixtures/generation/flow/qualified-generic-type/actual.js
vendored
Normal file
4
test/fixtures/generation/flow/qualified-generic-type/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: A.B;
|
||||
var a: A.B.C;
|
||||
var a: A.B<T>;
|
||||
var a: typeof A.B<T>;
|
||||
4
test/fixtures/generation/flow/qualified-generic-type/expected.js
vendored
Normal file
4
test/fixtures/generation/flow/qualified-generic-type/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: A.B;
|
||||
var a: A.B.C;
|
||||
var a: A.B<T>;
|
||||
var a: typeof A.B<T>;
|
||||
2
test/fixtures/generation/flow/string-literal-types/actual.js
vendored
Normal file
2
test/fixtures/generation/flow/string-literal-types/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
function createElement(tagName: 'div'): HTMLDivElement {}
|
||||
2
test/fixtures/generation/flow/string-literal-types/expected.js
vendored
Normal file
2
test/fixtures/generation/flow/string-literal-types/expected.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
4
test/fixtures/generation/flow/tuples/actual.js
vendored
Normal file
4
test/fixtures/generation/flow/tuples/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: [] = [];
|
||||
var a: [Foo<T>] = [foo];
|
||||
var a: [number,] = [123,];
|
||||
var a: [number, string] = [123, "duck"];
|
||||
4
test/fixtures/generation/flow/tuples/expected.js
vendored
Normal file
4
test/fixtures/generation/flow/tuples/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: [] = [];
|
||||
var a: [Foo<T>] = [foo];
|
||||
var a: [number] = [123];
|
||||
var a: [number, string] = [123, "duck"];
|
||||
3
test/fixtures/generation/flow/type-alias/actual.js
vendored
Normal file
3
test/fixtures/generation/flow/type-alias/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type FBID = number;
|
||||
type Foo<T> = Bar<T>
|
||||
export type Foo = number;
|
||||
3
test/fixtures/generation/flow/type-alias/expected.js
vendored
Normal file
3
test/fixtures/generation/flow/type-alias/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type FBID = number;
|
||||
type Foo<T> = Bar<T>;
|
||||
export type Foo = number;
|
||||
97
test/fixtures/generation/flow/type-annotations/actual.js
vendored
Normal file
97
test/fixtures/generation/flow/type-annotations/actual.js
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
function foo(numVal: any) {}
|
||||
function foo(numVal: number) {}
|
||||
function foo(numVal: number, strVal: string) {}
|
||||
function foo(numVal: number, untypedVal) {}
|
||||
function foo(untypedVal, numVal: number) {}
|
||||
function foo(nullableNum: ?number) {}
|
||||
function foo(callback: () => void) {}
|
||||
function foo(callback: () => number) {}
|
||||
function foo(callback: (_: bool) => number) {}
|
||||
function foo(callback: (_1: bool, _2: string) => number) {}
|
||||
function foo(callback: (_1: bool, ...foo: Array<number>) => number) {}
|
||||
function foo(): number{}
|
||||
function foo():() => void {}
|
||||
function foo():(_:bool) => number{}
|
||||
function foo():(_?:bool) => number{}
|
||||
function foo(): {} {}
|
||||
function foo<T>() {}
|
||||
function foo<T,S>() {}
|
||||
a = function<T,S>() {};
|
||||
a = { set fooProp(value: number) {} };
|
||||
a = { set fooProp(value: number): void {} };
|
||||
a = { get fooProp():number{} };
|
||||
a = { id<T>(x: T): T {} };
|
||||
a = { *id<T>(x: T): T {} };
|
||||
a = { async id<T>(x: T): T {} };
|
||||
a = { 123<T>(x: T): T {} };
|
||||
class Foo {
|
||||
set fooProp(value: number) {}
|
||||
}
|
||||
class Foo {
|
||||
set fooProp(value: number): void {}
|
||||
}
|
||||
class Foo {
|
||||
get fooProp(): number {}
|
||||
}
|
||||
var numVal: number;
|
||||
var numVal: number = otherNumVal;
|
||||
var a: { numVal: number };
|
||||
var a: { numVal: number; };
|
||||
var a: { numVal: number; [indexer: string]: number };
|
||||
var a: ?{ numVal: number };
|
||||
var a: { numVal: number; strVal: string }
|
||||
var a: { subObj: {strVal: string} }
|
||||
var a: { subObj: ?{strVal: string} }
|
||||
var a: { param1: number; param2: string }
|
||||
var a: { param1: number; param2?: string }
|
||||
var a: { [a: number]: string; [b: number]: string; };
|
||||
var a: { add(x: number, ...y: Array<string>): void };
|
||||
var a: { id<T>(x: T): T; };
|
||||
var a:Array<number> = [1, 2, 3]
|
||||
a = class Foo<T> {}
|
||||
a = class Foo<T> extends Bar<T> {}
|
||||
class Foo<T> {}
|
||||
class Foo<T> extends Bar<T> {}
|
||||
class Foo<T> extends mixin(Bar) {}
|
||||
class Foo<T> {
|
||||
bar<U>():number { return 42; }
|
||||
}
|
||||
class Foo {
|
||||
"bar"<T>() {}
|
||||
}
|
||||
function foo(requiredParam, optParam?) {}
|
||||
class Foo {
|
||||
prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
class Foo {
|
||||
static prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
var x: number | string = 4;
|
||||
class Array { concat(items:number | string) {}; }
|
||||
var x: () => number | () => string = fn;
|
||||
var x: typeof Y = Y;
|
||||
var x: typeof Y | number = Y;
|
||||
var {x}: {x: string; } = { x: "hello" };
|
||||
var {x}: {x: string } = { x: "hello" };
|
||||
var [x]: Array<string> = [ "hello" ];
|
||||
function foo({x}: { x: string; }) {}
|
||||
function foo([x]: Array<string>) {}
|
||||
function foo(...rest: Array<number>) {}
|
||||
(function (...rest: Array<number>) {});
|
||||
((...rest: Array<number>) => rest);
|
||||
var a: Map<string, Array<string> >
|
||||
var a: Map<string, Array<string>>
|
||||
var a: number[]
|
||||
var a: ?string[]
|
||||
var a: Promise<bool>[]
|
||||
var a:(...rest:Array<number>) => number
|
||||
var identity: <T>(x: T) => T
|
||||
var identity: <T>(x: T, ...y:T[]) => T
|
||||
import type foo from "bar";
|
||||
import type { foo, bar } from "baz";
|
||||
import type { foo as bar } from "baz";
|
||||
import type from "foo";
|
||||
import type, { foo } from "bar";
|
||||
import type * as namespace from "bar";
|
||||
101
test/fixtures/generation/flow/type-annotations/expected.js
vendored
Normal file
101
test/fixtures/generation/flow/type-annotations/expected.js
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
function foo(numVal: any) {}
|
||||
function foo(numVal: number) {}
|
||||
function foo(numVal: number, strVal: string) {}
|
||||
function foo(numVal: number, untypedVal) {}
|
||||
function foo(untypedVal, numVal: number) {}
|
||||
function foo(nullableNum: ?number) {}
|
||||
function foo(callback: () => void) {}
|
||||
function foo(callback: () => number) {}
|
||||
function foo(callback: (_: bool) => number) {}
|
||||
function foo(callback: (_1: bool, _2: string) => number) {}
|
||||
function foo(callback: (_1: bool, ...foo: Array<number>) => number) {}
|
||||
function foo(): number {}
|
||||
function foo(): () => void {}
|
||||
function foo(): (_: bool) => number {}
|
||||
function foo(): (_?: bool) => number {}
|
||||
function foo(): {} {}
|
||||
function foo<T>() {}
|
||||
function foo<T, S>() {}
|
||||
a = function <T, S>() {};
|
||||
a = { set fooProp(value: number) {} };
|
||||
a = { set fooProp(value: number): void {} };
|
||||
a = { get fooProp(): number {} };
|
||||
a = { id<T>(x: T): T {} };
|
||||
a = { *id<T>(x: T): T {} };
|
||||
a = { async id<T>(x: T): T {} };
|
||||
a = { 123<T>(x: T): T {} };
|
||||
class Foo {
|
||||
set fooProp(value: number) {}
|
||||
}
|
||||
class Foo {
|
||||
set fooProp(value: number): void {}
|
||||
}
|
||||
class Foo {
|
||||
get fooProp(): number {}
|
||||
}
|
||||
var numVal: number;
|
||||
var numVal: number = otherNumVal;
|
||||
var a: { numVal: number };
|
||||
var a: { numVal: number };
|
||||
var a: { numVal: number; [indexer: string]: number };
|
||||
var a: ?{ numVal: number };
|
||||
var a: { numVal: number; strVal: string };
|
||||
var a: { subObj: { strVal: string } };
|
||||
var a: { subObj: ?{ strVal: string } };
|
||||
var a: { param1: number; param2: string };
|
||||
var a: { param1: number; param2?: string };
|
||||
var a: { [a: number]: string; [b: number]: string };
|
||||
var a: { add(x: number, ...y: Array<string>): void };
|
||||
var a: { id<T>(x: T): T };
|
||||
var a: Array<number> = [1, 2, 3];
|
||||
a = class Foo<T> {};
|
||||
a = class Foo<T> extends Bar<T> {};
|
||||
class Foo<T> {}
|
||||
class Foo<T> extends Bar<T> {}
|
||||
class Foo<T> extends mixin(Bar) {}
|
||||
class Foo<T> {
|
||||
bar<U>(): number {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
class Foo {
|
||||
"bar"<T>() {}
|
||||
}
|
||||
function foo(requiredParam, optParam?) {}
|
||||
class Foo {
|
||||
prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
class Foo {
|
||||
static prop1: string;
|
||||
prop2: number;
|
||||
}
|
||||
var x: number | string = 4;
|
||||
class Array {
|
||||
concat(items: number | string) {}
|
||||
}
|
||||
var x: () => number | () => string = fn;
|
||||
var x: typeof Y = Y;
|
||||
var x: typeof Y | number = Y;
|
||||
var { x }: { x: string } = { x: "hello" };
|
||||
var { x }: { x: string } = { x: "hello" };
|
||||
var [x]: Array<string> = ["hello"];
|
||||
function foo({ x }: { x: string }) {}
|
||||
function foo([x]: Array<string>) {}
|
||||
function foo(...rest: Array<number>) {}
|
||||
(function (...rest: Array<number>) {});
|
||||
(...rest: Array<number>) => rest;
|
||||
var a: Map<string, Array<string>>;
|
||||
var a: Map<string, Array<string>>;
|
||||
var a: number[];
|
||||
var a: ?string[];
|
||||
var a: Promise<bool>[];
|
||||
var a: (...rest: Array<number>) => number;
|
||||
var identity: <T>(x: T) => T;
|
||||
var identity: <T>(x: T, ...y: T[]) => T;
|
||||
import type foo from "bar";
|
||||
import type { foo, bar } from "baz";
|
||||
import type { foo as bar } from "baz";
|
||||
import type from "foo";
|
||||
import type, { foo } from "bar";
|
||||
import type * as namespace from "bar";
|
||||
4
test/fixtures/generation/flow/typecasts/actual.js
vendored
Normal file
4
test/fixtures/generation/flow/typecasts/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
(xxx: number);
|
||||
({ xxx: 0, yyy: "hey" }: { xxx: number; yyy: string });
|
||||
(xxx => xxx + 1: (xxx: number) => number);
|
||||
((xxx: number), (yyy: string));
|
||||
4
test/fixtures/generation/flow/typecasts/expected.js
vendored
Normal file
4
test/fixtures/generation/flow/typecasts/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
(xxx: number);
|
||||
({ xxx: 0, yyy: "hey" }: { xxx: number; yyy: string });
|
||||
(xxx => xxx + 1: (xxx: number) => number);
|
||||
(xxx: number), (yyy: string);
|
||||
5
test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/actual.js
vendored
Normal file
5
test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
let a = 1;
|
||||
for (let a = 1; a < 100; a++) {
|
||||
items.forEach(item => a);
|
||||
}
|
||||
console.log(a);
|
||||
11
test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/expected.js
vendored
Normal file
11
test/fixtures/transformation/es6-block-scoping/wrap-closure-shadow-variables/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var a = 1;
|
||||
for (var _a = 1; _a < 100; _a++) {
|
||||
(function (_a) {
|
||||
items.forEach(function (item) {
|
||||
return _a;
|
||||
});
|
||||
})(_a);
|
||||
}
|
||||
console.log(a);
|
||||
@@ -2,89 +2,89 @@
|
||||
|
||||
// labels
|
||||
|
||||
foo: {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
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 x = _step.value;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}foo: {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}foo: {
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator3 = foo()[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
var x = _step3.value;
|
||||
if (_iterator3["return"]) _iterator3["return"]();
|
||||
while (true) {
|
||||
if (_iterator["return"]) _iterator["return"]();
|
||||
|
||||
break foo;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"]) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3["return"]) {
|
||||
_iterator3["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
} // basic
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -137,4 +137,4 @@ try {
|
||||
throw _iteratorError5;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,18 @@ var concat = (...arrs) => {
|
||||
var x = arrs[0];
|
||||
var y = arrs[1];
|
||||
};
|
||||
|
||||
var somefun = function () {
|
||||
let get2ndArg = (a, b, ...args1) => {
|
||||
var _b = args1[0];
|
||||
let somef = (x, y, z, ...args2) => {
|
||||
var _a = args2[0];
|
||||
};
|
||||
let somefg = (c, d, e, f, ...args3) => {
|
||||
var _a = args3[0];
|
||||
};
|
||||
var _c = arguments[1];
|
||||
var _d = args1[1];
|
||||
};
|
||||
let get1stArg = (...args) => args[0];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
var _arguments = arguments;
|
||||
var concat = function () {
|
||||
var x = _arguments[0];
|
||||
var y = _arguments[1];
|
||||
var x = arguments[0];
|
||||
var y = arguments[1];
|
||||
};
|
||||
|
||||
var somefun = function somefun() {
|
||||
var _arguments = arguments;
|
||||
|
||||
var get2ndArg = function (a, b) {
|
||||
var _b = arguments[2];
|
||||
var somef = function (x, y, z) {
|
||||
var _a = arguments[3];
|
||||
};
|
||||
var somefg = function (c, d, e, f) {
|
||||
var _a = arguments[4];
|
||||
};
|
||||
var _c = _arguments[1];
|
||||
var _d = arguments[3];
|
||||
};
|
||||
var get1stArg = function () {
|
||||
return arguments[0];
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -8,17 +8,23 @@ var y = function (foo, ...bar) {
|
||||
};
|
||||
};
|
||||
|
||||
var b = function (x, y, ...args) {
|
||||
console.log(args[0]);
|
||||
args.pop();
|
||||
console.log(args[1]);
|
||||
};
|
||||
|
||||
var z = function (foo, ...bar) {
|
||||
var x = function () {
|
||||
bar[1] = 5;
|
||||
};
|
||||
var x = function () {
|
||||
bar[1] = 5;
|
||||
};
|
||||
};
|
||||
|
||||
var a = function (foo, ...bar) {
|
||||
return bar.join(',');
|
||||
return bar.join(',');
|
||||
};
|
||||
|
||||
var b = function (foo, ...bar) {
|
||||
var join = "join";
|
||||
return bar[join];
|
||||
var join = "join";
|
||||
return bar[join];
|
||||
};
|
||||
|
||||
@@ -1,43 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
var x = function x(foo) {
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
console.log(bar);
|
||||
console.log(bar);
|
||||
};
|
||||
|
||||
var y = function y(foo) {
|
||||
var x = function z(bar) {
|
||||
bar[1] = 5;
|
||||
};
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
var x = function z(bar) {
|
||||
bar[1] = 5;
|
||||
};
|
||||
};
|
||||
|
||||
var b = function b(x, y) {
|
||||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
||||
args[_key - 2] = arguments[_key];
|
||||
}
|
||||
|
||||
console.log(args[0]);
|
||||
args.pop();
|
||||
console.log(args[1]);
|
||||
};
|
||||
|
||||
var z = function z(foo) {
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
var x = function x() {
|
||||
bar[1] = 5;
|
||||
};
|
||||
var x = function x() {
|
||||
bar[1] = 5;
|
||||
};
|
||||
};
|
||||
|
||||
var a = function a(foo) {
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
return bar.join(",");
|
||||
return bar.join(",");
|
||||
};
|
||||
|
||||
var b = function b(foo) {
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
for (var _len = arguments.length, bar = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
bar[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
var join = "join";
|
||||
return bar[join];
|
||||
var join = "join";
|
||||
return bar[join];
|
||||
};
|
||||
|
||||
|
||||
5
test/fixtures/transformation/flow/options.json
vendored
Normal file
5
test/fixtures/transformation/flow/options.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"experimental": true,
|
||||
"whitelist": ["flow"],
|
||||
"noCheckAst": true
|
||||
}
|
||||
6
test/fixtures/transformation/flow/strip-array-types/actual.js
vendored
Normal file
6
test/fixtures/transformation/flow/strip-array-types/actual.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a: number[];
|
||||
var a: ?number[];
|
||||
var a: (?number)[];
|
||||
var a: () => number[];
|
||||
var a: (() => number)[];
|
||||
var a: typeof A[];
|
||||
6
test/fixtures/transformation/flow/strip-array-types/expected.js
vendored
Normal file
6
test/fixtures/transformation/flow/strip-array-types/expected.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
5
test/fixtures/transformation/flow/strip-call-properties/actual.js
vendored
Normal file
5
test/fixtures/transformation/flow/strip-call-properties/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
var a: { (): number };
|
||||
var a: { (): number; };
|
||||
var a: { (): number; y: string; (x: string): string };
|
||||
var a: { <T>(x: T): number; };
|
||||
interface A { (): number; }
|
||||
4
test/fixtures/transformation/flow/strip-call-properties/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-call-properties/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
5
test/fixtures/transformation/flow/strip-declare-module/actual.js
vendored
Normal file
5
test/fixtures/transformation/flow/strip-declare-module/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module A {}
|
||||
declare module "./a/b.js" {}
|
||||
declare module A { declare var x: number; }
|
||||
declare module A { declare function foo(): number; }
|
||||
declare module A { declare class B { foo(): number; } }
|
||||
11
test/fixtures/transformation/flow/strip-declare-statements/actual.js
vendored
Normal file
11
test/fixtures/transformation/flow/strip-declare-statements/actual.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
declare var foo
|
||||
declare var foo;
|
||||
declare function foo(): void
|
||||
declare function foo(): void;
|
||||
declare function foo<T>(): void;
|
||||
declare function foo(x: number, y: string): void;
|
||||
declare class A {}
|
||||
declare class A<T> extends B<T> { x: number }
|
||||
declare class A { static foo(): number; static x : string }
|
||||
declare class A { static [ indexer: number]: string }
|
||||
declare class A { static () : number }
|
||||
9
test/fixtures/transformation/flow/strip-interfaces-module-and-script/actual.js
vendored
Normal file
9
test/fixtures/transformation/flow/strip-interfaces-module-and-script/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
interface A {}
|
||||
interface A extends B {}
|
||||
interface A<T> extends B<T>, C<T> {}
|
||||
interface A { foo: () => number; }
|
||||
interface Dictionary { [index: string]: string; length: number; }
|
||||
class Foo implements Bar {}
|
||||
class Foo2 extends Bar implements Bat, Man<number> {}
|
||||
class Foo3 extends class Bar implements Bat {} {}
|
||||
class Foo4 extends class Bar implements Bat {} implements Man {}
|
||||
4
test/fixtures/transformation/flow/strip-interfaces-module-and-script/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-interfaces-module-and-script/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Foo {}
|
||||
class Foo2 extends Bar {}
|
||||
class Foo3 extends class Bar {} {}
|
||||
class Foo4 extends class Bar {} {}
|
||||
4
test/fixtures/transformation/flow/strip-qualified-generic-type/actual.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-qualified-generic-type/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a: A.B;
|
||||
var a: A.B.C;
|
||||
var a: A.B<T>;
|
||||
var a: typeof A.B<T>;
|
||||
4
test/fixtures/transformation/flow/strip-qualified-generic-type/expected.js
vendored
Normal file
4
test/fixtures/transformation/flow/strip-qualified-generic-type/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
var a;
|
||||
2
test/fixtures/transformation/flow/strip-string-literal-types/actual.js
vendored
Normal file
2
test/fixtures/transformation/flow/strip-string-literal-types/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
function createElement(tagName: "div"): HTMLDivElement {}
|
||||
function createElement(tagName: 'div'): HTMLDivElement {}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user