Compare commits

..

375 Commits

Author SHA1 Message Date
Sebastian McKenzie
39854dc088 v4.4.3 2015-02-21 18:13:10 +11:00
Sebastian McKenzie
81132aa942 add 4.4.3 changelog 2015-02-21 18:08:32 +11:00
Sebastian McKenzie
5ba2e6254b check if iterator has a return method before calling it when breaking in a for...of - #838 2015-02-21 18:00:43 +11:00
Sebastian McKenzie
61ea720637 don't traverse into replacement breaks in for-of transformer - thanks @zloirock 2015-02-21 17:55:38 +11:00
Sebastian McKenzie
55357a331d rename selfContained transformer to runtime 2015-02-21 17:20:59 +11:00
Sebastian McKenzie
5deaeba3a0 4.4.2 2015-02-21 14:31:52 +11:00
Sebastian McKenzie
a38ae381e2 v4.4.2 2015-02-21 14:31:07 +11:00
Sebastian McKenzie
9a2e56f003 add moduleId option for specifying a custom module id 2015-02-21 14:29:26 +11:00
Sebastian McKenzie
5bc78b0237 4.4.1 2015-02-21 14:23:36 +11:00
Sebastian McKenzie
c5af8b8694 v4.4.1 2015-02-21 14:23:04 +11:00
Sebastian McKenzie
c637575cab remove tail-call template 2015-02-21 14:21:31 +11:00
Sebastian McKenzie
bc8d49c95c v4.4.0 2015-02-21 14:20:37 +11:00
Sebastian McKenzie
59ff0fd9a9 remove redundant esnext test 2015-02-21 14:18:53 +11:00
Sebastian McKenzie
b1f794eb84 fix linting errors 2015-02-21 14:16:02 +11:00
Sebastian McKenzie
79ab92b5d4 add 4.4.0 changelog 2015-02-21 14:14:50 +11:00
Sebastian McKenzie
f6512b45d5 coerce inferred function name to a valid identifier 2015-02-21 14:11:18 +11:00
Sebastian McKenzie
8065c981dc add iterator.return to for-of breaks - fixes #838 2015-02-21 13:31:14 +11:00
Sebastian McKenzie
7927aa2e18 make use strict directive stateless - fixes #828 2015-02-21 13:06:02 +11:00
Sebastian McKenzie
35bd510930 make react JSX transformer more generic and allow JSX comments - closes #841 2015-02-21 12:53:09 +11:00
Sebastian McKenzie
74186241f9 fix linting errors 2015-02-21 12:41:11 +11:00
Sebastian McKenzie
1effa72a33 remove format options but move compact option to main options 2015-02-21 12:41:03 +11:00
Sebastian McKenzie
b03a806d7c don't append a newline to the last switchcase 2015-02-21 12:27:38 +11:00
Sebastian McKenzie
6220fd9fc3 better control flow for tco continuation - fixes #850 and fixes #822 2015-02-21 12:27:24 +11:00
Sebastian McKenzie
8d92a75190 remove whitespace from the end of the last newline and improve newlines for switches 2015-02-21 03:22:44 +11:00
Sebastian McKenzie
60a7e40140 add website/docs issues reference to the readme 2015-02-21 02:24:28 +11:00
Sebastian McKenzie
299e462a29 unpack array rest elements when given a right hand array expression 2015-02-21 02:09:07 +11:00
Sebastian McKenzie
62556f6102 finish code generator revamp, output is now much nicer and liberal with it's use of newlines 2015-02-20 23:24:11 +11:00
Sebastian McKenzie
f2c5accab3 add getModuleName option - fixes #844 2015-02-20 23:23:50 +11:00
Sebastian McKenzie
15f1978cae Merge branch 'master' of github.com:6to5/6to5 2015-02-20 11:35:46 +11:00
Sebastian McKenzie
710ff548cb improve whitespace handling of code generator, reduce the use of lookaheads, add max newlines of 2 and better newline insertion for generated nodes 2015-02-20 11:35:27 +11:00
Sebastian McKenzie
fbb19fc656 clean up type alias keys 2015-02-20 11:34:43 +11:00
Sebastian McKenzie
e87ef80bc5 add back named methods for classes and add param binding check to spec.functionName transformer 2015-02-20 11:34:00 +11:00
Sebastian McKenzie
aca750e881 Merge pull request #839 from raganwald/patch-1
Links the babel logo in the readme to the home page
2015-02-20 08:00:26 +11:00
Reg Braithwaite
672e55082c link the babel logo in the readme to the home page 2015-02-19 15:46:35 -05:00
Sebastian McKenzie
a49f746700 add end_of_line = lf to editorconfig 2015-02-19 22:00:24 +11:00
Sebastian McKenzie
83cd3bef92 clean up destructuring transformer and optimise array destructuring - closes #749 2015-02-19 19:16:27 +11:00
Sebastian McKenzie
5e4a008a06 make code generator deopt on input >100KB 2015-02-19 10:48:08 +11:00
Sebastian McKenzie
1594efbc20 remove unused whitespace option 2015-02-19 10:47:51 +11:00
Sebastian McKenzie
002be9a05c enable spec.functionName by default 2015-02-19 10:47:44 +11:00
Sebastian McKenzie
8e06db8f7d remove minify binary 2015-02-19 10:47:08 +11:00
Sebastian McKenzie
b1238a1746 Merge branch 'master' of github.com:6to5/6to5 2015-02-19 10:46:47 +11:00
Ingvar Stepanyan
0874f390ff Add explicit return at the end of tail-recursive function.
Issue #822.
2015-02-18 14:44:47 +02:00
Sebastian McKenzie
eeff4ac9d1 add support for a string literal constructor name 2015-02-18 15:06:18 +11:00
Sebastian McKenzie
8f0ffc7302 4.3.0 2015-02-18 15:05:56 +11:00
Sebastian McKenzie
bb19649af8 v4.3.0 2015-02-18 13:15:45 +11:00
Sebastian McKenzie
692262df1b fix linting errors 2015-02-18 13:14:06 +11:00
Sebastian McKenzie
067047da34 update commonStandard tests to commonStrict 2015-02-18 13:10:25 +11:00
Sebastian McKenzie
1c5d169b1e 4.2.1 2015-02-18 13:08:36 +11:00
Sebastian McKenzie
3f82b4ec72 remove commonStandard module formatter and make it the default behaviour of all the strict module formatters 2015-02-18 13:08:25 +11:00
Sebastian McKenzie
9c6e632021 Merge pull request #785 from babel/fn-name
Set Function.name for funcs in variables and properties as per spec.
2015-02-18 11:49:52 +11:00
Sebastian McKenzie
45553f1fb7 v4.2.1 2015-02-18 11:37:47 +11:00
Sebastian McKenzie
f228edbb84 add auxiliary comment to let scoping closure flow control - fixes #819 2015-02-18 11:35:57 +11:00
Sebastian McKenzie
64e657e53d 4.2.0 2015-02-18 11:33:58 +11:00
Sebastian McKenzie
36423f2e78 v4.2.0 2015-02-18 11:28:53 +11:00
Sebastian McKenzie
06eaba5ad1 add 4.2.0 changelog 2015-02-18 11:26:46 +11:00
Sebastian McKenzie
7e8cd2ca8a i'm a terrible spellerer #777 2015-02-18 11:24:51 +11:00
Sebastian McKenzie
2541dcf960 bump acorn 2015-02-18 10:25:59 +11:00
Sebastian McKenzie
5d45e1475c Merge branch 'master' of github.com:6to5/6to5 2015-02-18 10:22:33 +11:00
Sebastian McKenzie
9964de9b2f remove redundant unknown transformer error message 2015-02-18 10:22:07 +11:00
Sebastian McKenzie
5b75b11628 add error message to use of eval(); and enable strict mode on the parser 2015-02-18 10:21:57 +11:00
Sebastian McKenzie
1890fb5bd3 add loose mode to __esModule 2015-02-18 10:21:32 +11:00
Sebastian McKenzie
df20b3df5a Merge pull request #815 from kolodny/iojs-test
add iojs to travis
2015-02-18 08:46:38 +11:00
Moshe Kolodny
56e74dfd10 add iojs to travis 2015-02-17 13:31:45 -05:00
Sebastian McKenzie
513d05143a 4.1.1 2015-02-18 00:01:55 +11:00
Sebastian McKenzie
84068943dd v4.1.1 2015-02-18 00:01:18 +11:00
Sebastian McKenzie
d3c75378ec v4.1.0 2015-02-17 23:59:38 +11:00
Sebastian McKenzie
ffe058bf69 add BABEL_CACHE_PATH and BABEL_DISABLE_CACHE environment variables 2015-02-17 23:06:19 +11:00
Sebastian McKenzie
765d95cd6f Merge branch 'master' of github.com:6to5/6to5 2015-02-17 16:57:26 +11:00
Sebastian McKenzie
33e82222ca remove 0.11 from travis.yml - #813, #807 2015-02-17 16:56:28 +11:00
Sebastian McKenzie
82d1c29696 Merge pull request #812 from sindresorhus/modularize-shebang-regex
modularize `SHEBANG_REGEX`
2015-02-17 16:33:12 +11:00
Sindre Sorhus
211c9802a5 modularize SHEBANG_REGEX
https://github.com/sindresorhus/shebang-regex
2015-02-17 12:26:36 +07:00
Sebastian McKenzie
f5a81e71bd Merge pull request #811 from sindresorhus/drop-helpers-clone
drop `helpers/clone`
2015-02-17 15:55:51 +11:00
Sindre Sorhus
4ea7a864fa drop helpers/clone
it's misleading as it doesn't actually do a deepClone, not even a clone
2015-02-17 11:42:24 +07:00
Sebastian McKenzie
d645659770 Merge pull request #810 from sindresorhus/modularize-normalisePathSeparator
modularize `normalisePathSeparator`
2015-02-17 15:24:06 +11:00
Sindre Sorhus
75ec9c8f2c modularize normalisePathSeparator
https://github.com/sindresorhus/slash
2015-02-17 11:19:12 +07:00
Sebastian McKenzie
3bffdc2be0 Merge pull request #809 from sindresorhus/modularize-isinteger
modularize `util.isInteger`
2015-02-17 15:12:18 +11:00
Sindre Sorhus
820db09613 modularize util.isInteger
https://github.com/parshap/js-is-integer
2015-02-17 11:10:00 +07:00
Sebastian McKenzie
f24ae6feab Merge pull request #808 from sindresorhus/modularize-trimright
modularize `util.trimRight`
2015-02-17 14:54:11 +11:00
Sindre Sorhus
5b09114b85 modularize util.trimRight
https://github.com/sindresorhus/trim-right
2015-02-17 10:51:02 +07:00
Sebastian McKenzie
28c948e5ea Merge pull request #806 from sindresorhus/modularize-isabsolute
modularize `util.isAbsolute`
2015-02-17 14:29:26 +11:00
Sindre Sorhus
bbf5a8f4aa modularize util.isAbsolute
by using a polyfill of the Node 0.12 `path.isAbsolute()` method

https://github.com/sindresorhus/path-is-absolute
2015-02-17 10:17:04 +07:00
Sebastian McKenzie
5f2865883b Merge branch 'master' of github.com:6to5/6to5 2015-02-17 14:09:49 +11:00
Sebastian McKenzie
c8433f950d fix 4.0.2 changelog... 2015-02-17 14:09:09 +11:00
Sebastian McKenzie
9135e700c6 Merge pull request #805 from sindresorhus/modularize-repeat
modularize `util.repeat`
2015-02-17 13:28:49 +11:00
Sindre Sorhus
eb17568c94 modularize util.repeat
https://github.com/sindresorhus/repeating
2015-02-17 09:25:00 +07:00
Sebastian McKenzie
407ff1e4a0 add 4.0.2 changelog 2015-02-17 13:12:31 +11:00
Sebastian McKenzie
fbaaf63c49 4.0.2 2015-02-17 13:11:15 +11:00
Sebastian McKenzie
f93daa3ca5 v4.0.2 2015-02-17 13:10:18 +11:00
Sebastian McKenzie
7fc1d04f9b Merge branch 'master' of github.com:6to5/6to5 2015-02-17 13:07:35 +11:00
Sebastian McKenzie
d6a34f02ca upgrade regenerator-babel #803 2015-02-17 13:07:22 +11:00
Sebastian McKenzie
fc3cb099c5 Merge pull request #802 from sindresorhus/sourcemapcomment
modularize the `sourceMapToComment` method
2015-02-17 12:49:12 +11:00
Sindre Sorhus
fc663d54fa modularize the sourceMapToComment method
https://github.com/sindresorhus/source-map-to-comment
2015-02-17 08:46:23 +07:00
Sebastian McKenzie
bf2418db66 set loose property assignments to computed if it's a literal 2015-02-17 10:45:24 +11:00
Sebastian McKenzie
5bd75db0b6 update setter validation error message 2015-02-17 09:34:45 +11:00
Sebastian McKenzie
13b3335a67 Merge pull request #800 from sindresorhus/remove-unused-deps
remove unused dependencies
2015-02-17 09:26:17 +11:00
Sindre Sorhus
4987f9e668 remove unused dependencies 2015-02-17 05:23:50 +07:00
Sebastian McKenzie
e585aa6bed use ranges for devDependencies 2015-02-17 09:23:48 +11:00
Sebastian McKenzie
d6c7be760b update settersInvalidParamLength error message - closes #797 2015-02-17 09:17:06 +11:00
Sebastian McKenzie
a19321ea69 update dependency ranges 2015-02-17 09:13:23 +11:00
Sebastian McKenzie
73fc1ac64e Merge pull request #794 from sindresorhus/bump-deps
bump dependencies
2015-02-17 09:11:10 +11:00
Sindre Sorhus
1d14764471 bump dependencies
The only breaking change is 599dd668fd and it doesn't affect `babel` since it doesn't use that property.
2015-02-17 05:02:32 +07:00
Sebastian McKenzie
e336ecd9cc Merge pull request #792 from sindresorhus/remove-moot-dep
Remove `supports-color` dependency as it's available in `chalk`
2015-02-17 08:53:42 +11:00
Sebastian McKenzie
5737a96f9f Merge pull request #793 from sindresorhus/levenshtein
Use `leven` module for levenshtein distance
2015-02-17 08:53:02 +11:00
Sebastian McKenzie
d7d4ec54cd Merge pull request #796 from richgilbank/babel-rename-makefile
Fix leftover `to5`
2015-02-17 08:49:18 +11:00
Rich Gilbank
98056e26af Update Makefile 2015-02-16 11:52:20 -05:00
Sindre Sorhus
afd07c9172 Use leven module for levenshtein distance
https://github.com/sindresorhus/leven

