Compare commits

...

210 Commits

Author SHA1 Message Date
Sebastian McKenzie
afdde8b3a7 v2.2.0 2014-12-29 12:48:45 +11:00
Sebastian McKenzie
918ddb4124 disable system tests temporairly 2014-12-29 11:16:47 +11:00
Sebastian McKenzie
18739ad78b remove unused variable 2014-12-29 11:15:24 +11:00
Sebastian McKenzie
74a84e2473 fix duplicate comments being output, breaking code 2014-12-29 11:13:50 +11:00
Sebastian McKenzie
52ffc65a06 make system module formatter modules anonymous by default - fixes #347 2014-12-29 01:55:30 +11:00
Sebastian McKenzie
d4fbfbbe47 Merge pull request #348 from guybedford/system
System test adjustments
2014-12-29 01:51:16 +11:00
Sebastian McKenzie
781467d423 v2.1.0 2014-12-29 01:41:05 +11:00
Sebastian McKenzie
44f5b7d013 fix case statement newline in code generator test 2014-12-29 01:39:04 +11:00
Sebastian McKenzie
dcf7f0b70b fix newline in case statement test 2014-12-29 01:37:19 +11:00
Sebastian McKenzie
03efd69998 check if node exists before inheriting comments to it 2014-12-29 01:37:12 +11:00
Sebastian McKenzie
213003a007 fix new templates path in dotfiles 2014-12-29 01:34:49 +11:00
Sebastian McKenzie
b0503f2efe add 2.1.0 changelog 2014-12-29 01:33:58 +11:00
Sebastian McKenzie
c8cf7ff286 better blacklist tests and expose register cache - closes #344 2014-12-29 01:31:26 +11:00
Sebastian McKenzie
ceb32816d7 fix destructuring in switch/case statements - closes #346 2014-12-29 01:26:51 +11:00
Sebastian McKenzie
32b94899a6 update runtime script to runtime generator 2014-12-29 01:26:21 +11:00
Sebastian McKenzie
d951082b09 move replacement node comment inheritance to traverse replacement 2014-12-29 01:26:11 +11:00
Sebastian McKenzie
b49f6e33d6 fix newline on case statement 2014-12-29 01:25:56 +11:00
Sebastian McKenzie
c5fa6425a5 explicit canRun for hidden transformers 2014-12-29 01:25:15 +11:00
Sebastian McKenzie
70d896d609 rename runtime script to runtime-generator 2014-12-29 01:24:57 +11:00
Sebastian McKenzie
e00fa8c9b1 update core-js 2014-12-29 01:24:41 +11:00
Sebastian McKenzie
13933bc9b8 move templates folder into transformation folder 2014-12-29 01:24:35 +11:00
guybedford
295bab544b re-exporting in setters 2014-12-28 14:43:56 +02:00
guybedford
cfe05ca10d exported variable declarations hoist along with functions 2014-12-28 14:41:32 +02:00
guybedford
da72182219 make modules anonymous 2014-12-28 14:38:52 +02:00
Sebastian McKenzie
005f5b2174 v2.0.4 2014-12-28 11:06:04 +11:00
Sebastian McKenzie
8551c94fa0 fix linting errors 2014-12-28 11:05:27 +11:00
Sebastian McKenzie
c509d06bc2 vaoid being greedy when destructuring array iterables 2014-12-28 11:04:00 +11:00
Sebastian McKenzie
f21743012b v2.0.3 2014-12-28 09:37:32 +11:00
Sebastian McKenzie
22dc33f93c remove unused variable 2014-12-28 09:36:29 +11:00
Sebastian McKenzie
6df6652629 better circular references in amd/umd/system module formatter 2014-12-28 09:35:47 +11:00
Sebastian McKenzie
4942ba6dd7 v2.0.2 2014-12-28 01:14:54 +11:00
Sebastian McKenzie
b63bd8cba0 remove interopRequire from system module formatter 2014-12-28 01:14:08 +11:00
Sebastian McKenzie
cd1eb11171 Merge branch 'master' of github.com:6to5/6to5 2014-12-28 01:10:00 +11:00
Sebastian McKenzie
6e1c12fd78 inherit comments in for-of transformer 2014-12-28 01:09:48 +11:00
Sebastian McKenzie
a4ea71b85d Merge pull request #337 from guybedford/master
Correct system format base support tests
2014-12-28 01:03:35 +11:00
Sebastian McKenzie
1df69bdbeb v2.0.1 2014-12-28 01:02:29 +11:00
Sebastian McKenzie
84c2766756 remove unused variable 2014-12-28 01:01:52 +11:00
Sebastian McKenzie
1f000ac83d add 2.0.1 changelog 2014-12-28 01:01:18 +11:00
Sebastian McKenzie
322aa246b8 fix automatic closure on private declarations - fixes #335 2014-12-28 01:01:13 +11:00
Sebastian McKenzie
601bbb86cd remap UpdateExpression in module exports - closes #334 2014-12-28 01:00:53 +11:00
guybedford
5c39685650 correct system format base support tests 2014-12-27 15:59:52 +02:00
Sebastian McKenzie
e6ac5eccd0 v2.0.0 2014-12-27 23:56:34 +11:00
Sebastian McKenzie
c4c9f7984f fix linting errors 2014-12-27 23:55:52 +11:00
Sebastian McKenzie
8d472a14be Merge pull request #319 from 6to5/2.0.0
2.0.0
2014-12-27 21:36:07 +11:00
Sebastian McKenzie
4fd007948c fix system modules exports from test 2014-12-27 21:34:20 +11:00
Sebastian McKenzie
f4e516e8ce fix tests as per acorn upgrade 2014-12-27 21:29:24 +11:00
Sebastian McKenzie
7fcd8ea642 upgrade acorn 2014-12-27 21:24:34 +11:00
Sebastian McKenzie
add0a7d5fe better ClassDeclarations in expression contexts 2014-12-27 21:24:29 +11:00
Sebastian McKenzie
e9445c9277 move spec transformers to bottom 2014-12-27 21:24:02 +11:00
Sebastian McKenzie
df66fa0a7f heavily simplify system module formatter and share common code between them all 2014-12-27 21:23:53 +11:00
Sebastian McKenzie
0a85211e8e fix traverse blacklist test 2014-12-27 21:22:34 +11:00
Sebastian McKenzie
ac8fc24fdb fix traverse test to reflect the new api 2014-12-27 19:16:06 +11:00
Sebastian McKenzie
71c4a29a78 update 2.0.0 changelog 2014-12-27 19:13:05 +11:00
Sebastian McKenzie
08dde22939 better ClassDeclaration contextual transformation 2014-12-27 19:12:56 +11:00
Sebastian McKenzie
d3ea0fe84f always add additional newline on the last node 2014-12-27 19:12:43 +11:00
Sebastian McKenzie
22851cd1ac clean up system module formatter 2014-12-27 19:12:31 +11:00
Sebastian McKenzie
987dc0692f Merge branch 'feat-system-module-rewrite' of https://github.com/douglasduteil/6to5 into 2.0.0
Conflicts:
	lib/6to5/transformation/modules/system.js
	test/fixtures/transformation/es6-modules-system/exports-from/expected.js
2014-12-27 17:05:21 +11:00
Sebastian McKenzie
560d60e3e7 fix formatting on react display name object declaration actual test 2014-12-27 17:02:00 +11:00
Sebastian McKenzie
e96d02c972 make traversal code simpler 2014-12-27 17:01:47 +11:00
Sebastian McKenzie
13a2d469a3 update core-js 2014-12-27 17:01:06 +11:00
Sebastian McKenzie
0b232ed228 add api opts.ast === false test 2014-12-27 17:00:58 +11:00
Sebastian McKenzie
9053e0dedf ignore bin tests under instanbul 2014-12-27 17:00:46 +11:00
Sebastian McKenzie
873e820210 add unknown module formatter test 2014-12-27 17:00:38 +11:00
Sebastian McKenzie
27bb08eadf add amd module name test 2014-12-27 17:00:27 +11:00
Sebastian McKenzie
bea903c69f add modules remap tests 2014-12-27 17:00:20 +11:00
Sebastian McKenzie
198a9c6ead nicer local exports remapping in default module formatter 2014-12-27 16:59:57 +11:00
Sebastian McKenzie
9c92679053 fix polyfill regenerator runtime path 2014-12-27 16:59:39 +11:00
Sebastian McKenzie
87d2bdadeb remove user transformers 2014-12-27 16:59:19 +11:00
Sebastian McKenzie
fa71f2a7f9 Merge branch 'core-js' into 2.0.0
Conflicts:
	lib/6to5/polyfill.js
2014-12-25 14:27:29 +11:00
Sebastian McKenzie
66e7134335 revert strict equals after #329 2014-12-23 16:11:15 +11:00
Sebastian McKenzie
99a1cf08f9 Merge pull request #329 from chicoxyzzy/fix_jshint_errors_2.0.0
fix jsHint errors in branch 2.0.0
2014-12-23 16:08:34 +11:00
chico
5de9c22452 fix jsHint errors in branch 2.0.0 2014-12-23 06:23:16 +03:00
Sebastian McKenzie
694a8dc456 rename helper functions to be more reflective of what they do 2014-12-22 23:23:59 +11:00
Sebastian McKenzie
2df1ca3971 properly freeze tagged template literal object #328 2014-12-22 22:07:45 +11:00
Sebastian McKenzie
6c7cdc9b7c update 2.0.0 changelog 2014-12-22 22:04:42 +11:00
Sebastian McKenzie
52b1d055ac fix regenerator/recast/ast-types monkey patch 2014-12-22 21:58:35 +11:00
Sebastian McKenzie
2a316bf362 move default parameters to after destructuring for param destructuring 2014-12-22 21:38:11 +11:00
Sebastian McKenzie
26ce0b8c8b switch to regenerator/runtime 2014-12-22 21:37:40 +11:00
Sebastian McKenzie
275c4cc34e add note about node/browserify polyfill usage 2014-12-22 21:37:32 +11:00
Sebastian McKenzie
bc914e6f23 freeze tagged template literal object - fixes #328 2014-12-22 21:36:59 +11:00
Sebastian McKenzie
4ea425ac7b remove ParenthesizedExpression 2014-12-22 21:36:33 +11:00
Sebastian McKenzie
bd255257f1 switch to vanilla regenerator 2014-12-22 21:34:09 +11:00
Sebastian McKenzie
41f072d112 clarify es5 and add getters/setters in IE 8<= to caveats fixes #314 2014-12-19 01:11:48 +11:00
Sebastian McKenzie
2a4c8e8423 add note about sourcemaps and 6to5/register 2014-12-18 16:30:49 +11:00
Sebastian McKenzie
122705bdaf remove custom regenerator runtime from dist 2014-12-18 16:30:33 +11:00
Sebastian McKenzie
f84e0ba640 add if statement to class super constructor call 2014-12-18 16:30:23 +11:00
Sebastian McKenzie
64216ec384 change generators/async functions to reference regenerator runtime rather than the polyfill 2014-12-18 16:30:14 +11:00
Sebastian McKenzie
a948928973 add roadrunner dependency 2014-12-18 16:29:20 +11:00
Sebastian McKenzie
5ab891b39d make first node in a class body inherit class comments 2014-12-18 16:28:13 +11:00
Sebastian McKenzie
2a742b5fac add in todo for a better t.isReferenced 2014-12-18 16:28:00 +11:00
Sebastian McKenzie
cd6b678b51 add support for exportdeclarations to constants 2014-12-18 16:27:50 +11:00
Sebastian McKenzie
c290a008b2 add --cache option to 6to5-node 2014-12-18 16:27:30 +11:00
Sebastian McKenzie
e8f0c8e8a4 Merge branch '2.0.0' of github.com:6to5/6to5 into 2.0.0 2014-12-18 01:10:28 +11:00
Sebastian McKenzie
22eb8edf41 support other operators in abstract reference assignment expression - fixes #311 2014-12-18 01:09:51 +11:00
Sebastian McKenzie
a3eb8900a9 add if super check to constructor default 2014-12-18 01:09:24 +11:00
Sebastian McKenzie
bf74f5a634 Merge pull request #310 from Dashed/patch-1
Clarify usage of 6to5 in node with harmony flag.
2014-12-18 00:25:44 +11:00
Alberto Leal
98e9a45f63 Rephrasing again.
Clarified by @sebmck on gitter.
2014-12-17 08:23:02 -05:00
Alberto Leal
1d91a758b4 Rephrasing 2014-12-17 08:19:47 -05:00
Alberto Leal
b94b4b335b Clarify usage of 6to5 in node with harmony flag. 2014-12-17 04:18:53 -05:00
Douglas Duteil
104b1f4c9b feat(system-module): rewrite 2014-12-17 02:36:47 +01:00
Sebastian McKenzie
00c95f6a94 Merge pull request #302 from raine/patch-1
Update differences.md
2014-12-16 09:37:22 +11:00
Raine Virta
f14dc60934 Update differences.md
fix typo
2014-12-16 00:36:18 +02:00
Sebastian McKenzie
2fc8010034 move jshint to normal dependencies 2014-12-16 08:08:14 +11:00
Sebastian McKenzie
882ed48438 fix a catch param property identifier incorrectly being replaced when exploding statements in generators - fixes #301 2014-12-16 08:08:06 +11:00
Sebastian McKenzie
49578fe223 fix let variable declaration hoisting bug. All let variable declarators now have a default initializer of undefined unless they're the left of a ForIn or ForOf 2014-12-16 08:07:46 +11:00
Sebastian McKenzie
01bdb7efdc fix export and import specifier getIds and add support for computed properties to isReferenced 2014-12-16 08:07:18 +11:00
Sebastian McKenzie
fc7fc384c9 add declaration/reference support to scope 2014-12-16 08:06:56 +11:00
Sebastian McKenzie
bd78e3ed4d add end/start user transformers 2014-12-16 08:06:38 +11:00
Sebastian McKenzie
1f990f4030 fFix module formatter parsing bug where literals were being converted to identifiers 2014-12-16 08:06:25 +11:00
Sebastian McKenzie
d8e4a4a776 add module changes to 2.0.0 changelog 2014-12-15 22:36:10 +11:00
Sebastian McKenzie
473b6d6a91 more microoptimizations 2014-12-15 22:35:58 +11:00
Sebastian McKenzie
3d975da530 remove reference to regenerator runtime and say that the explicit polyfill is required 2014-12-15 22:35:41 +11:00
Sebastian McKenzie
1a4110e0a1 categorise differences and elaborate on why they're significant 2014-12-15 22:35:25 +11:00
Sebastian McKenzie
a03d491ac6 microoptimize module formatters, change method names to a new API, and add support for exporting multiple variable declarators - fixes #299 2014-12-15 22:34:49 +11:00
Sebastian McKenzie
e01e010577 add 2.0.0 changelog 2014-12-15 18:53:50 +11:00
Sebastian McKenzie
132ac00ec7 Merge pull request #298 from Dashed/patch-2
Clarify usage in node env
2014-12-15 16:35:54 +11:00
Alberto Leal
1673f78ab5 Clarify usage in node env 2014-12-15 00:35:17 -05:00
Sebastian McKenzie
76b8a06e90 Merge branch 'master' into 2.0.0 2014-12-15 16:35:15 +11:00
Sebastian McKenzie
711f84c826 Merge pull request #297 from Dashed/patch-1
Clarify polyfill usage in node env
2014-12-15 16:34:55 +11:00
Alberto Leal
4b4ff007e9 Clarify polyfill usage in node env 2014-12-15 00:34:14 -05:00
Sebastian McKenzie
e31e68cae3 use types.isSpecifierDefault in amd modules formatter 2014-12-15 14:16:34 +11:00
Sebastian McKenzie
778b4e3a27 remove commonStrict module formatter 2014-12-15 14:16:18 +11:00
Sebastian McKenzie
6011db7ae1 Merge branch 'master' into 2.0.0 2014-12-15 14:02:04 +11:00
Sebastian McKenzie
363b1631f5 switch to core-js from es6-symbol and es6-shim
Conflicts:
	lib/6to5/polyfill.js
