Skip to content

Commit

Permalink
feat: Add JSONLanguage#visitorKeys (#4)
Browse files Browse the repository at this point in the history
* feat: Add JSONLanguage#visitorKeys

Release-As: 0.1.0

* Update package.json
  • Loading branch information
nzakas committed Jul 4, 2024
1 parent 4fcd8e0 commit d8afca4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
"linting"
],
"license": "Apache-2.0",
"dependencies": {
"@humanwhocodes/momoa": "^3.1.1"
},
"devDependencies": {
"@eslint/core": "^0.1.0",
"@types/eslint": "^8.56.10",
Expand All @@ -77,9 +80,6 @@
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"dependencies": {
"@humanwhocodes/momoa": "^3.0.6"
},
"peerDependencies": {
"eslint": "^9.6.0"
}
Expand Down
7 changes: 7 additions & 0 deletions src/languages/json-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { parse } from "@humanwhocodes/momoa";
import { JSONSourceCode } from "./json-source-code.js";
import { visitorKeys } from "@humanwhocodes/momoa";

//-----------------------------------------------------------------------------
// Types
Expand Down Expand Up @@ -59,6 +60,12 @@ export class JSONLanguage {
*/
#mode = "json";

/**
* The visitor keys.
* @type {Record<string, string[]>}
*/
visitorKeys = Object.fromEntries([...visitorKeys]);

/**
* Creates a new instance.
* @param {Object} options The options to use for this instance.
Expand Down
8 changes: 8 additions & 0 deletions tests/languages/json-language.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ import assert from "node:assert";
//-----------------------------------------------------------------------------

describe("JSONLanguage", () => {
describe("visitorKeys", () => {
it("should have visitorKeys property", () => {
const language = new JSONLanguage({ mode: "json" });

assert.deepStrictEqual(language.visitorKeys.Document, ["body"]);
});
});

describe("parse()", () => {
it("should not parse jsonc by default", () => {
const language = new JSONLanguage({ mode: "json" });
Expand Down

0 comments on commit d8afca4

Please sign in to comment.