Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add tests for ecmaVersion default value #460

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down