Compare commits

...

48 Commits

Author SHA1 Message Date
Sebastian McKenzie
0e771c5d38 v5.4.7 2015-05-21 18:59:30 +01:00
Sebastian McKenzie
2ec1544f2d add 5.4.7 changelog 2015-05-21 18:58:49 +01:00
Sebastian McKenzie
049ef430b2 5.4.6 2015-05-21 18:58:12 +01:00
Sebastian McKenzie
34eb2babdb don't consider JSXAttribute keys to be referenced identifiers - fixes #1596 2015-05-21 18:58:07 +01:00
Sebastian McKenzie
8706754550 v5.4.6 2015-05-21 18:46:22 +01:00
Sebastian McKenzie
c7b507e119 add 5.4.6 changelog 2015-05-21 18:45:31 +01:00
Sebastian McKenzie
221c632c05 deprecate custom module formatters 2015-05-21 18:44:02 +01:00
Sebastian McKenzie
7dbde208ef spec.functionName transformer: hasBinding(name) returns true for built-in globals, so we attempt to rename the binding but it doesn't exist so exits early, add a check that doesn't perform the renaming and instead uses the wrapper - fixes #1598 2015-05-21 18:43:55 +01:00
Sebastian McKenzie
52a2e3e17c return original input if glob returned nothing in babel-cli - fixes #1591 2015-05-21 10:57:37 +01:00
Sebastian McKenzie
fa22d7dca0 5.4.5 2015-05-21 01:52:03 +01:00
Sebastian McKenzie
9fcdebde08 v5.4.5 2015-05-21 01:44:29 +01:00
Sebastian McKenzie
92157161f0 fix prettyCall generation option 2015-05-21 01:43:02 +01:00
Sebastian McKenzie
82b5479436 add 5.4.5 changelog 2015-05-21 01:41:30 +01:00
Sebastian McKenzie
91a037af55 Merge pull request #1590 from Khan/fix_retainLines_with_jsx
tests for retainLines formatting
2015-05-21 01:39:33 +01:00
Kevin Barabash
067fccc2c9 tests for retainLines formatting 2015-05-20 18:36:47 -06:00
Sebastian McKenzie
348c0d2542 handle TCO for calls that exceed the functions parameter count - fixes #1589 2015-05-21 01:21:49 +01:00
Sebastian McKenzie
f2f6bbb02c clean up explosion of module declarations, remove and inherit comments when taking off the declaration - fixes #1583 2015-05-21 01:03:23 +01:00
Sebastian McKenzie
16f7b967b5 ignore CallExpression _prettyCall when retainLines is enabled - fixes #1585 2015-05-21 00:21:18 +01:00
Sebastian McKenzie
270a8be68d add JSXIdentifier as a valid ReferencedIdentifier - fixes #1584 2015-05-21 00:20:53 +01:00
Sebastian McKenzie
82254d9d9b force push space for await/async - fixes #1581 2015-05-20 12:45:04 +01:00
Sebastian McKenzie
759a265fb0 5.4.4 2015-05-20 10:52:28 +01:00
Sebastian McKenzie
ee46f45c90 v5.4.4 2015-05-20 10:50:35 +01:00
Sebastian McKenzie
c45ce61550 print assignment pattern shorthand with matching key nicely 2015-05-20 10:44:36 +01:00
Sebastian McKenzie
b36cf11ac8 add 5.4.4 changelog 2015-05-20 10:44:17 +01:00
Sebastian McKenzie
dca0f72e4d clarify default option descriptions - fixes #1577 2015-05-20 10:36:58 +01:00
Sebastian McKenzie
68a99ed1e9 fix es6.modules-system for head hoisting 2015-05-20 10:35:01 +01:00
Sebastian McKenzie
af4feb4d88 fix renaming of assignment expressions to fix pattern renaming in the es6.blockScoping transformer - fixes #1576 2015-05-20 10:34:50 +01:00
Sebastian McKenzie
de1e965fec fix placement of for loop in es6.modules-system hoisting test 2015-05-20 10:15:42 +01:00
Sebastian McKenzie
430c5df0e7 rename sourceMapName option to sourceMapTarget - closes #1568 2015-05-20 10:14:28 +01:00
Sebastian McKenzie
9b12f799f7 clean up system module formatter hoisting visitor and allow contextual replacement of variable declarations with expressions in for head positions - fixes #1570 2015-05-20 10:07:29 +01:00
Sebastian McKenzie
f3a9c6ee5d Merge pull request #1562 from clintwood/sourcemap-file
correct cli source map file: value, honor sourceRoot when using -o opion
2015-05-20 09:57:34 +01:00
Sebastian McKenzie
e0aceeafef Merge pull request #1570 from guybedford/system-hoist-bug
System format hoisting bug
2015-05-20 09:57:14 +01:00
Sebastian McKenzie
7643d86047 Merge branch 'master' of github.com:babel/babel 2015-05-20 09:57:03 +01:00
Sebastian McKenzie
98af01a73c update old 6to5 package.json description 2015-05-20 09:56:54 +01:00
Sebastian McKenzie
e280a810c3 add support for all completion record types when exploding an expression to statements 2015-05-20 09:56:45 +01:00
Sebastian McKenzie
7a59575d1e force space before class id when generating classes - fixes #1579 2015-05-20 09:56:19 +01:00
Sebastian McKenzie
b01d8448a0 Merge pull request #1558 from jquense/patch-2
Resolve "babel-plugin-" name before trying the plain name.
2015-05-19 01:28:02 +01:00
jquense
9b3c8569f7 Resolve 'babel-plugin-' name before the plain name
Otherwise you get situations like the following: `plugins: [
'object-assign']` resolves the module `object-assign` (an Object.assign
polyfill) instead of the intended babel plugin:
babel-plugin-object-assign.
2015-05-18 20:26:51 -04:00
Sebastian McKenzie
12104f822f add assignment pattern shorthand support to explode transformer - fixes #1566 2015-05-18 22:44:40 +01:00
Sebastian McKenzie
b4cd2df745 ignore this and arguments when performing TCO on shadowed functions - fixes #1564 2015-05-18 22:41:27 +01:00
guybedford
887ffed84c system hoist bug test case 2015-05-18 23:35:09 +02:00
Sebastian McKenzie
9be3d9c8e1 Merge branch 'master' of github.com:babel/babel 2015-05-18 10:33:12 +01:00
clintwood (Office)
9d3dff3b7a correct cli source map file: value, honor sourceRoot when using -o option 2015-05-18 10:11:20 +02:00
Sebastian McKenzie
55114ec631 update AMD module formatter to add import default remapping - #1150 2015-05-18 02:01:34 +01:00
Sebastian McKenzie
9c3d00d3c3 Merge pull request #1559 from sindresorhus/hometmp
use `home-or-tmp` module instead of `user-home`
2015-05-17 23:50:26 +01:00
Sindre Sorhus
90b8826e73 use home-or-tmp module instead of user-home
The main point about using this instead of just falling back in code is that it depends on an `os.tmpdir()` polyfill [0], which means the tmpdir handling is the same no matter node/iojs version. This is useful as the core `os.tmpdir()` function has changed a lot between node versions.

