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

feat: Add JSONLanguage#visitorKeys #4

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the dependency to ^3.1.1 in package.json.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so weird. I know I updated this locally and tested, and this is the second time you've pointed out that the version hasn't been updated in package.json. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it is updated in package.json but for some reason git isn't included it in the branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works if 3.1.1 is locally installed, which in most cases would be the case after doing npm install since it's the latest in-range version, but to be sure it should be set in package.json.


//-----------------------------------------------------------------------------
// 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