Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09e68d8d46 | ||
|
|
ee850c3aeb | ||
|
|
ff5a149cec | ||
|
|
957118fb41 | ||
|
|
e7ad0a9741 | ||
|
|
24f4b041c7 | ||
|
|
4c77d04b56 | ||
|
|
e945f0d10f | ||
|
|
fb04b2561f | ||
|
|
a4f8b41507 | ||
|
|
1fb6018e9c | ||
|
|
bca233d22c | ||
|
|
c78703e194 | ||
|
|
43fdbe3d6c | ||
|
|
8650ca7d55 | ||
|
|
3a0c226a34 | ||
|
|
73e8bdd048 | ||
|
|
e7c52a734e | ||
|
|
5a81b02569 | ||
|
|
999baf2888 | ||
|
|
70b25e8942 | ||
|
|
2ddbd4eecc | ||
|
|
7520807df3 | ||
|
|
974b71bcc3 | ||
|
|
0aee3c06ec | ||
|
|
a4382580fc | ||
|
|
166b2eda87 | ||
|
|
83c23d266f | ||
|
|
a9db70b60d | ||
|
|
5d90c442cb | ||
|
|
32606ddb93 | ||
|
|
330f6910c6 | ||
|
|
4ca8a0e6e2 | ||
|
|
f097ddeac3 | ||
|
|
1eb53dd13a | ||
|
|
75b5f32e7a | ||
|
|
f753cf4845 | ||
|
|
9a569f64da | ||
|
|
8efeae80af | ||
|
|
4df9cf6c05 | ||
|
|
7729cb4b68 | ||
|
|
307ffcd107 | ||
|
|
751557aef1 | ||
|
|
3f146b54ff | ||
|
|
19a173c622 | ||
|
|
89bcb307a2 | ||
|
|
ded1e02da7 | ||
|
|
564ba67190 | ||
|
|
b5f3c3f4cc | ||
|
|
5d83638583 | ||
|
|
24ace3c8c2 | ||
|
|
687b0f3180 | ||
|
|
e6855b974b | ||
|
|
a808742c19 | ||
|
|
c3f4091b6d | ||
|
|
edb880f87c | ||
|
|
e8741daee3 | ||
|
|
c5913564f8 | ||
|
|
662bddbaca | ||
|
|
8f540dfff3 | ||
|
|
1265bc5a92 | ||
|
|
e677c72d58 | ||
|
|
8ca854156a | ||
|
|
81ae656358 | ||
|
|
f2981b7e95 | ||
|
|
99b2e00d33 |
1
.eslintignore
Normal file
1
.eslintignore
Normal file
@@ -0,0 +1 @@
|
||||
src/babel/transformation/templates
|
||||
22
.eslintrc
Normal file
22
.eslintrc
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"parser": "babel-eslint",
|
||||
"rules": {
|
||||
"strict": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-unused-vars": 0,
|
||||
"curly": 0,
|
||||
"no-multi-spaces": 0,
|
||||
"key-spacing": 0,
|
||||
"no-return-assign": 0,
|
||||
"consistent-return": 0,
|
||||
"no-shadow": 0,
|
||||
"no-comma-dangle": 0,
|
||||
"no-use-before-define": 0,
|
||||
"no-empty": 0,
|
||||
"new-parens": 0,
|
||||
"no-cond-assign": 0
|
||||
},
|
||||
"env": {
|
||||
"node": true
|
||||
}
|
||||
}
|
||||
25
CHANGELOG.md
25
CHANGELOG.md
@@ -13,6 +13,31 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 4.6.1
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix generators in template directory being transformed.
|
||||
* Fix exposure of `util` for plugins.
|
||||
|
||||
## 4.6.0
|
||||
|
||||
* **New Feature**
|
||||
* Desugar sticky regexes to a new constructor expression so it can be handled by a polyfill.
|
||||
* **Spec Compliancy**
|
||||
* `for...of` now outputs in a lengthy `try...catch` this is to ensure spec compliancy in regards to iterator returns and abrupt completions. See [google/traceur-compiler#1773](https://github.com/google/traceur-compiler/issues/1773) and [babel/babel/#838](https://github.com/babel/babel/issues/838) for more information.
|
||||
* **Polish**
|
||||
* Rest parameters that are only refered to via number properties on member expressions are desugared into a direct `arguments` reference. Thanks [@neVERberleRfellerER](https://github.com/neVERberleRfellerER)!
|
||||
* `$ babel` no longer exits on syntax errors.
|
||||
* **Internal**
|
||||
* Upgrade `browserify`.
|
||||
* Upgrade `source-map`.
|
||||
* Publicly expose more internals.
|
||||
|
||||
## 4.5.5
|
||||
|
||||
* **Polish**
|
||||
* Delete old extensions when overriding them in `babel/register`.
|
||||
|
||||
## 4.5.3
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
@@ -4,10 +4,6 @@ Contributions are always welcome, no matter how large or small. Before
|
||||
contributing, please read the
|
||||
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
|
||||
|
||||
**NOTE:** Please do not send pull requests that fix linting issues. It's highly
|
||||
likely that they've already been fixed by the time it's submitted and it just
|
||||
pollutes the git tree.
|
||||
|
||||
## Developing
|
||||
|
||||
#### Setup
|
||||
@@ -44,15 +40,6 @@ running them with `mocha`:
|
||||
$ mocha test/transformation.js
|
||||
```
|
||||
|
||||
#### Linting
|
||||
|
||||
Please follow the correct code style, this ensures that the code is consistent
|
||||
and increases maintainability.
|
||||
|
||||
```sh
|
||||
$ make lint
|
||||
```
|
||||
|
||||
#### Workflow
|
||||
|
||||
* Fork the repository
|
||||
|
||||
@@ -31,6 +31,14 @@ module.exports = function (commander, filenames, opts) {
|
||||
console.log(src + " -> " + dest);
|
||||
};
|
||||
|
||||
var handleFile = function (src, filename) {
|
||||
if (util.canCompile(filename)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
}
|
||||
};
|
||||
|
||||
var handle = function (filename) {
|
||||
if (!fs.existsSync(filename)) return;
|
||||
|
||||
@@ -41,11 +49,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
_.each(util.readdir(dirname), function (filename) {
|
||||
var src = path.join(dirname, filename);
|
||||
if (util.canCompile(filename)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
}
|
||||
handleFile(src, filename);
|
||||
});
|
||||
} else {
|
||||
write(filename, filename);
|
||||
@@ -64,7 +68,11 @@ module.exports = function (commander, filenames, opts) {
|
||||
_.each(["add", "change"], function (type) {
|
||||
watcher.on(type, function (filename) {
|
||||
var relative = path.relative(dirname, filename) || filename;
|
||||
if (util.canCompile(filename)) write(filename, relative);
|
||||
try {
|
||||
handleFile(filename, relative);
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -119,7 +119,11 @@ module.exports = function (commander, filenames) {
|
||||
}).on("all", function (type, filename) {
|
||||
if (type === "add" || type === "change") {
|
||||
console.log(type, filename);
|
||||
walk();
|
||||
try {
|
||||
walk();
|
||||
} catch (err) {
|
||||
console.error(err.stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,17 +26,7 @@ exports.transform = function (filename, code, opts) {
|
||||
opts.filename = filename;
|
||||
resolveRc(filename, opts);
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = babel.transform(code, opts);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.error("SyntaxError:", e.message);
|
||||
process.exit(1);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
var result = babel.transform(code, opts);
|
||||
result.filename = filename;
|
||||
result.actual = code;
|
||||
return result;
|
||||
|
||||
14
package.json
14
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "4.5.5",
|
||||
"version": "4.6.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -36,7 +36,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-babel": "0.11.1-35",
|
||||
"acorn-babel": "0.11.1-37",
|
||||
"ast-types": "~0.6.1",
|
||||
"chalk": "^1.0.0",
|
||||
"chokidar": "^0.12.6",
|
||||
@@ -49,7 +49,7 @@
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"globals": "^6.2.0",
|
||||
"is-integer": "^1.0.4",
|
||||
"js-tokens": "0.4.1",
|
||||
"js-tokens": "1.0.0",
|
||||
"leven": "^1.0.1",
|
||||
"line-numbers": "0.2.0",
|
||||
"lodash": "^3.2.0",
|
||||
@@ -61,15 +61,17 @@
|
||||
"repeating": "^1.1.2",
|
||||
"shebang-regex": "^1.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.1.43",
|
||||
"source-map": "^0.4.0",
|
||||
"source-map-support": "^0.2.9",
|
||||
"source-map-to-comment": "^1.0.0",
|
||||
"trim-right": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "4.5.1",
|
||||
"browserify": "^8.1.3",
|
||||
"babel": "4.6.0",
|
||||
"browserify": "^9.0.3",
|
||||
"chai": "^2.0.0",
|
||||
"eslint": "^0.15.1",
|
||||
"babel-eslint": "^1.0.1",
|
||||
"esvalid": "^1.1.0",
|
||||
"istanbul": "^0.3.5",
|
||||
"matcha": "^0.6.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "4.5.4",
|
||||
"version": "4.6.1",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var buildHelpers = require("../lib/babel/build-helpers");
|
||||
var transform = require("../lib/babel/transformation");
|
||||
var buildHelpers = require("../lib/babel/build-helpers");
|
||||
var util = require("../lib/babel/util");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/babel/types");
|
||||
|
||||
@@ -4,14 +4,12 @@ transform.version = require("../../../package").version;
|
||||
|
||||
transform.transform = transform;
|
||||
|
||||
transform.run = function (code, opts) {
|
||||
opts ||= {};
|
||||
transform.run = function (code, opts = {}) {
|
||||
opts.sourceMap = "inline";
|
||||
return new Function(transform(code, opts).code)();
|
||||
};
|
||||
|
||||
transform.load = function (url, callback, opts, hold) {
|
||||
opts ||= {};
|
||||
transform.load = function (url, callback, opts = {}, hold) {
|
||||
opts.filename ||= url;
|
||||
|
||||
var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
|
||||
|
||||
@@ -1,32 +1,29 @@
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var transform = require("../transformation");
|
||||
var util = require("../util");
|
||||
var fs = require("fs");
|
||||
import isFunction from "lodash/lang/isFunction";
|
||||
import transform from "../transformation";
|
||||
import fs from "fs";
|
||||
|
||||
exports.version = require("../../../package").version;
|
||||
import * as util from "../util";
|
||||
export { util as _util };
|
||||
export { canCompile } from "../util";
|
||||
|
||||
exports.buildExternalHelpers = require("../build-external-helpers");
|
||||
export { default as acorn } from "acorn-babel";
|
||||
export { default as transform } from "../transformation";
|
||||
export { default as traverse } from "../traversal";
|
||||
export { default as buildExternalHelpers } from "../build-external-helpers";
|
||||
export { default as types } from "../types";
|
||||
export { version } from "../../../package";
|
||||
|
||||
exports.types = require("../types");
|
||||
export function register(opts) {
|
||||
var callback = require("./register/node");
|
||||
if (opts != null) callback(opts);
|
||||
return callback;
|
||||
}
|
||||
|
||||
exports.register = function (opts) {
|
||||
var register = require("./register/node");
|
||||
if (opts != null) register(opts);
|
||||
return register;
|
||||
};
|
||||
|
||||
exports.polyfill = function () {
|
||||
export function polyfill() {
|
||||
require("../polyfill");
|
||||
};
|
||||
}
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
|
||||
// do not use this - this is for use by official maintained babel plugins
|
||||
exports._util = util;
|
||||
|
||||
exports.transform = transform;
|
||||
|
||||
exports.transformFile = function (filename, opts, callback) {
|
||||
export function transformFile(filename, opts, callback) {
|
||||
if (isFunction(opts)) {
|
||||
callback = opts;
|
||||
opts = {};
|
||||
@@ -47,10 +44,9 @@ exports.transformFile = function (filename, opts, callback) {
|
||||
|
||||
callback(null, result);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.transformFileSync = function (filename, opts) {
|
||||
opts ||= {};
|
||||
export function transformFileSync(filename, opts = {}) {
|
||||
opts.filename = filename;
|
||||
return transform(fs.readFileSync(filename), opts);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// required to safely use babel/register within a browserify codebase
|
||||
|
||||
module.exports = function () {};
|
||||
export default function () {};
|
||||
|
||||
require("../../polyfill");
|
||||
import "../../polyfill";
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
var path = require("path");
|
||||
var os = require("os");
|
||||
var fs = require("fs");
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import fs from "fs";
|
||||
|
||||
var FILENAME = process.env.BABEL_CACHE_PATH || path.join(os.tmpdir(), "babel.json");
|
||||
var data = {};
|
||||
|
||||
exports.save = function () {
|
||||
export function save() {
|
||||
fs.writeFileSync(FILENAME, JSON.stringify(data, null, " "));
|
||||
};
|
||||
}
|
||||
|
||||
exports.load = function () {
|
||||
export function load() {
|
||||
if (process.env.BABEL_DISABLE_CACHE) return;
|
||||
|
||||
process.on("exit", exports.save);
|
||||
process.on("exit", save);
|
||||
|
||||
var sigint = function () {
|
||||
process.removeListener("SIGINT", sigint);
|
||||
exports.save();
|
||||
save();
|
||||
process.kill(process.pid, "SIGINT");
|
||||
};
|
||||
|
||||
@@ -29,8 +29,8 @@ exports.load = function () {
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.get = function () {
|
||||
export function get() {
|
||||
return data;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
require("../../polyfill");
|
||||
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var registerCache = require("./cache");
|
||||
var resolveRc = require("./resolve-rc");
|
||||
var extend = require("lodash/object/extend");
|
||||
var babel = require("../node");
|
||||
var each = require("lodash/collection/each");
|
||||
var util = require("../../util");
|
||||
var fs = require("fs");
|
||||
import "../../polyfill";
|
||||
import sourceMapSupport from "source-map-support";
|
||||
import * as registerCache from "./cache";
|
||||
import resolveRc from "./resolve-rc";
|
||||
import extend from "lodash/object/extend";
|
||||
import * as babel from "../node";
|
||||
import each from "lodash/collection/each";
|
||||
import * as util from "../../util";
|
||||
import fs from "fs";
|
||||
|
||||
sourceMapSupport.install({
|
||||
handleUncaughtExceptions: false,
|
||||
retrieveSourceMap(source) {
|
||||
var map = maps && maps[source];
|
||||
if (map) {
|
||||
@@ -33,7 +33,7 @@ var cache = registerCache.get();
|
||||
var transformOpts = {};
|
||||
var ignoreRegex = /node_modules/;
|
||||
var onlyRegex;
|
||||
var exts = {};
|
||||
var oldHandlers = {};
|
||||
var maps = {};
|
||||
|
||||
var mtime = function (filename) {
|
||||
@@ -105,7 +105,7 @@ var normalLoader = function (m, filename) {
|
||||
};
|
||||
|
||||
var registerExtension = function (ext) {
|
||||
var old = require.extensions[ext];
|
||||
var old = oldHandlers[ext] || oldHandlers[".js"];
|
||||
|
||||
var loader = normalLoader;
|
||||
if (process.env.running_under_istanbul) loader = istanbulLoader; // jshint ignore:line
|
||||
@@ -120,7 +120,7 @@ var registerExtension = function (ext) {
|
||||
};
|
||||
|
||||
var hookExtensions = function (_exts) {
|
||||
each(exts, function (old, ext) {
|
||||
each(oldHandlers, function (old, ext) {
|
||||
if (old === undefined) {
|
||||
delete require.extensions[ext];
|
||||
} else {
|
||||
@@ -128,20 +128,17 @@ var hookExtensions = function (_exts) {
|
||||
}
|
||||
});
|
||||
|
||||
exts = {};
|
||||
oldHandlers = {};
|
||||
|
||||
each(_exts, function (ext) {
|
||||
exts[ext] = require.extensions[ext];
|
||||
oldHandlers[ext] = require.extensions[ext];
|
||||
registerExtension(ext);
|
||||
});
|
||||
};
|
||||
|
||||
hookExtensions(util.canCompile.EXTENSIONS);
|
||||
|
||||
module.exports = function (opts) {
|
||||
// normalize options
|
||||
opts ||= {};
|
||||
|
||||
export default function (opts = {}) {
|
||||
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
||||
if (opts.ignore != null) ignoreRegex = util.regexify(opts.ignore);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var merge = require("lodash/object/merge");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
import merge from "lodash/object/merge";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
var cache = {};
|
||||
|
||||
@@ -10,9 +10,8 @@ function exists(filename) {
|
||||
return cache[filename] = fs.existsSync(filename);
|
||||
}
|
||||
|
||||
module.exports = function (loc, opts) {
|
||||
export default function (loc, opts = {}) {
|
||||
var rel = ".babelrc";
|
||||
opts ||= {};
|
||||
|
||||
function find(start, rel) {
|
||||
var file = path.join(start, rel);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var buildHelpers = require("./build-helpers");
|
||||
var generator = require("./generation");
|
||||
var util = require("./util");
|
||||
var t = require("./types");
|
||||
import buildHelpers from "./build-helpers";
|
||||
import generator from "./generation";
|
||||
import * as util from "./util";
|
||||
import t from "./types";
|
||||
|
||||
module.exports = function (whitelist) {
|
||||
export default function (whitelist) {
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
var body = [];
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var File = require("./transformation/file");
|
||||
var util = require("./util");
|
||||
var each = require("lodash/collection/each");
|
||||
var t = require("./types");
|
||||
import File from "./transformation/file";
|
||||
import * as util from "./util";
|
||||
import each from "lodash/collection/each";
|
||||
import t from "./types";
|
||||
|
||||
module.exports = function (body, namespace, whitelist = []) {
|
||||
export default function (body, namespace, whitelist = []) {
|
||||
each(File.helpers, function (name) {
|
||||
if (whitelist.length && whitelist.indexOf(name) == -1) return;
|
||||
if (whitelist.length && whitelist.indexOf(name) === -1) return;
|
||||
|
||||
var key = t.identifier(t.toIdentifier(name));
|
||||
body.push(t.expressionStatement(
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
module.exports = detect;
|
||||
import SYNTAX_KEYS from "./syntax-keys";
|
||||
import traverse from "../traversal";
|
||||
|
||||
var SYNTAX_KEYS = require("./syntax-keys");
|
||||
var traverse = require("../traversal");
|
||||
var visitors = traverse.explode(require("./visitors"));
|
||||
var visitors = traverse.explode(require("./visitors"));
|
||||
|
||||
function detect(ast) {
|
||||
export default function (ast) {
|
||||
var stats = {
|
||||
syntax: {},
|
||||
builtins: {}
|
||||
@@ -26,4 +25,4 @@ function detect(ast) {
|
||||
});
|
||||
|
||||
return stats;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
var t = require("../types");
|
||||
var includes = require("lodash/collection/includes");
|
||||
import includes from "lodash/collection/includes";
|
||||
import t from "../types";
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, detected) {
|
||||
export function AssignmentExpression(node, parent, detected) {
|
||||
if (node.operator === "**=") {
|
||||
detected("es6.exponentation");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.BinaryExpression = function (node, parent, detected) {
|
||||
export function BinaryExpression(node, parent, detected) {
|
||||
if (node.operator === "**") {
|
||||
detected("es6.exponentation");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, detected) {
|
||||
export function VariableDeclaration(node, parent, detected) {
|
||||
if (node.kind === "let" || node.kind === "const") {
|
||||
detected("es6.blockScoping");
|
||||
}
|
||||
@@ -21,9 +21,9 @@ exports.VariableDeclaration = function (node, parent, detected) {
|
||||
if (node.kind === "const") {
|
||||
detected("es6.constants");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.Property = function (node, parent, detected) {
|
||||
export function Property(node, parent, detected) {
|
||||
if (node.shorthand || node.method) {
|
||||
detected("es6.properties.shorthand");
|
||||
}
|
||||
@@ -35,13 +35,13 @@ exports.Property = function (node, parent, detected) {
|
||||
if (node.computed) {
|
||||
detected("es6.properties.computed");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.AssignmentPattern = function (node, parent, detected) {
|
||||
export function AssignmentPattern(node, parent, detected) {
|
||||
if (t.isFunction(parent) && includes(parent.params, node)) {
|
||||
detected("es6.parameters.default");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.Function = function (node, parent, detected) {
|
||||
if (node.generator) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var repeating = require("repeating");
|
||||
var trimRight = require("trim-right");
|
||||
var isBoolean = require("lodash/lang/isBoolean");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
import repeating from "repeating";
|
||||
import trimRight from "trim-right";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import includes from "lodash/collection/includes";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
|
||||
export default class Buffer {
|
||||
constructor(position, format) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
exports.File = function (node, print) {
|
||||
export function File(node, print) {
|
||||
print(node.program);
|
||||
};
|
||||
}
|
||||
|
||||
exports.Program = function (node, print) {
|
||||
export function Program(node, print) {
|
||||
print.sequence(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
exports.BlockStatement = function (node, print) {
|
||||
export function BlockStatement(node, print) {
|
||||
if (node.body.length === 0) {
|
||||
this.push("{}");
|
||||
} else {
|
||||
@@ -16,4 +16,4 @@ exports.BlockStatement = function (node, print) {
|
||||
this.removeLast("\n");
|
||||
this.rightBrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
exports.ClassExpression =
|
||||
exports.ClassDeclaration = function (node, print) {
|
||||
export function ClassDeclaration(node, print) {
|
||||
this.push("class");
|
||||
|
||||
if (node.id) {
|
||||
@@ -7,16 +6,26 @@ exports.ClassDeclaration = function (node, print) {
|
||||
print(node.id);
|
||||
}
|
||||
|
||||
print(node.typeParameters);
|
||||
|
||||
if (node.superClass) {
|
||||
this.push(" extends ");
|
||||
print(node.superClass);
|
||||
print(node.superTypeParameters);
|
||||
}
|
||||
|
||||
if (node.implements) {
|
||||
this.push(" implements ");
|
||||
print.join(node.implements, { separator: ", " });
|
||||
}
|
||||
|
||||
this.space();
|
||||
print(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
exports.ClassBody = function (node, print) {
|
||||
export { ClassDeclaration as ClassExpression };
|
||||
|
||||
export function ClassBody(node, print) {
|
||||
if (node.body.length === 0) {
|
||||
this.push("{}");
|
||||
} else {
|
||||
@@ -29,12 +38,12 @@ exports.ClassBody = function (node, print) {
|
||||
|
||||
this.rightBrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.MethodDefinition = function (node, print) {
|
||||
export function MethodDefinition(node, print) {
|
||||
if (node.static) {
|
||||
this.push("static ");
|
||||
}
|
||||
|
||||
this._method(node, print);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
exports.ComprehensionBlock = function (node, print) {
|
||||
export function ComprehensionBlock(node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
this.push(" of ");
|
||||
print(node.right);
|
||||
this.push(")");
|
||||
};
|
||||
}
|
||||
|
||||
exports.ComprehensionExpression = function (node, print) {
|
||||
export function ComprehensionExpression(node, print) {
|
||||
this.push(node.generator ? "(" : "[");
|
||||
|
||||
print.join(node.blocks, { separator: " " });
|
||||
@@ -24,4 +24,4 @@ exports.ComprehensionExpression = function (node, print) {
|
||||
print(node.body);
|
||||
|
||||
this.push(node.generator ? ")" : "]");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var isInteger = require("is-integer");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
var t = require("../../types");
|
||||
import isInteger from "is-integer";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import t from "../../types";
|
||||
|
||||
exports.UnaryExpression = function (node, print) {
|
||||
export function UnaryExpression(node, print) {
|
||||
var hasSpace = /[a-z]$/.test(node.operator);
|
||||
var arg = node.argument;
|
||||
|
||||
@@ -17,9 +17,9 @@ exports.UnaryExpression = function (node, print) {
|
||||
this.push(node.operator);
|
||||
if (hasSpace) this.push(" ");
|
||||
print(node.argument);
|
||||
};
|
||||
}
|
||||
|
||||
exports.UpdateExpression = function (node, print) {
|
||||
export function UpdateExpression(node, print) {
|
||||
if (node.prefix) {
|
||||
this.push(node.operator);
|
||||
print(node.argument);
|
||||
@@ -27,9 +27,9 @@ exports.UpdateExpression = function (node, print) {
|
||||
print(node.argument);
|
||||
this.push(node.operator);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.ConditionalExpression = function (node, print) {
|
||||
export function ConditionalExpression(node, print) {
|
||||
print(node.test);
|
||||
this.space();
|
||||
this.push("?");
|
||||
@@ -39,25 +39,25 @@ exports.ConditionalExpression = function (node, print) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.alternate);
|
||||
};
|
||||
}
|
||||
|
||||
exports.NewExpression = function (node, print) {
|
||||
export function NewExpression(node, print) {
|
||||
this.push("new ");
|
||||
print(node.callee);
|
||||
this.push("(");
|
||||
print.list(node.arguments);
|
||||
this.push(")");
|
||||
};
|
||||
}
|
||||
|
||||
exports.SequenceExpression = function (node, print) {
|
||||
export function SequenceExpression(node, print) {
|
||||
print.list(node.expressions);
|
||||
};
|
||||
}
|
||||
|
||||
exports.ThisExpression = function () {
|
||||
export function ThisExpression() {
|
||||
this.push("this");
|
||||
};
|
||||
}
|
||||
|
||||
exports.CallExpression = function (node, print) {
|
||||
export function CallExpression(node, print) {
|
||||
print(node.callee);
|
||||
|
||||
this.push("(");
|
||||
@@ -80,7 +80,7 @@ exports.CallExpression = function (node, print) {
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
};
|
||||
}
|
||||
|
||||
var buildYieldAwait = function (keyword) {
|
||||
return function (node, print) {
|
||||
@@ -97,17 +97,17 @@ var buildYieldAwait = function (keyword) {
|
||||
};
|
||||
};
|
||||
|
||||
exports.YieldExpression = buildYieldAwait("yield");
|
||||
exports.AwaitExpression = buildYieldAwait("await");
|
||||
export var YieldExpression = buildYieldAwait("yield");
|
||||
export var AwaitExpression = buildYieldAwait("await");
|
||||
|
||||
exports.EmptyStatement = function () {
|
||||
export function EmptyStatement() {
|
||||
this.semicolon();
|
||||
};
|
||||
}
|
||||
|
||||
exports.ExpressionStatement = function (node, print) {
|
||||
export function ExpressionStatement(node, print) {
|
||||
print(node.expression);
|
||||
this.semicolon();
|
||||
};
|
||||
}
|
||||
|
||||
exports.BinaryExpression =
|
||||
exports.LogicalExpression =
|
||||
@@ -123,7 +123,7 @@ exports.AssignmentExpression = function (node, print) {
|
||||
|
||||
var SCIENTIFIC_NOTATION = /e/i;
|
||||
|
||||
exports.MemberExpression = function (node, print) {
|
||||
export function MemberExpression(node, print) {
|
||||
var obj = node.object;
|
||||
print(obj);
|
||||
|
||||
@@ -149,4 +149,4 @@ exports.MemberExpression = function (node, print) {
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,34 +1,226 @@
|
||||
exports.AnyTypeAnnotation =
|
||||
exports.ArrayTypeAnnotation =
|
||||
exports.BooleanTypeAnnotation =
|
||||
exports.ClassProperty =
|
||||
exports.DeclareClass =
|
||||
exports.DeclareFunction =
|
||||
exports.DeclareModule =
|
||||
exports.DeclareVariable =
|
||||
exports.FunctionTypeAnnotation =
|
||||
exports.FunctionTypeParam =
|
||||
exports.GenericTypeAnnotation =
|
||||
exports.InterfaceExtends =
|
||||
exports.InterfaceDeclaration =
|
||||
exports.IntersectionTypeAnnotation =
|
||||
exports.NullableTypeAnnotation =
|
||||
exports.NumberTypeAnnotation =
|
||||
exports.StringLiteralTypeAnnotation =
|
||||
exports.StringTypeAnnotation =
|
||||
exports.TupleTypeAnnotation =
|
||||
exports.TypeofTypeAnnotation =
|
||||
exports.TypeAlias =
|
||||
exports.TypeAnnotation =
|
||||
exports.TypeParameterDeclaration =
|
||||
exports.TypeParameterInstantiation =
|
||||
exports.ObjectTypeAnnotation =
|
||||
exports.ObjectTypeCallProperty =
|
||||
exports.ObjectTypeIndexer =
|
||||
exports.ObjectTypeProperty =
|
||||
exports.QualifiedTypeIdentifier =
|
||||
exports.UnionTypeAnnotation =
|
||||
exports.TypeCastExpression =
|
||||
exports.VoidTypeAnnotation = function () {
|
||||
// todo: implement these once we have a `--keep-types` option
|
||||
};
|
||||
import t from "../../types";
|
||||
|
||||
export function AnyTypeAnnotation() {
|
||||
this.push("any");
|
||||
}
|
||||
|
||||
export function ArrayTypeAnnotation(node, print) {
|
||||
print(node.elementType);
|
||||
this.push("[");
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
export function BooleanTypeAnnotation(node) {
|
||||
this.push("bool");
|
||||
}
|
||||
|
||||
export function ClassProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.key);
|
||||
print(node.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function DeclareClass(node, print) {
|
||||
this.push("declare class ");
|
||||
this._interfaceish(node, print);
|
||||
}
|
||||
|
||||
export function DeclareFunction(node, print) {
|
||||
this.push("declare function ");
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function DeclareModule(node, print) {
|
||||
this.push("declare module ");
|
||||
print(node.id);
|
||||
this.space();
|
||||
print(node.body);
|
||||
}
|
||||
|
||||
export function DeclareVariable(node, print) {
|
||||
this.push("declare var ");
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function FunctionTypeAnnotation(node, print, parent) {
|
||||
print(node.typeParameters);
|
||||
this.push("(");
|
||||
print.list(node.params);
|
||||
|
||||
if (node.rest) {
|
||||
if (node.params.length) {
|
||||
this.push(",");
|
||||
this.space();
|
||||
}
|
||||
this.push("...");
|
||||
print(node.rest);
|
||||
}
|
||||
|
||||
this.push(")");
|
||||
|
||||
// this node type is overloaded, not sure why but it makes it EXTREMELY annoying
|
||||
if (parent.type === "ObjectTypeProperty" || parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction") {
|
||||
this.push(":");
|
||||
} else {
|
||||
this.space();
|
||||
this.push("=>");
|
||||
}
|
||||
|
||||
this.space();
|
||||
print(node.returnType);
|
||||
}
|
||||
|
||||
export function FunctionTypeParam(node, print) {
|
||||
print(node.name);
|
||||
if (node.optional) this.push("?");
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function InterfaceExtends(node, print) {
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
}
|
||||
|
||||
export { InterfaceExtends as ClassImplements, InterfaceExtends as GenericTypeAnnotation };
|
||||
|
||||
export function _interfaceish(node, print) {
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
if (node.extends.length) {
|
||||
this.push(" extends ");
|
||||
print.join(node.extends, { separator: ", " });
|
||||
}
|
||||
this.space();
|
||||
print(node.body);
|
||||
}
|
||||
|
||||
export function InterfaceDeclaration(node, print) {
|
||||
this.push("interface ");
|
||||
this._interfaceish(node, print);
|
||||
}
|
||||
|
||||
export function IntersectionTypeAnnotation(node, print) {
|
||||
print.join(node.types, { separator: " & " });
|
||||
}
|
||||
|
||||
export function NullableTypeAnnotation(node, print) {
|
||||
this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function NumberTypeAnnotation() {
|
||||
this.push("number");
|
||||
}
|
||||
|
||||
export function StringLiteralTypeAnnotation(node) {
|
||||
this._stringLiteral(node.value);
|
||||
}
|
||||
|
||||
export function StringTypeAnnotation() {
|
||||
this.push("string");
|
||||
}
|
||||
|
||||
export function TupleTypeAnnotation(node, print) {
|
||||
this.push("[");
|
||||
print.join(node.types, { separator: ", " });
|
||||
this.push("]");
|
||||
}
|
||||
|
||||
export function TypeofTypeAnnotation(node, print) {
|
||||
this.push("typeof ");
|
||||
print(node.argument);
|
||||
}
|
||||
|
||||
export function TypeAlias(node, print) {
|
||||
this.push("type ");
|
||||
print(node.id);
|
||||
print(node.typeParameters);
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
print(node.right);
|
||||
this.semicolon();
|
||||
}
|
||||
|
||||
export function TypeAnnotation(node, print) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
if (node.optional) this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
|
||||
export function TypeParameterInstantiation(node, print) {
|
||||
this.push("<");
|
||||
print.join(node.params, { separator: ", " });
|
||||
this.push(">");
|
||||
}
|
||||
|
||||
export { TypeParameterInstantiation as TypeParameterDeclaration };
|
||||
|
||||
export function ObjectTypeAnnotation(node, print) {
|
||||
this.push("{");
|
||||
var props = node.properties.concat(node.callProperties, node.indexers);
|
||||
if (props.length) {
|
||||
this.space();
|
||||
print.list(props, { indent: true, separator: "; " });
|
||||
this.space();
|
||||
}
|
||||
this.push("}");
|
||||
}
|
||||
|
||||
export function ObjectTypeCallProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.value);
|
||||
}
|
||||
|
||||
export function ObjectTypeIndexer(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
this.push("[");
|
||||
print(node.id);
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.key);
|
||||
this.push("]");
|
||||
this.push(":");
|
||||
this.space();
|
||||
print(node.value);
|
||||
}
|
||||
|
||||
export function ObjectTypeProperty(node, print) {
|
||||
if (node.static) this.push("static ");
|
||||
print(node.key);
|
||||
if (node.optional) this.push("?");
|
||||
if (!t.isFunctionTypeAnnotation(node.value)) {
|
||||
this.push(":");
|
||||
this.space();
|
||||
}
|
||||
print(node.value);
|
||||
}
|
||||
|
||||
export function QualifiedTypeIdentifier(node, print) {
|
||||
print(node.qualification);
|
||||
this.push(".");
|
||||
print(node.id);
|
||||
}
|
||||
|
||||
export function UnionTypeAnnotation(node, print) {
|
||||
print.join(node.types, { separator: " | " });
|
||||
}
|
||||
|
||||
export function TypeCastExpression(node, print) {
|
||||
this.push("(");
|
||||
print(node.expression);
|
||||
print(node.typeAnnotation);
|
||||
this.push(")");
|
||||
}
|
||||
|
||||
export function VoidTypeAnnotation(node) {
|
||||
this.push("void");
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
import each from "lodash/collection/each";
|
||||
import t from "../../types";
|
||||
|
||||
exports.JSXAttribute = function (node, print) {
|
||||
export function JSXAttribute(node, print) {
|
||||
print(node.name);
|
||||
if (node.value) {
|
||||
this.push("=");
|
||||
print(node.value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXIdentifier = function (node) {
|
||||
export function JSXIdentifier(node) {
|
||||
this.push(node.name);
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXNamespacedName = function (node, print) {
|
||||
export function JSXNamespacedName(node, print) {
|
||||
print(node.namespace);
|
||||
this.push(":");
|
||||
print(node.name);
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXMemberExpression = function (node, print) {
|
||||
export function JSXMemberExpression(node, print) {
|
||||
print(node.object);
|
||||
this.push(".");
|
||||
print(node.property);
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXSpreadAttribute = function (node, print) {
|
||||
export function JSXSpreadAttribute(node, print) {
|
||||
this.push("{...");
|
||||
print(node.argument);
|
||||
this.push("}");
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXExpressionContainer = function (node, print) {
|
||||
export function JSXExpressionContainer(node, print) {
|
||||
this.push("{");
|
||||
print(node.expression);
|
||||
this.push("}");
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXElement = function (node, print) {
|
||||
export function JSXElement(node, print) {
|
||||
var open = node.openingElement;
|
||||
print(open);
|
||||
if (open.selfClosing) return;
|
||||
@@ -53,9 +53,9 @@ exports.JSXElement = function (node, print) {
|
||||
this.dedent();
|
||||
|
||||
print(node.closingElement);
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXOpeningElement = function (node, print) {
|
||||
export function JSXOpeningElement(node, print) {
|
||||
this.push("<");
|
||||
print(node.name);
|
||||
if (node.attributes.length > 0) {
|
||||
@@ -63,12 +63,12 @@ exports.JSXOpeningElement = function (node, print) {
|
||||
print.join(node.attributes, { separator: " " });
|
||||
}
|
||||
this.push(node.selfClosing ? " />" : ">");
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXClosingElement = function (node, print) {
|
||||
export function JSXClosingElement(node, print) {
|
||||
this.push("</");
|
||||
print(node.name);
|
||||
this.push(">");
|
||||
};
|
||||
}
|
||||
|
||||
exports.JSXEmptyExpression = function () {};
|
||||
export function JSXEmptyExpression() {}
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
exports._params = function (node, print) {
|
||||
export function _params(node, print) {
|
||||
print(node.typeParameters);
|
||||
this.push("(");
|
||||
print.list(node.params);
|
||||
print.list(node.params, {
|
||||
iterator: (node) =>{
|
||||
if (node.optional) this.push("?");
|
||||
print(node.typeAnnotation);
|
||||
}
|
||||
});
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
exports._method = function (node, print) {
|
||||
if (node.returnType) {
|
||||
print(node.returnType);
|
||||
}
|
||||
}
|
||||
|
||||
export function _method(node, print) {
|
||||
var value = node.value;
|
||||
var kind = node.kind;
|
||||
var key = node.key;
|
||||
@@ -32,7 +42,7 @@ exports._method = function (node, print) {
|
||||
this._params(value, print);
|
||||
this.push(" ");
|
||||
print(value.body);
|
||||
};
|
||||
}
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, print) {
|
||||
@@ -52,7 +62,7 @@ exports.FunctionExpression = function (node, print) {
|
||||
print(node.body);
|
||||
};
|
||||
|
||||
exports.ArrowFunctionExpression = function (node, print) {
|
||||
export function ArrowFunctionExpression(node, print) {
|
||||
if (node.async) this.push("async ");
|
||||
|
||||
if (node.params.length === 1 && t.isIdentifier(node.params[0])) {
|
||||
@@ -63,4 +73,4 @@ exports.ArrowFunctionExpression = function (node, print) {
|
||||
|
||||
this.push(" => ");
|
||||
print(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
import each from "lodash/collection/each";
|
||||
import t from "../../types";
|
||||
|
||||
exports.ImportSpecifier = function (node, print) {
|
||||
export function ImportSpecifier(node, print) {
|
||||
if (t.isSpecifierDefault(node)) {
|
||||
print(t.getSpecifierName(node));
|
||||
} else {
|
||||
return exports.ExportSpecifier.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.ExportSpecifier = function (node, print) {
|
||||
export function ExportSpecifier(node, print) {
|
||||
print(node.id);
|
||||
if (node.name) {
|
||||
this.push(" as ");
|
||||
print(node.name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.ExportBatchSpecifier = function () {
|
||||
export function ExportBatchSpecifier() {
|
||||
this.push("*");
|
||||
};
|
||||
}
|
||||
|
||||
exports.ExportDeclaration = function (node, print) {
|
||||
export function ExportDeclaration(node, print) {
|
||||
this.push("export ");
|
||||
|
||||
var specifiers = node.specifiers;
|
||||
@@ -53,9 +53,9 @@ exports.ExportDeclaration = function (node, print) {
|
||||
}
|
||||
|
||||
this.ensureSemicolon();
|
||||
};
|
||||
}
|
||||
|
||||
exports.ImportDeclaration = function (node, print) {
|
||||
export function ImportDeclaration(node, print) {
|
||||
this.push("import ");
|
||||
|
||||
if (node.isType) {
|
||||
@@ -90,9 +90,9 @@ exports.ImportDeclaration = function (node, print) {
|
||||
|
||||
print(node.source);
|
||||
this.semicolon();
|
||||
};
|
||||
}
|
||||
|
||||
exports.ImportBatchSpecifier = function (node, print) {
|
||||
export function ImportBatchSpecifier(node, print) {
|
||||
this.push("* as ");
|
||||
print(node.name);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var each = require("lodash/collection/each");
|
||||
import each from "lodash/collection/each";
|
||||
|
||||
each(["BindMemberExpression", "BindFunctionExpression"], function (type) {
|
||||
exports[type] = function () {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
var repeating = require("repeating");
|
||||
var t = require("../../types");
|
||||
import repeating from "repeating";
|
||||
import t from "../../types";
|
||||
|
||||
exports.WithStatement = function (node, print) {
|
||||
export function WithStatement(node, print) {
|
||||
this.keyword("with");
|
||||
this.push("(");
|
||||
print(node.object);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
exports.IfStatement = function (node, print) {
|
||||
export function IfStatement(node, print) {
|
||||
this.keyword("if");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
@@ -23,9 +23,9 @@ exports.IfStatement = function (node, print) {
|
||||
this.push("else ");
|
||||
print.indentOnComments(node.alternate);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.ForStatement = function (node, print) {
|
||||
export function ForStatement(node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
|
||||
@@ -45,15 +45,15 @@ exports.ForStatement = function (node, print) {
|
||||
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
exports.WhileStatement = function (node, print) {
|
||||
export function WhileStatement(node, print) {
|
||||
this.keyword("while");
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
var buildForXStatement = function (op) {
|
||||
return function (node, print) {
|
||||
@@ -67,10 +67,10 @@ var buildForXStatement = function (op) {
|
||||
};
|
||||
};
|
||||
|
||||
exports.ForInStatement = buildForXStatement("in");
|
||||
exports.ForOfStatement = buildForXStatement("of");
|
||||
export var ForInStatement = buildForXStatement("in");
|
||||
export var ForOfStatement = buildForXStatement("of");
|
||||
|
||||
exports.DoWhileStatement = function (node, print) {
|
||||
export function DoWhileStatement(node, print) {
|
||||
this.keyword("do");
|
||||
print(node.body);
|
||||
this.space();
|
||||
@@ -78,7 +78,7 @@ exports.DoWhileStatement = function (node, print) {
|
||||
this.push("(");
|
||||
print(node.test);
|
||||
this.push(");");
|
||||
};
|
||||
}
|
||||
|
||||
var buildLabelStatement = function (prefix, key) {
|
||||
return function (node, print) {
|
||||
@@ -94,17 +94,17 @@ var buildLabelStatement = function (prefix, key) {
|
||||
};
|
||||
};
|
||||
|
||||
exports.ContinueStatement = buildLabelStatement("continue");
|
||||
exports.ReturnStatement = buildLabelStatement("return", "argument");
|
||||
exports.BreakStatement = buildLabelStatement("break");
|
||||
export var ContinueStatement = buildLabelStatement("continue");
|
||||
export var ReturnStatement = buildLabelStatement("return", "argument");
|
||||
export var BreakStatement = buildLabelStatement("break");
|
||||
|
||||
exports.LabeledStatement = function (node, print) {
|
||||
export function LabeledStatement(node, print) {
|
||||
print(node.label);
|
||||
this.push(": ");
|
||||
print(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
exports.TryStatement = function (node, print) {
|
||||
export function TryStatement(node, print) {
|
||||
this.keyword("try");
|
||||
print(node.block);
|
||||
this.space();
|
||||
@@ -123,23 +123,23 @@ exports.TryStatement = function (node, print) {
|
||||
this.push("finally ");
|
||||
print(node.finalizer);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.CatchClause = function (node, print) {
|
||||
export function CatchClause(node, print) {
|
||||
this.keyword("catch");
|
||||
this.push("(");
|
||||
print(node.param);
|
||||
this.push(") ");
|
||||
print(node.body);
|
||||
};
|
||||
}
|
||||
|
||||
exports.ThrowStatement = function (node, print) {
|
||||
export function ThrowStatement(node, print) {
|
||||
this.push("throw ");
|
||||
print(node.argument);
|
||||
this.semicolon();
|
||||
};
|
||||
}
|
||||
|
||||
exports.SwitchStatement = function (node, print) {
|
||||
export function SwitchStatement(node, print) {
|
||||
this.keyword("switch");
|
||||
this.push("(");
|
||||
print(node.discriminant);
|
||||
@@ -155,9 +155,9 @@ exports.SwitchStatement = function (node, print) {
|
||||
});
|
||||
|
||||
this.push("}");
|
||||
};
|
||||
}
|
||||
|
||||
exports.SwitchCase = function (node, print) {
|
||||
export function SwitchCase(node, print) {
|
||||
if (node.test) {
|
||||
this.push("case ");
|
||||
print(node.test);
|
||||
@@ -170,13 +170,13 @@ exports.SwitchCase = function (node, print) {
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.DebuggerStatement = function () {
|
||||
export function DebuggerStatement() {
|
||||
this.push("debugger;");
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node, print, parent) {
|
||||
export function VariableDeclaration(node, print, parent) {
|
||||
this.push(node.kind + " ");
|
||||
|
||||
var hasInits = false;
|
||||
@@ -202,22 +202,21 @@ exports.VariableDeclaration = function (node, print, parent) {
|
||||
if (!t.isFor(parent)) {
|
||||
this.semicolon();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.PrivateDeclaration = function (node, print) {
|
||||
export function PrivateDeclaration(node, print) {
|
||||
this.push("private ");
|
||||
print.join(node.declarations, { separator: ", " });
|
||||
this.semicolon();
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclarator = function (node, print) {
|
||||
export function VariableDeclarator(node, print) {
|
||||
print(node.id);
|
||||
print(node.id.typeAnnotation);
|
||||
if (node.init) {
|
||||
print(node.id);
|
||||
this.space();
|
||||
this.push("=");
|
||||
this.space();
|
||||
print(node.init);
|
||||
} else {
|
||||
print(node.id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
var each = require("lodash/collection/each");
|
||||
import each from "lodash/collection/each";
|
||||
|
||||
exports.TaggedTemplateExpression = function (node, print) {
|
||||
export function TaggedTemplateExpression(node, print) {
|
||||
print(node.tag);
|
||||
print(node.quasi);
|
||||
};
|
||||
}
|
||||
|
||||
exports.TemplateElement = function (node) {
|
||||
export function TemplateElement(node) {
|
||||
this._push(node.value.raw);
|
||||
};
|
||||
}
|
||||
|
||||
exports.TemplateLiteral = function (node, print) {
|
||||
export function TemplateLiteral(node, print) {
|
||||
this.push("`");
|
||||
|
||||
var quasis = node.quasis;
|
||||
@@ -26,4 +26,4 @@ exports.TemplateLiteral = function (node, print) {
|
||||
});
|
||||
|
||||
this._push("`");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var each = require("lodash/collection/each");
|
||||
import each from "lodash/collection/each";
|
||||
|
||||
exports.Identifier = function (node) {
|
||||
export function Identifier(node) {
|
||||
this.push(node.name);
|
||||
};
|
||||
}
|
||||
|
||||
exports.RestElement =
|
||||
exports.SpreadElement =
|
||||
@@ -11,11 +11,11 @@ exports.SpreadProperty = function (node, print) {
|
||||
print(node.argument);
|
||||
};
|
||||
|
||||
exports.VirtualPropertyExpression = function (node, print) {
|
||||
export function VirtualPropertyExpression(node, print) {
|
||||
print(node.object);
|
||||
this.push("::");
|
||||
print(node.property);
|
||||
};
|
||||
}
|
||||
|
||||
exports.ObjectExpression =
|
||||
exports.ObjectPattern = function (node, print) {
|
||||
@@ -34,7 +34,7 @@ exports.ObjectPattern = function (node, print) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Property = function (node, print) {
|
||||
export function Property(node, print) {
|
||||
if (node.method || node.kind === "get" || node.kind === "set") {
|
||||
this._method(node, print);
|
||||
} else {
|
||||
@@ -51,7 +51,7 @@ exports.Property = function (node, print) {
|
||||
this.space();
|
||||
print(node.value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.ArrayExpression =
|
||||
exports.ArrayPattern = function (node, print) {
|
||||
@@ -78,19 +78,12 @@ exports.ArrayPattern = function (node, print) {
|
||||
this.push("]");
|
||||
};
|
||||
|
||||
exports.Literal = function (node) {
|
||||
export function Literal(node) {
|
||||
var val = node.value;
|
||||
var type = typeof val;
|
||||
|
||||
if (type === "string") {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
// escape illegal js but valid json unicode characters
|
||||
val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) {
|
||||
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
this._stringLiteral(val);
|
||||
} else if (type === "number") {
|
||||
this.push(val + "");
|
||||
} else if (type === "boolean") {
|
||||
@@ -100,4 +93,15 @@ exports.Literal = function (node) {
|
||||
} else if (val === null) {
|
||||
this.push("null");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function _stringLiteral(val) {
|
||||
val = JSON.stringify(val);
|
||||
|
||||
// escape illegal js but valid json unicode characters
|
||||
val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) {
|
||||
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
|
||||
this.push(val);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
var detectIndent = require("detect-indent");
|
||||
var Whitespace = require("./whitespace");
|
||||
var repeating = require("repeating");
|
||||
var SourceMap = require("./source-map");
|
||||
var Position = require("./position");
|
||||
var messages = require("../messages");
|
||||
var Buffer = require("./buffer");
|
||||
var extend = require("lodash/object/extend");
|
||||
var each = require("lodash/collection/each");
|
||||
var n = require("./node");
|
||||
var t = require("../types");
|
||||
import detectIndent from "detect-indent";
|
||||
import Whitespace from "./whitespace";
|
||||
import repeating from "repeating";
|
||||
import SourceMap from "./source-map";
|
||||
import Position from "./position";
|
||||
import * as messages from "../messages";
|
||||
import Buffer from "./buffer";
|
||||
import extend from "lodash/object/extend";
|
||||
import each from "lodash/collection/each";
|
||||
import n from "./node";
|
||||
import t from "../types";
|
||||
|
||||
class CodeGenerator {
|
||||
constructor(ast, opts, code) {
|
||||
@@ -91,8 +91,7 @@ class CodeGenerator {
|
||||
return this.print(node, parent, opts);
|
||||
};
|
||||
|
||||
print.sequence = (nodes, opts) => {
|
||||
opts ||= {};
|
||||
print.sequence = (nodes, opts = {}) => {
|
||||
opts.statement = true;
|
||||
return this.printJoin(print, nodes, opts);
|
||||
};
|
||||
@@ -101,8 +100,7 @@ class CodeGenerator {
|
||||
return this.printJoin(print, nodes, opts);
|
||||
};
|
||||
|
||||
print.list = function (items, opts) {
|
||||
opts ||= {};
|
||||
print.list = function (items, opts = {}) {
|
||||
opts.separator ||= ", ";
|
||||
print.join(items, opts);
|
||||
};
|
||||
@@ -118,8 +116,8 @@ class CodeGenerator {
|
||||
return print;
|
||||
}
|
||||
|
||||
print(node, parent, opts) {
|
||||
if (!node) return "";
|
||||
print(node, parent, opts = {}) {
|
||||
if (!node) return;
|
||||
|
||||
if (parent && parent._compact) {
|
||||
node._compact = true;
|
||||
@@ -130,8 +128,6 @@ class CodeGenerator {
|
||||
this.format.concise = true;
|
||||
}
|
||||
|
||||
opts ||= {};
|
||||
|
||||
var newline = (leading) => {
|
||||
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
|
||||
return;
|
||||
@@ -197,11 +193,9 @@ class CodeGenerator {
|
||||
this.format.concise = oldConcise;
|
||||
}
|
||||
|
||||
printJoin(print, nodes, opts) {
|
||||
printJoin(print, nodes, opts = {}) {
|
||||
if (!nodes || !nodes.length) return;
|
||||
|
||||
opts ||= {};
|
||||
|
||||
var len = nodes.length;
|
||||
|
||||
if (opts.indent) this.indent();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var whitespace = require("./whitespace");
|
||||
var parens = require("./parentheses");
|
||||
var each = require("lodash/collection/each");
|
||||
var some = require("lodash/collection/some");
|
||||
var t = require("../../types");
|
||||
import whitespace from "./whitespace";
|
||||
import * as parens from "./parentheses";
|
||||
import each from "lodash/collection/each";
|
||||
import some from "lodash/collection/some";
|
||||
import t from "../../types";
|
||||
|
||||
var find = function (obj, node, parent) {
|
||||
if (!obj) return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
import each from "lodash/collection/each";
|
||||
import t from "../../types";
|
||||
|
||||
var PRECEDENCE = {};
|
||||
|
||||
@@ -21,14 +21,20 @@ each([
|
||||
});
|
||||
});
|
||||
|
||||
exports.UpdateExpression = function (node, parent) {
|
||||
export function NullableTypeAnnotation(node, parent) {
|
||||
return t.isArrayTypeAnnotation(parent);
|
||||
}
|
||||
|
||||
export { NullableTypeAnnotation as FunctionTypeAnnotation };
|
||||
|
||||
export function UpdateExpression(node, parent) {
|
||||
if (t.isMemberExpression(parent) && parent.object === node) {
|
||||
// (foo++).test()
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.ObjectExpression = function (node, parent) {
|
||||
export function ObjectExpression(node, parent) {
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
// ({ foo: "bar" });
|
||||
return true;
|
||||
@@ -40,9 +46,9 @@ exports.ObjectExpression = function (node, parent) {
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
exports.Binary = function (node, parent) {
|
||||
export function Binary(node, parent) {
|
||||
if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node) {
|
||||
return true;
|
||||
}
|
||||
@@ -70,9 +76,9 @@ exports.Binary = function (node, parent) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.BinaryExpression = function (node, parent) {
|
||||
export function BinaryExpression(node, parent) {
|
||||
if (node.operator === "in") {
|
||||
// var i = (1 in []);
|
||||
if (t.isVariableDeclarator(parent)) {
|
||||
@@ -84,9 +90,9 @@ exports.BinaryExpression = function (node, parent) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.SequenceExpression = function (node, parent) {
|
||||
export function SequenceExpression(node, parent) {
|
||||
if (t.isForStatement(parent)) {
|
||||
// Although parentheses wouldn't hurt around sequence
|
||||
// expressions in the head of for loops, traditional style
|
||||
@@ -102,9 +108,9 @@ exports.SequenceExpression = function (node, parent) {
|
||||
// Otherwise err on the side of overparenthesization, adding
|
||||
// explicit exceptions above if this proves overzealous.
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
exports.YieldExpression = function (node, parent) {
|
||||
export function YieldExpression(node, parent) {
|
||||
return t.isBinary(parent) ||
|
||||
t.isUnaryLike(parent) ||
|
||||
t.isCallExpression(parent) ||
|
||||
@@ -112,17 +118,17 @@ exports.YieldExpression = function (node, parent) {
|
||||
t.isNewExpression(parent) ||
|
||||
t.isConditionalExpression(parent) ||
|
||||
t.isYieldExpression(parent);
|
||||
};
|
||||
}
|
||||
|
||||
exports.ClassExpression = function (node, parent) {
|
||||
export function ClassExpression(node, parent) {
|
||||
return t.isExpressionStatement(parent);
|
||||
};
|
||||
}
|
||||
|
||||
exports.UnaryLike = function (node, parent) {
|
||||
export function UnaryLike(node, parent) {
|
||||
return t.isMemberExpression(parent) && parent.object === node;
|
||||
};
|
||||
}
|
||||
|
||||
exports.FunctionExpression = function (node, parent) {
|
||||
export function FunctionExpression(node, parent) {
|
||||
// function () {};
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
return true;
|
||||
@@ -137,10 +143,9 @@ exports.FunctionExpression = function (node, parent) {
|
||||
if (t.isCallExpression(parent) && parent.callee === node) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.AssignmentExpression =
|
||||
exports.ConditionalExpression = function (node, parent) {
|
||||
export function ConditionalExpression(node, parent) {
|
||||
if (t.isUnaryLike(parent)) {
|
||||
return true;
|
||||
}
|
||||
@@ -164,4 +169,6 @@ exports.ConditionalExpression = function (node, parent) {
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
export { ConditionalExpression as AssignmentExpression };
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
var isBoolean = require("lodash/lang/isBoolean");
|
||||
var each = require("lodash/collection/each");
|
||||
var map = require("lodash/collection/map");
|
||||
var t = require("../../types");
|
||||
|
||||
var crawl = function (node, state) {
|
||||
state ||= {};
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import each from "lodash/collection/each";
|
||||
import map from "lodash/collection/map";
|
||||
import t from "../../types";
|
||||
|
||||
function crawl(node, state = {}) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
crawl(node.object, state);
|
||||
if (node.computed) crawl(node.property, state);
|
||||
@@ -22,9 +20,9 @@ var crawl = function (node, state) {
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
}
|
||||
|
||||
var isHelper = function (node) {
|
||||
function isHelper(node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
return isHelper(node.object) || isHelper(node.property);
|
||||
} else if (t.isIdentifier(node)) {
|
||||
@@ -36,12 +34,12 @@ var isHelper = function (node) {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var isType = function (node) {
|
||||
function isType(node) {
|
||||
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) ||
|
||||
t.isIdentifier(node) || t.isMemberExpression(node);
|
||||
};
|
||||
}
|
||||
|
||||
exports.nodes = {
|
||||
AssignmentExpression(node) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var sourceMap = require("source-map");
|
||||
var t = require("../types");
|
||||
import sourceMap from "source-map";
|
||||
import t from "../types";
|
||||
|
||||
export default class SourceMap {
|
||||
constructor(position, opts, code) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var sortBy = require("lodash/collection/sortBy");
|
||||
import sortBy from "lodash/collection/sortBy";
|
||||
|
||||
/**
|
||||
* Returns `i`th number from `base`, continuing from 0 when `max` is reached.
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
var lineNumbers = require("line-numbers");
|
||||
var repeating = require("repeating");
|
||||
var jsTokens = require("js-tokens");
|
||||
var esutils = require("esutils");
|
||||
var chalk = require("chalk");
|
||||
var ary = require("lodash/function/ary");
|
||||
import lineNumbers from "line-numbers";
|
||||
import repeating from "repeating";
|
||||
import jsTokens from "js-tokens";
|
||||
import esutils from "esutils";
|
||||
import chalk from "chalk";
|
||||
import ary from "lodash/function/ary";
|
||||
|
||||
var defs = {
|
||||
string: chalk.red,
|
||||
punctuation: chalk.white.bold,
|
||||
operator: chalk.white.bold,
|
||||
curly: chalk.green,
|
||||
parens: chalk.blue.bold,
|
||||
square: chalk.yellow,
|
||||
name: chalk.white,
|
||||
keyword: chalk.cyan,
|
||||
number: chalk.magenta,
|
||||
regex: chalk.magenta,
|
||||
comment: chalk.grey,
|
||||
invalid: chalk.inverse
|
||||
string: chalk.red,
|
||||
punctuator: chalk.white.bold,
|
||||
curly: chalk.green,
|
||||
parens: chalk.blue.bold,
|
||||
square: chalk.yellow,
|
||||
name: chalk.white,
|
||||
keyword: chalk.cyan,
|
||||
number: chalk.magenta,
|
||||
regex: chalk.magenta,
|
||||
comment: chalk.grey,
|
||||
invalid: chalk.inverse
|
||||
};
|
||||
|
||||
var newline = /\r\n|[\n\r\u2028\u2029]/;
|
||||
@@ -25,11 +24,11 @@ var newline = /\r\n|[\n\r\u2028\u2029]/;
|
||||
var highlight = function (text) {
|
||||
var tokenType = function (match) {
|
||||
var token = jsTokens.matchToToken(match);
|
||||
if (token.type === "name" && esutils.keyword.isKeywordES6(token.value)) {
|
||||
if (token.type === "name" && esutils.keyword.isReservedWordES6(token.value)) {
|
||||
return "keyword";
|
||||
}
|
||||
|
||||
if (token.type === "punctuation") {
|
||||
if (token.type === "punctuator") {
|
||||
switch (token.value) {
|
||||
case "{":
|
||||
case "}":
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../types");
|
||||
import t from "../types";
|
||||
|
||||
module.exports = function (ast, comments, tokens) {
|
||||
if (ast && ast.type === "Program") {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var normalizeAst = require("./normalize-ast");
|
||||
var estraverse = require("estraverse");
|
||||
var codeFrame = require("./code-frame");
|
||||
var acorn = require("acorn-babel");
|
||||
import normalizeAst from "./normalize-ast";
|
||||
import estraverse from "estraverse";
|
||||
import codeFrame from "./code-frame";
|
||||
import acorn from "acorn-babel";
|
||||
|
||||
module.exports = function (opts, code, callback) {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var util = require("util");
|
||||
import * as util from "util";
|
||||
|
||||
exports.messages = {
|
||||
export var messages = {
|
||||
tailCallReassignmentDeopt: "Function reference has been reassigned so it's probably be dereferenced so we can't optimise this with confidence",
|
||||
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.",
|
||||
classesIllegalBareSuper: "Illegal use of bare super",
|
||||
@@ -21,7 +21,7 @@ exports.messages = {
|
||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2."
|
||||
};
|
||||
|
||||
exports.get = function (key) {
|
||||
export function get(key) {
|
||||
var msg = exports.messages[key];
|
||||
if (!msg) throw new ReferenceError("Unknown message `" + key + "`");
|
||||
|
||||
@@ -34,9 +34,9 @@ exports.get = function (key) {
|
||||
return msg.replace(/\$(\d+)/g, function (str, i) {
|
||||
return args[--i];
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.parseArgs = function (args) {
|
||||
export function parseArgs(args) {
|
||||
return args.map(function (val) {
|
||||
if (val != null && val.inspect) {
|
||||
return val.inspect();
|
||||
@@ -48,4 +48,4 @@ exports.parseArgs = function (args) {
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
var extend = require("lodash/object/extend");
|
||||
var t = require("./types");
|
||||
import estraverse from "estraverse";
|
||||
import extend from "lodash/object/extend";
|
||||
import types from "ast-types";
|
||||
import t from "./types";
|
||||
|
||||
// estraverse
|
||||
|
||||
var estraverse = require("estraverse");
|
||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
|
||||
// regenerator-babel/ast-types
|
||||
|
||||
var types = require("ast-types");
|
||||
var def = types.Type.def;
|
||||
var or = types.Type.or;
|
||||
|
||||
|
||||
@@ -3,5 +3,5 @@ if (global._babelPolyfill) {
|
||||
}
|
||||
global._babelPolyfill = true;
|
||||
|
||||
require("core-js/shim");
|
||||
require("regenerator-babel/runtime");
|
||||
import "core-js/shim";
|
||||
import "regenerator-babel/runtime";
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
var sourceMapToComment = require("source-map-to-comment");
|
||||
var shebangRegex = require("shebang-regex");
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var transform = require("./index");
|
||||
var generate = require("../generation");
|
||||
var defaults = require("lodash/object/defaults");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var assign = require("lodash/object/assign");
|
||||
var parse = require("../helpers/parse");
|
||||
var Scope = require("../traversal/scope");
|
||||
var slash = require("slash");
|
||||
var util = require("../util");
|
||||
var path = require("path");
|
||||
var each = require("lodash/collection/each");
|
||||
var t = require("../types");
|
||||
import sourceMapToComment from "source-map-to-comment";
|
||||
import shebangRegex from "shebang-regex";
|
||||
import isFunction from "lodash/lang/isFunction";
|
||||
import transform from "./index";
|
||||
import generate from "../generation";
|
||||
import defaults from "lodash/object/defaults";
|
||||
import includes from "lodash/collection/includes";
|
||||
import assign from "lodash/object/assign";
|
||||
import parse from "../helpers/parse";
|
||||
import Scope from "../traversal/scope";
|
||||
import slash from "slash";
|
||||
import * as util from "../util";
|
||||
import path from "path";
|
||||
import each from "lodash/collection/each";
|
||||
import t from "../types";
|
||||
|
||||
var checkTransformerVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -20,12 +20,12 @@ var checkTransformerVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
var checkNode = function (stack, node, scope) {
|
||||
function checkNode(stack, node, scope) {
|
||||
each(stack, function (pass) {
|
||||
if (pass.shouldRun) return;
|
||||
pass.checkNode(node, scope);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default class File {
|
||||
constructor(opts) {
|
||||
@@ -369,9 +369,7 @@ export default class File {
|
||||
// todo, (node, msg)
|
||||
}
|
||||
|
||||
errorWithNode(node, msg, Error) {
|
||||
Error ||= SyntaxError;
|
||||
|
||||
errorWithNode(node, msg, Error = SyntaxError) {
|
||||
var loc = node.loc.start;
|
||||
var err = new Error("Line " + loc.line + ": " + msg);
|
||||
err.loc = loc;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var explode = require("./explode-assignable-expression");
|
||||
var t = require("../../types");
|
||||
import explode from "./explode-assignable-expression";
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (exports, opts) {
|
||||
var isAssignment = function (node) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function build(node, buildBody) {
|
||||
var self = node.blocks.shift();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var explode = require("./explode-assignable-expression");
|
||||
var t = require("../../types");
|
||||
import explode from "./explode-assignable-expression";
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (exports, opts) {
|
||||
var buildAssignment = function (left, right) {
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
// jsx
|
||||
|
||||
var isString = require("lodash/lang/isString");
|
||||
var messages = require("../../messages");
|
||||
var esutils = require("esutils");
|
||||
var react = require("./react");
|
||||
var t = require("../../types");
|
||||
import isString from "lodash/lang/isString";
|
||||
import * as messages from "../../messages";
|
||||
import esutils from "esutils";
|
||||
import * as react from "./react";
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (exports, opts) {
|
||||
exports.check = function (node) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var cloneDeep = require("lodash/lang/cloneDeep");
|
||||
var traverse = require("../../traversal");
|
||||
var clone = require("lodash/lang/clone");
|
||||
var each = require("lodash/collection/each");
|
||||
var has = require("lodash/object/has");
|
||||
var t = require("../../types");
|
||||
import cloneDeep from "lodash/lang/cloneDeep";
|
||||
import traverse from "../../traversal";
|
||||
import clone from "lodash/lang/clone";
|
||||
import each from "lodash/collection/each";
|
||||
import has from "lodash/object/has";
|
||||
import t from "../../types";
|
||||
|
||||
exports.push = function (mutatorMap, key, kind, computed, value) {
|
||||
export function push(mutatorMap, key, kind, computed, value) {
|
||||
var alias;
|
||||
|
||||
if (t.isIdentifier(key)) {
|
||||
@@ -31,9 +31,9 @@ exports.push = function (mutatorMap, key, kind, computed, value) {
|
||||
}
|
||||
|
||||
map[kind] = value;
|
||||
};
|
||||
}
|
||||
|
||||
exports.build = function (mutatorMap) {
|
||||
export function build(mutatorMap) {
|
||||
var objExpr = t.objectExpression([]);
|
||||
|
||||
each(mutatorMap, function (map) {
|
||||
@@ -70,4 +70,4 @@ exports.build = function (mutatorMap) {
|
||||
});
|
||||
|
||||
return objExpr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
var getObjRef = function (node, nodes, file, scope) {
|
||||
var ref;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
module.exports = function (node) {
|
||||
var lastNonDefault = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var getFunctionArity = require("./get-function-arity");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
import getFunctionArity from "./get-function-arity";
|
||||
import * as util from "../../util";
|
||||
import t from "../../types";
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -49,7 +49,7 @@ var visit = function (node, name, scope) {
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(name),
|
||||
references: [],
|
||||
name: name,
|
||||
name: name
|
||||
};
|
||||
|
||||
// check to see if we have a local binding of the id we're setting inside of
|
||||
@@ -89,7 +89,7 @@ var visit = function (node, name, scope) {
|
||||
return state;
|
||||
};
|
||||
|
||||
exports.property = function (node, file, scope) {
|
||||
export function property(node, file, scope) {
|
||||
var key = t.toComputedKey(node, node.key);
|
||||
if (!t.isLiteral(key)) return node; // we can't set a function id with this
|
||||
|
||||
@@ -99,9 +99,9 @@ exports.property = function (node, file, scope) {
|
||||
var method = node.value;
|
||||
var state = visit(method, name, scope);
|
||||
node.value = wrap(state, method, id, scope);
|
||||
};
|
||||
}
|
||||
|
||||
exports.bare = function (node, parent, scope) {
|
||||
export function bare(node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
|
||||
@@ -123,4 +123,4 @@ exports.bare = function (node, parent, scope) {
|
||||
|
||||
var state = visit(node, name, scope);
|
||||
return wrap(state, node, id, scope);
|
||||
};
|
||||
}
|
||||
|
||||
12
src/babel/transformation/helpers/react.js
vendored
12
src/babel/transformation/helpers/react.js
vendored
@@ -1,8 +1,8 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
|
||||
|
||||
exports.isCreateClass = function (node) {
|
||||
export function isCreateClass(node) {
|
||||
if (!node || !t.isCallExpression(node)) return false;
|
||||
|
||||
// not React.createClass call member object
|
||||
@@ -17,10 +17,10 @@ exports.isCreateClass = function (node) {
|
||||
if (!t.isObjectExpression(first)) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
exports.isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
export var isReactComponent = t.buildMatchMemberExpression("React.Component");
|
||||
|
||||
exports.isCompatTag = function (tagName) {
|
||||
export function isCompatTag(tagName) {
|
||||
return tagName && /^[a-z]|\-/.test(tagName);
|
||||
};
|
||||
}
|
||||
|
||||
13
src/babel/transformation/helpers/regex.js
Normal file
13
src/babel/transformation/helpers/regex.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import pull from "lodash/array/pull";
|
||||
import t from "../../types";
|
||||
|
||||
export function is(node, flag) {
|
||||
return t.isLiteral(node) && node.regex && node.regex.flags.indexOf(flag) >= 0;
|
||||
}
|
||||
|
||||
export function pullFlag(node, flag) {
|
||||
var flags = node.regex.flags.split("");
|
||||
if (node.regex.flags.indexOf("u") < 0) return;
|
||||
pull(flags, "u");
|
||||
node.regex.flags = flags.join("");
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
var visitor = {
|
||||
enter(node) {
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
module.exports = ReplaceSupers;
|
||||
|
||||
var messages = require("../../messages");
|
||||
var t = require("../../types");
|
||||
import * as messages from "../../messages";
|
||||
import t from "../../types";
|
||||
|
||||
|
||||
var isIllegalBareSuper = function (node, parent) {
|
||||
function isIllegalBareSuper(node, parent) {
|
||||
if (!isSuper(node, parent)) return false;
|
||||
if (t.isMemberExpression(parent, { computed: false })) return false;
|
||||
if (t.isCallExpression(parent, { callee: node })) return false;
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
var isSuper = function (node, parent) {
|
||||
function isSuper(node, parent) {
|
||||
return t.isIdentifier(node, { name: "super" }) && t.isReferenced(node, parent);
|
||||
};
|
||||
}
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
exports.has = function (node) {
|
||||
export function has(node) {
|
||||
var first = node.body[0];
|
||||
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
|
||||
};
|
||||
}
|
||||
|
||||
exports.wrap = function (node, callback) {
|
||||
export function wrap(node, callback) {
|
||||
var useStrictNode;
|
||||
if (exports.has(node)) {
|
||||
useStrictNode = node.body.shift();
|
||||
@@ -16,4 +16,4 @@ exports.wrap = function (node, callback) {
|
||||
if (useStrictNode) {
|
||||
node.body.unshift(useStrictNode);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
module.exports = transform;
|
||||
import normalizeAst from "../helpers/normalize-ast";
|
||||
import Transformer from "./transformer";
|
||||
import object from "../helpers/object";
|
||||
import File from "./file";
|
||||
import each from "lodash/collection/each";
|
||||
|
||||
var normalizeAst = require("../helpers/normalize-ast");
|
||||
var Transformer = require("./transformer");
|
||||
var object = require("../helpers/object");
|
||||
var File = require("./file");
|
||||
var each = require("lodash/collection/each");
|
||||
|
||||
function transform(code, opts) {
|
||||
export default function transform(code, opts) {
|
||||
var file = new File(opts);
|
||||
return file.parse(code);
|
||||
}
|
||||
@@ -53,7 +51,7 @@ transform.namespaces = object();
|
||||
transform.deprecatedTransformerMap = require("./transformers/deprecated");
|
||||
transform.moduleFormatters = require("./modules");
|
||||
|
||||
var rawTransformers = require("./transformers");
|
||||
import rawTransformers from "./transformers";
|
||||
|
||||
each(rawTransformers, function (transformer, key) {
|
||||
var namespace = key.split(".")[0];
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var messages = require("../../messages");
|
||||
var extend = require("lodash/object/extend");
|
||||
var object = require("../../helpers/object");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
import * as messages from "../../messages";
|
||||
import extend from "lodash/object/extend";
|
||||
import object from "../../helpers/object";
|
||||
import * as util from "../../util";
|
||||
import t from "../../types";
|
||||
|
||||
var remapVisitor = {
|
||||
enter(node, parent, scope, formatter) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var util = require("../../util");
|
||||
import * as util from "../../util";
|
||||
|
||||
module.exports = function (Parent) {
|
||||
export default function (Parent) {
|
||||
var Constructor = function () {
|
||||
this.noInteropRequireImport = true;
|
||||
this.noInteropRequireExport = true;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var DefaultFormatter = require("./_default");
|
||||
var CommonFormatter = require("./common");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var values = require("lodash/object/values");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
import DefaultFormatter from "./_default";
|
||||
import CommonFormatter from "./common";
|
||||
import includes from "lodash/collection/includes";
|
||||
import values from "lodash/object/values";
|
||||
import * as util from "../../util";
|
||||
import t from "../../types";
|
||||
|
||||
export default class AMDFormatter extends DefaultFormatter {
|
||||
init = CommonFormatter.prototype.init;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var DefaultFormatter = require("./_default");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
import DefaultFormatter from "./_default";
|
||||
import includes from "lodash/collection/includes";
|
||||
import * as util from "../../util";
|
||||
import t from "../../types";
|
||||
|
||||
export default class CommonJSFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../../types");
|
||||
import t from "../../types";
|
||||
|
||||
export default class IgnoreFormatter {
|
||||
exportDeclaration(node, nodes) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var DefaultFormatter = require("./_default");
|
||||
var AMDFormatter = require("./amd");
|
||||
var util = require("../../util");
|
||||
var last = require("lodash/array/last");
|
||||
var each = require("lodash/collection/each");
|
||||
var map = require("lodash/collection/map");
|
||||
var t = require("../../types");
|
||||
import DefaultFormatter from "./_default";
|
||||
import AMDFormatter from "./amd";
|
||||
import * as util from "../../util";
|
||||
import last from "lodash/array/last";
|
||||
import each from "lodash/collection/each";
|
||||
import map from "lodash/collection/map";
|
||||
import t from "../../types";
|
||||
|
||||
var hoistVariablesVisitor = {
|
||||
enter(node, parent, scope, hoistDeclarators) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var AMDFormatter = require("./amd");
|
||||
var values = require("lodash/object/values");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
import AMDFormatter from "./amd";
|
||||
import values from "lodash/object/values";
|
||||
import * as util from "../../util";
|
||||
import t from "../../types";
|
||||
|
||||
export default class UMDFormatter extends AMDFormatter {
|
||||
transform(program) {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"blacklist": ["useStrict", "es6.blockScoping"]
|
||||
"blacklist": ["useStrict", "es6.blockScoping", "regenerator"]
|
||||
}
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
for (var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY; !(STEP_KEY = ITERATOR_KEY.next()).done; ) {
|
||||
var ITERATOR_COMPLETION = true;
|
||||
var ITERATOR_HAD_ERROR_KEY = false;
|
||||
var ITERATOR_ERROR_KEY = undefined;
|
||||
try {
|
||||
for (var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY; !(ITERATOR_COMPLETION = (STEP_KEY = ITERATOR_KEY.next()).done); ITERATOR_COMPLETION = true) {
|
||||
|
||||
}
|
||||
} catch (err) {
|
||||
ITERATOR_HAD_ERROR_KEY = true;
|
||||
ITERATOR_ERROR_KEY = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!ITERATOR_COMPLETION && ITERATOR_KEY.return) {
|
||||
ITERATOR_KEY.return();
|
||||
}
|
||||
} finally {
|
||||
if (ITERATOR_HAD_ERROR_KEY) {
|
||||
throw ITERATOR_ERROR_KEY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var includes = require("lodash/collection/includes");
|
||||
import includes from "lodash/collection/includes";
|
||||
|
||||
/**
|
||||
* This class is responsible for traversing over the provided `File`s
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var TransformerPass = require("./transformer-pass");
|
||||
var isFunction = require("lodash/lang/isFunction");
|
||||
var traverse = require("../traversal");
|
||||
var isObject = require("lodash/lang/isObject");
|
||||
var assign = require("lodash/object/assign");
|
||||
var each = require("lodash/collection/each");
|
||||
import TransformerPass from "./transformer-pass";
|
||||
import isFunction from "lodash/lang/isFunction";
|
||||
import traverse from "../traversal";
|
||||
import isObject from "lodash/lang/isObject";
|
||||
import assign from "lodash/object/assign";
|
||||
import each from "lodash/collection/each";
|
||||
|
||||
/**
|
||||
* This is the class responsible for normalising a transformers handlers
|
||||
@@ -12,7 +12,7 @@ var each = require("lodash/collection/each");
|
||||
*/
|
||||
|
||||
export default class Transformer {
|
||||
constructor(key, transformer, opts) {
|
||||
constructor(transformerKey, transformer, opts) {
|
||||
transformer = assign({}, transformer);
|
||||
|
||||
var take = function (key) {
|
||||
@@ -33,7 +33,7 @@ export default class Transformer {
|
||||
|
||||
this.handlers = this.normalize(transformer);
|
||||
this.opts ||= {};
|
||||
this.key = key;
|
||||
this.key = transformerKey;
|
||||
}
|
||||
|
||||
normalize(transformer) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"selfContained": "runtime"
|
||||
"selfContained": "runtime",
|
||||
"unicode-regex": "regex.unicode"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
exports.MemberExpression = function (node) {
|
||||
export function MemberExpression(node) {
|
||||
var prop = node.property;
|
||||
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
|
||||
// foo["bar"] => foo.bar
|
||||
@@ -11,4 +11,4 @@ exports.MemberExpression = function (node) {
|
||||
node.property = t.literal(prop.name);
|
||||
node.computed = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
exports.Property = function (node) {
|
||||
export function Property(node) {
|
||||
var key = node.key;
|
||||
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
|
||||
// "foo": "bar" -> foo: "bar"
|
||||
@@ -10,4 +10,4 @@ exports.Property = function (node) {
|
||||
// default: "bar" -> "default": "bar"
|
||||
node.key = t.literal(key.name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var defineMap = require("../../helpers/define-map");
|
||||
var t = require("../../../types");
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = function (node) {
|
||||
export function check(node) {
|
||||
return t.isProperty(node) && (node.kind === "get" || node.kind === "set");
|
||||
};
|
||||
}
|
||||
|
||||
exports.ObjectExpression = function (node) {
|
||||
export function ObjectExpression(node) {
|
||||
var mutatorMap = {};
|
||||
var hasAny = false;
|
||||
|
||||
@@ -25,4 +25,4 @@ exports.ObjectExpression = function (node) {
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
|
||||
[node, defineMap.build(mutatorMap)]
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isArrowFunctionExpression;
|
||||
export var check = t.isArrowFunctionExpression;
|
||||
|
||||
exports.ArrowFunctionExpression = function (node) {
|
||||
export function ArrowFunctionExpression(node) {
|
||||
t.ensureBlock(node);
|
||||
|
||||
node._aliasFunction = "arrow";
|
||||
@@ -10,4 +10,4 @@ exports.ArrowFunctionExpression = function (node) {
|
||||
node.type = "FunctionExpression";
|
||||
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -26,11 +26,9 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
exports.optional = true;
|
||||
export var optional = true;
|
||||
|
||||
exports.Loop =
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (node, parent, scope, file) {
|
||||
export function BlockStatement(node, parent, scope, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
|
||||
@@ -40,4 +38,6 @@ exports.BlockStatement = function (node, parent, scope, file) {
|
||||
};
|
||||
|
||||
scope.traverse(node, visitor, state);
|
||||
};
|
||||
}
|
||||
|
||||
export { BlockStatement as Program, BlockStatement as Loop };
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
var traverse = require("../../../traversal");
|
||||
var object = require("../../../helpers/object");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
var values = require("lodash/object/values");
|
||||
var extend = require("lodash/object/extend");
|
||||
import traverse from "../../../traversal";
|
||||
import object from "../../../helpers/object";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
import values from "lodash/object/values";
|
||||
import extend from "lodash/object/extend";
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind === "let" || node.kind === "const");
|
||||
};
|
||||
|
||||
var isLet = function (node, parent) {
|
||||
function isLet(node, parent) {
|
||||
if (!t.isVariableDeclaration(node)) return false;
|
||||
if (node._let) return true;
|
||||
if (node.kind !== "let") return false;
|
||||
@@ -25,23 +21,27 @@ var isLet = function (node, parent) {
|
||||
node._let = true;
|
||||
node.kind = "var";
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
var isLetInitable = function (node, parent) {
|
||||
function isLetInitable(node, parent) {
|
||||
return !t.isFor(parent) || !t.isFor(parent, { left: node });
|
||||
};
|
||||
}
|
||||
|
||||
var isVar = function (node, parent) {
|
||||
function isVar(node, parent) {
|
||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent);
|
||||
};
|
||||
}
|
||||
|
||||
var standardizeLets = function (declars) {
|
||||
function standardizeLets(declars) {
|
||||
for (var i = 0; i < declars.length; i++) {
|
||||
delete declars[i]._let;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
export function check(node) {
|
||||
return t.isVariableDeclaration(node) && (node.kind === "let" || node.kind === "const");
|
||||
}
|
||||
|
||||
export function VariableDeclaration(node, parent, scope, file) {
|
||||
if (!isLet(node, parent)) return;
|
||||
|
||||
if (isLetInitable(node) && file.transformers["es6.blockScopingTDZ"].canRun()) {
|
||||
@@ -61,9 +61,9 @@ exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
|
||||
return nodes;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.Loop = function (node, parent, scope, file) {
|
||||
export function Loop(node, parent, scope, file) {
|
||||
var init = node.left || node.init;
|
||||
if (isLet(init, node)) {
|
||||
t.ensureBlock(node);
|
||||
@@ -71,15 +71,16 @@ exports.Loop = function (node, parent, scope, file) {
|
||||
}
|
||||
var blockScoping = new BlockScoping(node, node.body, parent, scope, file);
|
||||
blockScoping.run();
|
||||
};
|
||||
}
|
||||
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (block, parent, scope, file) {
|
||||
export function BlockStatement(block, parent, scope, file) {
|
||||
if (!t.isLoop(parent)) {
|
||||
var blockScoping = new BlockScoping(false, block, parent, scope, file);
|
||||
blockScoping.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { BlockStatement as Program };
|
||||
|
||||
function replace(node, parent, scope, remaps) {
|
||||
if (!t.isReferencedIdentifier(node, parent)) return;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
var ReplaceSupers = require("../../helpers/replace-supers");
|
||||
var nameMethod = require("../../helpers/name-method");
|
||||
var defineMap = require("../../helpers/define-map");
|
||||
var messages = require("../../../messages");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
import ReplaceSupers from "../../helpers/replace-supers";
|
||||
import * as nameMethod from "../../helpers/name-method";
|
||||
import * as defineMap from "../../helpers/define-map";
|
||||
import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isClass;
|
||||
export var check = t.isClass;
|
||||
|
||||
exports.ClassDeclaration = function (node, parent, scope, file) {
|
||||
export function ClassDeclaration(node, parent, scope, file) {
|
||||
return new ClassTransformer(node, file, scope, true).run();
|
||||
};
|
||||
}
|
||||
|
||||
exports.ClassExpression = function (node, parent, scope, file) {
|
||||
export function ClassExpression(node, parent, scope, file) {
|
||||
if (!node.id) {
|
||||
if (t.isProperty(parent) && parent.value === node && !parent.computed && t.isIdentifier(parent.key)) {
|
||||
// var o = { foo: class {} };
|
||||
@@ -25,7 +25,7 @@ exports.ClassExpression = function (node, parent, scope, file) {
|
||||
}
|
||||
|
||||
return new ClassTransformer(node, file, scope, false).run();
|
||||
};
|
||||
}
|
||||
|
||||
class ClassTransformer {
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var messages = require("../../../messages");
|
||||
var t = require("../../../types");
|
||||
import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = function (node) {
|
||||
export function check(node) {
|
||||
return t.isVariableDeclaration(node, { kind: "const" });
|
||||
};
|
||||
}
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -36,13 +36,13 @@ var visitor = {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Scopable = function (node, parent, scope, file) {
|
||||
export function Scopable(node, parent, scope, file) {
|
||||
scope.traverse(node, visitor, {
|
||||
constants: scope.getAllBindingsOfKind("const"),
|
||||
file: file
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node) {
|
||||
export function VariableDeclaration(node) {
|
||||
if (node.kind === "const") node.kind = "let";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
var messages = require("../../../messages");
|
||||
var t = require("../../../types");
|
||||
import * as messages from "../../../messages";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isPattern;
|
||||
export var check = t.isPattern;
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
|
||||
if (t.isPattern(left)) {
|
||||
@@ -50,7 +49,9 @@ exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
}
|
||||
|
||||
export { ForOfStatement as ForInStatement };
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
var nodes = [];
|
||||
@@ -83,7 +84,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
block.body = nodes.concat(block.body);
|
||||
};
|
||||
|
||||
exports.CatchClause = function (node, parent, scope, file) {
|
||||
export function CatchClause(node, parent, scope, file) {
|
||||
var pattern = node.param;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
@@ -103,9 +104,9 @@ exports.CatchClause = function (node, parent, scope, file) {
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
export function ExpressionStatement(node, parent, scope, file) {
|
||||
var expr = node.expression;
|
||||
if (expr.type !== "AssignmentExpression") return;
|
||||
if (!t.isPattern(expr.left)) return;
|
||||
@@ -127,9 +128,9 @@ exports.ExpressionStatement = function (node, parent, scope, file) {
|
||||
destructuring.init(expr.left, ref);
|
||||
|
||||
return nodes;
|
||||
};
|
||||
}
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
export function AssignmentExpression(node, parent, scope, file) {
|
||||
if (!t.isPattern(node.left)) return;
|
||||
|
||||
var ref = scope.generateUidIdentifier("temp");
|
||||
@@ -152,18 +153,18 @@ exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
nodes.push(ref);
|
||||
|
||||
return t.toSequenceExpression(nodes, scope);
|
||||
};
|
||||
}
|
||||
|
||||
var variableDeclarationHasPattern = function (node) {
|
||||
function variableDeclarationHasPattern(node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
if (t.isPattern(node.declarations[i].id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
exports.VariableDeclaration = function (node, parent, scope, file) {
|
||||
export function VariableDeclaration(node, parent, scope, file) {
|
||||
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
|
||||
if (!variableDeclarationHasPattern(node)) return;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var messages = require("../../../messages");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
import * as messages from "../../../messages";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isForOfStatement;
|
||||
export var check = t.isForOfStatement;
|
||||
|
||||
exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.forOf")) callback = loose;
|
||||
|
||||
@@ -32,8 +32,8 @@ exports.ForOfStatement = function (node, parent, scope, file) {
|
||||
// todo: find out why this is necessary? #538
|
||||
loop._scopeInfo = node._scopeInfo;
|
||||
|
||||
return loop;
|
||||
};
|
||||
return build.node;
|
||||
}
|
||||
|
||||
var breakVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -113,6 +113,7 @@ var loose = function (node, parent, scope, file) {
|
||||
|
||||
return {
|
||||
declar: declar,
|
||||
node: loop,
|
||||
loop: loop
|
||||
};
|
||||
};
|
||||
@@ -140,26 +141,33 @@ var spec = function (node, parent, scope, file) {
|
||||
|
||||
var iteratorKey = scope.generateUidIdentifier("iterator");
|
||||
|
||||
var loop = util.template("for-of", {
|
||||
ITERATOR_KEY: iteratorKey,
|
||||
STEP_KEY: stepKey,
|
||||
OBJECT: node.right
|
||||
var template = util.template("for-of", {
|
||||
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
|
||||
ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
|
||||
ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
|
||||
ITERATOR_KEY: iteratorKey,
|
||||
STEP_KEY: stepKey,
|
||||
OBJECT: node.right,
|
||||
BODY: null
|
||||
});
|
||||
|
||||
var loop = template[3].block.body[0];
|
||||
|
||||
//
|
||||
|
||||
scope.traverse(node, breakVisitor, {
|
||||
iteratorKey: iteratorKey,
|
||||
label: t.isLabeledStatement(parent) && parent.label.name,
|
||||
wrapReturn: function (node) {
|
||||
return t.ifStatement(t.memberExpression(iteratorKey, t.identifier("return")), node);
|
||||
},
|
||||
label: t.isLabeledStatement(parent) && parent.label.name
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
return {
|
||||
declar: declar,
|
||||
loop: loop
|
||||
loop: loop,
|
||||
node: template
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = require("../internal/modules").check;
|
||||
export { check } from "../internal/modules";
|
||||
|
||||
exports.ImportDeclaration = function (node, parent, scope, file) {
|
||||
export function ImportDeclaration(node, parent, scope, file) {
|
||||
// flow type
|
||||
if (node.isType) return;
|
||||
|
||||
@@ -22,9 +22,9 @@ exports.ImportDeclaration = function (node, parent, scope, file) {
|
||||
}
|
||||
|
||||
return nodes;
|
||||
};
|
||||
}
|
||||
|
||||
exports.ExportDeclaration = function (node, parent, scope, file) {
|
||||
export function ExportDeclaration(node, parent, scope, file) {
|
||||
// flow type
|
||||
if (t.isTypeAlias(node.declaration)) return;
|
||||
|
||||
@@ -53,4 +53,4 @@ exports.ExportDeclaration = function (node, parent, scope, file) {
|
||||
}
|
||||
|
||||
return nodes;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var ReplaceSupers = require("../../helpers/replace-supers");
|
||||
var t = require("../../../types");
|
||||
import ReplaceSupers from "../../helpers/replace-supers";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = function (node) {
|
||||
export function check(node) {
|
||||
return t.isIdentifier(node, { name: "super" });
|
||||
};
|
||||
}
|
||||
|
||||
exports.Property = function (node, parent, scope, file) {
|
||||
export function Property(node, parent, scope, file) {
|
||||
if (!node.method) return;
|
||||
|
||||
var value = node.value;
|
||||
@@ -29,4 +29,4 @@ exports.Property = function (node, parent, scope, file) {
|
||||
])
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = function (node) {
|
||||
export function check(node) {
|
||||
return t.isFunction(node) && hasDefaults(node);
|
||||
};
|
||||
}
|
||||
|
||||
var hasDefaults = function (node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
|
||||
@@ -1,7 +1,56 @@
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isRestElement;
|
||||
export var check = t.isRestElement;
|
||||
|
||||
var memberExpressionOptimisationVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
// check if this scope has a local binding that will shadow the rest parameter
|
||||
if (t.isScope(node, parent) && !scope.bindingIdentifierEquals(state.name, state.outerBinding)) {
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
// skip over functions as whatever `arguments` we reference inside will refer
|
||||
// to the wrong function
|
||||
if (t.isFunctionDeclaration(node) || t.isFunctionExpression(node)) {
|
||||
state.noOptimise = true;
|
||||
scope.traverse(node, memberExpressionOptimisationVisitor, state);
|
||||
state.noOptimise = false;
|
||||
return this.skip();
|
||||
}
|
||||
|
||||
// is this a referenced identifier and is it referencing the rest parameter?
|
||||
if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;
|
||||
|
||||
if (!state.noOptimise && t.isMemberExpression(parent) && parent.computed) {
|
||||
// if we know that this member expression is referencing a number then we can safely
|
||||
// optimise it
|
||||
var prop = parent.property;
|
||||
if (isNumber(prop.value) || t.isUnaryExpression(prop) || t.isBinaryExpression(prop)) {
|
||||
state.candidates.push(this);
|
||||
state.canOptimise = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
state.canOptimise = false;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
|
||||
function optimizeMemberExpression(parent, offset) {
|
||||
var newExpr;
|
||||
var prop = parent.property;
|
||||
|
||||
if (t.isLiteral(prop)) {
|
||||
prop.value += offset;
|
||||
prop.raw = String(prop.value);
|
||||
} else { // // UnaryExpression, BinaryExpression
|
||||
newExpr = t.binaryExpression("+", prop, t.literal(offset));
|
||||
parent.property = newExpr;
|
||||
}
|
||||
}
|
||||
|
||||
var hasRest = function (node) {
|
||||
return t.isRestElement(node.params[node.params.length - 1]);
|
||||
@@ -17,6 +66,41 @@ exports.Function = function (node, parent, scope) {
|
||||
// otherwise `arguments` will be remapped in arrow functions
|
||||
argsId._ignoreAliasFunctions = true;
|
||||
|
||||
// support patterns
|
||||
if (t.isPattern(rest)) {
|
||||
var pattern = rest;
|
||||
rest = scope.generateUidIdentifier("ref");
|
||||
var declar = t.variableDeclaration("var", pattern.elements.map(function (elem, index) {
|
||||
var accessExpr = t.memberExpression(rest, t.literal(index), true);
|
||||
return t.variableDeclarator(elem, accessExpr);
|
||||
}));
|
||||
node.body.body.unshift(declar);
|
||||
}
|
||||
|
||||
// check if rest is used in member expressions and optimise for those cases
|
||||
|
||||
var state = {
|
||||
outerBinding: scope.getBindingIdentifier(rest.name),
|
||||
canOptimise: false,
|
||||
candidates: [],
|
||||
method: node,
|
||||
name: rest.name
|
||||
};
|
||||
|
||||
scope.traverse(node, memberExpressionOptimisationVisitor, state);
|
||||
|
||||
// we only have shorthands and there's no other references
|
||||
if (state.canOptimise) {
|
||||
for (var i = 0; i < state.candidates.length; i++) {
|
||||
var candidate = state.candidates[i];
|
||||
candidate.node = argsId;
|
||||
optimizeMemberExpression(candidate.parent, node.params.length);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
var start = t.literal(node.params.length);
|
||||
var key = scope.generateUidIdentifier("key");
|
||||
var len = scope.generateUidIdentifier("len");
|
||||
@@ -42,22 +126,6 @@ exports.Function = function (node, parent, scope) {
|
||||
);
|
||||
}
|
||||
|
||||
// support patterns
|
||||
if (t.isPattern(rest)) {
|
||||
var pattern = rest;
|
||||
rest = scope.generateUidIdentifier("ref");
|
||||
|
||||
// let the destructuring transformer handle this
|
||||
var restDeclar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(pattern, rest)
|
||||
]);
|
||||
|
||||
// retain evaluation position
|
||||
restDeclar._blockHoist = node.params.length + 1;
|
||||
|
||||
node.body.body.unshift(restDeclar);
|
||||
}
|
||||
|
||||
scope.assignTypeGeneric(rest.name, "Array");
|
||||
|
||||
var loop = util.template("rest", {
|
||||
|
||||
@@ -1,48 +1,6 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isProperty(node) && node.computed;
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
|
||||
if (hasComputed) break;
|
||||
}
|
||||
|
||||
if (!hasComputed) return;
|
||||
|
||||
var initProps = [];
|
||||
var objId = scope.generateUidBasedOnNode(parent);
|
||||
|
||||
//
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body));
|
||||
container._aliasFunction = true;
|
||||
|
||||
//
|
||||
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.properties.computed")) callback = loose;
|
||||
|
||||
var result = callback(node, body, objId, initProps, file);
|
||||
if (result) return result;
|
||||
|
||||
//
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, t.objectExpression(initProps))
|
||||
]));
|
||||
|
||||
body.push(t.returnStatement(objId));
|
||||
|
||||
return t.callExpression(container, []);
|
||||
};
|
||||
|
||||
var loose = function (node, body, objId) {
|
||||
function loose(node, body, objId) {
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
var prop = node.properties[i];
|
||||
|
||||
@@ -54,9 +12,9 @@ var loose = function (node, body, objId) {
|
||||
)
|
||||
));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var spec = function (node, body, objId, initProps, file) {
|
||||
function spec(node, body, objId, initProps, file) {
|
||||
var props = node.properties;
|
||||
var prop, key;
|
||||
|
||||
@@ -124,4 +82,46 @@ var spec = function (node, body, objId, initProps, file) {
|
||||
return first;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function check(node) {
|
||||
return t.isProperty(node) && node.computed;
|
||||
}
|
||||
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
var hasComputed = false;
|
||||
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
|
||||
if (hasComputed) break;
|
||||
}
|
||||
|
||||
if (!hasComputed) return;
|
||||
|
||||
var initProps = [];
|
||||
var objId = scope.generateUidBasedOnNode(parent);
|
||||
|
||||
//
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body));
|
||||
container._aliasFunction = true;
|
||||
|
||||
//
|
||||
|
||||
var callback = spec;
|
||||
if (file.isLoose("es6.properties.computed")) callback = loose;
|
||||
|
||||
var result = callback(node, body, objId, initProps, file);
|
||||
if (result) return result;
|
||||
|
||||
//
|
||||
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(objId, t.objectExpression(initProps))
|
||||
]));
|
||||
|
||||
body.push(t.returnStatement(objId));
|
||||
|
||||
return t.callExpression(container, []);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var clone = require("lodash/lang/clone");
|
||||
var t = require("../../../types");
|
||||
import clone from "lodash/lang/clone";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = function (node) {
|
||||
export function check(node) {
|
||||
return t.isProperty(node) && (node.method || node.shorthand);
|
||||
};
|
||||
}
|
||||
|
||||
exports.Property = function (node) {
|
||||
export function Property(node) {
|
||||
if (node.method) {
|
||||
node.method = false;
|
||||
}
|
||||
@@ -14,4 +14,4 @@ exports.Property = function (node) {
|
||||
node.shorthand = false;
|
||||
node.key = t.removeComments(clone(node.key));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
14
src/babel/transformation/transformers/es6/regex.sticky.js
Normal file
14
src/babel/transformation/transformers/es6/regex.sticky.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as regex from "../../helpers/regex";
|
||||
import t from "../../../types";
|
||||
|
||||
export function check(node) {
|
||||
return regex.is(node, "y");
|
||||
}
|
||||
|
||||
export function Literal(node) {
|
||||
if (!regex.is(node, "y")) return;
|
||||
return t.newExpression(t.identifier("RegExp"), [
|
||||
t.literal(node.regex.pattern),
|
||||
t.literal(node.regex.flags)
|
||||
]);
|
||||
}
|
||||
12
src/babel/transformation/transformers/es6/regex.unicode.js
Normal file
12
src/babel/transformation/transformers/es6/regex.unicode.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import rewritePattern from "regexpu/rewrite-pattern";
|
||||
import * as regex from "../../helpers/regex";
|
||||
|
||||
export function check(node) {
|
||||
return regex.is(node, "u");
|
||||
}
|
||||
|
||||
export function Literal(node) {
|
||||
if (!regex.is(node, "u")) return;
|
||||
regex.pullFlag(node, "y");
|
||||
node.regex.pattern = rewritePattern(node.regex.pattern, node.regex.flags);
|
||||
}
|
||||
@@ -1,22 +1,20 @@
|
||||
var includes = require("lodash/collection/includes");
|
||||
var t = require("../../../types");
|
||||
import includes from "lodash/collection/includes";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.check = t.isSpreadElement;
|
||||
|
||||
var getSpreadLiteral = function (spread, scope) {
|
||||
function getSpreadLiteral(spread, scope) {
|
||||
return scope.toArray(spread.argument, true);
|
||||
};
|
||||
}
|
||||
|
||||
var hasSpread = function (nodes) {
|
||||
function hasSpread(nodes) {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (t.isSpreadElement(nodes[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
var build = function (props, scope) {
|
||||
function build(props, scope) {
|
||||
var nodes = [];
|
||||
|
||||
var _props = [];
|
||||
@@ -40,9 +38,11 @@ var build = function (props, scope) {
|
||||
push();
|
||||
|
||||
return nodes;
|
||||
};
|
||||
}
|
||||
|
||||
exports.ArrayExpression = function (node, parent, scope) {
|
||||
export var check = t.isSpreadElement;
|
||||
|
||||
export function ArrayExpression(node, parent, scope) {
|
||||
var elements = node.elements;
|
||||
if (!hasSpread(elements)) return;
|
||||
|
||||
@@ -55,9 +55,9 @@ exports.ArrayExpression = function (node, parent, scope) {
|
||||
}
|
||||
|
||||
return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes);
|
||||
};
|
||||
}
|
||||
|
||||
exports.CallExpression = function (node, parent, scope) {
|
||||
export function CallExpression(node, parent, scope) {
|
||||
var args = node.arguments;
|
||||
if (!hasSpread(args)) return;
|
||||
|
||||
@@ -95,9 +95,9 @@ exports.CallExpression = function (node, parent, scope) {
|
||||
}
|
||||
|
||||
node.arguments.unshift(contextLiteral);
|
||||
};
|
||||
}
|
||||
|
||||
exports.NewExpression = function (node, parent, scope, file) {
|
||||
export function NewExpression(node, parent, scope, file) {
|
||||
var args = node.arguments;
|
||||
if (!hasSpread(args)) return;
|
||||
|
||||
@@ -128,4 +128,4 @@ exports.NewExpression = function (node, parent, scope, file) {
|
||||
} else {
|
||||
return t.callExpression(file.addHelper("apply-constructor"), [node.callee, args]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
var reduceRight = require("lodash/collection/reduceRight");
|
||||
var messages = require("../../../messages");
|
||||
var flatten = require("lodash/array/flatten");
|
||||
var util = require("../../../util");
|
||||
var map = require("lodash/collection/map");
|
||||
var t = require("../../../types");
|
||||
import reduceRight from "lodash/collection/reduceRight";
|
||||
import * as messages from "../../../messages";
|
||||
import flatten from "lodash/array/flatten";
|
||||
import * as util from "../../../util";
|
||||
import map from "lodash/collection/map";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
var tailCall = new TailCallTransformer(node, scope, file);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
var buildBinaryExpression = function (left, right) {
|
||||
return t.binaryExpression("+", left, right);
|
||||
};
|
||||
|
||||
exports.check = function (node) {
|
||||
export function check(node) {
|
||||
return t.isTemplateLiteral(node) || t.isTaggedTemplateExpression(node);
|
||||
};
|
||||
}
|
||||
|
||||
exports.TaggedTemplateExpression = function (node, parent, scope, file) {
|
||||
export function TaggedTemplateExpression(node, parent, scope, file) {
|
||||
var args = [];
|
||||
var quasi = node.quasi;
|
||||
|
||||
@@ -31,9 +31,9 @@ exports.TaggedTemplateExpression = function (node, parent, scope, file) {
|
||||
args = args.concat(quasi.expressions);
|
||||
|
||||
return t.callExpression(node.tag, args);
|
||||
};
|
||||
}
|
||||
|
||||
exports.TemplateLiteral = function (node) {
|
||||
export function TemplateLiteral(node) {
|
||||
var nodes = [];
|
||||
var i;
|
||||
|
||||
@@ -61,4 +61,4 @@ exports.TemplateLiteral = function (node) {
|
||||
} else {
|
||||
return nodes[0];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
var rewritePattern = require("regexpu/rewrite-pattern");
|
||||
var pull = require("lodash/array/pull");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.check = function (node) {
|
||||
return t.isLiteral(node) && node.regex && node.regex.flags.indexOf("u") >= 0;
|
||||
};
|
||||
|
||||
exports.Literal = function (node) {
|
||||
var regex = node.regex;
|
||||
if (!regex) return;
|
||||
|
||||
var flags = regex.flags.split("");
|
||||
if (regex.flags.indexOf("u") < 0) return;
|
||||
pull(flags, "u");
|
||||
|
||||
regex.pattern = rewritePattern(regex.pattern, regex.flags);
|
||||
regex.flags = flags.join("");
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
// https://github.com/zenparsing/es-abstract-refs
|
||||
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.experimental = true;
|
||||
export var experimental = true;
|
||||
|
||||
var container = function (parent, call, ret, file) {
|
||||
if (t.isExpressionStatement(parent) && !file.isConsequenceExpressionStatement(parent)) {
|
||||
@@ -21,7 +21,7 @@ var container = function (parent, call, ret, file) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
export function AssignmentExpression(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
if (!t.isVirtualPropertyExpression(left)) return;
|
||||
|
||||
@@ -59,9 +59,9 @@ exports.AssignmentExpression = function (node, parent, scope, file) {
|
||||
}
|
||||
|
||||
return container(parent, call, value, file);
|
||||
};
|
||||
}
|
||||
|
||||
exports.UnaryExpression = function (node, parent, scope, file) {
|
||||
export function UnaryExpression(node, parent, scope, file) {
|
||||
var arg = node.argument;
|
||||
if (!t.isVirtualPropertyExpression(arg)) return;
|
||||
if (node.operator !== "delete") return;
|
||||
@@ -72,9 +72,9 @@ exports.UnaryExpression = function (node, parent, scope, file) {
|
||||
});
|
||||
|
||||
return container(parent, call, t.literal(true), file);
|
||||
};
|
||||
}
|
||||
|
||||
exports.CallExpression = function (node, parent, scope) {
|
||||
export function CallExpression(node, parent, scope) {
|
||||
var callee = node.callee;
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
@@ -95,17 +95,17 @@ exports.CallExpression = function (node, parent, scope) {
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.VirtualPropertyExpression = function (node) {
|
||||
export function VirtualPropertyExpression(node) {
|
||||
return util.template("abstract-expression-get", {
|
||||
PROPERTY: node.property,
|
||||
OBJECT: node.object
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
exports.PrivateDeclaration = function (node) {
|
||||
export function PrivateDeclaration(node) {
|
||||
return t.variableDeclaration("const", node.declarations.map(function (id) {
|
||||
return t.variableDeclarator(id, t.newExpression(t.identifier("WeakMap"), []));
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
var buildComprehension = require("../../helpers/build-comprehension");
|
||||
var traverse = require("../../../traversal");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
import buildComprehension from "../../helpers/build-comprehension";
|
||||
import traverse from "../../../traversal";
|
||||
import * as util from "../../../util";
|
||||
import t from "../../../types";
|
||||
|
||||
exports.experimental = true;
|
||||
export var experimental = true;
|
||||
|
||||
exports.ComprehensionExpression = function (node, parent, scope, file) {
|
||||
export function ComprehensionExpression(node, parent, scope, file) {
|
||||
var callback = array;
|
||||
if (node.generator) callback = generator;
|
||||
return callback(node, parent, scope, file);
|
||||
};
|
||||
}
|
||||
|
||||
var generator = function (node) {
|
||||
function generator(node) {
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body), true);
|
||||
container._aliasFunction = true;
|
||||
@@ -21,9 +21,9 @@ var generator = function (node) {
|
||||
}));
|
||||
|
||||
return t.callExpression(container, []);
|
||||
};
|
||||
}
|
||||
|
||||
var array = function (node, parent, scope, file) {
|
||||
function array(node, parent, scope, file) {
|
||||
var uid = scope.generateUidBasedOnNode(parent, file);
|
||||
|
||||
var container = util.template("array-comprehension-container", {
|
||||
@@ -50,4 +50,4 @@ var array = function (node, parent, scope, file) {
|
||||
body.push(returnStatement);
|
||||
|
||||
return container;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// https://github.com/rwaldron/exponentiation-operator
|
||||
|
||||
exports.experimental = true;
|
||||
import build from "../../helpers/build-binary-assignment-operator-transformer";
|
||||
import t from "../../../types";
|
||||
|
||||
var build = require("../../helpers/build-binary-assignment-operator-transformer");
|
||||
var t = require("../../../types");
|
||||
export var experimental = true;
|
||||
|
||||
var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow"));
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// https://github.com/sebmarkbage/ecmascript-rest-spread
|
||||
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
exports.experimental = true;
|
||||
export var experimental = true;
|
||||
|
||||
exports.manipulateOptions = function (opts) {
|
||||
export function manipulateOptions(opts) {
|
||||
if (opts.whitelist.length) opts.whitelist.push("es6.destructuring");
|
||||
};
|
||||
}
|
||||
|
||||
var hasSpread = function (node) {
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
@@ -17,7 +17,7 @@ var hasSpread = function (node) {
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.ObjectExpression = function (node, parent, scope, file) {
|
||||
export function ObjectExpression(node, parent, scope, file) {
|
||||
if (!hasSpread(node)) return;
|
||||
|
||||
var args = [];
|
||||
@@ -46,4 +46,4 @@ exports.ObjectExpression = function (node, parent, scope, file) {
|
||||
}
|
||||
|
||||
return t.callExpression(file.addHelper("extends"), args);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
useStrict: require("./other/use-strict"),
|
||||
|
||||
"validation.undeclaredVariableCheck": require("./validation/undeclared-variable-check"),
|
||||
@@ -47,7 +47,8 @@ module.exports = {
|
||||
|
||||
"es6.forOf": require("./es6/for-of"),
|
||||
|
||||
"es6.unicodeRegex": require("./es6/unicode-regex"),
|
||||
"es6.regex.sticky": require("./es6/regex.sticky"),
|
||||
"es6.regex.unicode": require("./es6/regex.unicode"),
|
||||
"es7.abstractReferences": require("./es7/abstract-references"),
|
||||
|
||||
"es6.constants": require("./es6/constants"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var t = require("../../../types");
|
||||
import t from "../../../types";
|
||||
|
||||
var functionChildrenVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
@@ -76,16 +76,17 @@ var go = function (getBody, node, scope) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Program = function (node, parent, scope) {
|
||||
export function Program(node, parent, scope) {
|
||||
go(function () {
|
||||
return node.body;
|
||||
}, node, scope);
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, parent, scope) {
|
||||
export function FunctionDeclaration(node, parent, scope) {
|
||||
go(function () {
|
||||
t.ensureBlock(node);
|
||||
return node.body.body;
|
||||
}, node, scope);
|
||||
};
|
||||
}
|
||||
|
||||
export { FunctionDeclaration as FunctionExpression };
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user