Compare commits
95 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -11,5 +11,5 @@ test/tmp
|
|||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
.package.json
|
.package.json
|
||||||
packages/6to5-runtime/*.js
|
packages/babel-runtime/*.js
|
||||||
packages/6to5-runtime/regenerator/*.js
|
packages/babel-runtime/regenerator/*.js
|
||||||
|
|||||||
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -3,7 +3,7 @@
|
|||||||
url = https://github.com/google/traceur-compiler
|
url = https://github.com/google/traceur-compiler
|
||||||
[submodule "vendor/regenerator"]
|
[submodule "vendor/regenerator"]
|
||||||
path = vendor/regenerator
|
path = vendor/regenerator
|
||||||
url = https://github.com/6to5/regenerator-6to5
|
url = https://github.com/babel/regenerator-babel
|
||||||
[submodule "vendor/test262"]
|
[submodule "vendor/test262"]
|
||||||
path = vendor/test262
|
path = vendor/test262
|
||||||
url = https://github.com/tc39/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": {
|
"disallowSpacesInNamedFunctionExpression": {
|
||||||
"beforeOpeningRoundBrace": true
|
"beforeOpeningRoundBrace": true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
lib/6to5/transformation/templates
|
lib/babel/transformation/templates
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
node_modules
|
node_modules
|
||||||
*.log
|
*.log
|
||||||
*.cache
|
*.cache
|
||||||
lib/6to5/transformation/templates
|
lib/babel/transformation/templates
|
||||||
test
|
test
|
||||||
benchmark
|
benchmark
|
||||||
Makefile
|
Makefile
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ sudo: false
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- "0.10"
|
- "0.10"
|
||||||
- "0.11"
|
|
||||||
- "0.12"
|
- "0.12"
|
||||||
|
- "iojs"
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
except:
|
except:
|
||||||
|
|||||||
1093
CHANGELOG-6to5.md
Normal file
1093
CHANGELOG-6to5.md
Normal file
File diff suppressed because it is too large
Load Diff
1069
CHANGELOG.md
1069
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
|
Contributions are always welcome, no matter how large or small. Before
|
||||||
contributing, please read the
|
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
|
**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
|
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
|
#### Workflow
|
||||||
|
|
||||||
* Fork the repository
|
* 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`)
|
* Install the project dependencies (`make bootstrap`)
|
||||||
* Link your forked clone (`npm link`)
|
* Link your forked clone (`npm link`)
|
||||||
* Develop your changes ensuring you're fetching updates from upstream often
|
* 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
|
MIT License
|
||||||
|
|
||||||
|
|||||||
33
Makefile
33
Makefile
@@ -5,31 +5,31 @@ UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
|||||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||||
JSCS_CMD = node_modules/jscs/bin/jscs
|
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
|
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
|
.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:
|
build-core:
|
||||||
#node $(6TO5_CMD) src --out-dir lib
|
#node $(BABEL_CMD) src --out-dir lib
|
||||||
|
|
||||||
watch-core:
|
watch-core:
|
||||||
#node $(6TO5_CMD) src --out-dir lib --watch
|
#node $(BABEL_CMD) src --out-dir lib --watch
|
||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
|
|
||||||
node tools/cache-templates
|
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 $(UGLIFY_CMD) dist/polyfill.js >dist/polyfill.min.js
|
||||||
|
|
||||||
node $(BROWSERIFY_CMD) lib/6to5/api/browser.js -s to5 >dist/6to5.js
|
node $(BROWSERIFY_CMD) lib/babel/api/browser.js -s babel >dist/babel.js
|
||||||
node $(UGLIFY_CMD) dist/6to5.js >dist/6to5.min.js
|
node $(UGLIFY_CMD) dist/babel.js >dist/babel.min.js
|
||||||
|
|
||||||
node bin/6to5-runtime >dist/runtime.js
|
node bin/babel-external-helpers >dist/external-helpers.js
|
||||||
node $(UGLIFY_CMD) dist/runtime.js >dist/runtime.min.js
|
node $(UGLIFY_CMD) dist/external-helpers.js >dist/external-helpers.min.js
|
||||||
|
|
||||||
rm -rf templates.json
|
rm -rf templates.json
|
||||||
|
|
||||||
@@ -49,17 +49,16 @@ test: lint
|
|||||||
|
|
||||||
test-simple:
|
test-simple:
|
||||||
# excludes test262
|
# excludes test262
|
||||||
export SIMPLE_6TO5_TESTS=1; \
|
export SIMPLE_BABEL_TESTS=1; \
|
||||||
make test
|
make test
|
||||||
|
|
||||||
test-all:
|
test-all:
|
||||||
# includes traceur, esnext, regenerator
|
export ALL_BABEL_TESTS=1; \
|
||||||
export ALL_6TO5_TESTS=1; \
|
|
||||||
make test
|
make test
|
||||||
|
|
||||||
test-cov:
|
test-cov:
|
||||||
rm -rf coverage
|
rm -rf coverage
|
||||||
export SIMPLE_6TO5_TESTS=1; \
|
export SIMPLE_BABEL_TESTS=1; \
|
||||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||||
|
|
||||||
test-travis: build-core bootstrap
|
test-travis: build-core bootstrap
|
||||||
@@ -71,7 +70,7 @@ test-browser:
|
|||||||
|
|
||||||
node tools/cache-templates
|
node tools/cache-templates
|
||||||
node tools/cache-tests
|
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
|
rm -rf templates.json tests.json
|
||||||
|
|
||||||
test -n "`which open`" && open test/browser.html
|
test -n "`which open`" && open test/browser.html
|
||||||
@@ -85,9 +84,9 @@ publish:
|
|||||||
npm version $$version --message "v%s"
|
npm version $$version --message "v%s"
|
||||||
|
|
||||||
make build
|
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/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
|
node tools/cache-templates
|
||||||
test -f templates.json
|
test -f templates.json
|
||||||
@@ -99,12 +98,12 @@ publish:
|
|||||||
make publish-core
|
make publish-core
|
||||||
make publish-runtime
|
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:
|
publish-runtime:
|
||||||
cd packages; \
|
cd packages; \
|
||||||
node build-runtime.js; \
|
node build-runtime.js; \
|
||||||
cd 6to5-runtime; \
|
cd babel-runtime; \
|
||||||
npm publish
|
npm publish
|
||||||
|
|
||||||
publish-core:
|
publish-core:
|
||||||
|
|||||||
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).
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="6to5" src="https://raw.githubusercontent.com/6to5/logo/master/logo.png" width="546">
|
<img alt="babel" src="https://raw.githubusercontent.com/babel/logo/master/logo.png" width="546">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<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>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
For more information view the <a href="https://6to5.github.io">documentation</a>. For
|
For more information view the <a href="https://babeljs.io/">documentation</a>. For
|
||||||
support visit the <a href="https://gitter.im/6to5/6to5">gitter room</a>.
|
support visit the <a href="https://gitter.im/babel/babel">gitter room</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -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
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var commander = require("commander");
|
var pathIsAbsolute = require("path-is-absolute");
|
||||||
var Module = require("module");
|
var commander = require("commander");
|
||||||
var path = require("path");
|
var Module = require("module");
|
||||||
var repl = require("repl");
|
var babel = require("../lib/babel/api/node");
|
||||||
var to5 = require("../lib/6to5/api/node");
|
var path = require("path");
|
||||||
var util = require("../lib/6to5/util");
|
var repl = require("repl");
|
||||||
var vm = require("vm");
|
var util = require("../lib/babel/util");
|
||||||
var _ = require("lodash");
|
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("-e, --eval [script]", "Evaluate script");
|
||||||
program.option("-p, --print [code]", "Evaluate script and print result");
|
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,
|
experimental: program.experimental,
|
||||||
extensions: program.extensions,
|
extensions: program.extensions,
|
||||||
playground: program.playground,
|
playground: program.playground,
|
||||||
@@ -41,7 +42,7 @@ to5.register({
|
|||||||
//
|
//
|
||||||
|
|
||||||
var _eval = function (code, filename) {
|
var _eval = function (code, filename) {
|
||||||
code = to5.transform(code, {
|
code = babel.transform(code, {
|
||||||
filename: filename,
|
filename: filename,
|
||||||
blacklist: ["useStrict"].concat(program.blacklist || []),
|
blacklist: ["useStrict"].concat(program.blacklist || []),
|
||||||
whitelist: program.whitelist,
|
whitelist: program.whitelist,
|
||||||
@@ -60,7 +61,7 @@ if (program.eval || program.print) {
|
|||||||
if (program.print) console.log(result);
|
if (program.print) console.log(result);
|
||||||
} else {
|
} else {
|
||||||
if (program.args.length) {
|
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 args = process.argv.slice(2);
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@@ -85,7 +86,7 @@ if (program.eval || program.print) {
|
|||||||
|
|
||||||
// make the filename absolute
|
// make the filename absolute
|
||||||
var filename = args[0]
|
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
|
// add back on node and concat the sliced args
|
||||||
process.argv = ["node"].concat(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());
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var opts = require("./6to5").opts;
|
var opts = require("./babel").opts;
|
||||||
opts.optional = (opts.optional || []).concat("minification");
|
opts.optional = (opts.optional || []).concat("minification");
|
||||||
opts.format = {
|
opts.format = {
|
||||||
compact: true
|
compact: true
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This tiny wrapper file checks for known node flags and appends them
|
* 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){
|
process.argv.slice(2).forEach(function(arg){
|
||||||
var flag = arg.split("=")[0];
|
var flag = arg.split("=")[0];
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
var sourceMap = require("source-map");
|
var sourceMapToComment = require("source-map-to-comment");
|
||||||
var chokidar = require("chokidar");
|
var sourceMap = require("source-map");
|
||||||
var util2 = require("../../lib/6to5/util");
|
var chokidar = require("chokidar");
|
||||||
var path = require("path");
|
var path = require("path");
|
||||||
var util = require("./util");
|
var util = require("./util");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
module.exports = function (commander, filenames) {
|
module.exports = function (commander, filenames) {
|
||||||
var results = [];
|
var results = [];
|
||||||
@@ -42,7 +42,7 @@ module.exports = function (commander, filenames) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (commander.sourceMapsInline || (!commander.outFile && commander.sourceMaps)) {
|
if (commander.sourceMapsInline || (!commander.outFile && commander.sourceMaps)) {
|
||||||
code += "\n" + util2.sourceMapToComment(map);
|
code += "\n" + sourceMapToComment(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var commander = require("commander");
|
var commander = require("commander");
|
||||||
var transform = require("../../lib/6to5/transformation");
|
var transform = require("../../lib/babel/transformation");
|
||||||
var util = require("../../lib/6to5/util");
|
var util = require("../../lib/babel/util");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var each = require("lodash/collection/each");
|
var each = require("lodash/collection/each");
|
||||||
var keys = require("lodash/object/keys");
|
var keys = require("lodash/object/keys");
|
||||||
@@ -11,7 +11,7 @@ commander.option("-t, --source-maps-inline", "Append sourceMappingURL comment to
|
|||||||
commander.option("-s, --source-maps", "Save source map alongside the compiled code");
|
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("-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("-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("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
||||||
commander.option("-p, --playground", "Enable playground support");
|
commander.option("-p, --playground", "Enable playground support");
|
||||||
|
|
||||||
@@ -26,6 +26,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("-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("-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("--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 () {
|
commander.on("--help", function () {
|
||||||
var outKeys = function (title, obj) {
|
var outKeys = function (title, obj) {
|
||||||
@@ -99,6 +100,8 @@ if (errors.length) {
|
|||||||
|
|
||||||
exports.opts = {
|
exports.opts = {
|
||||||
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
keepModuleIdExtensions: commander.keepModuleIdExtensions,
|
||||||
|
auxiliaryComment: commander.auxiliaryComment,
|
||||||
|
externalHelpers: commander.externalHelpers,
|
||||||
sourceMapName: commander.outFile,
|
sourceMapName: commander.outFile,
|
||||||
experimental: commander.experimental,
|
experimental: commander.experimental,
|
||||||
reactCompat: commander.reactCompat,
|
reactCompat: commander.reactCompat,
|
||||||
@@ -109,13 +112,12 @@ exports.opts = {
|
|||||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||||
optional: commander.optional,
|
optional: commander.optional,
|
||||||
comments: !commander.removeComments,
|
comments: !commander.removeComments,
|
||||||
runtime: commander.runtime,
|
|
||||||
modules: commander.modules,
|
modules: commander.modules,
|
||||||
loose: commander.loose
|
loose: commander.loose
|
||||||
};
|
};
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
// this is just a hack to give `6to5-minify` and other files including this
|
// this is just a hack to give `babel-minify` and other files including this
|
||||||
// time to modify `exports.opts`
|
// time to modify `exports.opts`
|
||||||
|
|
||||||
var fn;
|
var fn;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
var readdir = require("fs-readdir-recursive");
|
var readdir = require("fs-readdir-recursive");
|
||||||
var index = require("./index");
|
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 path = require("path");
|
||||||
var to5 = require("../../lib/6to5/api/node");
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ exports.transform = function (filename, code, opts) {
|
|||||||
|
|
||||||
var result;
|
var result;
|
||||||
try {
|
try {
|
||||||
result = to5.transform(code, opts);
|
result = babel.transform(code, opts);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof SyntaxError) {
|
if (e instanceof SyntaxError) {
|
||||||
console.error("SyntaxError:", e.message);
|
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-minify
Executable file
3
bin/deprecated/6to5-minify
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
console.error("`6to5-minify` has been renamed to `babel-minify`");
|
||||||
|
require("../babel-minify");
|
||||||
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,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,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,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,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"
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,7 @@ transform.load = function (url, callback, opts, hold) {
|
|||||||
|
|
||||||
var runScripts = function () {
|
var runScripts = function () {
|
||||||
var scripts = [];
|
var scripts = [];
|
||||||
var types = ["text/ecmascript-6", "text/6to5", "module"];
|
var types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
||||||
var exec = function () {
|
var exec = function () {
|
||||||
@@ -7,7 +7,7 @@ var fs = require("fs");
|
|||||||
|
|
||||||
exports.version = require("../../../package").version;
|
exports.version = require("../../../package").version;
|
||||||
|
|
||||||
exports.runtime = require("../build-runtime");
|
exports.buildExternalHelpers = require("../build-external-helpers");
|
||||||
|
|
||||||
exports.types = require("../types");
|
exports.types = require("../types");
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ exports.polyfill = function () {
|
|||||||
|
|
||||||
exports.canCompile = util.canCompile;
|
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._util = util;
|
||||||
|
|
||||||
exports.transform = transform;
|
exports.transform = transform;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"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 () {};
|
module.exports = function () {};
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ var path = require("path");
|
|||||||
var os = require("os");
|
var os = require("os");
|
||||||
var fs = require("fs");
|
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 = {};
|
var data = {};
|
||||||
|
|
||||||
exports.save = function () {
|
exports.save = function () {
|
||||||
@@ -12,6 +12,8 @@ exports.save = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.load = function () {
|
exports.load = function () {
|
||||||
|
if (process.env.BABEL_DISABLE_CACHE) return;
|
||||||
|
|
||||||
process.on("exit", exports.save);
|
process.on("exit", exports.save);
|
||||||
|
|
||||||
var sigint = function () {
|
var sigint = function () {
|
||||||
@@ -5,9 +5,9 @@ require("../../polyfill");
|
|||||||
var sourceMapSupport = require("source-map-support");
|
var sourceMapSupport = require("source-map-support");
|
||||||
var registerCache = require("./cache");
|
var registerCache = require("./cache");
|
||||||
var extend = require("lodash/object/extend");
|
var extend = require("lodash/object/extend");
|
||||||
|
var babel = require("../node");
|
||||||
var each = require("lodash/collection/each");
|
var each = require("lodash/collection/each");
|
||||||
var util = require("../../util");
|
var util = require("../../util");
|
||||||
var to5 = require("../node");
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
sourceMapSupport.install({
|
sourceMapSupport.install({
|
||||||
@@ -54,7 +54,7 @@ var compile = function (filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
result = to5.transformFileSync(filename, extend({
|
result = babel.transformFileSync(filename, extend({
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
ast: false
|
ast: false
|
||||||
}, transformOpts));
|
}, transformOpts));
|
||||||
@@ -6,7 +6,7 @@ var util = require("./util");
|
|||||||
var t = require("./types");
|
var t = require("./types");
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
var namespace = t.identifier("to5Runtime");
|
var namespace = t.identifier("babelHelpers");
|
||||||
|
|
||||||
var body = [];
|
var body = [];
|
||||||
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
|
||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
module.exports = Buffer;
|
module.exports = Buffer;
|
||||||
|
|
||||||
|
var repeating = require("repeating");
|
||||||
|
var trimRight = require("trim-right");
|
||||||
var isBoolean = require("lodash/lang/isBoolean");
|
var isBoolean = require("lodash/lang/isBoolean");
|
||||||
var includes = require("lodash/collection/includes");
|
var includes = require("lodash/collection/includes");
|
||||||
var isNumber = require("lodash/lang/isNumber");
|
var isNumber = require("lodash/lang/isNumber");
|
||||||
var util = require("../util");
|
|
||||||
|
|
||||||
function Buffer(position, format) {
|
function Buffer(position, format) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
@@ -15,14 +16,14 @@ function Buffer(position, format) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Buffer.prototype.get = function () {
|
Buffer.prototype.get = function () {
|
||||||
return util.trimRight(this.buf);
|
return trimRight(this.buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
Buffer.prototype.getIndent = function () {
|
Buffer.prototype.getIndent = function () {
|
||||||
if (this.format.compact || this.format.concise) {
|
if (this.format.compact || this.format.concise) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
return util.repeat(this._indent, this.format.indent.style);
|
return repeating(this.format.indent.style, this._indent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ Buffer.prototype.newline = function (i, removeLast) {
|
|||||||
|
|
||||||
if (isNumber(i)) {
|
if (isNumber(i)) {
|
||||||
if (this.endsWith("{\n")) i--;
|
if (this.endsWith("{\n")) i--;
|
||||||
if (this.endsWith(util.repeat(i, "\n"))) return;
|
if (this.endsWith(repeating("\n", i > 0 ? i : 0))) return;
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
this._newline(removeLast);
|
this._newline(removeLast);
|
||||||
@@ -153,9 +154,9 @@ Buffer.prototype.endsWith = function (str) {
|
|||||||
return d >= 0 && this.buf.lastIndexOf(str) === d;
|
return d >= 0 && this.buf.lastIndexOf(str) === d;
|
||||||
};
|
};
|
||||||
|
|
||||||
Buffer.prototype.isLast = function (cha, trimRight) {
|
Buffer.prototype.isLast = function (cha, shouldTrimRight) {
|
||||||
var buf = this.buf;
|
var buf = this.buf;
|
||||||
if (trimRight) buf = util.trimRight(buf);
|
if (shouldTrimRight) buf = trimRight(buf);
|
||||||
var last = buf[buf.length - 1];
|
var last = buf[buf.length - 1];
|
||||||
|
|
||||||
if (Array.isArray(cha)) {
|
if (Array.isArray(cha)) {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var util = require("../../util");
|
var isInteger = require("is-integer");
|
||||||
var t = require("../../types");
|
var isNumber = require("lodash/lang/isNumber");
|
||||||
var isNumber = require("lodash/lang/isNumber");
|
var t = require("../../types");
|
||||||
|
|
||||||
exports.UnaryExpression = function (node, print) {
|
exports.UnaryExpression = function (node, print) {
|
||||||
var hasSpace = /[a-z]$/.test(node.operator);
|
var hasSpace = /[a-z]$/.test(node.operator);
|
||||||
@@ -146,7 +146,7 @@ exports.MemberExpression = function (node, print) {
|
|||||||
this.push("]");
|
this.push("]");
|
||||||
} else {
|
} else {
|
||||||
// 5..toFixed(2);
|
// 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(".");
|
this.push(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var util = require("../../util");
|
var repeating = require("repeating");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
|
||||||
exports.WithStatement = function (node, print) {
|
exports.WithStatement = function (node, print) {
|
||||||
this.keyword("with");
|
this.keyword("with");
|
||||||
@@ -190,7 +190,7 @@ exports.VariableDeclaration = function (node, print, parent) {
|
|||||||
|
|
||||||
var sep = ",";
|
var sep = ",";
|
||||||
if (hasInits) {
|
if (hasInits) {
|
||||||
sep += "\n" + util.repeat(node.kind.length + 1);
|
sep += "\n" + repeating(" ", node.kind.length + 1);
|
||||||
} else {
|
} else {
|
||||||
sep += " ";
|
sep += " ";
|
||||||
}
|
}
|
||||||
@@ -9,13 +9,13 @@ module.exports.CodeGenerator = CodeGenerator;
|
|||||||
|
|
||||||
var detectIndent = require("detect-indent");
|
var detectIndent = require("detect-indent");
|
||||||
var Whitespace = require("./whitespace");
|
var Whitespace = require("./whitespace");
|
||||||
|
var repeating = require("repeating");
|
||||||
var SourceMap = require("./source-map");
|
var SourceMap = require("./source-map");
|
||||||
var Position = require("./position");
|
var Position = require("./position");
|
||||||
var Buffer = require("./buffer");
|
var Buffer = require("./buffer");
|
||||||
var extend = require("lodash/object/extend");
|
var extend = require("lodash/object/extend");
|
||||||
var merge = require("lodash/object/merge");
|
var merge = require("lodash/object/merge");
|
||||||
var each = require("lodash/collection/each");
|
var each = require("lodash/collection/each");
|
||||||
var util = require("../util");
|
|
||||||
var n = require("./node");
|
var n = require("./node");
|
||||||
var t = require("../types");
|
var t = require("../types");
|
||||||
|
|
||||||
@@ -344,7 +344,7 @@ CodeGenerator.prototype._printComments = function (comments) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var indent = Math.max(self.indentSize(), column);
|
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) {
|
if (column === 0) {
|
||||||
@@ -82,7 +82,7 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endToken.type.type === "eof") {
|
if (endToken && endToken.type.type === "eof") {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
var lines = this.getNewlinesBetween(startToken, endToken);
|
var lines = this.getNewlinesBetween(startToken, endToken);
|
||||||
@@ -96,6 +96,8 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
|
||||||
|
if (!endToken || !endToken.loc) return 0;
|
||||||
|
|
||||||
var start = startToken ? startToken.loc.end.line : 1;
|
var start = startToken ? startToken.loc.end.line : 1;
|
||||||
var end = endToken.loc.start.line;
|
var end = endToken.loc.start.line;
|
||||||
var lines = 0;
|
var lines = 0;
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
// syntax highlighting based on https://github.com/dominictarr/ansi-highlight by the fantastic Dominic Tarr
|
// syntax highlighting based on https://github.com/dominictarr/ansi-highlight by the fantastic Dominic Tarr
|
||||||
|
|
||||||
var supportsColor = require("supports-color");
|
var repeating = require("repeating");
|
||||||
var tokenize = require("js-tokenizer");
|
var tokenize = require("js-tokenizer");
|
||||||
var chalk = require("chalk");
|
var chalk = require("chalk");
|
||||||
var util = require("../util");
|
|
||||||
|
|
||||||
var defs = {
|
var defs = {
|
||||||
string1: "red",
|
string1: "red",
|
||||||
@@ -43,7 +42,7 @@ var highlight = function (text) {
|
|||||||
module.exports = function (lines, lineNumber, colNumber) {
|
module.exports = function (lines, lineNumber, colNumber) {
|
||||||
colNumber = Math.max(colNumber, 0);
|
colNumber = Math.max(colNumber, 0);
|
||||||
|
|
||||||
if (supportsColor) {
|
if (chalk.supportsColor) {
|
||||||
lines = highlight(lines);
|
lines = highlight(lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,15 +62,15 @@ module.exports = function (lines, lineNumber, colNumber) {
|
|||||||
|
|
||||||
var gutter = curr === lineNumber ? "> " : " ";
|
var gutter = curr === lineNumber ? "> " : " ";
|
||||||
|
|
||||||
var sep = curr + util.repeat(width + 1);
|
var sep = curr + repeating(" ", width + 1);
|
||||||
gutter += sep + "| ";
|
gutter += sep + "| ";
|
||||||
|
|
||||||
var str = gutter + line;
|
var str = gutter + line;
|
||||||
|
|
||||||
if (colNumber && curr === lineNumber) {
|
if (colNumber && curr === lineNumber) {
|
||||||
str += "\n";
|
str += "\n";
|
||||||
str += util.repeat(gutter.length - 2);
|
str += repeating(" ", gutter.length - 2);
|
||||||
str += "|" + util.repeat(colNumber) + "^";
|
str += "|" + repeating(" ", colNumber) + "^";
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
var normalizeAst = require("./normalize-ast");
|
var normalizeAst = require("./normalize-ast");
|
||||||
var estraverse = require("estraverse");
|
var estraverse = require("estraverse");
|
||||||
var codeFrame = require("./code-frame");
|
var codeFrame = require("./code-frame");
|
||||||
var acorn = require("acorn-6to5");
|
var acorn = require("acorn-babel");
|
||||||
|
|
||||||
module.exports = function (opts, code, callback) {
|
module.exports = function (opts, code, callback) {
|
||||||
try {
|
try {
|
||||||
@@ -30,8 +30,8 @@ module.exports = function (opts, code, callback) {
|
|||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!err._6to5) {
|
if (!err._babel) {
|
||||||
err._6to5 = true;
|
err._babel = true;
|
||||||
var message = opts.filename + ": " + err.message;
|
var message = opts.filename + ": " + err.message;
|
||||||
|
|
||||||
var loc = err.loc;
|
var loc = err.loc;
|
||||||
@@ -9,13 +9,15 @@ exports.messages = {
|
|||||||
scopeDuplicateDeclaration: "Duplicate declaration $1",
|
scopeDuplicateDeclaration: "Duplicate declaration $1",
|
||||||
undeclaredVariable: "Reference to undeclared variable $1",
|
undeclaredVariable: "Reference to undeclared variable $1",
|
||||||
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
|
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",
|
noAssignmentsInForHead: "No assignments allowed in for-in/of head",
|
||||||
expectedMemberExpressionOrIdentifier: "Expected type MemeberExpression or Identifier",
|
expectedMemberExpressionOrIdentifier: "Expected type MemeberExpression or Identifier",
|
||||||
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
|
invalidParentForThisNode: "We don't know how to handle this node within the current parent - please open an issue",
|
||||||
readOnly: "$1 is read-only",
|
readOnly: "$1 is read-only",
|
||||||
modulesIllegalExportName: "Illegal export $1",
|
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"
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.get = function (key) {
|
exports.get = function (key) {
|
||||||
@@ -8,7 +8,7 @@ var t = require("./types");
|
|||||||
var estraverse = require("estraverse");
|
var estraverse = require("estraverse");
|
||||||
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
|
||||||
|
|
||||||
// regenerator-6to5/ast-types
|
// regenerator-babel/ast-types
|
||||||
|
|
||||||
var types = require("ast-types");
|
var types = require("ast-types");
|
||||||
var def = types.Type.def;
|
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,20 +2,21 @@
|
|||||||
|
|
||||||
module.exports = File;
|
module.exports = File;
|
||||||
|
|
||||||
var SHEBANG_REGEX = /^\#\!.*/;
|
var sourceMapToComment = require("source-map-to-comment");
|
||||||
|
var shebangRegex = require("shebang-regex");
|
||||||
var isFunction = require("lodash/lang/isFunction");
|
var isFunction = require("lodash/lang/isFunction");
|
||||||
var transform = require("./index");
|
var transform = require("./index");
|
||||||
var generate = require("../generation");
|
var generate = require("../generation");
|
||||||
var defaults = require("lodash/object/defaults");
|
var defaults = require("lodash/object/defaults");
|
||||||
var includes = require("lodash/collection/includes");
|
var includes = require("lodash/collection/includes");
|
||||||
var clone = require("../helpers/clone");
|
var assign = require("lodash/object/assign");
|
||||||
var parse = require("../helpers/parse");
|
var parse = require("../helpers/parse");
|
||||||
var Scope = require("../traversal/scope");
|
var Scope = require("../traversal/scope");
|
||||||
var util = require("../util");
|
var slash = require("slash");
|
||||||
var path = require("path");
|
var util = require("../util");
|
||||||
var each = require("lodash/collection/each");
|
var path = require("path");
|
||||||
var t = require("../types");
|
var each = require("lodash/collection/each");
|
||||||
|
var t = require("../types");
|
||||||
|
|
||||||
function File(opts) {
|
function File(opts) {
|
||||||
this.dynamicImportedNoDefault = [];
|
this.dynamicImportedNoDefault = [];
|
||||||
@@ -59,7 +60,8 @@ File.helpers = [
|
|||||||
"object-destructuring-empty",
|
"object-destructuring-empty",
|
||||||
"temporal-undefined",
|
"temporal-undefined",
|
||||||
"temporal-assert-defined",
|
"temporal-assert-defined",
|
||||||
"tail-call"
|
"tail-call",
|
||||||
|
"self-global"
|
||||||
];
|
];
|
||||||
|
|
||||||
File.validOptions = [
|
File.validOptions = [
|
||||||
@@ -85,7 +87,8 @@ File.validOptions = [
|
|||||||
"playground",
|
"playground",
|
||||||
"experimental",
|
"experimental",
|
||||||
"resolveModuleSource",
|
"resolveModuleSource",
|
||||||
"runtime",
|
"externalHelpers",
|
||||||
|
"auxiliaryComment",
|
||||||
|
|
||||||
// these are used by plugins
|
// these are used by plugins
|
||||||
"ignore",
|
"ignore",
|
||||||
@@ -95,7 +98,7 @@ File.validOptions = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
File.prototype.normalizeOptions = function (opts) {
|
File.prototype.normalizeOptions = function (opts) {
|
||||||
opts = clone(opts);
|
opts = assign({}, opts);
|
||||||
|
|
||||||
for (var key in opts) {
|
for (var key in opts) {
|
||||||
if (key[0] !== "_" && File.validOptions.indexOf(key) < 0) {
|
if (key[0] !== "_" && File.validOptions.indexOf(key) < 0) {
|
||||||
@@ -106,6 +109,8 @@ File.prototype.normalizeOptions = function (opts) {
|
|||||||
defaults(opts, {
|
defaults(opts, {
|
||||||
keepModuleIdExtensions: false,
|
keepModuleIdExtensions: false,
|
||||||
resolveModuleSource: null,
|
resolveModuleSource: null,
|
||||||
|
externalHelpers: false,
|
||||||
|
auxilaryComment: "",
|
||||||
experimental: false,
|
experimental: false,
|
||||||
reactCompat: false,
|
reactCompat: false,
|
||||||
playground: false,
|
playground: false,
|
||||||
@@ -118,16 +123,15 @@ File.prototype.normalizeOptions = function (opts) {
|
|||||||
comments: true,
|
comments: true,
|
||||||
filename: "unknown",
|
filename: "unknown",
|
||||||
modules: "common",
|
modules: "common",
|
||||||
runtime: false,
|
|
||||||
loose: [],
|
loose: [],
|
||||||
code: true,
|
code: true,
|
||||||
ast: true
|
ast: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// normalize windows path separators to unix
|
// normalize windows path separators to unix
|
||||||
opts.filename = util.normalisePathSeparator(opts.filename);
|
opts.filename = slash(opts.filename);
|
||||||
if (opts.sourceRoot) {
|
if (opts.sourceRoot) {
|
||||||
opts.sourceRoot = util.normalisePathSeparator(opts.sourceRoot);
|
opts.sourceRoot = slash(opts.sourceRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
||||||
@@ -162,8 +166,8 @@ File.prototype.normalizeOptions = function (opts) {
|
|||||||
opts.experimental = true;
|
opts.experimental = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.runtime) {
|
if (opts.externalHelpers) {
|
||||||
this.set("runtimeIdentifier", t.identifier("to5Runtime"));
|
this.set("runtimeIdentifier", t.identifier("babelHelpers"));
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
|
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
|
||||||
@@ -243,12 +247,13 @@ File.prototype.getModuleFormatter = function (type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
File.prototype.parseShebang = function (code) {
|
File.prototype.parseShebang = function (code) {
|
||||||
var shebangMatch = code.match(SHEBANG_REGEX);
|
var shebangMatch = shebangRegex.exec(code);
|
||||||
|
|
||||||
if (shebangMatch) {
|
if (shebangMatch) {
|
||||||
this.shebang = shebangMatch[0];
|
this.shebang = shebangMatch[0];
|
||||||
|
|
||||||
// remove shebang
|
// remove shebang
|
||||||
code = code.replace(SHEBANG_REGEX, "");
|
code = code.replace(shebangRegex, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
@@ -298,6 +303,18 @@ File.prototype.isConsequenceExpressionStatement = function (node) {
|
|||||||
return t.isExpressionStatement(node) && this.lastStatements.indexOf(node) >= 0;
|
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) {
|
File.prototype.addHelper = function (name) {
|
||||||
if (!includes(File.helpers, name)) {
|
if (!includes(File.helpers, name)) {
|
||||||
throw new ReferenceError("Unknown helper " + name);
|
throw new ReferenceError("Unknown helper " + name);
|
||||||
@@ -352,7 +369,7 @@ File.prototype.parse = function (code) {
|
|||||||
var opts = this.opts;
|
var opts = this.opts;
|
||||||
|
|
||||||
opts.allowImportExportEverywhere = this.isLoose("es6.modules");
|
opts.allowImportExportEverywhere = this.isLoose("es6.modules");
|
||||||
//opts.strictMode = this.transformers.useStrict.canRun();
|
opts.strictMode = this.transformers.useStrict.canRun();
|
||||||
|
|
||||||
return parse(opts, code, function (tree) {
|
return parse(opts, code, function (tree) {
|
||||||
self.transform(tree);
|
self.transform(tree);
|
||||||
@@ -440,7 +457,7 @@ File.prototype.generate = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts.sourceMap === "inline") {
|
if (opts.sourceMap === "inline") {
|
||||||
result.code += "\n" + util.sourceMapToComment(result.map);
|
result.code += "\n" + sourceMapToComment(result.map);
|
||||||
result.map = null;
|
result.map = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,10 +31,7 @@ transform._ensureTransformerNames = function (type, rawKeys) {
|
|||||||
var deprecatedKey = transform.deprecatedTransformerMap[key];
|
var deprecatedKey = transform.deprecatedTransformerMap[key];
|
||||||
if (deprecatedKey) {
|
if (deprecatedKey) {
|
||||||
// deprecated key, remap it to the new one
|
// deprecated key, remap it to the new one
|
||||||
console.error(
|
console.error("The transformer " + key + " has been renamed to " + deprecatedKey);
|
||||||
"The transformer " + key + " has been renamed to " + deprecatedKey +
|
|
||||||
" in v3.0.0 - backwards compatibilty will be removed 4.0.0"
|
|
||||||
);
|
|
||||||
rawKeys.push(deprecatedKey);
|
rawKeys.push(deprecatedKey);
|
||||||
} else if (transform.transformers[key]) {
|
} else if (transform.transformers[key]) {
|
||||||
// valid key
|
// valid key
|
||||||
@@ -44,12 +41,7 @@ transform._ensureTransformerNames = function (type, rawKeys) {
|
|||||||
keys = keys.concat(transform.namespaces[key]);
|
keys = keys.concat(transform.namespaces[key]);
|
||||||
} else {
|
} else {
|
||||||
// invalid key
|
// invalid key
|
||||||
throw new ReferenceError(
|
throw new ReferenceError("Unknown transformer " + key + " specified in " + type);
|
||||||
"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"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4,6 +4,7 @@ var util = require("../../util");
|
|||||||
|
|
||||||
module.exports = function (Parent) {
|
module.exports = function (Parent) {
|
||||||
var Constructor = function () {
|
var Constructor = function () {
|
||||||
|
this.noInteropRequireImport = true;
|
||||||
this.noInteropRequireExport = true;
|
this.noInteropRequireExport = true;
|
||||||
Parent.apply(this, arguments);
|
Parent.apply(this, arguments);
|
||||||
};
|
};
|
||||||
@@ -20,7 +20,9 @@ CommonJSFormatter.prototype.init = function () {
|
|||||||
scope.rename("module");
|
scope.rename("module");
|
||||||
|
|
||||||
if (!this.noInteropRequireImport && this.hasNonDefaultExports) {
|
if (!this.noInteropRequireImport && this.hasNonDefaultExports) {
|
||||||
file.ast.program.body.push(util.template("exports-module-declaration", true));
|
var templateName = "exports-module-declaration";
|
||||||
|
if (this.file.isLoose("es6.modules")) templateName += "-loose";
|
||||||
|
file.ast.program.body.push(util.template(templateName, true));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
10
lib/babel/transformation/modules/index.js
Normal file
10
lib/babel/transformation/modules/index.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
module.exports = {
|
||||||
|
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")
|
||||||
|
};
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user