Compare commits
235 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a45d6960da | ||
|
|
b13aa41a75 | ||
|
|
20a4ed6140 | ||
|
|
c256e060b3 | ||
|
|
bef315efd6 | ||
|
|
2ec5390b63 | ||
|
|
f4c9dd8768 | ||
|
|
510c7a3e60 | ||
|
|
3ce9508a1c | ||
|
|
717ef280f7 | ||
|
|
8c5e7cf272 | ||
|
|
811a843be9 | ||
|
|
b7c297bb89 | ||
|
|
b7342ef4ea | ||
|
|
1a899f5e77 | ||
|
|
f2eb1643c0 | ||
|
|
9621d1bbeb | ||
|
|
3cf7b2b761 | ||
|
|
ae8b1e242b | ||
|
|
eea48f866d | ||
|
|
84d2d7b7d4 | ||
|
|
ea30a619dd | ||
|
|
87a201db22 | ||
|
|
bcc86c47bc | ||
|
|
b6df9b583b | ||
|
|
52ea7b5f59 | ||
|
|
7bff8239a1 | ||
|
|
04d79c1740 | ||
|
|
e387da7c2b | ||
|
|
53cf453480 | ||
|
|
341528ee4a | ||
|
|
5f6808ba92 | ||
|
|
0b2f1fedcb | ||
|
|
c3c94f0a4a | ||
|
|
f2d60aab9e | ||
|
|
ab6bb35a4f | ||
|
|
e11b943514 | ||
|
|
b44a6eb297 | ||
|
|
f3288ddb1f | ||
|
|
476aa44a90 | ||
|
|
c5589e9336 | ||
|
|
404eb2f972 | ||
|
|
366257915e | ||
|
|
e0cd9bdbe3 | ||
|
|
39854dc088 | ||
|
|
81132aa942 | ||
|
|
5ba2e6254b | ||
|
|
61ea720637 | ||
|
|
55357a331d | ||
|
|
5deaeba3a0 | ||
|
|
a38ae381e2 | ||
|
|
9a2e56f003 | ||
|
|
5bc78b0237 | ||
|
|
c5af8b8694 | ||
|
|
c637575cab | ||
|
|
bc8d49c95c | ||
|
|
59ff0fd9a9 | ||
|
|
b1f794eb84 | ||
|
|
79ab92b5d4 | ||
|
|
f6512b45d5 | ||
|
|
8065c981dc | ||
|
|
7927aa2e18 | ||
|
|
35bd510930 | ||
|
|
74186241f9 | ||
|
|
1effa72a33 | ||
|
|
b03a806d7c | ||
|
|
6220fd9fc3 | ||
|
|
8d92a75190 | ||
|
|
60a7e40140 | ||
|
|
299e462a29 | ||
|
|
62556f6102 | ||
|
|
f2c5accab3 | ||
|
|
15f1978cae | ||
|
|
710ff548cb | ||
|
|
fbb19fc656 | ||
|
|
e87ef80bc5 | ||
|
|
aca750e881 | ||
|
|
672e55082c | ||
|
|
a49f746700 | ||
|
|
83cd3bef92 | ||
|
|
5e4a008a06 | ||
|
|
1594efbc20 | ||
|
|
002be9a05c | ||
|
|
8e06db8f7d | ||
|
|
b1238a1746 | ||
|
|
0874f390ff | ||
|
|
eeff4ac9d1 | ||
|
|
8f0ffc7302 | ||
|
|
bb19649af8 | ||
|
|
692262df1b | ||
|
|
067047da34 | ||
|
|
1c5d169b1e | ||
|
|
3f82b4ec72 | ||
|
|
9c6e632021 | ||
|
|
45553f1fb7 | ||
|
|
f228edbb84 | ||
|
|
64e657e53d | ||
|
|
36423f2e78 | ||
|
|
06eaba5ad1 | ||
|
|
7e8cd2ca8a | ||
|
|
2541dcf960 | ||
|
|
5d45e1475c | ||
|
|
9964de9b2f | ||
|
|
5b75b11628 | ||
|
|
1890fb5bd3 | ||
|
|
df20b3df5a | ||
|
|
56e74dfd10 | ||
|
|
513d05143a | ||
|
|
84068943dd | ||
|
|
d3c75378ec | ||
|
|
ffe058bf69 | ||
|
|
765d95cd6f | ||
|
|
33e82222ca | ||
|
|
82d1c29696 | ||
|
|
211c9802a5 | ||
|
|
f5a81e71bd | ||
|
|
4ea7a864fa | ||
|
|
d645659770 | ||
|
|
75ec9c8f2c | ||
|
|
3bffdc2be0 | ||
|
|
820db09613 | ||
|
|
f24ae6feab | ||
|
|
5b09114b85 | ||
|
|
28c948e5ea | ||
|
|
bbf5a8f4aa | ||
|
|
5f2865883b | ||
|
|
c8433f950d | ||
|
|
9135e700c6 | ||
|
|
eb17568c94 | ||
|
|
407ff1e4a0 | ||
|
|
fbaaf63c49 | ||
|
|
f93daa3ca5 | ||
|
|
7fc1d04f9b | ||
|
|
d6a34f02ca | ||
|
|
fc3cb099c5 | ||
|
|
fc663d54fa | ||
|
|
bf2418db66 | ||
|
|
5bd75db0b6 | ||
|
|
13b3335a67 | ||
|
|
4987f9e668 | ||
|
|
e585aa6bed | ||
|
|
d6c7be760b | ||
|
|
a19321ea69 | ||
|
|
73fc1ac64e | ||
|
|
1d14764471 | ||
|
|
e336ecd9cc | ||
|
|
5737a96f9f | ||
|
|
d7d4ec54cd | ||
|
|
98056e26af | ||
|
|
afd07c9172 | ||
|
|
af785126bf | ||
|
|
39c5849604 | ||
|
|
1b6e465317 | ||
|
|
17e65cc772 | ||
|
|
15dff73cc8 | ||
|
|
186a15b3ce | ||
|
|
610e52d767 | ||
|
|
b0467fcb6d | ||
|
|
05be131647 | ||
|
|
f2300a5463 | ||
|
|
86acc99fb3 | ||
|
|
21909cee76 | ||
|
|
c97b53b52d | ||
|
|
c5e01146fd | ||
|
|
010ff3ec31 | ||
|
|
17532bfd82 | ||
|
|
545e9499c3 | ||
|
|
02046c5448 | ||
|
|
1d34d03ac8 | ||
|
|
e05aed0394 | ||
|
|
2d3b595a8b | ||
|
|
8f0b7683a1 | ||
|
|
f0d2cbb055 | ||
|
|
602c5e0ca0 | ||
|
|
2a2dff0eaf | ||
|
|
e1151e08c9 | ||
|
|
84f54ca3c7 | ||
|
|
5fb793b75f | ||
|
|
1adc9bfc70 | ||
|
|
3649fad485 | ||
|
|
0e1743738e | ||
|
|
6ad16302cd | ||
|
|
4b6b7af332 | ||
|
|
55dfb423ee | ||
|
|
9d1bc4817d | ||
|
|
fc8666e7a4 | ||
|
|
07b6881d67 | ||
|
|
1f208a06db | ||
|
|
b5c9c84542 | ||
|
|
492555bb4e | ||
|
|
53d88c0f63 | ||
|
|
8a5da57162 | ||
|
|
1627e2f47e | ||
|
|
e195d6ca55 | ||
|
|
71d5d4fb2c | ||
|
|
dfe13cda0d | ||
|
|
a4c6660d21 | ||
|
|
9676666e7c | ||
|
|
388133642d | ||
|
|
23b5eeb72f | ||
|
|
db36c3a7c2 | ||
|
|
e841b88cbc | ||
|
|
3d874f2479 | ||
|
|
228719102a | ||
|
|
c6ce1a248c | ||
|
|
ba9b85f64b | ||
|
|
56c868efee | ||
|
|
1f3c3832ba | ||
|
|
3b04a8c648 | ||
|
|
2270057b54 | ||
|
|
c3206aa9a4 | ||
|
|
1912d1b26a | ||
|
|
9208e7e594 | ||
|
|
ce332b3384 | ||
|
|
a567531f77 | ||
|
|
9cce72def0 | ||
|
|
2d8581c6dc | ||
|
|
14a000396a | ||
|
|
4c41f5a22f | ||
|
|
6be2a6e02a | ||
|
|
0a4fc16ca0 | ||
|
|
25d8377411 | ||
|
|
14267a788d | ||
|
|
ba5c5760b1 | ||
|
|
49904b3ab3 | ||
|
|
a212f035e4 | ||
|
|
ea471a6a17 | ||
|
|
f5bae0b696 | ||
|
|
9ec9e13aeb | ||
|
|
0b042b2681 | ||
|
|
83b4d12884 | ||
|
|
98d555498d | ||
|
|
fdc05cb977 | ||
|
|
928ebda5bc | ||
|
|
0a2003af66 |
@@ -5,6 +5,7 @@ insert_final_newline = true
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
|
||||
[*.{js,json}]
|
||||
indent_style = space
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -11,5 +11,5 @@ test/tmp
|
||||
coverage
|
||||
dist
|
||||
.package.json
|
||||
packages/6to5-runtime/*.js
|
||||
packages/6to5-runtime/regenerator/*.js
|
||||
packages/babel-runtime/*.js
|
||||
packages/babel-runtime/regenerator/*.js
|
||||
|
||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -3,7 +3,7 @@
|
||||
url = https://github.com/google/traceur-compiler
|
||||
[submodule "vendor/regenerator"]
|
||||
path = vendor/regenerator
|
||||
url = https://github.com/6to5/regenerator-6to5
|
||||
url = https://github.com/babel/regenerator-babel
|
||||
[submodule "vendor/test262"]
|
||||
path = vendor/test262
|
||||
url = https://github.com/tc39/test262
|
||||
|
||||
2
.jscsrc
2
.jscsrc
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"excludeFiles": ["lib/6to5/transformation/templates"],
|
||||
"excludeFiles": ["lib/babel/transformation/templates"],
|
||||
"disallowSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
|
||||
@@ -1 +1 @@
|
||||
lib/6to5/transformation/templates
|
||||
lib/babel/transformation/templates
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
node_modules
|
||||
*.log
|
||||
*.cache
|
||||
lib/6to5/transformation/templates
|
||||
lib/babel/transformation/templates
|
||||
test
|
||||
benchmark
|
||||
Makefile
|
||||
|
||||
@@ -2,8 +2,8 @@ sudo: false
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
|
||||
branches:
|
||||
except:
|
||||
|
||||
1093
CHANGELOG-6to5.md
Normal file
1093
CHANGELOG-6to5.md
Normal file
File diff suppressed because it is too large
Load Diff
1059
CHANGELOG.md
1059
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
|
||||
Contributions are always welcome, no matter how large or small. Before
|
||||
contributing, please read the
|
||||
[code of conduct](https://github.com/6to5/6to5/blob/master/CODE_OF_CONDUCT.md).
|
||||
[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
|
||||
@@ -13,7 +13,7 @@ pollutes the git tree.
|
||||
#### Workflow
|
||||
|
||||
* Fork the repository
|
||||
* Clone your fork and change directory to it (`git clone git@github.com:yourUserName/6to5.git && cd 6to5`)
|
||||
* Clone your fork and change directory to it (`git clone git@github.com:yourUserName/babel.git && cd babel`)
|
||||
* Install the project dependencies (`make bootstrap`)
|
||||
* Link your forked clone (`npm link`)
|
||||
* Develop your changes ensuring you're fetching updates from upstream often
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2014-2015 Sebastian McKenzie
|
||||
Copyright (c) 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
|
||||
|
||||
MIT License
|
||||
|
||||
|
||||
37
Makefile
37
Makefile
@@ -5,31 +5,31 @@ UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
JSCS_CMD = node_modules/jscs/bin/jscs
|
||||
6TO5_CMD = node_modules/6to5/bin/6to5
|
||||
BABEL_CMD = node_modules/babel/bin/babel
|
||||
|
||||
export NODE_ENV = test
|
||||
|
||||
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core
|
||||
|
||||
build-core:
|
||||
#node $(6TO5_CMD) src --out-dir lib
|
||||
#node $(BABEL_CMD) src --out-dir lib
|
||||
|
||||
watch-core:
|
||||
#node $(6TO5_CMD) src --out-dir lib --watch
|
||||
#node $(BABEL_CMD) src --out-dir lib --watch
|
||||
|
||||
build:
|
||||
mkdir -p dist
|
||||
|
||||
node tools/cache-templates
|
||||
|
||||
node $(BROWSERIFY_CMD) -e lib/6to5/polyfill.js >dist/polyfill.js
|
||||
node $(BROWSERIFY_CMD) -e lib/babel/polyfill.js >dist/polyfill.js
|
||||
node $(UGLIFY_CMD) dist/polyfill.js >dist/polyfill.min.js
|
||||
|
||||
node $(BROWSERIFY_CMD) lib/6to5/api/browser.js -s to5 >dist/6to5.js
|
||||
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
|
||||
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel >dist/babel.js
|
||||
node $(UGLIFY_CMD) dist/babel.js >dist/babel.min.js
|
||||
|
||||
node bin/6to5-runtime >dist/runtime.js
|
||||
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
|
||||
node bin/babel-external-helpers >dist/external-helpers.js
|
||||
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
||||
|
||||
rm -rf templates.json
|
||||
|
||||
@@ -49,17 +49,16 @@ test: lint
|
||||
|
||||
test-simple:
|
||||
# excludes test262
|
||||
export SIMPLE_6TO5_TESTS=1; \
|
||||
export SIMPLE_BABEL_TESTS=1; \
|
||||
make test
|
||||
|
||||
test-all:
|
||||
# includes traceur, esnext, regenerator
|
||||
export ALL_6TO5_TESTS=1; \
|
||||
export ALL_BABEL_TESTS=1; \
|
||||
make test
|
||||
|
||||
test-cov:
|
||||
rm -rf coverage
|
||||
export SIMPLE_6TO5_TESTS=1; \
|
||||
export SIMPLE_BABEL_TESTS=1; \
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
|
||||
test-travis: build-core bootstrap
|
||||
@@ -71,7 +70,7 @@ test-browser:
|
||||
|
||||
node tools/cache-templates
|
||||
node tools/cache-tests
|
||||
node $(BROWSERIFY_CMD) -e test/_browser.js >dist/6to5-test.js
|
||||
node $(BROWSERIFY_CMD) -e test/_browser.js >dist/babel-test.js
|
||||
rm -rf templates.json tests.json
|
||||
|
||||
test -n "`which open`" && open test/browser.html
|
||||
@@ -85,9 +84,9 @@ publish:
|
||||
npm version $$version --message "v%s"
|
||||
|
||||
make build
|
||||
cp dist/6to5.min.js browser.js
|
||||
cp dist/babel.min.js browser.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/runtime.min.js runtime.js
|
||||
cp dist/external-helpers.min.js external-helpers.js
|
||||
|
||||
node tools/cache-templates
|
||||
test -f templates.json
|
||||
@@ -99,12 +98,12 @@ publish:
|
||||
make publish-core
|
||||
make publish-runtime
|
||||
|
||||
rm -rf templates.json browser.js browser-polyfill.js runtime.js
|
||||
rm -rf templates.json browser.js browser-polyfill.js external-helpers.js
|
||||
|
||||
publish-runtime:
|
||||
cd packages; \
|
||||
node build-runtime.js; \
|
||||
cd 6to5-runtime; \
|
||||
cd babel-runtime; \
|
||||
npm publish
|
||||
|
||||
publish-core:
|
||||
@@ -120,5 +119,5 @@ publish-core:
|
||||
bootstrap:
|
||||
npm install
|
||||
git submodule update --init
|
||||
cd vendor/regenerator; npm install
|
||||
cd vendor/compat-table; npm install object-assign
|
||||
cd vendor/regenerator && npm install
|
||||
cd vendor/compat-table && npm install object-assign
|
||||
|
||||
3
NOTES.md
3
NOTES.md
@@ -1,3 +0,0 @@
|
||||
# Notes
|
||||
|
||||
* Wildcard exports/imports wont normalize if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224).
|
||||
15
README.md
15
README.md
@@ -1,12 +1,19 @@
|
||||
<p align="center">
|
||||
<img alt="6to5" src="https://raw.githubusercontent.com/6to5/logo/master/logo.png" width="546">
|
||||
<a href="https://babeljs.io/">
|
||||
<img alt="babel" src="https://raw.githubusercontent.com/babel/logo/master/logo.png" width="546">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<strong>6to5</strong> turns ES6+ code into vanilla ES5, so you can use next generation features <strong>today.</strong>
|
||||
<strong>Babel</strong> is a transpiler for writing next generation JavaScript.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
For more information view the <a href="https://6to5.github.io">documentation</a>. For
|
||||
support visit the <a href="https://gitter.im/6to5/6to5">gitter room</a>.
|
||||
For more information view the <a href="https://babeljs.io/">documentation</a>. For questions
|
||||
and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> before
|
||||
creating an issue.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
For documentation and website issues please visit the <a href="https://github.com/babel/babel.github.io">babel.github.io</a> repo.
|
||||
</p>
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var opts = require("./6to5").opts;
|
||||
opts.optional = (opts.optional || []).concat("minification");
|
||||
opts.format = {
|
||||
compact: true
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/6to5/build-runtime");
|
||||
console.log(runtime());
|
||||
@@ -1,15 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var Module = require("module");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
var to5 = require("../lib/6to5/api/node");
|
||||
var util = require("../lib/6to5/util");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
var pathIsAbsolute = require("path-is-absolute");
|
||||
var commander = require("commander");
|
||||
var Module = require("module");
|
||||
var babel = require("../lib/babel/api/node");
|
||||
var path = require("path");
|
||||
var repl = require("repl");
|
||||
var util = require("../lib/babel/util");
|
||||
var vm = require("vm");
|
||||
var _ = require("lodash");
|
||||
|
||||
var program = new commander.Command("6to5-node");
|
||||
var program = new commander.Command("babel-node");
|
||||
|
||||
program.option("-e, --eval [script]", "Evaluate script");
|
||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
||||
@@ -28,7 +29,7 @@ program.parse(process.argv);
|
||||
|
||||
//
|
||||
|
||||
to5.register({
|
||||
babel.register({
|
||||
experimental: program.experimental,
|
||||
extensions: program.extensions,
|
||||
playground: program.playground,
|
||||
@@ -41,7 +42,7 @@ to5.register({
|
||||
//
|
||||
|
||||
var _eval = function (code, filename) {
|
||||
code = to5.transform(code, {
|
||||
code = babel.transform(code, {
|
||||
filename: filename,
|
||||
blacklist: ["useStrict"].concat(program.blacklist || []),
|
||||
whitelist: program.whitelist,
|
||||
@@ -49,7 +50,10 @@ var _eval = function (code, filename) {
|
||||
experimental: program.experimental,
|
||||
playground: program.playground
|
||||
}).code;
|
||||
return vm.runInThisContext(code, filename);
|
||||
|
||||
return vm.runInThisContext(code, {
|
||||
filename: filename
|
||||
});
|
||||
};
|
||||
|
||||
if (program.eval || program.print) {
|
||||
@@ -60,7 +64,7 @@ if (program.eval || program.print) {
|
||||
if (program.print) console.log(result);
|
||||
} else {
|
||||
if (program.args.length) {
|
||||
// slice all arguments up to the first filename since they're 6to5 args that we handle
|
||||
// slice all arguments up to the first filename since they're babel args that we handle
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
var i = 0;
|
||||
@@ -85,7 +89,7 @@ if (program.eval || program.print) {
|
||||
|
||||
// make the filename absolute
|
||||
var filename = args[0]
|
||||
if (!util.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
|
||||
|
||||
// add back on node and concat the sliced args
|
||||
process.argv = ["node"].concat(args);
|
||||
4
bin/babel-external-helpers
Executable file
4
bin/babel-external-helpers
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var runtime = require("../lib/babel/build-external-helpers");
|
||||
console.log(runtime());
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
/**
|
||||
* This tiny wrapper file checks for known node flags and appends them
|
||||
* when found, before invoking the "real" _6to5-node(1) executable.
|
||||
* when found, before invoking the "real" _babel-node(1) executable.
|
||||
*/
|
||||
|
||||
var args = [__dirname + "/_6to5-node"];
|
||||
var args = [__dirname + "/_babel-node"];
|
||||
|
||||
process.argv.slice(2).forEach(function(arg){
|
||||
var flag = arg.split("=")[0];
|
||||
@@ -16,7 +16,9 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
var dest = path.join(commander.outDir, relative);
|
||||
|
||||
var data = util.compile(src, { sourceMapName: dest });
|
||||
var data = util.compile(src, {
|
||||
sourceFileName: path.relative(dest + "/..", src)
|
||||
});
|
||||
|
||||
if (commander.sourceMaps) {
|
||||
var mapLoc = dest + ".map";
|
||||
@@ -1,10 +1,10 @@
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var util2 = require("../../lib/6to5/util");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
var sourceMapToComment = require("source-map-to-comment");
|
||||
var sourceMap = require("source-map");
|
||||
var chokidar = require("chokidar");
|
||||
var path = require("path");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (commander, filenames) {
|
||||
var results = [];
|
||||
@@ -42,7 +42,7 @@ module.exports = function (commander, filenames) {
|
||||
});
|
||||
|
||||
if (commander.sourceMapsInline || (!commander.outFile && commander.sourceMaps)) {
|
||||
code += "\n" + util2.sourceMapToComment(map);
|
||||
code += "\n" + sourceMapToComment(map);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var transform = require("../../lib/6to5/transformation");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var transform = require("../../lib/babel/transformation");
|
||||
var util = require("../../lib/babel/util");
|
||||
var fs = require("fs");
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
@@ -11,10 +11,11 @@ commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to
|
||||
commander.option("-s, --source-maps", "Save source map alongside the compiled code");
|
||||
commander.option("-f, --filename [filename]", "Filename to use when reading from stdin - this will be used in source-maps, errors etc [stdin]", "stdin");
|
||||
commander.option("-w, --watch", "Recompile files on changes");
|
||||
commander.option("-r, --runtime", "Replace 6to5 declarations with references to a runtime");
|
||||
commander.option("-r, --external-helpers", "Replace helpers with references to a `babelHelpers` global");
|
||||
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
||||
commander.option("-p, --playground", "Enable playground support");
|
||||
|
||||
commander.option("-c, --compact [mode]", "When set to \"auto\" compact is `true` when the input size exceeds 100KB. (auto|true|false)", "auto");
|
||||
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||
@@ -26,6 +27,7 @@ commander.option("-c, --remove-comments", "Remove comments from the compiled cod
|
||||
commander.option("-M, --module-ids", "Insert module id in modules", false);
|
||||
commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code");
|
||||
commander.option("--keep-module-id-extensions", "Keep extensions when generating module ids", false);
|
||||
commander.option("-a, --auxiliary-comment [comment]", "Comment text to prepend to all auxiliary code");
|
||||
|
||||
commander.on("--help", function () {
|
||||
var outKeys = function (title, obj) {
|
||||
@@ -99,6 +101,8 @@ if (errors.length) {
|
||||
|
||||
exports.opts = {
|
||||
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
||||
auxiliaryComment: commander.auxiliaryComment,
|
||||
externalHelpers: commander.externalHelpers,
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
reactCompat: commander.reactCompat,
|
||||
@@ -109,22 +113,17 @@ exports.opts = {
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
compact: commander.compact,
|
||||
loose: commander.loose
|
||||
};
|
||||
|
||||
setTimeout(function () {
|
||||
// this is just a hack to give `6to5-minify` and other files including this
|
||||
// time to modify `exports.opts`
|
||||
var fn;
|
||||
|
||||
var fn;
|
||||
if (commander.outDir) {
|
||||
fn = require("./dir");
|
||||
} else {
|
||||
fn = require("./file");
|
||||
}
|
||||
|
||||
if (commander.outDir) {
|
||||
fn = require("./dir");
|
||||
} else {
|
||||
fn = require("./file");
|
||||
}
|
||||
|
||||
fn(commander, filenames, exports.opts);
|
||||
}, 0);
|
||||
fn(commander, filenames, exports.opts);
|
||||
@@ -1,8 +1,8 @@
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var index = require("./index");
|
||||
var util = require("../../lib/6to5/util");
|
||||
var babel = require("../../lib/babel/api/node");
|
||||
var util = require("../../lib/babel/util");
|
||||
var path = require("path");
|
||||
var to5 = require("../../lib/6to5/api/node");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -21,12 +21,12 @@ exports.addSourceMappingUrl = function (code, loc) {
|
||||
};
|
||||
|
||||
exports.transform = function (filename, code, opts) {
|
||||
opts = _.extend(opts || {}, index.opts);
|
||||
opts = _.defaults(opts || {}, index.opts);
|
||||
opts.filename = filename;
|
||||
|
||||
var result;
|
||||
try {
|
||||
result = to5.transform(code, opts);
|
||||
result = babel.transform(code, opts);
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
console.error("SyntaxError:", e.message);
|
||||
3
bin/deprecated/6to5
Executable file
3
bin/deprecated/6to5
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
console.error("`6to5` has been renamed to `babel`");
|
||||
require("../babel");
|
||||
3
bin/deprecated/6to5-node
Executable file
3
bin/deprecated/6to5-node
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
console.error("`6to5-node` has been renamed to `babel-node`");
|
||||
require("../_babel-node");
|
||||
3
bin/deprecated/6to5-runtime
Executable file
3
bin/deprecated/6to5-runtime
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
console.error("`6to5-runtime` has been renamed to `babel-external-helpers`");
|
||||
require("../babel-external-helpers");
|
||||
@@ -1 +1 @@
|
||||
See [6to5.github.io/docs](https://github.com/6to5/6to5.github.io/tree/master/docs).
|
||||
See [babel.github.io/docs](https://github.com/babel/babel.github.io/tree/master/docs).
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
var map = require("lodash/collection/map");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
|
||||
exports.before = {
|
||||
nodes: {
|
||||
Property: function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
SpreadProperty: function (node, parent) {
|
||||
return exports.before.nodes.Property(node, parent);
|
||||
},
|
||||
|
||||
SwitchCase: function (node, parent) {
|
||||
if (parent.cases[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression: function (node) {
|
||||
if (t.isFunction(node.callee)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.after = {
|
||||
nodes: {
|
||||
LogicalExpression: function (node) {
|
||||
return t.isFunction(node.left) || t.isFunction(node.right);
|
||||
},
|
||||
|
||||
AssignmentExpression: function (node) {
|
||||
if (t.isFunction(node.right)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
list: {
|
||||
VariableDeclaration: function (node) {
|
||||
return map(node.declarations, "init");
|
||||
},
|
||||
|
||||
ArrayExpression: function (node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
ObjectExpression: function (node) {
|
||||
return node.properties;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
each({
|
||||
Function: 1,
|
||||
Class: 1,
|
||||
For: 1,
|
||||
ArrayExpression: { after: 1 },
|
||||
ObjectExpression: { after: 1 },
|
||||
SwitchStatement: 1,
|
||||
IfStatement: { before: 1 },
|
||||
CallExpression: { after: 1 },
|
||||
Literal: { after: 1 }
|
||||
}, function (amounts, type) {
|
||||
if (isNumber(amounts)) {
|
||||
amounts = { after: amounts, before: amounts };
|
||||
}
|
||||
|
||||
each([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) {
|
||||
each(amounts, function (amount, key) {
|
||||
exports[key].nodes[type] = function () {
|
||||
return amount;
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function cloneDeep(obj) {
|
||||
var obj2 = {};
|
||||
if (!obj) return obj2;
|
||||
|
||||
for (var key in obj) {
|
||||
obj2[key] = obj[key];
|
||||
}
|
||||
|
||||
return obj2;
|
||||
};
|
||||
@@ -1,79 +0,0 @@
|
||||
// syntax highlighting based on https://github.com/dominictarr/ansi-highlight by the fantastic Dominic Tarr
|
||||
|
||||
var supportsColor = require("supports-color");
|
||||
var tokenize = require("js-tokenizer");
|
||||
var chalk = require("chalk");
|
||||
var util = require("../util");
|
||||
|
||||
var defs = {
|
||||
string1: "red",
|
||||
string2: "red",
|
||||
punct: ["white", "bold"],
|
||||
curly: "green",
|
||||
parens: ["blue", "bold"],
|
||||
square: ["yellow"],
|
||||
name: "white",
|
||||
keyword: ["cyan"],
|
||||
number: "magenta",
|
||||
regexp: "magenta",
|
||||
comment1: "grey",
|
||||
comment2: "grey"
|
||||
};
|
||||
|
||||
var highlight = function (text) {
|
||||
var colorize = function (str, col) {
|
||||
if (!col) return str;
|
||||
|
||||
if (Array.isArray(col)) {
|
||||
col.forEach(function (col) {
|
||||
str = chalk[col](str);
|
||||
});
|
||||
} else {
|
||||
str = chalk[col](str);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
return tokenize(text, true).map(function (str) {
|
||||
var type = tokenize.type(str);
|
||||
return colorize(str, defs[type]);
|
||||
}).join("");
|
||||
};
|
||||
|
||||
module.exports = function (lines, lineNumber, colNumber) {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
if (supportsColor) {
|
||||
lines = highlight(lines);
|
||||
}
|
||||
|
||||
lines = lines.split(/\r\n|[\n\r\u2028\u2029]/);
|
||||
|
||||
var start = Math.max(lineNumber - 3, 0);
|
||||
var end = Math.min(lines.length, lineNumber + 3);
|
||||
var width = (end + "").length;
|
||||
|
||||
if (!lineNumber && !colNumber) {
|
||||
start = 0;
|
||||
end = lines.length;
|
||||
}
|
||||
|
||||
return "\n" + lines.slice(start, end).map(function (line, i) {
|
||||
var curr = i + start + 1;
|
||||
|
||||
var gutter = curr === lineNumber ? "> " : " ";
|
||||
|
||||
var sep = curr + util.repeat(width + 1);
|
||||
gutter += sep + "| ";
|
||||
|
||||
var str = gutter + line;
|
||||
|
||||
if (colNumber && curr === lineNumber) {
|
||||
str += "\n";
|
||||
str += util.repeat(gutter.length - 2);
|
||||
str += "|" + util.repeat(colNumber) + "^";
|
||||
}
|
||||
|
||||
return str;
|
||||
}).join("\n");
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
// taken from stackoverflow, it's crap i know.
|
||||
|
||||
module.exports = function (a, b) {
|
||||
if (a.length === 0) return b.length;
|
||||
if (b.length === 0) return a.length;
|
||||
|
||||
var matrix = [];
|
||||
|
||||
// increment along the first column of each row
|
||||
var i;
|
||||
for (i = 0; i <= b.length; i++) {
|
||||
matrix[i] = [i];
|
||||
}
|
||||
|
||||
// increment each column in the first row
|
||||
var j;
|
||||
for (j = 0; j <= a.length; j++) {
|
||||
matrix[0][j] = j;
|
||||
}
|
||||
|
||||
// Fill in the rest of the matrix
|
||||
for (i = 1; i <= b.length; i++) {
|
||||
for (j = 1; j <= a.length; j++) {
|
||||
if (b.charAt(i - 1) == a.charAt(j - 1)) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1];
|
||||
} else {
|
||||
matrix[i][j] = Math.min(
|
||||
matrix[i - 1][j - 1] + 1, // substitution
|
||||
Math.min(
|
||||
matrix[i][j - 1] + 1, // insertion
|
||||
matrix[i - 1][j] + 1) // deletion
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matrix[b.length][a.length];
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
if (global._6to5Polyfill) {
|
||||
throw new Error("only one instance of 6to5/polyfill is allowed");
|
||||
}
|
||||
global._6to5Polyfill = true;
|
||||
|
||||
require("core-js/shim");
|
||||
require("regenerator-6to5/runtime");
|
||||
@@ -1,53 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
// check if this node is an identifier that matches the same as our function id
|
||||
if (!t.isIdentifier(node, { name: state.id })) return;
|
||||
|
||||
// check if this node is the one referenced
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.getBindingIdentifier(state.id);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
|
||||
state.selfReference = true;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
|
||||
exports.property = function (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
|
||||
|
||||
var id = t.toIdentifier(key.value);
|
||||
key = t.identifier(id);
|
||||
|
||||
var state = {
|
||||
id: id,
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(id),
|
||||
};
|
||||
|
||||
scope.traverse(node, visitor, state);
|
||||
|
||||
var method = node.value;
|
||||
|
||||
if (state.selfReference) {
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
node.value = util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: key,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id),
|
||||
WRAPPER_KEY: scope.generateUidIdentifier(id + "Wrapper")
|
||||
});
|
||||
} else {
|
||||
method.id = key;
|
||||
}
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var t = require("../../types");
|
||||
|
||||
exports.has = function (node) {
|
||||
var first = node.body[0];
|
||||
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
|
||||
};
|
||||
|
||||
exports.wrap = function (node, callback) {
|
||||
var useStrictNode;
|
||||
if (exports.has(node)) {
|
||||
useStrictNode = node.body.shift();
|
||||
}
|
||||
|
||||
callback();
|
||||
|
||||
if (useStrictNode) {
|
||||
node.body.unshift(useStrictNode);
|
||||
}
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = CommonStandardFormatter;
|
||||
|
||||
var CommonStrictFormatter = require("./common-strict");
|
||||
var util = require("../../util");
|
||||
|
||||
function CommonStandardFormatter() {
|
||||
this.noInteropRequireImport = true;
|
||||
CommonStrictFormatter.apply(this, arguments);
|
||||
}
|
||||
|
||||
util.inherits(CommonStandardFormatter, CommonStrictFormatter);
|
||||
@@ -1,11 +0,0 @@
|
||||
module.exports = {
|
||||
commonStandard: require("./common-standard"),
|
||||
commonStrict: require("./common-strict"),
|
||||
amdStrict: require("./amd-strict"),
|
||||
umdStrict: require("./umd-strict"),
|
||||
common: require("./common"),
|
||||
system: require("./system"),
|
||||
ignore: require("./ignore"),
|
||||
amd: require("./amd"),
|
||||
umd: require("./umd")
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
FUNCTION_ID:while (true) BLOCK
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
(function () {
|
||||
function Tail(func, args, context) {
|
||||
this.func = func;
|
||||
this.args = args;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
Tail.prototype._isTailDescriptor = true;
|
||||
|
||||
var isRunning = false;
|
||||
|
||||
return function (func, args, context) {
|
||||
var result = new Tail(func, args, context);
|
||||
if (!isRunning) {
|
||||
isRunning = true;
|
||||
do {
|
||||
result = result.func.apply(result.context, result.args);
|
||||
} while (result instanceof Tail || (result && result._isTailDescriptor));
|
||||
isRunning = false;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
})()
|
||||
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"specNoForInOfAssignment": "validation.noForInOfAssignment",
|
||||
"specSetters": "validation.setters",
|
||||
"specBlockScopedFunctions": "spec.blockScopedFunctions",
|
||||
"malletOperator": "playground.malletOperator",
|
||||
"methodBinding": "playground.methodBinding",
|
||||
"memoizationOperator": "playground.memoizationOperator",
|
||||
"objectGetterMemoization": "playground.objectGetterMemoization",
|
||||
"modules": "es6.modules",
|
||||
"propertyNameShorthand": "es6.properties.shorthand",
|
||||
"arrayComprehension": "es7.comprehensions",
|
||||
"generatorComprehension": "es7.comprehensions",
|
||||
"arrowFunctions": "es6.arrowFunctions",
|
||||
"classes": "es6.classes",
|
||||
"objectSpread": "es7.objectRestSpread",
|
||||
"es7.objectSpread": "es7.objectRestSpread",
|
||||
"exponentiationOperator": "es7.exponentiationOperator",
|
||||
"spread": "es6.spread",
|
||||
"templateLiterals": "es6.templateLiterals",
|
||||
"propertyMethodAssignment": "es6.properties.shorthand",
|
||||
"computedPropertyNames": "es6.properties.computed",
|
||||
"defaultParameters": "es6.parameters.default",
|
||||
"restParameters": "es6.parameters.rest",
|
||||
"destructuring": "es6.destructuring",
|
||||
"forOf": "es6.forOf",
|
||||
"unicodeRegex": "es6.unicodeRegex",
|
||||
"abstractReferences": "es7.abstractReferences",
|
||||
"constants": "es6.constants",
|
||||
"letScoping": "es6.letScoping",
|
||||
"blockScopingTDZ": "es6.blockScopingTDZ",
|
||||
"generators": "regenerator",
|
||||
"protoToAssign": "spec.protoToAssign",
|
||||
"typeofSymbol": "spec.typeofSymbol",
|
||||
"coreAliasing": "selfContained",
|
||||
"undefinedToVoid": "spec.undefinedToVoid",
|
||||
"undeclaredVariableCheck": "validation.undeclaredVariableCheck",
|
||||
"specPropertyLiterals": "es3.propertyLiterals",
|
||||
"specMemberExpressionLiterals": "es3.memberExpressionLiterals",
|
||||
"minification.propertyLiterals": "es3.propertyLiterals",
|
||||
"minification.memberExpressionLiterals": "es3.memberExpressionLiterals"
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var groupBy = require("lodash/collection/groupBy");
|
||||
var flatten = require("lodash/array/flatten");
|
||||
var values = require("lodash/object/values");
|
||||
|
||||
// Priority:
|
||||
//
|
||||
// - 0 We want this to be at the **very** bottom
|
||||
// - 1 Default node position
|
||||
// - 2 Priority over normal nodes
|
||||
// - 3 We want this to be at the **very** top
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = {
|
||||
exit: function (node) {
|
||||
var hasChange = false;
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (bodyNode && bodyNode._blockHoist != null) hasChange = true;
|
||||
}
|
||||
if (!hasChange) return;
|
||||
|
||||
useStrict.wrap(node, function () {
|
||||
var nodePriorities = groupBy(node.body, function (bodyNode) {
|
||||
var priority = bodyNode._blockHoist;
|
||||
if (priority == null) priority = 1;
|
||||
if (priority === true) priority = 2;
|
||||
return priority;
|
||||
});
|
||||
|
||||
node.body = flatten(values(nodePriorities).reverse());
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.secondPass = true;
|
||||
|
||||
exports.BlockStatement =
|
||||
exports.Program = function (node) {
|
||||
if (!node._declarations) return;
|
||||
|
||||
var kinds = {};
|
||||
var kind;
|
||||
|
||||
useStrict.wrap(node, function () {
|
||||
for (var i in node._declarations) {
|
||||
var declar = node._declarations[i];
|
||||
|
||||
kind = declar.kind || "var";
|
||||
var declarNode = t.variableDeclarator(declar.id, declar.init);
|
||||
|
||||
if (!declar.init) {
|
||||
kinds[kind] = kinds[kind] || [];
|
||||
kinds[kind].push(declarNode);
|
||||
} else {
|
||||
node.body.unshift(t.variableDeclaration(kind, [declarNode]));
|
||||
}
|
||||
}
|
||||
|
||||
for (kind in kinds) {
|
||||
node.body.unshift(t.variableDeclaration(kind, kinds[kind]));
|
||||
}
|
||||
});
|
||||
|
||||
node._declarations = null;
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
|
||||
exports.post = function (file) {
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
var program = file.ast.program;
|
||||
|
||||
useStrict.wrap(program, function () {
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
|
||||
if (file.moduleFormatter.transform) {
|
||||
file.moduleFormatter.transform(program);
|
||||
}
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var react = require("../../helpers/react");
|
||||
var t = require("../../../types");
|
||||
|
||||
require("../../helpers/build-react-transformer")(exports, {
|
||||
pre: function (state) {
|
||||
var tagName = state.tagName;
|
||||
var args = state.args;
|
||||
if (react.isCompatTag(tagName)) {
|
||||
args.push(t.literal(tagName));
|
||||
} else {
|
||||
args.push(state.tagExpr);
|
||||
}
|
||||
},
|
||||
|
||||
post: function (state) {
|
||||
state.callee = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
|
||||
}
|
||||
});
|
||||
@@ -1,20 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.post = function (file) {
|
||||
var program = file.ast.program;
|
||||
if (!useStrict.has(program)) {
|
||||
program.body.unshift(t.expressionStatement(t.literal("use strict")));
|
||||
}
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function () {
|
||||
this.skip();
|
||||
};
|
||||
|
||||
exports.ThisExpression = function () {
|
||||
return t.identifier("undefined");
|
||||
};
|
||||
@@ -38,7 +38,7 @@ transform.load = function (url, callback, opts, hold) {
|
||||
|
||||
var runScripts = function () {
|
||||
var scripts = [];
|
||||
var types = ["text/ecmascript-6", "text/6to5", "module"];
|
||||
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||
var index = 0;
|
||||
|
||||
var exec = function () {
|
||||
@@ -7,7 +7,7 @@ var fs = require("fs");
|
||||
|
||||
exports.version = require("../../../package").version;
|
||||
|
||||
exports.runtime = require("../build-runtime");
|
||||
exports.buildExternalHelpers = require("../build-external-helpers");
|
||||
|
||||
exports.types = require("../types");
|
||||
|
||||
@@ -23,7 +23,7 @@ exports.polyfill = function () {
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
|
||||
// do not use this - this is for use by official maintained 6to5 plugins
|
||||
// do not use this - this is for use by official maintained babel plugins
|
||||
exports._util = util;
|
||||
|
||||
exports.transform = transform;
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
// required to safely use 6to5/register within a browserify codebase
|
||||
// required to safely use babel/register within a browserify codebase
|
||||
|
||||
module.exports = function () {};
|
||||
|
||||
@@ -4,7 +4,7 @@ var path = require("path");
|
||||
var os = require("os");
|
||||
var fs = require("fs");
|
||||
|
||||
var FILENAME = path.join(os.tmpdir(), "6to5.json");
|
||||
var FILENAME = process.env.BABEL_CACHE_PATH || path.join(os.tmpdir(), "babel.json");
|
||||
var data = {};
|
||||
|
||||
exports.save = function () {
|
||||
@@ -12,6 +12,8 @@ exports.save = function () {
|
||||
};
|
||||
|
||||
exports.load = function () {
|
||||
if (process.env.BABEL_DISABLE_CACHE) return;
|
||||
|
||||
process.on("exit", exports.save);
|
||||
|
||||
var sigint = function () {
|
||||
@@ -5,9 +5,9 @@ require("../../polyfill");
|
||||
var sourceMapSupport = require("source-map-support");
|
||||
var registerCache = require("./cache");
|
||||
var extend = require("lodash/object/extend");
|
||||
var babel = require("../node");
|
||||
var each = require("lodash/collection/each");
|
||||
var util = require("../../util");
|
||||
var to5 = require("../node");
|
||||
var fs = require("fs");
|
||||
|
||||
sourceMapSupport.install({
|
||||
@@ -54,7 +54,7 @@ var compile = function (filename) {
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
result = to5.transformFileSync(filename, extend({
|
||||
result = babel.transformFileSync(filename, extend({
|
||||
sourceMap: true,
|
||||
ast: false
|
||||
}, transformOpts));
|
||||
@@ -6,7 +6,7 @@ var util = require("./util");
|
||||
var t = require("./types");
|
||||
|
||||
module.exports = function () {
|
||||
var namespace = t.identifier("to5Runtime");
|
||||
var namespace = t.identifier("babelHelpers");
|
||||
|
||||
var body = [];
|
||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
module.exports = Buffer;
|
||||
|
||||
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");
|
||||
var util = require("../util");
|
||||
|
||||
function Buffer(position, format) {
|
||||
this.position = position;
|
||||
@@ -15,14 +16,14 @@ function Buffer(position, format) {
|
||||
}
|
||||
|
||||
Buffer.prototype.get = function () {
|
||||
return util.trimRight(this.buf);
|
||||
return trimRight(this.buf);
|
||||
};
|
||||
|
||||
Buffer.prototype.getIndent = function () {
|
||||
if (this.format.compact || this.format.concise) {
|
||||
return "";
|
||||
} else {
|
||||
return util.repeat(this._indent, this.format.indent.style);
|
||||
return repeating(this.format.indent.style, this._indent);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -58,13 +59,13 @@ Buffer.prototype.keyword = function (name) {
|
||||
|
||||
Buffer.prototype.space = function () {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (this.buf && !this.isLast([" ", "\n"])) {
|
||||
if (this.buf && !this.isLast(" ") && !this.isLast("\n")) {
|
||||
this.push(" ");
|
||||
}
|
||||
};
|
||||
|
||||
Buffer.prototype.removeLast = function (cha) {
|
||||
if (this.format.compact) return;
|
||||
if (!this.isLast(cha)) return;
|
||||
|
||||
this.buf = this.buf.substr(0, this.buf.length - 1);
|
||||
@@ -72,7 +73,9 @@ Buffer.prototype.removeLast = function (cha) {
|
||||
};
|
||||
|
||||
Buffer.prototype.newline = function (i, removeLast) {
|
||||
if (this.format.compact || this.format.concise) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (this.format.concise) {
|
||||
this.space();
|
||||
return;
|
||||
}
|
||||
@@ -80,11 +83,14 @@ Buffer.prototype.newline = function (i, removeLast) {
|
||||
removeLast = removeLast || false;
|
||||
|
||||
if (isNumber(i)) {
|
||||
if (this.endsWith("{\n")) i--;
|
||||
if (this.endsWith(util.repeat(i, "\n"))) return;
|
||||
i = Math.min(2, i);
|
||||
|
||||
while (i--) {
|
||||
if (this.endsWith("{\n") || this.endsWith(":\n")) i--;
|
||||
if (i <= 0) return;
|
||||
|
||||
while (i > 0) {
|
||||
this._newline(removeLast);
|
||||
i--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -97,11 +103,13 @@ Buffer.prototype.newline = function (i, removeLast) {
|
||||
};
|
||||
|
||||
Buffer.prototype._newline = function (removeLast) {
|
||||
// never allow more than two lines
|
||||
if (this.endsWith("\n\n")) return;
|
||||
|
||||
// remove the last newline
|
||||
if (removeLast && this.isLast("\n")) this.removeLast("\n");
|
||||
|
||||
this.removeLast(" ");
|
||||
|
||||
// remove whitespace if last character was a newline
|
||||
this._removeSpacesAfterLastNewline();
|
||||
this._push("\n");
|
||||
};
|
||||
@@ -109,6 +117,7 @@ Buffer.prototype._newline = function (removeLast) {
|
||||
/**
|
||||
* If buffer ends with a newline and some spaces after it, trim those spaces.
|
||||
*/
|
||||
|
||||
Buffer.prototype._removeSpacesAfterLastNewline = function () {
|
||||
var lastNewlineIndex = this.buf.lastIndexOf("\n");
|
||||
if (lastNewlineIndex === -1)
|
||||
@@ -129,7 +138,7 @@ Buffer.prototype._removeSpacesAfterLastNewline = function () {
|
||||
};
|
||||
|
||||
Buffer.prototype.push = function (str, noIndent) {
|
||||
if (this._indent && !noIndent && str !== "\n") {
|
||||
if (!this.format.compact && this._indent && !noIndent && str !== "\n") {
|
||||
// we have an indent level and we aren't pushing a newline
|
||||
var indent = this.getIndent();
|
||||
|
||||
@@ -137,7 +146,7 @@ Buffer.prototype.push = function (str, noIndent) {
|
||||
str = str.replace(/\n/g, "\n" + indent);
|
||||
|
||||
// we've got a newline before us so prepend on the indentation
|
||||
if (this.isLast("\n")) str = indent + str;
|
||||
if (this.isLast("\n")) this._push(indent);
|
||||
}
|
||||
|
||||
this._push(str);
|
||||
@@ -149,13 +158,13 @@ Buffer.prototype._push = function (str) {
|
||||
};
|
||||
|
||||
Buffer.prototype.endsWith = function (str) {
|
||||
var d = this.buf.length - str.length;
|
||||
return d >= 0 && this.buf.lastIndexOf(str) === d;
|
||||
return this.buf.slice(-str.length) === str;
|
||||
};
|
||||
|
||||
Buffer.prototype.isLast = function (cha, trimRight) {
|
||||
Buffer.prototype.isLast = function (cha) {
|
||||
if (this.format.compact) return false;
|
||||
|
||||
var buf = this.buf;
|
||||
if (trimRight) buf = util.trimRight(buf);
|
||||
var last = buf[buf.length - 1];
|
||||
|
||||
if (Array.isArray(cha)) {
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
var isInteger = require("is-integer");
|
||||
var isNumber = require("lodash/lang/isNumber");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.UnaryExpression = function (node, print) {
|
||||
var hasSpace = /[a-z]$/.test(node.operator);
|
||||
@@ -46,11 +46,9 @@ exports.ConditionalExpression = function (node, print) {
|
||||
exports.NewExpression = function (node, print) {
|
||||
this.push("new ");
|
||||
print(node.callee);
|
||||
if (node.arguments.length || this.format.parentheses) {
|
||||
this.push("(");
|
||||
print.list(node.arguments);
|
||||
this.push(")");
|
||||
}
|
||||
this.push("(");
|
||||
print.list(node.arguments);
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
exports.SequenceExpression = function (node, print) {
|
||||
@@ -146,7 +144,7 @@ exports.MemberExpression = function (node, print) {
|
||||
this.push("]");
|
||||
} else {
|
||||
// 5..toFixed(2);
|
||||
if (t.isLiteral(obj) && util.isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
||||
if (t.isLiteral(obj) && isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
|
||||
this.push(".");
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ exports.ObjectTypeIndexer =
|
||||
exports.ObjectTypeProperty =
|
||||
exports.QualifiedTypeIdentifier =
|
||||
exports.UnionTypeAnnotation =
|
||||
exports.TypeCastExpression =
|
||||
exports.VoidTypeAnnotation = function () {
|
||||
// todo: implement these once we have a `--keep-types` option
|
||||
};
|
||||
@@ -62,6 +62,10 @@ exports.ImportDeclaration = function (node, print) {
|
||||
|
||||
this.push("import ");
|
||||
|
||||
if (node.isType) {
|
||||
this.push("type ");
|
||||
}
|
||||
|
||||
var specfiers = node.specifiers;
|
||||
if (specfiers && specfiers.length) {
|
||||
var foundImportSpecifier = false;
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var repeating = require("repeating");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.WithStatement = function (node, print) {
|
||||
this.keyword("with");
|
||||
@@ -22,12 +22,7 @@ exports.IfStatement = function (node, print) {
|
||||
|
||||
if (node.alternate) {
|
||||
if (this.isLast("}")) this.space();
|
||||
this.keyword("else");
|
||||
|
||||
if (this.format.format && !t.isBlockStatement(node.alternate)) {
|
||||
this.push(" ");
|
||||
}
|
||||
|
||||
this.push("else ");
|
||||
print.indentOnComments(node.alternate);
|
||||
}
|
||||
};
|
||||
@@ -153,7 +148,14 @@ exports.SwitchStatement = function (node, print) {
|
||||
this.push(")");
|
||||
this.space();
|
||||
this.push("{");
|
||||
print.sequence(node.cases, { indent: true });
|
||||
|
||||
print.sequence(node.cases, {
|
||||
indent: true,
|
||||
addNewlines: function (leading, cas) {
|
||||
if (!leading && node.cases[node.cases.length - 1] === cas) return -1;
|
||||
}
|
||||
});
|
||||
|
||||
this.push("}");
|
||||
};
|
||||
|
||||
@@ -166,8 +168,10 @@ exports.SwitchCase = function (node, print) {
|
||||
this.push("default:");
|
||||
}
|
||||
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
if (node.consequent.length) {
|
||||
this.newline();
|
||||
print.sequence(node.consequent, { indent: true });
|
||||
}
|
||||
};
|
||||
|
||||
exports.DebuggerStatement = function () {
|
||||
@@ -189,8 +193,8 @@ exports.VariableDeclaration = function (node, print, parent) {
|
||||
}
|
||||
|
||||
var sep = ",";
|
||||
if (hasInits) {
|
||||
sep += "\n" + util.repeat(node.kind.length + 1);
|
||||
if (!this.format.compact && hasInits) {
|
||||
sep += "\n" + repeating(" ", node.kind.length + 1);
|
||||
} else {
|
||||
sep += " ";
|
||||
}
|
||||
@@ -72,7 +72,7 @@ exports.ArrayPattern = function (node, print) {
|
||||
// both (all) of the holes.
|
||||
self.push(",");
|
||||
} else {
|
||||
if (i > 0 && !self.format.compact) self.push(" ");
|
||||
if (i > 0) self.push(" ");
|
||||
print(elem);
|
||||
if (i < len - 1) self.push(",");
|
||||
}
|
||||
@@ -9,13 +9,13 @@ module.exports.CodeGenerator = CodeGenerator;
|
||||
|
||||
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 merge = require("lodash/object/merge");
|
||||
var each = require("lodash/collection/each");
|
||||
var util = require("../util");
|
||||
var n = require("./node");
|
||||
var t = require("../types");
|
||||
|
||||
@@ -28,7 +28,7 @@ function CodeGenerator(ast, opts, code) {
|
||||
this.opts = opts;
|
||||
this.ast = ast;
|
||||
|
||||
this.whitespace = new Whitespace(this.tokens, this.comments);
|
||||
this.whitespace = new Whitespace(this.tokens, this.comments, this.format);
|
||||
this.position = new Position;
|
||||
this.map = new SourceMap(this.position, opts, code);
|
||||
this.buffer = new Buffer(this.position, this.format);
|
||||
@@ -47,17 +47,25 @@ CodeGenerator.normalizeOptions = function (code, opts) {
|
||||
if (indent && indent !== " ") style = indent;
|
||||
}
|
||||
|
||||
return merge({
|
||||
parentheses: true,
|
||||
var format = {
|
||||
comments: opts.comments == null || opts.comments,
|
||||
compact: false,
|
||||
concise: false,
|
||||
compact: opts.compact,
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
style: style,
|
||||
base: 0
|
||||
}
|
||||
}, opts.format || {});
|
||||
};
|
||||
|
||||
if (format.compact === "auto") {
|
||||
format.compact = code.length > 100000; // 100KB
|
||||
|
||||
if (format.compact) {
|
||||
console.error(messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
||||
}
|
||||
}
|
||||
|
||||
return format;
|
||||
};
|
||||
|
||||
CodeGenerator.generators = {
|
||||
@@ -115,11 +123,7 @@ CodeGenerator.prototype.buildPrint = function (parent) {
|
||||
|
||||
print.list = function (items, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var sep = opts.separator || ", ";
|
||||
if (self.format.compact) sep = ",";
|
||||
opts.separator = sep;
|
||||
|
||||
opts.separator = opts.separator || ", ";
|
||||
print.join(items, opts);
|
||||
};
|
||||
|
||||
@@ -167,13 +171,14 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
|
||||
} else {
|
||||
// generated node
|
||||
if (!leading) lines++; // always include at least a single line after
|
||||
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0;
|
||||
|
||||
var needs = n.needsWhitespaceAfter;
|
||||
if (leading) needs = n.needsWhitespaceBefore;
|
||||
lines += needs(node, parent);
|
||||
if (needs(node, parent)) lines++;
|
||||
|
||||
// generated nodes can't add starting file whitespace
|
||||
if (!self.buffer.get()) lines = 0;
|
||||
if (!self.buffer.buf) lines = 0;
|
||||
}
|
||||
|
||||
self.newline(lines);
|
||||
@@ -227,6 +232,7 @@ CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
|
||||
each(nodes, function (node, i) {
|
||||
print(node, {
|
||||
statement: opts.statement,
|
||||
addNewlines: opts.addNewlines,
|
||||
after: function () {
|
||||
if (opts.iterator) {
|
||||
opts.iterator(node, i);
|
||||
@@ -302,6 +308,7 @@ CodeGenerator.prototype._getComments = function (key, node) {
|
||||
|
||||
CodeGenerator.prototype._printComments = function (comments) {
|
||||
if (this.format.compact) return;
|
||||
|
||||
if (!this.format.comments) return;
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
@@ -344,7 +351,7 @@ CodeGenerator.prototype._printComments = function (comments) {
|
||||
}
|
||||
|
||||
var indent = Math.max(self.indentSize(), column);
|
||||
val = val.replace(/\n/g, "\n" + util.repeat(indent));
|
||||
val = val.replace(/\n/g, "\n" + repeating(" ", indent));
|
||||
}
|
||||
|
||||
if (column === 0) {
|
||||
@@ -4,9 +4,9 @@ module.exports = Node;
|
||||
|
||||
var whitespace = require("./whitespace");
|
||||
var parens = require("./parentheses");
|
||||
var t = require("../../types");
|
||||
var each = require("lodash/collection/each");
|
||||
var some = require("lodash/collection/some");
|
||||
var t = require("../../types");
|
||||
|
||||
var find = function (obj, node, parent) {
|
||||
if (!obj) return;
|
||||
@@ -42,14 +42,19 @@ Node.needsWhitespace = function (node, parent, type) {
|
||||
node = node.expression;
|
||||
}
|
||||
|
||||
var lines = find(whitespace[type].nodes, node, parent);
|
||||
if (lines) return lines;
|
||||
var linesInfo = find(whitespace.nodes, node, parent);
|
||||
|
||||
each(find(whitespace[type].list, node, parent), function (expr) {
|
||||
lines = Node.needsWhitespace(expr, node, type);
|
||||
if (lines) return false;
|
||||
});
|
||||
return lines || 0;
|
||||
if (!linesInfo) {
|
||||
var items = find(whitespace.list, node, parent);
|
||||
if (items) {
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
linesInfo = Node.needsWhitespace(items[i], node, type);
|
||||
if (linesInfo) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (linesInfo && linesInfo[type]) || 0;
|
||||
};
|
||||
|
||||
Node.needsWhitespaceBefore = function (node, parent) {
|
||||
159
lib/babel/generation/node/whitespace.js
Normal file
159
lib/babel/generation/node/whitespace.js
Normal file
@@ -0,0 +1,159 @@
|
||||
"use strict";
|
||||
|
||||
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 = state || {};
|
||||
|
||||
if (t.isMemberExpression(node)) {
|
||||
crawl(node.object, state);
|
||||
if (node.computed) crawl(node.property, state);
|
||||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
|
||||
crawl(node.left, state);
|
||||
crawl(node.right, state);
|
||||
} else if (t.isCallExpression(node)) {
|
||||
state.hasCall = true;
|
||||
crawl(node.callee, state);
|
||||
} else if (t.isFunction(node)) {
|
||||
state.hasFunction = true;
|
||||
} else if (t.isIdentifier(node)) {
|
||||
state.hasHelper = state.hasHelper || isHelper(node.callee);
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
var isHelper = function (node) {
|
||||
if (t.isMemberExpression(node)) {
|
||||
return isHelper(node.object) || isHelper(node.property);
|
||||
} else if (t.isIdentifier(node)) {
|
||||
return node.name === "require" || node.name[0] === "_";
|
||||
} else if (t.isCallExpression(node)) {
|
||||
return isHelper(node.callee);
|
||||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
|
||||
return (t.isIdentifier(node.left) && isHelper(node.left)) || isHelper(node.right);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var isType = function (node) {
|
||||
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) ||
|
||||
t.isIdentifier(node) || t.isMemberExpression(node);
|
||||
};
|
||||
|
||||
exports.nodes = {
|
||||
AssignmentExpression: function (node) {
|
||||
var state = crawl(node.right);
|
||||
if ((state.hasCall && state.hasHelper) || state.hasFunction) {
|
||||
return {
|
||||
before: state.hasFunction,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
SwitchCase: function (node, parent) {
|
||||
return {
|
||||
before: node.consequent.length || parent.cases[0] === node
|
||||
};
|
||||
},
|
||||
|
||||
LogicalExpression: function (node) {
|
||||
if (t.isFunction(node.left) || t.isFunction(node.right)) {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
Literal: function (node) {
|
||||
if (node.value === "use strict") {
|
||||
return {
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
CallExpression: function (node) {
|
||||
if (t.isFunction(node.callee) || isHelper(node)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
VariableDeclaration: function (node) {
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
|
||||
var enabled = isHelper(declar.id) && !isType(declar.init);
|
||||
if (!enabled) {
|
||||
var state = crawl(declar.init);
|
||||
enabled = (isHelper(declar.init) && state.hasCall) || state.hasFunction;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
IfStatement: function (node) {
|
||||
if (t.isBlockStatement(node.consequent)) {
|
||||
return {
|
||||
before: true,
|
||||
after: true
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.nodes.Property =
|
||||
exports.nodes.SpreadProperty = function (node, parent) {
|
||||
if (parent.properties[0] === node) {
|
||||
return {
|
||||
before: true
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
exports.list = {
|
||||
VariableDeclaration: function (node) {
|
||||
return map(node.declarations, "init");
|
||||
},
|
||||
|
||||
ArrayExpression: function (node) {
|
||||
return node.elements;
|
||||
},
|
||||
|
||||
ObjectExpression: function (node) {
|
||||
return node.properties;
|
||||
}
|
||||
};
|
||||
|
||||
each({
|
||||
Function: true,
|
||||
Class: true,
|
||||
Loop: true,
|
||||
LabeledStatement: true,
|
||||
SwitchStatement: true,
|
||||
TryStatement: true
|
||||
}, function (amounts, type) {
|
||||
if (isBoolean(amounts)) {
|
||||
amounts = { after: amounts, before: amounts };
|
||||
}
|
||||
|
||||
each([type].concat(t.FLIPPED_ALIAS_KEYS[type] || []), function (type) {
|
||||
exports.nodes[type] = function () {
|
||||
return amounts;
|
||||
};
|
||||
});
|
||||
});
|
||||
@@ -13,11 +13,13 @@ var sortBy = require("lodash/collection/sortBy");
|
||||
* @param {Number} max Array length
|
||||
* @returns {Number} shiftedIndex
|
||||
*/
|
||||
|
||||
function getLookupIndex(i, base, max) {
|
||||
i += base;
|
||||
|
||||
if (i >= max)
|
||||
if (i >= max) {
|
||||
i -= max;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
@@ -82,7 +84,7 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
|
||||
}
|
||||
}
|
||||
|
||||
if (endToken.type.type === "eof") {
|
||||
if (endToken && endToken.type.type === "eof") {
|
||||
return 1;
|
||||
} else {
|
||||
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||
@@ -96,6 +98,8 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
|
||||
};
|
||||
|
||||
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
||||
if (!endToken || !endToken.loc) return 0;
|
||||
|
||||
var start = startToken ? startToken.loc.end.line : 1;
|
||||
var end = endToken.loc.start.line;
|
||||
var lines = 0;
|
||||
91
lib/babel/helpers/code-frame.js
Normal file
91
lib/babel/helpers/code-frame.js
Normal file
@@ -0,0 +1,91 @@
|
||||
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");
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
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)) {
|
||||
return "keyword";
|
||||
}
|
||||
|
||||
if (token.type === "punctuation") {
|
||||
switch (token.value) {
|
||||
case "{":
|
||||
case "}":
|
||||
return "curly";
|
||||
case "(":
|
||||
case ")":
|
||||
return "parens";
|
||||
case "[":
|
||||
case "]":
|
||||
return "square";
|
||||
}
|
||||
}
|
||||
|
||||
return token.type;
|
||||
};
|
||||
|
||||
return text.replace(jsTokens, function (match) {
|
||||
var type = tokenType(arguments);
|
||||
if (type in defs) {
|
||||
var colorize = ary(defs[type], 1);
|
||||
return match.split(newline).map(colorize).join("\n");
|
||||
}
|
||||
return match;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = function (lines, lineNumber, colNumber) {
|
||||
colNumber = Math.max(colNumber, 0);
|
||||
|
||||
if (chalk.supportsColor) {
|
||||
lines = highlight(lines);
|
||||
}
|
||||
|
||||
lines = lines.split(newline);
|
||||
|
||||
var start = Math.max(lineNumber - 3, 0);
|
||||
var end = Math.min(lines.length, lineNumber + 3);
|
||||
|
||||
if (!lineNumber && !colNumber) {
|
||||
start = 0;
|
||||
end = lines.length;
|
||||
}
|
||||
|
||||
return "\n" + lineNumbers(lines.slice(start, end), {
|
||||
start: start + 1,
|
||||
before: " ",
|
||||
after: " | ",
|
||||
transform: function (params) {
|
||||
if (params.number !== lineNumber) {
|
||||
return;
|
||||
}
|
||||
if (colNumber) {
|
||||
params.line += "\n" + params.before + repeating(" ", params.width) +
|
||||
params.after + repeating(" ", colNumber - 1) + "^";
|
||||
}
|
||||
params.before = params.before.replace(/^./, ">");
|
||||
}
|
||||
}).join("\n");
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
var normalizeAst = require("./normalize-ast");
|
||||
var estraverse = require("estraverse");
|
||||
var codeFrame = require("./code-frame");
|
||||
var acorn = require("acorn-6to5");
|
||||
var acorn = require("acorn-babel");
|
||||
|
||||
module.exports = function (opts, code, callback) {
|
||||
try {
|
||||
@@ -30,8 +30,8 @@ module.exports = function (opts, code, callback) {
|
||||
return ast;
|
||||
}
|
||||
} catch (err) {
|
||||
if (!err._6to5) {
|
||||
err._6to5 = true;
|
||||
if (!err._babel) {
|
||||
err._babel = true;
|
||||
var message = opts.filename + ": " + err.message;
|
||||
|
||||
var loc = err.loc;
|
||||
@@ -9,13 +9,16 @@ exports.messages = {
|
||||
scopeDuplicateDeclaration: "Duplicate declaration $1",
|
||||
undeclaredVariable: "Reference to undeclared variable $1",
|
||||
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
|
||||
settersInvalidParamLength: "Setters must have only one parameter",
|
||||
settersInvalidParamLength: "Setters must have exactly one parameter",
|
||||
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
|
||||
expectedMemberExpressionOrIdentifier: "Expected type MemeberExpression or Identifier",
|
||||
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
|
||||
readOnly: "$1 is read-only",
|
||||
modulesIllegalExportName: "Illegal export $1",
|
||||
unknownForHead: "Unknown node type $1 in ForStatement"
|
||||
unknownForHead: "Unknown node type $1 in ForStatement",
|
||||
didYouMean: "Did you mean $1?",
|
||||
evalInStrictMode: "eval is not allowed in strict mode",
|
||||
codeGeneratorDeopt: "Note: The code generator has deoptimised the styling of $1 as it exceeds the max of $2."
|
||||
};
|
||||
|
||||
exports.get = function (key) {
|
||||
@@ -8,7 +8,7 @@ var t = require("./types");
|
||||
var estraverse = require("estraverse");
|
||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||
|
||||
// regenerator-6to5/ast-types
|
||||
// regenerator-babel/ast-types
|
||||
|
||||
var types = require("ast-types");
|
||||
var def = types.Type.def;
|
||||
9
lib/babel/polyfill.js
Normal file
9
lib/babel/polyfill.js
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
if (global._babelPolyfill) {
|
||||
throw new Error("only one instance of babel/polyfill is allowed");
|
||||
}
|
||||
global._babelPolyfill = true;
|
||||
|
||||
require("core-js/shim");
|
||||
require("regenerator-babel/runtime");
|
||||
@@ -2,25 +2,27 @@
|
||||
|
||||
module.exports = File;
|
||||
|
||||
var 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 clone = require("../helpers/clone");
|
||||
var parse = require("../helpers/parse");
|
||||
var Scope = require("../traversal/scope");
|
||||
var util = require("../util");
|
||||
var path = require("path");
|
||||
var each = require("lodash/collection/each");
|
||||
var t = require("../types");
|
||||
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");
|
||||
|
||||
function File(opts) {
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
this.dynamicImportedNoDefault = [];
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
|
||||
this.dynamicData = {};
|
||||
this.data = {};
|
||||
@@ -58,7 +60,7 @@ File.helpers = [
|
||||
"object-destructuring-empty",
|
||||
"temporal-undefined",
|
||||
"temporal-assert-defined",
|
||||
"tail-call"
|
||||
"self-global"
|
||||
];
|
||||
|
||||
File.validOptions = [
|
||||
@@ -80,11 +82,17 @@ File.validOptions = [
|
||||
"keepModuleIdExtensions",
|
||||
"code",
|
||||
"ast",
|
||||
"format",
|
||||
"playground",
|
||||
"experimental",
|
||||
"externalHelpers",
|
||||
"auxiliaryComment",
|
||||
"compact",
|
||||
|
||||
"resolveModuleSource",
|
||||
"runtime",
|
||||
"moduleId",
|
||||
|
||||
// legacy
|
||||
"format",
|
||||
|
||||
// these are used by plugins
|
||||
"ignore",
|
||||
@@ -94,7 +102,7 @@ File.validOptions = [
|
||||
];
|
||||
|
||||
File.prototype.normalizeOptions = function (opts) {
|
||||
opts = clone(opts);
|
||||
opts = assign({}, opts);
|
||||
|
||||
for (var key in opts) {
|
||||
if (key[0] !== "_" && File.validOptions.indexOf(key) < 0) {
|
||||
@@ -105,10 +113,11 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
defaults(opts, {
|
||||
keepModuleIdExtensions: false,
|
||||
resolveModuleSource: null,
|
||||
externalHelpers: false,
|
||||
auxilaryComment: "",
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
@@ -117,16 +126,20 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
compact: "auto",
|
||||
loose: [],
|
||||
code: true,
|
||||
ast: true
|
||||
});
|
||||
|
||||
// normalize windows path separators to unix
|
||||
opts.filename = util.normalisePathSeparator(opts.filename);
|
||||
opts.filename = slash(opts.filename);
|
||||
if (opts.sourceRoot) {
|
||||
opts.sourceRoot = util.normalisePathSeparator(opts.sourceRoot);
|
||||
opts.sourceRoot = slash(opts.sourceRoot);
|
||||
}
|
||||
|
||||
if (opts.moduleId) {
|
||||
opts.moduleIds = true;
|
||||
}
|
||||
|
||||
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
||||
@@ -134,6 +147,7 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
opts.blacklist = util.arrayify(opts.blacklist);
|
||||
opts.whitelist = util.arrayify(opts.whitelist);
|
||||
opts.optional = util.arrayify(opts.optional);
|
||||
opts.compact = util.booleanify(opts.compact);
|
||||
opts.loose = util.arrayify(opts.loose);
|
||||
|
||||
if (includes(opts.loose, "all") || includes(opts.loose, true)) {
|
||||
@@ -161,8 +175,8 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
opts.experimental = true;
|
||||
}
|
||||
|
||||
if (opts.runtime) {
|
||||
this.set("runtimeIdentifier", t.identifier("to5Runtime"));
|
||||
if (opts.externalHelpers) {
|
||||
this.set("helpersNamespace", t.identifier("babelHelpers"));
|
||||
}
|
||||
|
||||
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||
@@ -172,8 +186,7 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
|
||||
if (opts.reactCompat) {
|
||||
opts.optional.push("reactCompat");
|
||||
console.error("The reactCompat option has been moved into the optional transformer " +
|
||||
"`reactCompat` - backwards compatibility will be removed in v4.0.0");
|
||||
console.error("The reactCompat option has been moved into the optional transformer `reactCompat`");
|
||||
}
|
||||
|
||||
var ensureEnabled = function (key) {
|
||||
@@ -242,12 +255,13 @@ File.prototype.getModuleFormatter = function (type) {
|
||||
};
|
||||
|
||||
File.prototype.parseShebang = function (code) {
|
||||
var shebangMatch = code.match(SHEBANG_REGEX);
|
||||
var shebangMatch = shebangRegex.exec(code);
|
||||
|
||||
if (shebangMatch) {
|
||||
this.shebang = shebangMatch[0];
|
||||
|
||||
// remove shebang
|
||||
code = code.replace(SHEBANG_REGEX, "");
|
||||
code = code.replace(shebangRegex, "");
|
||||
}
|
||||
|
||||
return code;
|
||||
@@ -273,17 +287,19 @@ File.prototype.get = function (key) {
|
||||
}
|
||||
};
|
||||
|
||||
File.prototype.addImport = function (source, name) {
|
||||
File.prototype.addImport = function (source, name, noDefault) {
|
||||
name = name || source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
if (!id) {
|
||||
id = this.dynamicImportIds[name] = this.generateUidIdentifier(name);
|
||||
id = this.dynamicImportIds[name] = this.scope.generateUidIdentifier(name);
|
||||
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
declar._blockHoist = 3;
|
||||
|
||||
this.dynamicImported.push(declar);
|
||||
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
||||
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
}
|
||||
@@ -295,6 +311,18 @@ File.prototype.isConsequenceExpressionStatement = function (node) {
|
||||
return t.isExpressionStatement(node) && this.lastStatements.indexOf(node) >= 0;
|
||||
};
|
||||
|
||||
File.prototype.attachAuxiliaryComment = function (node) {
|
||||
var comment = this.opts.auxiliaryComment;
|
||||
if (comment) {
|
||||
node.leadingComments = node.leadingComments || [];
|
||||
node.leadingComments.push({
|
||||
type: "Line",
|
||||
value: " " + comment
|
||||
});
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
File.prototype.addHelper = function (name) {
|
||||
if (!includes(File.helpers, name)) {
|
||||
throw new ReferenceError("Unknown helper " + name);
|
||||
@@ -305,14 +333,14 @@ File.prototype.addHelper = function (name) {
|
||||
var declar = program._declarations && program._declarations[name];
|
||||
if (declar) return declar.id;
|
||||
|
||||
var runtime = this.get("runtimeIdentifier");
|
||||
var runtime = this.get("helpersNamespace");
|
||||
if (runtime) {
|
||||
name = t.identifier(t.toIdentifier(name));
|
||||
return t.memberExpression(runtime, name);
|
||||
} else {
|
||||
var ref = util.template(name);
|
||||
ref._compact = true;
|
||||
var uid = this.generateUidIdentifier(name);
|
||||
var uid = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
key: name,
|
||||
id: uid,
|
||||
@@ -349,7 +377,7 @@ File.prototype.parse = function (code) {
|
||||
var opts = this.opts;
|
||||
|
||||
opts.allowImportExportEverywhere = this.isLoose("es6.modules");
|
||||
//opts.strictMode = this.transformers.useStrict.canRun();
|
||||
opts.strictMode = this.transformers.useStrict.canRun();
|
||||
|
||||
return parse(opts, code, function (tree) {
|
||||
self.transform(tree);
|
||||
@@ -437,36 +465,9 @@ File.prototype.generate = function () {
|
||||
}
|
||||
|
||||
if (opts.sourceMap === "inline") {
|
||||
result.code += "\n" + util.sourceMapToComment(result.map);
|
||||
result.code += "\n" + sourceMapToComment(result.map);
|
||||
result.map = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
File.prototype.generateUid = function (name, scope) {
|
||||
name = t.toIdentifier(name).replace(/^_+/, "");
|
||||
|
||||
scope = scope || this.scope;
|
||||
|
||||
var uid;
|
||||
var i = 0;
|
||||
do {
|
||||
uid = this._generateUid(name, i);
|
||||
i++;
|
||||
} while (scope.hasBinding(uid) || scope.hasGlobal(uid));
|
||||
return uid;
|
||||
};
|
||||
|
||||
File.prototype.generateUidIdentifier = function (name, scope) {
|
||||
scope = scope || this.scope;
|
||||
var id = t.identifier(this.generateUid(name, scope));
|
||||
scope.getFunctionParent().registerBinding("uid", id);
|
||||
return id;
|
||||
};
|
||||
|
||||
File.prototype._generateUid = function (name, i) {
|
||||
var id = name;
|
||||
if (i > 1) id += i;
|
||||
return "_" + id;
|
||||
};
|
||||
@@ -44,11 +44,19 @@ module.exports = function (exports, opts) {
|
||||
};
|
||||
|
||||
exports.JSXAttribute = {
|
||||
enter: function (node) {
|
||||
var value = node.value;
|
||||
if (t.isLiteral(value) && isString(value.value)) {
|
||||
value.value = value.value.replace(/\n\s+/g, " ");
|
||||
}
|
||||
},
|
||||
|
||||
exit: function (node) {
|
||||
var value = node.value || t.literal(true);
|
||||
return t.inherits(t.property("init", node.name, value), node);
|
||||
}
|
||||
};
|
||||
|
||||
exports.JSXOpeningElement = {
|
||||
exit: function (node, parent, scope, file) {
|
||||
var tagExpr = node.name;
|
||||
@@ -68,7 +76,7 @@ module.exports = function (exports, opts) {
|
||||
};
|
||||
|
||||
if (opts.pre) {
|
||||
opts.pre(state);
|
||||
opts.pre(state, file);
|
||||
}
|
||||
|
||||
var attribs = node.attributes;
|
||||
@@ -81,7 +89,7 @@ module.exports = function (exports, opts) {
|
||||
args.push(attribs);
|
||||
|
||||
if (opts.post) {
|
||||
opts.post(state);
|
||||
opts.post(state, file);
|
||||
}
|
||||
|
||||
return state.call || t.callExpression(state.callee, args);
|
||||
118
lib/babel/transformation/helpers/name-method.js
Normal file
118
lib/babel/transformation/helpers/name-method.js
Normal file
@@ -0,0 +1,118 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
var visitor = {
|
||||
enter: function (node, parent, scope, state) {
|
||||
// check if this node is a referenced identifier that matches the same as our
|
||||
// function id
|
||||
if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;
|
||||
|
||||
// check that we don't have a local variable declared as that removes the need
|
||||
// for the wrapper
|
||||
var localDeclar = scope.getBindingIdentifier(state.name);
|
||||
if (localDeclar !== state.outerDeclar) return;
|
||||
|
||||
state.selfReference = true;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
|
||||
var wrap = function (state, method, id, scope) {
|
||||
if (state.selfReference) {
|
||||
var templateName = "property-method-assignment-wrapper";
|
||||
if (method.generator) templateName += "-generator";
|
||||
return util.template(templateName, {
|
||||
FUNCTION: method,
|
||||
FUNCTION_ID: id,
|
||||
FUNCTION_KEY: scope.generateUidIdentifier(id.name),
|
||||
WRAPPER_KEY: scope.generateUidIdentifier(id.name + "Wrapper")
|
||||
});
|
||||
} else {
|
||||
method.id = id;
|
||||
return method;
|
||||
}
|
||||
};
|
||||
|
||||
var visit = function (node, name, scope) {
|
||||
var state = {
|
||||
selfAssignment: false,
|
||||
selfReference: false,
|
||||
outerDeclar: scope.getBindingIdentifier(name),
|
||||
references: [],
|
||||
name: name,
|
||||
};
|
||||
|
||||
// check to see if we have a local binding of the id we're setting inside of
|
||||
// the function, this is important as there are caveats associated
|
||||
|
||||
var bindingInfo = scope.getOwnBindingInfo(name);
|
||||
|
||||
if (bindingInfo) {
|
||||
if (bindingInfo.kind === "param") {
|
||||
// safari will blow up in strict mode with code like:
|
||||
//
|
||||
// var t = function t(t) {};
|
||||
//
|
||||
// with the error:
|
||||
//
|
||||
// Cannot declare a parameter named 't' as it shadows the name of a
|
||||
// strict mode function.
|
||||
//
|
||||
// this isn't to the spec and they've invented this behaviour which is
|
||||
// **extremely** annoying so we avoid setting the name if it has a param
|
||||
// with the same id
|
||||
state.selfReference = true;
|
||||
} else {
|
||||
// otherwise it's defined somewhere in scope like:
|
||||
//
|
||||
// var t = function () {
|
||||
// var t = 2;
|
||||
// };
|
||||
//
|
||||
// so we can safely just set the id and move along as it shadows the
|
||||
// bound function id
|
||||
}
|
||||
} else {
|
||||
scope.traverse(node, visitor, state);
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
exports.property = function (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
|
||||
|
||||
var name = t.toIdentifier(key.value);
|
||||
var id = t.identifier(name);
|
||||
|
||||
var method = node.value;
|
||||
var state = visit(method, name, scope);
|
||||
node.value = wrap(state, method, id, scope);
|
||||
};
|
||||
|
||||
exports.bare = function (node, parent, scope) {
|
||||
// has an `id` so we don't need to infer one
|
||||
if (node.id) return;
|
||||
|
||||
var id;
|
||||
if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) {
|
||||
// { foo: function () {} };
|
||||
id = parent.key;
|
||||
} else if (t.isVariableDeclarator(parent)) {
|
||||
// var foo = function () {};
|
||||
id = parent.id;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!t.isIdentifier(id)) return;
|
||||
|
||||
var name = t.toIdentifier(id.name);
|
||||
id = t.identifier(name);
|
||||
|
||||
var state = visit(node, name, scope);
|
||||
return wrap(state, node, id, scope);
|
||||
};
|
||||
@@ -143,7 +143,7 @@ ReplaceSupers.prototype.getThisReference = function () {
|
||||
if (this.topLevelThisReference) {
|
||||
return this.topLevelThisReference;
|
||||
} else {
|
||||
var ref = this.topLevelThisReference = this.file.generateUidIdentifier("this");
|
||||
var ref = this.topLevelThisReference = this.scope.generateUidIdentifier("this");
|
||||
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this.topLevelThisReference, t.thisExpression())
|
||||
]));
|
||||
@@ -31,10 +31,7 @@ transform._ensureTransformerNames = function (type, rawKeys) {
|
||||
var deprecatedKey = transform.deprecatedTransformerMap[key];
|
||||
if (deprecatedKey) {
|
||||
// deprecated key, remap it to the new one
|
||||
console.error(
|
||||
"The transformer " + key + " has been renamed to " + deprecatedKey +
|
||||
" in v3.0.0 - backwards compatibilty will be removed 4.0.0"
|
||||
);
|
||||
console.error("The transformer " + key + " has been renamed to " + deprecatedKey);
|
||||
rawKeys.push(deprecatedKey);
|
||||
} else if (transform.transformers[key]) {
|
||||
// valid key
|
||||
@@ -44,12 +41,7 @@ transform._ensureTransformerNames = function (type, rawKeys) {
|
||||
keys = keys.concat(transform.namespaces[key]);
|
||||
} else {
|
||||
// invalid key
|
||||
throw new ReferenceError(
|
||||
"Unknown transformer " + key + " specified in " + type + " - " +
|
||||
"transformer key names have been changed in 3.0.0 see " +
|
||||
"the changelog for more info " +
|
||||
"https://github.com/6to5/6to5/blob/master/CHANGELOG.md#300"
|
||||
);
|
||||
throw new ReferenceError("Unknown transformer " + key + " specified in " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@ var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function DefaultFormatter(file) {
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
this.scope = file.scope;
|
||||
this.file = file;
|
||||
this.ids = object();
|
||||
|
||||
this.hasNonDefaultExports = false;
|
||||
|
||||
@@ -145,6 +146,8 @@ DefaultFormatter.prototype.isLocalReference = function (node, scope) {
|
||||
|
||||
DefaultFormatter.prototype.getModuleName = function () {
|
||||
var opts = this.file.opts;
|
||||
if (opts.moduleId) return opts.moduleId;
|
||||
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
|
||||
@@ -212,9 +215,6 @@ DefaultFormatter.prototype.checkExportIdentifier = function (node) {
|
||||
};
|
||||
|
||||
DefaultFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
||||
var inherits = false;
|
||||
if (node.specifiers.length === 1) inherits = node;
|
||||
|
||||
if (node.source) {
|
||||
var ref = this.getExternalReference(node, nodes);
|
||||
|
||||
@@ -4,6 +4,7 @@ var util = require("../../util");
|
||||
|
||||
module.exports = function (Parent) {
|
||||
var Constructor = function () {
|
||||
this.noInteropRequireImport = true;
|
||||
this.noInteropRequireExport = true;
|
||||
Parent.apply(this, arguments);
|
||||
};
|
||||
@@ -4,10 +4,10 @@ module.exports = AMDFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var CommonFormatter = require("./common");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var values = require("lodash/object/values");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function AMDFormatter() {
|
||||
CommonFormatter.apply(this, arguments);
|
||||
@@ -70,7 +70,7 @@ AMDFormatter.prototype.getModuleName = function () {
|
||||
};
|
||||
|
||||
AMDFormatter.prototype._getExternalReference = function (node) {
|
||||
return this.file.generateUidIdentifier(node.source.value);
|
||||
return this.scope.generateUidIdentifier(node.source.value);
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.importDeclaration = function (node) {
|
||||
@@ -81,12 +81,12 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var key = t.getSpecifierName(specifier);
|
||||
var ref = this.getExternalReference(node);
|
||||
|
||||
if (includes(this.file.dynamicImported, node)) {
|
||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
// Prevent unnecessary renaming of dynamic imports.
|
||||
this.ids[node.source.value] = ref;
|
||||
} else if (t.isImportBatchSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
} else {
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user