microsoft / microsoft/node-jsonc-parser

parseTree - Option to keep comments

Open
#28 6 comments 4 reactions 1 assignee View on GitHub

@aeschli is already working on this.

Since Oct 28, 2019.

feature-request help wanted
Dominant language
TypeScript
Stars
759
Forks
66
Avg merge
5d 10h
Merged PRs (30d)
7

Description

Thanks for this library! I wrote a jsonc code formatter using it.

Right now I'm using the scanner to get the comments around the nodes in the tree. It would be slightly faster to not rescan these out and instead get all the comments when calling parseTree.

A simple solution would may be to have an option that returns all the comments in an array. Maybe something like...

export function parseTree(text: string, errors: ParseError[] = [], options: ParseOptions = ParseOptions.DEFAULT): Node;

Goes to:

export function parseTree(text: string, options: ParseOptions = ParseOptions.DEFAULT): ParseResult;

interface ParseResult {
	file: Node;
	errors: ParseError[];
	/** Included when `options.includeComments` is true. **/
	comments?: Comment[];
};

Then:

export interface ParseOptions {
	disallowComments?: boolean;
	allowTrailingComma?: boolean;
	allowEmptyContent?: boolean;
}

Goes to:

export interface ParseOptions {
	disallowComments?: boolean;
	includeComments?: boolean;
	allowTrailingComma?: boolean;
	allowEmptyContent?: boolean;
}

Thoughts? I could submit a PR for this, but will just need some direction on how the public API should look.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.