No point in bundling code like this.

Leven is also the fastest one: https://github.com/sindresorhus/leven#benchmark
2015-02-16 22:36:20 +07:00
Sindre Sorhus
af785126bf Remove supports-color dependency as it's available in chalk 2015-02-16 22:28:51 +07:00
Sebastian McKenzie
39c5849604 Merge branch 'master' of github.com:6to5/6to5 2015-02-16 14:37:08 +11:00
Sebastian McKenzie
1b6e465317 add email to license 2015-02-16 14:36:57 +11:00
Ingvar Stepanyan
17e65cc772 Set Function.name for funcs in variables and properties as per spec.
Implements correct Function.name for cases like following:
 * `var x = function () { ... }`
 * `var obj = {prop: function () { ... }}`
2015-02-15 23:43:17 +02:00
Sebastian McKenzie
15dff73cc8 Merge pull request #783 from mathiasbynens/patch-3
Update to regexpu v1.1.1
2015-02-16 03:05:59 +11:00
Mathias Bynens
186a15b3ce Update to regexpu v1.1.1 2015-02-15 17:05:35 +01:00
Sebastian McKenzie
610e52d767 4.0.1 2015-02-16 01:12:13 +11:00
Sebastian McKenzie
b0467fcb6d v4.0.1 2015-02-16 01:11:46 +11:00
Sebastian McKenzie
05be131647 rename bin tests to reflect new babel name 2015-02-16 01:08:26 +11:00
Sebastian McKenzie
f2300a5463 Revert "don't push array pattern uid if it's a local variable"
This reverts commit 86acc99fb3.
2015-02-16 01:06:14 +11:00
Sebastian McKenzie
86acc99fb3 don't push array pattern uid if it's a local variable 2015-02-16 01:01:42 +11:00
Sebastian McKenzie
21909cee76 rename runtime CLI flag to externalHelpers 2015-02-16 01:01:29 +11:00
Sebastian McKenzie
c97b53b52d fix 6to5 changelog 2015-02-16 01:01:14 +11:00
Sebastian McKenzie
c5e01146fd update rogue 6to5 occurences to babel 2015-02-15 20:39:46 +11:00
Sebastian McKenzie
010ff3ec31 reset transformer deprecation keys 2015-02-15 20:29:48 +11:00
Sebastian McKenzie
17532bfd82 update to 4.0.0 2015-02-15 19:54:14 +11:00
Sebastian McKenzie
545e9499c3 update readme to reflect babel name change 2015-02-15 19:54:08 +11:00
Sebastian McKenzie
02046c5448 rename runtime option to externalHelpers 2015-02-15 19:53:59 +11:00
Sebastian McKenzie
1d34d03ac8 rename to babel 2015-02-15 18:09:05 +11:00
Sebastian McKenzie
e05aed0394 support all loops when adding declarations - #779 2015-02-15 10:27:56 +11:00
Sebastian McKenzie
2d3b595a8b 3.6.5 2015-02-15 10:26:52 +11:00
Sebastian McKenzie
8f0b7683a1 v3.6.5 2015-02-14 23:05:13 +11:00
Sebastian McKenzie
f0d2cbb055 update 3.6.5 changelog 2015-02-14 22:57:57 +11:00
Sebastian McKenzie
602c5e0ca0 upgrade core-js 2015-02-14 22:56:49 +11:00
Sebastian McKenzie
2a2dff0eaf remap head variables when a closure is required in blockScoping transformer - fixes #763 2015-02-14 20:21:34 +11:00
Sebastian McKenzie
e1151e08c9 register default globals as bindings 2015-02-14 19:08:41 +11:00
Sebastian McKenzie
84f54ca3c7 rename defaultDeclarations to globals 2015-02-14 19:08:02 +11:00
Sebastian McKenzie
5fb793b75f add validation.react transformer 2015-02-14 19:07:54 +11:00
Sebastian McKenzie
1adc9bfc70 use t.buildMatchMemberExpression in selfContained transformer 2015-02-14 19:07:46 +11:00
Sebastian McKenzie
3649fad485 ensureBlock on if statements with expression return statements - fixes #764 2015-02-14 19:07:23 +11:00
Sebastian McKenzie
0e1743738e add auxilary comment option to prepend to helpers - #777 2015-02-14 16:53:41 +11:00
Sebastian McKenzie
6ad16302cd update 3.6.3 changelog 2015-02-14 13:29:57 +11:00
Sebastian McKenzie
4b6b7af332 3.6.4 2015-02-14 13:29:52 +11:00
Sebastian McKenzie
55dfb423ee v3.6.4 2015-02-14 13:26:59 +11:00
Sebastian McKenzie
9d1bc4817d fix flow module type stripping 2015-02-14 13:24:39 +11:00
Sebastian McKenzie
fc8666e7a4 3.6.3 2015-02-14 13:22:18 +11:00
Sebastian McKenzie
07b6881d67 add support for flow type casts and module types 2015-02-14 13:22:13 +11:00
Sebastian McKenzie
1f208a06db v3.6.3 2015-02-14 13:01:17 +11:00
Sebastian McKenzie
b5c9c84542 update bin/6to5 tests to reflect new source location 2015-02-14 12:59:31 +11:00
Sebastian McKenzie
492555bb4e fix linting errors 2015-02-14 12:54:44 +11:00
Sebastian McKenzie
53d88c0f63 upgrade acorn-6to5 2015-02-14 12:53:54 +11:00
Sebastian McKenzie
8a5da57162 use default property on 6to5-runtime modules - fixes #774 2015-02-14 00:59:34 +11:00
Sebastian McKenzie
1627e2f47e use sourceFileName instead of sourceMapName - fixes #775 2015-02-14 00:44:32 +11:00
Sebastian McKenzie
e195d6ca55 use relative location when generating the sourceMapName in bin/6to5 for directories - fixes #775 2015-02-13 23:08:47 +11:00
Sebastian McKenzie
71d5d4fb2c remove MemberExpression from binding identifier collection 2015-02-13 21:10:23 +11:00
Sebastian McKenzie
dfe13cda0d 3.6.2 2015-02-13 21:08:14 +11:00
Sebastian McKenzie
a4c6660d21 v3.6.2 2015-02-13 21:07:45 +11:00
Sebastian McKenzie
9676666e7c 3.6.1 2015-02-13 21:05:56 +11:00
Sebastian McKenzie
388133642d add support for UnaryExpression to getBindingIdentifiers and add it as a reassignment in the scope tracking 2015-02-13 21:05:52 +11:00
Sebastian McKenzie
23b5eeb72f use Symbol.iterator in for symbol detection and add the conversion of it to the selfContained transformer - @zloirock 2015-02-13 21:05:21 +11:00
Sebastian McKenzie
db36c3a7c2 v3.6.1 2015-02-13 20:50:37 +11:00
Sebastian McKenzie
e841b88cbc fix 6to5-node test collisions 2015-02-13 20:48:52 +11:00
Sebastian McKenzie
3d874f2479 update sliceToArray helper, again... 2015-02-13 20:45:43 +11:00
Sebastian McKenzie
228719102a update sliceToArray tests 2015-02-13 20:39:37 +11:00
Sebastian McKenzie
c6ce1a248c better slicedToArray helper 2015-02-13 20:38:28 +11:00
Sebastian McKenzie
ba9b85f64b only use functions returnType if it hasn't been reassigned 2015-02-13 20:36:43 +11:00
Sebastian McKenzie
56c868efee fix incorrect generateUid references in File 2015-02-13 18:27:53 +11:00
Sebastian McKenzie
1f3c3832ba fix linting errors 2015-02-13 18:25:34 +11:00
Sebastian McKenzie
3b04a8c648 fix linting errors 2015-02-13 18:24:24 +11:00
Sebastian McKenzie
2270057b54 add 3.6.1 changelog 2015-02-13 18:23:46 +11:00
Sebastian McKenzie
c3206aa9a4 move File::generateUid to Scope and add return type inferrence 2015-02-13 18:21:28 +11:00
Sebastian McKenzie
1912d1b26a remove ExportSpecifier from t.getBindingIdentifiers as it has none 2015-02-13 18:19:27 +11:00
Sebastian McKenzie
9208e7e594 update common standard import test 2015-02-13 17:47:46 +11:00
Sebastian McKenzie
ce332b3384 fix module binding resolution - fixes #762 2015-02-13 17:37:35 +11:00
Sebastian McKenzie
a567531f77 ignore member expressions in constants transformer - fixes #770 2015-02-13 17:18:42 +11:00
Sebastian McKenzie
9cce72def0 update tests that use the toSlicedArray helper 2015-02-13 17:04:18 +11:00
Sebastian McKenzie
2d8581c6dc Merge branch 'master' of github.com:6to5/6to5
Conflicts:
	lib/6to5/transformation/transformers/minification/dead-code-elimination.js
