Compare commits
97 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee46f45c90 | ||
|
|
c45ce61550 | ||
|
|
b36cf11ac8 | ||
|
|
dca0f72e4d | ||
|
|
68a99ed1e9 | ||
|
|
af4feb4d88 | ||
|
|
de1e965fec | ||
|
|
430c5df0e7 | ||
|
|
9b12f799f7 | ||
|
|
f3a9c6ee5d | ||
|
|
e0aceeafef | ||
|
|
7643d86047 | ||
|
|
98af01a73c | ||
|
|
e280a810c3 | ||
|
|
7a59575d1e | ||
|
|
b01d8448a0 | ||
|
|
9b3c8569f7 | ||
|
|
12104f822f | ||
|
|
b4cd2df745 | ||
|
|
887ffed84c | ||
|
|
9be3d9c8e1 | ||
|
|
9d3dff3b7a | ||
|
|
55114ec631 | ||
|
|
9c3d00d3c3 | ||
|
|
90b8826e73 | ||
|
|
65f39bbf6f | ||
|
|
e9eced846f | ||
|
|
a0befe349d | ||
|
|
04992effb3 | ||
|
|
9ae54d2a50 | ||
|
|
fe72a40159 | ||
|
|
ea510d09d0 | ||
|
|
375689a1ff | ||
|
|
9908e331b7 | ||
|
|
cd8655708d | ||
|
|
62b94f297a | ||
|
|
01d399ee3c | ||
|
|
30e3908484 | ||
|
|
ff12046009 | ||
|
|
1a058b4a6e | ||
|
|
02dfd18023 | ||
|
|
9ab7df5f47 | ||
|
|
7a5b140f92 | ||
|
|
6f83111c55 | ||
|
|
f3f60368da | ||
|
|
7a09640b20 | ||
|
|
2916d1262b | ||
|
|
741abb73d2 | ||
|
|
2e46755260 | ||
|
|
2cff9519e1 | ||
|
|
f9c2c6e988 | ||
|
|
5ae3dc01f1 | ||
|
|
af4fd69dd0 | ||
|
|
4d4493f325 | ||
|
|
e70d474b39 | ||
|
|
1b45f64858 | ||
|
|
b89cf6768f | ||
|
|
36ad1108b4 | ||
|
|
4c04371ea4 | ||
|
|
d3e385c554 | ||
|
|
6afcef9805 | ||
|
|
ed861e230b | ||
|
|
e15ced2922 | ||
|
|
93052e532f | ||
|
|
198d51ddaa | ||
|
|
8730b24def | ||
|
|
f09c0d5998 | ||
|
|
21e4481ab7 | ||
|
|
2f61754a24 | ||
|
|
3910d18bc9 | ||
|
|
583111ebfb | ||
|
|
1b15481460 | ||
|
|
fd9c98ff86 | ||
|
|
41b5607ef3 | ||
|
|
ae77ea807f | ||
|
|
ad44190c6b | ||
|
|
024e4454a1 | ||
|
|
14dddcda36 | ||
|
|
d4fb924b6a | ||
|
|
b02c97af60 | ||
|
|
cc611cb71c | ||
|
|
b8a01a9919 | ||
|
|
55c99661be | ||
|
|
1563b216df | ||
|
|
a9d4b485d9 | ||
|
|
360daa6267 | ||
|
|
724bf52929 | ||
|
|
7407b37bd9 | ||
|
|
da765cc4c1 | ||
|
|
4f862eee6e | ||
|
|
e05d7cf49a | ||
|
|
fd8e94a90f | ||
|
|
a6cf28c5b5 | ||
|
|
6b07b13a8e | ||
|
|
561c4dcc25 | ||
|
|
1a299b2bcc | ||
|
|
37f662d790 |
51
CHANGELOG.md
51
CHANGELOG.md
@@ -13,6 +13,57 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.4.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix bug where replacing variable declarations in the head of a `for` loop would turn them into `ExpressionStatement`s.
|
||||
* Fix renaming of assignment expressions that were non-identifiers ie. patterns.
|
||||
* Force space before `class` `id` to avoid breaking named classes when using `compact` mode.
|
||||
* Add assignment pattern explosion to avoid initial duplicate nodes.
|
||||
* Ignore this and arguments when performing TCO on shadowed functions.
|
||||
* **Polish**
|
||||
* Rename `sourceMapName` option to `sourceMapTarget`. Thanks [@getify](https://github.com/getify)!
|
||||
* Better detection of completion records, ignore those in `Function`s.
|
||||
* Clarified descriptions of the options that are enabled by default.
|
||||
* Resolve `\`babel-plugin-${name}\`` plugin names **before** just checking the `name`. Thanks [@jquense](https://github.com/jquense)!
|
||||
* Update AMD module formatter to add import default remapping.
|
||||
|
||||
## 5.4.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `module` being incorrectly rewritten when used as in an export declaration.
|
||||
* When performing single-reference inlining, ensure that the single reference isn't a child of the binding itself.
|
||||
* Fix a bug in `minification.deadCodeElimination` where a new binding instance was being created for local class bindings instead of just inheriting the parent one.
|
||||
* Fix bug with paren printing in `compact` and `retainLines` mode where a left paren was already printed before catching up.
|
||||
* **Internal**
|
||||
* Handle contexts for paths much better. This will ensure that the path node location info is in sync.
|
||||
|
||||
## 5.4.2
|
||||
|
||||
* **Polish**
|
||||
* `ignore` and `only` patterns are now **very** liberal. The pattern can now exist anywhere in the path.
|
||||
|
||||
## 5.4.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Add missing `slash` dependency. Thanks [@browncolyn](https://github.com/browncolyn)!
|
||||
* **Polish**
|
||||
* Clean up `shouldIgnore` algorithm to work how you'd expect rather than being a hacky piece of shit. It now crawls the entire path, checking each section of it against the input ignore/only patterns. This means that the pattern `foo` will ignore the paths `foo/bar.js`, `bar/foo` etc.
|
||||
|
||||
## 5.4.0
|
||||
|
||||
* **New Feature**
|
||||
* Added [function bind syntax](https://github.com/zenparsing/es-function-bind) behind stage 0. Thanks [@RReverser](https://github.com/rreverser)!
|
||||
* Added `env` option. Especially handy when using the `.babelrc`.
|
||||
* **Bug Fix**
|
||||
* Fix files not properly being ignored when `babel.transform` ignores them when using `$ babel`.
|
||||
* Fix scope tracking registering loop head bindings to their `VariableDeclaration` instead of `VariableDeclarator`.
|
||||
* **Polish**
|
||||
* Normalise path separators for souce map paths when using `$ babel`.
|
||||
* Rework `PathHoister` to ignore global references and to not deopt on reassignments to referenced bindings, instead it tries to hoist to the highest scope.
|
||||
* Added missing exponential operator inlining. Thanks [@nkt](https://github.com/nkt)!
|
||||
* Optimise `regenerator` transformer. Thanks [@benjamn](https://github.com/benjamn)!
|
||||
|
||||
## 5.3.3
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.3.3",
|
||||
"description": "A compiler for writing next generation JavaScript",
|
||||
"version": "5.4.4",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
@@ -41,6 +41,7 @@
|
||||
"esutils": "^2.0.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"globals": "^6.4.0",
|
||||
"home-or-tmp": "^1.0.0",
|
||||
"is-integer": "^1.0.4",
|
||||
"js-tokens": "1.0.0",
|
||||
"leven": "^1.0.1",
|
||||
@@ -60,8 +61,7 @@
|
||||
"source-map-support": "^0.2.10",
|
||||
"strip-json-comments": "^1.0.2",
|
||||
"to-fast-properties": "^1.0.0",
|
||||
"trim-right": "^1.0.0",
|
||||
"user-home": "^1.1.1"
|
||||
"trim-right": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "5.3.1",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var outputFileSync = require("output-file-sync");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
@@ -13,8 +14,10 @@ module.exports = function (commander, filenames, opts) {
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, {
|
||||
sourceFileName: path.relative(dest + "/..", src)
|
||||
sourceFileName: slash(path.relative(dest + "/..", src)),
|
||||
sourceMapTarget: path.basename(relative)
|
||||
});
|
||||
if (data.ignored) return;
|
||||
|
||||
if (commander.sourceMaps && commander.sourceMaps !== "inline") {
|
||||
var mapLoc = dest + ".map";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var convertSourceMap = require("convert-source-map");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
@@ -15,7 +16,8 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
var buildResult = function () {
|
||||
var map = new sourceMap.SourceMapGenerator({
|
||||
file: commander.outFile || "stdout"
|
||||
file: path.basename(commander.outFile) || "stdout",
|
||||
sourceRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
var code = "";
|
||||
@@ -27,11 +29,12 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
if (result.map) {
|
||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
var sourceFilename = filename;
|
||||
|
||||
var sourceFilename = filename;
|
||||
if (commander.outFile) {
|
||||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
||||
}
|
||||
sourceFilename = slash(sourceFilename);
|
||||
|
||||
map._sources.add(sourceFilename);
|
||||
map.setSourceContent(sourceFilename, result.actual);
|
||||
@@ -114,7 +117,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
_.each(_filenames, function (filename) {
|
||||
if (util.shouldIgnore(filename)) return;
|
||||
|
||||
results.push(util.compile(filename));
|
||||
var data = util.compile(filename);
|
||||
if (data.ignored) return;
|
||||
results.push(data);
|
||||
});
|
||||
|
||||
output();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.3.2",
|
||||
"version": "5.4.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.3.2",
|
||||
"babel-core": "^5.4.3",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
@@ -17,7 +17,8 @@
|
||||
"lodash": "^3.2.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"source-map": "^0.4.0"
|
||||
"source-map": "^0.4.0",
|
||||
"slash": "^1.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"babel": "./bin/babel/index.js",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.3.2",
|
||||
"version": "5.4.3",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
|
||||
48
sebmck-bjs.nfo
Normal file
48
sebmck-bjs.nfo
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
====== ==========M=
|
||||
============= == ======O= ======= MM ==
|
||||
M==+=== ==M === ==== == === ==
|
||||
=D === === ====MM ==M ==M ==M ===
|
||||
===M ====M ==== =D ===M === === ==
|
||||
==7 ====M ==M == ======== =========M ==M
|
||||
=========== ======M ===MMM === ==M ==
|
||||
=======MM==========MM== ==M ==M=== ==
|
||||
==M === M== ==M == === === =D =
|
||||
==M ===+ == == == ==$M =========== ============M
|
||||
=== ====M == ==M ===M== ====?MMMM M M
|
||||
== ===== ==M == ==MM M
|
||||
==M===M=M =M =MM M M
|
||||
==MM=M ==
|
||||
MMM =M
|
||||
M
|
||||
|
||||
> ú B ú A ú B ú E ú L ú <
|
||||
ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
|
||||
³ SOFTWARE .. : JavaScript Compiler ³ COMPANY ... : N/A ³
|
||||
³ SUPPLIER .. : N/A ³ CRACKER ... : Sebastian McKenzie ³
|
||||
³ RATING .... : depends.. ³ PACKAGER .. : Sebastian McKenzie ³
|
||||
³ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³
|
||||
³ GRAFIX .... : - ³ SOUND ..... : - ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
Babel is a JavaScript compiler and transformation platform for writing NeXt
|
||||
GeNeRaTiOn JavaScript.
|
||||
|
||||
ÆÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍ͵
|
||||
³ :: Greets :: ³
|
||||
³ ³
|
||||
³ sebmck, thejameskyle, RReverser, zloirock, monsanto, gaearon, zertosh, ³
|
||||
³ stefanpenner, eventualbuddha, AluisioASG, Apoxx, Couto, dominicbarnes, ³
|
||||
³ es128, gordonkristan, hkjels, jmeas, josh, loganfsmyth, nightire, ³
|
||||
³ Rich-Harris, shinnn, shuhei, sindresorhus, tricknotes ³
|
||||
³ ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
-*- JavaScripts for all , All for JavaScripts ! -*-
|
||||
|
||||
ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸
|
||||
³ If you want to Contact us, call 555-720-4228, Use the Handle "BABEL" w/ ³
|
||||
³ password : VISITOR and leave a mail to Sebastian or James. ³
|
||||
ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;
|
||||
|
||||
-=- We LoVe fun Too! -=-
|
||||
@@ -214,7 +214,12 @@ pp.parseExprSubscripts = function(refShorthandDefaultPos) {
|
||||
}
|
||||
|
||||
pp.parseSubscripts = function(base, start, noCalls) {
|
||||
if (this.eat(tt.dot)) {
|
||||
if (!noCalls && this.eat(tt.doubleColon)) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.object = base
|
||||
node.callee = this.parseNoCallExpr()
|
||||
return this.parseSubscripts(this.finishNode(node, "BindExpression"), start, noCalls)
|
||||
} else if (this.eat(tt.dot)) {
|
||||
let node = this.startNodeAt(start)
|
||||
node.object = base
|
||||
node.property = this.parseIdent(true)
|
||||
@@ -240,6 +245,13 @@ pp.parseSubscripts = function(base, start, noCalls) {
|
||||
} return base
|
||||
}
|
||||
|
||||
// Parse a no-call expression (like argument of `new` or `::` operators).
|
||||
|
||||
pp.parseNoCallExpr = function() {
|
||||
let start = this.markPosition()
|
||||
return this.parseSubscripts(this.parseExprAtom(), start, true)
|
||||
}
|
||||
|
||||
// Parse an atomic expression — either a single token that is an
|
||||
// expression, an expression started by a keyword like `function` or
|
||||
// `new`, or an expression wrapped in punctuation like `()`, `[]`,
|
||||
@@ -363,6 +375,15 @@ pp.parseExprAtom = function(refShorthandDefaultPos) {
|
||||
case tt.backQuote:
|
||||
return this.parseTemplate()
|
||||
|
||||
case tt.doubleColon:
|
||||
node = this.startNode()
|
||||
this.next()
|
||||
node.object = null
|
||||
let callee = node.callee = this.parseNoCallExpr()
|
||||
if (callee.type !== "MemberExpression")
|
||||
this.raise(callee.start, "Binding should be performed on object property.")
|
||||
return this.finishNode(node, "BindExpression")
|
||||
|
||||
default:
|
||||
this.unexpected()
|
||||
}
|
||||
@@ -472,8 +493,7 @@ pp.parseNew = function() {
|
||||
this.raise(node.property.start, "The only valid meta property for new is new.target")
|
||||
return this.finishNode(node, "MetaProperty")
|
||||
}
|
||||
let start = this.markPosition()
|
||||
node.callee = this.parseSubscripts(this.parseExprAtom(), start, true)
|
||||
node.callee = this.parseNoCallExpr()
|
||||
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(
|
||||
tt.parenR,
|
||||
this.options.features["es7.trailingFunctionCommas"]
|
||||
|
||||
@@ -320,7 +320,13 @@ pp.getTokenFromCode = function(code) {
|
||||
case 93: ++this.pos; return this.finishToken(tt.bracketR)
|
||||
case 123: ++this.pos; return this.finishToken(tt.braceL)
|
||||
case 125: ++this.pos; return this.finishToken(tt.braceR)
|
||||
case 58: ++this.pos; return this.finishToken(tt.colon)
|
||||
|
||||
case 58:
|
||||
if (this.options.features["es7.functionBind"] && this.input.charCodeAt(this.pos + 1) === 58)
|
||||
return this.finishOp(tt.doubleColon, 2)
|
||||
++this.pos
|
||||
return this.finishToken(tt.colon)
|
||||
|
||||
case 63: ++this.pos; return this.finishToken(tt.question)
|
||||
case 64: ++this.pos; return this.finishToken(tt.at)
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ export const types = {
|
||||
comma: new TokenType(",", beforeExpr),
|
||||
semi: new TokenType(";", beforeExpr),
|
||||
colon: new TokenType(":", beforeExpr),
|
||||
doubleColon: new TokenType("::", beforeExpr),
|
||||
dot: new TokenType("."),
|
||||
question: new TokenType("?", beforeExpr),
|
||||
arrow: new TokenType("=>", beforeExpr),
|
||||
|
||||
@@ -61,8 +61,8 @@ export function parse(code, opts = {}) {
|
||||
opts.sourceType = "module";
|
||||
opts.ecmaVersion = Infinity;
|
||||
opts.plugins = {
|
||||
flow: true,
|
||||
jsx: true
|
||||
jsx: true,
|
||||
flow: true
|
||||
};
|
||||
opts.features = {};
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import fs from "fs";
|
||||
import userHome from "user-home";
|
||||
import homeOrTmp from "home-or-tmp";
|
||||
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(userHome || os.tmpdir(), ".babel.json");
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
|
||||
var data = {};
|
||||
|
||||
export function save() {
|
||||
|
||||
@@ -53,6 +53,9 @@ var compile = function (filename) {
|
||||
|
||||
var cacheKey = `${filename}:${JSON.stringify(opts)}:${babel.version}`;
|
||||
|
||||
var env = process.env.BABEL_ENV || process.env.NODE_ENV;
|
||||
if (env) cacheKey += `:${env}`;
|
||||
|
||||
if (cache) {
|
||||
var cached = cache[cacheKey];
|
||||
if (cached && cached.mtime === mtime(filename)) {
|
||||
|
||||
@@ -117,8 +117,9 @@ export default class Buffer {
|
||||
|
||||
_removeSpacesAfterLastNewline() {
|
||||
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
||||
if (lastNewlineIndex === -1)
|
||||
if (lastNewlineIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index = this.buf.length - 1;
|
||||
while (index > lastNewlineIndex) {
|
||||
|
||||
@@ -3,7 +3,7 @@ export function ClassDeclaration(node, print) {
|
||||
this.push("class");
|
||||
|
||||
if (node.id) {
|
||||
this.space();
|
||||
this.push(" ");
|
||||
print(node.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,12 @@ export function AssignmentExpression(node, print) {
|
||||
print(node.right);
|
||||
}
|
||||
|
||||
export function BindExpression(node, print) {
|
||||
print(node.object);
|
||||
this.push("::");
|
||||
print(node.callee);
|
||||
}
|
||||
|
||||
export {
|
||||
AssignmentExpression as BinaryExpression,
|
||||
AssignmentExpression as LogicalExpression,
|
||||
|
||||
@@ -39,6 +39,12 @@ export function Property(node, print) {
|
||||
print(node.key);
|
||||
this.push("]");
|
||||
} else {
|
||||
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
|
||||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
|
||||
print(node.value);
|
||||
return;
|
||||
}
|
||||
|
||||
print(node.key);
|
||||
|
||||
// shorthand!
|
||||
|
||||
@@ -149,11 +149,12 @@ class CodeGenerator {
|
||||
return print;
|
||||
}
|
||||
|
||||
catchUp(node, parent) {
|
||||
catchUp(node, parent, leftParenPrinted) {
|
||||
// catch up to this nodes newline if we're behind
|
||||
if (node.loc && this.format.retainLines && this.buffer.buf) {
|
||||
var needsParens = false;
|
||||
if (parent && this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
||||
if (!leftParenPrinted && parent &&
|
||||
this.position.line < node.loc.start.line && t.isTerminatorless(parent)) {
|
||||
needsParens = true;
|
||||
this._push("(");
|
||||
}
|
||||
@@ -216,7 +217,7 @@ class CodeGenerator {
|
||||
|
||||
this.printLeadingComments(node, parent);
|
||||
|
||||
var needsParensFromCatchup = this.catchUp(node, parent);
|
||||
var needsParensFromCatchup = this.catchUp(node, parent, needsParens);
|
||||
|
||||
newline(true);
|
||||
|
||||
@@ -330,7 +331,6 @@ class CodeGenerator {
|
||||
|
||||
_printComments(comments) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (!this.format.comments) return;
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export default class SourceMap {
|
||||
|
||||
if (opts.sourceMaps) {
|
||||
this.map = new sourceMap.SourceMapGenerator({
|
||||
file: opts.sourceMapName,
|
||||
file: opts.sourceMapTarget,
|
||||
sourceRoot: opts.sourceRoot
|
||||
});
|
||||
|
||||
|
||||
17
src/babel/helpers/merge.js
Normal file
17
src/babel/helpers/merge.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import merge from "lodash/object/merge";
|
||||
|
||||
export default function (dest, src) {
|
||||
if (!dest || !src) return;
|
||||
|
||||
return merge(dest, src, function(a, b) {
|
||||
if (Array.isArray(a)) {
|
||||
var c = a.slice(0);
|
||||
for (var v of b) {
|
||||
if (a.indexOf(v) < 0) {
|
||||
c.push(v);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -27,7 +27,6 @@ export default function (code, opts = {}) {
|
||||
}
|
||||
|
||||
var ast = acorn.parse(code, parseOpts);
|
||||
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
ast = normalizeAst(ast, comments, tokens);
|
||||
return ast;
|
||||
|
||||
@@ -22,6 +22,7 @@ export const MESSAGES = {
|
||||
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||
unsupportedOutputType: "Unsupported output type $1",
|
||||
illegalMethodName: "Illegal method name $1",
|
||||
lostTrackNodePath: "We lost track of this nodes position, likely because the AST was directly manipulated",
|
||||
|
||||
traverseNeedsParent: "Must pass a scope and parentPath unless traversing a Program/File got a $1 node",
|
||||
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||
|
||||
@@ -72,4 +72,10 @@ def("ExportAllDeclaration")
|
||||
.field("exported", def("Identifier"))
|
||||
.field("source", def("Literal"));
|
||||
|
||||
def("BindExpression")
|
||||
.bases("Expression")
|
||||
.build("object", "callee")
|
||||
.field("object", or(def("Expression"), null))
|
||||
.field("callee", def("Expression"));
|
||||
|
||||
types.finalize();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import stripJsonComments from "strip-json-comments";
|
||||
import merge from "lodash/object/merge";
|
||||
import merge from "../helpers/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
@@ -42,17 +42,7 @@ export default function (loc, opts = {}) {
|
||||
opts.babelrc.push(file);
|
||||
|
||||
if (json.breakConfig) return;
|
||||
merge(opts, json, function(a, b) {
|
||||
if (Array.isArray(a)) {
|
||||
var c = a.slice(0);
|
||||
for (var v of b) {
|
||||
if (a.indexOf(v) < 0) {
|
||||
c.push(v);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
});
|
||||
merge(opts, json);
|
||||
}
|
||||
|
||||
var up = path.dirname(start);
|
||||
|
||||
@@ -19,6 +19,7 @@ import assign from "lodash/object/assign";
|
||||
import Logger from "./logger";
|
||||
import parse from "../../helpers/parse";
|
||||
import Scope from "../../traversal/scope";
|
||||
import merge from "../../helpers/merge";
|
||||
import slash from "slash";
|
||||
import clone from "lodash/lang/clone";
|
||||
import * as util from "../../util";
|
||||
@@ -37,6 +38,7 @@ export default class File {
|
||||
this.declarations = {};
|
||||
this.usedHelpers = {};
|
||||
this.dynamicData = {};
|
||||
this.metadata = {};
|
||||
this.data = {};
|
||||
|
||||
this.pipeline = pipeline;
|
||||
@@ -106,6 +108,9 @@ export default class File {
|
||||
if (!option) this.log.error(`Unknown option: ${key}`, ReferenceError);
|
||||
}
|
||||
|
||||
var envKey = process.env.BABEL_ENV || process.env.NODE_ENV || "development";
|
||||
if (opts.env) merge(opts, opts.env[envKey]);
|
||||
|
||||
for (let key in File.options) {
|
||||
let option = File.options[key];
|
||||
|
||||
@@ -163,7 +168,7 @@ export default class File {
|
||||
|
||||
defaults(opts, {
|
||||
sourceFileName: opts.filenameRelative,
|
||||
sourceMapName: opts.filenameRelative
|
||||
sourceMapTarget: opts.filenameRelative
|
||||
});
|
||||
|
||||
//
|
||||
@@ -458,7 +463,7 @@ export default class File {
|
||||
}
|
||||
|
||||
_addAst(ast) {
|
||||
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
||||
this.path = TraversalPath.get(null, ast, ast, "program", this).setContext(null, this);
|
||||
this.scope = this.path.scope;
|
||||
this.ast = ast;
|
||||
}
|
||||
@@ -488,7 +493,8 @@ export default class File {
|
||||
try {
|
||||
if (this.shouldIgnore()) {
|
||||
return {
|
||||
metadata: {},
|
||||
metadata: this.metadata,
|
||||
ignored: true,
|
||||
code: code,
|
||||
map: null,
|
||||
ast: null
|
||||
@@ -581,7 +587,7 @@ export default class File {
|
||||
var ast = this.ast;
|
||||
|
||||
var result = {
|
||||
metadata: {},
|
||||
metadata: this.metadata,
|
||||
code: "",
|
||||
map: null,
|
||||
ast: null
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"env": {
|
||||
"hidden": true,
|
||||
"default": {}
|
||||
},
|
||||
|
||||
"moduleId": {
|
||||
"description": "specify a custom name for module ids",
|
||||
"type": "string"
|
||||
@@ -38,7 +43,7 @@
|
||||
"nonStandard": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "enable support for JSX and Flow"
|
||||
"description": "enable/disable support for JSX and Flow (on by default)"
|
||||
},
|
||||
|
||||
"experimental": {
|
||||
@@ -46,7 +51,7 @@
|
||||
},
|
||||
|
||||
"highlightCode": {
|
||||
"description": "ANSI syntax highlight code frames",
|
||||
"description": "enable/disable ANSI syntax highlighting of code frames (on by default)",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
},
|
||||
@@ -143,7 +148,7 @@
|
||||
"comments": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "output comments in generated output"
|
||||
"description": "strip/output comments in generated output (on by default)"
|
||||
},
|
||||
|
||||
"compact": {
|
||||
@@ -192,6 +197,11 @@
|
||||
},
|
||||
|
||||
"sourceMapName": {
|
||||
"alias": "sourceMapTarget",
|
||||
"description": "DEPRECATED - Please use sourceMapTarget"
|
||||
},
|
||||
|
||||
"sourceMapTarget": {
|
||||
"type": "string",
|
||||
"description": "set `file` on returned source map"
|
||||
},
|
||||
|
||||
@@ -35,7 +35,7 @@ export default class PluginManager {
|
||||
var match = name.match(/^(.*?):(after|before)$/);
|
||||
if (match) [, name, position] = match;
|
||||
|
||||
var loc = util.resolveRelative(name) || util.resolveRelative(`babel-plugin-${name}`);
|
||||
var loc = util.resolveRelative(`babel-plugin-${name}`) || util.resolveRelative(name);
|
||||
if (loc) {
|
||||
return {
|
||||
position: position,
|
||||
|
||||
@@ -26,7 +26,7 @@ var getObjRef = function (node, nodes, file, scope) {
|
||||
throw new Error(`We can't explode this node type ${node.type}`);
|
||||
}
|
||||
|
||||
var temp = scope.generateUidBasedOnNode(ref);
|
||||
var temp = scope.generateUidIdentifierBasedOnNode(ref);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, ref)
|
||||
]));
|
||||
@@ -38,7 +38,7 @@ var getPropRef = function (node, nodes, file, scope) {
|
||||
var key = t.toComputedKey(node, prop);
|
||||
if (t.isLiteral(key)) return key;
|
||||
|
||||
var temp = scope.generateUidBasedOnNode(prop);
|
||||
var temp = scope.generateUidIdentifierBasedOnNode(prop);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(temp, prop)
|
||||
]));
|
||||
|
||||
@@ -6,7 +6,7 @@ export default function (decorators, scope) {
|
||||
var expression = decorator.expression;
|
||||
if (!t.isMemberExpression(expression)) continue;
|
||||
|
||||
var temp = scope.generateMemoisedReference(expression.object);
|
||||
var temp = scope.maybeGenerateMemoised(expression.object);
|
||||
var ref;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
@@ -6,8 +6,8 @@ import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class AMDFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
CommonFormatter.prototype._init.call(this, this.hasNonDefaultExports);
|
||||
setup() {
|
||||
CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports);
|
||||
}
|
||||
|
||||
buildDependencyLiterals() {
|
||||
@@ -92,9 +92,9 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
// import foo from "foo";
|
||||
var uid = this.scope.generateUidIdentifier(specifier.local.name);
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require"), [ref]))
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||
]));
|
||||
ref = uid;
|
||||
ref = t.memberExpression(uid, t.identifier("default"));
|
||||
} else {
|
||||
// import { foo } from "foo";
|
||||
var imported = specifier.imported;
|
||||
|
||||
@@ -4,11 +4,11 @@ import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class CommonJSFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
this._init(this.hasLocalExports);
|
||||
setup() {
|
||||
this._setup(this.hasLocalExports);
|
||||
}
|
||||
|
||||
_init(conditional) {
|
||||
_setup(conditional) {
|
||||
var file = this.file;
|
||||
var scope = file.scope;
|
||||
|
||||
@@ -52,7 +52,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
} else if (this.noInteropRequireImport) {
|
||||
this.internalRemap[variableName.name] = t.memberExpression(ref, t.identifier("default"));
|
||||
} else {
|
||||
var uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
var uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
|
||||
@@ -111,7 +111,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
|
||||
} else if (this.isModuleType(node, "absoluteDefault")) {
|
||||
call = t.memberExpression(call, t.identifier("default"));
|
||||
} else {
|
||||
uid = this.scope.generateUidBasedOnNode(node, "import");
|
||||
uid = this.scope.generateUidIdentifierBasedOnNode(node, "import");
|
||||
}
|
||||
|
||||
uid = uid || node.specifiers[0].local;
|
||||
|
||||
@@ -8,41 +8,39 @@ import map from "lodash/collection/map";
|
||||
import * as t from "../../types";
|
||||
|
||||
var hoistVariablesVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) {
|
||||
// nothing inside is accessible
|
||||
return this.skip();
|
||||
Function() {
|
||||
// nothing inside is accessible
|
||||
this.skip();
|
||||
},
|
||||
|
||||
VariableDeclaration(node, parent, scope, state) {
|
||||
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
||||
// can't be accessed
|
||||
return;
|
||||
}
|
||||
|
||||
if (t.isVariableDeclaration(node)) {
|
||||
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
|
||||
// can't be accessed
|
||||
return;
|
||||
// ignore block hoisted nodes as these can be left in
|
||||
if (state.formatter._canHoist(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
if (declar.init) {
|
||||
// no initializer so we can just hoist it as-is
|
||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||
nodes.push(assign);
|
||||
}
|
||||
|
||||
// ignore block hoisted nodes as these can be left in
|
||||
if (state.formatter.canHoist(node)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
|
||||
if (declar.init) {
|
||||
// no initializer so we can just hoist it as-is
|
||||
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
|
||||
nodes.push(assign);
|
||||
}
|
||||
}
|
||||
|
||||
// for (var i in test)
|
||||
// for (var i = 0;;)
|
||||
if (t.isFor(parent) && parent.left === node) {
|
||||
return node.declarations[0].id;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
// for (var i in test)
|
||||
// for (var i = 0;;)
|
||||
if (t.isFor(parent) && (parent.left === node || parent.init === node)) {
|
||||
return node.declarations[0].id;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,7 +48,7 @@ var hoistFunctionsVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isFunction(node)) this.skip();
|
||||
|
||||
if (t.isFunctionDeclaration(node) || state.formatter.canHoist(node)) {
|
||||
if (t.isFunctionDeclaration(node) || state.formatter._canHoist(node)) {
|
||||
state.handlerBody.push(node);
|
||||
this.remove();
|
||||
}
|
||||
@@ -101,14 +99,14 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
var right = objectIdentifier;
|
||||
|
||||
var block = t.blockStatement([
|
||||
t.expressionStatement(this.buildExportCall(leftIdentifier, valIdentifier))
|
||||
t.expressionStatement(this._buildExportCall(leftIdentifier, valIdentifier))
|
||||
]);
|
||||
|
||||
return this._addImportSource(t.forInStatement(left, right, block), node);
|
||||
}
|
||||
|
||||
buildExportsAssignment(id, init, node) {
|
||||
var call = this.buildExportCall(t.literal(id.name), init, true);
|
||||
var call = this._buildExportCall(t.literal(id.name), init, true);
|
||||
return this._addImportSource(call, node);
|
||||
}
|
||||
|
||||
@@ -120,13 +118,13 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
var assign = node;
|
||||
|
||||
for (var i = 0; i < exported.length; i++) {
|
||||
assign = this.buildExportCall(t.literal(exported[i].name), assign);
|
||||
assign = this._buildExportCall(t.literal(exported[i].name), assign);
|
||||
}
|
||||
|
||||
return assign;
|
||||
}
|
||||
|
||||
buildExportCall(id, init, isStatement) {
|
||||
_buildExportCall(id, init, isStatement) {
|
||||
var call = t.callExpression(this.exportIdentifier, [id, init]);
|
||||
if (isStatement) {
|
||||
return t.expressionStatement(call);
|
||||
@@ -149,7 +147,7 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
this._addImportSource(last(nodes), node);
|
||||
}
|
||||
|
||||
buildRunnerSetters(block, hoistDeclarators) {
|
||||
_buildRunnerSetters(block, hoistDeclarators) {
|
||||
var scope = this.file.scope;
|
||||
|
||||
return t.arrayExpression(map(this.ids, function (uid, source) {
|
||||
@@ -165,7 +163,7 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
}));
|
||||
}
|
||||
|
||||
canHoist(node) {
|
||||
_canHoist(node) {
|
||||
return node._blockHoist && !this.file.dynamicImports.length;
|
||||
}
|
||||
|
||||
@@ -182,7 +180,7 @@ export default class SystemFormatter extends AMDFormatter {
|
||||
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
|
||||
EXPORT_IDENTIFIER: this.exportIdentifier,
|
||||
MODULE_NAME: moduleNameLiteral,
|
||||
SETTERS: this.buildRunnerSetters(block, hoistDeclarators),
|
||||
SETTERS: this._buildRunnerSetters(block, hoistDeclarators),
|
||||
EXECUTE: t.functionExpression(null, [], block)
|
||||
}, true);
|
||||
|
||||
|
||||
@@ -84,8 +84,6 @@ export function BlockStatement(block, parent, scope, file) {
|
||||
export { BlockStatement as Program };
|
||||
|
||||
function replace(node, parent, scope, remaps) {
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
|
||||
var remap = remaps[node.name];
|
||||
if (!remap) return;
|
||||
|
||||
@@ -100,11 +98,21 @@ function replace(node, parent, scope, remaps) {
|
||||
}
|
||||
|
||||
var replaceVisitor = {
|
||||
enter: replace
|
||||
ReferencedIdentifier: replace,
|
||||
|
||||
AssignmentExpression(node, parent, scope, remaps) {
|
||||
var ids = this.getBindingIdentifiers();
|
||||
for (var name in ids) {
|
||||
replace(ids[name], node, scope, remaps);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function traverseReplace(node, parent, scope, remaps) {
|
||||
replace(node, parent, scope, remaps);
|
||||
if (t.isIdentifier(node)) {
|
||||
replace(node, parent, scope, remaps);
|
||||
}
|
||||
|
||||
scope.traverse(node, replaceVisitor, remaps);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ class ClassTransformer {
|
||||
if (this.hasSuper) {
|
||||
closureArgs.push(superName);
|
||||
|
||||
superName = this.scope.generateUidBasedOnNode(superName);
|
||||
superName = this.scope.generateUidIdentifierBasedOnNode(superName);
|
||||
closureParams.push(superName);
|
||||
|
||||
this.superName = superName;
|
||||
|
||||
@@ -55,7 +55,7 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
|
||||
export { ForOfStatement as ForInStatement };
|
||||
|
||||
export function Func(node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
|
||||
var hasDestructuring = false;
|
||||
@@ -295,7 +295,7 @@ class DestructuringTransformer {
|
||||
// we need to assign the current value of the assignment to avoid evaluating
|
||||
// it more than once
|
||||
|
||||
var tempValueRef = this.scope.generateUidBasedOnNode(valueRef);
|
||||
var tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef);
|
||||
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(tempValueRef, valueRef)
|
||||
@@ -377,7 +377,7 @@ class DestructuringTransformer {
|
||||
// only evaluated once
|
||||
|
||||
if (pattern.properties.length > 1 && t.isMemberExpression(objRef)) {
|
||||
var temp = this.scope.generateUidBasedOnNode(objRef, this.file);
|
||||
var temp = this.scope.generateUidIdentifierBasedOnNode(objRef, this.file);
|
||||
this.nodes.push(this.buildVariableDeclaration(temp, objRef));
|
||||
objRef = temp;
|
||||
}
|
||||
@@ -461,7 +461,7 @@ class DestructuringTransformer {
|
||||
// array
|
||||
arrayRef = toArray;
|
||||
} else {
|
||||
arrayRef = this.scope.generateUidBasedOnNode(arrayRef);
|
||||
arrayRef = this.scope.generateUidIdentifierBasedOnNode(arrayRef);
|
||||
this.arrays[arrayRef.name] = true;
|
||||
this.nodes.push(this.buildVariableDeclaration(arrayRef, toArray));
|
||||
}
|
||||
@@ -500,7 +500,7 @@ class DestructuringTransformer {
|
||||
|
||||
var shouldMemoise = true;
|
||||
if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref)) {
|
||||
var memo = this.scope.generateMemoisedReference(ref, true);
|
||||
var memo = this.scope.maybeGenerateMemoised(ref, true);
|
||||
if (memo) {
|
||||
this.nodes.push(this.buildVariableDeclaration(memo, ref));
|
||||
ref = memo;
|
||||
|
||||
@@ -33,7 +33,7 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
this.parentPath.replaceWithMultiple(build.node);
|
||||
this.remove();
|
||||
} else {
|
||||
this.replaceWithMultiple(build.node);
|
||||
return build.node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ var iifeVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
export function Func(node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!hasDefaults(node)) return;
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
@@ -53,7 +53,7 @@ var hasRest = function (node) {
|
||||
return t.isRestElement(node.params[node.params.length - 1]);
|
||||
};
|
||||
|
||||
export function Func(node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!hasRest(node)) return;
|
||||
|
||||
var restParam = node.params.pop();
|
||||
|
||||
@@ -75,7 +75,7 @@ export var ObjectExpression = {
|
||||
if (!hasComputed) return;
|
||||
|
||||
var initProps = [];
|
||||
var objId = scope.generateUidBasedOnNode(parent);
|
||||
var objId = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
|
||||
//
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ export function CallExpression(node, parent, scope) {
|
||||
var callee = node.callee;
|
||||
|
||||
if (this.get("callee").isMemberExpression()) {
|
||||
var temp = scope.generateMemoisedReference(callee.object);
|
||||
var temp = scope.maybeGenerateMemoised(callee.object);
|
||||
if (temp) {
|
||||
callee.object = t.assignmentExpression("=", temp, callee.object);
|
||||
contextLiteral = temp;
|
||||
|
||||
@@ -10,7 +10,7 @@ export var metadata = {
|
||||
group: "builtin-trailing"
|
||||
};
|
||||
|
||||
export function Func(node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (node.generator || node.async) return;
|
||||
var tailCall = new TailCallTransformer(this, scope, file);
|
||||
tailCall.run();
|
||||
@@ -44,12 +44,14 @@ var visitor = {
|
||||
},
|
||||
|
||||
ThisExpression(node, parent, scope, state) {
|
||||
state.needsThis = true;
|
||||
state.thisPaths.push(this);
|
||||
if (!state.isShadowed) {
|
||||
state.needsThis = true;
|
||||
state.thisPaths.push(this);
|
||||
}
|
||||
},
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name === "arguments") {
|
||||
if (node.name === "arguments" && !state.isShadowed) {
|
||||
state.needsArguments = true;
|
||||
state.argumentsPaths.push(this);
|
||||
}
|
||||
@@ -67,8 +69,9 @@ class TailCallTransformer {
|
||||
this.needsThis = false;
|
||||
this.thisPaths = [];
|
||||
|
||||
this.ownerId = path.node.id;
|
||||
this.vars = [];
|
||||
this.isShadowed = path.isArrowFunctionExpression() || path.is("shadow");
|
||||
this.ownerId = path.node.id;
|
||||
this.vars = [];
|
||||
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
|
||||
@@ -26,7 +26,7 @@ function generator(node) {
|
||||
}
|
||||
|
||||
function array(node, parent, scope, file) {
|
||||
var uid = scope.generateUidBasedOnNode(parent);
|
||||
var uid = scope.generateUidIdentifierBasedOnNode(parent);
|
||||
|
||||
var container = util.template("array-comprehension-container", {
|
||||
KEY: uid
|
||||
|
||||
51
src/babel/transformation/transformers/es7/function-bind.js
Normal file
51
src/babel/transformation/transformers/es7/function-bind.js
Normal file
@@ -0,0 +1,51 @@
|
||||
// https://github.com/zenparsing/es-function-bind
|
||||
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true,
|
||||
stage: 0
|
||||
};
|
||||
|
||||
function getTempId(scope) {
|
||||
var id = scope.path.getData("functionBind");
|
||||
if (id) return id;
|
||||
|
||||
id = scope.generateDeclaredUidIdentifier("context");
|
||||
return scope.path.setData("functionBind", id);
|
||||
}
|
||||
|
||||
function getStaticContext(bind, scope) {
|
||||
var object = bind.object || bind.callee.object;
|
||||
return scope.isStatic(object) && object;
|
||||
}
|
||||
|
||||
function inferBindContext(bind, scope) {
|
||||
var staticContext = getStaticContext(bind, scope);
|
||||
if (staticContext) return staticContext;
|
||||
|
||||
var tempId = getTempId(scope);
|
||||
if (bind.object) {
|
||||
bind.callee = t.sequenceExpression([
|
||||
t.assignmentExpression("=", tempId, bind.object),
|
||||
bind.callee
|
||||
]);
|
||||
} else {
|
||||
bind.callee.object = t.assignmentExpression("=", tempId, bind.callee.object);
|
||||
}
|
||||
return tempId;
|
||||
}
|
||||
|
||||
export function CallExpression(node, parent, scope, file) {
|
||||
var bind = node.callee;
|
||||
if (!t.isBindExpression(bind)) return;
|
||||
|
||||
var context = inferBindContext(bind, scope);
|
||||
node.callee = t.memberExpression(bind.callee, t.identifier("call"));
|
||||
node.arguments.unshift(context);
|
||||
}
|
||||
|
||||
export function BindExpression(node, parent, scope, file) {
|
||||
var context = inferBindContext(node, scope);
|
||||
return t.callExpression(t.memberExpression(node.callee, t.identifier("bind")), [context]);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export default {
|
||||
//- builtin-setup
|
||||
strict: require("./other/strict"),
|
||||
_explode: require("./internal/explode"),
|
||||
_validation: require("./internal/validation"),
|
||||
_hoistDirectives: require("./internal/hoist-directives"),
|
||||
@@ -18,15 +19,12 @@ export default {
|
||||
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
|
||||
"es7.asyncFunctions": require("./es7/async-functions"),
|
||||
"es7.decorators": require("./es7/decorators"),
|
||||
strict: require("./other/strict"),
|
||||
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
|
||||
"validation.react": require("./validation/react"),
|
||||
"es6.arrowFunctions": require("./es6/arrow-functions"),
|
||||
"spec.blockScopedFunctions": require("./spec/block-scoped-functions"),
|
||||
"optimisation.react.constantElements": require("./optimisation/react.constant-elements"),
|
||||
"optimisation.react.inlineElements": require("./optimisation/react.inline-elements"),
|
||||
reactCompat: require("./other/react-compat"),
|
||||
react: require("./other/react"),
|
||||
"es7.comprehensions": require("./es7/comprehensions"),
|
||||
"es6.classes": require("./es6/classes"),
|
||||
asyncToGenerator: require("./other/async-to-generator"),
|
||||
@@ -51,6 +49,7 @@ export default {
|
||||
"spec.protoToAssign": require("./spec/proto-to-assign"),
|
||||
"es7.doExpressions": require("./es7/do-expressions"),
|
||||
"es6.spec.symbols": require("./es6/spec.symbols"),
|
||||
"es7.functionBind": require("./es7/function-bind"),
|
||||
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
|
||||
jscript: require("./other/jscript"),
|
||||
flow: require("./other/flow"),
|
||||
@@ -59,6 +58,8 @@ export default {
|
||||
"es6.destructuring": require("./es6/destructuring"),
|
||||
"es6.blockScoping": require("./es6/block-scoping"),
|
||||
"es6.spec.blockScoping": require("./es6/spec.block-scoping"),
|
||||
reactCompat: require("./other/react-compat"),
|
||||
react: require("./other/react"),
|
||||
|
||||
// es6 syntax transformation is **forbidden** past this point since regenerator will chuck a massive
|
||||
// hissy fit
|
||||
|
||||
@@ -5,9 +5,9 @@ export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
function buildClone(bindingKey, refKey) {
|
||||
function buildClone(bindingKey, refKey, check?) {
|
||||
return function (node) {
|
||||
if (node[bindingKey] === node[refKey]) {
|
||||
if (node[bindingKey] === node[refKey] || (check && check(node))) {
|
||||
node[refKey] = t.removeComments(clone(node[refKey]));
|
||||
}
|
||||
};
|
||||
@@ -25,6 +25,9 @@ function buildListClone(listKey, bindingKey, refKey) {
|
||||
};
|
||||
}
|
||||
|
||||
export var Property = buildClone("value", "key");
|
||||
export var Property = buildClone("value", "key", function (node) {
|
||||
return t.isAssignmentPattern(node.value) && node.value.left === node.key;
|
||||
});
|
||||
|
||||
export var ExportDeclaration = buildListClone("specifiers", "local", "exported");
|
||||
export var ImportDeclaration = buildListClone("specifiers", "local", "imported");
|
||||
|
||||
@@ -85,18 +85,28 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
}
|
||||
}
|
||||
|
||||
export function Program(node) {
|
||||
var imports = [];
|
||||
var rest = [];
|
||||
export var Program = {
|
||||
enter(node) {
|
||||
var imports = [];
|
||||
var rest = [];
|
||||
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isImportDeclaration(bodyNode)) {
|
||||
imports.push(bodyNode);
|
||||
} else {
|
||||
rest.push(bodyNode);
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isImportDeclaration(bodyNode)) {
|
||||
imports.push(bodyNode);
|
||||
} else {
|
||||
rest.push(bodyNode);
|
||||
}
|
||||
}
|
||||
|
||||
node.body = imports.concat(rest);
|
||||
},
|
||||
|
||||
exit(node, parent, scope, file) {
|
||||
if (!file.transformers["es6.modules"].canTransform()) return;
|
||||
|
||||
if (file.moduleFormatter.setup) {
|
||||
file.moduleFormatter.setup();
|
||||
}
|
||||
}
|
||||
|
||||
node.body = imports.concat(rest);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,6 +33,10 @@ export function ReferencedIdentifier(node, parent, scope) {
|
||||
}
|
||||
if (!replacement) return;
|
||||
|
||||
if (this.findParent((node) => replacement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
t.toExpression(replacement);
|
||||
scope.removeBinding(node.name);
|
||||
binding.path.remove();
|
||||
|
||||
@@ -36,8 +36,7 @@ export function JSXElement(node, parent, scope, file) {
|
||||
|
||||
if (state.isImmutable) {
|
||||
this.hoist();
|
||||
this.skip();
|
||||
} else {
|
||||
node._hoisted = true;
|
||||
}
|
||||
|
||||
node._hoisted = true;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export var metadata = {
|
||||
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
||||
};
|
||||
|
||||
export function Func(node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
return remapAsyncToGenerator(node, file.addHelper("async-to-generator"), scope);
|
||||
|
||||
@@ -10,7 +10,7 @@ export var metadata = {
|
||||
dependencies: ["es7.asyncFunctions", "es6.classes"]
|
||||
};
|
||||
|
||||
export function Func(node, parent, scope, file) {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
return remapAsyncToGenerator(
|
||||
|
||||
@@ -12,7 +12,7 @@ export function Class(node) {
|
||||
node.implements = null;
|
||||
}
|
||||
|
||||
export function Func(node) {
|
||||
export function Func/*tion*/(node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
var param = node.params[i];
|
||||
param.optional = false;
|
||||
|
||||
@@ -6,7 +6,8 @@ export function manipulateOptions(opts) {
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
optional: true,
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
require("../../helpers/build-react-transformer")(exports, {
|
||||
|
||||
@@ -3,6 +3,10 @@ import * as t from "../../../types";
|
||||
|
||||
var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export function Program(node, parent, scope, file) {
|
||||
var id = file.opts.jsxPragma;
|
||||
|
||||
|
||||
@@ -1,11 +1,69 @@
|
||||
import regenerator from "regenerator";
|
||||
import * as t from "../../../types";
|
||||
import { NodePath } from "ast-types";
|
||||
|
||||
export var metadata = {
|
||||
group: "regenerator"
|
||||
};
|
||||
|
||||
export function Program(ast) {
|
||||
regenerator.transform(ast);
|
||||
this.stop();
|
||||
export function Func/*tion*/(node) {
|
||||
if (node.async || node.generator) {
|
||||
// Although this code transforms only the subtree rooted at the given
|
||||
// Function node, that node might contain other generator functions
|
||||
// that will also be transformed. It might help performance to ignore
|
||||
// nested functions, and rely on the traversal to visit them later,
|
||||
// but that's a small optimization. Starting here instead of at the
|
||||
// root of the AST is the key optimization, since huge async/generator
|
||||
// functions are relatively rare.
|
||||
regenerator.transform(convertTraversalPathToNodePath(this));
|
||||
}
|
||||
}
|
||||
|
||||
// Given a TraversalPath, return a NodePath that includes full ancestry
|
||||
// information (up to and including the Program node). This is complicated
|
||||
// by having to include intermediate objects like blockStatement.body
|
||||
// arrays, in addition to Node objects.
|
||||
function convertTraversalPathToNodePath(path) {
|
||||
var programNode;
|
||||
var keysAlongPath = [];
|
||||
|
||||
while (path) {
|
||||
var pp = path.parentPath;
|
||||
var parentNode = pp && pp.node;
|
||||
if (parentNode) {
|
||||
keysAlongPath.push(path.key);
|
||||
|
||||
if (parentNode !== path.container) {
|
||||
var found = Object.keys(parentNode).some(containerKey => {
|
||||
if (parentNode[containerKey] === path.container) {
|
||||
keysAlongPath.push(containerKey);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
throw new Error("Failed to find container object in parent node");
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isProgram(parentNode)) {
|
||||
programNode = parentNode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
path = pp;
|
||||
}
|
||||
|
||||
if (!programNode) {
|
||||
throw new Error("Failed to find root Program node");
|
||||
}
|
||||
|
||||
var nodePath = new NodePath(programNode);
|
||||
|
||||
while (keysAlongPath.length > 0) {
|
||||
nodePath = nodePath.get(keysAlongPath.pop());
|
||||
}
|
||||
|
||||
return nodePath;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import * as messages from "../../../messages";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-setup"
|
||||
};
|
||||
|
||||
const THIS_BREAK_KEYS = ["FunctionExpression", "FunctionDeclaration", "ClassExpression", "ClassDeclaration"];
|
||||
|
||||
export var Program = {
|
||||
|
||||
@@ -24,7 +24,7 @@ export function AssignmentExpression(node, parent, scope, file) {
|
||||
|
||||
var nodes = [];
|
||||
var left = node.left.object;
|
||||
var temp = scope.generateMemoisedReference(left);
|
||||
var temp = scope.maybeGenerateMemoised(left);
|
||||
|
||||
nodes.push(t.expressionStatement(t.assignmentExpression("=", temp, left)));
|
||||
nodes.push(buildDefaultsCallExpression(node, temp, file));
|
||||
|
||||
@@ -16,7 +16,9 @@ export default class TraversalContext {
|
||||
}
|
||||
|
||||
create(node, obj, key) {
|
||||
return TraversalPath.get(this.parentPath, this, node, obj, key);
|
||||
var path = TraversalPath.get(this.parentPath, node, obj, key);
|
||||
path.unshiftContext(this);
|
||||
return path;
|
||||
}
|
||||
|
||||
visitMultiple(nodes, node, key) {
|
||||
@@ -37,25 +39,32 @@ export default class TraversalContext {
|
||||
}
|
||||
|
||||
// visit the queue
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
var path = queue[i];
|
||||
for (let path of (queue: Array)) {
|
||||
path.update();
|
||||
|
||||
if (visited.indexOf(path.node) >= 0) continue;
|
||||
visited.push(path.node);
|
||||
|
||||
path.setContext(this.parentPath, this, path.key);
|
||||
|
||||
if (path.visit()) {
|
||||
stop = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let path of (queue: Array)) {
|
||||
path.shiftContext();
|
||||
}
|
||||
|
||||
this.queue = null;
|
||||
|
||||
return stop;
|
||||
}
|
||||
|
||||
visitSingle(node, key) {
|
||||
if (this.shouldVisit(node[key])) {
|
||||
return this.create(node, node, key).visit();
|
||||
var path = this.create(node, node, key);
|
||||
path.visit();
|
||||
path.shiftContext();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ export function evaluate(): { confident: boolean; value: any } {
|
||||
case "/": return left / right;
|
||||
case "*": return left * right;
|
||||
case "%": return left % right;
|
||||
case "**": return Math.pow(left, right);
|
||||
case "<": return left < right;
|
||||
case ">": return left > right;
|
||||
case "<=": return left <= right;
|
||||
|
||||
@@ -2,28 +2,24 @@ import * as react from "../../transformation/helpers/react";
|
||||
import * as t from "../../types";
|
||||
|
||||
var referenceVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (this.isJSXIdentifier() && react.isCompatTag(node.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.isJSXIdentifier() || this.isIdentifier()) {
|
||||
// direct references that we need to track to hoist this to the highest scope we can
|
||||
if (this.isReferenced()) {
|
||||
var bindingInfo = scope.getBinding(node.name);
|
||||
// direct references that we need to track to hoist this to the highest scope we can
|
||||
var bindingInfo = scope.getBinding(node.name);
|
||||
if (!bindingInfo) return;
|
||||
|
||||
// this binding isn't accessible from the parent scope so we can safely ignore it
|
||||
// eg. it's in a closure etc
|
||||
if (bindingInfo !== state.scope.getBinding(node.name)) return;
|
||||
// this binding isn't accessible from the parent scope so we can safely ignore it
|
||||
// eg. it's in a closure etc
|
||||
if (bindingInfo !== state.scope.getBinding(node.name)) return;
|
||||
|
||||
if (bindingInfo) {
|
||||
if (bindingInfo.constant) {
|
||||
state.bindings[node.name] = bindingInfo;
|
||||
} else {
|
||||
state.foundIncompatible = true;
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
if (bindingInfo.constant) {
|
||||
state.bindings[node.name] = bindingInfo;
|
||||
} else {
|
||||
for (var violationPath of (bindingInfo.constantViolations: Array)) {
|
||||
state.breakOnScopePaths.push(violationPath.scope.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,10 +27,10 @@ var referenceVisitor = {
|
||||
|
||||
export default class PathHoister {
|
||||
constructor(path, scope) {
|
||||
this.foundIncompatible = false;
|
||||
this.breakOnScopePaths = [];
|
||||
this.bindings = {};
|
||||
this.scope = scope;
|
||||
this.scopes = [];
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@@ -45,32 +41,41 @@ export default class PathHoister {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
getCompatibleScopes() {
|
||||
var checkScope = this.path.scope;
|
||||
var scope = this.path.scope;
|
||||
do {
|
||||
if (this.isCompatibleScope(checkScope)) {
|
||||
this.scopes.push(checkScope);
|
||||
if (this.isCompatibleScope(scope)) {
|
||||
this.scopes.push(scope);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while(checkScope = checkScope.parent);
|
||||
|
||||
if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
|
||||
break;
|
||||
}
|
||||
} while(scope = scope.parent);
|
||||
}
|
||||
|
||||
getAttachmentPath() {
|
||||
var scopes = this.scopes;
|
||||
|
||||
var scope = scopes.pop();
|
||||
if (!scope) return;
|
||||
|
||||
if (scope.path.isFunction()) {
|
||||
if (this.hasNonParamBindings()) {
|
||||
// can't be attached to this scope
|
||||
return this.getNextScopeStatementParent();
|
||||
} else {
|
||||
if (this.hasOwnParamBindings(scope)) {
|
||||
// should ignore this scope since it's ourselves
|
||||
if (this.scope.is(scope)) return;
|
||||
|
||||
// needs to be attached to the body
|
||||
return scope.path.get("body").get("body")[0];
|
||||
} else {
|
||||
// doesn't need to be be attached to this scope
|
||||
return this.getNextScopeStatementParent();
|
||||
}
|
||||
} else if (scope.path.isProgram()) {
|
||||
return this.getNextScopeStatementParent();
|
||||
@@ -82,10 +87,12 @@ export default class PathHoister {
|
||||
if (scope) return scope.path.getStatementParent();
|
||||
}
|
||||
|
||||
hasNonParamBindings() {
|
||||
hasOwnParamBindings(scope) {
|
||||
for (var name in this.bindings) {
|
||||
if (!scope.hasOwnBinding(name)) continue
|
||||
|
||||
var binding = this.bindings[name];
|
||||
if (binding.kind !== "param") return true;
|
||||
if (binding.kind === "param") return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -96,7 +103,6 @@ export default class PathHoister {
|
||||
node._hoisted = true;
|
||||
|
||||
this.path.traverse(referenceVisitor, this);
|
||||
if (this.foundIncompatible) return;
|
||||
|
||||
this.getCompatibleScopes();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import PathHoister from "./hoister";
|
||||
import * as virtualTypes from "./virtual-types";
|
||||
import * as messages from "../../messages";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import isRegExp from "lodash/lang/isRegExp";
|
||||
@@ -45,6 +46,7 @@ var hoistVariablesVisitor = explode({
|
||||
export default class TraversalPath {
|
||||
constructor(parent, container) {
|
||||
this.container = container;
|
||||
this.contexts = [];
|
||||
this.parent = parent;
|
||||
this.data = {};
|
||||
}
|
||||
@@ -53,7 +55,7 @@ export default class TraversalPath {
|
||||
* Description
|
||||
*/
|
||||
|
||||
static get(parentPath: TraversalPath, context?: TraversalContext, parent, container, key, file?: File) {
|
||||
static get(parentPath: TraversalPath, parent, container, key) {
|
||||
var targetNode = container[key];
|
||||
var paths = container._paths = container._paths || [];
|
||||
var path;
|
||||
@@ -71,7 +73,7 @@ export default class TraversalPath {
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
path.setContext(parentPath, context, key, file);
|
||||
path.setup(parentPath, key);
|
||||
|
||||
return path;
|
||||
}
|
||||
@@ -178,8 +180,10 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
queueNode(path) {
|
||||
if (this.context && this.context.queue) {
|
||||
this.context.queue.push(path);
|
||||
for (var context of (this.contexts: Array)) {
|
||||
if (context.queue) {
|
||||
context.queue.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +205,7 @@ export default class TraversalPath {
|
||||
this._containerInsertBefore(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.node = this.container[this.key] = t.blockStatement(nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
@@ -225,7 +229,7 @@ export default class TraversalPath {
|
||||
paths.push(path);
|
||||
this.queueNode(path);
|
||||
} else {
|
||||
paths.push(TraversalPath.get(this, null, node, this.container, to));
|
||||
paths.push(TraversalPath.get(this, node, this.container, to));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,10 +260,15 @@ export default class TraversalPath {
|
||||
|
||||
do {
|
||||
var container = path.container;
|
||||
|
||||
if (path.isFunction()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Array.isArray(container) && path.key !== container.length - 1) {
|
||||
return false;
|
||||
}
|
||||
} while (path = path.parentPath && !path.isProgram());
|
||||
} while ((path = path.parentPath) && !path.isProgram());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -287,7 +296,7 @@ export default class TraversalPath {
|
||||
return this.parentPath.insertAfter(nodes);
|
||||
} else if (this.isPreviousType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
|
||||
if (this.node) {
|
||||
var temp = this.scope.generateTemp();
|
||||
var temp = this.scope.generateDeclaredUidIdentifier();
|
||||
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
|
||||
nodes.push(t.expressionStatement(temp));
|
||||
}
|
||||
@@ -298,7 +307,7 @@ export default class TraversalPath {
|
||||
this._containerInsertAfter(nodes);
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.unshift(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.node = this.container[this.key] = t.blockStatement(nodes);
|
||||
} else {
|
||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||
}
|
||||
@@ -344,6 +353,8 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
setScope(file?) {
|
||||
if (this.opts && this.opts.noScope) return;
|
||||
|
||||
var target = this.context || this.parentPath;
|
||||
this.scope = TraversalPath.getScope(this, target && target.scope, file);
|
||||
}
|
||||
@@ -352,34 +363,87 @@ export default class TraversalPath {
|
||||
* Description
|
||||
*/
|
||||
|
||||
clearContext() {
|
||||
this.context = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
setContext(parentPath, context, key, file?) {
|
||||
setContext(context, file) {
|
||||
this.shouldSkip = false;
|
||||
this.shouldStop = false;
|
||||
this.removed = false;
|
||||
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.key = key;
|
||||
|
||||
if (context) {
|
||||
this.context = context;
|
||||
this.state = context.state;
|
||||
this.opts = context.opts;
|
||||
}
|
||||
|
||||
this.type = this.node && this.node.type;
|
||||
|
||||
var log = file && this.type === "Program";
|
||||
if (log) file.log.debug("Start scope building");
|
||||
this.setScope(file);
|
||||
if (log) file.log.debug("End scope building");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
update() {
|
||||
if (this.node === this.container[this.key]) return;
|
||||
|
||||
// grrr, path key is out of sync. this is likely due to a modification to the AST
|
||||
// not through our path APIs
|
||||
|
||||
if (Array.isArray(this.container)) {
|
||||
for (var i = 0; i < this.container.length; i++) {
|
||||
if (this.container[i] === this.node) {
|
||||
return this.setKey(i);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var key in this.container) {
|
||||
if (this.container[key] === this.node) {
|
||||
return this.setKey(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(messages.get("lostTrackNodePath"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
shiftContext() {
|
||||
this.contexts.shift();
|
||||
this.setContext(this.contexts[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
unshiftContext(context) {
|
||||
this.contexts.unshift(context);
|
||||
this.setContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
setup(parentPath, key) {
|
||||
this.parentPath = parentPath || this.parentPath;
|
||||
this.setKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
setKey(key) {
|
||||
this.key = key;
|
||||
this.node = this.container[this.key];
|
||||
this.type = this.node && this.node.type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,6 +534,7 @@ export default class TraversalPath {
|
||||
} else {
|
||||
this.container[this.key] = null;
|
||||
}
|
||||
this.node = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -500,18 +565,6 @@ export default class TraversalPath {
|
||||
return err;
|
||||
}
|
||||
|
||||
get node() {
|
||||
if (this.removed) {
|
||||
return null;
|
||||
} else {
|
||||
return this.container[this.key];
|
||||
}
|
||||
}
|
||||
|
||||
set node(replacement) {
|
||||
throw new Error("Don't use `path.node = newNode;`, use `path.replaceWith(newNode)` or `path.replaceWithMultiple([newNode])`");
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
@@ -564,7 +617,7 @@ export default class TraversalPath {
|
||||
// doesn't matter, our nodes will be inserted anyway
|
||||
|
||||
var container = this.node[containerKey];
|
||||
var path = TraversalPath.get(this, null, this.node, container, 0);
|
||||
var path = TraversalPath.get(this, this.node, container, 0);
|
||||
|
||||
return path.insertBefore(nodes);
|
||||
}
|
||||
@@ -581,7 +634,7 @@ export default class TraversalPath {
|
||||
|
||||
var container = this.node[containerKey];
|
||||
var i = container.length;
|
||||
var path = TraversalPath.get(this, null, this.node, container, i);
|
||||
var path = TraversalPath.get(this, this.node, container, i);
|
||||
|
||||
return path.replaceWith(nodes, true);
|
||||
}
|
||||
@@ -593,7 +646,7 @@ export default class TraversalPath {
|
||||
replaceWithMultiple(nodes: Array<Object>) {
|
||||
nodes = this._verifyNodeList(nodes);
|
||||
t.inheritsComments(nodes[0], this.node);
|
||||
this.container[this.key] = null;
|
||||
this.node = this.container[this.key] = null;
|
||||
this.insertAfter(nodes);
|
||||
if (!this.node) this.remove();
|
||||
}
|
||||
@@ -660,7 +713,7 @@ export default class TraversalPath {
|
||||
}
|
||||
|
||||
// replacing a statement with an expression so wrap it in an expression statement
|
||||
if (this.isPreviousType("Statement") && t.isExpression(replacement)) {
|
||||
if (this.isPreviousType("Statement") && t.isExpression(replacement) && !this.canHaveVariableDeclarationOrExpression()) {
|
||||
replacement = t.expressionStatement(replacement);
|
||||
}
|
||||
|
||||
@@ -673,13 +726,27 @@ export default class TraversalPath {
|
||||
if (oldNode) t.inheritsComments(replacement, oldNode);
|
||||
|
||||
// replace the node
|
||||
this.container[this.key] = replacement;
|
||||
this.node = this.container[this.key] = replacement;
|
||||
this.type = replacement.type;
|
||||
|
||||
// potentially create new scope
|
||||
this.setScope();
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks whether or now we're in one of the following positions:
|
||||
*
|
||||
* for (KEY in right);
|
||||
* for (KEY;;);
|
||||
*
|
||||
* This is because these spots allow VariableDeclarations AND normal expressions so we need to tell the
|
||||
* path replacement that it's ok to replace this with an expression.
|
||||
*/
|
||||
|
||||
canHaveVariableDeclarationOrExpression() {
|
||||
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
@@ -706,20 +773,22 @@ export default class TraversalPath {
|
||||
* Description
|
||||
*/
|
||||
|
||||
getLastStatements(): Array<TraversalPath> {
|
||||
getCompletionRecords(): Array<TraversalPath> {
|
||||
var paths = [];
|
||||
|
||||
var add = function (path) {
|
||||
if (path) paths = paths.concat(path.getLastStatements());
|
||||
if (path) paths = paths.concat(path.getCompletionRecords());
|
||||
};
|
||||
|
||||
if (this.isIfStatement()) {
|
||||
add(this.get("consequent"));
|
||||
add(this.get("alternate"));
|
||||
} else if (this.isDoExpression()) {
|
||||
} else if (this.isDoExpression() || this.isFor() || this.isWhile()) {
|
||||
add(this.get("body"));
|
||||
} else if (this.isProgram() || this.isBlockStatement()) {
|
||||
add(this.get("body").pop());
|
||||
} else if (this.isFunction()) {
|
||||
return this.get("body").getCompletionRecords();
|
||||
} else {
|
||||
paths.push(this);
|
||||
}
|
||||
@@ -740,19 +809,27 @@ export default class TraversalPath {
|
||||
var container = t.functionExpression(null, [], t.blockStatement(nodes));
|
||||
container.shadow = true;
|
||||
|
||||
this.replaceWith(t.callExpression(container, []));
|
||||
this.traverse(hoistVariablesVisitor);
|
||||
|
||||
// add implicit returns to all ending expression statements
|
||||
var last = this.getLastStatements();
|
||||
var last = this.get("callee").getCompletionRecords();
|
||||
for (var i = 0; i < last.length; i++) {
|
||||
var lastNode = last[i];
|
||||
if (lastNode.isExpressionStatement()) {
|
||||
lastNode.replaceWith(t.returnStatement(lastNode.node.expression));
|
||||
var loop = lastNode.findParent((node, path) => path.isLoop());
|
||||
if (loop) {
|
||||
var uid = this.get("callee").scope.generateDeclaredUidIdentifier("ret");
|
||||
this.get("callee.body").pushContainer("body", t.returnStatement(uid));
|
||||
lastNode.get("expression").replaceWith(
|
||||
t.assignmentExpression("=", uid, lastNode.node.expression)
|
||||
);
|
||||
} else {
|
||||
lastNode.replaceWith(t.returnStatement(lastNode.node.expression));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.replaceWith(t.callExpression(container, []));
|
||||
|
||||
this.traverse(hoistVariablesVisitor);
|
||||
|
||||
return this.node;
|
||||
}
|
||||
}
|
||||
@@ -777,9 +854,10 @@ export default class TraversalPath {
|
||||
var node = this.node;
|
||||
if (!node) return;
|
||||
|
||||
var previousType = this.type;
|
||||
|
||||
// call the function with the params (node, parent, scope, state)
|
||||
var replacement = fn.call(this, node, this.parent, this.scope, this.state);
|
||||
var previousType = this.type;
|
||||
|
||||
if (replacement) {
|
||||
this.replaceWith(replacement, true);
|
||||
@@ -787,7 +865,7 @@ export default class TraversalPath {
|
||||
|
||||
if (this.shouldStop || this.shouldSkip || this.removed) return;
|
||||
|
||||
if (replacement && previousType !== this.type) {
|
||||
if (previousType !== this.type) {
|
||||
this.queueNode(this);
|
||||
return;
|
||||
}
|
||||
@@ -841,7 +919,7 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
getSibling(key) {
|
||||
return TraversalPath.get(this.parentPath, null, this.parent, this.container, key, this.file);
|
||||
return TraversalPath.get(this.parentPath, this.parent, this.container, key, this.file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -868,10 +946,10 @@ export default class TraversalPath {
|
||||
if (Array.isArray(container)) {
|
||||
// requested a container so give them all the paths
|
||||
return container.map((_, i) => {
|
||||
return TraversalPath.get(this, null, node, container, i);
|
||||
return TraversalPath.get(this, node, container, i).setContext();
|
||||
});
|
||||
} else {
|
||||
return TraversalPath.get(this, null, node, node, key);
|
||||
return TraversalPath.get(this, node, node, key).setContext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,6 +1183,7 @@ export default class TraversalPath {
|
||||
*/
|
||||
|
||||
traverse(visitor, state) {
|
||||
if (!this.scope) console.log(this.contexts);
|
||||
traverse(this.node, visitor, this.scope, state, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import * as t from "../types";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class Binding {
|
||||
constructor({ identifier, scope, path, kind }) {
|
||||
this.constantViolations = [];
|
||||
this.constant = true;
|
||||
|
||||
this.identifier = identifier;
|
||||
this.references = 0;
|
||||
this.referenced = false;
|
||||
this.constant = true;
|
||||
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
this.kind = kind;
|
||||
@@ -51,8 +54,9 @@ export default class Binding {
|
||||
* Description
|
||||
*/
|
||||
|
||||
reassign() {
|
||||
reassign(path) {
|
||||
this.constant = false;
|
||||
this.constantViolations.push(path);
|
||||
|
||||
if (this.typeAnnotationInferred) {
|
||||
// destroy the inferred typeAnnotation
|
||||
@@ -1,15 +1,15 @@
|
||||
import includes from "lodash/collection/includes";
|
||||
import { explode } from "./visitors";
|
||||
import traverse from "./index";
|
||||
import { explode } from "../visitors";
|
||||
import traverse from "../index";
|
||||
import defaults from "lodash/object/defaults";
|
||||
import * as messages from "../messages";
|
||||
import * as messages from "../../messages";
|
||||
import Binding from "./binding";
|
||||
import globals from "globals";
|
||||
import flatten from "lodash/array/flatten";
|
||||
import extend from "lodash/object/extend";
|
||||
import object from "../helpers/object";
|
||||
import object from "../../helpers/object";
|
||||
import each from "lodash/collection/each";
|
||||
import * as t from "../types";
|
||||
import * as t from "../../types";
|
||||
|
||||
var functionVariableVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -163,11 +163,22 @@ export default class Scope {
|
||||
traverse(node, opts, this, state, this.path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Since `Scope` instances are unique to their traversal we need some other
|
||||
* way to compare if scopes are the same. Here we just compare `this.bindings`
|
||||
* as it will be the same across all instances.
|
||||
*/
|
||||
|
||||
is(scope) {
|
||||
return this.bindings === scope.bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
generateTemp(name: string = "temp") {
|
||||
generateDeclaredUidIdentifier(name: string = "temp") {
|
||||
var id = this.generateUidIdentifier(name);
|
||||
this.push({ id });
|
||||
return id;
|
||||
@@ -213,7 +224,7 @@ export default class Scope {
|
||||
* Description
|
||||
*/
|
||||
|
||||
generateUidBasedOnNode(parent: Object, defaultName?: String): Object {
|
||||
generateUidIdentifierBasedOnNode(parent: Object, defaultName?: String): Object {
|
||||
var node = parent;
|
||||
|
||||
if (t.isAssignmentExpression(parent)) {
|
||||
@@ -264,21 +275,39 @@ export default class Scope {
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
* Determine whether evaluating the specific input `node` is a consequenceless reference. ie.
|
||||
* evaluating it wont result in potentially arbitrary code from being ran. The following are
|
||||
* whitelisted and determined not cause side effects:
|
||||
*
|
||||
* - `this` expressions
|
||||
* - `super` expressions
|
||||
* - Bound identifiers
|
||||
*/
|
||||
|
||||
generateMemoisedReference(node: Object, dontPush?: boolean): ?Object {
|
||||
isStatic(node: Object): boolean {
|
||||
if (t.isThisExpression(node) || t.isSuper(node)) {
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (t.isIdentifier(node) && this.hasBinding(node.name)) {
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
var id = this.generateUidBasedOnNode(node);
|
||||
if (!dontPush) this.push({ id });
|
||||
return id;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
maybeGenerateMemoised(node: Object, dontPush?: boolean): ?Object {
|
||||
if (this.isStatic(node)) {
|
||||
return null;
|
||||
} else {
|
||||
var id = this.generateUidIdentifierBasedOnNode(node);
|
||||
if (!dontPush) this.push({ id });
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,11 +446,13 @@ export default class Scope {
|
||||
for (var name in ids) {
|
||||
var binding = this.getBinding(name);
|
||||
if (!binding) continue;
|
||||
|
||||
if (right) {
|
||||
var rightType = right.typeAnnotation;
|
||||
if (rightType && binding.isCompatibleWithType(rightType)) continue;
|
||||
}
|
||||
binding.reassign();
|
||||
|
||||
binding.reassign(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,6 +463,14 @@ export default class Scope {
|
||||
registerBinding(kind: string, path: TraversalPath) {
|
||||
if (!kind) throw new ReferenceError("no `kind`");
|
||||
|
||||
if (path.isVariableDeclaration()) {
|
||||
var declarators = path.get("declarations");
|
||||
for (var declar of (declarators: Array)) {
|
||||
this.registerBinding(kind, declar);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var ids = path.getBindingIdentifiers();
|
||||
|
||||
for (var name in ids) {
|
||||
@@ -514,7 +553,7 @@ export default class Scope {
|
||||
isPure(node) {
|
||||
if (t.isIdentifier(node)) {
|
||||
var bindingInfo = this.getBinding(node.name);
|
||||
return bindingInfo.constant;
|
||||
return bindingInfo && bindingInfo.constant;
|
||||
} else {
|
||||
return t.isPure(node);
|
||||
}
|
||||
@@ -560,8 +599,13 @@ export default class Scope {
|
||||
|
||||
// Class
|
||||
|
||||
if (path.isClass() && path.has("id")) {
|
||||
this.registerBinding("var", path.get("id"));
|
||||
if (path.isClassDeclaration()) {
|
||||
var name = path.node.id.name;
|
||||
this.bindings[name] = this.parent.bindings[name];
|
||||
}
|
||||
|
||||
if (path.isClassExpression() && path.has("id")) {
|
||||
this.registerBinding("var", path);
|
||||
}
|
||||
|
||||
// Function - params, rest
|
||||
@@ -20,6 +20,11 @@
|
||||
"right": null
|
||||
},
|
||||
|
||||
"BindExpression": {
|
||||
"object": null,
|
||||
"callee": null
|
||||
},
|
||||
|
||||
"BlockStatement": {
|
||||
"body": null
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"AssignmentPattern": ["left", "right"],
|
||||
"AwaitExpression": ["argument"],
|
||||
"BinaryExpression": ["left", "right"],
|
||||
"BindExpression": ["object", "callee"],
|
||||
"BlockStatement": ["body"],
|
||||
"BreakStatement": ["label"],
|
||||
"CallExpression": ["callee", "arguments"],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import "./patch";
|
||||
|
||||
import escapeRegExp from "lodash/string/escapeRegExp";
|
||||
|
||||
import startsWith from "lodash/string/startsWith";
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import * as messages from "./messages";
|
||||
@@ -69,9 +69,23 @@ export function list(val: string): Array<string> {
|
||||
|
||||
export function regexify(val: any): RegExp {
|
||||
if (!val) return new RegExp(/.^/);
|
||||
|
||||
if (Array.isArray(val)) val = new RegExp(val.map(escapeRegExp).join("|"), "i");
|
||||
if (isString(val)) return minimatch.makeRe(val, { nocase: true });
|
||||
|
||||
if (isString(val)) {
|
||||
// normalise path separators
|
||||
val = slash(val);
|
||||
|
||||
// remove starting wildcards or relative separator if present
|
||||
if (startsWith(val, "./") || startsWith(val, "*/")) val = val.slice(2);
|
||||
if (startsWith(val, "**/")) val = val.slice(3);
|
||||
|
||||
var regex = minimatch.makeRe(val, { nocase: true });
|
||||
return new RegExp(regex.source.slice(1, -1), "i");
|
||||
}
|
||||
|
||||
if (isRegExp(val)) return val;
|
||||
|
||||
throw new TypeError("illegal type for regexify");
|
||||
}
|
||||
|
||||
@@ -96,6 +110,7 @@ export function booleanify(val: any): boolean {
|
||||
|
||||
export function shouldIgnore(filename, ignore, only) {
|
||||
filename = slash(filename);
|
||||
|
||||
if (only.length) {
|
||||
for (var pattern of (only: Array)) {
|
||||
if (pattern.test(filename)) return false;
|
||||
|
||||
@@ -99,6 +99,47 @@ suite("api", function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite("env option", function () {
|
||||
var oldBabelEnv = process.env.BABEL_ENV;
|
||||
var oldNodeEnv = process.env.NODE_ENV;
|
||||
|
||||
before(function () {
|
||||
delete process.env.BABEL_ENV;
|
||||
delete process.env.NODE_ENV;
|
||||
});
|
||||
|
||||
after(function () {
|
||||
process.env.BABEL_ENV = oldBabelEnv;
|
||||
process.env.NODE_ENV = oldNodeEnv;
|
||||
});
|
||||
|
||||
test("default", function () {
|
||||
assert.equal(transform("foo;", {
|
||||
env: {
|
||||
development: { blacklist: "strict" }
|
||||
}
|
||||
}).code, "foo;");
|
||||
});
|
||||
|
||||
test("BABEL_ENV", function () {
|
||||
process.env.BABEL_ENV = "foo";
|
||||
assert.equal(transform("foo;", {
|
||||
env: {
|
||||
foo: { blacklist: "strict" }
|
||||
}
|
||||
}).code, "foo;");
|
||||
});
|
||||
|
||||
test("NODE_ENV", function () {
|
||||
process.env.NODE_ENV = "foo";
|
||||
assert.equal(transform("foo;", {
|
||||
env: {
|
||||
foo: { blacklist: "strict" }
|
||||
}
|
||||
}).code, "foo;");
|
||||
});
|
||||
});
|
||||
|
||||
test("addHelper unknown", function () {
|
||||
var file = new File({}, transform.pipeline);
|
||||
assert.throws(function () {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
function foo(l) {
|
||||
return (
|
||||
// hi
|
||||
l
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
function foo(l){
|
||||
return (
|
||||
|
||||
l);}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"retainLines": true,
|
||||
"compact": true
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
::foo.bar.foo;
|
||||
::foo.bar["foo"];
|
||||
|
||||
ctx::foo.bar.foo;
|
||||
ctx::foo.bar["foo"];
|
||||
@@ -0,0 +1,5 @@
|
||||
::foo.bar.foo;
|
||||
::foo.bar["foo"];
|
||||
|
||||
ctx::foo.bar.foo;
|
||||
ctx::foo.bar["foo"];
|
||||
@@ -0,0 +1,8 @@
|
||||
const foo = "foo";
|
||||
|
||||
function foobar() {
|
||||
for (let item of [1, 2, 3]) {
|
||||
let foo = "bar";
|
||||
[bar, foo] = [1, 2];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
var foo = "foo";
|
||||
|
||||
function foobar() {
|
||||
var _arr = [1, 2, 3];
|
||||
|
||||
for (var _i = 0; _i < _arr.length; _i++) {
|
||||
var item = _arr[_i];
|
||||
var _foo = "bar";
|
||||
bar = 1;
|
||||
_foo = 2;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
define(["exports", "foo"], function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _foo2 = babelHelpers.interopRequire(_foo);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
var _foo22 = babelHelpers.interopRequire(_foo);
|
||||
var _foo22 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
_foo2;
|
||||
_foo22;
|
||||
_foo2["default"];
|
||||
_foo22["default"];
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
define(["exports", "foo"], function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _foo2 = babelHelpers.interopRequire(_foo);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
_foo2;
|
||||
_foo2["default"];
|
||||
_foo.baz;
|
||||
});
|
||||
@@ -5,7 +5,7 @@ define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports,
|
||||
value: true
|
||||
});
|
||||
|
||||
var _foo2 = babelHelpers.interopRequire(_foo);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
exports.test = test;
|
||||
var test2 = 5;
|
||||
@@ -13,7 +13,7 @@ define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports,
|
||||
exports.test2 = test2;
|
||||
exports["default"] = test;
|
||||
|
||||
_foo2;
|
||||
_foo2["default"];
|
||||
_foo;
|
||||
_foo.bar;
|
||||
_foo.foo;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function module() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.module = _module;
|
||||
|
||||
function _module() {}
|
||||
@@ -6,6 +6,8 @@ export function nextOdd(n) {
|
||||
|
||||
export var p = 5;
|
||||
|
||||
for (var a in b) ;
|
||||
|
||||
export var isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
System.register(["./evens"], function (_export) {
|
||||
"use strict";
|
||||
|
||||
var isEven, p, isOdd;
|
||||
var isEven, p, a, isOdd;
|
||||
|
||||
_export("nextOdd", nextOdd);
|
||||
|
||||
@@ -18,6 +18,8 @@ System.register(["./evens"], function (_export) {
|
||||
|
||||
_export("p", p);
|
||||
|
||||
for (a in b);
|
||||
|
||||
isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
})(this, function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _foo2 = babelHelpers.interopRequire(_foo);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
var _foo22 = babelHelpers.interopRequire(_foo);
|
||||
var _foo22 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
_foo2;
|
||||
_foo22;
|
||||
_foo2["default"];
|
||||
_foo22["default"];
|
||||
});
|
||||
@@ -13,7 +13,7 @@
|
||||
})(this, function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var _foo2 = babelHelpers.interopRequire(_foo);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
_foo.baz;
|
||||
});
|
||||
@@ -17,7 +17,7 @@
|
||||
value: true
|
||||
});
|
||||
|
||||
var _foo2 = babelHelpers.interopRequire(_foo);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
exports.test = test;
|
||||
var test2 = 5;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
(function(){
|
||||
var foo = () => {
|
||||
this;
|
||||
arguments;
|
||||
foo();
|
||||
};
|
||||
foo();
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
(function () {
|
||||
var _this = this,
|
||||
_arguments = arguments;
|
||||
|
||||
var foo = function foo() {
|
||||
_this;
|
||||
_arguments;
|
||||
foo();
|
||||
};
|
||||
foo();
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
var f = ctx::ns.obj.func;
|
||||
var g = ::ns.obj.func;
|
||||
var h = new X::y;
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var _context;
|
||||
|
||||
var f = (_context = ctx, ns.obj.func).bind(_context);
|
||||
var g = (_context = ns.obj).func.bind(_context);
|
||||
var h = (_context = new X(), y).bind(_context);
|
||||
@@ -0,0 +1,4 @@
|
||||
ctx::ns.obj.func();
|
||||
::ns.obj.func();
|
||||
|
||||
ns.obj2::ns.obj1.func();
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _context;
|
||||
|
||||
(_context = ctx, ns.obj.func).call(_context);
|
||||
(_context = ns.obj).func.call(_context);
|
||||
|
||||
(_context = ns.obj2, ns.obj1.func).call(_context);
|
||||
@@ -0,0 +1,6 @@
|
||||
import { map, takeWhile, forEach } from "iterlib";
|
||||
|
||||
getPlayers()
|
||||
::map(x => x.character())
|
||||
::takeWhile(x => x.strength > 100)
|
||||
::forEach(x => console.log(x));
|
||||
@@ -0,0 +1,27 @@
|
||||
var operations = [];
|
||||
|
||||
var lib = {};
|
||||
|
||||
for (let key of ['f', 'g', 'h']) {
|
||||
let func = () => operations.push(`lib.${key}()`);
|
||||
Object.defineProperty(lib, key, {
|
||||
get() {
|
||||
operations.push(`get lib.${key}`);
|
||||
return func;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
({prop:'value'})
|
||||
::lib.f()
|
||||
::lib.g()
|
||||
::lib.h();
|
||||
|
||||
assert.deepEqual(operations, [
|
||||
'get lib.f',
|
||||
'lib.f()',
|
||||
'get lib.g',
|
||||
'lib.g()',
|
||||
'get lib.h',
|
||||
'lib.h()'
|
||||
]);
|
||||
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
var _context;
|
||||
|
||||
var _iterlib = require("iterlib");
|
||||
|
||||
(_context = (_context = (_context = getPlayers(), _iterlib.map).call(_context, function (x) {
|
||||
return x.character();
|
||||
}), _iterlib.takeWhile).call(_context, function (x) {
|
||||
return x.strength > 100;
|
||||
}), _iterlib.forEach).call(_context, function (x) {
|
||||
return console.log(x);
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"optional": "es7.functionBind"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
var bar = function () {};
|
||||
foo::bar;
|
||||
|
||||
var foo = {};
|
||||
::foo.bar;
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var bar = function bar() {};
|
||||
bar.bind(foo);
|
||||
|
||||
var foo = {};
|
||||
foo.bar.bind(foo);
|
||||
@@ -0,0 +1,4 @@
|
||||
class A {
|
||||
constructor() { this.value = 12345; }
|
||||
}
|
||||
export default new A();
|
||||
@@ -0,0 +1,3 @@
|
||||
import aInstance from './imported';
|
||||
|
||||
assert.equal(aInstance.value, 12345);
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var A = function A() {
|
||||
babelHelpers.classCallCheck(this, A);
|
||||
this.value = 12345;
|
||||
};
|
||||
|
||||
exports["default"] = new A();
|
||||
module.exports = exports["default"];
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class A {
|
||||
constructor() { this.value = 12345; }
|
||||
}
|
||||
export default new A();
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
f() { return 1235; }
|
||||
}
|
||||
|
||||
let a = new A();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user