diff --git a/README.md b/README.md index 6ccbc728..a13abb91 100644 --- a/README.md +++ b/README.md @@ -140,9 +140,9 @@ const options = { // create a top-level tokens array containing all tokens tokens: false, - // Set to 3, 5, 6, 7, 8, 9, 10, 11, or 12 to specify the version of ECMAScript syntax you want to use. + // Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, or 12 to specify the version of ECMAScript syntax you want to use. // You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), or 2022 (same as 13) to use the year-based naming. - // You can also set "latest" (the default) to use the most recently supported version. + // You can also set "latest" to use the most recently supported version. ecmaVersion: 5, // specify which type of script you're parsing ("script" or "module") diff --git a/lib/options.js b/lib/options.js index 434b9a5b..ae441ac3 100644 --- a/lib/options.js +++ b/lib/options.js @@ -42,7 +42,7 @@ export function getSupportedEcmaVersions() { * @throws {Error} throws an error if the ecmaVersion is invalid. * @returns {number} normalized ECMAScript version */ -function normalizeEcmaVersion(ecmaVersion = getLatestEcmaVersion()) { +function normalizeEcmaVersion(ecmaVersion = 5) { let version = ecmaVersion === "latest" ? getLatestEcmaVersion() : ecmaVersion; diff --git a/tests/lib/ecma-version.js b/tests/lib/ecma-version.js index 5d336fdb..179afa49 100644 --- a/tests/lib/ecma-version.js +++ b/tests/lib/ecma-version.js @@ -205,21 +205,15 @@ describe("ecmaVersion", () => { assert.deepStrictEqual(actual, expected); }); - it("Should use the latestEcmaVersion as the default for ecmaVersion", () => { - const expected = espree.parse( - "let foo = bar;", { - ecmaVersion: espree.latestEcmaVersion, - sourceType: "module" - } - ); + it("Should use the 5 as the default for ecmaVersion", () => { - const actual = espree.parse( - "let foo = bar;", { - sourceType: "module" - } - ); + assert.throws(() => { + espree.parse( + "let foo = bar;" + ); + + }, /Unexpected token foo/u); - assert.deepStrictEqual(actual, expected); }); }); diff --git a/tests/lib/options.js b/tests/lib/options.js index 61c9ac85..9c5571fb 100644 --- a/tests/lib/options.js +++ b/tests/lib/options.js @@ -16,12 +16,12 @@ import { normalizeOptions, getLatestEcmaVersion } from "../../lib/options.js"; //------------------------------------------------------------------------------ describe("normalizeOptions", () => { - it("should set ecmaVersion to latestEcmaVersion if it wasn't specified", () => { + it("should set ecmaVersion to 5 if it wasn't specified", () => { const option = {}; const output = normalizeOptions(option); - assert.strictEqual(output.ecmaVersion, getLatestEcmaVersion()); + assert.strictEqual(output.ecmaVersion, 5); }); it("should set ecmaVersion to latestEcmaVersion if ecmaVersion: latest is passed", () => { diff --git a/tests/lib/parse.js b/tests/lib/parse.js index 7df027f2..50c5345e 100644 --- a/tests/lib/parse.js +++ b/tests/lib/parse.js @@ -23,10 +23,20 @@ describe("parse()", () => { describe("ecmaVersion", () => { - it("should be latestEcmaVersion if not specified", () => { + it("should be 5 if not specified", () => { + + // needs `ecmaVersion: 5` or higher (`ecmaVersion: 3` would throw on getters/setters) + espree.parse("var foo = { get bar() {} }"); + + assert.throws(() => { + espree.parse( + + // needs `ecmaVersion: 6` or higher + "let foo = bar;" + ); + + }, /Unexpected token foo/u); - // `ecmaVersion: 5` would throw on async - espree.parse("let foo = { async bar() {} }"); }); }); diff --git a/tests/lib/tokenize.js b/tests/lib/tokenize.js index e4539c8b..531a6d8b 100644 --- a/tests/lib/tokenize.js +++ b/tests/lib/tokenize.js @@ -30,10 +30,14 @@ import tildeOperatorTokens from "../fixtures/tokenize/tilde-operator.tokens.js"; describe("tokenize()", () => { - it("should have latestEcmaVersion as default", () => { + it("should have 5 as default", () => { - // needs `ecmaVersion: 6` or higher - espree.tokenize("`template`"); + assert.throws(() => { + + // needs `ecmaVersion: 6` or higher + espree.tokenize("`template`"); + + }, /Unexpected character '`'/u); }); it("should produce tokens when using let", () => {