Compare commits

...

101 Commits

Author SHA1 Message Date
Sebastian McKenzie
aefd69d31e v5.6.12 2015-06-26 11:40:40 +01:00
Sebastian McKenzie
e328031b19 add 5.6.12 changelog 2015-06-26 11:39:47 +01:00
Sebastian McKenzie
571b6a4cd7 check parent node alongside path in shadow functions 2015-06-26 11:39:10 +01:00
Sebastian McKenzie
41cf942391 clean up shadow functions findParent logic - fixes #1846 2015-06-26 11:34:13 +01:00
Sebastian McKenzie
98f28b8e89 5.6.11 2015-06-26 02:40:00 +01:00
Sebastian McKenzie
8f88afc037 v5.6.11 2015-06-26 02:39:04 +01:00
Sebastian McKenzie
6359675a4f make shadowed function findParent target finder more reliable 2015-06-26 02:38:14 +01:00
Sebastian McKenzie
a265c3f25c add missing semi 2015-06-26 02:25:46 +01:00
Sebastian McKenzie
29eb99ee93 rejigger shadowd function findParent logic 2015-06-26 02:24:42 +01:00
Sebastian McKenzie
0c5c1ff989 remove unused variable 2015-06-26 02:22:10 +01:00
Sebastian McKenzie
499951123a add 5.6.11 changelog 2015-06-26 02:21:34 +01:00
Sebastian McKenzie
c0fd4c1f9e merge es6.parameters.rest and es6.parameters.default transformers
This is necessary in order to retain correct function arity and to have
completely correct semantics. Sometimes features are tied together so much
that they would require so much desugaring to retain the correct semantics
that they'd be equivalent to... the normal transpiled output.
2015-06-26 02:20:16 +01:00
Sebastian McKenzie
579e6fecee upgrade internal dev babel dependency to 5.6.10 2015-06-26 02:05:43 +01:00
Sebastian McKenzie
bb3665a3b6 5.6.10 2015-06-26 01:12:50 +01:00
Sebastian McKenzie
e6de688234 v5.6.10 2015-06-26 01:11:32 +01:00
Sebastian McKenzie
4c233e88ff add use strict 2015-06-26 01:09:47 +01:00
Sebastian McKenzie
ae2ba0b5a3 add 5.6.10 changelog 2015-06-26 01:08:36 +01:00
Sebastian McKenzie
e34d950793 require babel-core at the top of the file 2015-06-26 01:07:54 +01:00
Sebastian McKenzie
e4083fbbd7 add support for trailing commas in arrow function parameter lists - fixes #1841 2015-06-26 00:37:33 +01:00
Sebastian McKenzie
59ed7977ef 5.6.9 2015-06-25 23:59:12 +01:00
Sebastian McKenzie
dc441e9a8f v5.6.9 2015-06-25 23:58:07 +01:00
Sebastian McKenzie
2e21795f57 add index.js to fix internal api error 2015-06-25 23:57:16 +01:00
Sebastian McKenzie
5c988f7fc8 5.6.8 2015-06-25 23:35:34 +01:00
Sebastian McKenzie
493826973e v5.6.8 2015-06-25 23:34:30 +01:00
Sebastian McKenzie
1acc71aa4e fix api module id relative tests 2015-06-25 23:32:43 +01:00
Sebastian McKenzie
bbab5f72ec add 5.6.8 changelog 2015-06-25 23:31:07 +01:00
Sebastian McKenzie
58ff9e387a remove root internals protect 2015-06-25 23:30:43 +01:00
Sebastian McKenzie
5a0d099984 don't add protect to register either 2015-06-25 23:28:27 +01:00
Sebastian McKenzie
05c95e04f7 don't add protect to polyfill 2015-06-25 23:26:24 +01:00
Sebastian McKenzie
88430b4be2 forgive hotlinking to polyfill 2015-06-25 23:24:45 +01:00
Sebastian McKenzie
19adcfae4d add type import 2015-06-25 23:22:42 +01:00
Sebastian McKenzie
7c4fe984ce start linting babel-cli/bin - fixes #1836 2015-06-25 23:22:38 +01:00
Sebastian McKenzie
4476e8311c use relative tools/protect.js filenames 2015-06-25 23:20:18 +01:00
Sebastian McKenzie
2a3142273d add path-exists dependency to babel-cli 2015-06-25 23:20:08 +01:00
Sebastian McKenzie
bbcb889a49 Merge branch 'master' of github.com:babel/babel 2015-06-25 23:04:24 +01:00
Sebastian McKenzie
c87f85815b used filter rather than setting init properties to null in properties.computed transformer - fixes #1831 2015-06-25 23:04:17 +01:00
Sebastian McKenzie
48d0df17d0 Merge pull request #1832 from Mark-Simulacrum/path-exists
Use path-exists module instead of fs.exists.
2015-06-25 22:57:27 +01:00
Sebastian McKenzie
01b243347f add NodePath#baseTypeStrictlyMatches method 2015-06-25 22:55:46 +01:00
Sebastian McKenzie
45a5cbf72f use capitalised builder method 2015-06-25 22:55:35 +01:00
Sebastian McKenzie
05efae1c58 complete t.createTypeAnnotationBasedOnTypeof 2015-06-25 22:55:25 +01:00
Sebastian McKenzie
c08fff4b44 add node builder for normal AST node type 2015-06-25 22:55:12 +01:00
Sebastian McKenzie
13e910ea83 force spaces for binary expressions - fixes #1835 2015-06-25 22:55:00 +01:00
Mark-Simulacrum
b308602098 Use path-exists instead of fs.exists.
fs.exists is being deprecated, see: https://github.com/nodejs/io.js/issues/103.
2015-06-25 12:39:39 -06:00
Sebastian McKenzie
560a044d8f Merge pull request #1821 from kpdecker/destructure-performance
Avoid deopt in iterable destructure template
2015-06-25 15:23:53 +01:00
Sebastian McKenzie
619fbe4c3b Merge pull request #1830 from kpdecker/avoid-define-property
Avoid defineProperty when not needed
2015-06-25 15:23:39 +01:00
kpdecker
1d83ad6cce Avoid defineProperty when not needed
This lets us use the fast path for most object literal assignments and then utilizes the defineProperty path when there is a chance that we could hit the setter issue described in #357.

