diff --git a/.eslintrc b/.eslintrc
index 00dd6a98ad..02f7711758 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,7 +1,6 @@
{
"extends": "babel",
"rules": {
- "max-len": 0
},
"env": {
"node": true,
diff --git a/.gitignore b/.gitignore
index 7e25e4ad05..702ae50d45 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ node_modules
test/tmp
*.log
*.cache
+/.eslintcache
/templates.json
/tests.json
/browser.js
@@ -17,3 +18,4 @@ dist
_babel.github.io
/tests/.browser-build.js
.nyc_output
+/babel.sublime-workspace
diff --git a/README.md b/README.md
index dca5d6b564..7987b5b840 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@
+
diff --git a/babel.sublime-project b/babel.sublime-project
new file mode 100644
index 0000000000..1f18a8cc50
--- /dev/null
+++ b/babel.sublime-project
@@ -0,0 +1,25 @@
+{
+ "settings": {
+ "rulers": [
+ 110
+ ],
+
+ // Set to false to disable detection of tabs vs. spaces on load
+ "detect_indentation": false,
+
+ "translate_tabs_to_spaces": true,
+
+ "tab_size": 2
+ },
+
+ "folders": [{
+ "path": ".",
+ "folder_exclude_patterns": [
+ "packages/*/lib",
+ "node_modules"
+ ],
+ "file_exclude_patterns": [
+
+ ]
+ }]
+}
diff --git a/packages/babel-cli/src/babel-node.js b/packages/babel-cli/src/babel-node.js
index e3d0c2e901..ee25b5f48a 100755
--- a/packages/babel-cli/src/babel-node.js
+++ b/packages/babel-cli/src/babel-node.js
@@ -1,5 +1,3 @@
-/* eslint indent: 0 */
-
/**
* This tiny wrapper file checks for known node flags and appends them
* when found, before invoking the "real" _babel-node(1) executable.
diff --git a/packages/babel-cli/src/babel/index.js b/packages/babel-cli/src/babel/index.js
index 3f7f143987..194254bf61 100755
--- a/packages/babel-cli/src/babel/index.js
+++ b/packages/babel-cli/src/babel/index.js
@@ -1,7 +1,4 @@
#!/usr/bin/env node
-/* eslint max-len: 0 */
-
-require("babel-core");
const fs = require("fs");
const commander = require("commander");
@@ -38,6 +35,7 @@ Object.keys(options).forEach(function (key) {
commander.option(arg, desc.join(" "));
});
+/* eslint-disable max-len */
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
commander.option("-w, --watch", "Recompile files on changes");
commander.option("--skip-initial-build", "Do not compile files before watching");
@@ -45,6 +43,7 @@ commander.option("-o, --out-file [out]", "Compile all input files into a single
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files");
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 + ")");
diff --git a/packages/babel-cli/test/index.js b/packages/babel-cli/test/index.js
index 1655a4e79b..9da8405733 100644
--- a/packages/babel-cli/test/index.js
+++ b/packages/babel-cli/test/index.js
@@ -46,7 +46,8 @@ const assertTest = function (stdout, stderr, opts) {
if (opts.stderr) {
if (opts.stderrContains) {
- assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) + " didn't contain " + JSON.stringify(expectStderr));
+ assert.ok(includes(stderr, expectStderr), "stderr " + JSON.stringify(stderr) +
+ " didn't contain " + JSON.stringify(expectStderr));
} else {
chai.expect(stderr).to.equal(expectStderr, "stderr didn't match");
}
@@ -60,7 +61,8 @@ const assertTest = function (stdout, stderr, opts) {
if (opts.stdout) {
if (opts.stdoutContains) {
- assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) + " didn't contain " + JSON.stringify(expectStdout));
+ assert.ok(includes(stdout, expectStdout), "stdout " + JSON.stringify(stdout) +
+ " didn't contain " + JSON.stringify(expectStdout));
} else {
chai.expect(stdout).to.equal(expectStdout, "stdout didn't match");
}
diff --git a/packages/babel-code-frame/README.md b/packages/babel-code-frame/README.md
index 0257a2da1f..7ef5368d31 100644
--- a/packages/babel-code-frame/README.md
+++ b/packages/babel-code-frame/README.md
@@ -35,9 +35,26 @@ If the column number is not known, you may pass `null` instead.
## Options
-name | type | default | description
------------------------|----------|-----------------|------------------------------------------------------
-highlightCode | boolean | `false` | Syntax highlight the code as JavaScript for terminals
-linesAbove | number | 2 | The number of lines to show above the error
-linesBelow | number | 3 | The number of lines to show below the error
-forceColor | boolean | `false` | Forcibly syntax highlight the code as JavaScript (for non-terminals); overrides highlightCode
+### `highlightCode`
+
+`boolean`, defaults to `false`.
+
+Toggles syntax highlighting the code as JavaScript for terminals.
+
+### `linesAbove`
+
+`number`, defaults to `2`.
+
+Adjust the number of lines to show above the error.
+
+### `linesBelow`
+
+`number`, defaults to `3`.
+
+Adjust the number of lines to show below the error.
+
+### `forceColor`
+
+`boolean`, defaults to `false`.
+
+Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides `highlightCode`.
diff --git a/packages/babel-code-frame/test/index.js b/packages/babel-code-frame/test/index.js
index b6906100ee..f91727cb24 100644
--- a/packages/babel-code-frame/test/index.js
+++ b/packages/babel-code-frame/test/index.js
@@ -197,10 +197,12 @@ 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 | ")
- ].join("\n")));
+ assert.equal(codeFrame(rawLines, 3, null, { linesAbove: 1, linesBelow: 1, forceColor: true }),
+ chalk.reset([
+ " " + gutter(" 2 | "),
+ marker(">") + gutter(" 3 | "),
+ " " + gutter(" 4 | ")
+ ].join("\n"))
+ );
});
});
diff --git a/packages/babel-core/README.md b/packages/babel-core/README.md
index c4b0f93016..5b2f4d53d1 100644
--- a/packages/babel-core/README.md
+++ b/packages/babel-core/README.md
@@ -117,4 +117,5 @@ Following is a table of the options you can use:
| `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option. |
| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map. |
| `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative. |
+| `sourceType` | `"module"` | Indicate the mode the code should be parsed in. Can be either "script" or "module". |
| `wrapPluginVisitorMethod`| `null` | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`.
diff --git a/packages/babel-core/src/tools/build-external-helpers.js b/packages/babel-core/src/tools/build-external-helpers.js
index b97d25c2d1..8eb206f5ff 100644
--- a/packages/babel-core/src/tools/build-external-helpers.js
+++ b/packages/babel-core/src/tools/build-external-helpers.js
@@ -1,5 +1,3 @@
-/* eslint max-len: 0 */
-
import * as helpers from "babel-helpers";
import generator from "babel-generator";
import * as messages from "babel-messages";
@@ -23,12 +21,14 @@ const buildUmdWrapper = template(`
function buildGlobal(namespace, builder) {
const body = [];
const container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
- const tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
+ const tree = t.program([
+ t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(
namespace,
- t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([]))
+ t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace),
+ t.objectExpression([]))
)
]));
diff --git a/packages/babel-core/src/transformation/file/index.js b/packages/babel-core/src/transformation/file/index.js
index a013eb5d6a..50b641c194 100644
--- a/packages/babel-core/src/transformation/file/index.js
+++ b/packages/babel-core/src/transformation/file/index.js
@@ -1,5 +1,4 @@
/* global BabelFileResult, BabelParserOptions, BabelFileMetadata */
-/* eslint max-len: 0 */
import getHelper from "babel-helpers";
import * as metadataVisitor from "./metadata";
@@ -339,7 +338,7 @@ export default class File extends Store {
this.scope.push({
id: uid,
init: init,
- _blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers
+ _blockHoist: 1.9 // This ensures that we don't fail if not using function expression helpers
});
return uid;
}
@@ -378,8 +377,8 @@ export default class File extends Store {
sourceRoot: inputMapConsumer.sourceRoot
});
- // This assumes the output map always has a single source, since Babel always compiles a single source file to a
- // single output file.
+ // This assumes the output map always has a single source, since Babel always compiles a
+ // single source file to a single output file.
const source = outputMapConsumer.sources[0];
inputMapConsumer.eachMapping(function (mapping) {
@@ -424,7 +423,8 @@ export default class File extends Store {
if (parser) {
parseCode = require(parser).parse;
} else {
- throw new Error(`Couldn't find parser ${parserOpts.parser} with "parse" method relative to directory ${dirname}`);
+ throw new Error(`Couldn't find parser ${parserOpts.parser} with "parse" method ` +
+ `relative to directory ${dirname}`);
}
} else {
parseCode = parserOpts.parser;
@@ -472,7 +472,8 @@ export default class File extends Store {
this.log.debug("Start transform traverse");
// merge all plugin visitors into a single visitor
- const visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod);
+ const visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses,
+ this.opts.wrapPluginVisitorMethod);
traverse(this.ast, visitor, this.scope);
this.log.debug("End transform traverse");
@@ -610,14 +611,16 @@ export default class File extends Store {
if (generator) {
gen = require(generator).print;
} else {
- throw new Error(`Couldn't find generator ${gen} with "print" method relative to directory ${dirname}`);
+ throw new Error(`Couldn't find generator ${gen} with "print" method relative ` +
+ `to directory ${dirname}`);
}
}
}
this.log.debug("Generation start");
- const _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts, this.code);
+ const _result = gen(ast, opts.generatorOpts ? Object.assign(opts, opts.generatorOpts) : opts,
+ this.code);
result.code = _result.code;
result.map = _result.map;
diff --git a/packages/babel-core/src/transformation/file/options/config.js b/packages/babel-core/src/transformation/file/options/config.js
index 7b11963f38..dbc60c6043 100644
--- a/packages/babel-core/src/transformation/file/options/config.js
+++ b/packages/babel-core/src/transformation/file/options/config.js
@@ -1,4 +1,4 @@
-/* eslint max-len: 0 */
+/* eslint max-len: "off" */
module.exports = {
filename: {
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 8221e3fe19..3e6209abfc 100644
--- a/packages/babel-core/src/transformation/file/options/option-manager.js
+++ b/packages/babel-core/src/transformation/file/options/option-manager.js
@@ -1,5 +1,3 @@
-/* eslint max-len: 0 */
-
import * as context from "../../../index";
import type Logger from "../logger";
import Plugin from "../../plugin";
@@ -180,10 +178,13 @@ export default class OptionManager {
// check for an unknown option
if (!option && this.log) {
if (removed[key]) {
- this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`, ReferenceError);
+ this.log.error(`Using removed Babel 5 option: ${alias}.${key} - ${removed[key].message}`,
+ ReferenceError);
} else {
+ /* eslint-disable max-len */
const unknownOptErr = `Unknown option: ${alias}.${key}. Check out http://babeljs.io/docs/usage/options/ for more information about options.`;
const presetConfigErr = "A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:\n\nInvalid:\n `{ presets: [{option: value}] }`\nValid:\n `{ presets: [['presetName', {option: value}]] }`\n\nFor more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options.";
+ /* eslint-enable max-len */
this.log.error(`${unknownOptErr}\n\n${presetConfigErr}`, ReferenceError);
}
diff --git a/packages/babel-core/src/transformation/file/options/removed.js b/packages/babel-core/src/transformation/file/options/removed.js
index 00a24ea61e..cb0077cb92 100644
--- a/packages/babel-core/src/transformation/file/options/removed.js
+++ b/packages/babel-core/src/transformation/file/options/removed.js
@@ -1,4 +1,4 @@
-/* eslint max-len: 0 */
+/* eslint max-len: "off" */
module.exports = {
"auxiliaryComment": {
diff --git a/packages/babel-core/src/transformation/plugin.js b/packages/babel-core/src/transformation/plugin.js
index f3461ae9bf..d6c5406574 100644
--- a/packages/babel-core/src/transformation/plugin.js
+++ b/packages/babel-core/src/transformation/plugin.js
@@ -1,5 +1,3 @@
-/* eslint max-len: 0 */
-
import OptionManager from "./file/options/option-manager";
import * as messages from "babel-messages";
import Store from "../store";
@@ -85,7 +83,8 @@ export default class Plugin extends Store {
normaliseVisitor(visitor: Object): Object {
for (const key of GLOBAL_VISITOR_PROPS) {
if (visitor[key]) {
- throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. Please target individual nodes.");
+ throw new Error("Plugins aren't allowed to specify catch-all enter/exit handlers. " +
+ "Please target individual nodes.");
}
}
diff --git a/packages/babel-core/test/api.js b/packages/babel-core/test/api.js
index 910418321b..7cd5157afe 100644
--- a/packages/babel-core/test/api.js
+++ b/packages/babel-core/test/api.js
@@ -265,6 +265,7 @@ describe("api", function () {
it("source map merging", function () {
const result = babel.transform([
+ /* eslint-disable max-len */
"function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }",
"",
"let Foo = function Foo() {",
@@ -272,6 +273,7 @@ describe("api", function () {
"};",
"",
"//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZG91dCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztJQUFNLEdBQUcsWUFBSCxHQUFHO3dCQUFILEdBQUciLCJmaWxlIjoidW5kZWZpbmVkIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgRm9vIHt9XG4iXX0="
+ /* eslint-enable max-len */
].join("\n"), {
sourceMap: true
});
@@ -329,12 +331,14 @@ describe("api", function () {
};
}]
}).then(function (result) {
- assert.equal(result.code, "/*before*/start;\n/*after*/class Foo {}\n/*before*/end;\n/*after*/");
+ assert.equal(result.code,
+ "/*before*/start;\n/*after*/class Foo {}\n/*before*/end;\n/*after*/");
});
});
it("modules metadata", function () {
return Promise.all([
+ // eslint-disable-next-line max-len
transformAsync("import { externalName as localName } from \"external\";").then(function (result) {
assert.deepEqual(result.metadata.modules.imports[0], {
source: "external",
@@ -586,8 +590,10 @@ describe("api", function () {
});
it("resolveModuleSource option", function () {
+ /* eslint-disable max-len */
const actual = "import foo from \"foo-import-default\";\nimport \"foo-import-bare\";\nexport { foo } from \"foo-export-named\";";
const expected = "import foo from \"resolved/foo-import-default\";\nimport \"resolved/foo-import-bare\";\nexport { foo } from \"resolved/foo-export-named\";";
+ /* eslint-enable max-len */
return transformAsync(actual, {
resolveModuleSource: function (originalSource) {
diff --git a/packages/babel-core/test/option-manager.js b/packages/babel-core/test/option-manager.js
index 2606a4bca0..2ca432dd20 100644
--- a/packages/babel-core/test/option-manager.js
+++ b/packages/babel-core/test/option-manager.js
@@ -35,6 +35,7 @@ describe("option-manager", () => {
"blacklist": true
});
},
+ // eslint-disable-next-line max-len
/Using removed Babel 5 option: base.auxiliaryComment - Use `auxiliaryCommentBefore` or `auxiliaryCommentAfter`/
);
});
@@ -59,6 +60,7 @@ describe("option-manager", () => {
"presets": [{ option: "value" }]
});
},
+ // eslint-disable-next-line max-len
/Unknown option: foreign.option\.(?:.|\n)+A common cause of this error is the presence of a configuration options object without the corresponding preset name/
);
});
diff --git a/packages/babel-generator/package.json b/packages/babel-generator/package.json
index 9a6b38db42..7e5511e367 100644
--- a/packages/babel-generator/package.json
+++ b/packages/babel-generator/package.json
@@ -16,7 +16,8 @@
"detect-indent": "^5.0.0",
"jsesc": "^1.3.0",
"lodash": "^4.2.0",
- "source-map": "^0.5.0"
+ "source-map": "^0.5.0",
+ "trim-right": "^1.0.1"
},
"devDependencies": {
"babel-helper-fixtures": "^6.22.0",
diff --git a/packages/babel-generator/src/buffer.js b/packages/babel-generator/src/buffer.js
index d1187be275..3c53ef666d 100644
--- a/packages/babel-generator/src/buffer.js
+++ b/packages/babel-generator/src/buffer.js
@@ -1,5 +1,5 @@
import type SourceMap from "./source-map";
-import trimEnd from "lodash/trimEnd";
+import trimRight from "trim-right";
const SPACES_RE = /^[ \t]+$/;
@@ -40,7 +40,9 @@ export default class Buffer {
const map = this._map;
const result = {
- code: trimEnd(this._buf.join("")),
+ // Whatever trim is used here should not execute a regex against the
+ // source string since it may be arbitrarily large after all transformations
+ code: trimRight(this._buf.join("")),
map: null,
rawMappings: map && map.getRawMappings(),
};
diff --git a/packages/babel-generator/src/generators/expressions.js b/packages/babel-generator/src/generators/expressions.js
index 0cf5f2093e..8ba9491071 100644
--- a/packages/babel-generator/src/generators/expressions.js
+++ b/packages/babel-generator/src/generators/expressions.js
@@ -1,5 +1,3 @@
-/* eslint max-len: 0 */
-
import * as t from "babel-types";
import * as n from "../node";
diff --git a/packages/babel-generator/src/generators/flow.js b/packages/babel-generator/src/generators/flow.js
index 2e96843eaf..d8de870dee 100644
--- a/packages/babel-generator/src/generators/flow.js
+++ b/packages/babel-generator/src/generators/flow.js
@@ -1,5 +1,3 @@
-/* eslint max-len: 0 */
-
export function AnyTypeAnnotation() {
this.word("any");
}
diff --git a/packages/babel-generator/src/generators/methods.js b/packages/babel-generator/src/generators/methods.js
index 97bbcd3129..2ad6d41ffb 100644
--- a/packages/babel-generator/src/generators/methods.js
+++ b/packages/babel-generator/src/generators/methods.js
@@ -93,5 +93,6 @@ export function ArrowFunctionExpression(node: Object) {
}
function hasTypes(node, param) {
- return node.typeParameters || node.returnType || param.typeAnnotation || param.optional || param.trailingComments;
+ return node.typeParameters || node.returnType || param.typeAnnotation || param.optional ||
+ param.trailingComments;
}
diff --git a/packages/babel-generator/src/generators/types.js b/packages/babel-generator/src/generators/types.js
index fa8498aff7..5fada08e79 100644
--- a/packages/babel-generator/src/generators/types.js
+++ b/packages/babel-generator/src/generators/types.js
@@ -1,6 +1,3 @@
-/* eslint max-len: 0 */
-/* eslint quotes: 0 */
-
import * as t from "babel-types";
import jsesc from "jsesc";
@@ -62,7 +59,8 @@ export function ObjectProperty(node: Object) {
this.token("]");
} else {
// print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});`
- if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) {
+ if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) &&
+ node.key.name === node.value.left.name) {
this.print(node.value, node);
return;
}
diff --git a/packages/babel-generator/src/node/parentheses.js b/packages/babel-generator/src/node/parentheses.js
index e6424aced6..558bceb14c 100644
--- a/packages/babel-generator/src/node/parentheses.js
+++ b/packages/babel-generator/src/node/parentheses.js
@@ -170,16 +170,14 @@ export function FunctionExpression(node: Object, parent: Object, printStack: Arr
}
export function ArrowFunctionExpression(node: Object, parent: Object): boolean {
- // export default (function () {});
- if (t.isExportDeclaration(parent)) {
- return true;
- }
-
- if (t.isBinaryExpression(parent) || t.isLogicalExpression(parent)) {
- return true;
- }
-
- if (t.isUnaryExpression(parent)) {
+ if (
+ // export default (function () {});
+ t.isExportDeclaration(parent) ||
+ t.isBinaryExpression(parent) ||
+ t.isLogicalExpression(parent) ||
+ t.isUnaryExpression(parent) ||
+ t.isTaggedTemplateExpression(parent)
+ ) {
return true;
}
@@ -199,6 +197,10 @@ export function ConditionalExpression(node: Object, parent: Object): boolean {
return true;
}
+ if (t.isAwaitExpression(parent)) {
+ return true;
+ }
+
return UnaryLike(node, parent);
}
@@ -225,6 +227,10 @@ function isFirstInStatement(printStack: Array