2014-12-15 14:00:41 +11:00
Sebastian McKenzie
01286ebd5b add custom regenerator runtime to build process 2014-12-15 14:00:14 +11:00
Sebastian McKenzie
fe918a3535 add async generator functions to docs 2014-12-15 14:00:04 +11:00
Sebastian McKenzie
2fb6c7820c microoptimizations 2014-12-15 13:59:54 +11:00
Sebastian McKenzie
e7cbbefc11 Merge pull request #296 from caseywebdev/fix-295
Fix incorrect object reference in #295
2014-12-15 13:58:34 +11:00
Casey Foster
f4fdc3adc6 Fix incorrect object reference in #295 2014-12-14 20:57:32 -06:00
Sebastian McKenzie
2cd49b08ec add async generator functions to docs 2014-12-15 13:56:22 +11:00
Sebastian McKenzie
1b16ff3a0b Revert "switch to core-js from es6-symbol and es6-shim"
This reverts commit 37b2e747d5.
2014-12-15 13:54:45 +11:00
Sebastian McKenzie
b7c298a0ee Merge pull request #295 from caseywebdev/amd-umd-interop-require
Add interop require support for AMD and UMD
2014-12-15 13:48:59 +11:00
Casey Foster
5da4397392 Add interop require support for AMD and UMD 2014-12-14 20:44:38 -06:00
Sebastian McKenzie
ea5954121e disable es6-transpiler 2014-12-14 23:58:42 +11:00
Sebastian McKenzie
37b2e747d5 switch to core-js from es6-symbol and es6-shim 2014-12-14 23:58:31 +11:00
Sebastian McKenzie
3dd6eb1202 update acorn-6to5 2014-12-14 14:53:00 +11:00
Sebastian McKenzie
319ed09407 remove string includes polyfill 2014-12-14 14:49:48 +11:00
Sebastian McKenzie
77f9596682 update classes tests to work with new _extends method 2014-12-14 14:49:37 +11:00
Sebastian McKenzie
00cb90541a add support for experimental private abstract references syntax - closes #291 2014-12-14 14:49:25 +11:00
Sebastian McKenzie
d26f441a5c support falsy and null super classes - fixes #284 2014-12-14 12:19:24 +11:00
Sebastian McKenzie
11fc7cd0ce rename 6to5-browserify to 6to5ify 2014-12-14 12:18:33 +11:00
Sebastian McKenzie
c38428c536 make react transformer first 2014-12-14 12:18:14 +11:00
Sebastian McKenzie
bf40849e35 make ensureProto methods non-enumerable 2014-12-14 12:18:03 +11:00
Sebastian McKenzie
194fb77b9c add WithStatement buider keys 2014-12-14 12:17:28 +11:00
Sebastian McKenzie
ceb8e812b6 expose transformers and types 2014-12-14 12:17:16 +11:00
Sebastian McKenzie
3a261a5e05 add kexec to optionalDependencies 2014-12-13 18:02:26 +11:00
Sebastian McKenzie
4c1ad04b2c fix wrong variable name for bin/6to5-node kexec catch 2014-12-13 17:56:17 +11:00
Sebastian McKenzie
0d9e6aca67 Merge pull request #289 from monsanto/kexec
run _6to5-node using execvp() if available
2014-12-13 17:53:55 +11:00
Christopher Monsanto
aac6303696 run _6to5-node using execvp() if available 2014-12-13 01:53:36 -05:00
Sebastian McKenzie
833a4900da remove IIFE on class declarations #288 2014-12-13 17:33:35 +11:00
Sebastian McKenzie
525169460a add back parentheses generator option 2014-12-13 17:32:58 +11:00
Sebastian McKenzie
13785bddb0 escape illegal js but valid json unicode characters - fixes #247 2014-12-13 14:14:47 +11:00
Sebastian McKenzie
84332da399 document format options 2014-12-13 12:52:31 +11:00
Sebastian McKenzie
aae7d8190b fix up tests to work with the new method binding operator 2014-12-13 12:40:43 +11:00
Sebastian McKenzie
03dcc335d8 Merge branch 'master' into 2.0.0
Conflicts:
	CHANGELOG.md
2014-12-13 12:20:02 +11:00
Sebastian McKenzie
2267344471 use # operator instead of : for playground method binding to remove ambiguous syntax 2014-12-13 04:37:00 +11:00
Sebastian McKenzie
593e4ca670 remove useless GeneratorFunction aliasing causing issues #283 2014-12-12 12:14:24 +11:00
Sebastian McKenzie
e563783a1e add gratipay to readme 2014-12-12 12:14:07 +11:00
Sebastian McKenzie
615425c808 fix linting errors 2014-12-12 12:14:02 +11:00
Sebastian McKenzie
55e2010311 comment out broken esnext 2014-12-11 23:12:15 +11:00
Sebastian McKenzie
74f40c2824 fix generator rest parameters 2014-12-11 11:02:55 +11:00
Sebastian McKenzie
c26ce1c114 abstract away astRun from transformer 2014-12-11 10:14:08 +11:00
Sebastian McKenzie
2537768772 inherit comments in modules transformer - fixes #280 2014-12-11 10:13:40 +11:00
Sebastian McKenzie
8af05634fa fix rest parameters on arrow functions 2014-12-11 10:10:07 +11:00
Sebastian McKenzie
74614e712e make rest parameters work inside of aliasFunction 2014-12-11 09:52:50 +11:00
Sebastian McKenzie
ad923cf8fa add playground support to 6to5-node 2014-12-11 09:52:29 +11:00
Sebastian McKenzie
c7d69b2f92 block scope constants 2014-12-10 23:49:13 +11:00
Sebastian McKenzie
2a0b63f3bb better symbol iterator check in regenerator runtime 2014-12-10 23:28:50 +11:00
Sebastian McKenzie
01934b6960 fix default import generation 2014-12-10 23:18:23 +11:00
Sebastian McKenzie
8ffd2e843f fix fromAst not passing ast to transform 2014-12-10 22:34:58 +11:00
Sebastian McKenzie
6d68b3da4d fix fromAst usage 2014-12-10 21:54:54 +11:00
Sebastian McKenzie
79b4207b44 upgrade acorn-6to5 2014-12-10 21:54:43 +11:00
Sebastian McKenzie
30a90d2554 fix hash bang support 2014-12-10 21:54:38 +11:00
Sebastian McKenzie
bac8758369 remove other commonInterop reference 2014-12-10 21:37:07 +11:00
Sebastian McKenzie
d00faf4a72 remove commonInterop option from register 2014-12-10 21:33:30 +11:00
Sebastian McKenzie
b986a4e482 expose ast transformer - fixes #263 2014-12-10 21:31:27 +11:00
Sebastian McKenzie
f11f364d2c add _aliasFunction to generator comprehension container - fixes #278 2014-12-10 21:28:49 +11:00
Sebastian McKenzie
c4a0f62eef add global symbol registry to polyfill 2014-12-10 21:12:01 +11:00
Sebastian McKenzie
072fff0f4c clean up system modules formatter 2014-12-10 21:11:43 +11:00
Sebastian McKenzie
59b81b389a Fix up checkLoop method comment 2014-12-10 21:11:26 +11:00
Sebastian McKenzie
4a439857d2 make mutators enumerable 2014-12-10 21:11:13 +11:00
Sebastian McKenzie
187f7ba01e Remove regenerator finished generator error 2014-12-10 21:10:59 +11:00
Sebastian McKenzie
e6da342e8b add a "spec" transformer namespace for transformers that nicen up code and make it well, more spec compliant 2014-12-10 21:09:58 +11:00
Sebastian McKenzie
1c22c608a9 make bin/6to5-node usage more inline with node 2014-12-10 21:09:09 +11:00
Sebastian McKenzie
8e96130bc0 rename common to commonStrict and commonInterop to common 2014-12-10 21:08:54 +11:00
Sebastian McKenzie
0f47814b41 separate experimental page in docs 2014-12-10 21:08:00 +11:00
Sebastian McKenzie
b32d56a168 remove 6to5-node filenames test 2014-12-09 23:32:25 +11:00
Sebastian McKenzie
5f26a0c5cc update modules tests 2014-12-09 23:28:07 +11:00
Sebastian McKenzie
2245bbc6c4 make bin/6to5-node more node bin compliant 2014-12-09 23:18:54 +11:00
Sebastian McKenzie
b8d61f1528 update github urls and regroup plugins 2014-12-09 23:18:54 +11:00
Sebastian McKenzie
e97e916b5c module export variable declaration initializer default - fixes #264 2014-12-09 23:18:54 +11:00
Sebastian McKenzie
b688154aee reformat CHANGELOG 2014-12-09 23:18:54 +11:00
Sebastian McKenzie
ccb56fe33f Merge pull request #271 from es128/patch-1
Simplify chokidar event handler
2014-12-09 09:57:12 +11:00
Elan Shanker
5e67dfbd9e Ensure only file events are acted upon 2014-12-08 17:55:54 -05:00
Elan Shanker
6f6d9bd5a8 Simplify chokidar event handler 2014-12-08 17:17:31 -05:00
Sebastian McKenzie
61b9c28ce6 update plugins to reflect 6to5 org migrations 2014-12-08 12:11:39 +11:00
Sebastian McKenzie
d11d0d3216 split up plugins into sections and change some community plugin urls to official ones 2014-12-07 22:00:31 +11:00
Sebastian McKenzie
bd876f7a4d fix starting file newlines 2014-12-07 22:00:30 +11:00
Sebastian McKenzie
f9f48620de remove unused test transformation whitespace option 2014-12-07 22:00:30 +11:00
Sebastian McKenzie
ce9a82c194 add docs for ast and code option 2014-12-07 22:00:30 +11:00
Sebastian McKenzie
24f6dfa8e2 Merge pull request #262 from josh/comment-before-newlines
Fix whitespace before comments
2014-12-07 21:11:48 +11:00
Joshua Peek
f592f95a68 Subtract one if line already ends with "{\n" 2014-12-07 02:06:54 -08:00
Joshua Peek
2e0cd0f349 Add tests for newlines before comments 2014-12-07 02:06:41 -08:00
Sebastian McKenzie
e17d5bdb13 fix comments test in property name shorthand 2014-12-07 11:46:59 +11:00
Sebastian McKenzie
c1c22ed5f7 fix duplicate comments on property key shorthands - fixes #234 2014-12-07 11:43:51 +11:00
Sebastian McKenzie
bf07f54e57 add note about inline functions to docs/differences 2014-12-07 11:31:08 +11:00
Sebastian McKenzie
eef0344cb2 fix comments-only rendering 2014-12-07 11:30:50 +11:00
Sebastian McKenzie
88a85c0ca8 fix files only containg comments not being output - fixes #259 2014-12-07 11:20:43 +11:00
Sebastian McKenzie
302e6f4caa Merge pull request #257 from thejameskyle/readme-center
Center everything in README
2014-12-07 10:55:43 +11:00
James Kyle
36c16a0227 Center everything in README 2014-12-06 15:33:17 -08:00
299 changed files with 2596 additions and 4249 deletions

View File

@@ -1,3 +1,3 @@
node_modules
test
lib/6to5/templates
lib/6to5/transformation/templates

View File

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

View File

