From 0e09d9a4f213cb87073a6a87cb7d6317b77d1a23 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Wed, 25 Nov 2020 21:33:48 +0100 Subject: [PATCH] Chore: Add tests for ecmaVersion default value (#460) --- tests/lib/options.js | 8 ++++++++ tests/lib/parse.js | 15 +++++++++++++++ tests/lib/tokenize.js | 10 ++++++++++ 3 files changed, 33 insertions(+) diff --git a/tests/lib/options.js b/tests/lib/options.js index 4a1a9806..29b50ee1 100644 --- a/tests/lib/options.js +++ b/tests/lib/options.js @@ -17,6 +17,14 @@ const assert = require("assert"), //------------------------------------------------------------------------------ describe("normalizeOptions", () => { + it("should set ecmaVersion to 5 if it wasn't specified", () => { + const option = {}; + + const output = normalizeOptions(option); + + assert.strictEqual(output.ecmaVersion, 5); + }); + it("should throw error for sourceType module and ecmaVersion < 6", () => { const option = { sourceType: "module", diff --git a/tests/lib/parse.js b/tests/lib/parse.js index fe0b73ed..b901c485 100644 --- a/tests/lib/parse.js +++ b/tests/lib/parse.js @@ -19,6 +19,21 @@ const assert = require("assert"), describe("parse()", () => { + describe("ecmaVersion", () => { + + it("should be 5 if not specified", () => { + + // `ecmaVersion: 3` would throw on getters/setters + espree.parse("var foo = { get bar() {} }"); + + // needs `ecmaVersion: 6` or higher + assert.throws(() => { + espree.parse("let foo"); + }); + }); + + }); + describe("modules", () => { it("should have correct column number when strict mode error occurs", () => { diff --git a/tests/lib/tokenize.js b/tests/lib/tokenize.js index 5a310d0c..f276a0f5 100644 --- a/tests/lib/tokenize.js +++ b/tests/lib/tokenize.js @@ -19,6 +19,16 @@ const assert = require("assert"), describe("tokenize()", () => { + it("should have `ecmaVersion: 5` as default", () => { + + // FIXME: is there a way to test that it isn't `ecmaVersion: 3`? + + // needs `ecmaVersion: 6` or higher + assert.throws(() => { + espree.tokenize("`template`"); + }); + }); + it("should produce tokens when using let", () => { const tokens = espree.tokenize("let foo = bar;", { ecmaVersion: 6,