2015-02-13 16:54:09 +11:00
Sebastian McKenzie
14a000396a add error message to the sliced-to-array helper on a non-iterable param - fixes #766 2015-02-13 16:50:03 +11:00
Sebastian McKenzie
4c41f5a22f bump acorn-6to5 and 6to5 devDependency 2015-02-13 15:09:28 +11:00
Sebastian McKenzie
6be2a6e02a add extra note to minification dead code elimination transformer 2015-02-13 15:09:17 +11:00
Sebastian McKenzie
0a4fc16ca0 add type inferrence that expires when a binding is reassigned 2015-02-13 15:08:58 +11:00
Sebastian McKenzie
25d8377411 normalise JSX attribute strings 2015-02-13 15:08:39 +11:00
Brian Donovan
14267a788d Fix a typo. 2015-02-12 19:12:09 -08:00
Sebastian McKenzie
ba5c5760b1 Merge pull request #769 from 6to5/if-truthy-minification-returns-consequent
Return the consequent if the test is truthy.
2015-02-13 14:08:32 +11:00
Brian Donovan
49904b3ab3 Fix a small grammar issue. 2015-02-12 19:07:54 -08:00
Brian Donovan
a212f035e4 Return the consequent if the test is truthy. 2015-02-12 19:06:06 -08:00
Brian Donovan
ea471a6a17 Fix a few typos. 2015-02-12 18:47:08 -08:00
Brian Donovan
f5bae0b696 Remove redundant variable. 2015-02-12 18:46:53 -08:00
Brian Donovan
9ec9e13aeb Update the jsdoc to indicate that key is optional. 2015-02-12 18:36:36 -08:00
Brian Donovan
0b042b2681 Use the posessive form of "its", not a contraction of "it is". 2015-02-12 18:36:02 -08:00
Brian Donovan
83b4d12884 Correct a jsdoc comment parameter name. 2015-02-12 18:35:35 -08:00
Brian Donovan
98d555498d Remove unused variable. 2015-02-12 18:29:14 -08:00
Sebastian McKenzie
fdc05cb977 Merge pull request #767 from 6to5/templates-should-not-recurse
Ensure that templates do not recurse.
2015-02-13 11:13:30 +11:00
Brian Donovan
928ebda5bc Ensure that templates do not recurse.
Closes #765.
2015-02-12 16:10:13 -08:00
Sebastian McKenzie
0a2003af66 3.6.0 2015-02-12 21:59:37 +11:00
Sebastian McKenzie
02392635ef v3.6.0 2015-02-12 21:57:18 +11:00
Sebastian McKenzie
298cfac7f4 fix linting errors 2015-02-12 21:55:31 +11:00
Sebastian McKenzie
476b683f0f upgrade core-js 2015-02-12 21:53:51 +11:00
Sebastian McKenzie
5c5b66df54 add 3.6.0 changelog 2015-02-12 21:53:45 +11:00
Sebastian McKenzie
e7f6572a3b track arrays to avoid turning something into an array multiple times - closes #757 2015-02-12 21:30:48 +11:00
Sebastian McKenzie
e9cfd2df3e fix toConsumableArray helper 2015-02-12 16:53:00 +11:00
Sebastian McKenzie
a425136680 allow loose = true as an alias for loose = "all" 2015-02-12 16:36:17 +11:00
Sebastian McKenzie
8d06a4301c pdate tests to reflect toConsumableArray updates 2015-02-12 16:35:55 +11:00
Sebastian McKenzie
1909a16dc7 copy over files that we can't compile when specifying a directory in bin/6to5 2015-02-12 16:35:41 +11:00
Sebastian McKenzie
3bfa1f610c add bootstrapping base 2015-02-12 16:35:04 +11:00
Sebastian McKenzie
4faf2b7730 fix namespace name 2015-02-12 16:00:54 +11:00
Sebastian McKenzie
4e5d6ee976 rice up toConsumableArray helper 2015-02-12 16:00:43 +11:00
Sebastian McKenzie
afb1ee79a1 fix autoenabling of playground/experimental when used in whitelist/optional 2015-02-12 16:00:26 +11:00
Sebastian McKenzie
efe3f30741 make minification.renameLocalVariables work 2015-02-12 07:46:34 +11:00
Sebastian McKenzie
5ff0285ba7 use space helper instead of pushing a space in IfStatement generation 2015-02-12 07:46:21 +11:00
Sebastian McKenzie
d7bea2f325 remove legacy jshint comment 2015-02-12 07:46:03 +11:00
Sebastian McKenzie
32316ad942 clean up t.is 2015-02-12 07:45:55 +11:00
Sebastian McKenzie
7953eb560e force experimental and playground flag when whitelisting/optionalising transformers 2015-02-12 07:45:50 +11:00
Sebastian McKenzie
faa10df84c add toConsumableArray helper for spread - fixes #757 2015-02-12 07:37:40 +11:00
Sebastian McKenzie
ae344aa23e recurse over and duplicate array in toArray in order to handle sparse arrays - fixes #754 2015-02-12 00:33:04 +11:00
Sebastian McKenzie
e0bfc72700 fix tail call deopt check 2015-02-11 20:16:50 +11:00
Sebastian McKenzie
bf8f80faf7 add general support for declarations to Scope::rename - closes #751 2015-02-11 20:14:41 +11:00
Sebastian McKenzie
77fa8bf01c fix isReferenced on AssignmentPattern 2015-02-11 20:14:21 +11:00
Sebastian McKenzie
34ca1ac04f delay binding reassignment to after reference replacements - #751 2015-02-11 19:48:54 +11:00
Sebastian McKenzie
85d33536e0 add deopt logging to tail call transformer 2015-02-11 15:59:15 +11:00
Sebastian McKenzie
a4932e0e0f add messages to make it easier to make error messages 2015-02-11 15:57:30 +11:00
Sebastian McKenzie
4ebd0a1e8a upgrade regenerator-6to5 2015-02-11 12:12:43 +11:00
Sebastian McKenzie
14e92e9e3f remove kexec from optionalDependencies 2015-02-11 12:00:38 +11:00
Sebastian McKenzie
13687d98ed bump regenerator-6to5 2015-02-11 11:52:16 +11:00
Sebastian McKenzie
db93c52182 opt out of tail recursion optimisation if the owner id has been reassigned - fixes #744 2015-02-11 11:27:50 +11:00
Sebastian McKenzie
56a953df64 add basic support for class property initializers - #619 2015-02-11 10:59:44 +11:00
Sebastian McKenzie
c38edbbb42 Merge branch 'master' of github.com:6to5/6to5 2015-02-11 08:29:08 +11:00
Sebastian McKenzie
017bb6427a Merge pull request #743 from chicoxyzzy/master
optimise lodash usage
2015-02-11 08:28:58 +11:00
Sebastian McKenzie
714ad40cb0 update contributing guide 2015-02-11 08:28:47 +11:00
Ingvar Stepanyan
904a72fb3a Fix rename not establishing binding. 2015-02-10 17:18:46 +02:00
chico
146835e0f1 fix broken code, lint and codestyle fixes 2015-02-10 18:16:54 +03:00
chico
79ba97872c optimise lodash usage; change contains function to includes for convenience 2015-02-10 17:40:53 +03:00
Sebastian McKenzie
897566ccb3 more reliable scope construction 2015-02-11 00:38:59 +11:00
Sebastian McKenzie
4df1b6700b remove acorn node patching 2015-02-11 00:37:59 +11:00
Sebastian McKenzie
50f903caf7 proper optional builder keys 2015-02-11 00:13:27 +11:00
Sebastian McKenzie
7b8118d8bd default newName in scope.rename to a new uid 2015-02-11 00:13:21 +11:00
Sebastian McKenzie
0c1e1e757c default optional builder keys to false 2015-02-11 00:02:51 +11:00
Sebastian McKenzie
62fa583fc1 fix linting errors 2015-02-10 23:55:11 +11:00
Sebastian McKenzie
8598000a69 restructure Scope API and internal data structure 2015-02-10 23:52:23 +11:00
Sebastian McKenzie
edc8bee38e test for falsy nodes in tail call transformer subtransform 2015-02-10 22:39:46 +11:00
Sebastian McKenzie
45b70d7fba fix bad ctrl+f Class -> ClassTransformer replacement 2015-02-10 22:39:21 +11:00
Sebastian McKenzie
49a53b26bb add scope renaming helper method - fixes #645 - @RReverser 2015-02-10 22:39:07 +11:00
Sebastian McKenzie
329b4e9d21 append Transformer to the end of transformer classes 2015-02-10 22:12:36 +11:00
Sebastian McKenzie
f1bca0013e refactor tail call transformer into a class - @RReverser 2015-02-10 22:11:22 +11:00
Sebastian McKenzie
87af83f1cb Merge pull request #742 from douglasduteil/patch-1
chore(travis): run tests on nodejs 0.12 too
2015-02-10 20:30:30 +11:00
Douglas Duteil
5156574bf2 chore(travis): run tests on nodejs 0.12 too 2015-02-10 10:29:05 +01:00
Sebastian McKenzie
ac098255be fix allowPartial in t.buildMatchMemberExpression 2015-02-10 18:34:16 +11:00
Sebastian McKenzie
47b803ef24 remove old tail call transformer 2015-02-10 18:33:51 +11:00
Sebastian McKenzie
7f61c8b65e add descriptor falsy check to defaults helper - #739 2015-02-10 18:33:29 +11:00
Sebastian McKenzie
4fa9aa63a3 Merge branch 'better-tail-recursion' 2015-02-10 18:04:05 +11:00
Sebastian McKenzie
d582c7c93a Merge pull request #739 from lukescott/defaults-fix
fix defaults helper in strict mode - #738
2015-02-10 18:00:26 +11:00
Sebastian McKenzie
6266f5b924 finish minification.removeConsoleCall transformer #740 2015-02-10 17:56:31 +11:00
Luke Scott
c6920a0e60 fix defaults helper in strict mode - #738 2015-02-09 20:38:57 -08:00
Sebastian McKenzie
825d84ba52 fix defaults helper iteration - #738 2015-02-10 13:20:19 +11:00
Sebastian McKenzie
94a0eb5b06 copy over descriptors and handle non-enumerable properties in defaults helper - fixes #738 2015-02-10 13:06:26 +11:00
Sebastian McKenzie
b6d708caf2 add SpreadProperty to t.getBindingIdentifiers - fixes #734 2015-02-10 09:04:27 +11:00
Ingvar Stepanyan
0d542b61d3 Performance improvements for TCO.
http://jsperf.com/tco/17
2015-02-09 19:00:31 +02:00
Ingvar Stepanyan
5a842ab623 Fix statement substitution in templates. 2015-02-09 17:34:59 +02:00
Sebastian McKenzie
26d4b5f2cf normalise opts.sourceRoot path - 6to5/karma-6to5-preprocessor#5 2015-02-09 23:38:54 +11:00
Sebastian McKenzie
ba0dfac53d add uid scope kind 2015-02-09 21:28:51 +11:00
Sebastian McKenzie
8a4296a948 remove binding kind from pushing bindings to the function scope, better block scoped collision logic, and track label ids as references 2015-02-09 21:21:25 +11:00
Sebastian McKenzie
478f9e028f put function params into the param kind 2015-02-09 20:16:38 +11:00
Sebastian McKenzie
c4e56894d9 ignore hoisted kind when checking for block scoped collisions 2015-02-09 20:03:59 +11:00
Sebastian McKenzie
c6f13844ed move FunctionDeclarations into a hoisted kind 2015-02-09 19:53:46 +11:00
Sebastian McKenzie
5e81653680 change function params binding kind to let 2015-02-09 19:45:03 +11:00
Sebastian McKenzie
8e2df3f1f9 add kinds to binding registration and rename declaration scope methods to bindings 2015-02-09 19:42:52 +11:00
Sebastian McKenzie
a2cc384172 move rest parameters transformer above default parameters 2015-02-09 10:59:31 +11:00
Sebastian McKenzie
d37bf292a1 rename declarationKinds to bindingKinds in scope tracker 2015-02-09 10:59:20 +11:00
Sebastian McKenzie
70eb641530 fix element name in default parameters 2015-02-09 08:46:06 +11:00
Sebastian McKenzie
f845a9b2c4 ignore binding elements when finding the last non-default param - fixes #723 2015-02-09 08:25:58 +11:00
Sebastian McKenzie
ee5cb8d9ed clean up tail call transformer 2015-02-08 22:47:50 +11:00
Sebastian McKenzie
9020a21ba2 3.5.3 2015-02-08 22:17:36 +11:00
Sebastian McKenzie
fdda013d07 v3.5.3 2015-02-08 22:17:05 +11:00
Sebastian McKenzie
64477d934d add 3.5.3 changelog 2015-02-08 22:10:00 +11:00
Sebastian McKenzie
45c507056a add back old tail call implementation 2015-02-08 22:09:41 +11:00
Sebastian McKenzie
730b96c195 3.5.2 2015-02-08 21:23:55 +11:00
Sebastian McKenzie
a185f91433 v3.5.2 2015-02-08 21:23:24 +11:00
Sebastian McKenzie
d053622802 add 3.5.2 changelog 2015-02-08 21:21:38 +11:00
Sebastian McKenzie
74d6b61973 disable es6 tail call tests 2015-02-08 21:21:32 +11:00
Sebastian McKenzie
97784c8cca comment out tailCall transformer 2015-02-08 21:19:01 +11:00
Sebastian McKenzie
812d93553a temporairly disable tailCall transformer 2015-02-08 21:17:21 +11:00
Sebastian McKenzie
d251b4cb56 3.5.1 2015-02-08 21:16:34 +11:00
Sebastian McKenzie
caf38e1962 v3.5.1 2015-02-08 21:04:05 +11:00
Sebastian McKenzie
4ccbee4639 fix linting errors 2015-02-08 20:59:48 +11:00
Sebastian McKenzie
84196a3a07 add 3.5.1 changelog 2015-02-08 20:57:58 +11:00
Ingvar Stepanyan
29361c055a Fix #718. 2015-02-08 11:56:39 +02:00
Sebastian McKenzie
4277265591 Merge branch 'master' of github.com:6to5/6to5 2015-02-08 20:40:47 +11:00
Sebastian McKenzie
812a2b315d bump acorn-6to5 2015-02-08 20:40:30 +11:00
Ingvar Stepanyan
0a1724fc3f Remove no more needed returnBlock helper. 2015-02-08 11:31:19 +02:00
Sebastian McKenzie
bcc9e016b1 only evaluate object destructuring pattern once 2015-02-08 20:23:22 +11:00
Sebastian McKenzie
4ea0175ca7 simplify set template 2015-02-08 20:23:22 +11:00
Sebastian McKenzie
799445c745 add property method assignment wrapper generator template 2015-02-08 20:23:22 +11:00
Sebastian McKenzie
481ea12999 add cleanup internal transformer 2015-02-08 20:23:22 +11:00
Sebastian McKenzie
de6b608dda add _declarations and _scopeInfo to t.inherits 2015-02-08 20:23:21 +11:00
Sebastian McKenzie
606f813822 enable traceur test suite by default 2015-02-08 20:23:21 +11:00
Sebastian McKenzie
e06c8cd106 support generators in nameMethod helper 2015-02-08 20:23:21 +11:00
Ingvar Stepanyan
9e3c67a8a2 Clean up functionChildrenVisitor a bit. 2015-02-08 10:53:09 +02:00
Ingvar Stepanyan
91362f80b1 Clean up transformations after #714.
Since now we have runtime helper, we don't need
expression -> statement conversions anymore.
2015-02-08 10:40:03 +02:00
Sebastian McKenzie
cde988f99f update 3.5.0 changelog 2015-02-08 16:53:33 +11:00
Sebastian McKenzie
9ec0854659 3.5.0 2015-02-08 16:37:13 +11:00
Sebastian McKenzie
bb17571e56 v3.5.0 2015-02-08 16:35:45 +11:00
Sebastian McKenzie
9161af58c0 fix linting errors 2015-02-08 16:32:08 +11:00
Sebastian McKenzie
e39f4e8025 update 3.5.0 changelog 2015-02-08 16:31:24 +11:00
Sebastian McKenzie
f5e9909e71 Merge pull request #716 from daliwali/master
Make `__esModule` property not enumerable
2015-02-08 16:30:26 +11:00
Sebastian McKenzie
46913fc55f add 3.5.0 changelog 2015-02-08 16:22:12 +11:00
Dali Zheng
d358a86e98 make __esModule property not enumerable 2015-02-07 21:19:11 -08:00
Sebastian McKenzie
055545980c update traceur test runner 2015-02-08 16:19:05 +11:00
Sebastian McKenzie
6fd7f9868e upgrade acorn-6to5 2015-02-08 16:18:54 +11:00
Sebastian McKenzie
e8184a9bc5 fix browser api location in browser test 2015-02-08 14:34:43 +11:00
Sebastian McKenzie
f74de3ef55 move destructuring and parameters.rest transformer to above blockScoping 2015-02-08 14:34:34 +11:00
Sebastian McKenzie
9624f8287d add checkNode to block scoped functions transformer 2015-02-08 14:34:10 +11:00
Sebastian McKenzie
e42d5a889e make destructuring in catch clauses block scoped and add support for non-variable destructuring in for-in/of heads 2015-02-08 14:33:55 +11:00
Sebastian McKenzie
4c8e6481b6 make default parameters iife invocation less serious 2015-02-08 09:54:24 +11:00
Sebastian McKenzie
0867df2691 fix ForOf block body not properly inheriting declarations 2015-02-08 09:50:12 +11:00
Sebastian McKenzie
b06f99ab30 add iife detection to non-identifier params in default parameters 2015-02-08 09:37:06 +11:00
Sebastian McKenzie
9afa3f6b58 add opts param to t.isReferencedIdentifier 2015-02-08 09:31:41 +11:00
Sebastian McKenzie
785cb4b72f allow optional transformer to be set via the whitelist 2015-02-08 09:31:30 +11:00
Sebastian McKenzie
dabe69856a add additional checks to transformers 2015-02-08 09:31:19 +11:00
Sebastian McKenzie
24e70802b5 fix block scoped tracking in functions - fixes #710 2015-02-08 09:31:04 +11:00
Sebastian McKenzie
c1ba55a52d Merge pull request #714 from RReverser/master
Added complete TCO (tail call optimization).
2015-02-08 08:55:19 +11:00
Ingvar Stepanyan
4c318166e1 Added complete TCO (tail call optimization).
Works across functions and generates simpler and faster code than #701.
Works even across files when used in conjunction with `runtime` option.

