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

fix: Derive espree.Syntax from espree.VisitorKeys #532

Merged
merged 2 commits into from
Feb 9, 2022
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
18 changes: 8 additions & 10 deletions espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

import * as acorn from "acorn";
import jsx from "acorn-jsx";
import astNodeTypes from "./lib/ast-node-types.js";
import espree from "./lib/espree.js";
import espreeVersion from "./lib/version.js";
import * as visitorKeys from "eslint-visitor-keys";
Expand Down Expand Up @@ -141,8 +140,12 @@ export function parse(code, options) {

export const version = espreeVersion;

/* istanbul ignore next */
export const VisitorKeys = (function() {
return visitorKeys.KEYS;
}());

// Deep copy.
// Derive node types from VisitorKeys
/* istanbul ignore next */
export const Syntax = (function() {
let name,
Expand All @@ -152,9 +155,9 @@ export const Syntax = (function() {
types = Object.create(null);
}

for (name in astNodeTypes) {
if (Object.hasOwnProperty.call(astNodeTypes, name)) {
types[name] = astNodeTypes[name];
for (name in VisitorKeys) {
if (Object.hasOwnProperty.call(VisitorKeys, name)) {
types[name] = name;
}
}

Expand All @@ -165,11 +168,6 @@ export const Syntax = (function() {
return types;
}());

/* istanbul ignore next */
export const VisitorKeys = (function() {
return visitorKeys.KEYS;
}());

export const latestEcmaVersion = getLatestEcmaVersion();

export const supportedEcmaVersions = getSupportedEcmaVersions();
94 changes: 0 additions & 94 deletions lib/ast-node-types.js

This file was deleted.

24 changes: 24 additions & 0 deletions tests/lib/syntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @fileoverview Test for Syntax.
*/

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

import assert from "assert";
import * as espree from "../../espree.js";


//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

describe("Syntax", () => {
it("keys of Syntax should match the keys of VisitorKeys", () => {
assert.deepStrictEqual(
Object.keys(espree.Syntax),
Object.keys(espree.VisitorKeys)
);
});
});