10x performance boosts seen for the six-speed test case, going from 200k operations/sec to 2M ops/sec.
2015-06-25 09:22:03 -05:00
kpdecker
5353ccd773 Move slice iterator helper out of primary call
Avoids overhead of instantiating the helper on each call to the slice to array helper.
2015-06-25 09:18:12 -05:00
Sebastian McKenzie
a8e23d2eb9 ignore templates folder in protect plugin 2015-06-25 14:33:38 +01:00
Sebastian McKenzie
95d830fde0 don't output comma separator for decorator list and output Property decorators - fixes #1811 2015-06-25 12:23:45 +01:00
Sebastian McKenzie
c8a5d7d970 Merge branch 'arthurvr-dep' 2015-06-25 12:12:21 +01:00
Sebastian McKenzie
43481eb2cc Merge branch 'dep' of https://github.com/arthurvr/babel into arthurvr-dep 2015-06-25 12:12:19 +01:00
Sebastian McKenzie
b8bb665691 Merge branch 'arthurvr-tests' 2015-06-25 12:12:05 +01:00
Sebastian McKenzie
e6846b2730 Merge branch 'tests' of https://github.com/arthurvr/babel into arthurvr-tests 2015-06-25 12:12:05 +01:00
Sebastian McKenzie
31c1286a3c protect internal files from hotlinking 2015-06-25 12:10:22 +01:00
Arthur Verschaeve
489f9e92b5 Add tests for util.resolve 2015-06-25 10:10:56 +02:00
Arthur Verschaeve
073809efac Remove leven dependency 2015-06-25 09:37:27 +02:00
Brian Donovan
c9b8e2f3ce Merge pull request #1822 from azu/patch-1
Add missing asterisk in CHANGELOG
2015-06-24 21:23:51 -07:00
azu
c6cb871355 Add missing asterisk in CHANGELOG 2015-06-25 13:17:23 +09:00
kpdecker
1b0e5b3ed1 Avoid deopt in iterable destructure template
The try/catch was forcing deoptimization under most engines. This roughly doubles throughput under V8 and 7x increases were seen under Firefox.