Closes #256.
2015-02-07 22:22:38 +02:00
Sebastian McKenzie
c0af67eca1 add support for super in object literals - fixes #411 2015-02-08 02:01:17 +11:00
Sebastian McKenzie
eb14f1da00 implement optional TDZ - fixes #563 2015-02-08 01:27:22 +11:00
Sebastian McKenzie
3361b81658 expose parentPath 2015-02-08 01:27:00 +11:00
Sebastian McKenzie
a15f218e9b dump code to esvalid errors 2015-02-08 01:26:46 +11:00
Sebastian McKenzie
067cf43f52 fix File::addHelper unknown helper error message 2015-02-08 00:01:26 +11:00
Sebastian McKenzie
689ce048e6 remove tail call exec test 2015-02-07 23:52:41 +11:00
Sebastian McKenzie
8a143bf957 use a template in tail call transformer - @RReverser 2015-02-07 23:52:35 +11:00
Sebastian McKenzie
9f7bcf585d remove dead TraversalContext code 2015-02-07 23:51:05 +11:00
Sebastian McKenzie
f9efd8a272 fix error message in File::addHelper 2015-02-07 23:50:56 +11:00
Sebastian McKenzie
8cd2326ff9 Merge branch 'master' of github.com:6to5/6to5 2015-02-07 23:37:51 +11:00
Sebastian McKenzie
eb1ae70bfa Merge pull request #701 from RReverser/master
Add tail recursion optimization.
2015-02-07 23:37:43 +11:00
Ingvar Stepanyan
24ef81908c Increase test timeout for Travis. 2015-02-07 14:34:23 +02:00
Ingvar Stepanyan
b53b41cef3 Provide placeholders for proper function length. 2015-02-07 14:26:03 +02:00
Sebastian McKenzie
ad245ed46a 3.4.1 2015-02-07 19:48:59 +11:00
Sebastian McKenzie
3f6199493e v3.4.1 2015-02-07 19:48:28 +11:00
Sebastian McKenzie
e06aac4783 Revert "make export { foo as default }; trigger common interop"
This reverts commit 07c7b5b419.
2015-02-07 19:40:49 +11:00
Sebastian McKenzie
6a5adfe338 update 3.4.1 changelog 2015-02-07 19:40:29 +11:00
Sebastian McKenzie
07c7b5b419 make export { foo as default }; trigger common interop 2015-02-07 19:29:59 +11:00
Sebastian McKenzie
7f985fe08a fix incorrect strict module formatter variable - fixes #706 2015-02-07 19:29:32 +11:00
Sebastian McKenzie
38f02a6429 add 3.4.1 changelog 2015-02-07 19:19:55 +11:00
Sebastian McKenzie
f943bdcac0 Merge branch 'master' of github.com:6to5/6to5 2015-02-07 19:18:29 +11:00
Sebastian McKenzie
8dc634edfc add options to require cache key - fixes #707 2015-02-07 19:18:12 +11:00
Sebastian McKenzie
05b9cf17f0 Merge pull request #708 from tricknotes/avoid-conflict
Switch short option of `--module-ids` from `-i` to `-M`
2015-02-07 19:12:22 +11:00
Ryunosuke SATO
69bbe89616 Switch short option of --module-ids from -i to -M
`-i` conflicts with `--optional` option.

```
$ bin/6to5/index.js --help | grep "\-i,"
    -i, --optional [list]        List of optional transformers to enable
    -i, --module-ids             Insert module id in modules
```
2015-02-07 16:37:38 +09:00
Sebastian McKenzie
6b49958f7c Merge branch 'master' of github.com:6to5/6to5 2015-02-07 15:59:15 +11:00
Sebastian McKenzie
e75ce94578 move reactCompat option onto an optional transformer 2015-02-07 15:59:00 +11:00
Sebastian McKenzie
f666473724 Merge pull request #705 from cesarandreu/patch-2
Add 6to5-runtime README
2015-02-07 13:54:58 +11:00
Cesar Andreu
ae817e3c9c Add 6to5-runtime README 2015-02-06 18:53:42 -08:00
Sebastian McKenzie
2e9352de14 3.4.0 2015-02-07 10:44:06 +11:00
Sebastian McKenzie
1e9e55ddef fix browser build location in makefile 2015-02-07 10:42:28 +11:00
Sebastian McKenzie
0799ed7116 v3.4.0 2015-02-07 10:41:38 +11:00
Sebastian McKenzie
5537250d4f fix linting errors 2015-02-07 10:40:01 +11:00
Sebastian McKenzie
7ada50937b add 3.4.0 changelog 2015-02-07 10:39:24 +11:00
Sebastian McKenzie
f2ae88af93 add commonStandard module formatter - fixes #675
will be merged into strict formatters in next major
TODO: rewrite all module formatters as they've gotten out of han
2015-02-07 10:31:52 +11:00
Sebastian McKenzie
726451f86f reverts d6b39bc89b 2015-02-07 09:54:18 +11:00
Sebastian McKenzie
306cfc6328 fix 3.3.12 changelog misspelling 2015-02-07 09:53:18 +11:00
Sebastian McKenzie
a051a47048 reorder types requires 2015-02-07 08:11:42 +11:00
Ingvar Stepanyan
5b2216b348 Add tail recursion optimization.
As per ES6, VMs should perform tail call optimization and prevent growth of call stack.
This adds tail call optimization for recursion case (when function has explicit name and calls itself in `return`).
Cross-function optimization is not currently performed as it's more complicated and requires value tracking.
2015-02-06 16:34:35 +02:00
Sebastian McKenzie
ad60d49611 fix bindingEquals in constants transformer 2015-02-06 23:35:19 +11:00
Sebastian McKenzie
a6d1a5a724 add bindingEquals, typeEquals, referenceEquals helper methods to Scope 2015-02-06 23:07:10 +11:00
Sebastian McKenzie
399d835285 fix linting errors 2015-02-06 23:06:54 +11:00
Sebastian McKenzie
b66367ddde change namespace of minification.propertyLiterals and minifciation.memberExpressionLiterals to es3 2015-02-06 22:42:16 +11:00
Sebastian McKenzie
37d29b7a6f clean up function scope collection - @RReverser 2015-02-06 22:04:13 +11:00
Sebastian McKenzie
1e708fb373 fix traverse test 2015-02-06 01:59:45 +11:00
Sebastian McKenzie
76ae1682a3 remove context arg in favor of this, rename TraversalIteration to TraversalPath, and remove ast handlers 2015-02-06 01:47:43 +11:00
Sebastian McKenzie
2ef0aa95c5 clean up indentation 2015-02-06 01:17:42 +11:00
Sebastian McKenzie
9cbb49c6b2 don't return the sourcemap when inline is requested - 6to5/grunt-6to5#18 2015-02-05 22:25:33 +11:00
Sebastian McKenzie
f04a734838 fix module ids shorthand arg - fixes #696 2015-02-05 22:19:39 +11:00
Sebastian McKenzie
beb5ccab25 split up traversal so it's easier to maintain and extend later on 2015-02-05 19:42:08 +11:00
Sebastian McKenzie
b8f8f24e82 add newline to es6 destructuring member expression test 2015-02-05 19:41:53 +11:00
Sebastian McKenzie
c35a007401 simplify replace supers helper 2015-02-05 19:41:37 +11:00
Sebastian McKenzie
e639c82f2f fix internal refactoring... 2015-02-05 14:08:02 +11:00
Sebastian McKenzie
f365cc1248 more internal rearchitecturing 2015-02-05 14:05:15 +11:00
Sebastian McKenzie
2b75c67448 better scope traversal inferType todo comments 2015-02-05 11:16:13 +11:00
Sebastian McKenzie
e5e9ae7e0f v3.3.12 2015-02-05 10:32:14 +11:00
Sebastian McKenzie
009422e997 add 3.3.12 changelog 2015-02-05 10:15:15 +11:00
Sebastian McKenzie
386e221a0f don't override core supported member expressions if there's a local binding 2015-02-05 09:53:12 +11:00
Sebastian McKenzie
58db94401e 3.3.11 2015-02-05 08:53:29 +11:00
628 changed files with 7131 additions and 4516 deletions

5
.babelrc Normal file
View File

@@ -0,0 +1,5 @@
{
"experimental": true,
"playground": true,
"loose": true
}

View File

@@ -5,7 +5,8 @@ insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
[*.js]
[*.{js,json}]
indent_style = space
indent_size = 2

4
.gitignore vendored
View File

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

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

View File

@@ -1,5 +1,5 @@
{
"excludeFiles": ["lib/6to5/transformation/templates"],
"excludeFiles": ["lib/babel/transformation/templates"],
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},

View File

@@ -1 +1 @@
lib/6to5/transformation/templates
lib/babel/transformation/templates

View File

@@ -2,6 +2,7 @@
"esnext": true,
"indent": 2,
"freeze": true,
"validthis": true,
"camelcase": true,
"unused": true,
"eqnull": true,

View File

@@ -1,7 +1,7 @@
node_modules
*.log
*.cache
lib/6to5/transformation/templates
lib/babel/transformation/templates
test
benchmark
Makefile

View File

@@ -2,7 +2,8 @@ sudo: false
language: node_js
node_js:
- "0.10"
- "0.11"
- "0.12"
- "iojs"
branches:
except:

