Skip to content

Commit

Permalink
fix: Derive espree.Syntax from espree.VisitorKeys (#532)
Browse files Browse the repository at this point in the history
* Fix: Derive espree/Syntax from espree/VisitorKeys

Fixes #531

* Chore: Delete obsolete lib/ast-node-types.js module
  • Loading branch information
codeworrior committed Feb 9, 2022
1 parent ea0cf6a commit 64010de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 104 deletions.
18 changes: 8 additions & 10 deletions espree.js
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
@@ -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)
);
});
});

0 comments on commit 64010de

Please sign in to comment.