Performance numbers based on https://github.com/kpdecker/six-speed/tree/master/tests/destructuring
2015-06-24 22:42:13 -05:00
Sebastian McKenzie
0f70c76312 5.6.7 2015-06-25 04:18:49 +01:00
Sebastian McKenzie
e8c672bf4f v5.6.7 2015-06-25 04:17:52 +01:00
Sebastian McKenzie
7083ac61ff remove test.js 2015-06-25 04:16:06 +01:00
Sebastian McKenzie
d256809120 Merge branch 'master' of github.com:babel/babel
# Conflicts:
#	src/babel/traversal/path/replacement.js
2015-06-25 04:12:13 +01:00
Sebastian McKenzie
26a19f82d2 add 5.6.7 changelog 2015-06-25 04:11:40 +01:00
Sebastian McKenzie
128d3b5c91 add missing computed loose test - ref #1820 2015-06-25 04:11:32 +01:00
Sebastian McKenzie
c1a080d0ca supress duplicate deprecation messages 2015-06-25 04:11:13 +01:00
Sebastian McKenzie
0b1ce6c9a4 always coerce leading computed property initialisers into the init object - fixes #1820 2015-06-25 04:10:56 +01:00
Sebastian McKenzie
a6f04055c0 fix block scoping transformer 2015-06-25 04:10:32 +01:00
Sebastian McKenzie
c3219e8b88 deprecate returning source strings from visitor methods 2015-06-25 03:51:25 +01:00
Sebastian McKenzie
a35c863341 deprecate returning source strings from visitor methods 2015-06-25 03:50:10 +01:00
Sebastian McKenzie
6f862a4c45 actually push for left declaration to the returned block scoping body - fixes #1819 2015-06-25 03:48:29 +01:00
Sebastian McKenzie
cf38210fd2 5.6.6 2015-06-24 23:28:44 +01:00
Sebastian McKenzie
5c9d564339 v5.6.6 2015-06-24 23:27:44 +01:00
Sebastian McKenzie
031a61515b add labels, and inX properties to lookahead getState 2015-06-24 23:26:59 +01:00
Sebastian McKenzie
d3884fd53b add inType assignment in flow parse declare method 2015-06-24 23:26:48 +01:00
Sebastian McKenzie
c6eef3080e add 5.6.6 changelog 2015-06-24 23:26:35 +01:00
Sebastian McKenzie
25be0a974d fixing linting errors 2015-06-24 23:20:03 +01:00
Sebastian McKenzie
7ccd135e83 fix isKeyword flow overload 2015-06-24 23:18:21 +01:00
Sebastian McKenzie
4fc1bbeb60 acorn resync 2015-06-24 23:15:27 +01:00
Sebastian McKenzie
32a4d7172b optimise generator for compact mode 2015-06-24 23:15:22 +01:00
Sebastian McKenzie
aa25903c05 parse void as an identifier when inside a type annotation to avoid setting void keyword token - cc @DmitrySoshnikov 2015-06-24 23:15:00 +01:00
Sebastian McKenzie
23ec1a455e upgrade babel-plugin-dead-code-elimination 2015-06-24 23:14:08 +01:00
Sebastian McKenzie
e6ac2d049b add 5.6.5 changelog 2015-06-24 13:50:53 +01:00
Sebastian McKenzie
084ae31816 5.6.5 2015-06-24 13:48:43 +01:00
Sebastian McKenzie
8e530afd78 v5.6.5 2015-06-24 13:47:54 +01:00
Sebastian McKenzie
6c66a82b37 Merge branch 'master' of github.com:babel/babel 2015-06-24 13:46:05 +01:00
Sebastian McKenzie
737abca3a9 use this.space() instead of manually pushing 2015-06-24 13:45:56 +01:00
Sebastian McKenzie
9db43ca7a9 clean up t.isReferenced 2015-06-24 13:45:48 +01:00
Sebastian McKenzie
25b0683316 add Path#couldBeBaseType 2015-06-24 13:45:32 +01:00
Sebastian McKenzie
a096f6b1c5 fix noOptimise state being incorrect when recursing into multiple nested functions - fixes #1815 2015-06-24 13:45:14 +01:00
Sebastian McKenzie
e41ab2ab0c Merge pull request #1807 from benjamn/patch-1
Update Regenerator dependency to 0.8.31.
2015-06-23 17:07:25 +01:00
Ben Newman
6a6764fa7b Update Regenerator dependency to 0.8.31.
Fixes #1805.
2015-06-23 12:06:48 -04:00
Sebastian McKenzie
a2358d6863 5.6.4 2015-06-22 20:39:14 +01:00
Sebastian McKenzie
612ef79d35 v5.6.4 2015-06-22 20:38:12 +01:00
Sebastian McKenzie
2dfa6ddf36 add 5.6.4 changelog 2015-06-22 20:37:00 +01:00
Sebastian McKenzie
2910d4f82c fix Program can only be replaced with another Program error 2015-06-22 20:36:34 +01:00
Sebastian McKenzie
4b6c954f5e add ParenthesizedExpression node type for plugins to generate 2015-06-22 20:36:12 +01:00
Sebastian McKenzie
b7e23e3410 5.6.3 2015-06-22 11:57:53 +01:00
Sebastian McKenzie
a19f10e124 v5.6.3 2015-06-22 11:56:46 +01:00
Sebastian McKenzie
8e1f134635 fix rest parameter array allocation loop being incorrectly aliased - fixes #1800 2015-06-22 11:54:57 +01:00
Sebastian McKenzie
aa151016f5 5.6.2 2015-06-22 00:10:56 +01:00
103 changed files with 751 additions and 193 deletions

View File

@@ -2,5 +2,6 @@
"stage": 0,
"loose": ["all"],
"blacklist": ["es6.tailCall"],
"optional": ["optimisation.flow.forOf"]
"optional": ["optimisation.flow.forOf"],
"plugins": ["./tools/build-plugins/protect"]
}

View File

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

View File

