Compare commits

...

203 Commits

Author SHA1 Message Date
Henry Zhu
c732f5e1d0 v7.0.0-alpha.7 2017-04-05 17:13:26 -04:00
Henry Zhu
9acbcccff8 update issue template [skip ci] (#5591) 2017-04-05 15:26:26 -04:00
Brian Ng
ae0681aa3f Merge pull request #5588 from babel/xtuc-patch-2
Update transform-es2015-modules-commonjs doc
2017-04-05 09:48:14 -05:00
Sven SAULEAU
beae0ff9ba docs: [skip ci] type in plugin's name 2017-04-05 16:43:56 +02:00
Henry Zhu
8f848b4b32 add individual polyfill files (#5584)
* add individual polyfill files

* rename files

* use preset-env for the script [skip ci]
2017-04-05 10:11:58 -04:00
Logan Smyth
d39400c9d5 Separate config/plugin loading from config processing. (#5563) 2017-04-04 14:48:48 -07:00
Logan Smyth
9155c613cb Change babel-register default ignore to cwd content. (#5583) 2017-04-04 14:47:49 -07:00
Daniel Tschinder
b2ced1d6bd Update babylon to latest beta (#5585) 2017-04-04 22:32:31 +02:00
Brian Ng
7ad697cd86 Merge pull request #5580 from loganfsmyth/fix-docs
Remove incorrect docs.
2017-04-04 08:56:47 -05:00
Alex Rattray
348cc5eeff Use raw value of JSXText and JSXAttribute (#5256) 2017-04-04 15:46:20 +02:00
Logan Smyth
5576a8942b Remove incorrect docs. 2017-04-03 21:13:00 -07:00
Logan Smyth
878a7c5fdb Add tests to test the plugin ordering. (#5571) 2017-03-31 18:52:58 -07:00
Logan Smyth
d3497348b8 Ensure that incremental builds work with 'gulp build'. (#5561) 2017-03-28 15:18:12 -07:00
Henry Zhu
4bf8e4d08d temp fix for watch, still recompiles all [skip ci] 2017-03-28 14:31:55 -04:00
Logan Smyth
0c2ac9d907 Use a standard .babelignore and babel-register. (#5555) 2017-03-27 21:16:09 -04:00
Henry Zhu
899daafcf4 Merge pull request #5551 from babel/fix
use latest babel-core
2017-03-27 18:00:11 -04:00
Logan Smyth
fa23b662c2 Add empty .babelrc for CLI tests. 2017-03-27 14:46:39 -07:00
Henry Zhu
3d74dc044f fix ci 2017-03-27 17:26:39 -04:00
Henry Zhu
67253c5d27 babelrc false to relevant files 2017-03-27 17:19:02 -04:00
Henry Zhu
7935dd6642 pass config 2017-03-27 16:44:42 -04:00
Henry Zhu
f3ef03abfd use caret for devDeps 2017-03-27 16:32:13 -04:00
Henry Zhu
75328ccc60 use latest babel-core 2017-03-27 16:24:13 -04:00
Henry Zhu
dea509377c v7.0.0-alpha.6 2017-03-27 15:09:36 -04:00
Henry Zhu
7262ad631f Merge pull request #5543 from babel/food
🐶 🍲
2017-03-27 15:00:23 -04:00
Kai Cataldo
1f2f63ccdf Fix: config lookup logic in babel-core (#5550)
This fixes a bug that was causing the config lookup to stop
when a package.json file was found even if it did not contain a
"babel" key.
2017-03-27 11:54:57 -07:00
Henry Zhu
1ada981077 run coverage on circle ci 2017-03-27 14:24:32 -04:00
Henry Zhu
18bbaa0253 use node current in dev 2017-03-27 14:24:32 -04:00
Henry Zhu
4278ede41f 🐶 🍲 2017-03-27 14:24:16 -04:00
Henry Zhu
7a1ccf076c Misc (#5545)
* normalize npmignores

* fixup eslint ignore, etc

* lint

* remove unused

* rm from gitignore

* use strict
2017-03-25 21:46:16 -04:00
Henry Zhu
cff1c8db39 v7.0.0-alpha.5 2017-03-24 10:38:10 -04:00
Henry Zhu
b8cf7b89f2 keep one core-js helper file in git, remove babel-runtime from deps (#5540) 2017-03-24 10:36:41 -04:00
azrael25
0eb898d95b fix babel-runtime helpers gererator (#5539) 2017-03-24 08:56:41 -04:00
Henry Zhu
d0b6db1901 v7.0.0-alpha.4 2017-03-23 18:06:48 -04:00
Henry Zhu
d7a77f4161 register should be a devDep 2017-03-23 18:04:46 -04:00
Henry Zhu
287869dcc2 nvm [skip ci] 2017-03-23 17:50:45 -04:00
Logan Smyth
a498371005 Ensure the ignore regex is consistent and initialized fully. (#5534) 2017-03-23 17:44:03 -04:00
Henry Zhu
ab68800e06 v7.0.0-alpha.3 2017-03-23 15:49:01 -04:00
Henry Zhu
f438a4e6b6 force publish all pkgs for now, clean runtime helpers/core-js correctly [skip ci] 2017-03-23 15:45:49 -04:00
Brian Ng
c687b703ae Ensure babel-cli tests compare generated output with out-files (#5205) 2017-03-23 12:06:56 -04:00
Boopathi Rajaa
c9a851a218 Cleanup traverse cache APIs (#5494) 2017-03-23 12:00:28 -04:00
Damien Maillard
299e51298c Fix path.remove() leading & trailing comments sharing (#5504) 2017-03-23 11:55:14 -04:00
Patrick Williams
0cd541b7d8 document cache option for babel-register (#5440) [skip ci] 2017-03-23 11:44:44 -04:00
Artem Yavorsky
796d497ea1 [skip ci] devEngines: Bump node to 4.x. (#5530) 2017-03-23 11:28:36 -04:00
Jason Julian
640515b3f6 removed unused alias in babel-runtime (#5516) 2017-03-22 20:03:35 -04:00
Henry Zhu
e155859b12 Merge pull request #5528 from babel/fix-babel-runtime-helpers
Fix babel runtime helpers
2017-03-22 20:02:29 -04:00
Brian Ng
c0779fdb71 Merge pull request #5341 from yavorsky/regenerator-transform-0-9-10
Bump regenerator-transform version to 0.9.11.
2017-03-22 18:07:47 -05:00
Artem Yavorsky
60b5409183 Bump regenerator-transform version to 0.9.11 2017-03-22 18:02:09 -05:00
Henry Zhu
26b9f9ed15 commit one helper to git to check regressions 2017-03-22 18:18:08 -04:00
Henry Zhu
483958b24d fix runtime helpers
Ref f3f907bdb3 (diff-339968af11c78f10673c78c6c7568d2fR34)
2017-03-22 18:07:11 -04:00
Guy Bedford
b75d80386c document dynamic import support (#5457) [skip ci] 2017-03-22 16:55:42 -04:00
Samuel Reed
f20da57317 Fix PathHoister attaching to default parameters. (#5415)
* Fix PathHoister attaching to default parameters.

Ref: #5315

* Update hoister.js
2017-03-22 16:37:53 -04:00
Patrick Williams
b2c977a1b0 Seperate version env cache files (#5411) 2017-03-22 16:29:29 -04:00
jddxf
7e25dccc6e Update babel-generator's README (#5517) [skip ci] 2017-03-22 16:25:42 -04:00
Robert Jackson
c4ebc8553b Properly preserve import ordering with AMD format. (#5474)
Previously, all "bare imports" (e.g. `import './foo';`) were moved to the
end of the array of sources. I presume this was done to remove needless
variables in the callback signature.

Unfortunately, doing this actually changes the intent of the program.
Modules should be evaluated in the order that they were in the source.

In the case of a bare import, it is quite possible that the bare import
has side effects that a later required module should see. With the current
implementation the later imported modules are evaluated before that "side
effecty" module has been evaluated.

Obviously, it is better to avoid these sorts of side effect ridden modules
but even still you could imagine a similar issue with cycles.

This change ensures that module source order is preserved in the AMD
dependencies list, and avoids making needless variables as much as possible.
2017-03-22 16:24:17 -04:00
Henry Zhu
b638c8b3eb Transform the template literals revision proposal (#5523)
* Account for template literals revision

* extra tests

* update to babylon beta 7

* pr feedback (keep arr length the same)
2017-03-22 16:07:36 -04:00
Henry Zhu
492ee95f27 Merge pull request #5522 from babel/update-babylon 2017-03-22 10:49:29 -04:00
Sven SAULEAU
2b774f46fb fix: handle bailed when recursive convert (#5499) 2017-03-22 09:18:37 +01:00
Arshabh Kumar Agarwal
a55f38b127 Changes the throw error for test in super-illegal-non-constructor-call (#5450) 2017-03-22 00:24:28 -04:00
Henry Zhu
ceb68f5bb7 babylon@7.0.0-beta.6 2017-03-22 00:24:00 -04:00
Henry Zhu
7d37017a5f Merge pull request #5489 from loganfsmyth/conf-refactor
Misc fixes + Move babel-core config processing from transformation/file/options into top-level folder
2017-03-21 14:12:41 -04:00
Henry Zhu
7551a8e666 Update yarn.lock 2017-03-21 13:04:54 -04:00
Henry Zhu
4901f33423 remove unnecessary call 2017-03-21 13:03:54 -04:00
Henry Zhu
95c905c5d2 fix markdown rendering [skip ci] 2017-03-20 09:32:32 -04:00
Aaron Ang
94024961ba Update error message when importing babel-cli (#5507) 2017-03-19 15:59:01 -07:00
Daniel Tschinder
ae8728c146 Merge branch 'master' into 7.0 2017-03-19 14:21:00 +01:00
Brian Ng
baafe486b3 Add useBuiltins and useESModules options to transform-runtime README [skip ci] (#5481) 2017-03-17 14:55:55 -04:00
Henry Zhu
534f621183 remove unused use of removed util class 2017-03-17 10:41:19 -04:00
Logan Smyth
a15de19888 Encapsulate config loading in config/ index file. 2017-03-17 00:04:00 -07:00
Logan Smyth
3c63431c7e Move config loading helpers into config folder. 2017-03-17 00:03:59 -07:00
Logan Smyth
f3f907bdb3 Remove unneeded helper file. 2017-03-17 00:03:59 -07:00
Logan Smyth
7b5d4fe069 Resolve parser and generator plugins in configuration resolution. 2017-03-17 00:03:59 -07:00
Logan Smyth
b71569ff6c Remove unneeded util.js file. 2017-03-17 00:03:59 -07:00
Logan Smyth
3e2d731d50 Move the Store class to be inside transformation. 2017-03-17 00:03:59 -07:00
Logan Smyth
12a2124d16 Move the deeply nested option logic to a toplevel folder. 2017-03-17 00:03:58 -07:00
Logan Smyth
6c4810cea5 Move Plugin class to be part of config loading, independent of File. 2017-03-17 00:03:58 -07:00
Logan Smyth
05ee30c9f7 Use the standard option parser to load the internal plugins. 2017-03-17 00:03:58 -07:00
Logan Smyth
38720ae309 Remove store subclassing from Plugin class. 2017-03-17 00:03:58 -07:00
Logan Smyth
bf13ed4da0 Limit where certain arguments are allowed in Babel config. 2017-03-17 00:03:58 -07:00
Logan Smyth
344f0a68c9 Centralize preset processing from two loops to one. 2017-03-17 00:03:57 -07:00
Logan Smyth
62def8da19 Make presets consistently resolve string values relative to their config file location. 2017-03-17 00:03:50 -07:00
Logan Smyth
39c862c195 Make only/ignore relative to cwd/config file and move only/ignore checking all to core. (#5487)
* Make only/ignore relative to cwd/config file and move only/ignore checking all to core.
2017-03-16 23:22:43 -07:00
Logan Smyth
b6194a8533 Merge pull request #5467 from loganfsmyth/clean-options
Misc reorganizing and prep for ignore/only refactoring
2017-03-16 20:25:20 -07:00
Brian Ng
612cce399a Fix options header on preset-latest readme [skip ci] 2017-03-16 14:10:26 -05:00
Ryan Paul
4e96a2da5e Removes unused lodash dep from babel-helper-builder-react-jsx (#5484) 2017-03-16 15:08:11 -04:00
Aaron Ang
edf2c76d63 Improve options documentation for babel-plugin-transform-runtime (#5401) 2017-03-16 10:37:50 -05:00
Sergey Bekrin
bf1b6ace53 update coffescript reference in readme [skip ci] (#5475) 2017-03-16 10:35:40 -05:00
Diogo Franco
2c0907acdc Merge pull request #5442 from babel/babel-runtime-with-builtins
Add useBuiltIns and useESModules options to transform-runtime
2017-03-15 11:47:35 +09:00
Logan Smyth
dd1bc3b183 Resolve programmatic/CLI arguments from cwd, not file being compiled. (#5466) 2017-03-14 16:56:00 -07:00
Logan Smyth
bf4664b430 Invert the resolution order of config-chain to process higher-priority items first. 2017-03-14 13:39:57 -07:00
Logan Smyth
dcb0f91f38 Ignore files if they don't match only OR they do match ignore. 2017-03-14 13:39:57 -07:00
Logan Smyth
738bd54bfb Move OptionManager calls out of 'new File'. 2017-03-14 13:39:57 -07:00
Logan Smyth
83356abd92 Centralize transform API functions. 2017-03-14 13:39:56 -07:00
Logan Smyth
c1be6a36c4 Delete Logger class. 2017-03-14 13:39:56 -07:00
Logan Smyth
188fe105c2 Move option-defaulting to option-manager. 2017-03-14 13:30:24 -07:00
Logan Smyth
540f9b2ad6 Remove the nonstandard basename option. 2017-03-14 13:30:24 -07:00
Logan Smyth
2642c2c2df Merge pull request #5463 from loganfsmyth/strict-args
More strictly parse configs and explicitly handle arguments in babel-cli
2017-03-14 10:21:32 -07:00
Nitin Tulswani
8c1cd177b2 added examples for transforms. [skip ci] (#5393) 2017-03-14 09:43:51 -05:00
Sven SAULEAU
0bc802cf1b Merge pull request #5448 from xtuc/feat-expose-env-core
Export Babel's environment
2017-03-14 12:50:21 +01:00
Logan Smyth
5b50b73d8b Remove config.js file in favor of config code. 2017-03-13 11:06:46 -07:00
Logan Smyth
4f72232ca9 Move option parsing to babel-cli. 2017-03-13 11:06:46 -07:00
Logan Smyth
2c564a6973 Move babel config descriptions to babel-cli. 2017-03-13 00:06:01 -07:00
Logan Smyth
0c0f090a98 Get rid of circular dependencies in babel cli script. 2017-03-13 00:00:56 -07:00
Henry Zhu
523a41b25e v6.24.0 changelog [skip ci] 2017-03-12 22:23:51 -04:00
Sven SAULEAU
c00ffb83be Merge pull request #5029 from xtuc/fix-require-debug
Require debug module directly
2017-03-12 21:23:56 +01:00
Sven SAULEAU
d328af0aec feat: export env getter 2017-03-11 20:40:23 +01:00
Sven SAULEAU
8744303f06 Merge branch '7.0' into fix-require-debug 2017-03-11 12:17:04 +01:00
Diogo Franco (Kovensky)
752788f22f Add fixtures for the transform-runtime output 2017-03-11 13:36:38 +09:00
Logan Smyth
01b250a8fa Merge pull request #5430 from loganfsmyth/opts-simplify
Simplify option and plugin pass processing
2017-03-10 13:03:19 -08:00
MrSpider
5287e13817 Fix replacing function declaration in export default (fixes #4468) (#5444) 2017-03-10 11:41:03 -08:00
Aaron Ang
911b71f2c6 Use absolute paths in Babel's CONTRIBUTING.md (#5431) 2017-03-10 08:49:28 -06:00
Diogo Franco (Kovensky)
25212445ed Add new generated files to .gitignore 2017-03-10 18:53:20 +09:00
Diogo Franco (Kovensky)
8dc2176a04 Fix Node 4 parse errors 2017-03-10 16:36:20 +09:00
Diogo Franco (Kovensky)
cf5ab16ff9 Add useBuiltIns and useESModules options to transform-runtime
useBuiltIns uses versions of the helpers that do not import even
internal polyfills from core-js.

useESModules uses versions of the helpers that do not go through
transform-es2015-modules-commonjs. This allows for smaller builds in
module systems like webpack, as it doesn't need to preserve commonjs
semantics.

This includes changes to the babel-runtime build-dist script, which
will build the versions of the runtime helpers to be used by
combinations of useBuiltIns and useESModules.
2017-03-10 16:27:35 +09:00
Logan Smyth
ca71c74696 Move plugin and pass initialization into a more central location. 2017-03-09 16:13:38 -08:00
Logan Smyth
305165eda4 Remove Logger usage from options processing. 2017-03-09 16:13:38 -08:00
Henry Zhu
12eb25c06c don't show other presets in readme [skip ci] (#5438) 2017-03-09 11:00:25 -05:00
Sven SAULEAU
7c8825f6b2 Merge pull request #5418 from babel/xtuc-patch-4
Add new members
2017-03-09 16:48:06 +01:00
Aaron Ang
3d987ed6c0 Keep parentheses for logical expression when in await expression (fix #5428) (#5433) 2017-03-09 09:13:53 -05:00
Henry Zhu
230712e091 Internal: back to fixed, publish everything (#5436) 2017-03-08 22:56:00 -05:00
Henry Zhu
0553d7761d Publish
- babel-cli@7.0.0-alpha.2
 - babel-core@7.0.0-alpha.2
 - babel-helper-plugin-test-runner@7.0.0-alpha.2
 - babel-helper-transform-fixture-test-runner@7.0.0-alpha.2
 - babel-register@7.0.0-alpha.2
2017-03-08 13:08:44 -05:00
Henry Zhu
02473a72c1 Merge pull request #4892 from kaicataldo/babelrcjs
Add support for .babelrc.js files
2017-03-07 16:58:00 -05:00
Kai Cataldo
d054cd0ea8 Add support for .babelrc.js files 2017-03-07 16:44:24 -05:00
Brian Ng
0336cab757 Fix transform-object-rest-spread README [skip ci] (#5409) 2017-03-07 16:41:49 -05:00
Artem Gurzhii
6888a2c51b Code refactoring for the babel-generator (#5344)
* refactoring code for babel-generator package

* removing spaces and refactoring if statement

* fixing warnings
2017-03-07 16:41:49 -05:00
Logan Smyth
39eca84642 Use 'resolve' from npm instead of private 'module' methods. (#5416) 2017-03-07 12:42:25 -08:00
Logan Smyth
836dd95c44 Merge pull request #5422 from rwjblue/remove-interop-require-default-in-strict-mode
Add noInterop option to babel-plugin-transform-es2015-modules-commonjs.
2017-03-07 11:16:43 -08:00
Robert Jackson
23de276718 Add docs for strict and noInterop with es2015-modules-commonjs. 2017-03-06 20:19:38 -05:00
Robert Jackson
0d1edb9811 Add noInterop option to babel-plugin-transform-es2015-modules-commonjs.
The intent of this option is to toggle module interop behavior. When `true`
no `interopRequireXXX` helper invocations will be emitted.
2017-03-06 19:51:35 -05:00
Brian Ng
8a82cc060a Run new lint rules (#5413) 2017-03-04 10:46:01 -05:00
Sven SAULEAU
990d22a8d4 docs: [skip ci] add new members 2017-03-04 11:26:13 +01:00
Henry Zhu
f7e2d88f6c independent mode [skip ci] 2017-03-02 16:25:18 -05:00
Henry Zhu
11e54a6bd3 v7.0.0-alpha.1 2017-03-02 16:04:47 -05:00
Henry Zhu
22a5ce43f1 fix lerna config [skip ci] 2017-03-02 16:00:44 -05:00
Henry Zhu
67ed224df0 update babel-types readme [skip ci] 2017-03-02 15:58:12 -05:00
Henry Zhu
c86f922dc7 add exact flag [skip ci] 2017-03-02 15:54:51 -05:00
Henry Zhu
b4b03d48fa remove undeclared plugin [skip ci] (#5407) 2017-03-02 15:53:02 -05:00
Henry Zhu
0847ae055d cleanup + update to lerna 38 (#5406) 2017-03-02 15:04:54 -05:00
Aaron Ang
4ad0caaa66 Merge pull request #5400 from JPeer264/fix/usage
[doc] Fix: comments in usage w/ options
2017-03-01 12:50:29 -08:00
JPeer264
b9c0f364c4 [skip ci] Fix: comments in usage w/ options 2017-03-01 21:35:51 +01:00
Henry Zhu
65f23b8212 Merge pull request #5399 from babel/update-babylon-beta-4
Update babylon beta 4
2017-03-01 13:26:28 -05:00
Henry Zhu
b363e7b199 add @danez's changes 2017-03-01 12:54:22 -05:00
Henry Zhu
2b9c3735fd update to babylon beta 4 2017-03-01 12:38:19 -05:00
Henry Zhu
3ff77a61e4 Update babylon beta 3 (#5394)
* Update babylon to v7-beta.3

* convert RestProperty/SpreadProperty to RestElement/SpreadElement

* add virtual types to make it easier to upgrade
2017-02-28 16:58:19 -05:00
Daniel Tschinder
6d6cdf6baf [7.0] Allow presets to be objects (#5385)
* Allow presets to be objects

* Improve logic to detect preset format
2017-02-28 16:39:08 -05:00
Logan Smyth
9acae54a29 Merge pull request #5376 from loganfsmyth/no-pipeline
[7.0] Remove the unneeded Pipeline class.
2017-02-27 12:33:11 -08:00
Henry Zhu
696e63c58b Merge pull request #5380 from babel/extra-do + 6.x commits 2017-02-25 18:48:27 -05:00
Henry Zhu
6529cb5f01 babel-generator: add another do test 2017-02-25 18:39:18 -05:00
Logan Smyth
f3e92010c5 Remove the unneeded Pipeline class. 2017-02-24 13:37:33 -08:00
Henry Zhu
d33d023594 Merge remote-tracking branch 'origin/master' into merge-master 2017-02-23 18:54:15 -05:00
Daniel Tschinder
87ca6150ae [7.0] Remove bc code from preset handling and preset-es2015 (#5128)
* Remove bc code from preset handling and preset-es2015

* Add more tests

* Only allow functions for presets

* Fix lint
2017-02-22 14:58:01 +01:00
Aaron Ang
45087b258b Add Yarn installation to CONTRIBUTING.md (#5358) [skip ci] 2017-02-22 07:50:22 -05:00
Marcelo Dapper
724c949244 Replace lodash/assign with Object.assign (#5356)
Remove imports to lodash/assign and replace assign with Object.assign.
The lodash/assign is unnecessary for babel 7 as node >4 has the same
functionality built-in with Object.assign as used here.

This resolve the [issue 5353](https://github.com/babel/babel/issues/5353)
2017-02-21 22:08:20 -05:00
Logan Smyth
c1f7d67bae Merge pull request #5351 from loganfsmyth/reduce-require
Avoid usage of exports/module.exports/require().
2017-02-21 16:59:32 -08:00
Logan Smyth
4ee385e96c Avoid usage of exports/module.exports/require(). 2017-02-21 16:52:42 -08:00
Henry Zhu
d9f01cbce6 Merge pull request #5317 from babel/update-babylon
Update to babylon@7.0.0-beta.0
2017-02-18 13:06:39 -05:00
Daniel Tschinder
7e540cdcc9 Remove obsolete code 2017-02-18 12:30:46 +01:00
Daniel Tschinder
7c62278dcd [7.0] Change for-await to use new AST (#5321) 2017-02-15 17:29:09 -05:00
Alexander
1ba3269ece [7.0] Switch decorators-legacy to decorators in the Stage 1 Preset (#5318) (#5319) 2017-02-15 16:58:31 -05:00
Daniel Tschinder
ca78da6501 Fix variance (#5320) 2017-02-15 22:37:19 +01:00
Alex Kuzmenko
fa2a373acd [7.0] Replacing current decorators with decorators-legacy (#5290) 2017-02-15 15:42:50 -05:00
Toru Kobayashi
9188be9ed5 [7.0] Rename flow AST Type ExistentialTypeParam to ExistsTypeAnnotation (#5199) 2017-02-15 14:58:07 -05:00
Charles Pick
bc8f476d33 [7.0] Rename NumericLiteralTypeAnnotation to NumberLiteralTypeAnnotation (#5229) 2017-02-15 14:54:27 -05:00
Henry Zhu
b3e208fcd0 Update to babylon@7.0.0-beta.0 2017-02-15 14:45:21 -05:00
Sergey Rubanov
c3098d2437 Add Node 7 to CI (#5165)
This reapplies this commit, as it was lost before
2017-02-14 15:33:10 +01:00
Daniel Tschinder
6c03cb0783 Merge branch 'master' into merge-master
# Conflicts:
#	lerna.json
#	packages/babel-cli/package.json
#	packages/babel-core/package.json
#	packages/babel-generator/package.json
#	packages/babel-helper-builder-react-jsx/package.json
#	packages/babel-helper-function-name/package.json
#	packages/babel-helper-optimise-call-expression/package.json
#	packages/babel-helper-replace-supers/package.json
#	packages/babel-helper-transform-fixture-test-runner/package.json
#	packages/babel-helpers/package.json
#	packages/babel-plugin-transform-class-properties/package.json
#	packages/babel-plugin-transform-es2015-block-scoping/package.json
#	packages/babel-plugin-transform-es2015-classes/package.json
#	packages/babel-plugin-transform-es2015-modules-commonjs/package.json
#	packages/babel-plugin-transform-es2015-modules-systemjs/package.json
#	packages/babel-plugin-transform-es2015-modules-umd/package.json
#	packages/babel-plugin-transform-es2015-parameters/package.json
#	packages/babel-plugin-transform-react-jsx/package.json
#	packages/babel-register/package.json
#	packages/babel-template/package.json
#	packages/babel-traverse/package.json
#	packages/babel/package.json
2017-02-14 12:46:23 +01:00
Henry Zhu
dde70c0a04 [7.0] remove standalone babel package (#5293)
Having it isn't compatible with the changes for `babel-cli -> @babel/cli`
2017-02-10 14:40:24 -05:00
Henry Zhu
870a37834c .gitignore for test [skip ci] 2017-02-09 19:19:41 -05:00
Henry Zhu
982cdb2a3a update yarn 2017-02-09 18:54:42 -05:00
Henry Zhu
ad91c6d186 use lerna@2-beta.37 (#5254) 2017-02-09 18:47:58 -05:00
Henry Zhu
9083bd6283 Merge branch 'master' into 7.0 2017-02-09 18:36:02 -05:00
Logan Smyth
6fa6f5924d [7.0] Run Babel's unittests in a custom sandbox (take 2). (#5263)
* Run Babel's unittests in a custom sandbox (take 2).

* Add tests for sandboxing behavior.
2017-02-04 13:31:33 -08:00
Marek Święcicki
ba0df23365 [7.0] Remove quotes option (#5154)
* remove mention of 'quotes' option from README.md

* always infer quotes option's value
2017-01-31 12:03:51 -08:00
Brian Ng
e530e3c025 [7.0] List babylon plugins instead of * in babel-generator tests (#5231) 2017-01-28 09:35:21 -05:00
Kai Cataldo
e09ea222c9 Remove babel-runtime from packages' dependencies (#5218) 2017-01-27 09:04:35 -05:00
wtgtybhertgeghgtwtg
e5aa501327 Bump detect-indent. (#5226) 2017-01-27 09:02:48 -05:00
Artem Yavorsky
3f95a767f2 [7.0] Add legacy-decorators to stage-1. Fixes #5220 (#5225) 2017-01-27 09:02:10 -05:00
Anderson Vasques
0766f29591 [7.0] Use lerna's --independent mode + changes (fixes #5221)
Adding version `independent` and cacheDir `.changelog`
2017-01-26 20:01:54 -05:00
wtgtybhertgeghgtwtg
398b0326a3 [7.0] Bump home-or-tmp for babel-register. (#5189) 2017-01-23 23:35:44 -05:00
Chau Nguyen
2ee3a017f0 [7.0] Added yarn.lock (#5175)
* Added yarn.lock

* Updated bootstrap npm install commands to yarn and added yarn caching
2017-01-23 18:15:33 -05:00
Vivek Kumar Bansal
728072f47b [7.0] Remove old babel-runtime code (#5187) 2017-01-21 11:25:29 -05:00
Scott Arnold
20a5249dea [7.0] Drop support for Node 5 (#5186) 2017-01-21 10:14:49 -05:00
Henry Zhu
661102c7ea Merge branch 'master' into 7.0
# Conflicts:
#	.travis.yml
#	CHANGELOG.md
#	lerna.json
#	packages/babel-cli/package.json
2017-01-21 08:52:14 -05:00
Andres Suarez
e9d87ed55c Remove path-is-absolute in favor of builtin path.isAbsolute (#5179) 2017-01-21 08:33:34 -05:00
Mathias Bynens
090f7abda4 [7.0] babel-preset-stage-2: Add transform-unicode-property-regex (#3683)
This enables the use of Unicode property escapes of the form `\p{…}` and `\P{…}` in regular expressions with the `u` flag enabled.

More info: https://mathiasbynens.be/notes/es-unicode-property-escapes
Proposal: https://github.com/mathiasbynens/es-regexp-unicode-property-escapes
Plugin: https://github.com/mathiasbynens/babel-plugin-transform-unicode-property-regex
2017-01-20 08:17:25 -05:00
Colin
1aa7a2a1a3 Remove "class-constructor-call" syntax and transform plugins (#5119)
* removed class-constructor-call syntax and transform plugins and all references to them

* #5112, removed another reference to constructor call
2017-01-20 10:42:56 +01:00
Sergey Rubanov
d0b42d4313 Update babel-core browserify fixture (#5164) 2017-01-20 10:29:44 +01:00
Adonis K
12886ea495 [7.0] Remove stage 4 plugins from stage 3 preset (#5126)
* remove trailing function commas from stage-3 preset (#5117)

trailing function commas is now a finished proposal and was moved to stage 4 (https://github.com/tc39/proposal-trailing-function-commas)

* remove the exponentiation operator from stage-3 preset (#5117)

exponentiation-operator is now a finished proposal and was moved to stage 4 (https://github.com/rwaldron/exponentiation-operator)

* remove async function to es2015 generator from stage-3 preset (#5117)

async functions is now a finished proposal and was moved to stage 4 (https://github.com/tc39/ecmascript-asyncawait)
2017-01-19 23:03:49 -05:00
Sergey Rubanov
b978996ba4 Remove add-module-exports use internally (#5131) 2017-01-19 23:02:19 -05:00
Jordan Jones
1742035a98 [7.0] Fixes #5108, browser.js and browser.js test removed (#5124)
* Fixes #5108, browser.js and browser.js test removed

* Moved api/node.js to index.js and adjusted associated file references
2017-01-19 22:43:11 -05:00
Janus Troelsen
e4ba28c294 [7.0] Dependencies: Upgrade regexpu-core to ^4.0.2 (#5028) 2017-01-19 22:33:46 -05:00
Anderson Vasques
81c3578adc [7.0] Remove old code used for backwards compatibility (#5122)
[7.0] Remove old code used for backwards compatibility in babel-polyfill

Fixes #5121
2017-01-19 22:32:16 -05:00
Chau Nguyen
d710e6dd5b [7.0] Drop flowUsesCommas option from babel-generator (#5123) 2017-01-19 22:24:13 -05:00
Sergey Rubanov
3a5ce620c8 [7.0] Deprecate babel-core/register.js (#5132)
* Deprecate babel-core/register.js

* add error when using `babel-core/register`
2017-01-19 22:22:45 -05:00
Shubheksha Jalan
c468b15a15 [7.0] removed old code from transform-runtime (#5142) 2017-01-19 22:20:04 -05:00
Henry Zhu
ef3ab66847 Merge pull request #5025 from siddharthkp/patch-1
Drop support for Node 0.12 💀
2017-01-19 21:25:16 -05:00
Henry Zhu
e2c5a513f6 Create circle.yml 2017-01-19 20:42:25 -05:00
Henry Zhu
2471d5ebf3 Merge pull request #5041 from xtuc/remove-0.10-support
Remove node 0.10 support (CI)
2017-01-19 20:24:22 -05:00
Sven SAULEAU
d67b55e88f fix: [skip ci] update supported environments 2017-01-15 19:45:07 +01:00
Sven SAULEAU
90279f102f docs: remove compiler support for 0.10 2016-12-25 20:54:38 +01:00
Sven SAULEAU
8b25e21520 build: remove Circle CI 2016-12-25 20:54:20 +01:00
Sven SAULEAU
1672982873 fix: require debug directly instead of debug/node 2016-12-21 18:09:58 +01:00
Siddharth Kshetrapal
868c9ecc11 change node version in contributing 2016-12-21 12:35:16 +05:30
Siddharth Kshetrapal
7135751750 Drop support for Node 0.12 💀 2016-12-21 12:28:28 +05:30
834 changed files with 12611 additions and 5696 deletions

3
.babelignore Normal file
View File

@@ -0,0 +1,3 @@
# Ensure babel-register won't compile fixtures, or try to recompile compiled code.
packages/*/test/fixtures
packages/*/lib

29
.babelrc.js Normal file
View File

@@ -0,0 +1,29 @@
"use strict";
let envOpts = {
loose: true
};
module.exports = {
comments: false,
presets: [
[
"env", envOpts
],
"stage-0",
"flow",
],
env: {
cov: {
auxiliaryCommentBefore: "istanbul ignore next",
plugins: ["istanbul"]
}
}
};
if (process.env.BABEL_ENV === 'development') {
envOpts.targets = {
node: "current"
};
envOpts.debug = true;
};

View File

@@ -1,11 +1,9 @@
/lib
scripts
packages/babel-core/src/transformation/templates
packages/babel-runtime
!packages/babel-runtime/scripts
!packages/babel-runtime/core-js.js
packages/*/node_modules
packages/*/lib
packages/*/dist
packages/*/test/fixtures
vendor
_babel.github.io
Gulpfile.js
packages/*/test/tmp

View File

@@ -1,6 +1,11 @@
{
"extends": "babel",
"rules": {
"comma-dangle": ["error", "always-multiline"],
"curly": ["error", "multi-line"],
"func-call-spacing": "error",
"key-spacing": "error",
"no-multi-spaces": "error"
},
"env": {
"node": true,

View File

@@ -1,20 +1,21 @@
<!---
BEFORE YOU SUBMIT please read the following:
Thanks for filing an issue 😄 ! Before you submit, please read the following:
Please search open/closed issues before submitting since someone might have asked the same thing before!
Search open/closed issues before submitting since someone might have asked the same thing before!
If you have a support request or question please submit them to one of this resources:
* Discussion Forum: https://discuss.babeljs.io/
* Slack Community: https://slack.babeljs.io/
* StackOverflow: http://stackoverflow.com/questions/tagged/babeljs using the tag `babeljs`
* Slack community: https://slack.babeljs.io/
* Also have a look at the Readme for more information on how to get support:
* Also have a look at the readme for more information on how to get support:
https://github.com/babel/babel/blob/master/README.md
Issues on GitHub are only related to problems of babel itself and we cannot answer
Issues on GitHub are only related to problems of Babel itself and we cannot answer
support questions here.
-->
Choose one: is this a bug report or feature request?
<!--- Provide a general summary of the issue in the title above -->
### Input Code
@@ -53,7 +54,7 @@ var your => (code) => here;
### Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
| software | version
| software | version(s)
| ---------------- | -------
| Babel |
| node |

15
.gitignore vendored
View File

@@ -1,22 +1,25 @@
.DS_Store
node_modules
test/tmp
*.log
*.cache
/.eslintcache
/templates.json
/tests.json
/browser.js
/browser-polyfill.js
/runtime.js
/coverage
dist
/.package.json
/packages/babel-runtime/core-js
/packages/babel-runtime/core-js/**/*.js
!/packages/babel-runtime/core-js/map.js
/packages/babel-runtime/helpers/*.js
!/packages/babel-runtime/helpers/toArray.js
/packages/babel-runtime/helpers/builtin/*.js
!/packages/babel-runtime/helpers/builtin/toArray.js
/packages/babel-runtime/helpers/builtin/es6/*.js
!/packages/babel-runtime/helpers/builtin/es6/toArray.js
/packages/babel-runtime/helpers/es6/*.js
!/packages/babel-runtime/helpers/es6/toArray.js
/packages/babel-register/test/.babel
/packages/*/lib
_babel.github.io
/tests/.browser-build.js
.nyc_output
/babel.sublime-workspace

View File

@@ -3,27 +3,24 @@ git:
sudo: false
language: node_js
cache:
yarn: true
directories:
- node_modules
node_js:
- '7'
- '6'
- '5'
- '4'
- '0.12'
env:
- JOB=test
script:
- 'if [ "$JOB" = "test" ]; then make test-ci; fi'
- 'if [ "$JOB" = "test-coverage" ]; then make test-ci-coverage; fi'
- 'if [ "$JOB" = "lint" ]; then make lint && make flow; fi'
matrix:
fast_finish: true
include:
- node_js: "7"
env: JOB=test-coverage
- node_js: "node"
env: JOB=lint

View File

@@ -40,10 +40,13 @@ Feel free to check out the `#discussion`/`#development` channels on our [slack](
**Note:** Versions `< 5.1.10` can't be built.
Babel is built for node 0.10 and up but we develop using node 6. Make sure you are on npm 3.
Babel is built for node 4 and up but we develop using node 6. Make sure you are on npm 3.
You can check this with `node -v` and `npm -v`.
In addition, make sure that Yarn is installed.
Installation instructions can be found here: https://yarnpkg.com/en/docs/install.
### Setup
```sh

View File

@@ -1,77 +1,52 @@
var plumber = require("gulp-plumber");
var through = require("through2");
var chalk = require("chalk");
var newer = require("gulp-newer");
var babel = require("gulp-babel");
var watch = require("gulp-watch");
var gutil = require("gulp-util");
var gulp = require("gulp");
var path = require("path");
"use strict";
var scripts = "./packages/*/src/**/*.js";
const plumber = require("gulp-plumber");
const through = require("through2");
const chalk = require("chalk");
const newer = require("gulp-newer");
const babel = require("gulp-babel");
const watch = require("gulp-watch");
const gutil = require("gulp-util");
const gulp = require("gulp");
const path = require("path");
var srcEx, libFragment;
const base = path.join(__dirname, "packages");
const scripts = "./packages/*/src/**/*.js";
if (path.win32 === path) {
srcEx = /(packages\\[^\\]+)\\src\\/;
libFragment = "$1\\lib\\";
} else {
srcEx = new RegExp("(packages/[^/]+)/src/");
libFragment = "$1/lib/";
function swapSrcWithLib(srcPath) {
const parts = srcPath.split(path.sep);
parts[1] = "lib";
return parts.join(path.sep);
}
var mapToDest = function (path) { return path.replace(srcEx, libFragment); };
var dest = "packages";
gulp.task("default", ["build"]);
gulp.task("build", function () {
return gulp.src(scripts)
return gulp.src(scripts, { base: base })
.pipe(plumber({
errorHandler: function (err) {
gutil.log(err.stack);
}
},
}))
.pipe(newer({
dest: base,
map: swapSrcWithLib,
}))
.pipe(newer({map: mapToDest}))
.pipe(through.obj(function (file, enc, callback) {
gutil.log("Compiling", "'" + chalk.cyan(file.path) + "'...");
gutil.log("Compiling", "'" + chalk.cyan(file.relative) + "'...");
callback(null, file);
}))
.pipe(babel())
.pipe(through.obj(function (file, enc, callback) {
file._path = file.path;
file.path = mapToDest(file.path);
// Passing 'file.relative' because newer() above uses a relative path and this keeps it consistent.
file.path = path.resolve(file.base, swapSrcWithLib(file.relative));
callback(null, file);
}))
.pipe(gulp.dest(dest));
.pipe(gulp.dest(base));
});
// TODO: remove this section
// temporarily just copying the old code since watch isn't working
var dest = "packages";
gulp.task("build-watch", function () {
return gulp.src(scripts)
.pipe(plumber({
errorHandler: function (err) {
gutil.log(err.stack);
}
}))
.pipe(through.obj(function (file, enc, callback) {
file._path = file.path;
file.path = file.path.replace(srcEx, libFragment);
callback(null, file);
}))
.pipe(newer(dest))
.pipe(through.obj(function (file, enc, callback) {
gutil.log("Compiling", "'" + chalk.cyan(file._path) + "'...");
callback(null, file);
}))
.pipe(babel())
.pipe(gulp.dest(dest));
});
gulp.task("watch", ["build-watch"], function (callback) {
watch(scripts, {debounceDelay: 200}, function () {
gulp.start("build-watch");
gulp.task("watch", ["build"], function () {
watch(scripts, { debounceDelay: 200 }, function () {
gulp.start("build");
});
});

View File

@@ -16,20 +16,22 @@ build-dist: build
watch: clean
rm -rf packages/*/lib
./node_modules/.bin/gulp watch
BABEL_ENV=development ./node_modules/.bin/gulp watch
lint:
./node_modules/.bin/eslint packages/ --format=codeframe
./node_modules/.bin/eslint scripts packages *.js --format=codeframe
flow:
./node_modules/.bin/flow check
fix:
./node_modules/.bin/eslint packages/ --format=codeframe --fix
./node_modules/.bin/eslint scripts packages *.js --format=codeframe --fix
clean: test-clean
rm -rf packages/babel-polyfill/browser*
rm -rf packages/babel-polyfill/dist
# rm -rf packages/babel-runtime/helpers
# rm -rf packages/babel-runtime/core-js
rm -rf coverage
rm -rf packages/*/npm-debug*
@@ -63,14 +65,14 @@ publish:
BABEL_ENV=production make build-dist
make test
# not using lerna independent mode atm, so only update packages that have changed since we use ^
./node_modules/.bin/lerna publish --only-explicit-updates
# --only-explicit-updates
./node_modules/.bin/lerna publish --npm-tag=next --exact --skip-temp-tag
make clean
bootstrap:
make clean-all
npm install
yarn
./node_modules/.bin/lerna bootstrap
make build
cd packages/babel-runtime; \
npm install; \
node scripts/build-dist.js

View File

@@ -137,27 +137,9 @@ After Babel 6, the default transforms were removed; if you don't specify any plu
The transformer[s] used in Babel are the independent pieces of code that transform specific things. For example: the [`es2015-arrow-functions`](/packages/babel-plugin-transform-es2015-arrow-functions) transform specifically changes arrow functions into a regular function. Presets are just simply an array of plugins that make it easier to run a whole a set of transforms without specifying each one manually.
There are a few presets that we maintain officially.
| Package | Version | Dependencies |
|--------|-------|------------|
| [`babel-preset-es2015`](/packages/babel-preset-es2015) | [![npm](https://img.shields.io/npm/v/babel-preset-es2015.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2015) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2015)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2015) |
| [`babel-preset-es2016`](/packages/babel-preset-es2016) | [![npm](https://img.shields.io/npm/v/babel-preset-es2016.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2016) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2016)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2016) |
| [`babel-preset-es2017`](/packages/babel-preset-es2017) | [![npm](https://img.shields.io/npm/v/babel-preset-es2017.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-es2017) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-es2017)](https://david-dm.org/babel/babel?path=packages/babel-preset-es2017) |
| [`babel-preset-latest`](/packages/babel-preset-latest) | [![npm](https://img.shields.io/npm/v/babel-preset-latest.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-latest) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-latest)](https://david-dm.org/babel/babel?path=packages/babel-preset-latest) |
| [`babel-preset-stage-0`](/packages/babel-preset-stage-0) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-0.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-0) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-0)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-0) |
| [`babel-preset-stage-1`](/packages/babel-preset-stage-1) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-1.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-1) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-1)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-1) |
| [`babel-preset-stage-2`](/packages/babel-preset-stage-2) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-2.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-2) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-2)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-2) |
| [`babel-preset-stage-3`](/packages/babel-preset-stage-3) | [![npm](https://img.shields.io/npm/v/babel-preset-stage-3.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-stage-3) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-stage-3)](https://david-dm.org/babel/babel?path=packages/babel-preset-stage-3) |
| [`babel-preset-react`](/packages/babel-preset-react) | [![npm](https://img.shields.io/npm/v/babel-preset-react.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-react) | [![Dependency Status](https://david-dm.org/babel/babel.svg?path=packages/babel-preset-react)](https://david-dm.org/babel/babel?path=packages/babel-preset-react) |
| [`babel-preset-env`](https://github.com/babel/babel-preset-env) | [![npm](https://img.shields.io/npm/v/babel-preset-env.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-env) | [![Dependency Status](https://david-dm.org/babel/babel-preset-env.svg)](https://david-dm.org/babel/babel-preset-env) |
We maintain:
- a preset for each yearly release of ECMAScript (Javascript) starting from ES6/ES2015.
- a preset for react (JSX/Flow).
- a preset for each [stage (0-3)](http://babeljs.io/docs/plugins/#stage-x-experimental-presets) of the [TC-39 Process](https://tc39.github.io/process-document/) for ECMAScript proposals.
- a preset that can automatically determine plugins and polyfills you need based on your supported environments.
| Package | Version | Dependencies | Description |
|--------|-------|------------|---|
| [`babel-preset-env`](https://github.com/babel/babel-preset-env) | [![npm](https://img.shields.io/npm/v/babel-preset-env.svg?maxAge=2592000)](https://www.npmjs.com/package/babel-preset-env) | [![Dependency Status](https://david-dm.org/babel/babel-preset-env.svg)](https://david-dm.org/babel/babel-preset-env) | automatically determines plugins and polyfills you need based on your supported environments |
> You can find community maintained presets on [npm](https://www.npmjs.com/search?q=babel-preset)
@@ -184,24 +166,24 @@ These are mostly for internal use in various plugins: `babel-helper-x`.
### Core members
[![Babel](https://avatars.githubusercontent.com/u/9637642?s=64)](https://github.com/babel) | [![Daniel Tschinder](https://avatars.githubusercontent.com/u/231804?s=64)](https://github.com/danez) | [![Logan Smyth](https://avatars.githubusercontent.com/u/132260?s=64)](https://github.com/loganfsmyth) | [![Henry Zhu](https://avatars.githubusercontent.com/u/588473?s=64)](https://github.com/hzoo) |
|---|---|---|---|---|
|---|---|---|---|
Babel | Daniel Tschinder | Logan Smyth | Henry Zhu |
:octocat: [@babel](https://github.com/babel) | [@danez](https://github.com/danez) | [@loganfsmyth](https://github.com/loganfsmyth) | [@hzoo](https://github.com/hzoo) |
:bird: [@babeljs](https://twitter.com/babeljs) | [@TschinderDaniel](https://twitter.com/TschinderDaniel) | [@loganfsmyth](https://twitter.com/loganfsmyth) | [@left_pad](https://twitter.com/left_pad) |
### Members
[![Andrew Levine](https://avatars.githubusercontent.com/u/5233399?s=64)](https://github.com/drewml) | [![Boopathi Rajaa](https://avatars.githubusercontent.com/u/294474?s=64)](https://github.com/boopathi) | [![Brian Ng](https://avatars.githubusercontent.com/u/56288?s=64)](https://github.com/existentialism) | [![Dan Harper](https://avatars.githubusercontent.com/u/510740?s=64)](https://github.com/danharper) | [![Diogo Franco](https://avatars.githubusercontent.com/u/73085?s=64)](https://github.com/kovensky) |
|---|---|---|---|---|---|---|---|---|
| Andrew Levine | Boopathi Rajaa | Brian Ng | Dan Harper | Diogo Franco |
| [@drewml](https://github.com/drewml) | [@boopathi](https://github.com/boopathi) | [@existentialism](https://github.com/existentialism) | [@danharper](https://github.com/danharper) | [@kovensky](https://github.com/kovensky) |
| [@drewml](https://twitter.com/drewml) | [@heisenbugger](https://twitter.com/heisenbugger) | [@existentialism](https://twitter.com/existentialism) | [@DanHarper7](https://twitter.com/DanHarper7) | [@kovnsk](https://twitter.com/kovnsk) |
[![Andrew Levine](https://avatars.githubusercontent.com/u/5233399?s=64)](https://github.com/drewml) | [![Boopathi Rajaa](https://avatars.githubusercontent.com/u/294474?s=64)](https://github.com/boopathi) | [![Brian Ng](https://avatars.githubusercontent.com/u/56288?s=64)](https://github.com/existentialism) | [![Dan Harper](https://avatars.githubusercontent.com/u/510740?s=64)](https://github.com/danharper) | [![diogo franco](https://avatars.githubusercontent.com/u/73085?s=64)](https://github.com/kovensky) | [![Aaron Ang](https://avatars1.githubusercontent.com/u/7579804?s=64)](https://github.com/aaronang) | [![Artem Yavorsky](https://avatars2.githubusercontent.com/u/1521229?s=64)](https://github.com/yavorsky) |
|---|---|---|---|---|---|---|
| Andrew Levine | Boopathi Rajaa | Brian Ng | Dan Harper | Diogo Franco | Aaron Ang | Artem Yavorsky |
| [@drewml](https://github.com/drewml) | [@boopathi](https://github.com/boopathi) | [@existentialism](https://github.com/existentialism) | [@danharper](https://github.com/danharper) | [@kovensky](https://github.com/kovensky) | [@aaronang](https://github.com/aaronang) | [@yavorsky](https://github.com/yavorsky) |
| [@drewml](https://twitter.com/drewml) | [@heisenbugger](https://twitter.com/heisenbugger) | [@existentialism](https://twitter.com/existentialism) | [@DanHarper7](https://twitter.com/DanHarper7) | [@kovnsk](https://twitter.com/kovnsk) | [@_aaronang](https://twitter.com/_aaronang) | [@yavorsky_](https://twitter.com/yavorsky_) |
[![Juriy Zaytsev](https://avatars.githubusercontent.com/u/383?s=64)](https://github.com/kangax) | [![Kai Cataldo](https://avatars.githubusercontent.com/u/7041728?s=64)](https://github.com/kaicataldo) | [![Moti Zilberman](https://avatars.githubusercontent.com/u/2246565?s=64)](https://github.com/motiz88) | [![Sven Sauleau](https://avatars3.githubusercontent.com/u/1493671?s=64)](https://github.com/xtuc) |
|---|---|---|---|---|---|---|---|---|
| Juriy Zaytsev | Kai Cataldo | Moti Zilberman | Sven Sauleau |
| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) |
| [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) |
[![Juriy Zaytsev](https://avatars.githubusercontent.com/u/383?s=64)](https://github.com/kangax) | [![Kai Cataldo](https://avatars.githubusercontent.com/u/7041728?s=64)](https://github.com/kaicataldo) | [![Moti Zilberman](https://avatars.githubusercontent.com/u/2246565?s=64)](https://github.com/motiz88) | [![Sven Sauleau](https://avatars3.githubusercontent.com/u/1493671?s=64)](https://github.com/xtuc) | [![Samuel Reed](https://avatars3.githubusercontent.com/u/1197375?s=64)](https://github.com/STRML) | [![Sergey Rubanov](https://avatars1.githubusercontent.com/u/1507086?s=64)](https://github.com/chicoxyzzy) |
|---|---|---|---|---|---|
| Juriy Zaytsev | Kai Cataldo | Moti Zilberman | Sven Sauleau | Samuel Reed | Sergey Rubanov |
| [@kangax](https://github.com/kangax) | [@kaicataldo](https://github.com/kaicataldo) | [@motiz88](https://github.com/motiz88) | [@xtuc](https://github.com/xtuc) | [@STRML](https://github.com/STRML) | [@chicoxyzzy](https://github.com/chicoxyzzy) |
| [@kangax](https://twitter.com/kangax) | [@kai_cataldo](https://twitter.com/kai_cataldo) | [@motiz88](https://twitter.com/motiz88) | [@svensauleau](https://twitter.com/svensauleau) | [@STRML_](https://twitter.com/STRML_) | [@chicoxyzzy](https://twitter.com/chicoxyzzy) |
### Non-Human Members
@@ -222,3 +204,4 @@ Amjad Masad | James Kyle | Jesse McCarthy | Sebastian McKenzie |
## License
[MIT](https://github.com/babel/babel/blob/master/LICENSE)

View File

@@ -1,8 +1,16 @@
machine:
node:
version:
0.10.46
6
dependencies:
pre:
- curl -o- -L https://yarnpkg.com/install.sh | bash
cache_directories:
- ~/.yarn-cache
override:
- yarn
test:
override:
- make test-ci
- make test-ci-coverage

View File

@@ -2,12 +2,12 @@
**NOTE:** Compiler support does not dictate the runtime requirements of compiled code.
## Supported environments
## Officially supported environments
The Babel compiler is **only** supported in these environments:
- Modern browsers such as Chrome, Firefox, Safari, Edge etc.
- Node 0.10+
- Node.js 4 and upper versions
## Unsupported environments
@@ -17,7 +17,6 @@ to:
- Rhino
- Nashorn
- Internet Explorer
- ...
**NOTE:** If Babel works in any of the unsupported environments, it is purely
coincidental and has no bearing on future compatibility. Use at your own risk.

View File

@@ -1,6 +1,6 @@
{
"lerna": "2.0.0-beta.23",
"version": "6.24.0",
"lerna": "2.0.0-beta.38",
"version": "7.0.0-alpha.7",
"changelog": {
"repo": "babel/babel",
"labels": {
@@ -13,13 +13,13 @@
"tag: internal": ":house: Internal"
}
},
"bootstrapConfig": {
"ignore": "babel-runtime"
},
"publishConfig": {
"ignore": [
"*.md",
"test/**"
]
"cacheDir": ".changelog",
"commands": {
"publish": {
"ignore": [
"*.md",
"test/**"
]
}
}
}

View File

@@ -581,8 +581,8 @@ declare class BabelNodeDeclareVariable extends BabelNode {
id: any;
}
declare class BabelNodeExistentialTypeParam extends BabelNode {
type: "ExistentialTypeParam";
declare class BabelNodeExistsTypeAnnotation extends BabelNode {
type: "ExistsTypeAnnotation";
}
declare class BabelNodeFunctionTypeAnnotation extends BabelNode {
@@ -632,8 +632,8 @@ declare class BabelNodeNullableTypeAnnotation extends BabelNode {
typeAnnotation: any;
}
declare class BabelNodeNumericLiteralTypeAnnotation extends BabelNode {
type: "NumericLiteralTypeAnnotation";
declare class BabelNodeNumberLiteralTypeAnnotation extends BabelNode {
type: "NumberLiteralTypeAnnotation";
}
declare class BabelNodeNumberTypeAnnotation extends BabelNode {
@@ -873,7 +873,7 @@ type BabelNodeClass = BabelNodeClassDeclaration | BabelNodeClassExpression;
type BabelNodeModuleDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration | BabelNodeImportDeclaration;
type BabelNodeExportDeclaration = BabelNodeExportAllDeclaration | BabelNodeExportDefaultDeclaration | BabelNodeExportNamedDeclaration;
type BabelNodeModuleSpecifier = BabelNodeExportSpecifier | BabelNodeImportDefaultSpecifier | BabelNodeImportNamespaceSpecifier | BabelNodeImportSpecifier | BabelNodeExportDefaultSpecifier | BabelNodeExportNamespaceSpecifier;
type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistentialTypeParam | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumericLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation;
type BabelNodeFlow = BabelNodeAnyTypeAnnotation | BabelNodeArrayTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeBooleanLiteralTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeClassImplements | BabelNodeClassProperty | BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeExistsTypeAnnotation | BabelNodeFunctionTypeAnnotation | BabelNodeFunctionTypeParam | BabelNodeGenericTypeAnnotation | BabelNodeInterfaceExtends | BabelNodeInterfaceDeclaration | BabelNodeIntersectionTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNullableTypeAnnotation | BabelNodeNumberLiteralTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringLiteralTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeTupleTypeAnnotation | BabelNodeTypeofTypeAnnotation | BabelNodeTypeAlias | BabelNodeTypeAnnotation | BabelNodeTypeCastExpression | BabelNodeTypeParameterDeclaration | BabelNodeTypeParameterInstantiation | BabelNodeObjectTypeAnnotation | BabelNodeObjectTypeCallProperty | BabelNodeObjectTypeIndexer | BabelNodeObjectTypeProperty | BabelNodeQualifiedTypeIdentifier | BabelNodeUnionTypeAnnotation | BabelNodeVoidTypeAnnotation;
type BabelNodeFlowBaseAnnotation = BabelNodeAnyTypeAnnotation | BabelNodeBooleanTypeAnnotation | BabelNodeNullLiteralTypeAnnotation | BabelNodeMixedTypeAnnotation | BabelNodeNumberTypeAnnotation | BabelNodeStringTypeAnnotation | BabelNodeThisTypeAnnotation | BabelNodeVoidTypeAnnotation;
type BabelNodeFlowDeclaration = BabelNodeDeclareClass | BabelNodeDeclareFunction | BabelNodeDeclareInterface | BabelNodeDeclareModule | BabelNodeDeclareModuleExports | BabelNodeDeclareTypeAlias | BabelNodeDeclareVariable | BabelNodeInterfaceDeclaration | BabelNodeTypeAlias;
type BabelNodeJSX = BabelNodeJSXAttribute | BabelNodeJSXClosingElement | BabelNodeJSXElement | BabelNodeJSXEmptyExpression | BabelNodeJSXExpressionContainer | BabelNodeJSXIdentifier | BabelNodeJSXMemberExpression | BabelNodeJSXNamespacedName | BabelNodeJSXOpeningElement | BabelNodeJSXSpreadAttribute | BabelNodeJSXText;
@@ -965,7 +965,7 @@ declare module "babel-types" {
declare function declareModuleExports(typeAnnotation: any): BabelNodeDeclareModuleExports;
declare function declareTypeAlias(id: any, typeParameters: any, right: any): BabelNodeDeclareTypeAlias;
declare function declareVariable(id: any): BabelNodeDeclareVariable;
declare function existentialTypeParam(): BabelNodeExistentialTypeParam;
declare function existsTypeAnnotation(): BabelNodeExistsTypeAnnotation;
declare function functionTypeAnnotation(typeParameters: any, params: any, rest: any, returnType: any): BabelNodeFunctionTypeAnnotation;
declare function functionTypeParam(name: any, typeAnnotation: any): BabelNodeFunctionTypeParam;
declare function genericTypeAnnotation(id: any, typeParameters: any): BabelNodeGenericTypeAnnotation;
@@ -974,7 +974,7 @@ declare module "babel-types" {
declare function intersectionTypeAnnotation(types: any): BabelNodeIntersectionTypeAnnotation;
declare function mixedTypeAnnotation(): BabelNodeMixedTypeAnnotation;
declare function nullableTypeAnnotation(typeAnnotation: any): BabelNodeNullableTypeAnnotation;
declare function numericLiteralTypeAnnotation(): BabelNodeNumericLiteralTypeAnnotation;
declare function numberLiteralTypeAnnotation(): BabelNodeNumberLiteralTypeAnnotation;
declare function numberTypeAnnotation(): BabelNodeNumberTypeAnnotation;
declare function stringLiteralTypeAnnotation(): BabelNodeStringLiteralTypeAnnotation;
declare function stringTypeAnnotation(): BabelNodeStringTypeAnnotation;
@@ -1101,7 +1101,7 @@ declare module "babel-types" {
declare function isDeclareModuleExports(node: Object, opts?: Object): boolean;
declare function isDeclareTypeAlias(node: Object, opts?: Object): boolean;
declare function isDeclareVariable(node: Object, opts?: Object): boolean;
declare function isExistentialTypeParam(node: Object, opts?: Object): boolean;
declare function isExistsTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isFunctionTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isFunctionTypeParam(node: Object, opts?: Object): boolean;
declare function isGenericTypeAnnotation(node: Object, opts?: Object): boolean;
@@ -1110,7 +1110,7 @@ declare module "babel-types" {
declare function isIntersectionTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isMixedTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isNullableTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isNumericLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isNumberLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isNumberTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isStringLiteralTypeAnnotation(node: Object, opts?: Object): boolean;
declare function isStringTypeAnnotation(node: Object, opts?: Object): boolean;

View File

@@ -10,16 +10,13 @@
},
"devDependencies": {
"async": "^1.5.0",
"babel-core": "^6.13.2",
"babel-core": "^7.0.0-alpha.6",
"babel-eslint": "^7.0.0",
"babel-plugin-istanbul": "^2.0.1",
"babel-plugin-transform-class-properties": "^6.6.0",
"babel-plugin-transform-flow-strip-types": "^6.3.13",
"babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015": "^6.13.2",
"babel-preset-stage-0": "^6.0.0",
"babel-register": "^6.14.0",
"babel-runtime": "^6.0.0",
"babel-preset-env": "^2.0.0-alpha.3",
"babel-preset-flow": "^7.0.0-alpha.3",
"babel-preset-stage-0": "^7.0.0-alpha.3",
"babel-register": "^7.0.0-alpha.6",
"browserify": "^13.1.1",
"bundle-collapser": "^1.2.1",
"chai": "^3.5.0",
@@ -29,14 +26,14 @@
"eslint": "^3.9.0",
"eslint-config-babel": "^6.0.0",
"eslint-plugin-flowtype": "^2.20.0",
"flow-bin": "^0.34.0",
"flow-bin": "^0.41.0",
"gulp": "^3.9.0",
"gulp-babel": "^6.0.0",
"gulp-babel": "babel/gulp-babel#b7-alpha",
"gulp-newer": "^1.0.0",
"gulp-plumber": "^1.0.1",
"gulp-util": "^3.0.7",
"gulp-watch": "^4.3.5",
"lerna": "2.0.0-beta.23",
"lerna": "^2.0.0-beta.38",
"lerna-changelog": "^0.2.0",
"lodash": "^4.2.0",
"mocha": "^3.0.0",
@@ -48,35 +45,9 @@
"uglify-js": "^2.4.16"
},
"devEngines": {
"node": ">= 0.10 <= 7.x",
"node": ">= 4.x <= 7.x",
"npm": "2.x || 3.x || 4.x"
},
"babel": {
"comments": false,
"presets": [
[
"es2015",
{
"loose": true
}
],
"stage-0"
],
"plugins": [
"./scripts/add-module-exports",
"transform-runtime",
"transform-class-properties",
"transform-flow-strip-types"
],
"env": {
"cov": {
"auxiliaryCommentBefore": "istanbul ignore next",
"plugins": [
"istanbul"
]
}
}
},
"nyc": {
"all": true,
"exclude": [

View File

@@ -1,3 +1,3 @@
src
test
node_modules
*.log

View File

@@ -1 +1 @@
throw new Error("Use the `babel-core` package not `babel`.");
throw new Error("Use the `babel-core` package instead of `babel-cli`.");

View File

@@ -1,6 +1,6 @@
{
"name": "babel-cli",
"version": "6.24.0",
"version": "7.0.0-alpha.7",
"description": "Babel command line.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@@ -16,17 +16,15 @@
"compiler"
],
"dependencies": {
"babel-core": "^6.24.0",
"babel-register": "^6.24.0",
"babel-polyfill": "^6.23.0",
"babel-runtime": "^6.22.0",
"babel-core": "7.0.0-alpha.7",
"babel-register": "7.0.0-alpha.7",
"babel-polyfill": "7.0.0-alpha.7",
"commander": "^2.8.1",
"convert-source-map": "^1.1.0",
"fs-readdir-recursive": "^1.0.0",
"glob": "^7.0.0",
"lodash": "^4.2.0",
"output-file-sync": "^1.1.0",
"path-is-absolute": "^1.0.0",
"slash": "^1.0.0",
"source-map": "^0.5.0",
"v8flags": "^2.0.10"
@@ -35,7 +33,7 @@
"chokidar": "^1.6.1"
},
"devDependencies": {
"babel-helper-fixtures": "^6.22.0"
"babel-helper-fixtures": "^7.0.0-alpha.3"
},
"bin": {
"babel-doctor": "./bin/babel-doctor.js",

View File

@@ -1,3 +0,0 @@
#!/bin/sh
set -e
npm link babel-core

View File

@@ -1,26 +1,36 @@
import pathIsAbsolute from "path-is-absolute";
import commander from "commander";
import Module from "module";
import { inspect } from "util";
import path from "path";
import repl from "repl";
import { util } from "babel-core";
import * as babel from "babel-core";
import vm from "vm";
import "babel-polyfill";
import register from "babel-register";
import pkg from "../package.json";
const program = new commander.Command("babel-node");
function collect(value, previousValue): Array<string> {
// If the user passed the option with no value, like "babel-node file.js --presets", do nothing.
if (typeof value !== "string") return previousValue;
const values = value.split(",");
return previousValue ? previousValue.concat(values) : values;
}
/* eslint-disable max-len */
program.option("-e, --eval [script]", "Evaluate script");
program.option("-p, --print [code]", "Evaluate script and print result");
program.option("-o, --only [globs]", "");
program.option("-i, --ignore [globs]", "");
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
program.option("-w, --plugins [string]", "", util.list);
program.option("-b, --presets [string]", "", util.list);
program.option("-o, --only [globs]", "A comma-separated list of glob patterns to compile", collect);
program.option("-i, --ignore [globs]", "A comma-separated list of glob patterns to skip compiling", collect);
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]", collect);
program.option("-w, --plugins [string]", "", collect);
program.option("-b, --presets [string]", "", collect);
/* eslint-enable max-len */
const pkg = require("../package.json");
program.version(pkg.version);
program.usage("[options] [ -e script | script.js ] [arguments]");
program.parse(process.argv);
@@ -29,10 +39,10 @@ program.parse(process.argv);
register({
extensions: program.extensions,
ignore: program.ignore,
only: program.only,
plugins: program.plugins,
presets: program.presets,
ignore: program.ignore,
only: program.only,
plugins: program.plugins,
presets: program.presets,
});
//
@@ -55,8 +65,8 @@ const replPlugin = ({ types: t }) => ({
// If the executed code doesn't evaluate to a value,
// prevent implicit strict mode from printing 'use strict'.
path.pushContainer("body", t.expressionStatement(t.identifier("undefined")));
}
}
},
},
});
//
@@ -68,11 +78,11 @@ const _eval = function (code, filename) {
code = babel.transform(code, {
filename: filename,
presets: program.presets,
plugins: (program.plugins || []).concat([replPlugin])
plugins: (program.plugins || []).concat([replPlugin]),
}).code;
return vm.runInThisContext(code, {
filename: filename
filename: filename,
});
};
@@ -85,10 +95,10 @@ if (program.eval || program.print) {
const module = new Module(global.__filename);
module.filename = global.__filename;
module.paths = Module._nodeModulePaths(global.__dirname);
module.paths = Module._nodeModulePaths(global.__dirname);
global.exports = module.exports;
global.module = module;
global.module = module;
global.require = module.require.bind(module);
const result = _eval(code, global.__filename);
@@ -123,7 +133,7 @@ if (program.eval || program.print) {
// make the filename absolute
const filename = args[0];
if (!pathIsAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
if (!path.isAbsolute(filename)) args[0] = path.join(process.cwd(), filename);
// add back on node and concat the sliced args
process.argv = ["node"].concat(args);
@@ -141,7 +151,7 @@ function replStart() {
input: process.stdin,
output: process.stdout,
eval: replEval,
useGlobal: true
useGlobal: true,
});
}

View File

@@ -1,7 +1,16 @@
import commander from "commander";
import { util, buildExternalHelpers } from "babel-core";
import { buildExternalHelpers } from "babel-core";
commander.option("-l, --whitelist [whitelist]", "Whitelist of helpers to ONLY include", util.list);
function collect(value, previousValue): Array<string> {
// If the user passed the option with no value, like "babel-external-helpers --whitelist", do nothing.
if (typeof value !== "string") return previousValue;
const values = value.split(",");
return previousValue ? previousValue.concat(values) : values;
}
commander.option("-l, --whitelist [whitelist]", "Whitelist of helpers to ONLY include", collect);
commander.option("-t, --output-type [type]", "Type of output (global|umd|var)", "global");
commander.usage("[options]");

View File

@@ -3,8 +3,8 @@
* when found, before invoking the "real" _babel-node(1) executable.
*/
const getV8Flags = require("v8flags");
const path = require("path");
import getV8Flags from "v8flags";
import path from "path";
let args = [path.join(__dirname, "_babel-node")];
@@ -14,7 +14,7 @@ let userArgs;
// separate node arguments from script arguments
const argSeparator = babelArgs.indexOf("--");
if (argSeparator > -1) {
userArgs = babelArgs.slice(argSeparator); // including the --
userArgs = babelArgs.slice(argSeparator); // including the --
babelArgs = babelArgs.slice(0, argSeparator);
}

View File

@@ -1,21 +1,26 @@
const outputFileSync = require("output-file-sync");
const slash = require("slash");
const path = require("path");
const util = require("./util");
const fs = require("fs");
import defaults from "lodash/defaults";
import outputFileSync from "output-file-sync";
import slash from "slash";
import path from "path";
import fs from "fs";
module.exports = function (commander, filenames) {
import * as util from "./util";
export default function (commander, filenames, opts) {
function write(src, relative) {
if (!util.isCompilableExtension(relative, commander.extensions)) return false;
// remove extension and then append back on .js
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
const dest = path.join(commander.outDir, relative);
const data = util.compile(src, {
const data = util.compile(src, defaults({
sourceFileName: slash(path.relative(dest + "/..", src)),
sourceMapTarget: path.basename(relative)
});
if (!commander.copyFiles && data.ignored) return;
sourceMapTarget: path.basename(relative),
}, opts));
if (!data) return false;
// we've requested explicit sourcemaps to be written to disk
if (data.map && commander.sourceMaps && commander.sourceMaps !== "inline") {
@@ -28,14 +33,14 @@ module.exports = function (commander, filenames) {
util.chmod(src, dest);
util.log(src + " -> " + dest);
return true;
}
function handleFile(src, filename) {
if (util.shouldIgnore(src)) return;
const didWrite = write(src, filename);
if (util.canCompile(filename, commander.extensions)) {
write(src, filename);
} else if (commander.copyFiles) {
if (!didWrite && commander.copyFiles) {
const dest = path.join(commander.outDir, filename);
outputFileSync(dest, fs.readFileSync(src));
util.chmod(src, dest);
@@ -73,7 +78,7 @@ module.exports = function (commander, filenames) {
awaitWriteFinish: {
stabilityThreshold: 50,
pollInterval: 10,
}
},
});
["add", "change"].forEach(function (type) {
@@ -88,4 +93,4 @@ module.exports = function (commander, filenames) {
});
});
}
};
}

View File

@@ -1,11 +1,13 @@
const convertSourceMap = require("convert-source-map");
const sourceMap = require("source-map");
const slash = require("slash");
const path = require("path");
const util = require("./util");
const fs = require("fs");
import convertSourceMap from "convert-source-map";
import defaults from "lodash/defaults";
import sourceMap from "source-map";
import slash from "slash";
import path from "path";
import fs from "fs";
module.exports = function (commander, filenames, opts) {
import * as util from "./util";
export default function (commander, filenames, opts) {
if (commander.sourceMaps === "inline") {
opts.sourceMaps = true;
}
@@ -15,7 +17,7 @@ module.exports = function (commander, filenames, opts) {
const buildResult = function () {
const map = new sourceMap.SourceMapGenerator({
file: path.basename(commander.outFile || "") || "stdout",
sourceRoot: opts.sourceRoot
sourceRoot: opts.sourceRoot,
});
let code = "";
@@ -63,7 +65,7 @@ module.exports = function (commander, filenames, opts) {
return {
map: map,
code: code
code: code,
};
};
@@ -95,9 +97,9 @@ module.exports = function (commander, filenames, opts) {
});
process.stdin.on("end", function () {
results.push(util.transform(commander.filename, code, {
results.push(util.transform(commander.filename, code, defaults({
sourceFileName: "stdin",
}));
}, opts)));
output();
});
};
@@ -122,19 +124,18 @@ module.exports = function (commander, filenames, opts) {
});
_filenames.forEach(function (filename) {
if (util.shouldIgnore(filename)) return;
let sourceFilename = filename;
if (commander.outFile) {
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
}
sourceFilename = slash(sourceFilename);
const data = util.compile(filename, {
const data = util.compile(filename, defaults({
sourceFileName: sourceFilename,
});
}, opts));
if (!data) return;
if (data.ignored) return;
results.push(data);
});
@@ -155,9 +156,9 @@ module.exports = function (commander, filenames, opts) {
awaitWriteFinish: {
stabilityThreshold: 50,
pollInterval: 10,
}
},
}).on("all", function (type, filename) {
if (util.shouldIgnore(filename) || !util.canCompile(filename, commander.extensions)) return;
if (!util.isCompilableExtension(filename, commander.extensions)) return;
if (type === "add" || type === "change") {
util.log(type + " " + filename);
@@ -176,4 +177,4 @@ module.exports = function (commander, filenames, opts) {
} else {
stdin();
}
};
}

View File

@@ -1,42 +1,73 @@
#!/usr/bin/env node
const fs = require("fs");
const commander = require("commander");
const kebabCase = require("lodash/kebabCase");
const options = require("babel-core").options;
const util = require("babel-core").util;
const uniq = require("lodash/uniq");
const glob = require("glob");
import fs from "fs";
import commander from "commander";
import { version } from "babel-core";
import uniq from "lodash/uniq";
import glob from "glob";
Object.keys(options).forEach(function (key) {
const option = options[key];
if (option.hidden) return;
import dirCommand from "./dir";
import fileCommand from "./file";
let arg = kebabCase(key);
import pkg from "../../package.json";
if (option.type !== "boolean") {
arg += " [" + (option.type || "string") + "]";
function booleanify(val: any): boolean | any {
if (val === "true" || val == 1) {
return true;
}
if (option.type === "boolean" && option.default === true) {
arg = "no-" + arg;
if (val === "false" || val == 0 || !val) {
return false;
}
arg = "--" + arg;
return val;
}
if (option.shorthand) {
arg = "-" + option.shorthand + ", " + arg;
}
function collect(value, previousValue): Array<string> {
// If the user passed the option with no value, like "babel file.js --presets", do nothing.
if (typeof value !== "string") return previousValue;
const desc = [];
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
if (option.description) desc.push(option.description);
const values = value.split(",");
commander.option(arg, desc.join(" "));
});
return previousValue ? previousValue.concat(values) : values;
}
/* eslint-disable max-len */
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
// Standard Babel input configs.
commander.option("-f, --filename [filename]", "filename to use when reading from stdin - this will be used in source-maps, errors etc");
commander.option("--presets [list]", "comma-separated list of preset names", collect);
commander.option("--plugins [list]", "comma-separated list of plugin names", collect);
// Basic file input configuration.
commander.option("--source-type [script|module]", "");
commander.option("--no-babelrc", "Whether or not to look up .babelrc and .babelignore files");
commander.option("--ignore [list]", "list of glob paths to **not** compile", collect);
commander.option("--only [list]", "list of glob paths to **only** compile", collect);
// Misc babel config.
commander.option("--no-highlight-code", "enable/disable ANSI syntax highlighting of code frames (on by default)");
// General output formatting.
commander.option("--no-comments", "write comments to generated output (true by default)");
commander.option("--retain-lines", "retain line numbers - will result in really ugly code");
commander.option("--compact [true|false|auto]", "do not include superfluous whitespace characters and line terminators", booleanify);
commander.option("--minified", "save as much bytes when printing [true|false]");
commander.option("--auxiliary-comment-before [string]", "print a comment before any injected non-user code");
commander.option("--auxiliary-comment-after [string]", "print a comment after any injected non-user code");
// General soucemap formatting.
commander.option("-s, --source-maps [true|false|inline|both]", "", booleanify);
commander.option("--source-map-target [string]", "set `file` on returned source map");
commander.option("--source-file-name [string]", "set `sources[0]` on returned source map");
commander.option("--source-root [filename]", "the root from which all sources are relative");
// Config params for certain module output formats.
commander.option("--module-root [filename]", "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions");
commander.option("-M, --module-ids", "insert an explicit id for modules");
commander.option("--module-id [string]", "specify a custom name for module ids");
// "babel" command specific arguments that are not passed to babel-core.
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]", collect);
commander.option("-w, --watch", "Recompile files on changes");
commander.option("--skip-initial-build", "Do not compile files before watching");
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
@@ -45,19 +76,12 @@ commander.option("-D, --copy-files", "When compiling a directory copy over non-c
commander.option("-q, --quiet", "Don't log anything");
/* eslint-enable max-len */
const pkg = require("../../package.json");
commander.version(pkg.version + " (babel-core " + require("babel-core").version + ")");
commander.version(pkg.version + " (babel-core " + version + ")");
commander.usage("[options] <files ...>");
commander.parse(process.argv);
//
if (commander.extensions) {
commander.extensions = util.arrayify(commander.extensions);
}
//
const errors = [];
let filenames = commander.args.reduce(function (globbed, input) {
@@ -103,27 +127,23 @@ if (errors.length) {
//
const opts = exports.opts = {};
const opts = commander.opts();
Object.keys(options).forEach(function (key) {
const opt = options[key];
if (commander[key] !== undefined && commander[key] !== opt.default) {
opts[key] = commander[key];
}
});
// Delete options that are specific to babel-cli and shouldn't be passed to babel-core.
delete opts.version;
delete opts.extensions;
delete opts.watch;
delete opts.skipInitialBuild;
delete opts.outFile;
delete opts.outDir;
delete opts.copyFiles;
delete opts.quiet;
opts.ignore = util.arrayify(opts.ignore, util.regexify);
// Commander will default the "--no-" arguments to true, but we want to leave them undefined so that
// babel-core can handle the default-assignment logic on its own.
if (opts.babelrc === true) opts.babelrc = undefined;
if (opts.comments === true) opts.comments = undefined;
if (opts.highlightCode === true) opts.highlightCode = undefined;
if (opts.only) {
opts.only = util.arrayify(opts.only, util.regexify);
}
let fn;
if (commander.outDir) {
fn = require("./dir");
} else {
fn = require("./file");
}
fn(commander, filenames, exports.opts);
const fn = commander.outDir ? dirCommand : fileCommand;
fn(commander, filenames, opts);

View File

@@ -1,11 +1,9 @@
const commander = require("commander");
const defaults = require("lodash/defaults");
const readdir = require("fs-readdir-recursive");
const index = require("./index");
const babel = require("babel-core");
const util = require("babel-core").util;
const path = require("path");
const fs = require("fs");
import commander from "commander";
import readdir from "fs-readdir-recursive";
import * as babel from "babel-core";
import includes from "lodash/includes";
import path from "path";
import fs from "fs";
export function chmod(src, dest) {
fs.chmodSync(dest, fs.statSync(src).mode);
@@ -13,16 +11,19 @@ export function chmod(src, dest) {
export function readdirFilter(filename) {
return readdir(filename).filter(function (filename) {
return util.canCompile(filename);
return babel.util.isCompilableExtension(filename);
});
}
export { readdir };
export const canCompile = util.canCompile;
export function shouldIgnore(loc) {
return util.shouldIgnore(loc, index.opts.ignore, index.opts.only);
/**
* Test if a filename ends with a compilable extension.
*/
export function isCompilableExtension(filename: string, altExts?: Array<string>): boolean {
const exts = altExts || babel.DEFAULT_EXTENSIONS;
const ext = path.extname(filename);
return includes(exts, ext);
}
export function addSourceMappingUrl(code, loc) {
@@ -34,19 +35,16 @@ export function log(msg) {
}
export function transform(filename, code, opts) {
opts = defaults(opts || {}, index.opts);
opts.filename = filename;
opts = Object.assign({}, opts, {
filename,
});
const result = babel.transform(code, opts);
result.filename = filename;
result.actual = code;
return result;
return babel.transform(code, opts);
}
export function compile(filename, opts) {
try {
const code = fs.readFileSync(filename, "utf8");
return transform(filename, code, opts);
return babel.transformFileSync(filename, opts);
} catch (err) {
if (commander.watch) {
console.error(toErrorStack(err));

View File

@@ -0,0 +1 @@
index;

View File

@@ -0,0 +1,8 @@
{
"args": [
"src",
"--out-dir", "lib",
"--copy-files",
"--ignore", "src/foo/*"
]
}

View File

@@ -0,0 +1,3 @@
"use strict";
index;

View File

@@ -0,0 +1 @@
src/index.js -> lib/index.js

View File

@@ -0,0 +1 @@
index;

View File

@@ -0,0 +1,8 @@
{
"args": [
"src",
"--out-dir", "lib",
"--copy-files",
"--only", "src/foo/*"
]
}

View File

@@ -0,0 +1,3 @@
"use strict";
bar;

View File

@@ -0,0 +1 @@
index;

View File

@@ -0,0 +1 @@
src/foo/bar.js -> lib/foo/bar.js

View File

@@ -0,0 +1 @@
bar;

View File

@@ -0,0 +1,3 @@
{
"args": ["src", "--out-dir", "lib", "--copy-files"]
}

View File

@@ -0,0 +1,3 @@
"use strict";
bar;

View File

@@ -0,0 +1 @@
"use strict";

View File

@@ -0,0 +1,2 @@
src/bar/index.js -> lib/bar/index.js
src/foo/foo.js -> lib/foo/foo.js

View File

@@ -1,3 +1,3 @@
{
"args": ["src", "--out-dir", "lib", "--ignore", "/bar/*"]
"args": ["src", "--out-dir", "lib", "--ignore", "src/bar"]
}

View File

@@ -0,0 +1 @@
a.foo;

View File

@@ -0,0 +1 @@
a;

View File

@@ -0,0 +1 @@
b;

View File

@@ -0,0 +1 @@
b.foo;

View File

@@ -0,0 +1 @@
c;

View File

@@ -0,0 +1 @@
foo;

View File

@@ -0,0 +1,3 @@
{
"args": ["src", "--out-dir", "lib", "--ignore", "**/*.foo.js"]
}

View File

@@ -0,0 +1,3 @@
"use strict";
a;

View File

@@ -0,0 +1,3 @@
"use strict";
b;

View File

@@ -0,0 +1,3 @@
"use strict";
c;

View File

@@ -0,0 +1,3 @@
"use strict";
foo;

View File

@@ -0,0 +1,4 @@
src/a.js -> lib/a.js
src/b.js -> lib/b.js
src/baz/c.js -> lib/baz/c.js
src/foo.js -> lib/foo.js

View File

@@ -0,0 +1 @@
a.foo;

View File

@@ -0,0 +1 @@
a;

View File

@@ -0,0 +1 @@
b;

View File

@@ -0,0 +1 @@
b.foo;

View File

@@ -0,0 +1 @@
c;

View File

@@ -0,0 +1 @@
foo;

View File

@@ -0,0 +1,3 @@
{
"args": ["src", "--out-dir", "lib", "--only", "**/*.foo.js"]
}

View File

@@ -0,0 +1,3 @@
"use strict";
a.foo;

View File

@@ -0,0 +1,3 @@
"use strict";
b.foo;

View File

@@ -0,0 +1,2 @@
src/a.foo.js -> lib/a.foo.js
src/baz/b.foo.js -> lib/baz/b.foo.js

View File

@@ -5,4 +5,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var Test = function Test() {
_classCallCheck(this, Test);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7SUFBTUEsSSIsImZpbGUiOiJiYXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSJdfQ==
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7SUFBTUEsSSIsImZpbGUiOiJiYXIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjbGFzcyBUZXN0IHtcblxufSJdfQ==

View File

@@ -3,4 +3,4 @@
arr.map(function (x) {
return x * MULTIPLIER;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6ImZvby5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6ImZvby5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19

View File

@@ -4,4 +4,4 @@ arr.map(function (x) {
return x * MULTIPLIER;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLElBQUksR0FBSixDQUFRO0FBQUEsU0FBSyxJQUFJLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLElBQUksR0FBSixDQUFRO0FBQUEsU0FBSyxJQUFJLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIE1VTFRJUExJRVIpOyJdfQ==

View File

@@ -1,3 +1,3 @@
{
"inlineSourceMap": true
"sourceMap": "inline"
}

View File

@@ -4,4 +4,4 @@ var foo = function foo() {
return 4;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsVUFBVSxlO1MsQUFBTTtBQUFDIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgZm9vID0gKCkgPT4gNDsiXX0=
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm9yaWdpbmFsLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsVUFBVSxlO1MsQUFBTTtBQUFDIiwiZmlsZSI6InNjcmlwdDIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgZm9vID0gKCkgPT4gNDsiXX0=

View File

@@ -11,4 +11,4 @@ arr.map(function (x) {
return x * MULTIPLIER;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7O0FDQU4sSUFBSSxHQUFKLENBQVE7QUFBQSxTQUFLLElBQUksVUFBVDtBQUFBLENBQVIiLCJmaWxlIjoic2NyaXB0My5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59IiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0=
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyIsInNjcmlwdDIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7OztJQUFNLEk7Ozs7O0FDQU4sSUFBSSxHQUFKLENBQVE7QUFBQSxTQUFLLElBQUksVUFBVDtBQUFBLENBQVIiLCJmaWxlIjoic2NyaXB0My5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59IiwiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0=

View File

@@ -1,21 +1,25 @@
const includes = require("lodash/includes");
const readdir = require("fs-readdir-recursive");
const helper = require("babel-helper-fixtures");
const assert = require("assert");
const rimraf = require("rimraf");
const includes = require("lodash/includes");
const readdir = require("fs-readdir-recursive");
const helper = require("babel-helper-fixtures");
const assert = require("assert");
const rimraf = require("rimraf");
const outputFileSync = require("output-file-sync");
const child = require("child_process");
const merge = require("lodash/merge");
const path = require("path");
const chai = require("chai");
const fs = require("fs");
const child = require("child_process");
const merge = require("lodash/merge");
const path = require("path");
const chai = require("chai");
const fs = require("fs");
const fixtureLoc = path.join(__dirname, "fixtures");
const tmpLoc = path.join(__dirname, "tmp");
const fileFilter = function(x) {
return x !== ".DS_Store";
};
const presetLocs = [
path.join(__dirname, "../../babel-preset-es2015"),
path.join(__dirname, "../../babel-preset-react")
path.join(__dirname, "../../babel-preset-react"),
].join(",");
const pluginLocs = [
@@ -23,10 +27,10 @@ const pluginLocs = [
path.join(__dirname, "/../../babel-plugin-transform-es2015-modules-commonjs"),
].join(",");
const readDir = function (loc) {
const readDir = function (loc, filter) {
const files = {};
if (fs.existsSync(loc)) {
readdir(loc).forEach(function (filename) {
readdir(loc, filter).forEach(function (filename) {
files[filename] = helper.readFile(path.join(loc, filename));
});
}
@@ -34,6 +38,9 @@ const readDir = function (loc) {
};
const saveInFiles = function (files) {
// Place an empty .babelrc in each test so tests won't unexpectedly get to repo-level config.
outputFileSync(".babelrc", "{}");
Object.keys(files).forEach(function (filename) {
const content = files[filename];
outputFileSync(filename, content);
@@ -70,11 +77,27 @@ const assertTest = function (stdout, stderr, opts) {
throw new Error("stdout:\n" + stdout);
}
Object.keys(opts.outFiles, function (filename) {
const expect = opts.outFiles[filename];
const actual = helper.readFile(filename);
chai.expect(actual).to.equal(expect, "out-file " + filename);
});
if (opts.outFiles) {
const actualFiles = readDir(path.join(tmpLoc));
Object.keys(actualFiles).forEach(function (filename) {
if (!opts.inFiles.hasOwnProperty(filename)) {
const expect = opts.outFiles[filename];
const actual = actualFiles[filename];
chai.expect(expect, "Output is missing: " + filename).to.not.be.undefined;
if (expect) {
chai.expect(actual).to.equal(expect, "Compiled output does not match: " + filename);
}
}
});
Object.keys(opts.outFiles).forEach(function(filename) {
chai.expect(actualFiles, "Extraneous file in output: " + filename)
.to.contain.key(filename);
});
}
};
const buildTest = function (binName, testName, opts) {
@@ -91,7 +114,7 @@ const buildTest = function (binName, testName, opts) {
}
if (binName === "babel-node") {
args.push("--only", "packages/*/test");
args.push("--only", "../../../../packages/*/test");
}
args = args.concat(opts.args);
@@ -119,7 +142,7 @@ const buildTest = function (binName, testName, opts) {
}
if (err) {
err.message = args.join(" ") + ": " + err.message;
err.message = args.map((arg) => `"${ arg }"`).join(" ") + ": " + err.message;
}
callback(err);
@@ -150,7 +173,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
const testLoc = path.join(suiteLoc, testName);
const opts = {
args: []
args: [],
};
const optionsLoc = path.join(testLoc, "options.json");
@@ -165,8 +188,8 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
}
});
opts.outFiles = readDir(path.join(testLoc, "out-files"));
opts.inFiles = readDir(path.join(testLoc, "in-files"));
opts.outFiles = readDir(path.join(testLoc, "out-files"), fileFilter);
opts.inFiles = readDir(path.join(testLoc, "in-files"), fileFilter);
const babelrcLoc = path.join(testLoc, ".babelrc");
if (fs.existsSync(babelrcLoc)) {

View File

@@ -1,3 +1,3 @@
src
test
node_modules
*.log

View File

@@ -1,6 +1,6 @@
{
"name": "babel-code-frame",
"version": "6.22.0",
"version": "7.0.0-alpha.3",
"description": "Generate errors that contain a code frame that point to source locations.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",

View File

@@ -8,18 +8,18 @@ import Chalk from "chalk";
function getDefs(chalk) {
return {
keyword: chalk.cyan,
keyword: chalk.cyan,
capitalized: chalk.yellow,
jsx_tag: chalk.yellow,
punctuator: chalk.yellow,
jsx_tag: chalk.yellow,
punctuator: chalk.yellow,
// bracket: intentionally omitted.
number: chalk.magenta,
string: chalk.green,
regex: chalk.magenta,
comment: chalk.grey,
invalid: chalk.white.bgRed.bold,
gutter: chalk.grey,
marker: chalk.red.bold,
number: chalk.magenta,
string: chalk.green,
regex: chalk.magenta,
comment: chalk.grey,
invalid: chalk.white.bgRed.bold,
gutter: chalk.grey,
marker: chalk.red.bold,
};
}
@@ -117,7 +117,7 @@ export default function (
const lines = rawLines.split(NEWLINE);
let start = Math.max(lineNumber - (linesAbove + 1), 0);
let end = Math.min(lines.length, lineNumber + linesBelow);
let end = Math.min(lines.length, lineNumber + linesBelow);
if (!lineNumber && !colNumber) {
start = 0;
@@ -138,14 +138,14 @@ export default function (
"\n ",
maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")),
markerSpacing,
maybeHighlight(defs.marker, "^")
maybeHighlight(defs.marker, "^"),
].join("");
}
return [
maybeHighlight(defs.marker, ">"),
maybeHighlight(defs.gutter, gutter),
line,
markerLine
markerLine,
].join("");
} else {
return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;

View File

@@ -55,7 +55,7 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
"}"
"}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2), [
" 5 | * @param b Number",
@@ -80,7 +80,7 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
"}"
"}",
].join("\n");
assert.equal(codeFrame(rawLines, 6, 2), [
" 4 | * @param a Number",
@@ -130,7 +130,7 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
"}"
"}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1 }), [
" 6 | * @returns Number",
@@ -154,14 +154,14 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
"}"
"}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2, { linesBelow: 1 }), [
" 5 | * @param b Number",
" 6 | * @returns Number",
"> 7 | */",
" | ^",
" 8 | "
" 8 | ",
].join("\n"));
});
@@ -177,13 +177,13 @@ describe("babel-code-frame", function () {
"",
"function sum(a, b) {",
" return a + b",
"}"
"}",
].join("\n");
assert.equal(codeFrame(rawLines, 7, 2, { linesAbove: 1, linesBelow: 1 }), [
" 6 | * @returns Number",
"> 7 | */",
" | ^",
" 8 | "
" 8 | ",
].join("\n"));
});
@@ -195,13 +195,13 @@ describe("babel-code-frame", function () {
"",
"",
"",
""
"",
].join("\n");
assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }),
chalk.reset([
" " + gutter(" 2 | "),
marker(">") + gutter(" 3 | "),
" " + gutter(" 4 | ")
" " + gutter(" 4 | "),
].join("\n"))
);
});

View File

@@ -1,13 +1,3 @@
src
test
*.log
*.cache
.*
/lib/transformation/templates
/test
/dist
/tests.json
/CHANGELOG.md
/.package.json
/packages
/scripts
/src
_babel.github.io

View File

@@ -1 +1 @@
module.exports = require("./lib/api/node.js");
module.exports = require("./lib/index.js");

View File

@@ -1,6 +1,6 @@
{
"name": "babel-core",
"version": "6.24.0",
"version": "7.0.0-alpha.7",
"description": "Babel compiler core.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
@@ -21,34 +21,32 @@
"babel-core",
"compiler"
],
"scripts": {
"bench": "make bench",
"test": "make test"
"browser": {
"./lib/config/loading/files/index.js": "./lib/config/loading/files/index-browser.js"
},
"dependencies": {
"babel-code-frame": "^6.22.0",
"babel-generator": "^6.24.0",
"babel-helpers": "^6.23.0",
"babel-messages": "^6.23.0",
"babel-template": "^6.23.0",
"babel-runtime": "^6.22.0",
"babel-register": "^6.24.0",
"babel-traverse": "^6.23.1",
"babel-types": "^6.23.0",
"babylon": "^6.11.0",
"babel-code-frame": "7.0.0-alpha.3",
"babel-generator": "7.0.0-alpha.7",
"babel-helpers": "7.0.0-alpha.7",
"babel-messages": "7.0.0-alpha.3",
"babel-template": "7.0.0-alpha.7",
"babel-traverse": "7.0.0-alpha.7",
"babel-types": "7.0.0-alpha.7",
"babylon": "7.0.0-beta.8",
"convert-source-map": "^1.1.0",
"debug": "^2.1.1",
"json5": "^0.5.0",
"lodash": "^4.2.0",
"minimatch": "^3.0.2",
"path-is-absolute": "^1.0.0",
"micromatch": "^2.3.11",
"private": "^0.1.6",
"resolve": "^1.3.2",
"slash": "^1.0.0",
"source-map": "^0.5.0"
},
"devDependencies": {
"babel-helper-fixtures": "^6.22.0",
"babel-helper-transform-fixture-test-runner": "^6.24.0",
"babel-polyfill": "^6.23.0"
"babel-helper-fixtures": "^7.0.0-alpha.3",
"babel-helper-transform-fixture-test-runner": "7.0.0-alpha.7",
"babel-polyfill": "7.0.0-alpha.7",
"babel-register": "7.0.0-alpha.7"
}
}

View File

@@ -1,3 +1 @@
/* eslint max-len: 0 */
// TODO: eventually deprecate this console.trace("use the `babel-register` package instead of `babel-core/register`");
module.exports = require("babel-register");
throw new Error("`babel-core/register` has been moved to `babel-register`.");

View File

@@ -1,112 +0,0 @@
/* eslint max-len: 0 */
/* eslint no-new-func: 0 */
import { transform } from "./node";
export {
File,
options,
buildExternalHelpers,
template,
version,
util,
messages,
types,
traverse,
OptionManager,
Plugin,
Pipeline,
analyse,
transform,
transformFromAst,
transformFile,
transformFileSync
} from "./node";
export function run(code: string, opts: Object = {}): any {
return new Function(transform(code, opts).code)();
}
export function load(url: string, callback: Function, opts: Object = {}, hold?: boolean) {
opts.filename = opts.filename || url;
const xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
xhr.open("GET", url, true);
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) return;
const status = xhr.status;
if (status === 0 || status === 200) {
const param = [xhr.responseText, opts];
if (!hold) run(param);
if (callback) callback(param);
} else {
throw new Error(`Could not load ${url}`);
}
};
xhr.send(null);
}
function runScripts() {
const scripts: Array<Array<any> | Object> = [];
const types = ["text/ecmascript-6", "text/6to5", "text/babel", "module"];
let index = 0;
/**
* Transform and execute script. Ensures correct load order.
*/
function exec() {
const param = scripts[index];
if (param instanceof Array) {
run(param, index);
index++;
exec();
}
}
/**
* Load, transform, and execute all scripts.
*/
function run(script: Object, i: number) {
const opts = {};
if (script.src) {
load(script.src, function (param) {
scripts[i] = param;
exec();
}, opts, true);
} else {
opts.filename = "embedded";
scripts[i] = [script.innerHTML, opts];
}
}
// Collect scripts with Babel `types`.
const _scripts = global.document.getElementsByTagName("script");
for (let i = 0; i < _scripts.length; ++i) {
const _script = _scripts[i];
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
}
for (let i = 0; i < scripts.length; i++) {
run(scripts[i], i);
}
exec();
}
/**
* Register load event to transform and execute scripts.
*/
if (global.addEventListener) {
global.addEventListener("DOMContentLoaded", runScripts, false);
} else if (global.attachEvent) {
global.attachEvent("onload", runScripts);
}

View File

@@ -1,68 +0,0 @@
import fs from "fs";
export { default as File } from "../transformation/file";
export { default as options } from "../transformation/file/options/config";
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
export { default as template } from "babel-template";
export { default as resolvePlugin } from "../helpers/resolve-plugin";
export { default as resolvePreset } from "../helpers/resolve-preset";
export { version } from "../../package";
import * as util from "../util";
export { util };
import * as messages from "babel-messages";
export { messages };
import * as t from "babel-types";
export { t as types };
import traverse from "babel-traverse";
export { traverse };
import OptionManager from "../transformation/file/options/option-manager";
export { OptionManager };
export function Plugin(alias) {
throw new Error(`The (${alias}) Babel 5 plugin is being run with Babel 6.`);
}
import Pipeline from "../transformation/pipeline";
export { Pipeline };
const pipeline = new Pipeline;
export const analyse = pipeline.analyse.bind(pipeline);
export const transform = pipeline.transform.bind(pipeline);
export const transformFromAst = pipeline.transformFromAst.bind(pipeline);
export function transformFile(filename: string, opts?: Object, callback: Function) {
if (typeof opts === "function") {
callback = opts;
opts = {};
}
opts.filename = filename;
fs.readFile(filename, function (err, code) {
let result;
if (!err) {
try {
result = transform(code, opts);
} catch (_err) {
err = _err;
}
}
if (err) {
callback(err);
} else {
callback(null, result);
}
});
}
export function transformFileSync(filename: string, opts?: Object = {}): string {
opts.filename = filename;
return transform(fs.readFileSync(filename, "utf8"), opts);
}

View File

@@ -0,0 +1,187 @@
import * as babel from "../index";
import path from "path";
import micromatch from "micromatch";
import { findConfigs, loadConfig } from "./loading/files";
export default function buildConfigChain(opts: Object = {}) {
const filename = opts.filename ? path.resolve(opts.filename) : null;
const builder = new ConfigChainBuilder(filename);
try {
builder.mergeConfig({
type: "arguments",
options: opts,
alias: "base",
dirname: process.cwd(),
});
// resolve all .babelrc files
if (opts.babelrc !== false) {
builder.findConfigs(filename);
}
} catch (e) {
if (e.code !== "BABEL_IGNORED_FILE") throw e;
return null;
}
return builder.configs.reverse();
}
class ConfigChainBuilder {
constructor(filename) {
this.configs = [];
this.filename = filename;
this.possibleDirs = null;
}
/**
* Tests if a filename should be ignored based on "ignore" and "only" options.
*/
shouldIgnore(
ignore: Array<string | RegExp | Function>,
only?: Array<string | RegExp | Function>,
dirname: string,
): boolean {
if (!this.filename) return false;
if (ignore) {
if (!Array.isArray(ignore)) {
throw new Error(`.ignore should be an array, was ${JSON.stringify(ignore)}`);
}
for (const pattern of ignore) {
if (this.matchesPattern(pattern, dirname)) return true;
}
}
if (only) {
if (!Array.isArray(only)) {
throw new Error(`.only should be an array, was ${JSON.stringify(only)}`);
}
for (const pattern of only) {
if (this.matchesPattern(pattern, dirname)) return false;
}
return true;
}
return false;
}
/**
* Returns result of calling function with filename if pattern is a function.
* Otherwise returns result of matching pattern Regex with filename.
*/
matchesPattern(pattern: string | Function | RegExp, dirname: string) {
if (typeof pattern === "string") {
// Lazy-init so we don't initialize this for files that have no glob patterns.
if (!this.possibleDirs) {
this.possibleDirs = [];
if (this.filename) {
this.possibleDirs.push(this.filename);
let current = this.filename;
while (true) {
const previous = current;
current = path.dirname(current);
if (previous === current) break;
this.possibleDirs.push(current);
}
}
}
return this.possibleDirs.some(micromatch.filter(path.resolve(dirname, pattern), {
nocase: true,
nonegate: true,
}));
} else if (typeof pattern === "function") {
return pattern(this.filename);
} else {
return pattern.test(this.filename);
}
}
findConfigs(loc: string) {
if (!loc) return;
if (!path.isAbsolute(loc)) {
loc = path.join(process.cwd(), loc);
}
findConfigs(path.dirname(loc)).forEach(({ filepath, dirname, options }) => {
this.mergeConfig({
type: "options",
options,
alias: filepath,
dirname,
});
});
}
mergeConfig({
type,
options,
alias,
loc,
dirname,
}) {
if (!options) {
return false;
}
// Bail out ASAP if this file is ignored so that we run as little logic as possible on ignored files.
if (this.filename && this.shouldIgnore(options.ignore, options.only, dirname)) {
// TODO(logan): This is a really cross way to bail out. Avoid this in rewrite.
throw Object.assign(new Error("This file has been ignored."), { code: "BABEL_IGNORED_FILE" });
}
options = Object.assign({}, options);
loc = loc || alias;
// env
const envKey = babel.getEnv();
if (options.env) {
const envOpts = options.env[envKey];
delete options.env;
this.mergeConfig({
type,
options: envOpts,
alias: `${alias}.env.${envKey}`,
dirname: dirname,
});
}
this.configs.push({
type,
options,
alias,
loc,
dirname,
});
// add extends clause
if (options.extends) {
const extendsConfig = loadConfig(options.extends, dirname);
const existingConfig = this.configs.some((config) => {
return config.alias === extendsConfig.filepath;
});
if (!existingConfig) {
this.mergeConfig({
type: "options",
alias: extendsConfig.filepath,
options: extendsConfig.options,
dirname: extendsConfig.dirname,
});
}
delete options.extends;
}
}
}

View File

@@ -0,0 +1,6 @@
export function getEnv(defaultValue = "development") {
return process.env.BABEL_ENV
|| process.env.NODE_ENV
|| defaultValue;
}

View File

@@ -0,0 +1,30 @@
import type Plugin from "./plugin";
import OptionManager from "./option-manager";
export type ResolvedConfig = {
options: Object,
passes: Array<Array<Plugin>>,
};
/**
* Standard API for loading Babel configuration data. Not for public consumption.
*/
export default function loadConfig(opts: Object): ResolvedConfig|null {
const mergedOpts = new OptionManager().init(opts);
if (!mergedOpts) return null;
let passes = [];
if (mergedOpts.plugins) {
passes.push(mergedOpts.plugins);
}
// With "passPerPreset" enabled there may still be presets in the options.
if (mergedOpts.presets) {
passes = passes.concat(mergedOpts.presets.map((preset) => preset.plugins).filter(Boolean));
}
return {
options: mergedOpts,
passes,
};
}

View File

@@ -0,0 +1,175 @@
// @flow
import path from "path";
import fs from "fs";
import json5 from "json5";
import resolve from "resolve";
type ConfigFile = {
filepath: string,
dirname: string,
options: Object,
};
const existsCache = {};
const jsonCache = {};
const BABELRC_FILENAME = ".babelrc";
const BABELRC_JS_FILENAME = ".babelrc.js";
const PACKAGE_FILENAME = "package.json";
const BABELIGNORE_FILENAME = ".babelignore";
function exists(filename) {
const cached = existsCache[filename];
if (cached == null) {
return existsCache[filename] = fs.existsSync(filename);
} else {
return cached;
}
}
export function findConfigs(dirname: string): Array<ConfigFile> {
let foundConfig = false;
let foundIgnore = false;
const confs = [];
let loc = dirname;
while (true) {
if (!foundIgnore) {
const ignoreLoc = path.join(loc, BABELIGNORE_FILENAME);
const ignore = readIgnoreConfig(ignoreLoc);
if (ignore) {
confs.push(ignore);
foundIgnore = true;
}
}
if (!foundConfig) {
const conf = [
BABELRC_FILENAME,
BABELRC_JS_FILENAME,
PACKAGE_FILENAME,
].reduce((previousConfig: ConfigFile|null, name) => {
const filepath = path.join(loc, name);
const config = readConfig(filepath);
if (config && previousConfig) {
throw new Error(`Multiple configuration files found. Please remove one:\n- ${
path.basename(previousConfig.filepath)}\n- ${name}\nfrom ${loc}`);
}
return config || previousConfig;
}, null);
if (conf) {
confs.push(conf);
foundConfig = true;
}
}
if (foundIgnore && foundConfig) break;
if (loc === path.dirname(loc)) break;
loc = path.dirname(loc);
}
return confs;
}
export function loadConfig(name: string, dirname: string): ConfigFile {
const filepath = resolve.sync(name, { basedir: dirname });
const conf = readConfig(filepath);
if (!conf) throw new Error(`Config file ${filepath} contains no configuration data`);
return conf;
}
/**
* Read the given config file, returning the result. Returns null if no config was found, but will
* throw if there are parsing errors while loading a config.
*/
function readConfig(filepath) {
return (path.extname(filepath) === ".js") ? readConfigJS(filepath) : readConfigFile(filepath);
}
function readIgnoreConfig(filepath) {
if (!exists(filepath)) return null;
const file = fs.readFileSync(filepath, "utf8");
let lines = file.split("\n");
lines = lines
.map((line) => line.replace(/#(.*?)$/, "").trim())
.filter((line) => !!line);
return {
filepath,
dirname: path.dirname(filepath),
options: { ignore: lines },
};
}
function readConfigJS(filepath) {
if (!exists(filepath)) return null;
let options;
try {
// $FlowIssue
const configModule = (require(filepath): mixed);
options = configModule && configModule.__esModule ? (configModule.default || undefined) : configModule;
} catch (err) {
err.message = `${filepath}: Error while loading config - ${err.message}`;
throw err;
}
if (!options || typeof options !== "object" || Array.isArray(options)) {
throw new Error(`${filepath}: Configuration should be an exported JavaScript object.`);
}
return {
filepath,
dirname: path.dirname(filepath),
options,
};
}
function readConfigFile(filepath) {
if (!exists(filepath)) return null;
const content = fs.readFileSync(filepath, "utf8");
let options;
if (path.basename(filepath) === PACKAGE_FILENAME) {
try {
const json = jsonCache[content] = jsonCache[content] || JSON.parse(content);
options = json.babel;
} catch (err) {
err.message = `${filepath}: Error while parsing JSON - ${err.message}`;
throw err;
}
if (!options) return null;
} else {
try {
options = jsonCache[content] = jsonCache[content] || json5.parse(content);
} catch (err) {
err.message = `${filepath}: Error while parsing config - ${err.message}`;
throw err;
}
if (!options) throw new Error(`${filepath}: No config detected`);
}
if (typeof options !== "object") throw new Error(`${filepath}: Config returned typeof ${typeof options}`);
if (Array.isArray(options)) throw new Error(`${filepath}: Expected config object but found array`);
return {
filepath,
dirname: path.dirname(filepath),
options,
};
}

View File

@@ -0,0 +1,42 @@
// @flow
type ConfigFile = {
filepath: string,
dirname: string,
options: Object,
};
// eslint-disable-next-line no-unused-vars
export function findConfigs(dirname: string): Array<ConfigFile> {
return [];
}
export function loadConfig(name: string, dirname: string): ConfigFile {
throw new Error(`Cannot load ${name} relative to ${dirname} in a browser`);
}
// eslint-disable-next-line no-unused-vars
export function resolvePlugin(name: string, dirname: string): string|null {
return null;
}
// eslint-disable-next-line no-unused-vars
export function resolvePreset(name: string, dirname: string): string|null {
return null;
}
export function loadPlugin(name: string, dirname: string): { filepath: string, plugin: mixed } {
throw new Error(`Cannot load plugin ${name} relative to ${dirname} in a browser`);
}
export function loadPreset(name: string, dirname: string): { filepath: string, preset: mixed } {
throw new Error(`Cannot load preset ${name} relative to ${dirname} in a browser`);
}
export function loadParser(name: string, dirname: string): { filepath: string, parser: Function } {
throw new Error(`Cannot load parser ${name} relative to ${dirname} in a browser`);
}
export function loadGenerator(name: string, dirname: string): { filepath: string, generator: Function } {
throw new Error(`Cannot load generator ${name} relative to ${dirname} in a browser`);
}

View File

@@ -0,0 +1,11 @@
// @flow
import typeof * as indexBrowserType from "./index-browser";
import typeof * as indexType from "./index";
// Kind of gross, but essentially asserting that the exports of this module are the same as the
// exports of index-browser, since this file may be replaced at bundle time with index-browser.
((({}: any) : $Exact<indexBrowserType>): $Exact<indexType>);
export * from "./configuration";
export * from "./plugins";

View File

@@ -0,0 +1,111 @@
// @flow
/**
* This file handles all logic for converting string-based configuration references into loaded objects.
*/
import resolve from "resolve";
export function resolvePlugin(pluginName: string, dirname: string): string|null {
const possibleNames = [`babel-plugin-${pluginName}`, pluginName];
return resolveFromPossibleNames(possibleNames, dirname);
}
export function resolvePreset(presetName: string, dirname: string): string|null {
const possibleNames = [`babel-preset-${presetName}`, presetName];
// trying to resolve @organization shortcat
// @foo/es2015 -> @foo/babel-preset-es2015
const matches = presetName.match(/^(@[^/]+)\/(.+)$/);
if (matches) {
const [, orgName, presetPath] = matches;
possibleNames.push(`${orgName}/babel-preset-${presetPath}`);
}
return resolveFromPossibleNames(possibleNames, dirname);
}
export function loadPlugin(name: string, dirname: string): { filepath: string, plugin: mixed } {
const filepath = resolvePlugin(name, dirname);
if (!filepath) throw new Error(`Plugin ${name} not found relative to ${dirname}`);
return {
filepath,
plugin: requireModule(filepath),
};
}
export function loadPreset(name: string, dirname: string): { filepath: string, preset: mixed } {
const filepath = resolvePreset(name, dirname);
if (!filepath) throw new Error(`Preset ${name} not found relative to ${dirname}`);
return {
filepath,
preset: requireModule(filepath),
};
}
export function loadParser(name: string, dirname: string): { filepath: string, parser: Function } {
const filepath = resolveQuiet(name, dirname);
if (!filepath) throw new Error(`Parser ${name} not found relative to ${dirname}`);
const mod = requireModule(filepath);
if (!mod) {
throw new Error(`Parser ${name} relative to ${dirname} does not export an object`);
}
if (typeof mod.parse !== "function") {
throw new Error(`Parser ${name} relative to ${dirname} does not export a .parse function`);
}
return {
filepath,
parser: mod.parse,
};
}
export function loadGenerator(name: string, dirname: string): { filepath: string, generator: Function } {
const filepath = resolveQuiet(name, dirname);
if (!filepath) throw new Error(`Generator ${name} not found relative to ${dirname}`);
const mod = requireModule(filepath);
if (!mod) {
throw new Error(`Generator ${name} relative to ${dirname} does not export an object`);
}
if (typeof mod.print !== "function") {
throw new Error(`Generator ${name} relative to ${dirname} does not export a .print function`);
}
return {
filepath,
generator: mod.print,
};
}
function resolveQuiet(name: string, dirname: string): string|null {
try {
return resolve.sync(name, { basedir: dirname });
} catch (e) {
// The 'resolve' module can currently throw ENOTDIR
// https://github.com/substack/node-resolve/issues/121
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "ENOTDIR") throw e;
// Silently fail and move to the next item.
}
return null;
}
function resolveFromPossibleNames(possibleNames: Array<string>, dirname: string): string|null {
for (const name of possibleNames) {
const result = resolveQuiet(name, dirname);
if (result !== null) return result;
}
return null;
}
function requireModule(name: string): mixed {
// $FlowIssue
return require(name);
}

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