@@ -2,6 +2,77 @@
Gaps between patch versions are faulty/broken releases.
## 2.2.0
* Make `system` module formatter modules anonymous by default.
* Fix duplicate comments being output, breaking code.
## 2.1.0
* Add `cache` option to register hook.
* Update `core-js`.
* Fix starting newline not being added on case statements.
* Fix destructuring `VariableDeclaration`s not inside `BlockStatement`s and `Program`.
## 2.0.4
* Avoid being greedy when destructuring array iterables.
## 2.0.3
* Hoist function declarations in system module formatter for circular references.
* Hoist default function declarations in umd and amd module formatters for circular references.
## 2.0.2
* Inherit comments in `for-of` transformer.
* Remove `interopRequire` from `system` module formatter.
## 2.0.1
* Remap `UpdateExpression` module export binding.
* Fix automatic closure on `PrivateDeclaration` in classes.
## 2.0.0
* Make string literal generation only escapes unicode that it has to.
* Internal code generation format options have been exposed.
* Change playground method binding operator from `:` to `#` removing ambiguous syntax with terns.
* Fix rest parameters in async and generator functions.
* Export/import declarations replace by the modules transformer now inherit comments.
* Added playground flag to `6to5-node`.
* `6to5-node` now behaves the same as `node`.
* `6to5-node` now uses `kexec` to become the forked process to correctly propagate signals on unix.
* Constants are now block scoped.
* Exposed ast transformer.
* Merged `commonInterop` and `common` module formatters.
* Fix generator comprehensions not inheriting `arguments`, `this` etc.
* Object and class mutator shorthand are now enumerable.
* Remove regenerator `Generator has already finished` error which isn't spec-compliant.
* Expose internal `spec` transformers that nicen up code output.
* Add export variable declaration default initializers.
* Propagate export declaration reassignments.
* Add initializer default to block scoped variable declarations within a loop.
* Flow type support.
* Make async/await contextual keywords.
* Allow `yield`ing of non-objects.
* Class declarations now lack an IIFE.
* Support falsy and `null` super classes.
* Add support for experimental abstract references `private` declarations.
* Leave out IIFE for class declarations.
* Switched to [core-js](https://github.com/zloirock/core-js) from [es6-symbol](https://github.com/medikoo/es6-symbol) and [es6-shim](https://github.com/paulmillr/es6-shim/) for built-in polyfill.
* `amd` and `umd` module formatters now behave the same as `common` with `interopRequire`.
* Micro-optimizations to boost performance by 200%.
* Rename module formatter methods `import` to `importDeclaration` and `export` to `exportDeclaration`.
* Support multiple declarators in export variable declarations.
* Freeze tagged template literal object.
* Remove inlined `regenerator` fork.
* Remove `ParenthesizedExpression`.
* Rename `object-spread` helper to `object-without-properties`.
* Rename `class-props` helper to `prototype-properties`.
* Rename `extends` helper to `inherits`.
* Completely rewritten `system` module formatter.
## 1.15.0
* Don't alias `GeneratorFunction` and check the name which causes minifiers to remove the name and throw an error later on when we check if it's set.

View File

@@ -3,6 +3,10 @@
</p>
<p align="center">
<a href="https://gratipay.com/sebmck">
<img alt="Gratipay" src="https://img.shields.io/gratipay/sebmck.svg?style=flat">
</a>
<a href="https://travis-ci.org/6to5/6to5">
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&amp;label=travis">
</a>
@@ -24,7 +28,11 @@
</a>
</p>
**6to5** turns ES6+ code into vanilla ES5, so you can use next generation features **today.**
<p align="center">
<strong>6to5</strong> turns ES6+ code into vanilla ES5, so you can use next generation features <strong>today.</strong>
</p>
For more information view the [documentation](https://6to5.github.io). For
support visit the [gitter room](https://gitter.im/6to5/6to5).
<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>.
</p>

View File

@@ -2,9 +2,9 @@ Error.stackTraceLimit = Infinity;
var jsTrans = require("jstransform");
var traceur = require("traceur");
var es6tr = require("es6-transpiler");
//var es6tr = require("es6-transpiler");
var es6now = require("es6now");
var esnext = require("esnext");
//var esnext = require("esnext");
var to5 = require("../lib/6to5");
//var uglify = require("uglify-js");
@@ -56,12 +56,12 @@ var compilers = {
}
},
esnext: {
/*esnext: {
runtime: readResolve("esnext/node_modules/regenerator/runtime.js") || readResolve("regenerator/runtime.js"),
compile: function (code) {
return esnext.compile(code).code;
}
},
},*/
es6now: {
runtime: readResolve("es6now/runtime/ES6.js"),
@@ -70,13 +70,13 @@ var compilers = {
}
},
"es6-transpiler": {
/*"es6-transpiler": {
compile: function (code) {
var result = es6tr.run({ src: code });
if (result.errors.length) throw new Error(result.join("; "));
return result.src;
}
},
},*/
jstransform: {
compile: function (code) {

View File

@@ -5,7 +5,6 @@
* when found, before invoking the "real" _6to5-node(1) executable.
*/
var spawn = require("child_process").spawn;
var args = ["--harmony", __dirname + "/_6to5-node"];
process.argv.slice(2).forEach(function(arg){
@@ -49,13 +48,21 @@ process.argv.slice(2).forEach(function(arg){
}
});
var proc = spawn(process.argv[0], args, { stdio: "inherit" });
proc.on("exit", function (code, signal) {
process.on("exit", function () {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
try {
var kexec = require("kexec");
kexec(process.argv[0], args);
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") throw err;
var child_process = require("child_process");
var proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
proc.on("exit", function (code, signal) {
process.on("exit", function () {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
})
});
});
}

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env node
var runtime = require("../lib/6to5/runtime");
var runtime = require("../lib/6to5/runtime-generator");
console.log(runtime(process.argv[2]));

View File

@@ -113,16 +113,14 @@ module.exports = function (commander, filenames) {
walk();
if (commander.watch) {
var watcher = chokidar.watch(filenames, {
chokidar.watch(filenames, {
persistent: true,
ignoreInitial: true
});
_.each(["add", "change", "unlink"], function (type) {
watcher.on(type, function (filename) {
}).on("all", function (type, filename) {
if (type === "add" || type === "change" || type === "unlink" ) {
console.log(type, filename);
walk();
});
}
});
}
};

View File

@@ -20,7 +20,8 @@ commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NO
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("-a, --amd-module-ids", "Insert module id in AMD modules", false);
commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0
commander.option("-m, --module-ids", "Insert module id in modules", false);
commander.on("--help", function(){
var outKeys = function (title, obj) {
@@ -89,9 +90,9 @@ if (errors.length) {
exports.opts = {
sourceMapName: commander.outFile,
amdModuleIds: commander.amdModuleIds,
experimental: commander.experimental,
playground: commander.playground,
moduleIds: commander.amdModuleIds || commander.moduleIds,
blacklist: commander.blacklist,
whitelist: commander.whitelist,
sourceMap: commander.sourceMaps || commander.sourceMapsInline,

View File

@@ -1,12 +1,14 @@
#!/usr/bin/env node
var commander = require("commander");
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 roadrunner = require("roadrunner");
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");
commander.option("-e, --eval [script]", "Evaluate script");
commander.option("-p, --print", "Evaluate script and print result");
@@ -14,28 +16,33 @@ commander.option("-i, --ignore [regex]", "Ignore all files that match this regex
commander.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
commander.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
commander.option("-g, --playground", "Enable playground support");
commander.option("-c, --cache", "Cache compiled files and require paths");
var pkg = require("../package.json");
commander.version(pkg.version);
commander.usage("[options] [ -e script | script.js ] [arguments]");
commander.parse(process.argv);
if (commander.cache) roadrunner.load();
//
to5.register({
experimental: commander.experimental,
extensions: commander.extensions,
ignore: commander.ignore
playground: commander.playground,
ignore: commander.ignore,
cache: commander.cache && roadrunner.get("6to5")
});
//
var _eval = function (code, filename) {
code = to5.transform(code, {
modules: "commonInterop",
filename: filename,
blacklist: ["useStrict"],
experimental: commander.experimental
experimental: commander.experimental,
playground: commander.playground
}).code;
return vm.runInThisContext(code, filename);
};
@@ -44,21 +51,34 @@ if (commander.eval) {
var result = _eval(commander.eval, "eval");
if (commander.print) console.log(result);
} else {
var filenames = commander.args;
if (commander.args.length) {
// slice all arguments up to the first filename since they're 6to5 args that we handle
var args = process.argv.slice(2);
if (filenames.length) {
_.each(filenames, function (filename) {
if (!util.isAbsolute(filename)) {
filename = path.join(process.cwd(), filename);
var i = 0;
_.each(args, function (arg, i2) {
if (arg[0] !== "-") {
i = i2;
return false;
}
require(require.resolve(filename));
});
args = args.slice(i);
// make the filename absolute
var filename = args[0]
if (!util.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
// add back on node and concat the sliced args
process.argv = ["node"].concat(args);
Module.runMain();
} else {
replStart();
}
}
if (commander.cache) roadrunner.save();
function replStart() {
repl.start({
prompt: "> ",

View File

@@ -2,22 +2,31 @@
In order for certain features to work they require certain polyfills. You can
satisfy **all** 6to5 feature requirements by using the included
[polyfill](polyfill.md). You may alternatively selectively include what you need:
[polyfill](polyfill.md).
| Feature | Requirements |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Abstract References | [experimental](usage.md#experimental), `Symbol` |
| Array destructuring | `Array.isArray`, `Array.from` |
| Async functions, Generators | [experimental](usage.md#experimental), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
| Comprehensions | [experimental](usage.md#experimental), `Array.isArray`, `Array.from` |
| For Of | `Symbol`, `prototype[Symbol.iterator]` |
| Object spread/rest | [experimental](usage.md#experimental), `Object.assign` |
| Spread | `Array.isArray`, `Array.from` |
You may alternatively selectively include what you need:
## Classes
| Feature | Requirements |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| Abstract References | [experimental](experimental.md), `Symbol` |
| Array destructuring | `Array.isArray`, `Array.from` |
| Async functions, Generators | [experimental](experimental.md), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
| Comprehensions | [experimental](experimental.md), `Array.isArray`, `Array.from` |
| For Of | `Symbol`, `prototype[Symbol.iterator]` |
| Object spread/rest | [experimental](experimental.md), `Object.assign` |
| Spread | `Array.isArray`, `Array.from` |
Built-in classes such as `Date`, `Array` and `DOM` cannot be subclassed due to
limitations in ES5 implementations.
## ES5
Since 6to5 assumes that your code will be ran in an ES5 environment it uses ES5
functions. So if you're using an environment that has limited or no support for
ES5 such as lower versions of IE then using the
[es5-shim](https://github.com/es-shims/es5-shim) along with the
[6to5 polyfill](polyfill.md) will add support for these methods.
## Internet Explorer
### Classes (9 and below)
If you're inheriting from a class then static properties are inherited from it
via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto),
@@ -39,3 +48,12 @@ class Bar extends Foo {
}
}
```
## Getters/setters (8 and below)
In IE8 `Object.defineProperty` can only be used on DOM objects. This is
unfortunate as it's required to set getters and setters. Due to this if
you plan on supporting IE8 or below then the user of getters and setters
isn't recommended.
Reference: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).

View File

@@ -1,6 +1,8 @@
# Differences
## Philosophy
There are three main points that separate 6to5 from all other transpilers.
### Readable code
The fundamental concept behind 6to5 is that the generated code must be close as
possible to the original, retaining all the same formatting and readability.
@@ -51,7 +53,27 @@ As you can tell, it's not very pretty, unreadable even. Instead of mapping
directly to a runtime, like other transpilers, 6to5 maps directly to the
equivalent ES5.
Sometimes there are little things that 6to5 needs
Sometimes there are little inline functions that 6to5 needs. These are
placed at the top of your file much like coffee-script does. If these
are bother you then you can use the [optional runtime](optional-runtime.md).
We promise that these inline functions will never be significant and will
always be used as little as possible.
### Static analysis
6to5 uses a lot of static analysis to simplify code as much as possible.
Not many other transpilers do this, and those that do don't do it nearly
as much as 6to5. This process is pretty intensive but it leads to higher
quality code.
### Spec compliancy
6to5 prides itself on
[spec compliancy](https://kangax.github.io/compat-table/es6/). We have
excellent support for edgecases, something that many other transpilers
suffer from, including Traceur. When you use 6to5 you can be confident
that when you turn it off and use your code in a full ES6 environment
**it'll just work**.
## Comparison to other transpilers
@@ -62,40 +84,44 @@ Sometimes there are little things that 6to5 needs
| Source maps | ✓ | ✓ | ✓ | ✓ | | ✓ |
| No compiler global pollution | ✓ | | ✓ | ✓ | | ✓ |
| Optional runtime | ✓ | | ✓ | | | ✓ |
| Browser support | ✓ | ✓ | | ✓ | | |
| Browser compiler | ✓ | ✓ | | ✓ | | |
### Language Support
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
| ---------------------------- | ----- | ------- | -------------- | ------ | ------ | ----------- |
| Abstract references | ✓ | | | | | |
| Array comprehension | ✓ | ✓ | ✓ | | | |
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Async functions | ✓ | ✓ | | ✓ | | |
| Classes | ✓ | ✓ | | | | |
| Computed property names | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Constants | ✓ | ✓ | ✓ | | | |
| Default parameters | ✓ | ✓ | ✓ | | | |
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Exponentiation operator | ✓ | ✓ | | | | |
| For-of | ✓ | ✓ | | | | |
| Generators | ✓ | | | | | |
| Generator comprehension | ✓ | ✓ | | | | |
| Let scoping | ✓ | ✓ | | | | |
| Modules | ✓ | ✓ | | | | |
| Object rest/spread | ✓ | | | | | |
| Property method assignment | ✓ | ✓ | ✓ | | | |
| Property name shorthand | ✓ | ✓ | | ✓ | ✓ | ✓ |
| Rest parameters | ✓ | | | | | ✓ |
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Unicode regex | ✓ | ✓ | ✓ | | | |
| | 6to5 | Traceur | es6-transpiler | esnext | es6now | jstransform |
| ---------------------------- | ---- | ------- | -------------- | ------ | ------ | ----------- |
| Abstract references | ✓ | | | | | |
| Array comprehension | ✓ | ✓ | ✓ | | | |
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Async functions | ✓ | ✓ | | ✓ | | |
| Async generator functions | ✓ | ✓ | | | | |
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Computed property names | ✓ | ✓ | ✓ | | | |
| Constants | ✓ | ✓ | ✓ | | | |
| Default parameters | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Destructuring | ✓ | ✓ | | | | |
| Exponentiation operator | ✓ | ✓ | | | | |
| Flow types | ✓ | | | | | |
| For-of | ✓ | ✓ | | | | |
| Generators | ✓ | ✓ | | | | |
| Generator comprehension | ✓ | ✓ | | | | |
| JSX | ✓ | | | | | |
| Let scoping | ✓ | ✓ | ✓ | | | |
| Modules | ✓ | ✓ | | | ✓ | |
| Object rest/spread | ✓ | | | | | ✓ |
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Rest parameters | ✓ | ✓ | ✓ | | | |
| React | ✓ | | | | | |
| Spread | ✓ | ✓ | ✓ | ✓ | ✓ | |
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Unicode regex | ✓ | ✓ | ✓ | | | |
### [Traceur](https://github.com/google/traceur-compiler)
Traceur requires quite a bulky runtime (~75KB) and produces quite verbose code.
While this can be trimmed down by selectively building the runtime, it's an
unneccesary step when a large runtime can be eliminated entirely.
unnecessary step when a large runtime can be eliminated entirely.
### [es6now](https://github.com/zenparsing/es6now)

8
doc/experimental.md Normal file
View File

@@ -0,0 +1,8 @@
## Experimental
6to5 also has experimental support for ES7 proposals. You can enable this with
the `experimental: true` option when using the [Node API](#node) or
`--experimental` when using the [CLI](#cli).
**WARNING:** These proposals are subject to change so use with
**extreme caution**.

View File

@@ -1,6 +1,6 @@
# Features
## Abstract references ([experimental](usage.md#experimental)) ([spec](https://github.com/zenparsing/es-abstract-refs))
## Abstract references ([experimental](experimental.md)) ([spec](https://github.com/zenparsing/es-abstract-refs))
```javascript
foo::bar;
@@ -8,7 +8,7 @@ foo::bar = baz;
delete foo::bar;
```
## Array comprehensions ([experimental](usage.md#experimental))
## Array comprehensions ([experimental](experimental.md))
```javascript
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
@@ -39,7 +39,7 @@ var bob = {
};
```
## Async functions ([experimental](usage.md#experimental)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait))
## Async functions ([experimental](experimental.md)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait))
```javascript
async function chainAnimationsAsync(elem, animations) {
@@ -49,6 +49,12 @@ async function chainAnimationsAsync(elem, animations) {
}
```
## Async generator functions ([experimental](experimental.md)) ([spec](https://github.com/jhusain/asyncgenerator))
```javascript
```
## Classes
```javascript
@@ -130,7 +136,7 @@ var [a] = [];
a === undefined;
```
## Exponentiation operator ([experimental](usage.md#experimental)) ([spec](https://github.com/rwaldron/exponentiation-operator))
## Exponentiation operator ([experimental](experimental.md)) ([spec](https://github.com/rwaldron/exponentiation-operator))
```javascript
var a = 2;
@@ -167,7 +173,7 @@ for (var n of fibonacci()) {
}
```
## Generator comprehensions ([experimental](usage.md#experimental))
## Generator comprehensions ([experimental](experimental.md))
```javascript
var nums = [1, 2, 3, 4, 5, 6];
@@ -208,7 +214,7 @@ export default test;
0o767 === 503; // true
```
## Object spread/rest ([experimental](usage.md#experimental)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread))
## Object spread/rest ([experimental](experimental.md)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread))
```javascript
var n = { x, y, ...z };

View File

@@ -35,23 +35,24 @@ And it doesn't end here! To see all the ways you can use 6to5, check out the
## [Features](features.md)
- [Abstract references](features.md#abstract-references) ([experimental](usage.md#experimental))
- [Array comprehension](features.md#array-comprehension) ([experimental](usage.md#experimental))
- [Async functions](features.md#async-functions) ([experimental](usage.md#experimental))
- [Abstract references](features.md#abstract-references) ([experimental](experimental.md))
- [Array comprehension](features.md#array-comprehension) ([experimental](experimental.md))
- [Async functions](features.md#async-functions) ([experimental](experimental.md))
- [Async generator functions](features.md#async-generator-functions) ([experimental](experimental.md))
- [Arrow functions](features.md#arrow-functions)
- [Classes](features.md#classes)
- [Computed property names](features.md#computed-property-names)
- [Constants](features.md#constants)
- [Default parameters](features.md#default-parameters)
- [Destructuring](features.md#destructuring)
- [Exponentiation operator](features.md#exponentiation-operator) ([experimental](usage.md#experimental))
- [Exponentiation operator](features.md#exponentiation-operator) ([experimental](experimental.md))
- [For-of](features.md#for-of)
- [Generators](features.md#generators)
- [Generator comprehension](features.md#generator-comprehension) ([experimental](usage.md#experimental))
- [Generator comprehension](features.md#generator-comprehension) ([experimental](experimental.md))
- [Let scoping](features.md#let-scoping)
- [Modules](features.md#modules)
- [Numeric literals](features.md#numeric-literals)
- [Object Rest/Spread](features.md#object-rest-spread) ([experimental](usage.md#experimental))
- [Object Rest/Spread](features.md#object-rest-spread) ([experimental](experimental.md))
- [Property method assignment](features.md#property-method-assignment)
- [Property name shorthand](features.md#property-name-shorthand)
- [React/JSX](react.md)

View File

@@ -19,12 +19,11 @@ to5.transform('import "foo";', { modules: "common" });
* [AMD](#amd)
* [Common (Default)](#common-default)
* [Common Interop](#common-interop)
* [Ignore](#ignore)
* [System](#system)
* [UMD](#umd)
### Common (Default)
### Common
```sh
$ 6to5 --modules common
@@ -33,6 +32,11 @@ $ 6to5 --modules common
**In**
```javascript
export default test;
export {test};
export var test = 5;
import "foo";
import foo from "foo";
@@ -40,95 +44,30 @@ import * as foo from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
export {test};
export var test = 5;
export default test;
```
**Out**
```javascript
require("foo");
"use strict";
var foo = require("foo").default;
var foo = require("foo");
var bar = require("foo").bar;
var bar = require("foo").foo;
exports.test = test;
var test = 5; exports.test = test;
exports.default = test;
```
### Common interop
```sh
$ 6to5 --modules commonInterop
```
**In**
```javascript
import "foo";
import foo from "foo";
import * as foo from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
export {test};
export var test = 5;
export default test;
```
**Out**
```javascript
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
require("foo");
var foo = _interopRequire(require("foo"));
var foo = require("foo");
var bar = require("foo").bar;
var bar = require("foo").foo;
exports = module.exports = test;
exports.test = test;
var test = exports.test = 5;
exports["default"] = test;
```
require("foo");
#### module.exports behaviour
var foo = _interopRequire(require("foo"));
If there exist no other non-default `export`s then `default exports` are
exported as `module.exports` instead of `exports.default`.
var foo = require("foo");
**In**
```javascript
export default function foo() {
}
```
**Out**
```javascript
module.exports = foo;
function foo() {
}
var bar = require("foo").bar;
var bar = require("foo").foo;
```
### AMD
@@ -151,9 +90,14 @@ export function bar() {
```javascript
define(["exports", "foo"], function (exports, _foo) {
exports.bar = bar;
"use strict";
var foo = _foo.default;
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
exports.bar = bar;
var foo = _interopRequire(_foo);
function bar() {
return foo("foobar");
@@ -192,10 +136,15 @@ export function bar() {
} else if (typeof exports !== "undefined") {
factory(exports, require("foo"));
}
})(function (exports) {
exports.bar = bar;
})(function (exports, _foo) {
"use strict";
var foo = _foo.default;
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
exports.bar = bar;
var foo = _interopRequire(_foo);
function bar() {
return foo("foobar");
@@ -288,7 +237,7 @@ ModuleFormatter.prototype.transform = function (ast) {
// feel free to modify this however
};
ModuleFormatter.prototype.import = function (node, nodes) {
ModuleFormatter.prototype.importDeclaration = function (node, nodes) {
// node is an ImportDeclaration
};
@@ -297,7 +246,7 @@ ModuleFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
// node is an ImportDeclaration
};
ModuleFormatter.prototype.export = function (node, nodes) {
ModuleFormatter.prototype.exportDeclaration = function (node, nodes) {
// node is an ExportDeclaration
};

View File

@@ -12,7 +12,7 @@ Playground is a proving ground for **possible** ES7 proposals.
to5.transform("code", { playground: true });
```
**NOTE:** Enabling `playground` also enables [experimental support](usage.md#experimental).
**NOTE:** Enabling `playground` also enables [experimental support](experimental.md).
## Features
@@ -52,11 +52,11 @@ if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
### Method binding
```javascript
var fn = obj:method;
var fn = obj:method("foob");
var fn = obj#method;
var fn = obj#method("foob");
["foo", "bar"].map(:toUpperCase); // ["FOO", "BAR"]
[1.1234, 23.53245, 3].map(:toFixed(2)); // ["1.12", "23.53", "3.00"]
["foo", "bar"].map(#toUpperCase); // ["FOO", "BAR"]
[1.1234, 23.53245, 3].map(#toFixed(2)); // ["1.12", "23.53", "3.00"]
```
equivalent to:

View File

@@ -1,18 +1,33 @@
# Plugins
- [Broccoli](https://github.com/very-geek/broccoli-6to5-transpiler)
- [Browserify](https://github.com/6to5/6to5-browserify)
- [Brunch](https://github.com/es128/6to5-brunch)
- [Duo](https://github.com/bdo-labs/duo6to5)
- [Connect](https://github.com/6to5/6to5-connect)
- [Gobble](https://github.com/gobblejs/gobble-6to5)
- [Gulp](https://github.com/sindresorhus/gulp-6to5)
- [Grunt](https://github.com/sindresorhus/grunt-6to5)
## Build systems
- [Broccoli](https://github.com/6to5/broccoli-6to5-transpiler)
- [Browserify](https://github.com/6to5/6to5ify)
- [Brunch](https://github.com/6to5/6to5-brunch)
- [Duo](https://github.com/6to5/duo6to5)
- [Gobble](https://github.com/6to5/gobble-6to5)
- [Gulp](https://github.com/6to5/gulp-6to5)
- [Grunt](https://github.com/6to5/grunt-6to5)
- [Sprockets](https://github.com/josh/sprockets-es6) or via [Browserify](https://github.com/6to5/6to5-rails)
- [webpack](https://github.com/6to5/6to5-loader)
## Integrations
- [Isparta](https://github.com/douglasduteil/isparta) - Code coverage with `karma` and `instanbul` using 6to5
- [Jade](https://github.com/Apoxx/jade-6to5)
- [Jest](https://github.com/6to5/6to5-jest)
- [JSXHint](https://github.com/STRML/JSXHint) - A wrapper around JSHint to allow linting of JSX files
- [Karma](https://github.com/shuhei/karma-6to5-preprocessor)
## Bridges
- [Ruby](https://github.com/6to5/6to5-ruby)
## Testing
- [Jest](https://github.com/6to5/6to5-jest)
- [Karma](https://github.com/6to5/karma-6to5-preprocessor)
- [Mocha](https://github.com/6to5/6to5-mocha)
- [Rails](https://github.com/josh/sprockets-es6) or via [browserify-rails](https://github.com/6to5/6to5-rails)
- [webpack](https://github.com/Couto/6to5-loader)
## Misc
- [Connect](https://github.com/6to5/6to5-connect)
- [Jade](https://github.com/6to5/jade-6to5)

View File

@@ -1,16 +1,15 @@
# Polyfill
6to5 includes a polyfill that includes the
[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and the
[es6-shim](https://github.com/paulmillr/es6-shim) and
[es6-symbol](https://github.com/medikoo/es6-symbol) polyfills.
6to5 includes a polyfill that includes a custom
[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and
[core.js](https://github.com/zloirock/core-js).
This will emulate a full ES6 environment. This polyfill is automatically loaded
when using [6to5-node](usage.md#node).
when using [6to5-node](usage.md#node) and [6to5/register](usage.md#register-hook).
## Usage
### Node
### Node/Browserify
You need to include the polyfill require at the top the **entry point** to your
application.
@@ -19,9 +18,17 @@ application.
require("6to5/polyfill");
```
Fortunately, this is automatically loaded when using:
```javascript
require("6to5/register");
```
### Browser
Available from the `browser-polyfill.js` file within the 6to5 directory of an
npm release. This needs to be included **before** all your compiled 6to5 code.
You can either prepend it to your compiled code or include it in a `<script>`
before it.
**NOTE:** Do not `require` this via browserify etc, use `6to5/polyfill`.

View File

@@ -95,6 +95,15 @@ to5.transformFile("filename.js", options, function (err, result) {
});
```
### to5.transform.fromAst(ast, [code], [opts])
```javascript
var result = to5.transform.fromAst(ast, "var a = 2;", opts);
result.code;
result.map;
result.ast;
```
#### Options
```javascript
@@ -143,23 +152,57 @@ to5.transformFile("filename.js", options, function (err, result) {
// Default: `sourceRoot` option.
moduleRoot: "my-app",
// If truthy, insert an explicit id for each defined AMD module.
// By default, AMD modules are anonymous.
// If truthy, insert an explicit id for each defined AMD/System module.
// By default, AMD/System modules are anonymous.
// Default: false
amdModuleIds: true,
moduleIds: true,
// Optionally replace all 6to5 helper declarations with a referenece to this
// variable. If set to `true` then the default namespace is used "to5Runtime".
// Default: false
runtime: true,
// Output comments in generated output
// Default: true
comments: false,
// Enable support for experimental ES7 features
// Default: false
experimental: true
experimental: true,
// Set this to `false` if you don't want the transformed AST in the returned
// result
// Default: true
ast: true,
// Set this to `false` if you don't want the transformed code in the returned
// result
// Default: true
code: true,
format: {
// Output comments in generated output
// Default: true
comments: true,
// Do not include superfluous whitespace characters and line terminators
// Default: false
compact: false,
indent: {
// Preserve parentheses in new expressions that have no arguments
// Default: true
parentheses: true,
// Adjust the indentation of multiline comments to keep asterisks vertically aligned
// Default: true
adjustMultilineComment: true,
// Indent string
// Default: " "
style: " ",
// Base indent level
// Default: 0
base: 0
}
}
}
```
@@ -167,7 +210,10 @@ to5.transformFile("filename.js", options, function (err, result) {
All subsequent files required by node with the extensions `.es6` and `.js` will
be transformed by 6to5. The polyfill specified in [Polyfill](polyfill.md) is
also required.
also required; but this is automatically loaded when using:
Source maps are automatically configured so if any errors a thrown then line
number info is mapped and you'll get the correct source location.
```javascript
require("6to5/register");
@@ -184,6 +230,8 @@ require("6to5/register")({
});
```
**NOTE:** Using 6to5-node or `require("6to5/register")`, 6to5 will check what features are available in the current environment and blacklists them if they're supported.
#### Options
```javascript
@@ -202,15 +250,10 @@ require("6to5/register")({
// This will remove the currently hooked extensions of .es6 and .js so you'll
// have to add them back if you want them to be used again.
extensions: [".js", ".es6"]
extensions: [".js", ".es6"],
// Enables `roadrunner` cache that will save to a `.roadrunner.json` file in your cwd
// Do not check this into git as it's user-specific
cache: true
});
```
## Experimental
6to5 also has experimental support for ES7 proposals. You can enable this with
the `experimental: true` option when using the [Node API](#node) or
`--experimental` when using the [CLI](#cli).
**WARNING:** These proposals are subject to change so use with
**extreme caution**.

View File

@@ -16,13 +16,14 @@ function File(opts) {
}
File.declarations = [
"extends",
"class-props",
"inherits",
"prototype-properties",
"apply-constructor",
"tagged-template-literal",
"interop-require",
"to-array",
"object-spread",
"sliced-to-array",
"object-without-properties",
"has-own",
"slice"
];
@@ -34,6 +35,7 @@ File.normaliseOptions = function (opts) {
experimental: false,
playground: false,
whitespace: true,
moduleIds: opts.amdModuleIds || false,
blacklist: [],
whitelist: [],
sourceMap: false,
@@ -82,13 +84,19 @@ File.normaliseOptions = function (opts) {
return opts;
};
File.prototype.toArray = function (node) {
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.addDeclaration("slice"), t.identifier("call")), [node]);
} else {
return t.callExpression(this.addDeclaration("to-array"), [node]);
var declarationName = "to-array";
var args = [node];
if (i) {
args.push(t.literal(i));
declarationName = "sliced-to-array";
}
return t.callExpression(this.addDeclaration(declarationName), args);
}
};
@@ -101,7 +109,7 @@ File.prototype.getModuleFormatter = function (type) {
}
if (!ModuleFormatter) {
throw new ReferenceError("unknown module formatter type " + type);
throw new ReferenceError("Unknown module formatter type " + JSON.stringify(type));
}
return new ModuleFormatter(this);
@@ -156,14 +164,16 @@ File.prototype.errorWithNode = function (node, msg, Error) {
return err;
};
File.prototype.parse = function (code) {
File.prototype.addCode = function (code) {
code = (code || "") + "";
this.code = code;
return this.parseShebang(code);
};
File.prototype.parse = function (code) {
var self = this;
this.code = code;
code = this.parseShebang(code);
code = this.addCode(code);
return util.parse(this.opts, code, function (tree) {
self.transform(tree);

View File

@@ -35,7 +35,7 @@ Buffer.prototype.dedent = function () {
};
Buffer.prototype.semicolon = function () {
if (this.format.semicolons) this.push(";");
this.push(";");
};
Buffer.prototype.ensureSemicolon = function () {
@@ -66,9 +66,7 @@ Buffer.prototype.removeLast = function (cha) {
};
Buffer.prototype.newline = function (i, removeLast) {
if (!this.buf) return;
if (this.format.compact) return;
if (this.endsWith("{\n")) return;
if (_.isBoolean(i)) {
removeLast = i;
@@ -76,6 +74,7 @@ Buffer.prototype.newline = function (i, removeLast) {
}
if (_.isNumber(i)) {
if (this.endsWith("{\n")) i--;
if (this.endsWith(util.repeat(i, "\n"))) return;
var self = this;
@@ -88,7 +87,10 @@ Buffer.prototype.newline = function (i, removeLast) {
if (removeLast && this.isLast("\n")) this.removeLast("\n");
this.removeLast(" ");
// remove whitespace if last character was a newline
this.buf = this.buf.replace(/\n +$/, "\n");
this._push("\n");
};

View File

@@ -37,7 +37,6 @@ _.each(Buffer.prototype, function (fn, key) {
CodeGenerator.normaliseOptions = function (opts) {
return _.merge({
parentheses: true,
semicolons: true,
comments: opts.comments == null || opts.comments,
compact: false,
indent: {
@@ -58,6 +57,7 @@ CodeGenerator.generators = {
methods: require("./generators/methods"),
modules: require("./generators/modules"),
types: require("./generators/types"),
flow: require("./generators/flow"),
base: require("./generators/base"),
jsx: require("./generators/jsx")
};
@@ -71,6 +71,12 @@ CodeGenerator.prototype.generate = function () {
this.print(ast);
var comments = [];
_.each(ast.comments, function (comment) {
if (!comment._displayed) comments.push(comment);
});
this._printComments(comments);
return {
map: this.map.get(),
code: this.buffer.get()
@@ -132,6 +138,9 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
var needs = n.needsWhitespaceAfter;
if (leading) needs = n.needsWhitespaceBefore;
lines += needs(node, parent);
// generated nodes can't add starting file whitespace
if (!self.buffer.get()) lines = 0;
}
self.newline(lines);
@@ -147,7 +156,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
// only compute if this node needs parens if our parent has been changed
// since acorn would've wrapped us in a ParanthesizedExpression
var needsParens = parent !== node._parent && n.needsParens(node, parent);
var needsParens = n.needsParens(node, parent);
if (needsParens) this.push("(");
this[node.type](node, this.buildPrint(node), parent);
@@ -259,6 +268,14 @@ CodeGenerator.prototype._printComments = function (comments) {
var self = this;
_.each(comments, function (comment) {
// find the original comment in the ast and set it as displayed
_.each(self.ast.comments, function (origComment) {
if (origComment.start === comment.start) {
origComment._displayed = true;
return false;
}
});
// whitespace before
self.newline(self.whitespace.getNewlinesBefore(comment));

View File

@@ -18,12 +18,6 @@ exports.UnaryExpression = function (node, print) {
print(node.argument);
};
exports.ParenthesizedExpression = function (node, print) {
this.push("(");
print(node.expression);
this.push(")");
};
exports.UpdateExpression = function (node, print) {
if (node.prefix) {
this.push(node.operator);
@@ -98,8 +92,11 @@ exports.AssignmentExpression = function (node, print) {
print(node.right);
};
var SCIENTIFIC_NOTATION = /e/i;
exports.MemberExpression = function (node, print) {
print(node.object);
var obj = node.object;
print(obj);
if (node.computed) {
this.push("[");
@@ -107,7 +104,7 @@ exports.MemberExpression = function (node, print) {
this.push("]");
} else {
// 5..toFixed(2);
if (t.isLiteral(node.object) && util.isInteger(node.object.value)) {
if (t.isLiteral(obj) && util.isInteger(obj.value) && !SCIENTIFIC_NOTATION.test(obj.value.toString())) {
this.push(".");
}

View File

@@ -0,0 +1,3 @@
exports.ClassProperty = function () {
throw new Error("not implemented");
};

View File

@@ -1,7 +1,14 @@
var t = require("../../types");
var _ = require("lodash");
exports.ImportSpecifier =
exports.ImportSpecifier = function (node, print) {
if (node.id && node.id.name === "default") {
print(node.name);
} else {
return exports.ExportSpecifier.apply(this, arguments);
}
};
exports.ExportSpecifier = function (node, print) {
print(node.id);
if (node.name) {
@@ -62,7 +69,9 @@ exports.ImportDeclaration = function (node, print) {
self.push(", ");
}
if (!spec.default && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) {
var isDefault = spec.id && spec.id.name === "default";
if (!isDefault && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) {
foundImportSpecifier = true;
self.push("{ ");
}

View File

@@ -146,7 +146,7 @@ exports.SwitchCase = function (node, print) {
this.push("default:");
}
this.space();
this.newline();
print.sequence(node.consequent, { indent: true });
};
@@ -164,6 +164,12 @@ exports.VariableDeclaration = function (node, print, parent) {
}
};
exports.PrivateDeclaration = function (node, print) {
this.push("private ");
print.join(node.declarations, { separator: ", " });
this.semicolon();
};
exports.VariableDeclarator = function (node, print) {
if (node.init) {
print(node.id);

View File

@@ -84,8 +84,8 @@ exports.Literal = function (node) {
if (type === "string") {
val = JSON.stringify(val);
// escape unicode characters
val = val.replace(/[\u007f-\uffff]/g, function (c) {
// escape illegal js but valid json unicode characters
val = val.replace(/[\u000A\u000D\u2028\u2029]/g, function (c) {
return "\\u" + ("0000" + c.charCodeAt(0).toString(16)).slice(-4);
});

View File

@@ -92,13 +92,6 @@ exports.YieldExpression = function (node, parent) {
t.isYieldExpression(parent);
};
exports.Literal = function (node, parent) {
// (1).valueOf()
if (_.isNumber(node.value) && t.isMemberExpression(parent) && parent.object === node) {
return true;
}
};
exports.ClassExpression = function (node, parent) {
return t.isExpressionStatement(parent);
};

View File

@@ -38,7 +38,11 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
}
});
return this.getNewlinesBetween(startToken, endToken);
if (endToken.type.type === "eof") {
return 1;
} else {
return this.getNewlinesBetween(startToken, endToken);
}
};
Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {

View File

@@ -3,7 +3,11 @@ var util = require("./util");
var fs = require("fs");
var _ = require("lodash");
exports.runtime = require("./runtime");
exports.Transformer = require("./transformation/transformer");
exports.types = require("./types");
exports.runtime = require("./runtime-generator");
exports.register = function (opts) {
var register = require("./register");

View File

@@ -1,22 +1,17 @@
var t = require("./types");
var _ = require("lodash");
// estraverse
var estraverse = require("estraverse");
_.extend(estraverse.VisitorKeys, t.VISITOR_KEYS);
// regenerator/recast/ast-types
var types = require("ast-types");
var def = types.Type.def;
var or = types.Type.or;
// Program wrapper
def("File")
.bases("Node")
.build("program")
.field("program", def("Program"));
// Non-standard Acorn type
def("ParenthesizedExpression")
.bases("Expression")
.build("expression")
.field("expression", def("Expression"));
// Acorn - Same as ImportNamespaceSpecifier but `id` is `name`
def("ImportBatchSpecifier")
.bases("Specifier")
@@ -30,6 +25,11 @@ def("VirtualPropertyExpression")
.field("object", def("Expression"))
.field("property", or(def("Identifier"), def("Expression")));
def("PrivateDeclaration")
.bases("Declaration")
.build("declarations")
.field("declarations", [def("Identifier")]);
// Playground
def("BindMemberExpression")
.bases("Expression")
@@ -45,6 +45,3 @@ def("BindFunctionExpression")
.field("arguments", [def("Expression")]);
types.finalize();
var estraverse = require("estraverse");
_.extend(estraverse.VisitorKeys, t.VISITOR_KEYS);

View File

@@ -1,37 +1,2 @@
/* jshint newcap: false */
var ensureSymbol = function (key) {
Symbol[key] = Symbol[key] || Symbol();
};
var ensureProto = function (Constructor, key, val) {
var proto = Constructor.prototype;
proto[key] = proto[key] || val;
};
//
if (typeof Symbol === "undefined") {
require("es6-symbol/implement");
}
require("es6-shim");
require("./transformation/transformers/es6-generators/runtime");
// Abstract references
ensureSymbol("referenceGet");
ensureSymbol("referenceSet");
ensureSymbol("referenceDelete");
ensureProto(Function, Symbol.referenceGet, function () { return this; });
ensureProto(Map, Symbol.referenceGet, Map.prototype.get);
ensureProto(Map, Symbol.referenceSet, Map.prototype.set);
ensureProto(Map, Symbol.referenceDelete, Map.prototype.delete);
if (global.WeakMap) {
ensureProto(WeakMap, Symbol.referenceGet, WeakMap.prototype.get);
ensureProto(WeakMap, Symbol.referenceSet, WeakMap.prototype.set);
ensureProto(WeakMap, Symbol.referenceDelete, WeakMap.prototype.delete);
}
require("core-js/shim");
require("regenerator/runtime");

View File

@@ -1,6 +1,7 @@
require("./polyfill");
var sourceMapSupport = require("source-map-support");
var roadrunner = require("roadrunner");
var util = require("./util");
var to5 = require("./index");
var fs = require("fs");
@@ -38,15 +39,22 @@ var blacklistTest = function (transformer, code) {
};
blacklistTest("arrayComprehension", "var foo = [for (foo of bar) foo * foo];");
//blacklistTest("generatorComprehension", "");
blacklistTest("generatorComprehension", "var foo = (for (foo of bar) foo * foo)");
blacklistTest("arrowFunctions", "var foo = x => x * x;");
blacklistTest("classes", "class Foo {}");
blacklistTest("computedPropertyNames", "var foo = { [foo]: bar };");
//blacklistTest("constants", "const foo = 0;");
blacklistTest("constants", function () {
try {
new Function("const foo = 'foo';\nfoo = 'wow';");
} catch (err) {
return; // constants are supported
}
throw new SyntaxError;
});
blacklistTest("defaultParamaters", "var foo = function (bar = 0) {};");
blacklistTest("destructuring", "var { x, y } = { x: 0, y: 0 };");
blacklistTest("forOf", "for (var foo of bar) {}");
blacklistTest("generators", "function* foo() {}");
blacklistTest("generators", "function* foo() {}\nasync function bar() {}"); // generators/async functions delegated to same transformer
blacklistTest("letScoping", "let foo = 0;");
blacklistTest("modules", 'import foo from "from";');
blacklistTest("propertyMethodAssignment", "{ get foo() {} }");
@@ -89,7 +97,6 @@ var loader = function (m, filename) {
whitelist: whitelist,
blacklist: blacklist,
sourceMap: true,
modules: "commonInterop",
ast: false
}, transformOpts));
@@ -131,6 +138,11 @@ module.exports = function (opts) {
if (opts.cache) cache = opts.cache;
if (opts.cache === false) cache = null;
if (opts.cache === true) {
roadrunner.load();
roadrunner.setup();
cache = roadrunner.get("6to5");
}
_.extend(transformOpts, opts);
};

View File

@@ -1,2 +0,0 @@
SUPER_NAME.apply(this, arguments);

View File

@@ -1,7 +0,0 @@
(function () {
var CLASS_NAME = function () {
};
return CLASS_NAME;
})()

View File

@@ -1 +0,0 @@
exports.VARIABLE_NAME = OBJECT.KEY;

View File

@@ -1 +0,0 @@
exports.default = VALUE;

View File

@@ -1 +0,0 @@
System.register(MODULE_NAME, MODULE_DEPENDENCIES, MODULE_BODY);

View File

@@ -1,4 +0,0 @@
(function (strings, raw) {
return Object.defineProperties(strings, { raw: { value: raw } });
});

View File

@@ -0,0 +1,204 @@
module.exports = DefaultFormatter;
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
function DefaultFormatter(file) {
this.file = file;
this.localExports = this.getLocalExports();
this.remapAssignments();
}
DefaultFormatter.prototype.getLocalExports = function () {
var localExports = {};
traverse(this.file.ast, {
enter: function (node) {
var declar = node && node.declaration;
if (t.isExportDeclaration(node) && declar && t.isStatement(declar)) {
_.extend(localExports, t.getIds(declar, true));
}
}
});
return localExports;
};
DefaultFormatter.prototype.remapExportAssignment = function (node) {
return t.assignmentExpression(
"=",
node.left,
t.assignmentExpression(
node.operator,
t.memberExpression(t.identifier("exports"), node.left),
node.right
)
);
};
DefaultFormatter.prototype.remapAssignments = function () {
var localExports = this.localExports;
var self = this;
var isLocalReference = function (node, scope) {
var name = node.name;
return t.isIdentifier(node) && localExports[name] && localExports[name] === scope.get(name, true);
};
traverse(this.file.ast, {
enter: function (node, parent, scope) {
if (t.isUpdateExpression(node) && isLocalReference(node.argument, scope)) {
this.stop();
// expand to long file assignment expression
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
// remap this assignment expression
var remapped = self.remapExportAssignment(assign);
// we don't need to change the result
if (t.isExpressionStatement(parent) || node.prefix) {
return remapped;
}
var nodes = [];
nodes.push(remapped);
var operator;
if (node.operator === "--") {
operator = "+";
} else { // "++"
operator = "-";
}
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
return t.sequenceExpression(nodes);
}
if (t.isAssignmentExpression(node) && isLocalReference(node.left, scope)) {
this.stop();
return self.remapExportAssignment(node);
}
}
});
};
DefaultFormatter.prototype.getModuleName = function () {
var opts = this.file.opts;
var filenameRelative = opts.filenameRelative;
var moduleName = "";
if (opts.moduleRoot) {
moduleName = opts.moduleRoot + "/";
}
if (!opts.filenameRelative) {
return moduleName + opts.filename.replace(/^\//, "");
}
if (opts.sourceRoot) {
// remove sourceRoot from filename
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
}
// remove extension
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
moduleName += filenameRelative;
return moduleName;
};
DefaultFormatter.prototype._pushStatement = function (ref, nodes) {
if (t.isClass(ref) || t.isFunction(ref)) {
if (ref.id) {
nodes.push(t.toStatement(ref));
ref = ref.id;
}
}
return ref;
};
DefaultFormatter.prototype._hoistExport = function (declar, assign) {
if (t.isFunctionDeclaration(declar)) {
assign._blockHoist = true;
}
return assign;
};
DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node, nodes) {
var inherits = false;
if (node.specifiers.length === 1) inherits = node;
if (node.source) {
if (t.isExportBatchSpecifier(specifier)) {
// export * from "foo";
nodes.push(this._exportsWildcard(getRef()));
} else {
// export { foo } from "test";
nodes.push(this._exportsAssign(
t.getSpecifierName(specifier),
t.memberExpression(getRef(), specifier.id)
));
}
} else {
// export { foo };
nodes.push(this._exportsAssign(t.getSpecifierName(specifier), specifier.id));
}
};
DefaultFormatter.prototype._exportsWildcard = function (objectIdentifier) {
return util.template("exports-wildcard", {
OBJECT: objectIdentifier
}, true);
};
DefaultFormatter.prototype._exportsAssign = function (id, init) {
return util.template("exports-assign", {
VALUE: init,
KEY: id
}, true);
};
DefaultFormatter.prototype.exportDeclaration = function (node, nodes) {
var declar = node.declaration;
var id = declar.id;
if (node.default) {
id = t.identifier("default");
}
var assign;
if (t.isVariableDeclaration(declar)) {
for (var i in declar.declarations) {
var decl = declar.declarations[i];
decl.init = this._exportsAssign(decl.id, decl.init).expression;
var newDeclar = t.variableDeclaration(declar.kind, [decl]);
if (i === "0") t.inherits(newDeclar, declar);
nodes.push(newDeclar);
}
} else {
var ref = declar;
if (t.isFunctionDeclaration(declar) || t.isClassDeclaration(declar)) {
ref = declar.id;
nodes.push(declar);
}
assign = this._exportsAssign(id, ref);
nodes.push(assign);
this._hoistExport(declar, assign);
}
};

View File

@@ -1,16 +1,28 @@
module.exports = AMDFormatter;
var CommonJSFormatter = require("./common");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
var DefaultFormatter = require("./_default");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
function AMDFormatter(file) {
this.file = file;
function AMDFormatter() {
DefaultFormatter.apply(this, arguments);
this.ids = {};
}
util.inherits(AMDFormatter, CommonJSFormatter);
util.inherits(AMDFormatter, DefaultFormatter);
AMDFormatter.prototype.buildDependencyLiterals = function () {
var names = [];
for (var name in this.ids) {
names.push(t.literal(name));
}
return names;
};
/**
* Wrap the entire body in a `define` wrapper.
*/
AMDFormatter.prototype.transform = function (ast) {
var program = ast.program;
@@ -18,10 +30,7 @@ AMDFormatter.prototype.transform = function (ast) {
// build an array of module names
var names = [t.literal("exports")];
_.each(this.ids, function (id, name) {
names.push(t.literal(name));
});
var names = [t.literal("exports")].concat(this.buildDependencyLiterals());
names = t.arrayExpression(names);
// build up define container
@@ -40,9 +49,14 @@ AMDFormatter.prototype.transform = function (ast) {
program.body = [t.expressionStatement(call)];
};
/**
* Get the AMD module name that we'll prepend to the wrapper
* to define this module
*/
AMDFormatter.prototype.getModuleName = function () {
if (this.file.opts.amdModuleIds) {
return CommonJSFormatter.prototype.getModuleName.apply(this, arguments);
if (this.file.opts.moduleIds) {
return DefaultFormatter.prototype.getModuleName.apply(this, arguments);
} else {
return null;
}
@@ -59,27 +73,22 @@ AMDFormatter.prototype._push = function (node) {
}
};
AMDFormatter.prototype.import = function (node) {
AMDFormatter.prototype.importDeclaration = function (node) {
this._push(node);
};
AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
var key = t.getSpecifierName(specifier);
var id = specifier.id;
// import foo from "foo";
if (specifier.default) {
id = t.identifier("default");
}
var ref;
var ref = this._push(node);
if (t.isImportBatchSpecifier(specifier)) {
// import * as bar from "foo";
ref = this._push(node);
} else {
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
// import foo from "foo";
ref = t.memberExpression(this._push(node), id, false);
ref = t.callExpression(this.file.addDeclaration("interop-require"), [ref]);
} else {
// import {foo} from "foo";
ref = t.memberExpression(ref, specifier.id, false);
}
nodes.push(t.variableDeclaration("var", [

View File

@@ -1,56 +0,0 @@
module.exports = CommonJSInteropFormatter;
var CommonJSFormatter = require("./common");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
function CommonJSInteropFormatter(file) {
CommonJSFormatter.apply(this, arguments);
var has = false;
_.each(file.ast.program.body, function (node) {
if (t.isExportDeclaration(node) && !node.default) has = true;
});
this.has = has;
}
util.inherits(CommonJSInteropFormatter, CommonJSFormatter);
CommonJSInteropFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
var variableName = t.getSpecifierName(specifier);
// import foo from "foo";
if (specifier.default) {
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(variableName,
t.callExpression(this.file.addDeclaration("interop-require"), [util.template("require", {
MODULE_NAME: node.source.raw
})])
)
]));
} else {
CommonJSFormatter.prototype.importSpecifier.apply(this, arguments);
}
};
CommonJSInteropFormatter.prototype.export = function (node, nodes) {
if (node.default && !this.has) {
var declar = node.declaration;
// module.exports = VALUE;
var assign = util.template("exports-default-module", {
VALUE: this._pushStatement(declar, nodes)
}, true);
// hoist to the top if this default is a function
nodes.push(this._hoistExport(declar, assign));
return;
}
CommonJSFormatter.prototype.export.apply(this, arguments);
};
CommonJSInteropFormatter.prototype.exportSpecifier = function () {
CommonJSFormatter.prototype.exportSpecifier.apply(this, arguments);
};

View File

@@ -1,161 +1,77 @@
module.exports = CommonJSFormatter;
var util = require("../../util");
var t = require("../../types");
var DefaultFormatter = require("./_default");
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
function CommonJSFormatter(file) {
this.file = file;
DefaultFormatter.apply(this, arguments);
var hasNonDefaultExports = false;
traverse(file.ast, {
enter: function (node) {
if (t.isExportDeclaration(node) && !node.default) hasNonDefaultExports = true;
}
});
this.hasNonDefaultExports = hasNonDefaultExports;
}
CommonJSFormatter.prototype.getModuleName = function () {
var opts = this.file.opts;
var filenameRelative = opts.filenameRelative;
var moduleName = "";
if (opts.moduleRoot) {
moduleName = opts.moduleRoot + "/";
}
if (!opts.filenameRelative) {
return moduleName + opts.filename.replace(/^\//, "");
}
if (opts.sourceRoot) {
// remove sourceRoot from filename
var sourceRootRegEx = new RegExp("^" + opts.sourceRoot + "\/?");
filenameRelative = filenameRelative.replace(sourceRootRegEx, "");
}
// remove extension
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
moduleName += filenameRelative;
return moduleName;
};
CommonJSFormatter.prototype.import = function (node, nodes) {
// import "foo";
nodes.push(util.template("require", {
//inherits: node,
MODULE_NAME: node.source.raw
}, true));
};
util.inherits(CommonJSFormatter, DefaultFormatter);
CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
var variableName = t.getSpecifierName(specifier);
// import foo from "foo";
if (specifier.default) {
specifier.id = t.identifier("default");
if (t.isSpecifierDefault(specifier)) {
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(variableName,
t.callExpression(this.file.addDeclaration("interop-require"), [util.template("require", {
MODULE_NAME: node.source
})])
)
]));
} else {
// import foo from "foo";
var templateName = "require-assign";
// import * as bar from "foo";
if (specifier.type !== "ImportBatchSpecifier") templateName += "-key";
nodes.push(util.template(templateName, {
VARIABLE_NAME: variableName,
MODULE_NAME: node.source,
KEY: specifier.id
}));
}
var templateName = "require-assign";
// import * as bar from "foo";
if (specifier.type !== "ImportBatchSpecifier") templateName += "-key";
nodes.push(util.template(templateName, {
//inherits: node.specifiers.length === 1 && node,
VARIABLE_NAME: variableName,
MODULE_NAME: node.source.raw,
KEY: specifier.id
}));
};
CommonJSFormatter.prototype._hoistExport = function (declar, assign) {
if (t.isFunctionDeclaration(declar)) {
assign._blockHoist = true;
}
return assign;
CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
// import "foo";
nodes.push(util.template("require", {
MODULE_NAME: node.source
}, true));
};
CommonJSFormatter.prototype._pushStatement = function (ref, nodes) {
if (t.isClass(ref) || t.isFunction(ref)) {
if (ref.id) {
nodes.push(t.toStatement(ref));
ref = ref.id;
}
}
return ref;
};
CommonJSFormatter.prototype.export = function (node, nodes) {
var declar = node.declaration;
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
if (node.default) {
nodes.push(util.template("exports-default", {
//inherits: node,
var declar = node.declaration;
// module.exports = VALUE;
var templateName = "exports-default-module";
// exports = module.exports = VALUE;
if (this.hasNonDefaultExports) templateName = "exports-default-module-override";
var assign = util.template(templateName, {
VALUE: this._pushStatement(declar, nodes)
}, true));
}, true);
// hoist to the top if this default is a function
nodes.push(this._hoistExport(declar, assign));
} else {
var assign;
if (t.isVariableDeclaration(declar)) {
var decl = declar.declarations[0];
if (decl.init) {
decl.init = util.template("exports-assign", {
//inherits: node,
VALUE: decl.init,
KEY: decl.id
});
}
nodes.push(declar);
} else {
assign = util.template("exports-assign", {
//inherits: node,
VALUE: declar.id,
KEY: declar.id
}, true);
nodes.push(t.toStatement(declar));
nodes.push(assign);
this._hoistExport(declar, assign);
}
}
};
CommonJSFormatter.prototype._exportSpecifier = function (getRef, specifier, node, nodes) {
var variableName = t.getSpecifierName(specifier);
var inherits = false;
if (node.specifiers.length === 1) inherits = node;
if (node.source) {
if (t.isExportBatchSpecifier(specifier)) {
// export * from "foo";
nodes.push(util.template("exports-wildcard", {
//inherits: inherits,
OBJECT: getRef()
}, true));
} else {
// export { foo } from "test";
nodes.push(util.template("exports-assign-key", {
//inherits: inherits,
VARIABLE_NAME: variableName.name,
OBJECT: getRef(),
KEY: specifier.id
}, true));
}
} else {
// export { foo };
nodes.push(util.template("exports-assign", {
//inherits: inherits,
VALUE: specifier.id,
KEY: variableName
}, true));
DefaultFormatter.prototype.exportDeclaration.apply(this, arguments);
}
};

View File

@@ -6,19 +6,13 @@ function IgnoreFormatter() {
}
IgnoreFormatter.prototype.import = function () {
};
IgnoreFormatter.prototype.importSpecifier = function () {
};
IgnoreFormatter.prototype.export = function (node, nodes) {
IgnoreFormatter.prototype.exportDeclaration = function (node, nodes) {
var declar = t.toStatement(node.declaration, true);
if (declar) nodes.push(t.inherits(declar, node));
};
IgnoreFormatter.prototype.importDeclaration =
IgnoreFormatter.prototype.importSpecifier =
IgnoreFormatter.prototype.exportSpecifier = function () {
};

View File

@@ -1,202 +1,102 @@
module.exports = SystemFormatter;
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
var SETTER_MODULE_NAMESPACE = t.identifier("m");
var DEFAULT_IDENTIFIER = t.identifier("default");
var NULL_SETTER = t.literal(null);
var AMDFormatter = require("./amd");
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
function SystemFormatter(file) {
this.exportedStatements = [];
this.importedModule = {};
this.exportIdentifier = file.generateUidIdentifier("export");
this.noInteropRequire = true;
this.exportIdentifier = file.generateUidIdentifier("export");
this.file = file;
AMDFormatter.apply(this, arguments);
}
util.inherits(SystemFormatter, AMDFormatter);
SystemFormatter.prototype._exportsWildcard = function (objectIdentifier) {
var leftIdentifier = t.identifier("i");
var valIdentifier = t.memberExpression(objectIdentifier, leftIdentifier, true);
var left = t.variableDeclaration("var", [
t.variableDeclarator(leftIdentifier)
]);
var right = objectIdentifier;
var block = t.blockStatement([
this.buildExportCall(leftIdentifier, valIdentifier)
]);
return t.forInStatement(left, right, block);
};
SystemFormatter.prototype._exportsAssign = function (id, init) {
return this.buildExportCall(t.literal(id.name), init, true);
};
SystemFormatter.prototype.remapExportAssignment = function (node) {
return this.buildExportCall(t.literal(node.left.name), node);
};
SystemFormatter.prototype.buildExportCall = function (id, init, isStatement) {
var call = t.callExpression(this.exportIdentifier, [id, init]);
if (isStatement) {
return t.expressionStatement(call);
} else {
return call;
}
};
SystemFormatter.prototype.buildRunnerSetters = function () {
return t.arrayExpression(_.map(this.ids, function (uid) {
var moduleIdentifier = t.identifier("m");
return t.functionExpression(null, [moduleIdentifier], t.blockStatement([
t.assignmentExpression("=", uid, moduleIdentifier)
]));
}));
};
SystemFormatter.prototype.transform = function (ast) {
var program = ast.program;
var body = program.body;
// extract the module name
var moduleName = this.file.opts.filename
.replace(/^.*\//, "").replace(/\..*$/, "");
var moduleName = this.getModuleName();
var moduleNameLiteral = t.literal(moduleName);
// build an array of module names
var dependencies = Object.keys(this.importedModule).map(t.literal);
var runner = util.template("system", {
MODULE_NAME: moduleNameLiteral,
MODULE_DEPENDENCIES: t.arrayExpression(this.buildDependencyLiterals()),
EXPORT_IDENTIFIER: this.exportIdentifier,
SETTERS: this.buildRunnerSetters(),
EXECUTE: t.functionExpression(null, [], t.blockStatement(program.body))
}, true);
// generate the __moduleName variable
var moduleNameVariableNode = t.variableDeclaration("var", [
t.variableDeclarator(
t.identifier("__moduleName"),
t.literal(moduleName)
)
]);
body.splice(1, 0, moduleNameVariableNode);
var handlerBody = runner.expression.arguments[2].body.body;
if (!moduleName) runner.expression.arguments.shift();
// generate an array of import variables
var returnStatement = handlerBody.pop();
var declaredSetters = _(this.importedModule)
.map()
.flatten()
.pluck("variableName")
.pluck("name")
.uniq()
.map(t.identifier)
.map(function (name) {
return t.variableDeclarator(name);
})
.value();
// hoist up function declarations for circular references
traverse(program, {
enter: function (node) {
if (t.isFunction(node)) this.stop();
if (declaredSetters.length) {
body.splice(2, 0, t.variableDeclaration("var", declaredSetters));
}
// generate the execute function expression
var executeFunctionExpression = t.functionExpression(
null, [], t.blockStatement(this.exportedStatements)
);
// generate the execute function expression
var settersArrayExpression = t.arrayExpression(this._buildSetters());
// generate the return statement
var moduleReturnStatement = t.returnStatement(t.objectExpression([
t.property("init", t.identifier("setters"), settersArrayExpression),
t.property("init", t.identifier("execute"), executeFunctionExpression)
]));
body.push(moduleReturnStatement);
// runner
var runner = util.template("register", {
MODULE_NAME: t.literal(moduleName),
MODULE_DEPENDENCIES: t.arrayExpression(dependencies),
MODULE_BODY: t.functionExpression(
null,
[this.exportIdentifier],
t.blockStatement(body)
)
});
program.body = [t.expressionStatement(runner)];
};
SystemFormatter.prototype._buildSetters = function () {
// generate setters array expression elements
return _.map(this.importedModule, function (specs) {
if (!specs.length) {
return NULL_SETTER;
}
var expressionStatements = _.map(specs, function (spec) {
var right = SETTER_MODULE_NAMESPACE;
if (!spec.isBatch) {
right = t.memberExpression(right, spec.key);
if (t.isFunctionDeclaration(node) || node._blockHoist) {
handlerBody.push(node);
this.remove();
}
return t.expressionStatement(
t.assignmentExpression("=", spec.variableName, right
)
);
});
return t.functionExpression(
null, [SETTER_MODULE_NAMESPACE], t.blockStatement(expressionStatements)
);
});
};
SystemFormatter.prototype.import = function (node) {
var MODULE_NAME = node.source.value;
this.importedModule[MODULE_NAME] = this.importedModule[MODULE_NAME] || [];
};
SystemFormatter.prototype.importSpecifier = function (specifier, node) {
var variableName = t.getSpecifierName(specifier);
// import foo from "foo";
if (specifier.default) {
specifier.id = DEFAULT_IDENTIFIER;
}
var MODULE_NAME = node.source.value;
this.importedModule[MODULE_NAME] = this.importedModule[MODULE_NAME] || [];
this.importedModule[MODULE_NAME].push({
variableName: variableName,
isBatch: specifier.type === "ImportBatchSpecifier",
key: specifier.id
});
};
SystemFormatter.prototype._export = function (name, identifier) {
this.exportedStatements.push(t.expressionStatement(
t.callExpression(this.exportIdentifier, [t.literal(name), identifier])
));
};
SystemFormatter.prototype.export = function (node, nodes) {
var declar = node.declaration;
var variableName, identifier;
if (node.default) {
// export default foo
variableName = DEFAULT_IDENTIFIER.name;
if (t.isClass(declar) || t.isFunction(declar)) {
if (!declar.id) {
declar.id = this.file.generateUidIdentifier("anonymous");
}
nodes.push(t.toStatement(declar));
declar = declar.id;
}
});
identifier = declar;
} else if (t.isVariableDeclaration(declar)) {
// export var foo
variableName = declar.declarations[0].id.name;
identifier = declar.declarations[0].id;
nodes.push(declar);
} else {
// export function foo () {}
variableName = declar.id.name;
identifier = declar.id;
nodes.push(declar);
if (!_.isEmpty(this.ids)) {
handlerBody.push(t.variableDeclaration("var", _.map(this.ids, function (uid) {
return t.variableDeclarator(uid);
})));
}
this._export(variableName, identifier);
};
SystemFormatter.prototype.exportSpecifier = function (specifier, node) {
var variableName = t.getSpecifierName(specifier);
if (node.source) {
if (t.isExportBatchSpecifier(specifier)) {
// export * from "foo";
var exportIdentifier = t.identifier("exports");
this.exportedStatements.push(
t.variableDeclaration("var", [
t.variableDeclarator(exportIdentifier, this.exportIdentifier)
])
);
this.exportedStatements.push(util.template("exports-wildcard", {
OBJECT: t.identifier(node.source.value)
}, true));
} else {
// export { foo } from "test";
this._export(variableName.name, t.memberExpression(
t.identifier(node.source.value),
specifier.id
));
}
} else {
// export { foo };
this._export(variableName.name, specifier.id);
}
handlerBody.push(returnStatement);
program.body = [runner];
};

View File

@@ -18,9 +18,9 @@ UMDFormatter.prototype.transform = function (ast) {
// build an array of module names
var names = [];
_.each(this.ids, function (id, name) {
for (var name in this.ids) {
names.push(t.literal(name));
});
}
// factory

View File

@@ -0,0 +1,3 @@
if (SUPER_NAME) {
SUPER_NAME.apply(this, arguments);
}

View File

@@ -0,0 +1 @@
exports = module.exports = VALUE;

View File

@@ -1,5 +1,5 @@
(function (child, parent) {
child.prototype = Object.create(parent.prototype, {
child.prototype = Object.create(parent && parent.prototype, {
constructor: {
value: child,
enumerable: false,
@@ -7,5 +7,5 @@
configurable: true
}
});
child.__proto__ = parent;
if (parent) child.__proto__ = parent;
})

View File

@@ -0,0 +1,12 @@
(function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
if (i && _arr.length === i) break;
}
return _arr;
}
});

View File

@@ -0,0 +1,6 @@
System.register(MODULE_NAME, MODULE_DEPENDENCIES, function (EXPORT_IDENTIFIER) {
return {
setters: SETTERS,
execute: EXECUTE
};
});

View File

@@ -0,0 +1,6 @@
(function (strings, raw) {
return Object.freeze(Object.defineProperties(strings, {
raw: { value: Object.freeze(raw) }
}));
});

View File

@@ -2,6 +2,7 @@ module.exports = transform;
var Transformer = require("./transformer");
var File = require("../file");
var util = require("../util");
var _ = require("lodash");
function transform(code, opts) {
@@ -9,31 +10,46 @@ function transform(code, opts) {
return file.parse(code);
}
transform.fromAst = function (ast, code, opts) {
ast = util.normaliseAst(ast);
var file = new File(opts);
file.addCode(code);
file.transform(ast);
return file.generate();
};
transform._ensureTransformerNames = function (type, keys) {
_.each(keys, function (key) {
for (var i in keys) {
var key = keys[i];
if (!_.has(transform.transformers, key)) {
throw new ReferenceError("unknown transformer " + key + " specified in " + type);
}
});
}
};
transform.transformers = {};
transform.moduleFormatters = {
common: require("./modules/common"),
commonInterop: require("./modules/common-interop"),
system: require("./modules/system"),
ignore: require("./modules/ignore"),
amd: require("./modules/amd"),
umd: require("./modules/umd")
common: require("./modules/common"),
system: require("./modules/system"),
ignore: require("./modules/ignore"),
amd: require("./modules/amd"),
umd: require("./modules/umd")
};
_.each({
// plyground
// spec
specBlockHoistFunctions: require("./transformers/spec-block-hoist-functions"),
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
specNoDuplicateProperties: require("./transformers/spec-no-duplicate-properties"),
// playground
methodBinding: require("./transformers/playground-method-binding"),
memoizationOperator: require("./transformers/playground-memoization-operator"),
objectGetterMemoization: require("./transformers/playground-object-getter-memoization"),
react: require("./transformers/react"),
modules: require("./transformers/es6-modules"),
propertyNameShorthand: require("./transformers/es6-property-name-shorthand"),
arrayComprehension: require("./transformers/es7-array-comprehension"),
@@ -48,28 +64,30 @@ _.each({
spread: require("./transformers/es6-spread"),
templateLiterals: require("./transformers/es6-template-literals"),
propertyMethodAssignment: require("./transformers/es5-property-method-assignment"),
defaultParameters: require("./transformers/es6-default-parameters"),
restParameters: require("./transformers/es6-rest-parameters"),
destructuring: require("./transformers/es6-destructuring"),
defaultParameters: require("./transformers/es6-default-parameters"),
forOf: require("./transformers/es6-for-of"),
unicodeRegex: require("./transformers/es6-unicode-regex"),
abstractReferences: require("./transformers/es7-abstract-references"),
react: require("./transformers/react"),
constants: require("./transformers/es6-constants"),
letScoping: require("./transformers/es6-let-scoping"),
generators: require("./transformers/es6-generators"),
_blockHoist: require("./transformers/_block-hoist"),
generators: require("./transformers/es6-generators"),
restParameters: require("./transformers/es6-rest-parameters"),
_declarations: require("./transformers/_declarations"),
// wrap up
_aliasFunctions: require("./transformers/_alias-functions"),
useStrict: require("./transformers/use-strict"),
_moduleFormatter: require("./transformers/_module-formatter"),
_propertyLiterals: require("./transformers/_property-literals"),
_memberExpressioLiterals: require("./transformers/_member-expression-literals"),
_moduleFormatter: require("./transformers/_module-formatter")
// spec
specPropertyLiterals: require("./transformers/spec-property-literals"),
specMemberExpressionLiterals: require("./transformers/spec-member-expression-literals")
}, function (transformer, key) {
transform.transformers[key] = new Transformer(key, transformer);
});

View File

@@ -4,8 +4,9 @@ var traverse = require("../traverse");
var t = require("../types");
var _ = require("lodash");
function Transformer(key, transformer) {
function Transformer(key, transformer, opts) {
this.transformer = Transformer.normalise(transformer);
this.opts = opts || {};
this.key = key;
}
@@ -18,37 +19,38 @@ Transformer.normalise = function (transformer) {
if (type[0] === "_") return;
if (_.isFunction(fns)) fns = { enter: fns };
transformer[type] = fns;
var aliases = t.FLIPPED_ALIAS_KEYS[type];
if (aliases) {
_.each(aliases, function (alias) {
transformer[alias] = fns;
});
}
});
return transformer;
};
Transformer.prototype.astRun = function (file, key) {
var transformer = this.transformer;
var ast = file.ast;
if (transformer.ast && transformer.ast[key]) {
transformer.ast[key](ast, file);
}
};
Transformer.prototype.transform = function (file) {
if (!this.canRun(file)) return;
var transformer = this.transformer;
var ast = file.ast;
var astRun = function (key) {
if (transformer.ast && transformer.ast[key]) {
transformer.ast[key](ast, file);
}
};
astRun("enter");
this.astRun(file, "enter");
var build = function (exit) {
return function (node, parent, scope) {
// add any node type aliases that exist
var types = [node.type].concat(t.ALIAS_KEYS[node.type] || []);
var fns = transformer.all;
_.each(types, function (type) {
fns = transformer[type] || fns;
});
// this transformer cannot deal with this node type
var fns = transformer[node.type];
if (!fns) return;
var fn = fns.enter;
@@ -64,20 +66,19 @@ Transformer.prototype.transform = function (file) {
exit: build(true)
});
astRun("exit");
this.astRun(file, "exit");
};
Transformer.prototype.canRun = function (file) {
var opts = file.opts;
var key = this.key;
if (key[0] === "_") return true;
var blacklist = opts.blacklist;
if (blacklist.length && _.contains(blacklist, key)) return false;
if (key[0] !== "_") {
var whitelist = opts.whitelist;
if (whitelist.length && !_.contains(whitelist, key)) return false;
}
var whitelist = opts.whitelist;
if (whitelist.length && !_.contains(whitelist, key)) return false;
return true;
};

View File

@@ -15,38 +15,42 @@ var go = function (getBody, node, file, scope) {
// traverse the function and find all alias functions so we can alias
// `arguments` and `this` if necessary
traverse(node, function (node) {
if (!node._aliasFunction) {
if (t.isFunction(node)) {
// stop traversal of this node as it'll be hit again by this transformer
return false;
} else {
return;
traverse(node, {
enter: function (node) {
if (!node._aliasFunction) {
if (t.isFunction(node)) {
// stop traversal of this node as it'll be hit again by this transformer
return false;
} else {
return;
}
}
// traverse all child nodes of this function and find `arguments` and `this`
traverse(node, {
enter: function (node, parent) {
if (t.isFunction(node) && !node._aliasFunction) {
return false;
}
if (node._ignoreAliasFunctions) return false;
var getId;
if (t.isIdentifier(node) && node.name === "arguments") {
getId = getArgumentsId;
} else if (t.isThisExpression(node)) {
getId = getThisId;
} else {
return;
}
if (t.isReferenced(node, parent)) return getId();
}
});
return false;
}
// traverse all child nodes of this function and find `arguments` and `this`
traverse(node, function (node, parent) {
if (t.isFunction(node) && !node._aliasFunction) {
return false;
}
if (node._ignoreAliasFunctions) return false;
var getId;
if (t.isIdentifier(node) && node.name === "arguments") {
getId = getArgumentsId;
} else if (t.isThisExpression(node)) {
getId = getThisId;
} else {
return;
}
if (t.isReferenced(node, parent)) return getId();
});
return false;
});
var body;

View File

@@ -1,12 +1,14 @@
var t = require("../../types");
var _ = require("lodash");
exports.BlockStatement =
exports.Program = function (node) {
var kinds = {};
var kind;
_.each(node._declarations, function (declar) {
var kind = declar.kind || "var";
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) {
@@ -15,9 +17,9 @@ exports.Program = function (node) {
} else {
node.body.unshift(t.variableDeclaration(kind, [declarNode]));
}
});
}
_.each(kinds, function (declars, kind) {
node.body.unshift(t.variableDeclaration(kind, declars));
});
for (kind in kinds) {
node.body.unshift(t.variableDeclaration(kind, kinds[kind]));
}
};

View File

@@ -1,5 +1,4 @@
var util = require("../../util");
var _ = require("lodash");
exports.Property = function (node) {
if (node.method) node.method = false;
@@ -7,9 +6,11 @@ exports.Property = function (node) {
exports.ObjectExpression = function (node, parent, file) {
var mutatorMap = {};
var hasAny = false;
node.properties = node.properties.filter(function (prop) {
if (prop.kind === "get" || prop.kind === "set") {
hasAny = true;
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.value);
return false;
} else {
@@ -17,7 +18,7 @@ exports.ObjectExpression = function (node, parent, file) {
}
});
if (_.isEmpty(mutatorMap)) return;
if (!hasAny) return;
var objId = util.getUid(parent, file);

View File

@@ -3,7 +3,7 @@ var t = require("../../types");
exports.ArrowFunctionExpression = function (node) {
t.ensureBlock(node);
node._aliasFunction = true;
node._aliasFunction = "arrow";
node.expression = false;
node.type = "FunctionExpression";

View File

@@ -1,27 +1,38 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
exports.ClassDeclaration = function (node, parent, file, scope) {
var built = new Class(node, file, scope).run();
var closure = true;
if (t.isProgram(parent) || t.isBlockStatement(parent)) {
closure = false;
}
var declar = t.variableDeclaration("let", [
t.variableDeclarator(node.id, built)
]);
t.inheritsComments(declar, node);
return declar;
var factory = new Class(node, file, scope, closure);
var newNode = factory.run();
if (factory.closure) {
if (closure) {
// declaration in an expression context...
// export default class Foo {}
scope.push({
kind: "var",
key: node.id.key,
id: node.id
});
return t.assignmentExpression("=", node.id, newNode);
} else {
// likely has a PrivateDeclaration etc
return t.variableDeclaration("let", [
t.variableDeclarator(node.id, newNode)
]);
}
} else {
return newNode;
}
};
exports.ClassExpression = function (node, parent, file, scope) {
return new Class(node, file, scope).run();
};
var getMemberExpressionObject = function (node) {
while (t.isMemberExpression(node)) {
node = node.object;
}
return node;
return new Class(node, file, scope, true).run();
};
/**
@@ -30,12 +41,17 @@ var getMemberExpressionObject = function (node) {
* @param {Node} node
* @param {File} file
* @param {Scope} scope
* @param {Boolean} closure
*/
function Class(node, file, scope) {
this.scope = scope;
this.node = node;
this.file = file;
function Class(node, file, scope, closure) {
this.closure = closure;
this.scope = scope;
this.node = node;
this.file = file;
this.hasInstanceMutators = false;
this.hasStaticMutators = false;
this.instanceMutatorMap = {};
this.staticMutatorMap = {};
@@ -51,50 +67,61 @@ function Class(node, file, scope) {
*/
Class.prototype.run = function () {
var superClassArgument = this.superName;
var superClassCallee = this.superName;
var superName = this.superName;
var className = this.className;
var file = this.file;
var superName = this.superName;
var className = this.className;
var file = this.file;
if (superName) {
if (t.isMemberExpression(superName)) {
superClassArgument = superClassCallee = getMemberExpressionObject(superName);
} else if (!t.isIdentifier(superName)) {
superClassArgument = superName;
superClassCallee = superName = file.generateUidIdentifier("ref", this.scope);
}
//
var body = this.body = [];
var constructor = t.functionExpression(null, [], t.blockStatement([]));
if (this.node.id) constructor.id = className;
this.constructor = constructor;
body.push(t.variableDeclaration("let", [
t.variableDeclarator(className, constructor)
]));
//
if (superName && t.isDynamic(superName)) {
// so we're only evaluating it once
var superRefName = "super";
if (className) superRefName = className.name + "Super";
var superRef = file.generateUidIdentifier(superRefName, this.scope);
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(superRef, superName)
]));
superName = superRef;
}
this.superName = superName;
var container = util.template("class", {
CLASS_NAME: className
});
var block = container.callee.expression.body;
var body = this.body = block.body;
var constructor = this.constructor = body[0].declarations[0].init;
if (this.node.id) constructor.id = className;
var returnStatement = body.pop();
//
if (superName) {
body.push(t.expressionStatement(t.callExpression(file.addDeclaration("extends"), [className, superName])));
container.arguments.push(superClassArgument);
container.callee.expression.params.push(superClassCallee);
body.push(t.expressionStatement(t.callExpression(file.addDeclaration("inherits"), [className, superName])));
}
this.buildBody();
if (body.length === 1) {
// only a constructor so no need for a closure container
return constructor;
t.inheritsComments(body[0], this.node);
if (this.closure) {
if (body.length === 1) {
// only a constructor so no need for a closure container
return constructor;
} else {
body.push(t.returnStatement(className));
return t.callExpression(
t.functionExpression(null, [], t.blockStatement(body)),
[]
);
}
} else {
body.push(returnStatement);
return container;
return body;
}
};
@@ -110,15 +137,21 @@ Class.prototype.buildBody = function () {
var body = this.body;
var self = this;
_.each(classBody, function (node) {
self.replaceInstanceSuperReferences(node);
for (var i in classBody) {
var node = classBody[i];
if (t.isMethodDefinition(node)) {
self.replaceInstanceSuperReferences(node);
if (node.key.name === "constructor") {
self.pushConstructor(node);
} else {
self.pushMethod(node);
if (node.key.name === "constructor") {
self.pushConstructor(node);
} else {
self.pushMethod(node);
}
} else if (t.isPrivateDeclaration(node)) {
self.closure = true;
body.unshift(node);
}
});
}
if (!this.hasConstructor && superName) {
constructor.body.body.push(util.template("class-super-constructor-call", {
@@ -129,7 +162,7 @@ Class.prototype.buildBody = function () {
var instanceProps;
var staticProps;
if (!_.isEmpty(this.instanceMutatorMap)) {
if (this.hasInstanceMutators) {
var protoId = util.template("prototype-identifier", {
CLASS_NAME: className
});
@@ -137,7 +170,7 @@ Class.prototype.buildBody = function () {
instanceProps = util.buildDefineProperties(this.instanceMutatorMap, protoId);
}
if (!_.isEmpty(this.staticMutatorMap)) {
if (this.hasStaticMutators) {
staticProps = util.buildDefineProperties(this.staticMutatorMap, className);
}
@@ -148,7 +181,7 @@ Class.prototype.buildBody = function () {
if (instanceProps) args.push(instanceProps);
body.push(t.expressionStatement(
t.callExpression(this.file.addDeclaration("class-props"), args)
t.callExpression(this.file.addDeclaration("prototype-properties"), args)
));
}
};
@@ -171,11 +204,18 @@ Class.prototype.pushMethod = function (node) {
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
methodName = t.memberExpression(className, methodName, node.computed);
this.body.push(t.expressionStatement(t.assignmentExpression("=", methodName, node.value)));
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
t.inheritsComments(expr, node);
this.body.push(expr);
} else {
// mutator
var mutatorMap = this.instanceMutatorMap;
if (node.static) mutatorMap = this.staticMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
util.pushMutatorMap(mutatorMap, methodName, kind, node);
}
};
@@ -232,17 +272,19 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
var method = methodNode.value;
var self = this;
traverse(method, function (node, parent) {
if (t.isIdentifier(node, { name: "super" })) {
return self.superIdentifier(methodNode, node, parent);
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
traverse(method, {
enter: function (node, parent) {
if (t.isIdentifier(node, { name: "super" })) {
return self.superIdentifier(methodNode, node, parent);
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
// super.test(); -> ClassName.prototype.MethodName.call(this);
callee.property = t.memberExpression(callee.property, t.identifier("call"));
node.arguments.unshift(t.thisExpression());
// super.test(); -> ClassName.prototype.MethodName.call(this);
callee.property = t.memberExpression(callee.property, t.identifier("call"));
node.arguments.unshift(t.thisExpression());
}
}
});
};
@@ -262,6 +304,7 @@ Class.prototype.pushConstructor = function (method) {
var fn = method.value;
this.hasConstructor = true;
t.inherits(construct, fn);
t.inheritsComments(construct, method);

View File

@@ -1,6 +1,5 @@
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
exports.ObjectExpression = function (node, parent, file) {
var hasComputed = false;
@@ -26,12 +25,13 @@ exports.ObjectExpression = function (node, parent, file) {
OBJECT: node
});
var containerCallee = container.callee.expression;
var containerCallee = container.callee;
var containerBody = containerCallee.body.body;
containerCallee._aliasFunction = true;
_.each(computed, function (prop) {
for (var i in computed) {
var prop = computed[i];
containerBody.unshift(
t.expressionStatement(
t.assignmentExpression(
@@ -41,7 +41,7 @@ exports.ObjectExpression = function (node, parent, file) {
)
)
);
});
}
return container;
};

View File

@@ -7,48 +7,76 @@ exports.BlockStatement =
exports.ForInStatement =
exports.ForOfStatement =
exports.ForStatement = function (node, parent, file) {
var hasConstants = false;
var constants = {};
var check = function (parent, names) {
_.each(names, function (nameNode, name) {
if (!_.has(constants, name)) return;
if (parent && t.isBlockStatement(parent) && parent !== constants[name]) return;
/**
* Check the results of `util.getIds` as `names` generated from a
* node against it's parent.
*/
var check = function (parent, names, scope) {
for (var name in names) {
var nameNode = names[name];
if (!_.has(constants, name)) continue;
if (parent && t.isBlockStatement(parent) && parent !== constants[name]) continue;
if (scope) {
var defined = scope.get(name);
if (defined && defined === nameNode) continue;
}
throw file.errorWithNode(nameNode, name + " is read-only");
});
}
};
var getIds = function (node) {
return t.getIds(node, true, ["MemberExpression"]);
};
/**
* Collect all constants in this scope.
*/
_.each(node.body, function (child, parent) {
if (child && t.isVariableDeclaration(child, { kind: "const" })) {
_.each(child.declarations, function (declar) {
_.each(getIds(declar), function (nameNode, name) {
if (t.isExportDeclaration(child)) {
child = child.declaration;
}
if (t.isVariableDeclaration(child, { kind: "const" })) {
for (var i in child.declarations) {
var declar = child.declarations[i];
var ids = getIds(declar);
for (var name in ids) {
var nameNode = ids[name];
var names = {};
names[name] = nameNode;
check(parent, names);
constants[name] = parent;
});
hasConstants = true;
}
declar._ignoreConstant = true;
});
}
child._ignoreConstant = true;
child.kind = "let";
}
});
if (_.isEmpty(constants)) return;
if (!hasConstants) return;
traverse(node, function (child, parent) {
if (child._ignoreConstant) return;
if (t.isVariableDeclaration(child)) return;
traverse(node, {
enter: function (child, parent, scope) {
if (child._ignoreConstant) return;
if (t.isVariableDeclaration(child)) return;
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
check(parent, getIds(child));
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
check(parent, getIds(child), scope);
}
}
});
};

View File

@@ -12,9 +12,12 @@ exports.Function = function (node, parent, file, scope) {
});
var iife = false;
var i;
var def;
_.each(node.defaults, function (def, i) {
if (!def) return;
for (i in node.defaults) {
def = node.defaults[i];
if (!def) continue;
var param = node.params[i];
@@ -24,7 +27,7 @@ exports.Function = function (node, parent, file, scope) {
var check = function (node, parent) {
if (!t.isIdentifier(node) || !t.isReferenced(node, parent)) return;
if (_.contains(ids, node.name)) {
if (ids.indexOf(node.name) >= 0) {
throw file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
}
@@ -34,26 +37,27 @@ exports.Function = function (node, parent, file, scope) {
};
check(def, node);
traverse(def, check);
traverse(def, { enter: check });
});
// we're accessing a variable that's already defined within this function
var has = scope.get(param.name);
if (has && !_.contains(node.params, has)) {
if (has && node.params.indexOf(has) < 0) {
iife = true;
}
});
}
var body = [];
_.each(node.defaults, function (def, i) {
if (!def) return;
for (i in node.defaults) {
def = node.defaults[i];
if (!def) continue;
body.push(util.template("if-undefined-set-to", {
VARIABLE: node.params[i],
DEFAULT: def
}, true));
});
}
if (iife) {
var container = t.functionExpression(null, [], node.body, node.generator);

View File

@@ -1,7 +1,6 @@
// TODO: Clean up
var t = require("../../types");
var _ = require("lodash");
var buildVariableAssign = function (opts, id, init) {
var op = opts.operator;
@@ -27,23 +26,26 @@ var push = function (opts, nodes, elem, parentId) {
};
var pushObjectPattern = function (opts, nodes, pattern, parentId) {
_.each(pattern.properties, function (prop, i) {
for (var i in pattern.properties) {
var prop = pattern.properties[i];
if (t.isSpreadProperty(prop)) {
// get all the keys that appear in this object before the current spread
var keys = [];
_.each(pattern.properties, function (prop2, i2) {
if (i2 >= i) return false;
if (t.isSpreadProperty(prop2)) return;
for (var i2 in pattern.properties) {
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(opts.file.addDeclaration("object-spread"), [parentId, keys]);
var value = t.callExpression(opts.file.addDeclaration("object-without-properties"), [parentId, keys]);
nodes.push(buildVariableAssign(opts, prop.argument, value));
} else {
var pattern2 = prop.value;
@@ -55,25 +57,42 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
nodes.push(buildVariableAssign(opts, pattern2, patternId2));
}
}
});
}
};
var pushArrayPattern = function (opts, nodes, pattern, parentId) {
if (!pattern.elements) return;
var i;
var hasSpreadElement = false;
for (i in pattern.elements) {
if (t.isSpreadElement(pattern.elements[i])) {
hasSpreadElement = true;
break;
}
}
var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
var _parentId = opts.file.generateUidIdentifier("ref", opts.scope);
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(_parentId, opts.file.toArray(parentId))
t.variableDeclarator(_parentId, toArray)
]));
parentId = _parentId;
_.each(pattern.elements, function (elem, i) {
if (!elem) return;
for (i in pattern.elements) {
var elem = pattern.elements[i];
if (!elem) continue;
i = +i;
var newPatternId;
if (t.isSpreadElement(elem)) {
newPatternId = opts.file.toArray(parentId);
if (+i > 0) {
if (i > 0) {
newPatternId = t.callExpression(t.memberExpression(newPatternId, t.identifier("slice")), [t.literal(i)]);
}
@@ -83,7 +102,7 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
}
push(opts, nodes, elem, newPatternId);
});
}
};
var pushPattern = function (opts) {
@@ -215,17 +234,22 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
if (t.isForInStatement(parent) || t.isForOfStatement(parent)) return;
var nodes = [];
var i;
var declar;
var hasPattern = false;
_.each(node.declarations, function (declar) {
for (i in node.declarations) {
declar = node.declarations[i];
if (t.isPattern(declar.id)) {
hasPattern = true;
return false;
break;
}
});
}
if (!hasPattern) return;
_.each(node.declarations, function (declar) {
for (i in node.declarations) {
declar = node.declarations[i];
var patternId = declar.init;
var pattern = declar.id;
var opts = {
@@ -241,12 +265,13 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
} else {
nodes.push(buildVariableAssign(opts, declar.id, declar.init));
}
});
}
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) {
var declar;
declar = null;
_.each(nodes, function (node) {
for (i in nodes) {
node = nodes[i];
declar = declar || t.variableDeclaration(node.kind, []);
if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) {
@@ -254,7 +279,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
}
declar.declarations = declar.declarations.concat(node.declarations);
});
}
return declar;
}

View File

@@ -24,6 +24,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
OBJECT: node.right
});
t.inheritsComments(node2, node);
t.ensureBlock(node);
var block = node2.body;

View File

@@ -0,0 +1 @@
module.exports = require("regenerator").transform;

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