1093
CHANGELOG-6to5.md Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,25 @@
# Contributing
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).
Contributions are always welcome, no matter how large or small. Before
contributing, please read the
[code of conduct](https://github.com/babel/babel/blob/master/CODE_OF_CONDUCT.md).
**NOTE:** Please do not send pull requests that fix linting issues. It's highly
likely that they've already been fixed by the time it's submitted and it just
pollutes the git tree.
## Developing
#### 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
* Ensure the test are passing (`make test`)
* Create new pull request explaining your proposed change or reference an issue in your commit message
* Create new pull request explaining your proposed change or reference an issue
in your commit message
#### Code Standards

View File

@@ -1,4 +1,4 @@
Copyright (c) 2014-2015 Sebastian McKenzie
Copyright (c) 2014-2015 Sebastian McKenzie <sebmck@gmail.com>
MIT License

View File

@@ -5,24 +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
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
.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 $(BABEL_CMD) src --out-dir lib
watch-core:
#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/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
@@ -42,20 +49,19 @@ 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: bootstrap
test-travis: build-core bootstrap
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
@@ -64,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
@@ -78,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
@@ -92,12 +98,12 @@ publish:
make publish-core
make publish-runtime
rm -rf templates.json browser.js browser-polyfill.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:

View File

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

View File

@@ -1,12 +1,18 @@
<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
support visit the <a href="https://gitter.im/babel/babel">gitter room</a>.
</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>

View File

@@ -1,17 +0,0 @@
environment:
matrix:
- nodejs_version: "0.10"
- nodejs_version: "0.11"
install:
- "npm install"
- "cinst make"
test_script:
- "node --version"
- "npm --version"
- "make test-spec"
build: "off"
version: "{build}"

View File

@@ -1,7 +0,0 @@
#!/usr/bin/env node
var opts = require("./6to5").opts;
opts.optional = (opts.optional || []).concat("minification");
opts.format = {
compact: true
};

View File

@@ -1,4 +0,0 @@
#!/usr/bin/env node
var runtime = require("../lib/6to5/build-runtime");
console.log(runtime());

View File

@@ -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");
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,
@@ -60,7 +61,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 +86,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
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env node
var runtime = require("../lib/babel/build-external-helpers");
console.log(runtime());

View File

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

View File

@@ -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";
@@ -37,8 +39,13 @@ module.exports = function (commander, filenames, opts) {
if (stat.isDirectory(filename)) {
var dirname = filename;
_.each(util.readdirFilter(dirname), function (filename) {
write(path.join(dirname, filename), filename);
_.each(util.readdir(dirname), function (filename) {
var src = path.join(dirname, filename);
if (util.canCompile(filename)) {
write(src, filename);
} else {
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
}
});
} else {
write(filename, filename);

View File

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

View File

@@ -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);
@@ -23,9 +24,10 @@ commander.option("-L, --loose [list]", "List of transformers to enable loose mod
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
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("--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);

View File

@@ -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");
var fs = require("fs");
var _ = require("lodash");
@@ -12,17 +12,21 @@ exports.readdirFilter = function (filename) {
});
};
exports.readdir = readdir;
exports.canCompile = util.canCompile;
exports.addSourceMappingUrl = function (code, loc) {
return code + "\n//# sourceMappingURL=" + path.basename(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
View 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
View 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
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env node
console.error("`6to5-runtime` has been renamed to `babel-external-helpers`");
require("../babel-external-helpers");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +0,0 @@
"use strict";
// required to safely use 6to5/register within a browserify codebase
module.exports = function () {};
require("./polyfill");

View File

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

View File

@@ -1 +0,0 @@
var VARIABLE_NAME = ARGUMENTS[ARGUMENT_KEY] === undefined ? DEFAULT_VALUE : ARGUMENTS[ARGUMENT_KEY];

View File

@@ -1,8 +0,0 @@
(function (obj, defaults) {
for (var key in defaults) {
if (obj[key] === undefined) {
obj[key] = defaults[key];
}
}
return obj;
})

View File

@@ -1,94 +0,0 @@
module.exports = TransformerPass;
var util = require("../util");
var contains = require("lodash/collection/contains");
/**
* This class is responsible for traversing over the provided `File`s
* AST and running it's parent transformers handlers over it.
*/
function TransformerPass(file, transformer) {
this.transformer = transformer;
this.shouldRun = !transformer.check;
this.handlers = transformer.handlers;
this.file = file;
}
TransformerPass.prototype.astRun = function (key) {
if (!this.shouldRun) return;
var handlers = this.handlers;
var file = this.file;
if (handlers.ast && handlers.ast[key]) {
handlers.ast[key](file.ast, file);
}
};
TransformerPass.prototype.canRun = function () {
var transformer = this.transformer;
var opts = this.file.opts;
var key = transformer.key;
// internal
if (key[0] === "_") return true;
// blacklist
var blacklist = opts.blacklist;
if (blacklist.length && contains(blacklist, key)) return false;
// whitelist
var whitelist = opts.whitelist;
if (whitelist.length && !contains(whitelist, key)) return false;
// optional
if (transformer.optional && !contains(opts.optional, key)) return false;
// experimental
if (transformer.experimental && !opts.experimental) return false;
// playground
if (transformer.playground && !opts.playground) return false;
return true;
};
TransformerPass.prototype.checkNode = function (node) {
var check = this.transformer.check;
if (check) {
return this.shouldRun = check(node);
} else {
return true;
}
};
var transformVisitor = {
enter: function (node, parent, scope, context, state) {
var fns = state.handlers[node.type];
if (!fns) return;
return fns.enter(node, parent, scope, context, state.file, state.pass);
},
exit: function (node, parent, scope, context, state) {
var fns = state.handlers[node.type];
if (!fns) return;
return fns.exit(node, parent, scope, context, state.file, state.pass);
}
};
TransformerPass.prototype.transform = function () {
if (!this.shouldRun) return;
var file = this.file;
util.debug(file.opts.filename + ": Running transformer " + this.transformer.key);
this.astRun("before");
var state = { file: file, handlers: this.handlers, pass: this };
file.scope.traverse(file.ast, transformVisitor, state);
this.astRun("after");
};

View File

@@ -1,39 +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": "minification.propertyLiterals",
"specMemberExpressionLiterals": "minification.memberExpressionLiterals"
}

View File

@@ -1,49 +0,0 @@
"use strict";
var t = require("../../../types");
var visitor = {
enter: function (node, parent, scope, context, state) {
if (!t.isReferencedIdentifier(node, parent)) return;
var declared = state.letRefs[node.name];
if (!declared) return;
// declared node is different in this scope
if (scope.getBinding(node.name) !== declared) return;
var declaredLoc = declared.loc;
var referenceLoc = node.loc;
if (!declaredLoc || !referenceLoc) return;
// does this reference appear on a line before the declaration?
var before = referenceLoc.start.line < declaredLoc.start.line;
if (referenceLoc.start.line === declaredLoc.start.line) {
// this reference appears on the same line
// check it appears before the declaration
before = referenceLoc.start.col < declaredLoc.start.col;
}
if (before) {
throw state.file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
}
}
};
exports.optional = true;
exports.Loop =
exports.Program =
exports.BlockStatement = function (node, parent, scope, context, file) {
var letRefs = node._letReferences;
if (!letRefs) return;
var state = {
letRefs: letRefs,
file: file
};
scope.traverse(node, visitor, state);
};

View File

@@ -1,47 +0,0 @@
"use strict";
var t = require("../../../types");
exports.check = function (node) {
return t.isVariableDeclaration(node, { kind: "const" });
};
var visitor = {
enter: function (node, parent, scope, context, state) {
if (t.isAssignmentExpression(node) || t.isUpdateExpression(node)) {
var ids = t.getBindingIdentifiers(node);
for (var key in ids) {
var id = ids[key];
var constant = state.constants[key];
// no constant exists
if (!constant) continue;
// check if the assignment id matches the constant declaration id
// if it does then it was the id used to initially declare the
// constant so we can just ignore it
if (id === constant) continue;
var localBinding = scope.getBinding(key);
if (localBinding !== constant) continue;
throw state.file.errorWithNode(id, key + " is read-only");
}
} else if (t.isScope(node)) {
context.skip();
}
}
};
exports.Scope = function (node, parent, scope, context, file) {
scope.traverse(node, visitor, {
constants: scope.getAllDeclarationsOfKind("const"),
file: file
});
};
exports.VariableDeclaration = function (node) {
if (node.kind === "const") node.kind = "let";
};

View File

@@ -1,373 +0,0 @@
"use strict";
var t = require("../../../types");
exports.check = t.isPattern;
function Destructuring(opts) {
this.blockHoist = opts.blockHoist;
this.operator = opts.operator;
this.nodes = opts.nodes;
this.scope = opts.scope;
this.file = opts.file;
this.kind = opts.kind;
}
Destructuring.prototype.buildVariableAssignment = function (id, init) {
var op = this.operator;
if (t.isMemberExpression(id)) op = "=";
var node;
if (op) {
node = t.expressionStatement(t.assignmentExpression(op, id, init));
} else {
node = t.variableDeclaration(this.kind, [
t.variableDeclarator(id, init)
]);
}
node._blockHoist = this.blockHoist;
return node;
};
Destructuring.prototype.buildVariableDeclaration = function (id, init) {
var declar = t.variableDeclaration("var", [
t.variableDeclarator(id, init)
]);
declar._blockHoist = this.blockHoist;
return declar;
};
Destructuring.prototype.push = function (elem, parentId) {
if (t.isObjectPattern(elem)) {
this.pushObjectPattern(elem, parentId);
} else if (t.isArrayPattern(elem)) {
this.pushArrayPattern(elem, parentId);
} else if (t.isAssignmentPattern(elem)) {
this.pushAssignmentPattern(elem, parentId);
} else {
this.nodes.push(this.buildVariableAssignment(elem, parentId));
}
};
Destructuring.prototype.pushAssignmentPattern = function (pattern, parentId) {
var tempParentId = this.scope.generateUidBasedOnNode(parentId);
var declar = t.variableDeclaration("var", [
t.variableDeclarator(tempParentId, parentId)
]);
declar._blockHoist = this.blockHoist;
this.nodes.push(declar);
this.nodes.push(this.buildVariableAssignment(
pattern.left,
t.conditionalExpression(
t.binaryExpression("===", tempParentId, t.identifier("undefined")),
pattern.right,
tempParentId
)
));
};
Destructuring.prototype.pushObjectSpread = function (pattern, parentId, prop, i) {
// get all the keys that appear in this object before the current spread
var keys = [];
for (var i2 = 0; i2 < pattern.properties.length; i2++) {
var prop2 = pattern.properties[i2];
if (i2 >= i) break;
if (t.isSpreadProperty(prop2)) continue;
var key = prop2.key;
if (t.isIdentifier(key)) {
key = t.literal(prop2.key.name);
}
keys.push(key);
}
keys = t.arrayExpression(keys);
var value = t.callExpression(this.file.addHelper("object-without-properties"), [parentId, keys]);
this.nodes.push(this.buildVariableAssignment(prop.argument, value));
};
Destructuring.prototype.pushObjectProperty = function (prop, parentId) {
if (t.isLiteral(prop.key)) prop.computed = true;
var pattern2 = prop.value;
var patternId2 = t.memberExpression(parentId, prop.key, prop.computed);
if (t.isPattern(pattern2)) {
this.push(pattern2, patternId2);
} else {
this.nodes.push(this.buildVariableAssignment(pattern2, patternId2));
}
};
Destructuring.prototype.pushObjectPattern = function (pattern, parentId) {
if (!pattern.properties.length) {
this.nodes.push(t.expressionStatement(
t.callExpression(this.file.addHelper("object-destructuring-empty"), [parentId])
));
}
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
if (t.isSpreadProperty(prop)) {
this.pushObjectSpread(pattern, parentId, prop, i);
} else {
this.pushObjectProperty(prop, parentId);
}
}
};
var hasRest = function (pattern) {
for (var i = 0; i < pattern.elements.length; i++) {
if (t.isRestElement(pattern.elements[i])) {
return true;
}
}
return false;
};
Destructuring.prototype.pushArrayPattern = function (pattern, parentId) {
if (!pattern.elements) return;
// if we have a rest then we need all the elements
var count = !hasRest(pattern) && pattern.elements.length;
var toArray = this.file.toArray(parentId, count);
var _parentId = this.scope.generateUidBasedOnNode(parentId, this.file);
this.nodes.push(this.buildVariableDeclaration(_parentId, toArray));
parentId = _parentId;
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
// hole
if (!elem) continue;
var newPatternId;
if (t.isRestElement(elem)) {
newPatternId = this.file.toArray(parentId);
if (i > 0) {
newPatternId = t.callExpression(t.memberExpression(newPatternId, t.identifier("slice")), [t.literal(i)]);
}
elem = elem.argument;
} else {
newPatternId = t.memberExpression(parentId, t.literal(i), true);
}
this.push(elem, newPatternId);
}
};
Destructuring.prototype.init = function (pattern, parentId) {
if (!t.isArrayExpression(parentId) && !t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
var key = this.scope.generateUidBasedOnNode(parentId);
this.nodes.push(this.buildVariableDeclaration(key, parentId));
parentId = key;
}
this.push(pattern, parentId);
};
exports.ForInStatement =
exports.ForOfStatement = function (node, parent, scope, context, file) {
var declar = node.left;
if (!t.isVariableDeclaration(declar)) return;
var pattern = declar.declarations[0].id;
if (!t.isPattern(pattern)) return;
var key = scope.generateUidIdentifier("ref");
node.left = t.variableDeclaration(declar.kind, [
t.variableDeclarator(key, null)
]);
var nodes = [];
var destructuring = new Destructuring({
kind: declar.kind,
file: file,
scope: scope,
nodes: nodes
});
destructuring.init(pattern, key);
t.ensureBlock(node);
var block = node.body;
block.body = nodes.concat(block.body);
};
exports.Function = function (node, parent, scope, context, file) {
var nodes = [];
var hasDestructuring = false;
node.params = node.params.map(function (pattern, i) {
if (!t.isPattern(pattern)) return pattern;
hasDestructuring = true;
var parentId = scope.generateUidIdentifier("ref");
var destructuring = new Destructuring({
blockHoist: node.params.length - i,
nodes: nodes,
scope: scope,
file: file,
kind: "var",
});
destructuring.init(pattern, parentId);
return parentId;
});
if (!hasDestructuring) return;
t.ensureBlock(node);
var block = node.body;
block.body = nodes.concat(block.body);
};
exports.CatchClause = function (node, parent, scope, context, file) {
var pattern = node.param;
if (!t.isPattern(pattern)) return;
var ref = scope.generateUidIdentifier("ref");
node.param = ref;
var nodes = [];
var destructuring = new Destructuring({
kind: "var",
file: file,
scope: scope,
nodes: nodes
});
destructuring.init(pattern, ref);
node.body.body = nodes.concat(node.body.body);
};
exports.ExpressionStatement = function (node, parent, scope, context, file) {
var expr = node.expression;
if (expr.type !== "AssignmentExpression") return;
if (!t.isPattern(expr.left)) return;
if (file.isConsequenceExpressionStatement(node)) return;
var nodes = [];
var ref = scope.generateUidIdentifier("ref");
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(ref, expr.right)
]));
var destructuring = new Destructuring({
operator: expr.operator,
file: file,
scope: scope,
nodes: nodes
});
destructuring.init(expr.left, ref);
return nodes;
};
exports.AssignmentExpression = function (node, parent, scope, context, file) {
if (!t.isPattern(node.left)) return;
var ref = scope.generateUidIdentifier("temp");
scope.push({
key: ref.name,
id: ref
});
var nodes = [];
nodes.push(t.assignmentExpression("=", ref, node.right));
var destructuring = new Destructuring({
operator: node.operator,
file: file,
scope: scope,
nodes: nodes
});
destructuring.init(node.left, ref);
nodes.push(ref);
return t.toSequenceExpression(nodes, scope);
};
var variableDeclarationhasPattern = function (node) {
for (var i = 0; i < node.declarations.length; i++) {
if (t.isPattern(node.declarations[i].id)) {
return true;
}
}
return false;
};
exports.VariableDeclaration = function (node, parent, scope, context, file) {
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
if (!variableDeclarationhasPattern(node)) return;
var nodes = [];
var declar;
for (var i = 0; i < node.declarations.length; i++) {
declar = node.declarations[i];
var patternId = declar.init;
var pattern = declar.id;
var destructuring = new Destructuring({
nodes: nodes,
scope: scope,
kind: node.kind,
file: file
});
if (t.isPattern(pattern) && patternId) {
destructuring.init(pattern, patternId);
if (+i !== node.declarations.length - 1) {
// we aren't the last declarator so let's just make the
// last transformed node inherit from us
t.inherits(nodes[nodes.length - 1], declar);
}
} else {
nodes.push(t.inherits(destructuring.buildVariableAssignment(declar.id, declar.init), declar));
}
}
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) {
// https://github.com/6to5/6to5/issues/113
// for (let [x] = [0]; false;) {}
declar = null;
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
declar = declar || t.variableDeclaration(node.kind, []);
if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) {
throw file.errorWithNode(node, "Cannot use this node within the current parent");
}
declar.declarations = declar.declarations.concat(node.declarations);
}
return declar;
}
return nodes;
};

View File

@@ -1,103 +0,0 @@
"use strict";
var util = require("../../../util");
var t = require("../../../types");
exports.check = t.isForOfStatement;
exports.ForOfStatement = function (node, parent, scope, context, file) {
var callback = spec;
if (file.isLoose("es6.forOf")) callback = loose;
var build = callback(node, parent, scope, context, file);
var declar = build.declar;
var loop = build.loop;
var block = loop.body;
// inherit comments from the original loop
t.inheritsComments(loop, node);
// ensure that it's a block so we can take all it's statemetns
t.ensureBlock(node);
// add the value declaration to the new loop body
if (declar) {
block.body.push(declar);
}
// push the rest of the original loop body onto our new body
block.body = block.body.concat(node.body.body);
// todo: find out why this is necessary? #538
loop._scopeInfo = node._scopeInfo;
return loop;
};
var loose = function (node, parent, scope, context, file) {
var left = node.left;
var declar, id;
if (t.isIdentifier(left) || t.isPattern(left)) {
// for (i of test), for ({ i } of test)
id = left;
} else if (t.isVariableDeclaration(left)) {
// for (var i of test)
id = scope.generateUidIdentifier("ref");
declar = t.variableDeclaration(left.kind, [
t.variableDeclarator(left.declarations[0].id, id)
]);
} else {
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
}
var loop = util.template("for-of-loose", {
LOOP_OBJECT: scope.generateUidIdentifier("iterator"),
IS_ARRAY: scope.generateUidIdentifier("isArray"),
OBJECT: node.right,
INDEX: scope.generateUidIdentifier("i"),
ID: id
});
if (!declar) {
// no declaration so we need to remove the variable declaration at the top of
// the for-of-loose template
loop.body.body.shift();
}
return {
declar: declar,
loop: loop
};
};
var spec = function (node, parent, scope, context, file) {
var left = node.left;
var declar;
var stepKey = scope.generateUidIdentifier("step");
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
if (t.isIdentifier(left) || t.isPattern(left)) {
// for (i of test), for ({ i } of test)
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
} else if (t.isVariableDeclaration(left)) {
// for (var i of test)
declar = t.variableDeclaration(left.kind, [
t.variableDeclarator(left.declarations[0].id, stepValue)
]);
} else {
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
}
var loop = util.template("for-of", {
ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
STEP_KEY: stepKey,
OBJECT: node.right
});
return {
declar: declar,
loop: loop
};
};

View File

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

View File

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

View File

@@ -1,17 +0,0 @@
"use strict";
var useStrict = require("../../helpers/use-strict");
exports.ast = {
exit: function (ast, file) {
if (!file.transformers["es6.modules"].canRun()) return;
useStrict.wrap(ast.program, function () {
ast.program.body = file.dynamicImports.concat(ast.program.body);
});
if (file.moduleFormatter.transform) {
file.moduleFormatter.transform(ast);
}
}
};

View File

@@ -1,10 +0,0 @@
//var t = require("../../../types");
exports.optional = true;
exports.Scope = function () {
// todo: get all binding identifiers, generate compact names
// that wont collide and then call the remap identifier helper
// this transformer **has** to be ran last as it will absolutley
// destroy the scope tree
};

View File