[0]: https://github.com/sindresorhus/os-tmpdir

---

`os.tmpdir()` diff between Node 0.10.38 and iojs 2.0.2

```diff
+const trailingSlashRe = isWindows ? /[^:]\\$/
+                                  : /.\/$/;
+
 exports.tmpdir = function() {
-  return process.env.TMPDIR ||
-         process.env.TMP ||
-         process.env.TEMP ||
-         (process.platform === 'win32' ? 'c:\\windows\\temp' : '/tmp');
+  var path;
+  if (isWindows) {
+    path = process.env.TEMP ||
+           process.env.TMP ||
+           (process.env.SystemRoot || process.env.windir) + '\\temp';
+  } else {
+    path = process.env.TMPDIR ||
+           process.env.TMP ||
+           process.env.TEMP ||
+           '/tmp';
+  }
+  if (trailingSlashRe.test(path))
+    path = path.slice(0, -1);
+  return path;
 };
```
2015-05-18 00:39:49 +02:00
Sebastian McKenzie
65f39bbf6f switch order of jsx/flow plugins to avoid precedence issues - fixes babel/babel-eslint#103 2015-05-17 22:00:38 +01:00
Sebastian McKenzie
e9eced846f 5.4.3 2015-05-16 02:00:20 +01:00
56 changed files with 410 additions and 135 deletions

View File

