Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aefd69d31e | ||
|
|
e328031b19 | ||
|
|
571b6a4cd7 | ||
|
|
41cf942391 | ||
|
|
98f28b8e89 | ||
|
|
8f88afc037 | ||
|
|
6359675a4f | ||
|
|
a265c3f25c | ||
|
|
29eb99ee93 | ||
|
|
0c5c1ff989 | ||
|
|
499951123a | ||
|
|
c0fd4c1f9e | ||
|
|
579e6fecee | ||
|
|
bb3665a3b6 | ||
|
|
e6de688234 | ||
|
|
4c233e88ff | ||
|
|
ae2ba0b5a3 | ||
|
|
e34d950793 | ||
|
|
e4083fbbd7 | ||
|
|
59ed7977ef | ||
|
|
dc441e9a8f | ||
|
|
2e21795f57 | ||
|
|
5c988f7fc8 | ||
|
|
493826973e | ||
|
|
1acc71aa4e | ||
|
|
bbab5f72ec | ||
|
|
58ff9e387a | ||
|
|
5a0d099984 | ||
|
|
05c95e04f7 | ||
|
|
88430b4be2 | ||
|
|
19adcfae4d | ||
|
|
7c4fe984ce | ||
|
|
4476e8311c | ||
|
|
2a3142273d | ||
|
|
bbcb889a49 | ||
|
|
c87f85815b | ||
|
|
48d0df17d0 | ||
|
|
01b243347f | ||
|
|
45a5cbf72f | ||
|
|
05efae1c58 | ||
|
|
c08fff4b44 | ||
|
|
13e910ea83 | ||
|
|
b308602098 | ||
|
|
560a044d8f | ||
|
|
619fbe4c3b | ||
|
|
1d83ad6cce | ||
|
|
5353ccd773 | ||
|
|
a8e23d2eb9 | ||
|
|
95d830fde0 | ||
|
|
c8a5d7d970 | ||
|
|
43481eb2cc | ||
|
|
b8bb665691 | ||
|
|
e6846b2730 | ||
|
|
31c1286a3c | ||
|
|
489f9e92b5 | ||
|
|
073809efac | ||
|
|
c9b8e2f3ce | ||
|
|
c6cb871355 | ||
|
|
1b0e5b3ed1 | ||
|
|
0f70c76312 |
3
.babelrc
3
.babelrc
@@ -2,5 +2,6 @@
|
||||
"stage": 0,
|
||||
"loose": ["all"],
|
||||
"blacklist": ["es6.tailCall"],
|
||||
"optional": ["optimisation.flow.forOf"]
|
||||
"optional": ["optimisation.flow.forOf"],
|
||||
"plugins": ["./tools/build-plugins/protect"]
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
"new-cap": 0,
|
||||
"no-loop-func": 0,
|
||||
"no-unreachable": 0,
|
||||
"no-labels": 0
|
||||
"no-labels": 0,
|
||||
"no-process-exit": 0
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
|
||||
25
CHANGELOG.md
25
CHANGELOG.md
@@ -13,6 +13,29 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.6.12
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix finding parent for top-level shadowed functions.
|
||||
|
||||
## 5.6.11
|
||||
|
||||
** **Internal**
|
||||
* Merge `es6.parameters.rest` and `es6.parameters.default` transformers. See commit [c0fd4c1f9e0b18231f585c4fa793e4cb0e01aed1](https://github.com/babel/babel/commit/c0fd4c1f9e0b18231f585c4fa793e4cb0e01aed1) for more info.
|
||||
|
||||
## 5.6.10
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix faulty internal require check.
|
||||
* **Polish**
|
||||
* Add support for trailing commas in arrow function parameter lists.
|
||||
|
||||
## 5.6.8
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix binary expressions colliding with unary expression operators in compact mode.
|
||||
* Fix node properties being set to `null` when using computed properties.
|
||||
|
||||
## 5.6.7
|
||||
|
||||
* **Bug Fix**
|
||||
@@ -29,7 +52,7 @@ See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.6.5
|
||||
|
||||
* *Bug Fix**
|
||||
* **Bug Fix**
|
||||
* Fix nested functions causing rest parameter optimisation to not properly detect when it should deopt on a reference.
|
||||
* **Internal**
|
||||
* Update Regenerator `0.8.31`.
|
||||
|
||||
@@ -113,8 +113,6 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad
|
||||
|
||||
+ [js-tokens](http://ghub.io/js-tokens) This is used to get tokens for syntax error highlighting.
|
||||
|
||||
+ [leven](http://ghub.io/leven) A levenstein algorithm to determine how close a word is to another. This is used to offer suggestions when using the utility.undeclaredVariableCheck transformer.
|
||||
|
||||
+ [line-numbers](http://ghub.io/line-numbers) Used to produce the code frames in syntax errors.
|
||||
|
||||
+ [lodash](http://ghub.io/lodash) Used for various utilities.
|
||||
|
||||
2
Makefile
2
Makefile
@@ -24,7 +24,7 @@ clean-core:
|
||||
rm -rf lib
|
||||
|
||||
lint:
|
||||
eslint src/babel
|
||||
eslint src/babel packages/babel-cli/bin
|
||||
|
||||
build:
|
||||
mkdir -p dist
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "A compiler for writing next generation JavaScript",
|
||||
"version": "5.6.7",
|
||||
"version": "5.6.12",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"main": "lib/babel/api/node.js",
|
||||
"browser": {
|
||||
"./lib/babel/api/register/node.js": "./lib/babel/api/register/browser.js"
|
||||
},
|
||||
@@ -57,11 +56,11 @@
|
||||
"home-or-tmp": "^1.0.0",
|
||||
"is-integer": "^1.0.4",
|
||||
"js-tokens": "1.0.1",
|
||||
"leven": "^1.0.1",
|
||||
"line-numbers": "0.2.0",
|
||||
"lodash": "^3.6.0",
|
||||
"minimatch": "^2.0.3",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-exists": "^1.0.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"private": "^0.1.6",
|
||||
"regenerator": "0.8.31",
|
||||
@@ -77,7 +76,7 @@
|
||||
"trim-right": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "5.5.7",
|
||||
"babel": "5.6.10",
|
||||
"browserify": "^9.0.8",
|
||||
"chai": "^2.2.0",
|
||||
"eslint": "^0.21.2",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var readline = require("readline");
|
||||
var child = require("child_process");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var pathExists = require("path-exists");
|
||||
var readline = require("readline");
|
||||
var child = require("child_process");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
function spawn(cmd, args, callback) {
|
||||
console.log(">", cmd, args);
|
||||
@@ -34,7 +35,7 @@ function spawnMultiple(cmds) {
|
||||
}
|
||||
|
||||
function template(name, data) {
|
||||
var source = fs.readFileSync(__dirname + "/templates/" + name, "utf8");
|
||||
var source = fs.readFileSync(path.join(__dirname, "templates", name), "utf8");
|
||||
source = source.replace(/[A-Z_]+/g, function (key) {
|
||||
return data[key] === undefined ? key : data[key];
|
||||
});
|
||||
@@ -98,7 +99,7 @@ var cmds = {
|
||||
|
||||
write("README.md", template("README.md", templateData));
|
||||
|
||||
if (!fs.existsSync("src")) {
|
||||
if (!pathExists.sync("src")) {
|
||||
fs.mkdirSync("src");
|
||||
write("src/index.js", template("index.js", templateData));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var outputFileSync = require("output-file-sync");
|
||||
var pathExists = require("path-exists");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
var path = require("path");
|
||||
@@ -6,7 +7,7 @@ var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames, opts) {
|
||||
module.exports = function (commander, filenames) {
|
||||
var write = function (src, relative) {
|
||||
// remove extension and then append back on .js
|
||||
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
|
||||
@@ -41,7 +42,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
};
|
||||
|
||||
var handle = function (filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
if (!pathExists.sync(filename)) return;
|
||||
|
||||
var stat = fs.statSync(filename);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var convertSourceMap = require("convert-source-map");
|
||||
var pathExists = require("path-exists");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var slash = require("slash");
|
||||
@@ -100,7 +101,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
results = [];
|
||||
|
||||
_.each(filenames, function (filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
if (!pathExists.sync(filename)) return;
|
||||
|
||||
var stat = fs.statSync(filename);
|
||||
if (stat.isDirectory()) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require("babel-core");
|
||||
|
||||
var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
|
||||
var pathExists = require("path-exists");
|
||||
var commander = require("commander");
|
||||
var transform = require("babel-core").transform;
|
||||
var kebabCase = require("lodash/string/kebabCase");
|
||||
@@ -9,7 +12,6 @@ var util = require("babel-core").util;
|
||||
var uniq = require("lodash/array/uniq");
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
var fs = require("fs");
|
||||
var glob = require("glob");
|
||||
|
||||
each(options, function (option, key) {
|
||||
@@ -88,7 +90,7 @@ var filenames = commander.args.reduce(function (globbed, input) {
|
||||
filenames = uniq(filenames);
|
||||
|
||||
each(filenames, function (filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
if (!pathExists.sync(filename)) {
|
||||
errors.push(filename + " doesn't exist");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.6.6",
|
||||
"version": "5.6.11",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.6.6",
|
||||
"babel-core": "^5.6.11",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
@@ -16,6 +16,7 @@
|
||||
"glob": "^5.0.5",
|
||||
"lodash": "^3.2.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"path-exists": "^1.0.0",
|
||||
"path-is-absolute": "^1.0.0",
|
||||
"source-map": "^0.4.0",
|
||||
"slash": "^1.0.0"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.6.6",
|
||||
"version": "5.6.11",
|
||||
"license": "MIT",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
|
||||
@@ -432,9 +432,18 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
|
||||
}
|
||||
|
||||
let innerStart = this.markPosition(), exprList = [], first = true
|
||||
let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart
|
||||
let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart, optionalCommaStart
|
||||
while (this.type !== tt.parenR) {
|
||||
first ? first = false : this.expect(tt.comma)
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
this.expect(tt.comma)
|
||||
if (this.type === tt.parenR && this.options.features["es7.trailingFunctionCommas"]) {
|
||||
optionalCommaStart = this.start
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (this.type === tt.ellipsis) {
|
||||
let spreadNodeStart = this.markPosition()
|
||||
spreadStart = this.start
|
||||
@@ -462,6 +471,7 @@ pp.parseParenAndDistinguishExpression = function(start, isAsync, canBeArrow) {
|
||||
this.unexpected(this.lastTokStart)
|
||||
}
|
||||
}
|
||||
if (optionalCommaStart) this.unexpected(optionalCommaStart)
|
||||
if (spreadStart) this.unexpected(spreadStart)
|
||||
if (refShorthandDefaultPos.start) this.unexpected(refShorthandDefaultPos.start)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import homeOrTmp from "home-or-tmp";
|
||||
import pathExists from "path-exists";
|
||||
|
||||
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
|
||||
var data = {};
|
||||
@@ -15,7 +16,7 @@ export function load() {
|
||||
process.on("exit", save);
|
||||
process.nextTick(save);
|
||||
|
||||
if (!fs.existsSync(FILENAME)) return;
|
||||
if (!pathExists.sync(FILENAME)) return;
|
||||
|
||||
try {
|
||||
data = JSON.parse(fs.readFileSync(FILENAME));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export function ClassDeclaration(node, print) {
|
||||
print.list(node.decorators);
|
||||
print.list(node.decorators, { separator: "" });
|
||||
this.push("class");
|
||||
|
||||
if (node.id) {
|
||||
@@ -43,7 +43,7 @@ export function ClassBody(node, print) {
|
||||
|
||||
|
||||
export function ClassProperty(node, print) {
|
||||
print.list(node.decorators);
|
||||
print.list(node.decorators, { separator: "" });
|
||||
|
||||
if (node.static) this.push("static ");
|
||||
print.plain(node.key);
|
||||
@@ -58,7 +58,7 @@ export function ClassProperty(node, print) {
|
||||
}
|
||||
|
||||
export function MethodDefinition(node, print) {
|
||||
print.list(node.decorators);
|
||||
print.list(node.decorators, { separator: "" });
|
||||
|
||||
if (node.static) {
|
||||
this.push("static ");
|
||||
|
||||
@@ -140,6 +140,7 @@ export function AssignmentExpression(node, print) {
|
||||
print.plain(node.left);
|
||||
|
||||
var spaces = node.operator === "in" || node.operator === "instanceof";
|
||||
spaces = true; // todo: https://github.com/babel/babel/issues/1835
|
||||
this.space(spaces);
|
||||
|
||||
this.push(node.operator);
|
||||
|
||||
@@ -33,6 +33,8 @@ export function ObjectExpression(node, print) {
|
||||
export { ObjectExpression as ObjectPattern };
|
||||
|
||||
export function Property(node, print) {
|
||||
print.list(node.decorators, { separator: "" });
|
||||
|
||||
if (node.method || node.kind === "get" || node.kind === "set") {
|
||||
this._method(node, print);
|
||||
} else {
|
||||
|
||||
9
src/babel/tools/protect.js
Normal file
9
src/babel/tools/protect.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import path from "path";
|
||||
|
||||
var root = path.resolve(__dirname, "../../../");
|
||||
|
||||
export default function (module) {
|
||||
if (module.parent && module.parent.filename.indexOf(root) !== 0) {
|
||||
throw new Error("Don't hotlink internal Babel files.");
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,15 @@ import { normaliseOptions } from "./index";
|
||||
import merge from "../../../helpers/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import pathExists from "path-exists";
|
||||
|
||||
var cache = {};
|
||||
var jsons = {};
|
||||
|
||||
function exists(filename) {
|
||||
if (!fs.existsSync) return false;
|
||||
|
||||
var cached = cache[filename];
|
||||
if (cached != null) return cached;
|
||||
return cache[filename] = fs.existsSync(filename);
|
||||
return cache[filename] = pathExists.sync(filename);
|
||||
}
|
||||
|
||||
export default function (loc, opts = {}) {
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
(function (obj, key, value) {
|
||||
return Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
// Shortcircuit the slow defineProperty path when possible.
|
||||
// We are trying to avoid issues where setters defined on the
|
||||
// prototype cause side effects under the fast path of simple
|
||||
// assignment. By checking for existence of the property with
|
||||
// the in operator, we can optimize most of this overhead away.
|
||||
if (key in obj) {
|
||||
Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(function (arr, i) {
|
||||
if (Array.isArray(arr)) {
|
||||
return arr;
|
||||
} else if (Symbol.iterator in Object(arr)) {
|
||||
(function () {
|
||||
// Broken out into a separate function to avoid deoptimizations due to the try/catch for the
|
||||
// array iterator case.
|
||||
function sliceIterator(arr, i) {
|
||||
// this is an expanded form of `for...of` that properly supports abrupt completions of
|
||||
// iterators etc. variable names have been minimised to reduce the size of this massive
|
||||
// helper. sometimes spec compliancy is annoying :(
|
||||
@@ -32,7 +32,15 @@
|
||||
}
|
||||
}
|
||||
return _arr;
|
||||
} else {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||
}
|
||||
});
|
||||
|
||||
return function (arr, i) {
|
||||
if (Array.isArray(arr)) {
|
||||
return arr;
|
||||
} else if (Symbol.iterator in Object(arr)) {
|
||||
return sliceIterator(arr, i);
|
||||
} else {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -8,5 +8,8 @@
|
||||
"utility.inlineExpressions": "minification.constantFolding",
|
||||
"utility.deadCodeElimination": "minification.deadCodeElimination",
|
||||
"utility.removeConsoleCalls": "minification.removeConsole",
|
||||
"utility.removeDebugger": "minification.removeDebugger"
|
||||
"utility.removeDebugger": "minification.removeDebugger",
|
||||
|
||||
"es6.parameters.rest": "es6.parameters",
|
||||
"es6.parameters.default": "es6.parameters"
|
||||
}
|
||||
|
||||
@@ -70,7 +70,15 @@ export var visitor = {
|
||||
let pattern = node.params[i];
|
||||
if (!t.isPattern(pattern)) continue;
|
||||
|
||||
var ref = node.params[i] = scope.generateUidIdentifier("ref");
|
||||
var ref = scope.generateUidIdentifier("ref");
|
||||
if (t.isAssignmentPattern(pattern)) {
|
||||
var _pattern = pattern;
|
||||
pattern = pattern.left;
|
||||
_pattern.left = ref;
|
||||
} else {
|
||||
node.params[i] = ref;
|
||||
}
|
||||
|
||||
t.inherits(ref, pattern);
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import callDelegate from "../../helpers/call-delegate";
|
||||
import getFunctionArity from "../../helpers/get-function-arity";
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
import callDelegate from "../../../helpers/call-delegate";
|
||||
import getFunctionArity from "../../../helpers/get-function-arity";
|
||||
import * as util from "../../../../util";
|
||||
import * as t from "../../../../types";
|
||||
|
||||
var hasDefaults = function (node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
@@ -38,7 +38,7 @@ export var visitor = {
|
||||
|
||||
//
|
||||
var argsIdentifier = t.identifier("arguments");
|
||||
argsIdentifier._shadowedFunctionLiteral = true;
|
||||
argsIdentifier._shadowedFunctionLiteral = this;
|
||||
|
||||
// push a default parameter definition
|
||||
function pushDefNode(left, right, i) {
|
||||
@@ -0,0 +1,10 @@
|
||||
import * as visitors from "../../../../traversal/visitors";
|
||||
|
||||
import * as def from "./default";
|
||||
import * as rest from "./rest";
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export var visitor = visitors.merge([rest.visitor, def.visitor]);
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
import * as util from "../../../../util";
|
||||
import * as t from "../../../../types";
|
||||
|
||||
var memberExpressionOptimisationVisitor = {
|
||||
Scope(node, parent, scope, state) {
|
||||
@@ -84,7 +84,7 @@ export var visitor = {
|
||||
var argsId = t.identifier("arguments");
|
||||
|
||||
// otherwise `arguments` will be remapped in arrow functions
|
||||
argsId._shadowedFunctionLiteral = true;
|
||||
argsId._shadowedFunctionLiteral = this;
|
||||
|
||||
// support patterns
|
||||
if (t.isPattern(rest)) {
|
||||
@@ -2,8 +2,6 @@ import * as t from "../../../types";
|
||||
|
||||
function loose(node, body, objId) {
|
||||
for (var prop of (node.properties: Array)) {
|
||||
if (!prop) continue;
|
||||
|
||||
body.push(t.expressionStatement(
|
||||
t.assignmentExpression(
|
||||
"=",
|
||||
@@ -19,8 +17,6 @@ function spec(node, body, objId, initProps, file) {
|
||||
// otherwise use Object.defineProperty
|
||||
|
||||
for (let prop of (node.properties: Array)) {
|
||||
if (!prop) continue;
|
||||
|
||||
// this wont work with Object.defineProperty
|
||||
if (t.isLiteral(t.toComputedKey(prop), { value: "__proto__" })) {
|
||||
initProps.push(prop);
|
||||
@@ -67,17 +63,18 @@ export var visitor = {
|
||||
var initProps = [];
|
||||
var stopInits = false;
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
let prop = node.properties[i];
|
||||
node.properties = node.properties.filter(function (prop) {
|
||||
if (prop.computed) {
|
||||
stopInits = true;
|
||||
}
|
||||
|
||||
if (prop.kind !== "init" || !stopInits) {
|
||||
initProps.push(prop);
|
||||
node.properties[i] = null;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ function build(props, scope) {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
export var metadata = {
|
||||
group: "builtin-advanced"
|
||||
};
|
||||
|
||||
export var visitor = {
|
||||
ArrayExpression(node, parent, scope) {
|
||||
var elements = node.elements;
|
||||
|
||||
@@ -211,7 +211,7 @@ class TailCallTransformer {
|
||||
var decl = t.variableDeclarator(this.argumentsId);
|
||||
if (this.argumentsId) {
|
||||
decl.init = t.identifier("arguments");
|
||||
decl.init._shadowedFunctionLiteral = true;
|
||||
decl.init._shadowedFunctionLiteral = this.path;
|
||||
}
|
||||
topVars.push(decl);
|
||||
}
|
||||
|
||||
@@ -46,9 +46,6 @@ export default {
|
||||
"es6.regex.sticky": require("./es6/regex.sticky"),
|
||||
"es6.regex.unicode": require("./es6/regex.unicode"),
|
||||
"es6.constants": require("./es6/constants"),
|
||||
"es6.parameters.rest": require("./es6/parameters.rest"),
|
||||
"es6.spread": require("./es6/spread"),
|
||||
"es6.parameters.default": require("./es6/parameters.default"),
|
||||
"es7.exportExtensions": require("./es7/export-extensions"),
|
||||
"spec.protoToAssign": require("babel-plugin-proto-to-assign"),
|
||||
"es7.doExpressions": require("./es7/do-expressions"),
|
||||
@@ -57,6 +54,8 @@ export default {
|
||||
"spec.undefinedToVoid": require("babel-plugin-undefined-to-void"),
|
||||
|
||||
//- builtin-advanced
|
||||
"es6.spread": require("./es6/spread"),
|
||||
"es6.parameters": require("./es6/parameters"),
|
||||
"es6.destructuring": require("./es6/destructuring"),
|
||||
"es6.blockScoping": require("./es6/block-scoping"),
|
||||
"es6.spec.blockScoping": require("./es6/spec.block-scoping"),
|
||||
|
||||
@@ -8,7 +8,30 @@ function remap(path, key, create) {
|
||||
// ensure that we're shadowed
|
||||
if (!path.inShadow()) return;
|
||||
|
||||
var fnPath = path.findParent((path) => !path.is("shadow") && (path.isFunction() || path.isProgram()));
|
||||
var shadowFunction = path.node._shadowedFunctionLiteral;
|
||||
var currentFunction;
|
||||
|
||||
var fnPath = path.findParent(function (path) {
|
||||
if (path.isProgram() || path.isFunction()) {
|
||||
// catch current function in case this is the shadowed one and we can ignore it
|
||||
currentFunction = currentFunction || path;
|
||||
}
|
||||
|
||||
if (path.isProgram()) {
|
||||
return true;
|
||||
} else if (path.isFunction()) {
|
||||
if (shadowFunction) {
|
||||
return path === shadowFunction || path.node === shadowFunction.node;
|
||||
} else {
|
||||
return !path.is("shadow");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// no point in realiasing if we're in this function
|
||||
if (fnPath === currentFunction) return;
|
||||
|
||||
var cached = fnPath.getData(key);
|
||||
if (cached) return cached;
|
||||
@@ -28,7 +51,7 @@ export var visitor = {
|
||||
},
|
||||
|
||||
ReferencedIdentifier(node) {
|
||||
if (node.name === "arguments" && !node._shadowedFunctionLiteral) {
|
||||
if (node.name === "arguments") {
|
||||
return remap(this, "arguments", () => t.identifier("arguments"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type NodePath from "./index";
|
||||
import * as inferers from "./inferers";
|
||||
import * as t from "../../../types";
|
||||
|
||||
@@ -76,6 +77,8 @@ function _isBaseType(baseName: string, type?, soft?): boolean {
|
||||
return t.isAnyTypeAnnotation(type);
|
||||
} else if (baseName === "mixed") {
|
||||
return t.isMixedTypeAnnotation(type);
|
||||
} else if (baseName === "void") {
|
||||
return t.isVoidTypeAnnotation(type);
|
||||
} else {
|
||||
if (soft) {
|
||||
return false;
|
||||
@@ -105,6 +108,19 @@ export function couldBeBaseType(name: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
export function baseTypeStrictlyMatches(right: NodePath) {
|
||||
var left = this.getTypeAnnotation();
|
||||
right = right.getTypeAnnotation();
|
||||
|
||||
if (!t.isAnyTypeAnnotation() && t.isFlowBaseAnnotation(left)) {
|
||||
return right.type === left.type;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
@@ -122,7 +122,7 @@ export default class PathHoister {
|
||||
if (parent.isJSXElement() && this.path.container === parent.node.children) {
|
||||
// turning the `span` in `<div><span /></div>` to an expression so we need to wrap it with
|
||||
// an expression container
|
||||
uid = t.jSXExpressionContainer(uid);
|
||||
uid = t.JSXExpressionContainer(uid);
|
||||
}
|
||||
|
||||
this.path.replaceWith(uid);
|
||||
|
||||
@@ -126,6 +126,8 @@ export function merge(visitors) {
|
||||
var rootVisitor = {};
|
||||
|
||||
for (var visitor of (visitors: Array)) {
|
||||
explode(visitor);
|
||||
|
||||
for (var type in visitor) {
|
||||
var nodeVisitor = rootVisitor[type] = rootVisitor[type] || {};
|
||||
mergePair(nodeVisitor, visitor[type]);
|
||||
|
||||
@@ -112,5 +112,9 @@ export function createTypeAnnotationBasedOnTypeof(type) {
|
||||
return t.genericTypeAnnotation(t.identifier("Function"));
|
||||
} else if (type === "object") {
|
||||
return t.genericTypeAnnotation(t.identifier("Object"));
|
||||
} else if (type === "symbol") {
|
||||
return t.genericTypeAnnotation(t.identifier("Symbol"));
|
||||
} else {
|
||||
throw new Error("Invalid typeof value");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ each(t.VISITOR_KEYS, function (keys, type) {
|
||||
});
|
||||
|
||||
each(t.BUILDER_KEYS, function (keys, type) {
|
||||
t[type[0].toLowerCase() + type.slice(1)] = function () {
|
||||
var builder = function () {
|
||||
var node = {};
|
||||
node.start = null;
|
||||
node.type = type;
|
||||
@@ -123,6 +123,9 @@ each(t.BUILDER_KEYS, function (keys, type) {
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
t[type] = builder;
|
||||
t[type[0].toLowerCase() + type.slice(1)] = builder;
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
@@ -18,6 +18,7 @@ import has from "lodash/object/has";
|
||||
import fs from "fs";
|
||||
import * as t from "./types";
|
||||
import slash from "slash";
|
||||
import pathExists from "path-exists";
|
||||
|
||||
export { inherits, inspect } from "util";
|
||||
|
||||
@@ -182,7 +183,7 @@ function loadTemplates() {
|
||||
var templates = {};
|
||||
|
||||
var templatesLoc = path.join(__dirname, "transformation/templates");
|
||||
if (!fs.existsSync(templatesLoc)) {
|
||||
if (!pathExists.sync(templatesLoc)) {
|
||||
throw new ReferenceError(messages.get("missingTemplatesDirectory"));
|
||||
}
|
||||
|
||||
|
||||
@@ -3374,6 +3374,49 @@ test("class Foo { bar(a,) { } }", {
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
test("(x, y, ) => 1;", {
|
||||
start: 0,
|
||||
body: [{
|
||||
start: 0,
|
||||
expression: {
|
||||
start: 0,
|
||||
id: null,
|
||||
generator: false,
|
||||
expression: true,
|
||||
params: [
|
||||
{
|
||||
start: 1,
|
||||
name: "x",
|
||||
type: "Identifier",
|
||||
end: 2
|
||||
},
|
||||
{
|
||||
start: 4,
|
||||
name: "y",
|
||||
type: "Identifier",
|
||||
end: 5
|
||||
}
|
||||
],
|
||||
body: {
|
||||
start: 12,
|
||||
value: 1,
|
||||
raw: "1",
|
||||
type: "Literal",
|
||||
end: 13
|
||||
},
|
||||
type: "ArrowFunctionExpression",
|
||||
end: 13
|
||||
},
|
||||
type: "ExpressionStatement",
|
||||
end: 14
|
||||
}],
|
||||
type: "Program",
|
||||
end: 14
|
||||
}, {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
testFail("log(,);", "Unexpected token (1:4)", {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
@@ -3383,3 +3426,8 @@ testFail("function log(,) { }", "Unexpected token (1:13)", {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
testFail("('foo',)", "Unexpected token (1:7)", {
|
||||
ecmaVersion: 7,
|
||||
features: { "es7.trailingFunctionCommas": true }
|
||||
});
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
var esvalid = require("esvalid");
|
||||
var util = require("../../lib/babel/util");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var pathExists = require("path-exists");
|
||||
var esvalid = require("esvalid");
|
||||
var util = require("../../lib/babel/util");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
var humanize = function (val, noext) {
|
||||
if (noext) val = path.basename(val, path.extname(val));
|
||||
@@ -10,7 +11,7 @@ var humanize = function (val, noext) {
|
||||
};
|
||||
|
||||
var readFile = exports.readFile = function (filename) {
|
||||
if (fs.existsSync(filename)) {
|
||||
if (pathExists.sync(filename)) {
|
||||
var file = fs.readFileSync(filename, "utf8").trim();
|
||||
file = file.replace(/\r\n/g, "\n");
|
||||
return file;
|
||||
@@ -31,7 +32,7 @@ exports.esvalid = function (ast, code, loc) {
|
||||
};
|
||||
|
||||
exports.assertVendor = function (name) {
|
||||
if (!fs.existsSync(__dirname + "/../../vendor/" + name)) {
|
||||
if (!pathExists.sync(__dirname + "/../../vendor/" + name)) {
|
||||
console.error("No vendor/" + name + " - run `make bootstrap`");
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -130,13 +131,13 @@ exports.get = function (entryName, entryLoc) {
|
||||
suite.tests.push(test);
|
||||
|
||||
var sourceMappingsLoc = taskDir + "/source-mappings.json";
|
||||
if (fs.existsSync(sourceMappingsLoc)) {
|
||||
if (pathExists.sync(sourceMappingsLoc)) {
|
||||
test.options.sourceMap = true;
|
||||
test.sourceMappings = require(sourceMappingsLoc);
|
||||
}
|
||||
|
||||
var sourceMap = taskDir + "/source-map.json";
|
||||
if (fs.existsSync(sourceMap)) {
|
||||
if (pathExists.sync(sourceMap)) {
|
||||
test.options.sourceMap = true;
|
||||
test.sourceMap = require(sourceMap);
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ suite("api", function () {
|
||||
|
||||
function getModuleNameTest(moduleFormat, expected) {
|
||||
var result = transform("foo('bar');", {
|
||||
filename: "foo/bar/index",
|
||||
filename: "/foo/bar/index",
|
||||
modules: moduleFormat,
|
||||
moduleIds: true,
|
||||
getModuleId: function (name) {
|
||||
@@ -232,7 +232,7 @@ suite("api", function () {
|
||||
|
||||
test("amd", function () {
|
||||
var expected = [
|
||||
"define('foo/bar', ['exports'], function (exports) {",
|
||||
"define('/foo/bar', ['exports'], function (exports) {",
|
||||
" 'use strict';",
|
||||
"",
|
||||
" foo('bar');",
|
||||
@@ -246,7 +246,7 @@ suite("api", function () {
|
||||
var expected = [
|
||||
"(function (global, factory) {",
|
||||
" if (typeof define === 'function' && define.amd) {",
|
||||
" define('foo/bar', ['exports'], factory);",
|
||||
" define('/foo/bar', ['exports'], factory);",
|
||||
" } else if (typeof exports !== 'undefined') {",
|
||||
" factory(exports);",
|
||||
" } else {",
|
||||
@@ -268,7 +268,7 @@ suite("api", function () {
|
||||
|
||||
test("system", function () {
|
||||
var expected = [
|
||||
"System.register('foo/bar', [], function (_export) {",
|
||||
"System.register('/foo/bar', [], function (_export) {",
|
||||
" 'use strict';",
|
||||
"",
|
||||
" return {",
|
||||
|
||||
@@ -9,6 +9,7 @@ var child = require("child_process");
|
||||
var path = require("path");
|
||||
var chai = require("chai");
|
||||
var fs = require("fs");
|
||||
var pathExists = require("path-exists");
|
||||
var _ = require("lodash");
|
||||
|
||||
var fixtureLoc = __dirname + "/fixtures/bin";
|
||||
@@ -16,7 +17,7 @@ var tmpLoc = __dirname + "/tmp";
|
||||
|
||||
var readDir = function (loc) {
|
||||
var files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
if (pathExists.sync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
var contents = helper.readFile(loc + "/" + filename);
|
||||
files[filename] = contents;
|
||||
@@ -112,7 +113,7 @@ var buildTest = function (binName, testName, opts) {
|
||||
|
||||
var clear = function () {
|
||||
process.chdir(__dirname);
|
||||
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
|
||||
if (pathExists.sync(tmpLoc)) rimraf.sync(tmpLoc);
|
||||
fs.mkdirSync(tmpLoc);
|
||||
process.chdir(tmpLoc);
|
||||
};
|
||||
@@ -132,11 +133,11 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
};
|
||||
|
||||
var optionsLoc = testLoc + "/options.json"
|
||||
if (fs.existsSync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
if (pathExists.sync(optionsLoc)) _.merge(opts, require(optionsLoc));
|
||||
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
var loc = testLoc + "/" + key + ".txt";
|
||||
if (fs.existsSync(loc)) {
|
||||
if (pathExists.sync(loc)) {
|
||||
opts[key] = helper.readFile(loc);
|
||||
} else {
|
||||
opts[key] = opts[key] || "";
|
||||
|
||||
31
test/core/fixtures/generation/types/Decorator/actual.js
Normal file
31
test/core/fixtures/generation/types/Decorator/actual.js
Normal file
@@ -0,0 +1,31 @@
|
||||
var obj = {
|
||||
@foo
|
||||
@bar
|
||||
foo: "bar",
|
||||
|
||||
@foo
|
||||
@bar
|
||||
foo() {},
|
||||
|
||||
@foo
|
||||
get foo() {},
|
||||
|
||||
@bar
|
||||
set bar(foo) {}
|
||||
};
|
||||
|
||||
class Foo {
|
||||
@foo
|
||||
@bar
|
||||
foo() {}
|
||||
|
||||
@foo
|
||||
@bar
|
||||
foo() {}
|
||||
|
||||
@foo
|
||||
get foo() {}
|
||||
|
||||
@bar
|
||||
set bar(foo) {}
|
||||
}
|
||||
31
test/core/fixtures/generation/types/Decorator/expected.js
Normal file
31
test/core/fixtures/generation/types/Decorator/expected.js
Normal file
@@ -0,0 +1,31 @@
|
||||
var obj = {
|
||||
@foo
|
||||
@bar
|
||||
foo: "bar",
|
||||
|
||||
@foo
|
||||
@bar
|
||||
foo() {},
|
||||
|
||||
@foo
|
||||
get foo() {},
|
||||
|
||||
@bar
|
||||
set bar(foo) {}
|
||||
};
|
||||
|
||||
class Foo {
|
||||
@foo
|
||||
@bar
|
||||
foo() {}
|
||||
|
||||
@foo
|
||||
@bar
|
||||
foo() {}
|
||||
|
||||
@foo
|
||||
get foo() {}
|
||||
|
||||
@bar
|
||||
set bar(foo) {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
function broken(x, ...foo) {
|
||||
if (true) {
|
||||
class Foo extends Bar { }
|
||||
return hello(...foo)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
|
||||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
|
||||
|
||||
function broken(x) {
|
||||
for (var _len = arguments.length, foo = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
foo[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
if (true) {
|
||||
var _ret = (function () {
|
||||
var Foo = (function (_Bar) {
|
||||
function Foo() {
|
||||
_classCallCheck(this, Foo);
|
||||
|
||||
_get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments);
|
||||
}
|
||||
|
||||
_inherits(Foo, _Bar);
|
||||
|
||||
return Foo;
|
||||
})(Bar);
|
||||
|
||||
return {
|
||||
v: hello.apply(undefined, foo)
|
||||
};
|
||||
})();
|
||||
|
||||
if (typeof _ret === "object") return _ret.v;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
(x, y, ) => {};
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
(function (x, y) {});
|
||||
@@ -32,6 +32,7 @@ _.each(helper.get("generation"), function (testSuite) {
|
||||
strictMode: false,
|
||||
sourceType: "module",
|
||||
features: {
|
||||
"es7.decorators": true,
|
||||
"es7.comprehensions": true,
|
||||
"es7.asyncFunctions": true,
|
||||
"es7.exportExtensions": true,
|
||||
|
||||
@@ -101,6 +101,11 @@ suite("util", function () {
|
||||
assert.strictEqual(util.booleanify("inline"), "inline");
|
||||
});
|
||||
|
||||
test("resolve", function () {
|
||||
assert.notEqual(util.resolve("is-integer").indexOf("node_modules/is-integer"), -1);
|
||||
assert.equal(util.resolve("foo-bar-module"), null);
|
||||
});
|
||||
|
||||
test("toIdentifier", function () {
|
||||
assert.equal(t.toIdentifier(t.identifier("swag")), "swag");
|
||||
assert.equal(t.toIdentifier("swag-lord"), "swagLord");
|
||||
|
||||
23
tools/build-plugins/protect.js
Normal file
23
tools/build-plugins/protect.js
Normal file
@@ -0,0 +1,23 @@
|
||||
var path = require("path");
|
||||
|
||||
module.exports = function (babel) {
|
||||
var t = babel.types;
|
||||
|
||||
return new babel.Plugin("protect-internal-apis", {
|
||||
visitor: {
|
||||
Program: function (node, parent, scope, file) {
|
||||
if (file.opts.filename.indexOf("tools/protect") >= 0) return;
|
||||
if (file.opts.filename.indexOf("templates") >= 0) return;
|
||||
|
||||
var from = "/" + path.dirname(file.opts.filename.replace(/^src/, "lib"));
|
||||
var to = "/lib/babel/tools";
|
||||
|
||||
var protectLoc = "./" + path.relative(from, to) + "/protect.js";
|
||||
|
||||
this.unshiftContainer("body", [
|
||||
t.expressionStatement(t.callExpression(file.addImport(protectLoc), [t.identifier("module")]))
|
||||
]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user