@@ -1,291 +0,0 @@
"use strict";
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser)
// https://github.com/RReverser/jsx-transpiler
// jsx
var isString = require("lodash/lang/isString");
var esutils = require("esutils");
var react = require("../../helpers/react");
var t = require("../../../types");
exports.check = function (node) {
if (t.isJSX(node)) return true;
if (react.isCreateClass(node)) return true;
return false;
};
exports.JSXIdentifier = function (node, parent) {
if (node.name === "this" && t.isReferenced(node, parent)) {
return t.thisExpression();
} else if (esutils.keyword.isIdentifierName(node.name)) {
node.type = "Identifier";
} else {
return t.literal(node.name);
}
};
exports.JSXNamespacedName = function (node, parent, scope, context, file) {
throw file.errorWithNode(node, "Namespace tags are not supported. ReactJSX is not XML.");
};
exports.JSXMemberExpression = {
exit: function (node) {
node.computed = t.isLiteral(node.property);
node.type = "MemberExpression";
}
};
exports.JSXExpressionContainer = function (node) {
return node.expression;
};
exports.JSXAttribute = {
exit: function (node) {
var value = node.value || t.literal(true);
return t.inherits(t.property("init", node.name, value), node);
}
};
var isCompatTag = function (tagName) {
return /^[a-z]|\-/.test(tagName);
};
exports.JSXOpeningElement = {
exit: function (node, parent, scope, context, file) {
var reactCompat = file.opts.reactCompat;
var tagExpr = node.name;
var args = [];
var tagName;
if (t.isIdentifier(tagExpr)) {
tagName = tagExpr.name;
} else if (t.isLiteral(tagExpr)) {
tagName = tagExpr.value;
}
if (!reactCompat) {
if (tagName && isCompatTag(tagName)) {
args.push(t.literal(tagName));
} else {
args.push(tagExpr);
}
}
var attribs = node.attributes;
if (attribs.length) {
attribs = buildJSXOpeningElementAttributes(attribs, file);
} else {
attribs = t.literal(null);
}
args.push(attribs);
if (reactCompat) {
if (tagName && isCompatTag(tagName)) {
return t.callExpression(
t.memberExpression(
t.memberExpression(t.identifier("React"), t.identifier("DOM")),
tagExpr,
t.isLiteral(tagExpr)
),
args
);
}
} else {
tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
}
return t.callExpression(tagExpr, args);
}
};
/**
* The logic for this is quite terse. It's because we need to
* support spread elements. We loop over all attributes,
* breaking on spreads, we then push a new object containg
* all prior attributes to an array for later processing.
*/
var buildJSXOpeningElementAttributes = function (attribs, file) {
var _props = [];
var objs = [];
var pushProps = function () {
if (!_props.length) return;
objs.push(t.objectExpression(_props));
_props = [];
};
while (attribs.length) {
var prop = attribs.shift();
if (t.isJSXSpreadAttribute(prop)) {
pushProps();
objs.push(prop.argument);
} else {
_props.push(prop);
}
}
pushProps();
if (objs.length === 1) {
// only one object
attribs = objs[0];
} else {
// looks like we have multiple objects
if (!t.isObjectExpression(objs[0])) {
objs.unshift(t.objectExpression([]));
}
// spread it
attribs = t.callExpression(
file.addHelper("extends"),
objs
);
}
return attribs;
};
exports.JSXElement = {
exit: function (node) {
var callExpr = node.openingElement;
for (var i = 0; i < node.children.length; i++) {
var child = node.children[i];
if (t.isLiteral(child) && typeof child.value === "string") {
cleanJSXElementLiteralChild(child, callExpr.arguments);
continue;
} else if (t.isJSXEmptyExpression(child)) {
continue;
}
callExpr.arguments.push(child);
}
callExpr.arguments = flatten(callExpr.arguments);
if (callExpr.arguments.length >= 3) {
callExpr._prettyCall = true;
}
return t.inherits(callExpr, node);
}
};
var isStringLiteral = function (node) {
return t.isLiteral(node) && isString(node.value);
};
var flatten = function (args) {
var flattened = [];
var last;
for (var i = 0; i < args.length; i++) {
var arg = args[i];
if (isStringLiteral(arg) && isStringLiteral(last)) {
last.value += arg.value;
} else {
last = arg;
flattened.push(arg);
}
}
return flattened;
};
var cleanJSXElementLiteralChild = function (child, args) {
var lines = child.value.split(/\r\n|\n|\r/);
var lastNonEmptyLine = 0;
var i;
for (i = 0; i < lines.length; i++) {
if (lines[i].match(/[^ \t]/)) {
lastNonEmptyLine = i;
}
}
for (i = 0; i < lines.length; i++) {
var line = lines[i];
var isFirstLine = i === 0;
var isLastLine = i === lines.length - 1;
var isLastNonEmptyLine = i === lastNonEmptyLine;
// replace rendered whitespace tabs with spaces
var trimmedLine = line.replace(/\t/g, " ");
// trim whitespace touching a newline
if (!isFirstLine) {
trimmedLine = trimmedLine.replace(/^[ ]+/, "");
}
// trim whitespace touching an endline
if (!isLastLine) {
trimmedLine = trimmedLine.replace(/[ ]+$/, "");
}
if (trimmedLine) {
if (!isLastNonEmptyLine) {
trimmedLine += " ";
}
args.push(t.literal(trimmedLine));
}
}
};
// display names
var addDisplayName = function (id, call) {
var props = call.arguments[0].properties;
var safe = true;
for (var i = 0; i < props.length; i++) {
var prop = props[i];
if (t.isIdentifier(prop.key, { name: "displayName" })) {
safe = false;
break;
}
}
if (safe) {
props.unshift(t.property("init", t.identifier("displayName"), t.literal(id)));
}
};
exports.ExportDeclaration = function (node, parent, scope, context, file) {
if (node.default && react.isCreateClass(node.declaration)) {
addDisplayName(file.opts.basename, node.declaration);
}
};
exports.AssignmentExpression =
exports.Property =
exports.VariableDeclarator = function (node) {
var left, right;
if (t.isAssignmentExpression(node)) {
left = node.left;
right = node.right;
} else if (t.isProperty(node)) {
left = node.key;
right = node.value;
} else if (t.isVariableDeclarator(node)) {
left = node.id;
right = node.init;
}
if (t.isMemberExpression(left)) {
left = left.property;
}
if (t.isIdentifier(left) && react.isCreateClass(right)) {
addDisplayName(left.name, right);
}
};

View File

@@ -1,16 +0,0 @@
"use strict";
var regenerator = require("regenerator-6to5");
var t = require("../../../types");
exports.check = function (node) {
return t.isFunction(node) && (node.async || node.generator);
};
exports.ast = {
before: function (ast, file) {
regenerator.transform(ast, {
includeRuntime: file.opts.includeRegenerator && "if used"
});
}
};

View File

@@ -1,91 +0,0 @@
"use strict";
var util = require("../../../util");
var core = require("core-js/library");
var t = require("../../../types");
var has = require("lodash/object/has");
var contains = require("lodash/collection/contains");
var coreHas = function (node) {
return node.name !== "_" && has(core, node.name);
};
var ALIASABLE_CONSTRUCTORS = [
"Symbol",
"Promise",
"Map",
"WeakMap",
"Set",
"WeakSet"
];
var astVisitor = {
enter: function (node, parent, scope, context, file) {
var prop;
if (t.isMemberExpression(node) && t.isReferenced(node, parent)) {
// Array.from -> _core.Array.from
var obj = node.object;
prop = node.property;
if (!t.isReferenced(obj, node)) return;
if (!node.computed && coreHas(obj) && has(core[obj.name], prop.name)) {
context.skip();
return t.prependToMemberExpression(node, file.get("coreIdentifier"));
}
} else if (t.isReferencedIdentifier(node, parent) && !t.isMemberExpression(parent) && contains(ALIASABLE_CONSTRUCTORS, node.name) && !scope.getBinding(node.name)) {
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
return t.memberExpression(file.get("coreIdentifier"), node);
} else if (t.isCallExpression(node)) {
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
if (node.arguments.length) return;
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (!callee.computed) return;
prop = callee.property;
if (!t.isIdentifier(prop.object, { name: "Symbol" })) return;
if (!t.isIdentifier(prop.property, { name: "iterator" })) return;
return util.template("corejs-iterator", {
CORE_ID: file.get("coreIdentifier"),
VALUE: callee.object
});
}
}
};
exports.optional = true;
exports.manipulateOptions = function (opts) {
if (opts.whitelist.length) opts.whitelist.push("es6.modules");
};
exports.ast = {
enter: function (ast, file) {
file.setDynamic("runtimeIdentifier", function () {
return file.addImport("6to5-runtime/helpers", "to5Helpers");
});
file.setDynamic("coreIdentifier", function () {
return file.addImport("6to5-runtime/core-js", "core");
});
file.setDynamic("regeneratorIdentifier", function () {
return file.addImport("6to5-runtime/regenerator", "regeneratorRuntime");
});
},
after: function (ast, file) {
file.scope.traverse(ast, astVisitor, file);
}
};
exports.Identifier = function (node, parent, scope, context, file) {
if (node.name === "regeneratorRuntime" && t.isReferenced(node, parent)) {
return file.get("regeneratorIdentifier");
}
};

View File

@@ -1,21 +0,0 @@
"use strict";
var useStrict = require("../../helpers/use-strict");
var t = require("../../../types");
exports.ast = {
exit: function (ast) {
if (!useStrict.has(ast.program)) {
ast.program.body.unshift(t.expressionStatement(t.literal("use strict")));
}
}
};
exports.FunctionDeclaration =
exports.FunctionExpression = function (node, parent, scope, context) {
context.skip();
};
exports.ThisExpression = function () {
return t.identifier("undefined");
};

View File

@@ -1,12 +0,0 @@
"use strict";
var t = require("../../../types");
exports.ForInStatement =
exports.ForOfStatement = function (node, parent, scope, context, file) {
var left = node.left;
if (t.isVariableDeclaration(left)) {
var declar = left.declarations[0];
if (declar.init) throw file.errorWithNode(declar, "No assignments allowed in for-in/of head");
}
};

View File

@@ -1,8 +0,0 @@
"use strict";
exports.MethodDefinition =
exports.Property = function (node, parent, scope, context, file) {
if (node.kind === "set" && node.value.params.length !== 1) {
throw file.errorWithNode(node.value, "Setters must have only one parameter");
}
};

View File

@@ -1,274 +0,0 @@
"use strict";
module.exports = traverse;
/* jshint maxparams:7 */
var Scope = require("./scope");
var t = require("../types");
var contains = require("lodash/collection/contains");
var flatten = require("lodash/array/flatten");
var compact = require("lodash/array/compact");
function TraversalContext(scope) {
this.shouldFlatten = false;
this.shouldRemove = false;
this.shouldSkip = false;
this.shouldStop = false;
this.scope = scope;
}
TraversalContext.prototype.flatten = function () {
this.shouldFlatten = true;
};
TraversalContext.prototype.remove = function () {
this.shouldRemove = true;
this.shouldSkip = true;
};
TraversalContext.prototype.skip = function () {
this.shouldSkip = true;
};
TraversalContext.prototype.stop = function () {
this.shouldStop = true;
this.shouldSkip = true;
};
TraversalContext.prototype.reset = function () {
this.shouldRemove = false;
this.shouldSkip = false;
this.shouldStop = false;
};
TraversalContext.prototype.maybeRemove = function (obj, key) {
if (this.shouldRemove) {
obj[key] = null;
this.flatten();
}
};
TraversalContext.prototype.replaceNode = function (obj, key, node, replacement, scope) {
var isArray = Array.isArray(replacement);
// inherit comments from original node to the first replacement node
var inheritTo = replacement;
if (isArray) inheritTo = replacement[0];
if (inheritTo) t.inheritsComments(inheritTo, node);
// replace the node
obj[key] = replacement;
var file = this.scope && this.scope.file;
if (file) {
if (isArray) {
for (var i = 0; i < replacement.length; i++) {
file.checkNode(replacement[i], scope);
}
} else {
file.checkNode(replacement, scope);
}
}
// we're replacing a statement or block node with an array of statements so we better
// ensure that it's a block
if (isArray && contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
t.ensureBlock(obj, key);
}
if (isArray) {
this.flatten();
}
};
TraversalContext.prototype.call = function (fn, obj, key, node, parent, scope, state) {
var replacement = fn(node, parent, scope, this, state);
if (replacement) {
this.replaceNode(obj, key, node, replacement, scope);
node = replacement;
}
this.maybeRemove(obj, key);
return node;
};
TraversalContext.prototype.visitNode = function (obj, key, opts, scope, parent, state) {
this.reset();
var node = obj[key];
// type is blacklisted
if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) {
return;
}
var ourScope = scope;
// we're entering a new scope so let's construct it!
if (!opts.noScope && t.isScope(node)) {
ourScope = new Scope(node, parent, scope);
}
node = this.call(opts.enter, obj, key, node, parent, ourScope, state);
if (this.shouldSkip) {
return this.shouldStop;
}
if (Array.isArray(node)) {
// traverse over these replacement nodes we purposely don't call exitNode
// as the original node has been destroyed
for (var i = 0; i < node.length; i++) {
traverseNode(node[i], opts, ourScope, state);
}
} else {
traverseNode(node, opts, ourScope, state);
this.call(opts.exit, obj, key, node, parent, ourScope, state);
}
return this.shouldStop;
};
TraversalContext.prototype.visit = function (node, key, opts, scope, state) {
var nodes = node[key];
if (!nodes) return;
if (!Array.isArray(nodes)) {
return this.visitNode(node, key, opts, scope, node, state);
}
if (nodes.length === 0) {
return;
}
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] && this.visitNode(nodes, i, opts, scope, node, state)) {
return true;
}
}
if (this.shouldFlatten) {
node[key] = flatten(node[key]);
if (key === "body") {
// we can safely compact this
node[key] = compact(node[key]);
}
}
};
function traverseNode(node, opts, scope, state) {
var keys = t.VISITOR_KEYS[node.type];
if (!keys) return;
var context = new TraversalContext(scope);
for (var i = 0; i < keys.length; i++) {
if (context.visit(node, keys[i], opts, scope, state)) {
return;
}
}
}
function traverse(parent, opts, scope, state) {
if (!parent) return;
if (!opts.noScope && !scope) {
if (parent.type !== "Program" && parent.type !== "File") {
throw new Error("Must pass a scope unless traversing a Program/File got a " + parent.type + " node");
}
}
if (!opts) opts = {};
if (!opts.enter) opts.enter = function () { };
if (!opts.exit) opts.exit = function () { };
// array of nodes
if (Array.isArray(parent)) {
for (var i = 0; i < parent.length; i++) {
traverseNode(parent[i], opts, scope, state);
}
} else {
traverseNode(parent, opts, scope, state);
}
}
function clearNode(node) {
node._declarations = null;
node.extendedRange = null;
node._scopeInfo = null;
node.tokens = null;
node.range = null;
node.start = null;
node.end = null;
node.loc = null;
node.raw = null;
if (Array.isArray(node.trailingComments)) {
clearComments(node.trailingComments);
}
if (Array.isArray(node.leadingComments)) {
clearComments(node.leadingComments);
}
}
var clearVisitor = {
noScope: true,
enter: clearNode
};
function clearComments(comments) {
for (var i = 0; i < comments.length; i++) {
clearNode(comments[i]);
}
}
traverse.removeProperties = function (tree) {
clearNode(tree);
traverse(tree, clearVisitor);
return tree;
};
traverse.explode = function (obj) {
for (var type in obj) {
var fns = obj[type];
var aliases = t.FLIPPED_ALIAS_KEYS[type];
if (aliases) {
for (var i = 0; i < aliases.length; i++) {
obj[aliases[i]] = fns;
}
}
}
return obj;
};
function hasBlacklistedType(node, parent, scope, context, state) {
if (node.type === state.type) {
state.has = true;
context.skip();
}
}
traverse.hasType = function (tree, scope, type, blacklistTypes) {
// the node we're searching in is blacklisted
if (contains(blacklistTypes, tree.type)) return false;
// the type we're looking for is the same as the passed node
if (tree.type === type) return true;
var state = {
has: false,
type: type
};
traverse(tree, {
blacklist: blacklistTypes,
enter: hasBlacklistedType
}, scope, state);
return state.has;
};

