Add espree parser (#9000)
Co-authored-by: Chris Brody <chris.brody+brodybits@gmail.com>
This commit is contained in:
1 parent
2bc68f11f3
commit
73e3976c34
73 files changed
+397
-116
No files matched your search
@@ -0,0 +1,5 @@
|
||||
#### Add `espree` parser (#9000 by @fisker)
|
||||
|
||||
A new value for the `parser` option has been added: [`espree`](https://github.com/eslint/espree) - which is the [`ESLint`](https://github.com/eslint/eslint) default parser.
|
||||
|
||||
Note that `espree` only works for [ECMAScript Finished Proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md), and is stricter than the `babel` parser.
|
||||
@@ -105,6 +105,7 @@
|
||||
"esbenp",
|
||||
"eslintignore",
|
||||
"eslump",
|
||||
"espree",
|
||||
"esproposal",
|
||||
"estree",
|
||||
"esutils",
|
||||
|
||||
@@ -211,6 +211,7 @@ Valid options:
|
||||
- `"babel-ts"` (similar to `"typescript"` but uses Babel and its TypeScript plugin) _First available in v2.0.0_
|
||||
- `"flow"` (via [flow-parser](https://github.com/facebook/flow/tree/master/src/parser))
|
||||
- `"typescript"` (via [@typescript-eslint/typescript-estree](https://github.com/typescript-eslint/typescript-eslint)) _First available in v1.4.0_
|
||||
- `"espree"` (via [espree](https://github.com/eslint/espree)) _First available in v2.2.0_
|
||||
- `"css"` (via [postcss](https://github.com/postcss/postcss)) _First available in v1.7.1_
|
||||
- `"scss"` (via [postcss-scss](https://github.com/postcss/postcss-scss)) _First available in v1.7.1_
|
||||
- `"less"` (via [postcss-less](https://github.com/shellscape/postcss-less) _First available in v1.7.1_
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
"editorconfig": "0.15.3",
|
||||
"editorconfig-to-prettier": "0.2.0",
|
||||
"escape-string-regexp": "4.0.0",
|
||||
"espree": "7.3.0",
|
||||
"esutils": "2.0.3",
|
||||
"fast-glob": "3.2.4",
|
||||
"fast-json-stable-stringify": "2.1.0",
|
||||
|
||||
@@ -42,6 +42,9 @@ const parsers = [
|
||||
'typeof globalThis === "object"': "true",
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "src/language-js/parser-espree.js",
|
||||
},
|
||||
{
|
||||
input: "src/language-js/parser-angular.js",
|
||||
},
|
||||
|
||||
@@ -27,6 +27,8 @@ function clean(ast, newObj, parent) {
|
||||
if (newObj.value) {
|
||||
newObj.value = newObj.value.toLowerCase();
|
||||
}
|
||||
}
|
||||
if (ast.type === "BigIntLiteral" || ast.type === "Literal") {
|
||||
if (newObj.bigint) {
|
||||
newObj.bigint = newObj.bigint.toLowerCase();
|
||||
}
|
||||
|
||||
@@ -991,7 +991,9 @@ function getCommentChildNodes(node, options) {
|
||||
// }
|
||||
// }
|
||||
if (
|
||||
(options.parser === "typescript" || options.parser === "flow") &&
|
||||
(options.parser === "typescript" ||
|
||||
options.parser === "flow" ||
|
||||
options.parser === "espree") &&
|
||||
node.type === "MethodDefinition" &&
|
||||
node.value &&
|
||||
node.value.type === "FunctionExpression" &&
|
||||
|
||||
@@ -10,7 +10,14 @@ const languages = [
|
||||
require("linguist-languages/data/JavaScript.json"),
|
||||
(data) => ({
|
||||
since: "0.0.0",
|
||||
parsers: ["babel", "babel-flow", "babel-ts", "flow", "typescript"],
|
||||
parsers: [
|
||||
"babel",
|
||||
"espree",
|
||||
"babel-flow",
|
||||
"babel-ts",
|
||||
"flow",
|
||||
"typescript",
|
||||
],
|
||||
vscodeLanguageIds: ["javascript", "mongo"],
|
||||
extensions: [
|
||||
...data.extensions,
|
||||
@@ -31,7 +38,14 @@ const languages = [
|
||||
})),
|
||||
createLanguage(require("linguist-languages/data/JSX.json"), () => ({
|
||||
since: "0.0.0",
|
||||
parsers: ["babel", "babel-flow", "babel-ts", "flow", "typescript"],
|
||||
parsers: [
|
||||
"babel",
|
||||
"babel-flow",
|
||||
"babel-ts",
|
||||
"flow",
|
||||
"typescript",
|
||||
"espree",
|
||||
],
|
||||
vscodeLanguageIds: ["javascriptreact"],
|
||||
})),
|
||||
createLanguage(require("linguist-languages/data/TypeScript.json"), () => ({
|
||||
@@ -132,6 +146,10 @@ const parsers = {
|
||||
get __ng_directive() {
|
||||
return require("./parser-angular").parsers.__ng_directive;
|
||||
},
|
||||
// JS - espree
|
||||
get espree() {
|
||||
return require("./parser-espree").parsers.espree;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
const { getShebang } = require("../common/util");
|
||||
const createError = require("../common/parser-create-error");
|
||||
const { hasPragma } = require("./pragma");
|
||||
const { locStart, locEnd } = require("./loc");
|
||||
const postprocess = require("./postprocess");
|
||||
|
||||
const espreeOptions = {
|
||||
range: true,
|
||||
loc: true,
|
||||
comment: true,
|
||||
tokens: true,
|
||||
sourceType: "module",
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
globalReturn: true,
|
||||
impliedStrict: false,
|
||||
},
|
||||
};
|
||||
|
||||
function parse(originalText, parsers, options) {
|
||||
const { parse, latestEcmaVersion } = require("espree");
|
||||
espreeOptions.ecmaVersion = latestEcmaVersion;
|
||||
|
||||
// Replace shebang with space
|
||||
const shebang = getShebang(originalText);
|
||||
const text = shebang
|
||||
? " ".repeat(shebang.length) + originalText.slice(shebang.length)
|
||||
: originalText;
|
||||
|
||||
let ast;
|
||||
|
||||
try {
|
||||
ast = parse(text, espreeOptions);
|
||||
} catch (moduleError) {
|
||||
try {
|
||||
ast = parse(text, { ...espreeOptions, sourceType: "script" });
|
||||
} catch (scriptError) {
|
||||
// throw the error for `module` parsing
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (typeof moduleError.lineNumber === "undefined") {
|
||||
throw moduleError;
|
||||
}
|
||||
|
||||
throw createError(moduleError.message, {
|
||||
start: { line: moduleError.lineNumber, column: moduleError.column },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return postprocess(ast, { ...options, originalText });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parsers: {
|
||||
espree: { parse, astFormat: "estree", hasPragma, locStart, locEnd },
|
||||
},
|
||||
};
|
||||
@@ -9,12 +9,20 @@ const { composeLoc, locStart, locEnd } = require("./loc");
|
||||
const { isTypeCastComment } = require("./comments");
|
||||
|
||||
function postprocess(ast, options) {
|
||||
if (options.parser === "typescript" || options.parser === "flow") {
|
||||
if (
|
||||
options.parser === "typescript" ||
|
||||
options.parser === "flow" ||
|
||||
options.parser === "espree"
|
||||
) {
|
||||
includeShebang(ast, options);
|
||||
}
|
||||
|
||||
// Keep Babel's non-standard ParenthesizedExpression nodes only if they have Closure-style type cast comments.
|
||||
if (options.parser !== "typescript" && options.parser !== "flow") {
|
||||
if (
|
||||
options.parser !== "typescript" &&
|
||||
options.parser !== "flow" &&
|
||||
options.parser !== "espree"
|
||||
) {
|
||||
const startOffsetsOfTypeCastedNodes = new Set();
|
||||
|
||||
// Comments might be attached not directly to ParenthesizedExpression but to its ancestor.
|
||||
@@ -48,6 +56,10 @@ function postprocess(ast, options) {
|
||||
|
||||
ast = visitNode(ast, (node) => {
|
||||
switch (node.type) {
|
||||
// Espree
|
||||
case "ChainExpression": {
|
||||
return transformChainExpression(node.expression);
|
||||
}
|
||||
case "LogicalExpression": {
|
||||
// We remove unneeded parens around same-operator LogicalExpressions
|
||||
if (isUnbalancedLogicalTree(node)) {
|
||||
@@ -126,6 +138,21 @@ function postprocess(ast, options) {
|
||||
}
|
||||
}
|
||||
|
||||
// This is a workaround to transform `ChainExpression` from `espree` into
|
||||
// `babel` shape AST, we should do the opposite, since `ChainExpression` is the
|
||||
// standard `estree` AST for `optional chaining`
|
||||
// https://github.com/estree/estree/blob/master/es2020.md
|
||||
function transformChainExpression(node) {
|
||||
if (node.type === "CallExpression") {
|
||||
node.type = "OptionalCallExpression";
|
||||
node.callee = transformChainExpression(node.callee);
|
||||
} else if (node.type === "MemberExpression") {
|
||||
node.type = "OptionalMemberExpression";
|
||||
node.object = transformChainExpression(node.object);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function visitNode(node, fn) {
|
||||
let entries;
|
||||
|
||||
|
||||
@@ -927,7 +927,7 @@ function returnArgumentHasLeadingComment(options, argument) {
|
||||
//
|
||||
// Angular does not support unquoted numbers in expressions.
|
||||
//
|
||||
// So we play it safe and only unquote numbers for the "babel" parser.
|
||||
// So we play it safe and only unquote numbers for the JavaScript parsers.
|
||||
// (Vue supports unquoted numbers in expressions, but let’s keep it simple.)
|
||||
//
|
||||
// Identifiers can be unquoted in more circumstances, though.
|
||||
@@ -945,7 +945,7 @@ function isStringPropSafeToUnquote(node, options) {
|
||||
)) ||
|
||||
(isSimpleNumber(node.key.value) &&
|
||||
String(Number(node.key.value)) === node.key.value &&
|
||||
options.parser === "babel"))
|
||||
(options.parser === "babel" || options.parser === "espree")))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ const options = {
|
||||
{ value: "babel-flow", since: "1.16.0", description: "Flow" },
|
||||
{ value: "babel-ts", since: "2.0.0", description: "TypeScript" },
|
||||
{ value: "typescript", since: "1.4.0", description: "TypeScript" },
|
||||
{ value: "espree", since: "2.2.0", description: "JavaScript" },
|
||||
{ value: "css", since: "1.7.1", description: "CSS" },
|
||||
{ value: "less", since: "1.7.1", description: "Less" },
|
||||
{ value: "scss", since: "1.7.1", description: "SCSS" },
|
||||
|
||||
@@ -119,6 +119,7 @@ function isSourceElement(opts, node) {
|
||||
case "babel-flow":
|
||||
case "babel-ts":
|
||||
case "typescript":
|
||||
case "espree":
|
||||
return isJsSourceElement(node.type);
|
||||
case "json":
|
||||
return jsonSourceElements.has(node.type);
|
||||
|
||||
@@ -45,11 +45,6 @@ func(
|
||||
veryLoooooooooooooooongName.something()
|
||||
);
|
||||
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
|
||||
|
||||
=====================================output=====================================
|
||||
@@ -97,11 +92,6 @@ func(
|
||||
veryLoooooooooooooooongName.something()
|
||||
);
|
||||
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
promise.then((result) =>
|
||||
result.veryLongVariable.veryLongPropertyName > someOtherVariable
|
||||
? "ok"
|
||||
@@ -156,11 +146,6 @@ func(
|
||||
veryLoooooooooooooooongName.something()
|
||||
);
|
||||
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
|
||||
|
||||
=====================================output=====================================
|
||||
@@ -208,11 +193,6 @@ func(
|
||||
veryLoooooooooooooooongName.something(),
|
||||
);
|
||||
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
promise.then((result) =>
|
||||
result.veryLongVariable.veryLongPropertyName > someOtherVariable
|
||||
? "ok"
|
||||
@@ -266,11 +246,6 @@ func(
|
||||
veryLoooooooooooooooongName.something()
|
||||
);
|
||||
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
|
||||
|
||||
=====================================output=====================================
|
||||
@@ -318,11 +293,6 @@ func(
|
||||
veryLoooooooooooooooongName.something()
|
||||
);
|
||||
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
promise.then((result) =>
|
||||
result.veryLongVariable.veryLongPropertyName > someOtherVariable
|
||||
? "ok"
|
||||
@@ -331,3 +301,65 @@ promise.then((result) =>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`class-property.js - {"arrowParens":"always"} format 1`] = `
|
||||
====================================options=====================================
|
||||
arrowParens: "always"
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`class-property.js - {"trailingComma":"all"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
trailingComma: "all"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`class-property.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -36,9 +36,4 @@ func(
|
||||
veryLoooooooooooooooongName.something()
|
||||
);
|
||||
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
|
||||
promise.then(result => result.veryLongVariable.veryLongPropertyName > someOtherVariable ? "ok" : "fail");
|
||||
@@ -0,0 +1,4 @@
|
||||
const composition = (ViewComponent, ContainerComponent) =>
|
||||
class extends React.Component {
|
||||
static propTypes = {};
|
||||
};
|
||||
@@ -1,7 +1,15 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
const errors = {
|
||||
espree: ["class-property.js"],
|
||||
};
|
||||
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors,
|
||||
});
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
trailingComma: "all",
|
||||
errors,
|
||||
});
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
arrowParens: "always",
|
||||
errors,
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], {
|
||||
errors: { espree: ["newline-before-arrow.js"] },
|
||||
});
|
||||
@@ -1,4 +1,31 @@
|
||||
// Only testing babel parsing
|
||||
// Do not add extra parsers here
|
||||
|
||||
run_spec(__dirname, ["babel", "babel-ts", "babel-flow"]);
|
||||
run_spec(__dirname, ["babel", "babel-ts", "babel-flow"], {
|
||||
errors: {
|
||||
espree: [
|
||||
"class-properties.js",
|
||||
"decimal.js",
|
||||
"decorators.js",
|
||||
"do-expressions.js",
|
||||
"export-default-from.js",
|
||||
"flow.js",
|
||||
"function-bind.js",
|
||||
"function-sent.js",
|
||||
"module-attributes-dynamic.js",
|
||||
"module-attributes-static.js",
|
||||
"partial-application.js",
|
||||
"pipeline-operator-fsharp.js",
|
||||
"pipeline-operator-minimal.js",
|
||||
"pipeline-operator-smart.js",
|
||||
"private-fields-in-in.js",
|
||||
"private-methods.js",
|
||||
"record-tuple-record.js",
|
||||
"record-tuple-tuple.js",
|
||||
"throw-expressions.js",
|
||||
"typescript.js",
|
||||
"v8intrinsic.js",
|
||||
"optional-chaining.js",
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -1,2 +1,2 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { semi: false });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } });
|
||||
@@ -1 +1,5 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors: {
|
||||
espree: ["class-property.js"],
|
||||
},
|
||||
});
|
||||
@@ -1,2 +1,2 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { semi: false });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } });
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors: { espree: ["property.js"] },
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } });
|
||||
@@ -1,2 +1,2 @@
|
||||
// TypeScript and Flow don't accept decorator after export
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors: { espree: ["class-property.js"] },
|
||||
});
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], {
|
||||
errors: { espree: true },
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1,5 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors: {
|
||||
espree: [],
|
||||
},
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1,2 +1,2 @@
|
||||
// flow-parser@0.38.0 fails to parse `1.e1`, so use babel here.
|
||||
run_spec(__dirname, ["babel", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } });
|
||||
@@ -1,5 +1,19 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`invalid.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz;
|
||||
|
||||
=====================================output=====================================
|
||||
c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`logical-assignment.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript"]
|
||||
@@ -26,7 +40,6 @@ c.foo["baz"] ??= result.foo.baz;
|
||||
|
||||
a.foo.bar().baz &&= result.foo.bar().baz;
|
||||
b.foo.bar().baz ||= result.foo.bar().baz;
|
||||
c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz;
|
||||
b.baz ||= result.baz;
|
||||
c.baz ??= result.baz;
|
||||
|
||||
@@ -83,7 +96,6 @@ c.foo["baz"] ??= result.foo.baz;
|
||||
|
||||
a.foo.bar().baz &&= result.foo.bar().baz;
|
||||
b.foo.bar().baz ||= result.foo.bar().baz;
|
||||
c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz;
|
||||
b.baz ||= result.baz;
|
||||
c.baz ??= result.baz;
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz;
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "typescript"], {
|
||||
errors: { espree: ["invalid.js"] },
|
||||
});
|
||||
@@ -18,7 +18,6 @@ c.foo["baz"] ??= result.foo.baz;
|
||||
|
||||
a.foo.bar().baz &&= result.foo.bar().baz;
|
||||
b.foo.bar().baz ||= result.foo.bar().baz;
|
||||
c.foo.bar().baz ??= result.foo.bar().baz(a.baz) &&= result.baz;
|
||||
b.baz ||= result.baz;
|
||||
c.baz ??= result.baz;
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -250,7 +250,7 @@ const Steps = styled.div\`
|
||||
}
|
||||
\`;
|
||||
|
||||
const Steps = styled.div\`
|
||||
const Steps2 = styled.div\`
|
||||
@media (min-width: \${breakpoints.lg}) {
|
||||
\${Step} {
|
||||
margin-bottom: 90px;
|
||||
@@ -288,7 +288,7 @@ const Steps = styled.div\`
|
||||
}
|
||||
\`;
|
||||
|
||||
const Steps = styled.div\`
|
||||
const Steps2 = styled.div\`
|
||||
@media (min-width: \${breakpoints.lg}) {
|
||||
\${Step} {
|
||||
margin-bottom: 90px;
|
||||
|
||||
@@ -4,7 +4,7 @@ const Steps = styled.div`
|
||||
}
|
||||
`;
|
||||
|
||||
const Steps = styled.div`
|
||||
const Steps2 = styled.div`
|
||||
@media (min-width: ${breakpoints.lg}) {
|
||||
${Step} {
|
||||
margin-bottom: 90px;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { semi: false });
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
run_spec(__dirname, ["babel"], { semi: false, errors: { espree: true } });
|
||||
@@ -1,2 +1,4 @@
|
||||
run_spec(__dirname, ["babel", "flow"]);
|
||||
run_spec(__dirname, ["babel", "flow"], { semi: false });
|
||||
const errors = { espree: ["class.js"] };
|
||||
|
||||
run_spec(__dirname, ["babel", "flow"], { errors });
|
||||
run_spec(__dirname, ["babel", "flow"], { semi: false, errors });
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "flow"]);
|
||||
run_spec(__dirname, ["babel", "flow"], {
|
||||
errors: { espree: ["comment.js"] },
|
||||
});
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], {
|
||||
errors: { espree: ["expression.js", "invalid-accessor-generator.js"] },
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1,16 +1,22 @@
|
||||
const errors = { espree: ["classes.js"] };
|
||||
|
||||
run_spec(__dirname, ["babel"], {
|
||||
quoteProps: "as-needed",
|
||||
errors,
|
||||
});
|
||||
|
||||
run_spec(__dirname, ["babel"], {
|
||||
quoteProps: "preserve",
|
||||
errors,
|
||||
});
|
||||
|
||||
run_spec(__dirname, ["babel"], {
|
||||
quoteProps: "consistent",
|
||||
errors,
|
||||
});
|
||||
|
||||
run_spec(__dirname, ["babel"], {
|
||||
quoteProps: "consistent",
|
||||
singleQuote: true,
|
||||
errors,
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1,4 @@
|
||||
run_spec(__dirname, ["babel", "flow"], { trailingComma: "all" });
|
||||
run_spec(__dirname, ["babel", "flow"], {
|
||||
trailingComma: "all",
|
||||
errors: { espree: true },
|
||||
});
|
||||
@@ -1,2 +1,4 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], { arrowParens: "avoid" });
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
arrowParens: "avoid",
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "typescript"], { errors: { espree: true } });
|
||||
@@ -1 +1,3 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"]);
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors: { espree: true },
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
@@ -1 +1 @@
|
||||
run_spec(__dirname, ["babel"]);
|
||||
run_spec(__dirname, ["babel"], { errors: { espree: true } });
|
||||
+24
-10
@@ -48,6 +48,13 @@ const unstableTests = new Map(
|
||||
})
|
||||
);
|
||||
|
||||
const espreeDisabledTests = new Set(
|
||||
[
|
||||
// These tests only work for `babel`
|
||||
"comments-closure-typecast",
|
||||
].map((directory) => path.join(__dirname, "../tests/js", directory))
|
||||
);
|
||||
|
||||
const isUnstable = (filename, options) => {
|
||||
const testFunction = unstableTests.get(filename);
|
||||
|
||||
@@ -58,18 +65,14 @@ const isUnstable = (filename, options) => {
|
||||
return testFunction(options);
|
||||
};
|
||||
|
||||
// TODO: refactor `disableBabelTS` option to use `errors`
|
||||
const shouldThrowOnFormat = (filename, options) => {
|
||||
if (options.parser !== "babel-ts") {
|
||||
return false;
|
||||
}
|
||||
const { errors = {}, disableBabelTS } = options;
|
||||
errors["babel-ts"] = disableBabelTS;
|
||||
|
||||
const { disableBabelTS } = options;
|
||||
const files = errors[options.parser];
|
||||
|
||||
if (disableBabelTS === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Array.isArray(disableBabelTS) && disableBabelTS.includes(filename)) {
|
||||
if (files === true || (Array.isArray(files) && files.includes(filename))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -77,7 +80,9 @@ const shouldThrowOnFormat = (filename, options) => {
|
||||
};
|
||||
|
||||
const isTestDirectory = (dirname, name) =>
|
||||
dirname.startsWith(path.join(__dirname, "../tests", name));
|
||||
(dirname + path.sep).startsWith(
|
||||
path.join(__dirname, "../tests", name) + path.sep
|
||||
);
|
||||
|
||||
function runSpec(fixtures, parsers, options) {
|
||||
let { dirname, snippets = [] } =
|
||||
@@ -144,6 +149,15 @@ function runSpec(fixtures, parsers, options) {
|
||||
allParsers.push("babel-ts");
|
||||
}
|
||||
|
||||
if (
|
||||
parsers.includes("babel") &&
|
||||
!parsers.includes("espree") &&
|
||||
isTestDirectory(dirname, "js") &&
|
||||
!espreeDisabledTests.has(dirname)
|
||||
) {
|
||||
allParsers.push("espree");
|
||||
}
|
||||
|
||||
const stringifiedOptions = stringifyOptionsForTitle(options);
|
||||
|
||||
for (const { name, filename, code, output } of [...files, ...snippets]) {
|
||||
|
||||
@@ -6,6 +6,7 @@ function composeOptionsForSnapshot(baseOptions, parsers) {
|
||||
plugins,
|
||||
filepath,
|
||||
parser,
|
||||
errors,
|
||||
|
||||
...snapshotOptions
|
||||
} = baseOptions;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
function stringifyOptions(options) {
|
||||
const string = JSON.stringify(options || {}, (key, value) =>
|
||||
key === "disableBabelTS" || key === "plugins"
|
||||
key === "disableBabelTS" || key === "plugins" || key === "errors"
|
||||
? undefined
|
||||
: value === Infinity
|
||||
? "Infinity"
|
||||
|
||||
@@ -84,7 +84,7 @@ Format options:
|
||||
Defaults to false.
|
||||
--jsx-single-quote Use single quotes in JSX.
|
||||
Defaults to false.
|
||||
--parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
--parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
Which parser to use.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
Defaults to 80.
|
||||
@@ -180,7 +180,7 @@ exports[`show warning with --help not-found (typo) (stderr) 1`] = `
|
||||
`;
|
||||
|
||||
exports[`show warning with --help not-found (typo) (stdout) 1`] = `
|
||||
"--parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
"--parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
|
||||
Which parser to use.
|
||||
|
||||
@@ -191,6 +191,7 @@ Valid options:
|
||||
babel-flow Flow
|
||||
babel-ts TypeScript
|
||||
typescript TypeScript
|
||||
espree JavaScript
|
||||
css CSS
|
||||
less Less
|
||||
scss SCSS
|
||||
@@ -244,7 +245,7 @@ Format options:
|
||||
Defaults to false.
|
||||
--jsx-single-quote Use single quotes in JSX.
|
||||
Defaults to false.
|
||||
--parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
--parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
Which parser to use.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
Defaults to 80.
|
||||
|
||||
@@ -361,7 +361,7 @@ exports[`show detailed usage with --help no-semi (write) 1`] = `Array []`;
|
||||
exports[`show detailed usage with --help parser (stderr) 1`] = `""`;
|
||||
|
||||
exports[`show detailed usage with --help parser (stdout) 1`] = `
|
||||
"--parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
"--parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
|
||||
Which parser to use.
|
||||
|
||||
@@ -372,6 +372,7 @@ Valid options:
|
||||
babel-flow Flow
|
||||
babel-ts TypeScript
|
||||
typescript TypeScript
|
||||
espree JavaScript
|
||||
css CSS
|
||||
less Less
|
||||
scss SCSS
|
||||
|
||||
@@ -20,8 +20,8 @@ exports[` 1`] = `
|
||||
Defaults to false.
|
||||
--jsx-single-quote Use single quotes in JSX.
|
||||
Defaults to false.
|
||||
- --parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
+ --parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc|foo-parser>
|
||||
- --parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
+ --parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc|foo-parser>
|
||||
Which parser to use.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
Defaults to 80.
|
||||
|
||||
@@ -20,8 +20,8 @@ exports[` 1`] = `
|
||||
Defaults to false.
|
||||
--jsx-single-quote Use single quotes in JSX.
|
||||
Defaults to false.
|
||||
- --parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
+ --parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc|foo-parser>
|
||||
- --parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc>
|
||||
+ --parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc|foo-parser>
|
||||
Which parser to use.
|
||||
--print-width <int> The line length where Prettier will try wrap.
|
||||
Defaults to 80.
|
||||
@@ -32,7 +32,7 @@ exports[` 1`] = `
|
||||
exports[`include plugin's parsers to the values of the \`parser\` option\` (stderr) 1`] = `""`;
|
||||
|
||||
exports[`include plugin's parsers to the values of the \`parser\` option\` (stdout) 1`] = `
|
||||
"--parser <flow|babel|babel-flow|babel-ts|typescript|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc|foo-parser>
|
||||
"--parser <flow|babel|babel-flow|babel-ts|typescript|espree|css|less|scss|json|json5|json-stringify|graphql|markdown|mdx|vue|yaml|html|angular|lwc|foo-parser>
|
||||
|
||||
Which parser to use.
|
||||
|
||||
@@ -43,6 +43,7 @@ Valid options:
|
||||
babel-flow Flow
|
||||
babel-ts TypeScript
|
||||
typescript TypeScript
|
||||
espree JavaScript
|
||||
css CSS
|
||||
less Less
|
||||
scss SCSS
|
||||
|
||||
@@ -162,6 +162,12 @@ This option cannot be used with --range-start and --range-end.",
|
||||
"typescript",
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"description": "JavaScript",
|
||||
"enum": Array [
|
||||
"espree",
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"description": "CSS",
|
||||
"enum": Array [
|
||||
|
||||
@@ -37,9 +37,11 @@ Object {
|
||||
"babel-ts",
|
||||
"flow",
|
||||
"typescript",
|
||||
"espree",
|
||||
],
|
||||
"JavaScript": Array [
|
||||
"babel",
|
||||
"espree",
|
||||
"babel-flow",
|
||||
"babel-ts",
|
||||
"flow",
|
||||
@@ -150,6 +152,7 @@ Object {
|
||||
"babel-flow",
|
||||
"babel-ts",
|
||||
"typescript",
|
||||
"espree",
|
||||
"css",
|
||||
"less",
|
||||
"scss",
|
||||
@@ -313,7 +316,14 @@ exports[`CLI --support-info (stdout) 1`] = `
|
||||
],
|
||||
\\"linguistLanguageId\\": 183,
|
||||
\\"name\\": \\"JavaScript\\",
|
||||
\\"parsers\\": [\\"babel\\", \\"babel-flow\\", \\"babel-ts\\", \\"flow\\", \\"typescript\\"],
|
||||
\\"parsers\\": [
|
||||
\\"babel\\",
|
||||
\\"espree\\",
|
||||
\\"babel-flow\\",
|
||||
\\"babel-ts\\",
|
||||
\\"flow\\",
|
||||
\\"typescript\\"
|
||||
],
|
||||
\\"since\\": \\"0.0.0\\",
|
||||
\\"tmScope\\": \\"source.js\\",
|
||||
\\"type\\": \\"programming\\",
|
||||
@@ -355,7 +365,14 @@ exports[`CLI --support-info (stdout) 1`] = `
|
||||
\\"group\\": \\"JavaScript\\",
|
||||
\\"linguistLanguageId\\": 178,
|
||||
\\"name\\": \\"JSX\\",
|
||||
\\"parsers\\": [\\"babel\\", \\"babel-flow\\", \\"babel-ts\\", \\"flow\\", \\"typescript\\"],
|
||||
\\"parsers\\": [
|
||||
\\"babel\\",
|
||||
\\"babel-flow\\",
|
||||
\\"babel-ts\\",
|
||||
\\"flow\\",
|
||||
\\"typescript\\",
|
||||
\\"espree\\"
|
||||
],
|
||||
\\"since\\": \\"0.0.0\\",
|
||||
\\"tmScope\\": \\"source.js.jsx\\",
|
||||
\\"type\\": \\"programming\\",
|
||||
@@ -864,6 +881,7 @@ exports[`CLI --support-info (stdout) 1`] = `
|
||||
\\"since\\": \\"1.4.0\\",
|
||||
\\"value\\": \\"typescript\\"
|
||||
},
|
||||
{ \\"description\\": \\"JavaScript\\", \\"since\\": \\"2.2.0\\", \\"value\\": \\"espree\\" },
|
||||
{ \\"description\\": \\"CSS\\", \\"since\\": \\"1.7.1\\", \\"value\\": \\"css\\" },
|
||||
{ \\"description\\": \\"Less\\", \\"since\\": \\"1.7.1\\", \\"value\\": \\"less\\" },
|
||||
{ \\"description\\": \\"SCSS\\", \\"since\\": \\"1.7.1\\", \\"value\\": \\"scss\\" },
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export default function (parser) {
|
||||
switch (parser) {
|
||||
case "babel":
|
||||
case "espree":
|
||||
return [
|
||||
'function HelloWorld({greeting = "hello", greeted = \'"World"\', silent = false, onMouseOver,}) {',
|
||||
"",
|
||||
|
||||
@@ -38,6 +38,7 @@ function getMarkdownSyntax(options) {
|
||||
case "babel":
|
||||
case "babel-flow":
|
||||
case "flow":
|
||||
case "espree":
|
||||
return "jsx";
|
||||
case "babel-ts":
|
||||
case "typescript":
|
||||
|
||||
@@ -68,6 +68,7 @@ export function getAstAutoFold(parser) {
|
||||
case "babel-flow":
|
||||
case "babel-ts":
|
||||
case "typescript":
|
||||
case "espree":
|
||||
case "json":
|
||||
case "json5":
|
||||
case "json-stringify":
|
||||
|
||||
@@ -1703,9 +1703,9 @@ acorn-globals@^6.0.0:
|
||||
acorn-walk "^7.1.1"
|
||||
|
||||
acorn-jsx@^5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.2.0.tgz#4c66069173d6fdd68ed85239fc256226182b2ebe"
|
||||
integrity sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ==
|
||||
version "5.3.1"
|
||||
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b"
|
||||
integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==
|
||||
|
||||
acorn-walk@^7.1.1:
|
||||
version "7.2.0"
|
||||
@@ -3625,7 +3625,7 @@ eslint@7.11.0:
|
||||
text-table "^0.2.0"
|
||||
v8-compile-cache "^2.0.3"
|
||||
|
||||
espree@^7.3.0:
|
||||
espree@7.3.0, espree@^7.3.0:
|
||||
version "7.3.0"
|
||||
resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.0.tgz#dc30437cf67947cf576121ebd780f15eeac72348"
|
||||
integrity sha512-dksIWsvKCixn1yrEXO8UosNSxaDoSYpq9reEjZSbHLpT5hpaCAKTLBwq0RHtLrIr+c0ByiYzWT8KTMRzoRCNlw==
|
||||
|
||||
Reference in new issue
Block a user