diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 039baaa09e..086a042266 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,6 +9,8 @@ | Writing tests | + Debugging code + | Internals
@@ -127,7 +129,8 @@ $ TEST_DEBUG=true make test To test the code coverage, use: ```sh -$ make test-cov +$ BABEL_ENV=cov make build +$ ./scripts/test-cov.sh ``` #### Writing tests @@ -199,9 +202,46 @@ For both `babel-plugin-x` and `babylon`, you can easily generate an `expected.js - expected.json (will be generated if not created) ``` +#### Debugging code + +A common approach to debugging JavaScript code is to walk through the code using the [Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/) debugger. +For illustration purposes, we are going to assume that we need to get a better understanding of [`Generator.generate()`](https://github.com/babel/babel/blob/b5246994b57f06af871be6a63dcc4c6fd41d94d6/packages/babel-generator/src/index.js#L32), which is responsible for generating code for a given AST. +To get a better understanding of what is actually going on for this particular piece of code, we are going to make use of breakpoints. + +```diff +generate() { ++ debugger; // breakpoint + return super.generate(this.ast); +} +``` + +To include the changes, we have to make sure to build Babel: + +```bash +$ make build +``` + +Next, we need to execute `Generator.generate()`, which can be achieved by running a test case in the `babel-generator` package. +For example, we can run the test case that tests the generation of class declarations: + +```bash +$ TEST_DEBUG=true TEST_GREP=ClassDeclaration make test-only + +./scripts/test.sh +Debugger listening on port 9229. +Warning: This is an experimental feature and could change at any time. +To start debugging, open the following URL in Chrome: + chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/3cdaebd2-be88-4e7b-a94b-432950ab72d0 +``` + +To start the debugging in Chrome DevTools, open the given URL. +The debugger starts at the first executed line of code, which is Mocha's first line by default. +Click _Resume script execution_
](https://github.com/babel-bot) |
+|---|
+| Babel Bot |
+| [@babel-bot](https://github.com/babel-bot) |
+| [@babeljs](https://twitter.com/babeljs) |
+
### Inactive members
[](https://github.com/amasad) | [](https://github.com/thejameskyle) | [](https://github.com/jmm) | [](https://github.com/kittens) (Creator) |
diff --git a/codecov.yml b/codecov.yml
new file mode 100644
index 0000000000..3e31ee1814
--- /dev/null
+++ b/codecov.yml
@@ -0,0 +1,4 @@
+coverage:
+ parsers:
+ javascript:
+ enable_partials: yes
diff --git a/package.json b/package.json
index dc045dc0ee..35b4fbc876 100644
--- a/package.json
+++ b/package.json
@@ -1,4 +1,5 @@
{
+ "name": "babel",
"private": true,
"license": "MIT",
"scripts": {
@@ -44,6 +45,10 @@
"through2": "^2.0.0",
"uglify-js": "^2.4.16"
},
+ "devEngines": {
+ "node": ">= 0.10 <= 7.x",
+ "npm": "2.x || 3.x || 4.x"
+ },
"babel": {
"comments": false,
"presets": [
diff --git a/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js b/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js
new file mode 100644
index 0000000000..13257ec5e8
--- /dev/null
+++ b/packages/babel-cli/test/fixtures/babel-node/arguments/in-files/bar.js
@@ -0,0 +1 @@
+console.log(process.argv[2]);
diff --git a/packages/babel-cli/test/fixtures/babel-node/arguments/options.json b/packages/babel-cli/test/fixtures/babel-node/arguments/options.json
new file mode 100644
index 0000000000..5aa934d555
--- /dev/null
+++ b/packages/babel-cli/test/fixtures/babel-node/arguments/options.json
@@ -0,0 +1,4 @@
+{
+ "args": ["bar", "foo"],
+ "stdout": "foo"
+}
diff --git a/packages/babel-core/src/transformation/file/options/option-manager.js b/packages/babel-core/src/transformation/file/options/option-manager.js
index 7a106f8ada..0dd3ecf70d 100644
--- a/packages/babel-core/src/transformation/file/options/option-manager.js
+++ b/packages/babel-core/src/transformation/file/options/option-manager.js
@@ -270,7 +270,7 @@ export default class OptionManager {
}
const presetFactory = this.getPresetFactoryForPreset(presetLoc || preset);
- preset = presetFactory(context, options);
+ preset = presetFactory(context, options, { dirname });
if (onResolve) onResolve(preset, presetLoc);
} catch (e) {
diff --git a/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js b/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js
index b2f7d13c73..1f313cfaa1 100644
--- a/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js
+++ b/packages/babel-core/test/fixtures/resolution/resolve-addons-relative-to-file/node_modules/addons/preset.js
@@ -1,7 +1,10 @@
-module.exports = function () {
- return {
- plugins: [plugin],
+module.exports = function (context, options, fileContext) {
+ if (/resolve-addons-relative-to-file$/.test(fileContext.dirname)) {
+ return {
+ plugins: [plugin],
+ };
}
+ return {};
};
function plugin () {
diff --git a/packages/babel-generator/src/generators/statements.js b/packages/babel-generator/src/generators/statements.js
index f6291e0165..574ef5c249 100644
--- a/packages/babel-generator/src/generators/statements.js
+++ b/packages/babel-generator/src/generators/statements.js
@@ -89,7 +89,6 @@ const buildForXStatement = function (op) {
this.space();
}
this.token("(");
-
this.print(node.left, node);
this.space();
this.word(op);
diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js
index 558bceb14c..948198f7cb 100644
--- a/packages/babel-generator/src/node/parentheses.js
+++ b/packages/babel-generator/src/node/parentheses.js
@@ -46,6 +46,10 @@ export function ObjectExpression(node: Object, parent: Object, printStack: Array
return isFirstInStatement(printStack, { considerArrow: true });
}
+export function DoExpression(node: Object, parent: Object, printStack: Array