diff --git a/package.json b/package.json
index 2ba1961e7..0ce6b2aa0 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,7 @@
"editorconfig": "0.15.3",
"editorconfig-to-prettier": "0.2.0",
"escape-string-regexp": "4.0.0",
- "espree": "7.3.1",
+ "espree": "8.0.0",
"esutils": "2.0.3",
"fast-glob": "3.2.5",
"fast-json-stable-stringify": "2.1.0",
diff --git a/src/language-js/parser-espree.js b/src/language-js/parser-espree.js
index a7abe00ab..77eb5972c 100644
--- a/src/language-js/parser-espree.js
+++ b/src/language-js/parser-espree.js
@@ -1,11 +1,14 @@
"use strict";
+
const createError = require("../common/parser-create-error");
const tryCombinations = require("../utils/try-combinations");
const postprocess = require("./parse-postprocess");
const createParser = require("./parser/create-parser");
const replaceHashbang = require("./parser/replace-hashbang");
+/** @type {import("espree").Options} */
const parseOptions = {
+ ecmaVersion: "latest",
range: true,
loc: true,
comment: true,
@@ -30,8 +33,7 @@ function createParseError(error) {
}
function parse(originalText, parsers, options) {
- const { parse, latestEcmaVersion } = require("espree");
- parseOptions.ecmaVersion = latestEcmaVersion;
+ const { parse } = require("espree");
const textToParse = replaceHashbang(originalText);
const { result: ast, error: moduleParseError } = tryCombinations(
diff --git a/tests/format/js/arrow-call/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/arrow-call/__snapshots__/jsfmt.spec.js.snap
index c7d0ae146..0a3a3cd0e 100644
--- a/tests/format/js/arrow-call/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/arrow-call/__snapshots__/jsfmt.spec.js.snap
@@ -302,26 +302,6 @@ promise.then((result) =>
================================================================================
`;
-exports[`class-property.js [espree] format 1`] = `
-"Unexpected token = (3:22)
- 1 | const composition = (ViewComponent, ContainerComponent) =>
- 2 | class extends React.Component {
-> 3 | static propTypes = {};
- | ^
- 4 | };
- 5 |"
-`;
-
-exports[`class-property.js - {"arrowParens":"always"} [espree] format 1`] = `
-"Unexpected token = (3:22)
- 1 | const composition = (ViewComponent, ContainerComponent) =>
- 2 | class extends React.Component {
-> 3 | static propTypes = {};
- | ^
- 4 | };
- 5 |"
-`;
-
exports[`class-property.js - {"arrowParens":"always"} format 1`] = `
====================================options=====================================
arrowParens: "always"
@@ -343,16 +323,6 @@ const composition = (ViewComponent, ContainerComponent) =>
================================================================================
`;
-exports[`class-property.js - {"trailingComma":"all"} [espree] format 1`] = `
-"Unexpected token = (3:22)
- 1 | const composition = (ViewComponent, ContainerComponent) =>
- 2 | class extends React.Component {
-> 3 | static propTypes = {};
- | ^
- 4 | };
- 5 |"
-`;
-
exports[`class-property.js - {"trailingComma":"all"} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
diff --git a/tests/format/js/arrow-call/jsfmt.spec.js b/tests/format/js/arrow-call/jsfmt.spec.js
index f7ff242dd..c4f8a4239 100644
--- a/tests/format/js/arrow-call/jsfmt.spec.js
+++ b/tests/format/js/arrow-call/jsfmt.spec.js
@@ -1,6 +1,4 @@
-const errors = {
- espree: ["class-property.js"],
-};
+const errors = {};
run_spec(__dirname, ["babel", "flow", "typescript"], {
errors,
diff --git a/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap
index cf3b93fc4..2f181ce7d 100644
--- a/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap
@@ -322,17 +322,6 @@ const alsoGoodPrecision = 9007199254740993n;
================================================================================
`;
-exports[`class-properties.js [espree] format 1`] = `
-"Unexpected token = (5:22)
- 3 | class Bork {
- 4 | //Property initializer syntax
-> 5 | instanceProperty = \\"bork\\";
- | ^
- 6 | boundFunction = () => {
- 7 | return this.instanceProperty;
- 8 | };"
-`;
-
exports[`class-properties.js format 1`] = `
====================================options=====================================
parsers: ["babel", "babel-ts", "babel-flow"]
@@ -398,13 +387,14 @@ console.log(Bork.staticFunction()); // > "babelIsCool"
`;
exports[`class-static-block.js [espree] format 1`] = `
-"Unexpected character '#' (2:10)
- 1 | class C {
-> 2 | static #x = 42;
- | ^
+"Unexpected token { (4:10)
+ 2 | static #x = 42;
3 | static y;
- 4 | static {
- 5 | try {"
+> 4 | static {
+ | ^
+ 5 | try {
+ 6 | this.y = doSomethingWith(this.#x);
+ 7 | } catch {"
`;
exports[`class-static-block.js [meriyah] format 1`] = `
@@ -1738,14 +1728,14 @@ value
`;
exports[`private-fields-in-in.js [espree] format 1`] = `
-"Unexpected character '#' (4:3)
- 2 |
- 3 | class C {
-> 4 | #brand;
- | ^
- 5 |
- 6 | static isC(obj) {
- 7 | try {"
+"Unexpected token #brand (44:12)
+ 42 |
+ 43 | static isC(obj) {
+> 44 | return #brand in obj && #method in obj && #getter in obj;
+ | ^
+ 45 | }
+ 46 | }
+ 47 |"
`;
exports[`private-fields-in-in.js format 1`] = `
@@ -1769,7 +1759,7 @@ class C {
}
}
-class C {
+class C2 {
#data = null; // populated later
get #getter() {
@@ -1789,7 +1779,7 @@ class C {
}
}
-class C {
+class C3 {
#brand;
#method() {}
@@ -1826,7 +1816,7 @@ class C {
}
}
-class C {
+class C2 {
#data = null; // populated later
get #getter() {
@@ -1846,7 +1836,7 @@ class C {
}
}
-class C {
+class C3 {
#brand;
#method() {}
@@ -1870,17 +1860,6 @@ class C {
================================================================================
`;
-exports[`private-methods.js [espree] format 1`] = `
-"Unexpected character '#' (6:3)
- 4 |
- 5 | class Counter extends HTMLElement {
-> 6 | #xValue = 0;
- | ^
- 7 |
- 8 | get #x() { return this.#xValue; }
- 9 | set #x(value) {"
-`;
-
exports[`private-methods.js format 1`] = `
====================================options=====================================
parsers: ["babel", "babel-ts", "babel-flow"]
@@ -1893,6 +1872,7 @@ printWidth: 80
class Counter extends HTMLElement {
#xValue = 0;
+ #render() {}
get #x() { return this.#xValue; }
set #x(value) {
@@ -1913,6 +1893,7 @@ class Counter extends HTMLElement {
class Counter extends HTMLElement {
#xValue = 0;
+ #render() {}
get #x() {
return this.#xValue;
@@ -1931,9 +1912,9 @@ class Counter extends HTMLElement {
`;
exports[`record-tuple-record.js [espree] format 1`] = `
-"Unexpected character '#' (1:17)
+"Unexpected character '{' (1:18)
> 1 | const record1 = #{
- | ^
+ | ^
2 | a: 1,
3 | b: 2,
4 | c: 3,"
@@ -1975,9 +1956,9 @@ const record2 = #{ ...record1, b: 5 };
`;
exports[`record-tuple-tuple.js [espree] format 1`] = `
-"Unexpected character '#' (1:16)
+"Unexpected character '[' (1:17)
> 1 | const tuple1 = #[1, 2, 3];
- | ^
+ | ^
2 |"
`;
diff --git a/tests/format/js/babel-plugins/jsfmt.spec.js b/tests/format/js/babel-plugins/jsfmt.spec.js
index 87e4633cf..b4b9e45ac 100644
--- a/tests/format/js/babel-plugins/jsfmt.spec.js
+++ b/tests/format/js/babel-plugins/jsfmt.spec.js
@@ -4,7 +4,6 @@
run_spec(__dirname, ["babel", "babel-ts", "babel-flow"], {
errors: {
espree: [
- "class-properties.js",
"decimal.js",
"decorators.js",
"do-expressions.js",
@@ -19,7 +18,6 @@ run_spec(__dirname, ["babel", "babel-ts", "babel-flow"], {
"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",
diff --git a/tests/format/js/babel-plugins/private-fields-in-in.js b/tests/format/js/babel-plugins/private-fields-in-in.js
index aba8e5df9..247ae66cb 100644
--- a/tests/format/js/babel-plugins/private-fields-in-in.js
+++ b/tests/format/js/babel-plugins/private-fields-in-in.js
@@ -13,7 +13,7 @@ class C {
}
}
-class C {
+class C2 {
#data = null; // populated later
get #getter() {
@@ -33,7 +33,7 @@ class C {
}
}
-class C {
+class C3 {
#brand;
#method() {}
diff --git a/tests/format/js/babel-plugins/private-methods.js b/tests/format/js/babel-plugins/private-methods.js
index e1486a9fb..0a9fc7c9f 100644
--- a/tests/format/js/babel-plugins/private-methods.js
+++ b/tests/format/js/babel-plugins/private-methods.js
@@ -4,6 +4,7 @@
class Counter extends HTMLElement {
#xValue = 0;
+ #render() {}
get #x() { return this.#xValue; }
set #x(value) {
diff --git a/tests/format/js/class-comment/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/class-comment/__snapshots__/jsfmt.spec.js.snap
index 4eaeb76b6..cddf25eca 100644
--- a/tests/format/js/class-comment/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/class-comment/__snapshots__/jsfmt.spec.js.snap
@@ -1,15 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`class-property.js [espree] format 1`] = `
-"Unexpected token = (2:12)
- 1 | class X {
-> 2 | TEMPLATE =
- | ^
- 3 | // tab index is needed so we can focus, which is needed for keyboard events
- 4 | '
' +
- 5 | '
' +"
-`;
-
exports[`class-property.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
diff --git a/tests/format/js/class-comment/jsfmt.spec.js b/tests/format/js/class-comment/jsfmt.spec.js
index 49b534281..eb85eda6b 100644
--- a/tests/format/js/class-comment/jsfmt.spec.js
+++ b/tests/format/js/class-comment/jsfmt.spec.js
@@ -1,5 +1 @@
-run_spec(__dirname, ["babel", "flow", "typescript"], {
- errors: {
- espree: ["class-property.js"],
- },
-});
+run_spec(__dirname, ["babel", "flow", "typescript"]);
diff --git a/tests/format/js/class-static-block/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/class-static-block/__snapshots__/jsfmt.spec.js.snap
index 70b25ea88..95a7cc8be 100644
--- a/tests/format/js/class-static-block/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/class-static-block/__snapshots__/jsfmt.spec.js.snap
@@ -1,13 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`class-static-block.js [espree] format 1`] = `
-"Unexpected character '#' (2:10)
- 1 | class C {
-> 2 | static #x = 42;
- | ^
+"Unexpected token { (4:10)
+ 2 | static #x = 42;
3 | static y;
- 4 | static {
- 5 | try {"
+> 4 | static {
+ | ^
+ 5 | try {
+ 6 | this.y = doSomethingWith(this.#x);
+ 7 | } catch {"
`;
exports[`class-static-block.js [meriyah] format 1`] = `
diff --git a/tests/format/js/classes-private-fields/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/classes-private-fields/__snapshots__/jsfmt.spec.js.snap
index 67fe4bafd..cc26e61e9 100644
--- a/tests/format/js/classes-private-fields/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/classes-private-fields/__snapshots__/jsfmt.spec.js.snap
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`optional-chaining.js [espree] format 1`] = `
-"Unexpected character '#' (3:13)
+"Private field '#x' must be declared in an enclosing class (3:13)
1 | // https://github.com/babel/babel/pull/11669
2 |
> 3 | delete obj?.#x.a
@@ -19,7 +19,7 @@ exports[`optional-chaining.js [meriyah] format 1`] = `
`;
exports[`optional-chaining.js - {"semi":false} [espree] format 1`] = `
-"Unexpected character '#' (3:13)
+"Private field '#x' must be declared in an enclosing class (3:13)
1 | // https://github.com/babel/babel/pull/11669
2 |
> 3 | delete obj?.#x.a
@@ -73,24 +73,6 @@ delete obj?.#x.a;
================================================================================
`;
-exports[`private_fields.js [espree] format 1`] = `
-"Unexpected character '#' (1:11)
-> 1 | class A { #x; #y; }
- | ^
- 2 | class B { #x = 0; #y = 1; }
- 3 |
- 4 | class C {"
-`;
-
-exports[`private_fields.js - {"semi":false} [espree] format 1`] = `
-"Unexpected character '#' (1:11)
-> 1 | class A { #x; #y; }
- | ^
- 2 | class B { #x = 0; #y = 1; }
- 3 |
- 4 | class C {"
-`;
-
exports[`private_fields.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel"]
@@ -348,26 +330,6 @@ class F {
================================================================================
`;
-exports[`with_comments.js [espree] format 1`] = `
-"Unexpected character '#' (2:3)
- 1 | class A {
-> 2 | #foobar =
- | ^
- 3 | // comment to break
- 4 | 1 +
- 5 | // comment to break again"
-`;
-
-exports[`with_comments.js - {"semi":false} [espree] format 1`] = `
-"Unexpected character '#' (2:3)
- 1 | class A {
-> 2 | #foobar =
- | ^
- 3 | // comment to break
- 4 | 1 +
- 5 | // comment to break again"
-`;
-
exports[`with_comments.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel"]
diff --git a/tests/format/js/classes-private-fields/jsfmt.spec.js b/tests/format/js/classes-private-fields/jsfmt.spec.js
index 4085f7737..fa5b7d9ca 100644
--- a/tests/format/js/classes-private-fields/jsfmt.spec.js
+++ b/tests/format/js/classes-private-fields/jsfmt.spec.js
@@ -1,7 +1,11 @@
+const errors = {
+ meriyah: ["optional-chaining.js"],
+ espree: ["optional-chaining.js"],
+};
run_spec(__dirname, ["babel"], {
- errors: { espree: true, meriyah: ["optional-chaining.js"] },
+ errors,
});
run_spec(__dirname, ["babel"], {
semi: false,
- errors: { espree: true, meriyah: ["optional-chaining.js"] },
+ errors,
});
diff --git a/tests/format/js/classes/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/classes/__snapshots__/jsfmt.spec.js.snap
index 44873cab8..192c21fb2 100644
--- a/tests/format/js/classes/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/classes/__snapshots__/jsfmt.spec.js.snap
@@ -212,16 +212,6 @@ new Ctor(class {});
================================================================================
`;
-exports[`property.js [espree] format 1`] = `
-"Unexpected token = (2:10)
- 1 | class A {
-> 2 | foobar =
- | ^
- 3 | // comment to break
- 4 | 1 +
- 5 | // comment to break again"
-`;
-
exports[`property.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
diff --git a/tests/format/js/classes/jsfmt.spec.js b/tests/format/js/classes/jsfmt.spec.js
index c883bd4e5..eb85eda6b 100644
--- a/tests/format/js/classes/jsfmt.spec.js
+++ b/tests/format/js/classes/jsfmt.spec.js
@@ -1,3 +1 @@
-run_spec(__dirname, ["babel", "flow", "typescript"], {
- errors: { espree: ["property.js"] },
-});
+run_spec(__dirname, ["babel", "flow", "typescript"]);
diff --git a/tests/format/js/empty-paren-comment/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/empty-paren-comment/__snapshots__/jsfmt.spec.js.snap
index e91495cca..0151ae287 100644
--- a/tests/format/js/empty-paren-comment/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/empty-paren-comment/__snapshots__/jsfmt.spec.js.snap
@@ -25,17 +25,6 @@ class x {
================================================================================
`;
-exports[`class-property.js [espree] format 1`] = `
-"Unexpected token = (4:5)
- 2 | f(/* ... */) {}
- 3 | f() /* ... */ {}
-> 4 | f = (/* ... */) => {};
- | ^
- 5 | static f(/* ... */) {};
- 6 | static f = (/* ... */) => {};
- 7 | static f = function(/* ... */) {};"
-`;
-
exports[`class-property.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
diff --git a/tests/format/js/empty-paren-comment/jsfmt.spec.js b/tests/format/js/empty-paren-comment/jsfmt.spec.js
index 833888c25..eb85eda6b 100644
--- a/tests/format/js/empty-paren-comment/jsfmt.spec.js
+++ b/tests/format/js/empty-paren-comment/jsfmt.spec.js
@@ -1,3 +1 @@
-run_spec(__dirname, ["babel", "flow", "typescript"], {
- errors: { espree: ["class-property.js"] },
-});
+run_spec(__dirname, ["babel", "flow", "typescript"]);
diff --git a/tests/format/js/for-of/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/for-of/__snapshots__/jsfmt.spec.js.snap
index 1dcc6d0b4..1aaf61bd1 100644
--- a/tests/format/js/for-of/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/for-of/__snapshots__/jsfmt.spec.js.snap
@@ -1,16 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`async-identifier.js [espree] format 1`] = `
-"Unexpected token [ (6:23)
- 4 |
- 5 | async function f() {
-> 6 | for await (async of []);
- | ^
- 7 | for await ((async) of []);
- 8 | for await ((foo) of async);
- 9 | for await ((foo) of []) async;"
-`;
-
exports[`async-identifier.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
diff --git a/tests/format/js/for-of/jsfmt.spec.js b/tests/format/js/for-of/jsfmt.spec.js
index ac56eed1b..eb85eda6b 100644
--- a/tests/format/js/for-of/jsfmt.spec.js
+++ b/tests/format/js/for-of/jsfmt.spec.js
@@ -1,3 +1 @@
-run_spec(__dirname, ["babel", "flow", "typescript"], {
- errors: { espree: ["async-identifier.js"] },
-});
+run_spec(__dirname, ["babel", "flow", "typescript"]);
diff --git a/tests/format/js/no-semi/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/no-semi/__snapshots__/jsfmt.spec.js.snap
index 5435656fc..806961a62 100644
--- a/tests/format/js/no-semi/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/no-semi/__snapshots__/jsfmt.spec.js.snap
@@ -1,27 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`class.js [espree] format 1`] = `
-"Unexpected token ; (12:6)
- 10 |
- 11 | class C1 {
-> 12 | get; // The semicolon *is* necessary
- | ^
- 13 | x(){}
- 14 | }
- 15 | class C2 {"
-`;
-
-exports[`class.js - {"semi":false} [espree] format 1`] = `
-"Unexpected token ; (12:6)
- 10 |
- 11 | class C1 {
-> 12 | get; // The semicolon *is* necessary
- | ^
- 13 | x(){}
- 14 | }
- 15 | class C2 {"
-`;
-
exports[`class.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow"]
@@ -1008,26 +986,6 @@ aReallyLongLine012345678901234567890123456789012345678901234567890123456789 *
================================================================================
`;
-exports[`private-field.js [espree] format 1`] = `
-"Unexpected character '#' (2:3)
- 1 | class C {
-> 2 | #field = 'value';
- | ^
- 3 | [\\"method\\"]() {}
- 4 | }
- 5 |"
-`;
-
-exports[`private-field.js - {"semi":false} [espree] format 1`] = `
-"Unexpected character '#' (2:3)
- 1 | class C {
-> 2 | #field = 'value';
- | ^
- 3 | [\\"method\\"]() {}
- 4 | }
- 5 |"
-`;
-
exports[`private-field.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow"]
diff --git a/tests/format/js/no-semi/jsfmt.spec.js b/tests/format/js/no-semi/jsfmt.spec.js
index c5222b708..54459ab48 100644
--- a/tests/format/js/no-semi/jsfmt.spec.js
+++ b/tests/format/js/no-semi/jsfmt.spec.js
@@ -1,4 +1,2 @@
-const errors = { espree: ["class.js", "private-field.js"] };
-
-run_spec(__dirname, ["babel", "flow"], { errors });
-run_spec(__dirname, ["babel", "flow"], { semi: false, errors });
+run_spec(__dirname, ["babel", "flow"], {});
+run_spec(__dirname, ["babel", "flow"], { semi: false });
diff --git a/tests/format/js/private-in/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/private-in/__snapshots__/jsfmt.spec.js.snap
index c4a9c07ae..877f0ea65 100644
--- a/tests/format/js/private-in/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/private-in/__snapshots__/jsfmt.spec.js.snap
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`private-in.js [espree] format 1`] = `
-"Unexpected character '#' (1:5)
+"Unexpected token #prop (1:5)
> 1 | if (#prop in obj) {
| ^
2 | }
diff --git a/tests/format/js/quote-props/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/quote-props/__snapshots__/jsfmt.spec.js.snap
index 23a2343d8..607faf8b4 100644
--- a/tests/format/js/quote-props/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/quote-props/__snapshots__/jsfmt.spec.js.snap
@@ -1,15 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`classes.js - {"quoteProps":"as-needed"} [espree] format 1`] = `
-"Unexpected token = (2:5)
- 1 | class A {
-> 2 | a = \\"a\\"
- | ^
- 3 | };
- 4 |
- 5 | class B {"
-`;
-
exports[`classes.js - {"quoteProps":"as-needed"} format 1`] = `
====================================options=====================================
parsers: ["babel"]
@@ -57,16 +47,6 @@ class D {
================================================================================
`;
-exports[`classes.js - {"quoteProps":"consistent","singleQuote":true} [espree] format 1`] = `
-"Unexpected token = (2:5)
- 1 | class A {
-> 2 | a = \\"a\\"
- | ^
- 3 | };
- 4 |
- 5 | class B {"
-`;
-
exports[`classes.js - {"quoteProps":"consistent","singleQuote":true} format 1`] = `
====================================options=====================================
parsers: ["babel"]
@@ -115,16 +95,6 @@ class D {
================================================================================
`;
-exports[`classes.js - {"quoteProps":"consistent"} [espree] format 1`] = `
-"Unexpected token = (2:5)
- 1 | class A {
-> 2 | a = \\"a\\"
- | ^
- 3 | };
- 4 |
- 5 | class B {"
-`;
-
exports[`classes.js - {"quoteProps":"consistent"} format 1`] = `
====================================options=====================================
parsers: ["babel"]
@@ -172,16 +142,6 @@ class D {
================================================================================
`;
-exports[`classes.js - {"quoteProps":"preserve"} [espree] format 1`] = `
-"Unexpected token = (2:5)
- 1 | class A {
-> 2 | a = \\"a\\"
- | ^
- 3 | };
- 4 |
- 5 | class B {"
-`;
-
exports[`classes.js - {"quoteProps":"preserve"} format 1`] = `
====================================options=====================================
parsers: ["babel"]
diff --git a/tests/format/js/quote-props/jsfmt.spec.js b/tests/format/js/quote-props/jsfmt.spec.js
index 3939c465a..3190476f2 100644
--- a/tests/format/js/quote-props/jsfmt.spec.js
+++ b/tests/format/js/quote-props/jsfmt.spec.js
@@ -1,6 +1,4 @@
-const errors = {
- espree: ["classes.js"],
-};
+const errors = {};
run_spec(__dirname, ["babel"], {
quoteProps: "as-needed",
diff --git a/tests/format/js/record/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/record/__snapshots__/jsfmt.spec.js.snap
index a4651e52d..0c7712f19 100644
--- a/tests/format/js/record/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/record/__snapshots__/jsfmt.spec.js.snap
@@ -1,10 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`computed.js [espree] format 1`] = `
-"Unexpected character '#' (2:8)
+"Unexpected character '{' (2:9)
1 | const key = \\"a\\";
> 2 | assert(#{ [key]: 1 } === #{ a: 1 })
- | ^
+ | ^
3 | assert(#{ [key.toUpperCase()]: 1 } === #{ A: 1 })
4 |
5 | assert(#{ [true]: 1 } === #{ true: 1 })"
@@ -51,9 +51,9 @@ assert(#{ [9 + 1]: "ten" } === #{ ["10"]: "ten" });
`;
exports[`destructuring.js [espree] format 1`] = `
-"Unexpected character '#' (1:18)
+"Unexpected character '{' (1:19)
> 1 | const { a, b } = #{ a: 1, b: 2 };
- | ^
+ | ^
2 | assert(a === 1);
3 | assert(b === 2);
4 |"
@@ -99,9 +99,9 @@ assert(rest.c === 3);
`;
exports[`record.js [espree] format 1`] = `
-"Unexpected character '#' (1:17)
+"Unexpected character '{' (1:18)
> 1 | const record1 = #{
- | ^
+ | ^
2 | a: 1,
3 | b: 2,
4 | c: 3,"
@@ -161,10 +161,10 @@ assert(record1.d?.a === undefined);
`;
exports[`shorthand.js [espree] format 1`] = `
-"Unexpected character '#' (2:16)
+"Unexpected character '{' (2:17)
1 | const url = \\"https://github.com/tc39/proposal-record-tuple\\";
> 2 | const record = #{ url }
- | ^
+ | ^
3 | console.log(record.url) // https://github.com/tc39/proposal-record-tuple
4 |"
`;
@@ -197,9 +197,9 @@ console.log(record.url); // https://github.com/tc39/proposal-record-tuple
`;
exports[`spread.js [espree] format 1`] = `
-"Unexpected character '#' (1:18)
+"Unexpected character '{' (1:19)
> 1 | const formData = #{ title: \\"Implement all the things\\" }
- | ^
+ | ^
2 | const taskNow = #{ id: 42, status: \\"WIP\\", ...formData }
3 | const taskLater = #{ ...taskNow, status: \\"DONE\\" }
4 |"
@@ -239,9 +239,9 @@ assert(taskLater === #{ status: "DONE", title: formData.title, id: 42 });
`;
exports[`syntax.js [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '{' (1:2)
> 1 | #{}
- | ^
+ | ^
2 | #{ a: 1, b: 2 }
3 | #{ a: 1, b: #[2, 3, #{ c: 4 }] }
4 |"
diff --git a/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap
index e1e9e91b3..16fca66a6 100644
--- a/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap
@@ -1,12 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`d-flag.js [espree] format 1`] = `
-"Invalid regular expression flag (1:2)
-> 1 | /./d;
- | ^
- 2 |"
-`;
-
exports[`d-flag.js [flow] format 1`] = `
"Invalid flags supplied to RegExp constructor 'd' (1:5)
> 1 | /./d;
diff --git a/tests/format/js/regex/jsfmt.spec.js b/tests/format/js/regex/jsfmt.spec.js
index fe800ee65..a833212bd 100644
--- a/tests/format/js/regex/jsfmt.spec.js
+++ b/tests/format/js/regex/jsfmt.spec.js
@@ -1,7 +1,6 @@
run_spec(__dirname, ["babel", "flow", "typescript"], {
errors: {
flow: ["d-flag.js"],
- espree: ["d-flag.js"],
meriyah: ["d-flag.js"],
},
});
diff --git a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap
index 4da5b3c20..2628d9838 100644
--- a/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/strings/__snapshots__/jsfmt.spec.js.snap
@@ -1,5 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`non-octal-eight-and-nine.js [espree] format 1`] = `
+"Invalid escape sequence (3:3)
+ 1 | // https://github.com/babel/babel/pull/11852
+ 2 |
+> 3 | \\"\\\\8\\",\\"\\\\9\\";
+ | ^
+ 4 | () => {
+ 5 | \\"use strict\\";
+ 6 | \\"\\\\8\\", \\"\\\\9\\";"
+`;
+
+exports[`non-octal-eight-and-nine.js - {"trailingComma":"all"} [espree] format 1`] = `
+"Invalid escape sequence (3:3)
+ 1 | // https://github.com/babel/babel/pull/11852
+ 2 |
+> 3 | \\"\\\\8\\",\\"\\\\9\\";
+ | ^
+ 4 | () => {
+ 5 | \\"use strict\\";
+ 6 | \\"\\\\8\\", \\"\\\\9\\";"
+`;
+
exports[`non-octal-eight-and-nine.js - {"trailingComma":"all"} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow"]
diff --git a/tests/format/js/strings/jsfmt.spec.js b/tests/format/js/strings/jsfmt.spec.js
index ea848c99e..8db31903d 100644
--- a/tests/format/js/strings/jsfmt.spec.js
+++ b/tests/format/js/strings/jsfmt.spec.js
@@ -1,2 +1,7 @@
-run_spec(__dirname, ["babel", "flow"]);
-run_spec(__dirname, ["babel", "flow"], { trailingComma: "all" });
+run_spec(__dirname, ["babel", "flow"], {
+ errors: { espree: ["non-octal-eight-and-nine.js"] },
+});
+run_spec(__dirname, ["babel", "flow"], {
+ trailingComma: "all",
+ errors: { espree: ["non-octal-eight-and-nine.js"] },
+});
diff --git a/tests/format/js/top-level-await/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/top-level-await/__snapshots__/jsfmt.spec.js.snap
index 1ab9ae795..9908ed9a7 100644
--- a/tests/format/js/top-level-await/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/top-level-await/__snapshots__/jsfmt.spec.js.snap
@@ -1,12 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`example.js [espree] format 1`] = `
-"Cannot use keyword 'await' outside an async function (1:1)
-> 1 | await something();
- | ^
- 2 |"
-`;
-
exports[`example.js [meriyah] format 1`] = `
"[1:5]: 'Await' may not be used as an identifier in this context (1:5)
> 1 | await something();
diff --git a/tests/format/js/top-level-await/jsfmt.spec.js b/tests/format/js/top-level-await/jsfmt.spec.js
index 93e955c84..9c681df32 100644
--- a/tests/format/js/top-level-await/jsfmt.spec.js
+++ b/tests/format/js/top-level-await/jsfmt.spec.js
@@ -1,3 +1,3 @@
run_spec(__dirname, ["babel", "typescript"], {
- errors: { espree: true, meriyah: true },
+ errors: { meriyah: true },
});
diff --git a/tests/format/js/tuple/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/tuple/__snapshots__/jsfmt.spec.js.snap
index dfb722765..b5b7ce713 100644
--- a/tests/format/js/tuple/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/js/tuple/__snapshots__/jsfmt.spec.js.snap
@@ -1,9 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`destructuring.js [espree] format 1`] = `
-"Unexpected character '#' (1:16)
+"Unexpected character '[' (1:17)
> 1 | const [a, b] = #[1, 2];
- | ^
+ | ^
2 | assert(a === 1);
3 | assert(b === 2);
4 |"
@@ -63,9 +63,9 @@ exports[`invalid-tuple-holes.js [babel] format 1`] = `
`;
exports[`invalid-tuple-holes.js [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '[' (1:2)
> 1 | #[,]
- | ^
+ | ^
2 |"
`;
@@ -77,9 +77,9 @@ exports[`invalid-tuple-holes.js [meriyah] format 1`] = `
`;
exports[`syntax.js [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '[' (1:2)
> 1 | #[]
- | ^
+ | ^
2 | #[1, 2]
3 | #[1, 2, #{ a: 3 }]
4 |"
@@ -113,9 +113,9 @@ printWidth: 80
`;
exports[`tuple.js [espree] format 1`] = `
-"Unexpected character '#' (1:16)
+"Unexpected character '[' (1:17)
> 1 | const tuple1 = #[1, 2, 3];
- | ^
+ | ^
2 |
3 | assert(tuple1[0] === 1);
4 |"
@@ -177,9 +177,9 @@ assert(tuple5 === #[2, 2, 3, 4]);
`;
exports[`tuple-trailing-comma.js [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '[' (1:2)
> 1 | #[1,]
- | ^
+ | ^
2 |"
`;
diff --git a/tests/format/misc/errors/js/async-await/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/async-await/__snapshots__/jsfmt.spec.js.snap
index ae58604af..bc7354615 100644
--- a/tests/format/misc/errors/js/async-await/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/misc/errors/js/async-await/__snapshots__/jsfmt.spec.js.snap
@@ -29,19 +29,11 @@ exports[`snippet: #0 [espree] format 1`] = `
`;
exports[`snippet: #0 [espree] format 2`] = `
-"Cannot use keyword 'await' outside an async function (1:12)
+"Await expression cannot be a default value (1:12)
> 1 | async (x = await (2)) => {};
| ^"
`;
-exports[`snippet: #0 [espree] format 3`] = `
-"Unexpected token = (2:5)
- 1 | export class C {
-> 2 | p = await 0;
- | ^
- 3 | }"
-`;
-
exports[`snippet: #0 [flow] format 1`] = `
"Unexpected number, expected the token \`,\` (2:26)
1 | async function foo() {
@@ -91,7 +83,7 @@ exports[`snippet: #1 [babel] format 3`] = `
`;
exports[`snippet: #1 [espree] format 1`] = `
-"Cannot use keyword 'await' outside an async function (1:12)
+"Await expression cannot be a default value (1:12)
> 1 | async (x = await 2) => {};
| ^"
`;
@@ -102,12 +94,6 @@ exports[`snippet: #1 [espree] format 2`] = `
| ^"
`;
-exports[`snippet: #1 [espree] format 3`] = `
-"Cannot use keyword 'await' outside an async function (1:1)
-> 1 | await 0;
- | ^"
-`;
-
exports[`snippet: #1 [flow] format 1`] = `
"Unexpected number, expected the token \`,\` (1:18)
> 1 | async (x = await 2) => {};
diff --git a/tests/format/misc/errors/js/async-await/jsfmt.spec.js b/tests/format/misc/errors/js/async-await/jsfmt.spec.js
index ed8d92816..4310cf1f2 100644
--- a/tests/format/misc/errors/js/async-await/jsfmt.spec.js
+++ b/tests/format/misc/errors/js/async-await/jsfmt.spec.js
@@ -59,5 +59,5 @@ run_spec(
"await 0;",
],
},
- ["espree", "meriyah"]
+ ["meriyah"]
);
diff --git a/tests/format/misc/errors/js/record/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/record/__snapshots__/jsfmt.spec.js.snap
index e53d48b7f..519b7cbbd 100644
--- a/tests/format/misc/errors/js/record/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/misc/errors/js/record/__snapshots__/jsfmt.spec.js.snap
@@ -7,9 +7,9 @@ exports[`snippet: #0 [babel] format 1`] = `
`;
exports[`snippet: #0 [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '{' (1:2)
> 1 | #{a() {}}
- | ^"
+ | ^"
`;
exports[`snippet: #0 [meriyah] format 1`] = `
@@ -25,9 +25,9 @@ exports[`snippet: #1 [babel] format 1`] = `
`;
exports[`snippet: #1 [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '{' (1:2)
> 1 | #{async b() {}}
- | ^"
+ | ^"
`;
exports[`snippet: #1 [meriyah] format 1`] = `
@@ -43,9 +43,9 @@ exports[`snippet: #2 [babel] format 1`] = `
`;
exports[`snippet: #2 [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '{' (1:2)
> 1 | #{get c() {}}
- | ^"
+ | ^"
`;
exports[`snippet: #2 [meriyah] format 1`] = `
@@ -61,9 +61,9 @@ exports[`snippet: #3 [babel] format 1`] = `
`;
exports[`snippet: #3 [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '{' (1:2)
> 1 | #{set d(_) {}}
- | ^"
+ | ^"
`;
exports[`snippet: #3 [meriyah] format 1`] = `
@@ -79,9 +79,9 @@ exports[`snippet: #4 [babel] format 1`] = `
`;
exports[`snippet: #4 [espree] format 1`] = `
-"Unexpected character '#' (1:1)
+"Unexpected character '{' (1:2)
> 1 | #{*e() {}}
- | ^"
+ | ^"
`;
exports[`snippet: #4 [meriyah] format 1`] = `
diff --git a/tsconfig.json b/tsconfig.json
index 4ffdab6ec..0c539b74a 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -7,7 +7,8 @@
"module": "commonjs",
"resolveJsonModule": true,
// TBD it is desired to enabled strict type checking at some point:
- "strict": false
+ "strict": false,
+ "typeRoots": ["./types", "./node_modules/@types"]
},
"exclude": [
"coverage/",
@@ -42,6 +43,7 @@
"docs/",
"scripts/",
"tests/",
- "website/"
+ "website/",
+ "types/"
]
}
diff --git a/types/espree/index.d.ts b/types/espree/index.d.ts
new file mode 100644
index 000000000..30f77c994
--- /dev/null
+++ b/types/espree/index.d.ts
@@ -0,0 +1,38 @@
+declare module "espree" {
+ // https://github.com/eslint/espree#options
+ export interface Options {
+ range?: boolean;
+ loc?: boolean;
+ comment?: boolean;
+ tokens?: boolean;
+ ecmaVersion?:
+ | 3
+ | 5
+ | 6
+ | 7
+ | 8
+ | 9
+ | 10
+ | 11
+ | 12
+ | 2015
+ | 2016
+ | 2017
+ | 2018
+ | 2019
+ | 2020
+ | 2021
+ | 2022
+ | "latest";
+ sourceType?: "script" | "module";
+ ecmaFeatures?: {
+ jsx?: boolean;
+ globalReturn?: boolean;
+ impliedStrict?: boolean;
+ };
+ }
+ // https://github.com/eslint/espree#options
+ export function parse(code: string, options?: Options): any;
+ // https://github.com/eslint/espree#tokenize
+ export function tokenize(code: string, options?: Options): any;
+}
diff --git a/yarn.lock b/yarn.lock
index 3d9cf1b7c..c9d4b77f2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2965,6 +2965,7 @@ eslint-plugin-jest@24.3.6:
"eslint-plugin-prettier-internal-rules@link:scripts/tools/eslint-plugin-prettier-internal-rules":
version "0.0.0"
+ uid ""
eslint-plugin-react@7.24.0:
version "7.24.0"
@@ -3058,6 +3059,11 @@ eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
+eslint-visitor-keys@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.0.0.tgz#e32e99c6cdc2eb063f204eda5db67bfe58bb4186"
+ integrity sha512-mJOZa35trBTb3IyRmo8xmKBZlxf+N7OnUl4+ZhJHs/r+0770Wh/LEACE2pqMGMe27G/4y8P2bYGk4J70IC5k1Q==
+
eslint@7.30.0:
version "7.30.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.30.0.tgz#6d34ab51aaa56112fd97166226c9a97f505474f8"
@@ -3109,7 +3115,16 @@ esm-utils@1.1.0:
resolved "https://registry.yarnpkg.com/esm-utils/-/esm-utils-1.1.0.tgz#026fd8c97eee9a9b956f6f3890c9b6b5b57c4771"
integrity sha512-vm3Q1u5RvJFKbizsyK4POBdFjXJFwA+1zEbSAuC+ekjOVWGt/FCXfY8b548fccFLGPihOu1CuS//EOUsj6jczA==
-espree@7.3.1, espree@^7.3.0, espree@^7.3.1:
+espree@8.0.0:
+ version "8.0.0"
+ resolved "https://registry.yarnpkg.com/espree/-/espree-8.0.0.tgz#08c92c31814c96c96c54d3a35cc80f1cdb420275"
+ integrity sha512-y/+i23dwTjIDJrYCcjcAMr3c3UGbPIjC6THMQKjWmhP97fW0FPiI89kmpKfmgV/5jrkIi6toQP+CMm3qBE1Hig==
+ dependencies:
+ acorn "^8.4.1"
+ acorn-jsx "^5.3.1"
+ eslint-visitor-keys "^3.0.0"
+
+espree@^7.3.0, espree@^7.3.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.1.tgz#f2df330b752c6f55019f8bd89b7660039c1bbbb6"
integrity sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==