@@ -13,6 +13,41 @@ _Note: Gaps between patch versions are faulty/broken releases._
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
## 5.4.7
* **Bug Fix**
* Don't consider `JSXAttribute` `names` to be valid `ReferencedIdentifier`s.
## 5.4.6
* **Bug Fix**
* Fix `spec.functionName` transformer incorrectly attempting to rename a binding that doesn't exist as it's a global.
* **Internal**
* Deprecate custom module formatters.
## 5.4.5
* **Bug Fix**
* Add `JSXIdentifier` as a valid `ReferencedIdentifier` visitor virtual type.
* Ignore `CallExpression` `_prettyCall` when the `retainLines` option is enabled.
* Inherit comments to new declaration node when exploding module declarations.
* Fix `es6.tailCall` transformer failing on calls that exceed the max parameters of the function.
## 5.4.4
* **Bug Fix**
* Fix bug where replacing variable declarations in the head of a `for` loop would turn them into `ExpressionStatement`s.
* Fix renaming of assignment expressions that were non-identifiers ie. patterns.
* Force space before `class` `id` to avoid breaking named classes when using `compact` mode.
* Add assignment pattern explosion to avoid initial duplicate nodes.
* Ignore this and arguments when performing TCO on shadowed functions.
* **Polish**
* Rename `sourceMapName` option to `sourceMapTarget`. Thanks [@getify](https://github.com/getify)!
* Better detection of completion records, ignore those in `Function`s.
* Clarified descriptions of the options that are enabled by default.
* Resolve `\`babel-plugin-${name}\`` plugin names **before** just checking the `name`. Thanks [@jquense](https://github.com/jquense)!
* Update AMD module formatter to add import default remapping.
## 5.4.3
* **Bug Fix**

View File

@@ -1,7 +1,7 @@
{
"name": "babel-core",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.4.3",
"description": "A compiler for writing next generation JavaScript",
"version": "5.4.7",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
@@ -41,6 +41,7 @@
"esutils": "^2.0.0",
"fs-readdir-recursive": "^0.1.0",
"globals": "^6.4.0",
"home-or-tmp": "^1.0.0",
"is-integer": "^1.0.4",
"js-tokens": "1.0.0",
"leven": "^1.0.1",
@@ -60,8 +61,7 @@
"source-map-support": "^0.2.10",
"strip-json-comments": "^1.0.2",
"to-fast-properties": "^1.0.0",
"trim-right": "^1.0.0",
"user-home": "^1.1.1"
"trim-right": "^1.0.0"
},
"devDependencies": {
"babel": "5.3.1",

View File

@@ -14,7 +14,8 @@ module.exports = function (commander, filenames, opts) {
var dest = path.join(commander.outDir, relative);
var data = util.compile(src, {
sourceFileName: slash(path.relative(dest + "/..", src))
sourceFileName: slash(path.relative(dest + "/..", src)),
sourceMapTarget: path.basename(relative)
});
if (data.ignored) return;

View File

@@ -16,7 +16,8 @@ module.exports = function (commander, filenames, opts) {
var buildResult = function () {
var map = new sourceMap.SourceMapGenerator({
file: slash(commander.outFile || "stdout")
file: path.basename(commander.outFile) || "stdout",
sourceRoot: opts.sourceRoot
});
var code = "";

View File

@@ -79,7 +79,9 @@ if (commander.extensions) {
var errors = [];
var filenames = commander.args.reduce(function (globbed, input) {
return globbed.concat(glob.sync(input));
var files = glob.sync(input);
if (!files.length) files = [input];
return globbed.concat(files);
}, []);
each(filenames, function (filename) {

View File

@@ -1,14 +1,14 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.4.2",
"version": "5.4.6",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel-core": "^5.4.2",
"babel-core": "^5.4.6",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"convert-source-map": "^1.1.0",

View File

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

View File

@@ -61,8 +61,8 @@ export function parse(code, opts = {}) {
opts.sourceType = "module";
opts.ecmaVersion = Infinity;
opts.plugins = {
flow: true,
jsx: true
jsx: true,
flow: true
};
opts.features = {};

View File

@@ -1,9 +1,9 @@
import path from "path";
import os from "os";
import fs from "fs";
import userHome from "user-home";
import homeOrTmp from "home-or-tmp";
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(userHome || os.tmpdir(), ".babel.json");
const FILENAME = process.env.BABEL_CACHE_PATH || path.join(homeOrTmp, ".babel.json");
var data = {};
export function save() {

View File

@@ -3,7 +3,7 @@ export function ClassDeclaration(node, print) {
this.push("class");
if (node.id) {
this.space();
this.push(" ");
print(node.id);
}

View File

@@ -79,7 +79,9 @@ export function CallExpression(node, print) {
var separator = ",";
if (node._prettyCall) {
var isPrettyCall = node._prettyCall && !this.format.retainLines;
if (isPrettyCall) {
separator += "\n";
this.newline();
this.indent();
@@ -89,7 +91,7 @@ export function CallExpression(node, print) {
print.list(node.arguments, { separator: separator });
if (node._prettyCall) {
if (isPrettyCall) {
this.newline();
this.dedent();
}
@@ -106,7 +108,7 @@ var buildYieldAwait = function (keyword) {
}
if (node.argument) {
this.space();
this.push(" ");
print(node.argument);
}
};

View File

@@ -39,6 +39,12 @@ export function Property(node, print) {
print(node.key);
this.push("]");
} else {
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
print(node.value);
return;
}
print(node.key);
// shorthand!

View File

@@ -8,7 +8,7 @@ export default class SourceMap {
if (opts.sourceMaps) {
this.map = new sourceMap.SourceMapGenerator({
file: opts.sourceMapName,
file: opts.sourceMapTarget,
sourceRoot: opts.sourceRoot
});

View File

@@ -27,7 +27,6 @@ export default function (code, opts = {}) {
}
var ast = acorn.parse(code, parseOpts);
estraverse.attachComments(ast, comments, tokens);
ast = normalizeAst(ast, comments, tokens);
return ast;

View File

@@ -168,7 +168,7 @@ export default class File {
defaults(opts, {
sourceFileName: opts.filenameRelative,
sourceMapName: opts.filenameRelative
sourceMapTarget: opts.filenameRelative
});
//
@@ -420,6 +420,10 @@ export default class File {
getModuleFormatter(type: string) {
if (isFunction(type) || !moduleFormatters[type]) {
this.log.deprecate("Custom module formatters are deprecated and will be removed in the next major. Please use Babel plugins instead.");
}
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
if (!ModuleFormatter) {

View File

@@ -43,7 +43,7 @@
"nonStandard": {
"type": "boolean",
"default": true,
"description": "enable support for JSX and Flow"
"description": "enable/disable support for JSX and Flow (on by default)"
},
"experimental": {
@@ -51,7 +51,7 @@
},
"highlightCode": {
"description": "ANSI syntax highlight code frames",
"description": "enable/disable ANSI syntax highlighting of code frames (on by default)",
"type": "boolean",
"default": true
},
@@ -148,7 +148,7 @@
"comments": {
"type": "boolean",
"default": true,
"description": "output comments in generated output"
"description": "strip/output comments in generated output (on by default)"
},
"compact": {
@@ -197,6 +197,11 @@
},
"sourceMapName": {
"alias": "sourceMapTarget",
"description": "DEPRECATED - Please use sourceMapTarget"
},
"sourceMapTarget": {
"type": "string",
"description": "set `file` on returned source map"
},

View File

@@ -35,7 +35,7 @@ export default class PluginManager {
var match = name.match(/^(.*?):(after|before)$/);
if (match) [, name, position] = match;
var loc = util.resolveRelative(name) || util.resolveRelative(`babel-plugin-${name}`);
var loc = util.resolveRelative(`babel-plugin-${name}`) || util.resolveRelative(name);
if (loc) {
return {
position: position,

View File

@@ -20,7 +20,7 @@ var visitor = {
var wrap = function (state, method, id, scope) {
if (state.selfReference) {
if (scope.hasBinding(id.name)) {
if (scope.hasBinding(id.name) && !scope.hasGlobal(id.name)) {
// we can just munge the local binding
scope.rename(id.name);
} else {

View File

@@ -92,9 +92,9 @@ export default class AMDFormatter extends DefaultFormatter {
// import foo from "foo";
var uid = this.scope.generateUidIdentifier(specifier.local.name);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require"), [ref]))
t.variableDeclarator(uid, t.callExpression(this.file.addHelper("interop-require-default"), [ref]))
]));
ref = uid;
ref = t.memberExpression(uid, t.identifier("default"));
} else {
// import { foo } from "foo";
var imported = specifier.imported;

View File

@@ -8,41 +8,39 @@ import map from "lodash/collection/map";
import * as t from "../../types";
var hoistVariablesVisitor = {
enter(node, parent, scope, state) {
if (t.isFunction(node)) {
// nothing inside is accessible
return this.skip();
Function() {
// nothing inside is accessible
this.skip();
},
VariableDeclaration(node, parent, scope, state) {
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
// can't be accessed
return;
}
if (t.isVariableDeclaration(node)) {
if (node.kind !== "var" && !t.isProgram(parent)) { // let, const
// can't be accessed
return;
// ignore block hoisted nodes as these can be left in
if (state.formatter._canHoist(node)) return;
var nodes = [];
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
if (declar.init) {
// no initializer so we can just hoist it as-is
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
nodes.push(assign);
}
// ignore block hoisted nodes as these can be left in
if (state.formatter._canHoist(node)) return;
var nodes = [];
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
state.hoistDeclarators.push(t.variableDeclarator(declar.id));
if (declar.init) {
// no initializer so we can just hoist it as-is
var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init));
nodes.push(assign);
}
}
// for (var i in test)
// for (var i = 0;;)
if (t.isFor(parent) && parent.left === node) {
return node.declarations[0].id;
}
return nodes;
}
// for (var i in test)
// for (var i = 0;;)
if (t.isFor(parent) && (parent.left === node || parent.init === node)) {
return node.declarations[0].id;
}
return nodes;
}
};

View File

@@ -84,8 +84,6 @@ export function BlockStatement(block, parent, scope, file) {
export { BlockStatement as Program };
function replace(node, parent, scope, remaps) {
if (!t.isReferencedIdentifier(node, parent)) return;
var remap = remaps[node.name];
if (!remap) return;
@@ -100,11 +98,21 @@ function replace(node, parent, scope, remaps) {
}
var replaceVisitor = {
enter: replace
ReferencedIdentifier: replace,
AssignmentExpression(node, parent, scope, remaps) {
var ids = this.getBindingIdentifiers();
for (var name in ids) {
replace(ids[name], node, scope, remaps);
}
},
};
function traverseReplace(node, parent, scope, remaps) {
replace(node, parent, scope, remaps);
if (t.isIdentifier(node)) {
replace(node, parent, scope, remaps);
}
scope.traverse(node, replaceVisitor, remaps);
}

View File

@@ -44,12 +44,14 @@ var visitor = {
},
ThisExpression(node, parent, scope, state) {
state.needsThis = true;
state.thisPaths.push(this);
if (!state.isShadowed) {
state.needsThis = true;
state.thisPaths.push(this);
}
},
ReferencedIdentifier(node, parent, scope, state) {
if (node.name === "arguments") {
if (node.name === "arguments" && (!state.isShadowed || node._shadowedFunctionLiteral)) {
state.needsArguments = true;
state.argumentsPaths.push(this);
}
@@ -67,8 +69,9 @@ class TailCallTransformer {
this.needsThis = false;
this.thisPaths = [];
this.ownerId = path.node.id;
this.vars = [];
this.isShadowed = path.isArrowFunctionExpression() || path.is("shadow");
this.ownerId = path.node.id;
this.vars = [];
this.scope = scope;
this.path = path;
@@ -208,6 +211,7 @@ class TailCallTransformer {
var decl = t.variableDeclarator(this.argumentsId);
if (this.argumentsId) {
decl.init = t.identifier("arguments");
decl.init._shadowedFunctionLiteral = true;
}
topVars.push(decl);
}
@@ -288,7 +292,8 @@ class TailCallTransformer {
}
subTransformCallExpression(node) {
var callee = node.callee, thisBinding, args;
var callee = node.callee;
var thisBinding, args;
if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property)) {
switch (callee.property.name) {
@@ -298,6 +303,7 @@ class TailCallTransformer {
case "apply":
args = node.arguments[1] || t.identifier("undefined");
this.needsArguments = true;
break;
default:
@@ -331,6 +337,10 @@ class TailCallTransformer {
args = t.arrayExpression(node.arguments);
}
if (t.isArrayExpression(args) && args.elements.length > this.node.params.length) {
this.needsArguments = true;
}
var argumentsId = this.getArgumentsId();
var params = this.getParams();

View File

@@ -5,9 +5,9 @@ export var metadata = {
group: "builtin-setup"
};
function buildClone(bindingKey, refKey) {
function buildClone(bindingKey, refKey, check?) {
return function (node) {
if (node[bindingKey] === node[refKey]) {
if (node[bindingKey] === node[refKey] || (check && check(node))) {
node[refKey] = t.removeComments(clone(node[refKey]));
}
};
@@ -25,6 +25,9 @@ function buildListClone(listKey, bindingKey, refKey) {
};
}
export var Property = buildClone("value", "key");
export var Property = buildClone("value", "key", function (node) {
return t.isAssignmentPattern(node.value) && node.value.left === node.key;
});
export var ExportDeclaration = buildListClone("specifiers", "local", "exported");
export var ImportDeclaration = buildListClone("specifiers", "local", "imported");

View File

@@ -7,6 +7,14 @@
import clone from "lodash/lang/clone";
import * as t from "../../../types";
function getDeclar(node) {
var declar = node.declaration;
t.inheritsComments(declar, node);
t.removeComments(node);
declar._ignoreUserWhitespace = true;
return declar;
}
export var metadata = {
group: "builtin-setup"
};
@@ -24,28 +32,28 @@ export function ExportDefaultDeclaration(node, parent, scope) {
var declar = node.declaration;
var getDeclar = function () {
declar._ignoreUserWhitespace = true;
return declar;
};
if (t.isClassDeclaration(declar)) {
// export default class Foo {};
var nodes = [getDeclar(node), node];
node.declaration = declar.id;
return [getDeclar(), node];
return nodes;
} else if (t.isClassExpression(declar)) {
// export default class {};
var temp = scope.generateUidIdentifier("default");
declar = t.variableDeclaration("var", [
node.declaration = t.variableDeclaration("var", [
t.variableDeclarator(temp, declar)
]);
var nodes = [getDeclar(node), node];
node.declaration = temp;
return [getDeclar(), node];
return nodes;
} else if (t.isFunctionDeclaration(declar)) {
// export default function Foo() {}
node._blockHoist = 2;
var nodes = [getDeclar(node), node];
node.declaration = declar.id;
return [getDeclar(), node];
return nodes;
}
}
@@ -58,22 +66,20 @@ export function ExportNamedDeclaration(node, parent, scope) {
var declar = node.declaration;
var getDeclar = function () {
declar._ignoreUserWhitespace = true;
return declar;
};
if (t.isClassDeclaration(declar)) {
// export class Foo {}
node.specifiers = [buildExportSpecifier(declar.id)];
var nodes = [getDeclar(node), node];
node.declaration = null;
return [getDeclar(), node];
return nodes;
} else if (t.isFunctionDeclaration(declar)) {
// export function Foo() {}
node.specifiers = [buildExportSpecifier(declar.id)];
node.declaration = null;
node._blockHoist = 2;
return [getDeclar(), node];
var nodes = [getDeclar(node), node];
node.declaration = null;
return nodes;
} else if (t.isVariableDeclaration(declar)) {
// export var foo = "bar";
var specifiers = [];

View File

@@ -260,10 +260,15 @@ export default class TraversalPath {
do {
var container = path.container;
if (path.isFunction()) {
return false;
}
if (Array.isArray(container) && path.key !== container.length - 1) {
return false;
}
} while (path = path.parentPath && !path.isProgram());
} while ((path = path.parentPath) && !path.isProgram());
return true;
}
@@ -708,7 +713,7 @@ export default class TraversalPath {
}
// replacing a statement with an expression so wrap it in an expression statement
if (this.isPreviousType("Statement") && t.isExpression(replacement)) {
if (this.isPreviousType("Statement") && t.isExpression(replacement) && !this.canHaveVariableDeclarationOrExpression()) {
replacement = t.expressionStatement(replacement);
}
@@ -728,6 +733,20 @@ export default class TraversalPath {
this.setScope();
}
/**
* This checks whether or now we're in one of the following positions:
*
* for (KEY in right);
* for (KEY;;);
*
* This is because these spots allow VariableDeclarations AND normal expressions so we need to tell the
* path replacement that it's ok to replace this with an expression.
*/
canHaveVariableDeclarationOrExpression() {
return (this.key === "init" || this.key === "left") && this.parentPath.isFor();
}
/**
* Description
*/
@@ -754,20 +773,22 @@ export default class TraversalPath {
* Description
*/
getLastStatements(): Array<TraversalPath> {
getCompletionRecords(): Array<TraversalPath> {
var paths = [];
var add = function (path) {
if (path) paths = paths.concat(path.getLastStatements());
if (path) paths = paths.concat(path.getCompletionRecords());
};
if (this.isIfStatement()) {
add(this.get("consequent"));
add(this.get("alternate"));
} else if (this.isDoExpression()) {
} else if (this.isDoExpression() || this.isFor() || this.isWhile()) {
add(this.get("body"));
} else if (this.isProgram() || this.isBlockStatement()) {
add(this.get("body").pop());
} else if (this.isFunction()) {
return this.get("body").getCompletionRecords();
} else {
paths.push(this);
}
@@ -788,19 +809,27 @@ export default class TraversalPath {
var container = t.functionExpression(null, [], t.blockStatement(nodes));
container.shadow = true;
this.replaceWith(t.callExpression(container, []));
this.traverse(hoistVariablesVisitor);
// add implicit returns to all ending expression statements
var last = this.getLastStatements();
var last = this.get("callee").getCompletionRecords();
for (var i = 0; i < last.length; i++) {
var lastNode = last[i];
if (lastNode.isExpressionStatement()) {
lastNode.replaceWith(t.returnStatement(lastNode.node.expression));
var loop = lastNode.findParent((node, path) => path.isLoop());
if (loop) {
var uid = this.get("callee").scope.generateDeclaredUidIdentifier("ret");
this.get("callee.body").pushContainer("body", t.returnStatement(uid));
lastNode.get("expression").replaceWith(
t.assignmentExpression("=", uid, lastNode.node.expression)
);
} else {
lastNode.replaceWith(t.returnStatement(lastNode.node.expression));
}
}
}
this.replaceWith(t.callExpression(container, []));
this.traverse(hoistVariablesVisitor);
return this.node;
}
}

View File

@@ -1,14 +1,14 @@
import * as t from "../../types";
export var ReferencedIdentifier = {
type: "Identifier",
types: ["Identifier", "JSXIdentifier"],
checkPath(path, opts) {
return t.isReferencedIdentifier(path.node, path.parent, opts);
}
};
export var Scope = {
type: "Scopable",
types: ["Scopable"],
checkPath(path) {
return t.isScope(path.node, path.parent);
}
@@ -27,7 +27,7 @@ export var BlockScoped = {
};
export var Var = {
type: "VariableDeclaration",
types: ["VariableDeclaration"],
checkPath(path) {
return t.isVar(path.node);
}

View File

@@ -29,19 +29,21 @@ export function explode(visitor, mergeConflicts) {
// wrap all the functions
var fns = visitor[nodeType];
for (var type in fns) {
for (let type in fns) {
fns[type] = wrapCheck(wrapper, fns[type]);
}
// clear it from the visitor
delete visitor[nodeType];
if (wrapper.type) {
// merge the visitor if necessary or just put it back in
if (visitor[wrapper.type]) {
mergePair(visitor[wrapper.type], fns);
} else {
visitor[wrapper.type] = fns;
if (wrapper.types) {
for (let type of (wrapper.types: Array)) {
// merge the visitor if necessary or just put it back in
if (visitor[type]) {
mergePair(visitor[type], fns);
} else {
visitor[type] = fns;
}
}
} else {
mergePair(visitor, fns);

View File

@@ -66,6 +66,10 @@ export function isReferenced(node: Object, parent: Object): boolean {
case "ImportNamespaceSpecifier":
return false;
// no: <div NODE="foo" />
case "JSXAttribute":
return parent.name !== node;
// no: import { NODE as foo } from "foo";
// no: import { foo as NODE } from "foo";
case "ImportSpecifier":

View File

@@ -0,0 +1,8 @@
const foo = "foo";
function foobar() {
for (let item of [1, 2, 3]) {
let foo = "bar";
[bar, foo] = [1, 2];
}
}

View File

@@ -0,0 +1,14 @@
"use strict";
var foo = "foo";
function foobar() {
var _arr = [1, 2, 3];
for (var _i = 0; _i < _arr.length; _i++) {
var item = _arr[_i];
var _foo = "bar";
bar = 1;
_foo = 2;
}
}

View File

@@ -1,10 +1,10 @@
define(["exports", "foo"], function (exports, _foo) {
"use strict";
var _foo2 = babelHelpers.interopRequire(_foo);
var _foo2 = babelHelpers.interopRequireDefault(_foo);
var _foo22 = babelHelpers.interopRequire(_foo);
var _foo22 = babelHelpers.interopRequireDefault(_foo);
_foo2;
_foo22;
_foo2["default"];
_foo22["default"];
});

View File

@@ -1,8 +1,8 @@
define(["exports", "foo"], function (exports, _foo) {
"use strict";
var _foo2 = babelHelpers.interopRequire(_foo);
var _foo2 = babelHelpers.interopRequireDefault(_foo);
_foo2;
_foo2["default"];
_foo.baz;
});

View File

@@ -5,7 +5,7 @@ define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports,
value: true
});
var _foo2 = babelHelpers.interopRequire(_foo);
var _foo2 = babelHelpers.interopRequireDefault(_foo);
exports.test = test;
var test2 = 5;
@@ -13,7 +13,7 @@ define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports,
exports.test2 = test2;
exports["default"] = test;
_foo2;
_foo2["default"];
_foo;
_foo.bar;
_foo.foo;

View File

@@ -6,6 +6,8 @@ export function nextOdd(n) {
export var p = 5;
for (var a in b) ;
export var isOdd = (function (isEven) {
return function (n) {
return !isEven(n);

View File

@@ -1,7 +1,7 @@
System.register(["./evens"], function (_export) {
"use strict";
var isEven, p, isOdd;
var isEven, p, a, isOdd;
_export("nextOdd", nextOdd);
@@ -18,6 +18,8 @@ System.register(["./evens"], function (_export) {
_export("p", p);
for (a in b);
isOdd = (function (isEven) {
return function (n) {
return !isEven(n);

View File

@@ -13,10 +13,10 @@
})(this, function (exports, _foo) {
"use strict";
var _foo2 = babelHelpers.interopRequire(_foo);
var _foo2 = babelHelpers.interopRequireDefault(_foo);
var _foo22 = babelHelpers.interopRequire(_foo);
var _foo22 = babelHelpers.interopRequireDefault(_foo);
_foo2;
_foo22;
_foo2["default"];
_foo22["default"];
});

View File

@@ -13,7 +13,7 @@
})(this, function (exports, _foo) {
"use strict";
var _foo2 = babelHelpers.interopRequire(_foo);
var _foo2 = babelHelpers.interopRequireDefault(_foo);
_foo.baz;
});

View File

@@ -17,7 +17,7 @@
value: true
});
var _foo2 = babelHelpers.interopRequire(_foo);
var _foo2 = babelHelpers.interopRequireDefault(_foo);
exports.test = test;
var test2 = 5;

View File

@@ -0,0 +1,4 @@
bar();
// bar
export function foo() {}

View File

@@ -0,0 +1,8 @@
"use strict";
export { foo };
bar();
// bar
function foo() {}

View File

@@ -0,0 +1,4 @@
{
"blacklist": ["es6.modules"],
"noCheckAst": true
}

View File

@@ -0,0 +1,9 @@
var count = (i = 10) => {
if (!i) return;
return count(i - 1);
};
function count2(i = 10) {
if (!i) return;
return count2(i - 1);
}

View File

@@ -0,0 +1,33 @@
"use strict";
var count = function count() {
var _arguments = arguments;
var _again = true;
_function: while (_again) {
i = undefined;
_again = false;
var i = _arguments[0] === undefined ? 10 : _arguments[0];
if (!i) return;
_arguments = [i - 1];
_again = true;
continue _function;
}
};
function count2() {
var _arguments2 = arguments;
var _again2 = true;
_function2: while (_again2) {
i = undefined;
_again2 = false;
var i = _arguments2[0] === undefined ? 10 : _arguments2[0];
if (!i) return;
_arguments2 = [i - 1];
_again2 = true;
continue _function2;
}
}

View File

@@ -0,0 +1,8 @@
(function(){
var foo = () => {
this;
arguments;
foo();
};
foo();
});

View File

@@ -0,0 +1,13 @@
"use strict";
(function () {
var _this = this,
_arguments = arguments;
var foo = function foo() {
_this;
_arguments;
foo();
};
foo();
});

View File

@@ -0,0 +1 @@
var div = <div>test</div>;

View File

@@ -0,0 +1 @@
var div = React.createElement("div", null, "test");

View File

@@ -0,0 +1,3 @@
{
"retainLines": true
}

View File

@@ -0,0 +1 @@
var div = <div>test</div>;

View File

@@ -0,0 +1,5 @@
var div = React.createElement(
"div",
null,
"test"
);

View File

@@ -1,7 +1,7 @@
define(["exports", "foo", "babel-runtime/helpers/interop-require"], function (exports, _foo, _babelRuntimeHelpersInteropRequire) {
define(["exports", "foo", "babel-runtime/helpers/interop-require-default"], function (exports, _foo, _babelRuntimeHelpersInteropRequireDefault) {
"use strict";
var _foo2 = (0, _babelRuntimeHelpersInteropRequire["default"])(_foo);
var _foo2 = (0, _babelRuntimeHelpersInteropRequireDefault["default"])(_foo);
_foo2;
});
_foo2["default"];
});

View File

@@ -1,17 +1,17 @@
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(["exports", "foo", "babel-runtime/helpers/interop-require"], factory);
define(["exports", "foo", "babel-runtime/helpers/interop-require-default"], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require("foo"), require("babel-runtime/helpers/interop-require"));
factory(exports, require("foo"), require("babel-runtime/helpers/interop-require-default"));
} else {
var mod = {
exports: {}
};
factory(mod.exports, global.foo, global._interopRequire);
factory(mod.exports, global.foo, global._interopRequireDefault);
global.actual = mod.exports;
}
})(this, function (exports, _foo, _babelRuntimeHelpersInteropRequire) {
})(this, function (exports, _foo, _babelRuntimeHelpersInteropRequireDefault) {
"use strict";
var _foo2 = (0, _babelRuntimeHelpersInteropRequire["default"])(_foo);
});
var _foo2 = (0, _babelRuntimeHelpersInteropRequireDefault["default"])(_foo);
});

View File

@@ -0,0 +1,5 @@
var test = {
setInterval: function(fn, ms) {
setInterval(fn, ms);
}
};

View File

@@ -0,0 +1,17 @@
"use strict";
var test = {
setInterval: (function (_setInterval) {
function setInterval(_x, _x2) {
return _setInterval.apply(this, arguments);
}
setInterval.toString = function () {
return _setInterval.toString();
};
return setInterval;
})(function (fn, ms) {
setInterval(fn, ms);
})
};

View File

@@ -9,3 +9,12 @@ var bar = {
get(arg, "baz");
}
};
var f = function ({ foo = "bar" }) {
var obj = {
// same name as parameter
foo: function () {
foo;
}
};
};

View File

@@ -11,3 +11,16 @@ var bar = {
_get(arg, "baz");
}
};
var f = function f(_ref) {
var _ref$foo = _ref.foo;
var _foo = _ref$foo === undefined ? "bar" : _ref$foo;
var obj = {
// same name as parameter
foo: function foo() {
_foo;
}
};
};