@@ -13,6 +13,66 @@ _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**
* Fix hoisting of `ForXStatement` `left` `var`s when inserting a block scoping IIFE.
* **Polish**
* Combine all leading computed property initialisers into the root object in loose mode.
* **Internal**
* Deprecate returning of replacement strings from visitor methods.
## 5.6.6
* **Bug Fix**
* Fix weird parser bug where `void` type annotations were being parsed as keywords causing the tokeniser to lose track of context.
## 5.6.5
* **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`.
## 5.6.4
* **Internal**
* Add `ParenthesizedExpression` node type.
## 5.6.3
* **Bug Fix**
* Fix rest parameter array allocation loop being incorrectly aliased.
## 5.6.2
* **Bug Fix**
* Fix method key literals not turning into computed member expression in loose mode.
* Elect rest parameters in spread element position as candidates instead of replacing them in place.
## 5.6.0
* **Bug Fix**

View File

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

View File

@@ -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
index.js Normal file
View File

@@ -0,0 +1 @@
module.exports = require("./lib/babel/api/node.js");

View File

@@ -1,12 +1,11 @@
{
"name": "babel-core",
"description": "A compiler for writing next generation JavaScript",
"version": "5.6.2",
"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"
},
@@ -31,7 +30,7 @@
"acorn-jsx": "^1.0.0",
"ast-types": "~0.7.0",
"babel-plugin-constant-folding": "^1.0.1",
"babel-plugin-dead-code-elimination": "^1.0.1",
"babel-plugin-dead-code-elimination": "^1.0.2",
"babel-plugin-eval": "^1.0.1",
"babel-plugin-inline-environment-variables": "^1.0.1",
"babel-plugin-jscript": "^1.0.1",
@@ -57,14 +56,14 @@
"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.30",
"regenerator": "0.8.31",
"regexpu": "^1.1.2",
"repeating": "^1.1.2",
"resolve": "^1.1.6",
@@ -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",

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,14 +1,14 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.6.1",
"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.1",
"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"

View File

@@ -1,7 +1,7 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "5.6.1",
"version": "5.6.11",
"license": "MIT",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>",

View File

@@ -1,3 +1,4 @@
Error.stackTraceLimit = Infinity;
var acorn = require("../src/index")
var pp = acorn.Parser.prototype
@@ -41,8 +42,11 @@ pp.flow_parseDeclareFunction = function (node) {
typeNode.rest = tmp.rest
this.expect(tt.parenR)
var oldInType = this.inType
this.inType = true
this.expect(tt.colon)
typeNode.returnType = this.flow_parseType()
this.inType = oldInType
typeContainer.typeAnnotation = this.finishNode(typeNode, "FunctionTypeAnnotation")
id.typeAnnotation = this.finishNode(typeContainer, "TypeAnnotation")
@@ -352,12 +356,6 @@ pp.flow_parseGenericType = function (start, id) {
return this.finishNode(node, "GenericTypeAnnotation")
}
pp.flow_parseVoidType = function () {
var node = this.startNode()
this.expect(tt._void)
return this.finishNode(node, "VoidTypeAnnotation")
}
pp.flow_parseTypeofType = function () {
var node = this.startNode()
this.expect(tt._typeof)
@@ -411,6 +409,9 @@ pp.flow_identToTypeAnnotation = function (start, node, id) {
case "any":
return this.finishNode(node, "AnyTypeAnnotation")
case "void":
return this.finishNode(node, "VoidTypeAnnotation")
case "bool":
case "boolean":
return this.finishNode(node, "BooleanTypeAnnotation")
@@ -524,14 +525,8 @@ pp.flow_parsePrimaryType = function () {
return this.finishNode(node, "StringLiteralTypeAnnotation")
default:
if (this.type.keyword) {
switch (this.type.keyword) {
case "void":
return this.flow_parseVoidType()
case "typeof":
return this.flow_parseTypeofType()
}
if (this.type.keyword === "typeof") {
return this.flow_parseTypeofType()
}
}
@@ -694,6 +689,18 @@ acorn.plugins.flow = function (instance) {
}
})
// don't consider `void` to be a keyword as then it'll use the void token type
// and set startExpr
instance.extend("isKeyword", function (inner) {
return function(name) {
if (this.inType && name === "void") {
return false
} else {
return inner.call(this, name)
}
}
})
instance.extend("readToken", function (inner) {
return function(code) {
if (this.inType && (code === 62 || code === 60)) {

View File

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

View File

@@ -19,7 +19,11 @@ var STATE_KEYS = [
"exprAllowed",
"potentialArrowAt",
"currLine",
"input"
"input",
"inType",
"inFunction",
"inGenerator",
"labels"
];
pp.getState = function () {
@@ -29,6 +33,7 @@ pp.getState = function () {
state[key] = this[key]
}
state.context = this.context.slice()
state.labels = this.labels.slice()
return state
};

View File

@@ -4,11 +4,11 @@ import {lineBreak} from "./whitespace"
export function Parser(options, input, startPos) {
this.options = options
this.loadPlugins(this.options.plugins)
this.sourceFile = this.options.sourceFile || null
this.isKeyword = keywords[this.options.ecmaVersion >= 6 ? 6 : 5]
this.isReservedWord = reservedWords[this.options.ecmaVersion]
this.input = input
this.loadPlugins(this.options.plugins)
// Set up token state

View File

@@ -112,7 +112,7 @@ kw("case", beforeExpr)
kw("catch")
kw("continue")
kw("debugger")
kw("default")
kw("default", beforeExpr)
kw("do", {isLoop: true})
kw("else", beforeExpr)
kw("finally")

View File

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

View File

@@ -54,9 +54,10 @@ export default class Buffer {
this.space();
}
space() {
if (this.format.compact) return;
if (this.buf && !this.isLast(" ") && !this.isLast("\n")) {
space(force?) {
if (!force && this.format.compact) return;
if (force || this.buf && !this.isLast(" ") && !this.isLast("\n")) {
this.push(" ");
}
}
@@ -155,8 +156,12 @@ export default class Buffer {
this.buf += str;
}
endsWith(str) {
return this.buf.slice(-str.length) === str;
endsWith(str, buf = this.buf) {
if (str.length === 1) {
return buf[buf.length - 1] === str;
} else {
return buf.slice(-str.length) === str;
}
}
isLast(cha) {

View File

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

View File

@@ -2,19 +2,19 @@ import isNumber from "lodash/lang/isNumber";
import * as t from "../../types";
export function UnaryExpression(node, print) {
var hasSpace = /[a-z]$/.test(node.operator);
var needsSpace = /[a-z]$/.test(node.operator);
var arg = node.argument;
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) {
hasSpace = true;
needsSpace = true;
}
if (t.isUnaryExpression(arg) && arg.operator === "!") {
hasSpace = false;
needsSpace = false;
}
this.push(node.operator);
if (hasSpace) this.push(" ");
if (needsSpace) this.push(" ");
print.plain(node.argument);
}
@@ -24,6 +24,12 @@ export function DoExpression(node, print) {
print.plain(node.body);
}
export function ParenthesizedExpression(node, print) {
this.push("(");
print.plain(node.expression);
this.push(")");
}
export function UpdateExpression(node, print) {
if (node.prefix) {
this.push(node.operator);
@@ -77,19 +83,16 @@ export function CallExpression(node, print) {
this.push("(");
var separator = ",";
var isPrettyCall = node._prettyCall && !this.format.retainLines;
var isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact;
var separator;
if (isPrettyCall) {
separator += "\n";
separator = ",\n";
this.newline();
this.indent();
} else {
separator += " ";
}
print.list(node.arguments, { separator: separator });
print.list(node.arguments, { separator });
if (isPrettyCall) {
this.newline();
@@ -135,9 +138,23 @@ export function AssignmentPattern(node, print) {
export function AssignmentExpression(node, print) {
// todo: add cases where the spaces can be dropped when in compact mode
print.plain(node.left);
this.push(" ");
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);
this.push(" ");
if (!spaces) {
// space is mandatory to avoid outputting <!--
// http://javascript.spec.whatwg.org/#comment-syntax
spaces = node.operator === "<" &&
t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) &&
t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" });
}
this.space(spaces);
print.plain(node.right);
}

View File

@@ -42,7 +42,7 @@ export function _method(node, print) {
}
this._params(value, print);
this.push(" ");
this.space();
print.plain(value.body);
}

View File

@@ -33,13 +33,13 @@ export function ForStatement(node, print) {
this.push(";");
if (node.test) {
this.push(" ");
this.space();
print.plain(node.test);
}
this.push(";");
if (node.update) {
this.push(" ");
this.space();
print.plain(node.update);
}
@@ -190,16 +190,29 @@ export function VariableDeclaration(node, print, parent) {
}
}
var sep = ",";
//
// use a pretty separator when we aren't in compact mode, have initializers and don't have retainLines on
// this will format declarations like:
//
// var foo = "bar", bar = "foo";
//
// into
//
// var foo = "bar",
// bar = "foo";
//
var sep;
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) {
sep += `\n${repeating(" ", node.kind.length + 1)}`;
} else {
sep += " ";
sep = `,\n${repeating(" ", node.kind.length + 1)}`;
}
//
print.list(node.declarations, { separator: sep });
if (t.isFor(parent)) {
// don't give semicolons to these nodes since they'll be inserted in the parent generator
if (parent.left === node || parent.init === node) return;
}

View File

@@ -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 {
@@ -80,7 +82,7 @@ export function ArrayExpression(node, print) {
// both (all) of the holes.
this.push(",");
} else {
if (i > 0) this.push(" ");
if (i > 0) this.space();
print.plain(elem);
if (i < len - 1) this.push(",");
}

View File

@@ -128,8 +128,7 @@ class CodeGenerator {
// catch up to this nodes newline if we're behind
if (node.loc && this.format.retainLines && this.buffer.buf) {
var needsParens = false;
if (!leftParenPrinted && 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("(");
}

View File

@@ -18,7 +18,11 @@ export default class NodePrinter {
}
list(items, opts = {}) {
if (opts.separator == null) opts.separator = ", ";
if (opts.separator == null) {
opts.separator = ",";
if (!this.generator.format.compact) opts.separator += " ";
}
return this.join(items, opts);
}

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

View File

@@ -4,6 +4,8 @@ import buildDebug from "debug/node";
var verboseDebug = buildDebug("babel:verbose");
var generalDebug = buildDebug("babel");
var seenDeprecatedMessages = [];
export default class Logger {
constructor(file: File, filename: string) {
this.filename = filename;
@@ -25,9 +27,17 @@ export default class Logger {
}
deprecate(msg) {
if (!this.file.opts.suppressDeprecationMessages) {
console.error(this._buildMessage(msg));
}
if (this.file.opts.suppressDeprecationMessages) return;
msg = this._buildMessage(msg);
// already seen this message
if (seenDeprecatedMessages.indexOf(msg) >= 0) return;
// make sure we don't see it again
seenDeprecatedMessages.push(msg);
console.error(msg);
}
verbose(msg: string) {

View File

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

View File

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

View File

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

View File

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

View File

@@ -162,6 +162,7 @@ var hoistVarDeclarationsVisitor = {
} else if (this.isFor()) {
if (isVar(node.left, node)) {
node.left = node.left.declarations[0].id;
self.pushDeclar(node.left);
}
} else if (isVar(node, parent)) {
return self.pushDeclar(node).map(t.expressionStatement);

View File

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

View File

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

View File

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

View File

@@ -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) {
@@ -12,9 +12,10 @@ var memberExpressionOptimisationVisitor = {
Function(node, parent, scope, state) {
// skip over functions as whatever `arguments` we reference inside will refer
// to the wrong function
var oldNoOptimise = state.noOptimise;
state.noOptimise = true;
this.traverse(memberExpressionOptimisationVisitor, state);
state.noOptimise = false;
state.noOptimise = oldNoOptimise;
this.skip();
},
@@ -27,7 +28,9 @@ var memberExpressionOptimisationVisitor = {
// is this a referenced identifier and is it referencing the rest parameter?
if (node.name !== state.name) return;
if (!state.noOptimise) {
if (state.noOptimise) {
state.deopted = true;
} else {
if (this.parentPath.isMemberExpression({ computed: true, object: node })) {
// if we know that this member expression is referencing a number then we can safely
// optimise it
@@ -46,11 +49,7 @@ var memberExpressionOptimisationVisitor = {
return;
}
}
}
if (state.noOptimise) {
state.deopted = true;
} else {
state.references.push(this);
}
}
@@ -85,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)) {
@@ -100,7 +99,6 @@ export var visitor = {
}
// check and optimise for extremely common cases
var state = {
references: [],
offset: node.params.length,
@@ -135,6 +133,9 @@ export var visitor = {
state.references = state.references.concat(state.candidates);
}
// deopt shadowed functions as transforms like regenerator may try touch the allocation loop
state.deopted = state.deopted || !!node.shadow;
//
var start = t.literal(node.params.length);
@@ -173,13 +174,13 @@ export var visitor = {
LEN: len
});
if (!state.deopted) {
if (state.deopted) {
loop._blockHoist = node.params.length + 1;
node.body.body.unshift(loop);
} else {
// perform allocation at the lowest common denominator of all references
loop._blockHoist = 1;
this.getEarliestCommonAncestorFrom(state.references).getStatementParent().insertBefore(loop);
return;
}
loop._blockHoist = node.params.length + 1;
node.body.body.unshift(loop);
}
};

View File

@@ -1,9 +1,7 @@
import * as t from "../../../types";
function loose(node, body, objId) {
for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];
for (var prop of (node.properties: Array)) {
body.push(t.expressionStatement(
t.assignmentExpression(
"=",
@@ -15,31 +13,15 @@ function loose(node, body, objId) {
}
function spec(node, body, objId, initProps, file) {
var props = node.properties;
// add all non-computed properties and `__proto__` properties to the initializer
var broken = false;
for (let i = 0; i < props.length; i++) {
let prop = props[i];
if (prop.computed) {
broken = true;
}
if (prop.kind !== "init" || !broken || t.isLiteral(t.toComputedKey(prop, prop.key), { value: "__proto__" })) {
initProps.push(prop);
props[i] = null;
}
}
// add a simple assignment for all Symbol member expressions due to symbol polyfill limitations
// otherwise use Object.defineProperty
for (let i = 0; i < props.length; i++) {
let prop = props[i];
if (!prop) continue;
for (let prop of (node.properties: Array)) {
// this wont work with Object.defineProperty
if (t.isLiteral(t.toComputedKey(prop), { value: "__proto__" })) {
initProps.push(prop);
continue;
}
let key = prop.key;
if (t.isIdentifier(key) && !prop.computed) {
@@ -68,14 +50,34 @@ export var visitor = {
exit(node, parent, scope, file) {
var hasComputed = false;
for (var prop of (node.properties: Array)) {
for (let prop of (node.properties: Array)) {
hasComputed = t.isProperty(prop, { computed: true, kind: "init" });
if (hasComputed) break;
}
if (!hasComputed) return;
// put all getters/setters into the first object expression as well as all initialisers up
// to the first computed property
var initProps = [];
var stopInits = false;
node.properties = node.properties.filter(function (prop) {
if (prop.computed) {
stopInits = true;
}
if (prop.kind !== "init" || !stopInits) {
initProps.push(prop);
return false;
} else {
return true;
}
});
//
var objId = scope.generateUidIdentifierBasedOnNode(parent);
//

View File

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

View File

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

View File

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

View File

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

View File

@@ -230,6 +230,7 @@ export function unshiftContext(context) {
*/
export function setup(parentPath, container, listKey, key) {
this.inList = !!listKey;
this.listKey = listKey;
this.parentKey = listKey || key;
this.container = container;

View File

@@ -21,6 +21,7 @@ export default class NodePath {
this.context = null;
this.container = null;
this.listKey = null;
this.inList = false;
this.parentKey = null;
this.key = null;
this.node = null;

View File

@@ -1,3 +1,4 @@
import type NodePath from "./index";
import * as inferers from "./inferers";
import * as t from "../../../types";
@@ -61,9 +62,11 @@ export function _getTypeAnnotation(): ?Object {
* Description
*/
export function isBaseType(baseName: string): boolean {
var type = this.getTypeAnnotation();
export function isBaseType(baseName: string, soft?): boolean {
return _isBaseType(baseName, this.getTypeAnnotation(), soft);
}
function _isBaseType(baseName: string, type?, soft?): boolean {
if (baseName === "string") {
return t.isStringTypeAnnotation(type);
} else if (baseName === "number") {
@@ -74,8 +77,47 @@ export function isBaseType(baseName: string): boolean {
return t.isAnyTypeAnnotation(type);
} else if (baseName === "mixed") {
return t.isMixedTypeAnnotation(type);
} else if (baseName === "void") {
return t.isVoidTypeAnnotation(type);
} else {
throw new Error(`Unknown base type ${baseName}`);
if (soft) {
return false;
} else {
throw new Error(`Unknown base type ${baseName}`);
}
}
}
/**
* Description
*/
export function couldBeBaseType(name: string): boolean {
var type = this.getTypeAnnotation();
if (t.isAnyTypeAnnotation(type)) return true;
if (t.isUnionTypeAnnotation(type)) {
for (var type2 of (type.types: Array)) {
if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
return true;
}
}
return false;
} else {
return _isBaseType(name, type, true);
}
}
/**
* Description
*/
export function baseTypeStrictlyMatches(right: NodePath) {
var left = this.getTypeAnnotation();
right = right.getTypeAnnotation();
if (!t.isAnyTypeAnnotation() && t.isFlowBaseAnnotation(left)) {
return right.type === left.type;
}
}

View File

@@ -140,7 +140,7 @@ export function ObjectExpression() {
//
export function ArrayExpression () {
export function ArrayExpression() {
return t.genericTypeAnnotation(t.identifier("Array"));
}

View File

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

View File

@@ -92,14 +92,14 @@ export function replaceWith(replacement, whateverAllowed) {
return;
}
if (this.isProgram() && !t.isProgram(replacement)) {
throw new Error("You can only replace a Program root node with another Program node");
}
// normalise inserting an entire AST
if (t.isProgram(replacement) && !this.isProgram()) {
replacement = replacement.body;
whateverAllowed = true;
} else {
if (this.isProgram()) {
throw new Error("You can only replace a Program root node with another Program node");
}
}
if (Array.isArray(replacement)) {
@@ -112,6 +112,13 @@ export function replaceWith(replacement, whateverAllowed) {
if (typeof replacement === "string") {
if (whateverAllowed) {
this.hub.file.log.deprecate("Returning a string from a visitor method will be removed in the future. String " +
"building is NOT a substitute for AST generation. String building leads to " +
"terrible performance due to the additional parsing overhead and will lead to " +
"extremely brittle transformers. For those extreme cases where you're dealing " +
"with strings from a foreign source you may continue to use " +
"`path.replaceWithSourceString(code)`. Please don't abuse this. Bad plugins " +
"hurt the ecosystem.");
return this.replaceWithSourceString(replacement);
} else {
throw new Error("Don't use `path.replaceWith()` with a string, use `path.replaceWithSourceString()`");

View File

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

View File

@@ -71,6 +71,7 @@
"MetaProperty": ["Expression"],
"NewExpression": ["Expression"],
"ObjectExpression": ["Expression"],
"ParenthesizedExpression": ["Expression"],
"SequenceExpression": ["Expression"],
"TaggedTemplateExpression": ["Expression"],
"ThisExpression": ["Expression"],

View File

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

View File

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

View File

@@ -23,7 +23,7 @@ export function isReferenced(node: Object, parent: Object): boolean {
switch (parent.type) {
// yes: PARENT[NODE]
// yes: NODE.child
// no: parent.CHILD
// no: parent.NODE
case "MemberExpression":
case "JSXMemberExpression":
if (parent.property === node && parent.computed) {
@@ -73,21 +73,17 @@ export function isReferenced(node: Object, parent: Object): boolean {
return parent.local === node;
}
// no: import NODE from "foo";
case "ImportDefaultSpecifier":
return false;
// no: import * as NODE from "foo";
case "ImportNamespaceSpecifier":
return false;
// no: <div NODE="foo" />
case "JSXAttribute":
return parent.name !== node;
// no: import NODE from "foo";
// no: import * as NODE from "foo";
// no: import { NODE as foo } from "foo";
// no: import { foo as NODE } from "foo";
// no: import NODE from "bar";
case "ImportDefaultSpecifier":
case "ImportNamespaceSpecifier":
case "ImportSpecifier":
return false;
@@ -112,12 +108,16 @@ export function isReferenced(node: Object, parent: Object): boolean {
case "RestElement":
return false;
// no: [NODE = foo] = [];
// yes: [foo = NODE] = [];
// yes: left = NODE;
// no: NODE = right;
case "AssignmentExpression":
case "AssignmentPattern":
return parent.right === node;
// no: [NODE = foo] = [];
// no: [foo = NODE] = [];
case "AssignmentPattern":
return false;
// no: [NODE] = [];
// no: ({ NODE }) = [];
case "ObjectPattern":
@@ -195,7 +195,7 @@ export function isImmutable(node: Object): boolean {
if (t.isLiteral(node)) {
if (node.regex) {
// regexes are mutable
// regexs are mutable
return false;
} else {
// immutable!

View File

@@ -46,6 +46,7 @@
"Noop": [],
"ObjectExpression": ["properties"],
"ObjectPattern": ["properties", "typeAnnotation"],
"ParenthesizedExpression": ["expression"],
"Program": ["body"],
"Property": ["key", "value", "decorators"],
"RestElement": ["argument", "typeAnnotation"],

View File

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

View File

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

View File

@@ -11148,3 +11148,9 @@ for (var ns in fbTestFixture) {
});
}
}
test("<Foo foo={function (): void {}} />", {}, {
ecmaVersion: 6,
sourceType: "module",
plugins: { jsx: true, flow: true },
});

View File

@@ -15328,3 +15328,5 @@ test("({ ['__proto__']: 1, __proto__: 2 })", {}, {ecmaVersion: 6});
test("({ __proto__() { return 1 }, __proto__: 2 })", {}, {ecmaVersion: 6});
test("({ get __proto__() { return 1 }, __proto__: 2 })", {}, {ecmaVersion: 6});
test("({ __proto__, __proto__: 2 })", {}, {ecmaVersion: 6});
test("export default /foo/", {}, {ecmaVersion: 6, sourceType: "module"});

View File

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

View File

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

View File

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

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

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

View File

@@ -0,0 +1,7 @@
var fn = async (...rest) => rest;
var fn = async (...rest) => {
if (true) {
rest;
}
};

View File

@@ -0,0 +1,39 @@
"use strict";
var _this = this;
var fn = function fn() {
for (var _len = arguments.length, rest = Array(_len), _key = 0; _key < _len; _key++) {
rest[_key] = arguments[_key];
}
return regeneratorRuntime.async(function fn$(context$1$0) {
while (1) switch (context$1$0.prev = context$1$0.next) {
case 0:
return context$1$0.abrupt("return", rest);
case 1:
case "end":
return context$1$0.stop();
}
}, null, _this);
};
var fn = function fn() {
for (var _len2 = arguments.length, rest = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
rest[_key2] = arguments[_key2];
}
return regeneratorRuntime.async(function fn$(context$1$0) {
while (1) switch (context$1$0.prev = context$1$0.next) {
case 0:
if (true) {
rest;
}
case 1:
case "end":
return context$1$0.stop();
}
}, null, _this);
};

View File

@@ -0,0 +1,3 @@
{
"stage": 0
}

View File

@@ -41,3 +41,12 @@ function r(...rest){
if (lol) rest;
rest;
}
// nested functions
function a(...args) {
return function() {
function b() {}
console.log("Shouldn't args be from a's scope?", args);
};
}

View File

@@ -64,3 +64,16 @@ function r() {
if (lol) rest;
rest;
}
// nested functions
function a() {
for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
return function () {
function b() {}
console.log("Shouldn't args be from a's scope?", args);
};
}

View File

@@ -0,0 +1,6 @@
function broken(x, ...foo) {
if (true) {
class Foo extends Bar { }
return hello(...foo)
}
}

View File

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

View File

@@ -0,0 +1,4 @@
var obj = {
foo: "bar",
[bar]: "foo"
};

View File

@@ -0,0 +1,7 @@
"use strict";
var _obj;
var obj = (_obj = {
foo: "bar"
}, _obj[bar] = "foo", _obj);

View File

@@ -1,3 +1,4 @@
{
"blacklist": ["es5.properties.mutators"],
"loose": ["es6.properties.computed"]
}

View File

@@ -1,4 +1,4 @@
var obj = {
first: "first",
["second"]: "second",
[second]: "second",
};

View File

@@ -2,4 +2,6 @@
var _obj;
var obj = (_obj = {}, _obj.first = "first", _obj["second"] = "second", _obj);
var obj = (_obj = {
first: "first"
}, _obj[second] = "second", _obj);

View File

@@ -0,0 +1,3 @@
"use strict";
(function (x, y) {});

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