View File

@@ -1,506 +0,0 @@
"use strict";
module.exports = Scope;
var contains = require("lodash/collection/contains");
var traverse = require("./index");
var defaults = require("lodash/object/defaults");
var globals = require("globals");
var flatten = require("lodash/array/flatten");
var extend = require("lodash/object/extend");
var object = require("../helpers/object");
var each = require("lodash/collection/each");
var has = require("lodash/object/has");
var t = require("../types");
/**
* This searches the current "scope" and collects all references/bindings
* within.
*
* @param {Node} block
* @param {Node} parentBlock
* @param {Scope} [parent]
* @param {File} [file]
*/
function Scope(block, parentBlock, parent, file) {
this.parent = parent;
this.file = parent ? parent.file : file;
this.parentBlock = parentBlock;
this.block = block;
this.crawl();
}
Scope.defaultDeclarations = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys));
/**
* Description
*
* @param {Object} node
* @param {Object} opts
* @param [state]
*/
Scope.prototype.traverse = function (node, opts, state) {
traverse(node, opts, this, state);
};
/**
* Description
*
* @param {File} file
* @param {String} [name="temp"]
*/
Scope.prototype.generateTemp = function (file, name) {
var id = file.generateUidIdentifier(name || "temp", this);
this.push({
key: id.name,
id: id
});
return id;
};
/**
* Description
*
* @param {String} name
*/
Scope.prototype.generateUidIdentifier = function (name) {
return this.file.generateUidIdentifier(name, this);
};
/*
* Description
*
* @param {Object} parent
* @returns {Object}
*/
Scope.prototype.generateUidBasedOnNode = function (parent) {
var node = parent;
if (t.isAssignmentExpression(parent)) {
node = parent.left;
} else if (t.isVariableDeclarator(parent)) {
node = parent.id;
} else if (t.isProperty(node)) {
node = node.key;
}
var parts = [];
var add = function (node) {
if (t.isMemberExpression(node)) {
add(node.object);
add(node.property);
} else if (t.isIdentifier(node)) {
parts.push(node.name);
} else if (t.isLiteral(node)) {
parts.push(node.value);
} else if (t.isCallExpression(node)) {
add(node.callee);
}
};
add(node);
var id = parts.join("$");
id = id.replace(/^_/, "") || "ref";
return this.file.generateUidIdentifier(id, this);
};
/**
* Description
*
* @param {Object} node
* @returns {Object}
*/
Scope.prototype.generateTempBasedOnNode = function (node) {
if (t.isIdentifier(node) && this.hasBinding(node.name)) {
return null;
}
var id = this.generateUidBasedOnNode(node);
this.push({
key: id.name,
id: id
});
return id;
};
Scope.prototype.checkBlockScopedCollisions = function (key, id) {
if (this.declarationKinds["let"][key] || this.declarationKinds["const"][key]) {
throw this.file.errorWithNode(id, "Duplicate declaration " + key, TypeError);
}
};
Scope.prototype.inferType = function (node) {
var target;
if (t.isVariableDeclarator(node)) {
target = node.init;
}
if (t.isLiteral(target) || t.isArrayExpression(target) || t.isObjectExpression(target)) {
// todo: possibly call some helper that will resolve these to a type annotation
}
if (t.isCallExpression(target)) {
// todo: need to resolve this to a return type
}
if (t.isMemberExpression(target)) {
// todo: crawl this and find the correct type, bail on anything that we cannot
// possibly be 100% confident on
}
if (t.isIdentifier(target)) {
return this.getType(target.name);
}
};
Scope.prototype.registerType = function (key, id, node) {
var type;
if (id.typeAnnotation) {
type = id.typeAnnotation;
}
if (!type) {
type = this.inferType(node);
}
if (type) {
if (t.isTypeAnnotation(type)) type = type.typeAnnotation;
this.types[key] = type;
}
};
Scope.prototype.register = function (node, reference, kind) {
if (t.isVariableDeclaration(node)) {
return this.registerVariableDeclaration(node);
}
var ids = t.getBindingIdentifiers(node);
extend(this.references, ids);
if (reference) return;
for (var key in ids) {
var id = ids[key];
this.checkBlockScopedCollisions(key, id);
this.registerType(key, id, node);
this.bindings[key] = id;
}
var kinds = this.declarationKinds[kind];
if (kinds) extend(kinds, ids);
};
Scope.prototype.registerVariableDeclaration = function (declar) {
var declars = declar.declarations;
for (var i = 0; i < declars.length; i++) {
this.register(declars[i], false, declar.kind);
}
};
var functionVariableVisitor = {
enter: function (node, parent, scope, context, state) {
if (t.isFor(node)) {
each(t.FOR_INIT_KEYS, function (key) {
var declar = node[key];
if (t.isVar(declar)) state.scope.register(declar);
});
}
// this block is a function so we'll stop since none of the variables
// declared within are accessible
if (t.isFunction(node)) return context.skip();
// function identifier doesn't belong to this scope
if (state.blockId && node === state.blockId) return;
// delegate block scope handling to the `blockVariableVisitor`
if (t.isBlockScoped(node)) return;
// this will be hit again once we traverse into it after this iteration
if (t.isExportDeclaration(node) && t.isDeclaration(node.declaration)) return;
// we've ran into a declaration!
if (t.isDeclaration(node)) state.scope.register(node);
}
};
var programReferenceVisitor = {
enter: function (node, parent, scope, context, state) {
if (t.isReferencedIdentifier(node, parent) && !scope.hasReference(node.name)) {
state.register(node, true);
}
}
};
var blockVariableVisitor = {
enter: function (node, parent, scope, context, state) {
if (t.isBlockScoped(node)) {
state.register(node);
} else if (t.isScope(node)) {
context.skip();
}
}
};
Scope.prototype.crawl = function () {
var parent = this.parent;
var block = this.block;
var i;
//
var info = block._scopeInfo;
if (info) {
extend(this, info);
return;
}
info = block._scopeInfo = {
declarationKinds: {
"const": object(),
"var": object(),
"let": object()
},
references: object(),
bindings: object(),
types: object(),
};
extend(this, info);
//
if (parent && t.isBlockStatement(block) && t.isLoop(parent.block, { body: block })) {
// delegate let bindings to the parent loop
return;
}
// ForStatement - left, init
if (t.isLoop(block)) {
for (i = 0; i < t.FOR_INIT_KEYS.length; i++) {
var node = block[t.FOR_INIT_KEYS[i]];
if (t.isBlockScoped(node)) this.register(node, false, true);
}
if (t.isBlockStatement(block.body)) {
block = block.body;
}
}
// Program, BlockStatement - let variables
if (t.isBlockStatement(block) || t.isProgram(block)) {
this.traverse(block, blockVariableVisitor, this);
}
// CatchClause - param
if (t.isCatchClause(block)) {
this.register(block.param);
}
// ComprehensionExpression - blocks
if (t.isComprehensionExpression(block)) {
this.register(block);
}
// Function - params, rest
if (t.isFunction(block)) {
for (i = 0; i < block.params.length; i++) {
this.register(block.params[i]);
}
}
// Program, Function - var variables
if (t.isProgram(block) || t.isFunction(block)) {
this.traverse(block, functionVariableVisitor, {
blockId: block.id,
scope: this
});
}
if (t.isFunctionExpression(block) && block.id) {
if (!t.isProperty(this.parentBlock, { method: true })) {
// SpiderMonkey AST doesn't use MethodDefinition here when it probably
// should since they should be semantically the same?
this.register(block.id);
}
}
// Program
if (t.isProgram(block)) {
this.traverse(block, programReferenceVisitor, this);
}
};
/**
* Description
*
* @param {Object} opts
*/
Scope.prototype.push = function (opts) {
var block = this.block;
if (t.isFor(block) || t.isCatchClause(block) || t.isFunction(block)) {
t.ensureBlock(block);
block = block.body;
}
if (t.isBlockStatement(block) || t.isProgram(block)) {
block._declarations = block._declarations || {};
block._declarations[opts.key] = {
kind: opts.kind,
id: opts.id,
init: opts.init
};
} else {
throw new TypeError("cannot add a declaration here in node type " + block.type);
}
};
/**
* Walk up the scope tree until we hit a `Function` and then
* push our `node` to it's references.
*
* @param {String} kind
* @param {Object} node
*/
Scope.prototype.addDeclarationToFunctionScope = function (kind, node) {
var scope = this.getFunctionParent();
var ids = t.getBindingIdentifiers(node);
extend(scope.bindings, ids);
extend(scope.references, ids);
// this ignores the duplicate declaration logic specified in `getInfo`
// but it doesn't really matter
extend(scope.declarationKinds[kind], ids);
};
/**
* Walk up the scope tree until we hit either a Function or reach the
* very top at hit Program.
*/
Scope.prototype.getFunctionParent = function () {
var scope = this;
while (scope.parent && !t.isFunction(scope.block)) {
scope = scope.parent;
}
return scope;
};
/**
* Walks the scope tree and gathers **all** bindings.
*
* @returns {Object}
*/
Scope.prototype.getAllBindings = function () {
var ids = object();
var scope = this;
do {
defaults(ids, scope.bindings);
scope = scope.parent;
} while (scope);
return ids;
};
/**
* Walks the scope tree and gathers all declarations of `kind`.
*
* @param {String} kind
* @returns {Object}
*/
Scope.prototype.getAllDeclarationsOfKind = function (kind) {
var ids = object();
var scope = this;
do {
defaults(ids, scope.declarationKinds[kind]);
scope = scope.parent;
} while (scope);
return ids;
};
//
Scope.prototype.get = function (id, type) {
return id && (this.getOwn(id, type) || this.parentGet(id, type));
};
Scope.prototype.getOwn = function (id, type) {
var refs = {
reference: this.references,
binding: this.bindings,
type: this.types
}[type];
return refs && has(refs, id) && refs[id];
};
Scope.prototype.parentGet = function (id, type) {
return this.parent && this.parent.get(id, type);
};
Scope.prototype.has = function (id, type) {
if (!id) return false;
if (this.hasOwn(id, type)) return true;
if (this.parentHas(id, type)) return true;
if (contains(Scope.defaultDeclarations, id)) return true;
return false;
};
Scope.prototype.hasOwn = function (id, type) {
return !!this.getOwn(id, type);
};
Scope.prototype.parentHas = function (id, type) {
return this.parent && this.parent.has(id, type);
};
each({
reference: "Reference",
binding: "Binding",
type: "Type"
}, function (title, type) {
each([
"get",
"has",
"getOwn",
"hasOwn",
"parentGet",
"parentHas",
], function (methodName) {
Scope.prototype[methodName + title] = function (id) {
return this[methodName](id, type);
};
});
});

View File

@@ -1,33 +0,0 @@
{
"ArrayExpression": ["elements"],
"ArrowFunctionExpression": ["params", "body"],
"AssignmentExpression": ["operator", "left", "right"],
"BinaryExpression": ["operator", "left", "right"],
"BlockStatement": ["body"],
"CallExpression": ["callee", "arguments"],
"ConditionalExpression": ["test", "consequent", "alternate"],
"ExpressionStatement": ["expression"],
"File": ["program", "comments", "tokens"],
"FunctionExpression": ["id", "params", "body", "generator"],
"FunctionDeclaration": ["id", "params", "body", "generator"],
"Identifier": ["name"],
"IfStatement": ["test", "consequent", "alternate"],
"ImportDeclaration": ["specifiers", "source"],
"ImportSpecifier": ["id", "name"],
"Literal": ["value"],
"LogicalExpression": ["operator", "left", "right"],
"MemberExpression": ["object", "property", "computed"],
"MethodDefinition": ["key", "value", "computed", "kind"],
"NewExpression": ["callee", "arguments"],
"ObjectExpression": ["properties"],
"Program": ["body"],
"Property": ["kind", "key", "value", "computed"],
"ReturnStatement": ["argument"],
"SequenceExpression": ["expressions"],
"ThrowExpression": ["argument"],
"UnaryExpression": ["operator", "argument", "prefix"],
"VariableDeclaration": ["kind", "declarations"],
"VariableDeclarator": ["id", "init"],
"WithStatement": ["object", "body"],
"YieldExpression": ["argument", "delegate"]
}

View File

@@ -1,12 +0,0 @@
"use strict";
module.exports = Node;
var acorn = require("acorn-6to5");
var oldNode = acorn.Node;
acorn.Node = Node;
function Node() {
oldNode.apply(this);
}

View File

@@ -1,8 +1,8 @@
"use strict";
var transform = module.exports = require("./transformation");
var transform = module.exports = require("../transformation");
transform.version = require("../../package").version;
transform.version = require("../../../package").version;
transform.transform = transform;
@@ -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 () {

View File

@@ -1,29 +1,29 @@
"use strict";
var transform = require("./transformation");
var util = require("./util");
var fs = require("fs");
var isFunction = require("lodash/lang/isFunction");
var transform = require("../transformation");
var util = require("../util");
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");
exports.register = function (opts) {
var register = require("./register");
var register = require("./register/node");
if (opts != null) register(opts);
return register;
};
exports.polyfill = function () {
require("./polyfill");
require("../polyfill");
};
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;

View File

@@ -0,0 +1,7 @@
"use strict";
// required to safely use babel/register within a browserify codebase
module.exports = function () {};
require("../../polyfill");

View File

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

View File

@@ -1,14 +1,14 @@
"use strict";
require("./polyfill");
require("../../polyfill");
var sourceMapSupport = require("source-map-support");
var registerCache = require("./register-cache");
var util = require("./util");
var to5 = require("./index");
var fs = require("fs");
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 fs = require("fs");
sourceMapSupport.install({
retrieveSourceMap: function (source) {
@@ -44,15 +44,17 @@ var mtime = function (filename) {
var compile = function (filename) {
var result;
var cacheKey = filename + ":" + JSON.stringify(transformOpts);
if (cache) {
var cached = cache[filename];
var cached = cache[cacheKey];
if (cached && cached.mtime === mtime(filename)) {
result = cached;
}
}
if (!result) {
result = to5.transformFileSync(filename, extend({
result = babel.transformFileSync(filename, extend({
sourceMap: true,
ast: false
}, transformOpts));
@@ -60,7 +62,7 @@ var compile = function (filename) {
if (cache) {
result.mtime = mtime(filename);
cache[filename] = result;
cache[cacheKey] = result;
}
maps[filename] = result.map;

View File

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

View File

@@ -1,4 +1,4 @@
var File = require("./file");
var File = require("./transformation/file");
var util = require("./util");
var each = require("lodash/collection/each");
var t = require("./types");

View File

@@ -1,7 +1,7 @@
module.exports = detect;
var SYNTAX_KEYS = require("./syntax-keys");
var traverse = require("../traverse");
var traverse = require("../traversal");
var visitors = traverse.explode(require("./visitors"));
function detect(ast) {

View File

@@ -1,5 +1,5 @@
var t = require("../types");
var _ = require("lodash");
var includes = require("lodash/collection/includes");
exports.AssignmentExpression = function (node, parent, detected) {
if (node.operator === "**=") {
@@ -38,7 +38,7 @@ exports.Property = function (node, parent, detected) {
};
exports.AssignmentPattern = function (node, parent, detected) {
if (t.isFunction(parent) && _.contains(parent.params, node)) {
if (t.isFunction(parent) && includes(parent.params, node)) {
detected("es6.parameters.default");
}
};

View File

@@ -2,10 +2,11 @@
module.exports = Buffer;
var util = require("../util");
var isNumber = require("lodash/lang/isNumber");
var repeating = require("repeating");
var trimRight = require("trim-right");
var isBoolean = require("lodash/lang/isBoolean");
var contains = require("lodash/collection/contains");
var includes = require("lodash/collection/includes");
var isNumber = require("lodash/lang/isNumber");
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,17 +158,17 @@ 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)) {
return contains(cha, last);
return includes(cha, last);
} else {
return cha === last;
}

View File

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

View File

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

View File

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

View File

@@ -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");
@@ -21,13 +21,8 @@ exports.IfStatement = function (node, print) {
print.indentOnComments(node.consequent);
if (node.alternate) {
if (this.isLast("}")) this.push(" ");
this.keyword("else");
if (this.format.format && !t.isBlockStatement(node.alternate)) {
this.push(" ");
}
if (this.isLast("}")) this.space();
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 += " ";
}

View File

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

View File

@@ -9,15 +9,15 @@ 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 util = require("../util");
var extend = require("lodash/object/extend");
var each = require("lodash/collection/each");
var n = require("./node");
var t = require("../types");
var each = require("lodash/collection/each");
var extend = require("lodash/object/extend");
var merge = require("lodash/object/merge");
function CodeGenerator(ast, opts, code) {
opts = opts || {};
@@ -25,9 +25,10 @@ function CodeGenerator(ast, opts, code) {
this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
this.format = CodeGenerator.normalizeOptions(code, opts);
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);
@@ -46,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 = {
@@ -114,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);
};
@@ -166,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);
@@ -226,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);
@@ -301,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;
@@ -343,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) {

View File

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

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

View File

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

View File

@@ -1,9 +1,8 @@
// 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 repeating = require("repeating");
var tokenize = require("js-tokenizer");
var chalk = require("chalk");
var defs = {
string1: "red",
@@ -43,7 +42,7 @@ var highlight = function (text) {
module.exports = function (lines, lineNumber, colNumber) {
colNumber = Math.max(colNumber, 0);
if (supportsColor) {
if (chalk.supportsColor) {
lines = highlight(lines);
}
@@ -63,15 +62,15 @@ module.exports = function (lines, lineNumber, colNumber) {
var gutter = curr === lineNumber ? "> " : " ";
var sep = curr + util.repeat(width + 1);
var sep = curr + repeating(" ", width + 1);
gutter += sep + "| ";
var str = gutter + line;
if (colNumber && curr === lineNumber) {
str += "\n";
str += util.repeat(gutter.length - 2);
str += "|" + util.repeat(colNumber) + "^";
str += repeating(" ", gutter.length - 2);
str += "|" + repeating(" ", colNumber) + "^";
}
return str;

View File

@@ -0,0 +1,9 @@
var t = require("../types");
module.exports = function (ast, comments, tokens) {
if (ast && ast.type === "Program") {
return t.file(ast, comments || [], tokens || []);
} else {
throw new Error("Not a valid ast?");
}
};

View File

@@ -0,0 +1,49 @@
var normalizeAst = require("./normalize-ast");
var estraverse = require("estraverse");
var codeFrame = require("./code-frame");
var acorn = require("acorn-babel");
module.exports = function (opts, code, callback) {
try {
var comments = [];
var tokens = [];
var ast = acorn.parse(code, {
allowImportExportEverywhere: opts.allowImportExportEverywhere,
allowReturnOutsideFunction: !opts._anal,
ecmaVersion: opts.experimental ? 7 : 6,
playground: opts.playground,
strictMode: opts.strictMode,
onComment: comments,
locations: true,
onToken: tokens,
ranges: true
});
estraverse.attachComments(ast, comments, tokens);
ast = normalizeAst(ast, comments, tokens);
if (callback) {
return callback(ast);
} else {
return ast;
}
} catch (err) {
if (!err._babel) {
err._babel = true;
var message = opts.filename + ": " + err.message;
var loc = err.loc;
if (loc) {
var frame = codeFrame(code, loc.line, loc.column + 1);
message += frame;
}
if (err.stack) err.stack = err.stack.replace(err.message, message);
err.message = message;
}
throw err;
}
};

51
lib/babel/messages.js Normal file
View File

@@ -0,0 +1,51 @@
var util = require("util");
exports.messages = {
tailCallReassignmentDeopt: "Function reference has been reassigned so it's probably be dereferenced so we can't optimise this with confidence",
JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.",
classesIllegalBareSuper: "Illegal use of bare super",
classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead",
classesIllegalConstructorKind: "Illegal kind for constructor method",
scopeDuplicateDeclaration: "Duplicate declaration $1",
undeclaredVariable: "Reference to undeclared variable $1",
undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?",
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",
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) {
var msg = exports.messages[key];
if (!msg) throw new ReferenceError("Unknown message `" + key + "`");
var args = [];
for (var i = 1; i < arguments.length; i++) {
args.push(arguments[i]);
}
args = exports.parseArgs(args);
return msg.replace(/\$(\d+)/g, function (str, i) {
return args[--i];
});
};
exports.parseArgs = function (args) {
return args.map(function (val) {
if (val != null && val.inspect) {
return val.inspect();
} else {
try {
return JSON.stringify(val) || val + "";
} catch (e) {
return util.inspect(val);
}
}
});
};

View File

@@ -1,16 +1,14 @@
"use strict";
var t = require("./types");
var extend = require("lodash/object/extend");
require("./types/node");
var t = require("./types");
// estraverse
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
View 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");

View File

@@ -2,24 +2,27 @@
module.exports = File;
var SHEBANG_REGEX = /^\#\!.*/;
var isFunction = require("lodash/lang/isFunction");
var transform = require("./transformation");
var generate = require("./generation");
var defaults = require("lodash/object/defaults");
var contains = require("lodash/collection/contains");
var clone = require("./helpers/clone");
var Scope = require("./traverse/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 = {};
@@ -40,6 +43,7 @@ File.helpers = [
"tagged-template-literal-loose",
"interop-require",
"to-array",
"to-consumable-array",
"sliced-to-array",
"object-without-properties",
"has-own",
@@ -53,7 +57,10 @@ File.helpers = [
"get",
"set",
"class-call-check",
"object-destructuring-empty"
"object-destructuring-empty",
"temporal-undefined",
"temporal-assert-defined",
"self-global"
];
File.validOptions = [
@@ -75,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",
@@ -89,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) {
@@ -100,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: [],
@@ -112,23 +126,31 @@ 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 = opts.filename.replace(/\\/g, "/");
opts.filename = slash(opts.filename);
if (opts.sourceRoot) {
opts.sourceRoot = slash(opts.sourceRoot);
}
if (opts.moduleId) {
opts.moduleIds = true;
}
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
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 (contains(opts.loose, "all")) {
if (includes(opts.loose, "all") || includes(opts.loose, true)) {
opts.loose = Object.keys(transform.transformers);
}
@@ -153,20 +175,34 @@ 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);
opts.whitelist = transform._ensureTransformerNames("whitelist", opts.whitelist);
opts.optional = transform._ensureTransformerNames("optional", opts.optional);
opts.loose = transform._ensureTransformerNames("loose", opts.loose);
opts.optional = transform._ensureTransformerNames("optional", opts.optional);
opts.loose = transform._ensureTransformerNames("loose", opts.loose);
if (opts.reactCompat) {
opts.optional.push("reactCompat");
console.error("The reactCompat option has been moved into the optional transformer `reactCompat`");
}
var ensureEnabled = function (key) {
var namespace = transform.transformerNamespaces[key];
if (namespace === "es7") opts.experimental = true;
if (namespace === "playground") opts.playground = true;
};
each(opts.whitelist, ensureEnabled);
each(opts.optional, ensureEnabled);
return opts;
};
File.prototype.isLoose = function (key) {
return contains(this.opts.loose, key);
return includes(this.opts.loose, key);
};
File.prototype.buildTransformers = function () {
@@ -197,20 +233,10 @@ File.prototype.buildTransformers = function () {
this.transformers = transformers;
};
File.prototype.toArray = function (node, i) {
if (t.isArrayExpression(node)) {
return node;
} else if (t.isIdentifier(node) && node.name === "arguments") {
return t.callExpression(t.memberExpression(this.addHelper("slice"), t.identifier("call")), [node]);
} else {
var declarationName = "to-array";
var args = [node];
if (i) {
args.push(t.literal(i));
declarationName = "sliced-to-array";
}
return t.callExpression(this.addHelper(declarationName), args);
}
File.prototype.debug = function (msg) {
var parts = this.opts.filename;
if (msg) parts += ": " + msg;
util.debug(parts);
};
File.prototype.getModuleFormatter = function (type) {
@@ -229,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;
@@ -260,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);
}
@@ -282,9 +311,21 @@ 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 (!contains(File.helpers, name)) {
throw new ReferenceError("unknown declaration " + name);
if (!includes(File.helpers, name)) {
throw new ReferenceError("Unknown helper " + name);
}
var program = this.ast.program;
@@ -292,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,
@@ -309,6 +350,10 @@ File.prototype.addHelper = function (name) {
}
};
File.prototype.logDeopt = function () {
// todo, (node, msg)
};
File.prototype.errorWithNode = function (node, msg, Error) {
Error = Error || SyntaxError;
@@ -332,18 +377,16 @@ 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 util.parse(opts, code, function (tree) {
return parse(opts, code, function (tree) {
self.transform(tree);
return self.generate();
});
};
File.prototype.transform = function (ast) {
var self = this;
util.debug(this.opts.filename);
this.debug();
this.ast = ast;
this.lastStatements = t.getLastStatements(ast.program);
@@ -356,42 +399,46 @@ File.prototype.transform = function (ast) {
this.checkNode(ast);
var astRun = function (key) {
each(self.transformerStack, function (pass) {
pass.astRun(key);
});
};
astRun("enter");
this.call("pre");
each(this.transformerStack, function (pass) {
pass.transform();
});
astRun("exit");
this.call("post");
};
var checkTransformerVisitor = {
enter: function (node, parent, scope, context, state) {
state.check(node, scope);
File.prototype.call = function (key) {
var stack = this.transformerStack;
for (var i = 0; i < stack.length; i++) {
var transformer = stack[i].transformer;
if (transformer[key]) {
transformer[key](this);
}
}
};
var checkTransformerVisitor = {
enter: function (node, parent, scope, state) {
checkNode(state.stack, node, scope);
}
};
var checkNode = function (stack, node, scope) {
each(stack, function (pass) {
if (pass.shouldRun) return;
pass.checkNode(node, scope);
});
};
File.prototype.checkNode = function (node, scope) {
var self = this;
var stack = this.transformerStack;
scope = scope || this.scope;
var check = function (node, scope) {
each(self.transformerStack, function (pass) {
if (pass.shouldRun) return;
pass.checkNode(node, scope);
});
};
check(node, scope);
checkNode(stack, node, scope);
scope.traverse(node, checkTransformerVisitor, {
check: check
stack: stack
});
};
@@ -418,35 +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.hasReference(uid));
return uid;
};
File.prototype.generateUidIdentifier = function (name, scope) {
scope = scope || this.scope;
var id = t.identifier(this.generateUid(name, scope));
scope.addDeclarationToFunctionScope("var", id);
return id;
};
File.prototype._generateUid = function (name, i) {
var id = name;
if (i > 1) id += i;
return "_" + id;
};

View File

@@ -12,7 +12,7 @@ module.exports = function (exports, opts) {
return t.assignmentExpression("=", left, right);
};
exports.ExpressionStatement = function (node, parent, scope, context, file) {
exports.ExpressionStatement = function (node, parent, scope, file) {
// hit the `AssignmentExpression` one below
if (file.isConsequenceExpressionStatement(node)) return;
@@ -29,7 +29,7 @@ module.exports = function (exports, opts) {
return nodes;
};
exports.AssignmentExpression = function (node, parent, scope, context, file) {
exports.AssignmentExpression = function (node, parent, scope, file) {
if (!isAssignment(node)) return;
var nodes = [];

View File

@@ -8,7 +8,7 @@ module.exports = function (exports, opts) {
return t.assignmentExpression("=", left, right);
};
exports.ExpressionStatement = function (node, parent, scope, context, file) {
exports.ExpressionStatement = function (node, parent, scope, file) {
// hit the `AssignmentExpression` one below
if (file.isConsequenceExpressionStatement(node)) return;
@@ -27,7 +27,7 @@ module.exports = function (exports, opts) {
return nodes;
};
exports.AssignmentExpression = function (node, parent, scope, context, file) {
exports.AssignmentExpression = function (node, parent, scope, file) {
if (!opts.is(node, file)) return;
var nodes = [];

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