Skip to content
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
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ test/
.gitignore
.mocharc.json
.eslintrc.json
eslint.config.cjs
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"runtimeArgs": [
"--enable-source-maps",
"--test",
"./lib/umd/test/**/*.test.js"
"./lib/esm/test/**/*.test.js"
],
"env": {},
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/lib/umd/**/*.js"],
"outFiles": ["${workspaceRoot}/lib/esm/**/*.js"],
"preLaunchTask": "npm: watch"
}
]
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
4.0.0-next.1 2026-03-04
=================
- package is now ESM-only.
- remove UMD build and package entrypoints.


3.3.0 2022-06-24
=================
- `JSONVisitor.onObjectBegin` and `JSONVisitor.onArrayBegin` can now return `false` to instruct the visitor that no children should be visited.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ JSONC is JSON with JavaScript style comments. This node module provides a scanne
Installation
------------

`jsonc-parser` is published as an ESM-only package.

```
npm install --save jsonc-parser
```
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "jsonc-parser",
"version": "3.3.1",
"version": "4.0.0-next.1",
"description": "Scanner and parser for JSON with comments.",
"main": "./lib/umd/main.js",
"typings": "./lib/umd/main.d.ts",
"module": "./lib/esm/main.js",
"type": "module",
"exports": {
".": {
"types": "./lib/esm/main.d.ts",
"import": "./lib/esm/main.js"
}
},
"types": "./lib/esm/main.d.ts",
"author": "Microsoft Corporation",
"repository": {
"type": "git",
Expand All @@ -23,13 +28,12 @@
"typescript": "^5.8.3"
},
"scripts": {
"prepack": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
"prepack": "npm run clean && npm run compile && npm run test && npm run remove-sourcemap-refs",
"compile": "tsc -p ./src && npm run lint",
"compile-esm": "tsc -p ./src/tsconfig.esm.json",
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.js",
"remove-sourcemap-refs": "node ./build/remove-sourcemap-refs.cjs",
"clean": "rimraf lib",
"watch": "tsc -w -p ./src",
"test": "npm run compile && node --enable-source-maps --test ./lib/umd/test/**/*.test.js",
"test": "npm run compile && node --enable-source-maps --test ./lib/esm/test/**/*.test.js",
"lint": "eslint src/**/*.ts"
}
}
6 changes: 3 additions & 3 deletions src/impl/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Edit, ParseError, Node, JSONPath, Segment, ModificationOptions } from '../main';
import { format, isEOL } from './format';
import { parseTree, findNodeAtLocation } from './parser';
import { Edit, ParseError, Node, JSONPath, Segment, ModificationOptions } from '../main.js';
import { format, isEOL } from './format.js';
import { parseTree, findNodeAtLocation } from './parser.js';

export function removeProperty(text: string, path: JSONPath, options: ModificationOptions): Edit[] {
return setProperty(text, path, void 0, options);
Expand Down
6 changes: 3 additions & 3 deletions src/impl/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Range, FormattingOptions, Edit, SyntaxKind, ScanError } from '../main';
import { createScanner } from './scanner';
import { cachedSpaces, cachedBreakLinesWithSpaces, supportedEols, SupportedEOL } from './string-intern';
import { Range, FormattingOptions, Edit, SyntaxKind, ScanError } from '../main.js';
import { createScanner } from './scanner.js';
import { cachedSpaces, cachedBreakLinesWithSpaces, supportedEols, SupportedEOL } from './string-intern.js';

export function format(documentText: string, range: Range | undefined, options: FormattingOptions): Edit[] {
let initialIndentLevel: number;
Expand Down
4 changes: 2 additions & 2 deletions src/impl/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { createScanner } from './scanner';
import { createScanner } from './scanner.js';
import {
JSONPath,
JSONVisitor,
Expand All @@ -17,7 +17,7 @@ import {
ScanError,
Segment,
SyntaxKind
} from '../main';
} from '../main.js';

namespace ParseOptionsConfigs {
export const DEFAULT = {
Expand Down
2 changes: 1 addition & 1 deletion src/impl/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { ScanError, SyntaxKind, JSONScanner } from '../main';
import { ScanError, SyntaxKind, JSONScanner } from '../main.js';

/**
* Creates a JSON scanner on the given text.
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import * as formatter from './impl/format';
import * as edit from './impl/edit';
import * as scanner from './impl/scanner';
import * as parser from './impl/parser';
import * as formatter from './impl/format.js';
import * as edit from './impl/edit.js';
import * as scanner from './impl/scanner.js';
import * as parser from './impl/parser.js';

/**
* Creates a JSON scanner on the given text.
Expand Down
10 changes: 5 additions & 5 deletions src/test/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

import * as assert from 'node:assert';
import { suite, test } from 'node:test';
import { Edit, FormattingOptions, ModificationOptions, modify } from '../main';
import { Edit, FormattingOptions, ModificationOptions, modify } from '../main.js';

suite('JSON - edits', () => {

function assertEdit(content: string, edits: Edit[], expected: string) {
assert(edits);
assert.ok(edits);
let lastEditOffset = content.length;
for (let i = edits.length - 1; i >= 0; i--) {
let edit = edits[i];
assert(edit.offset >= 0 && edit.length >= 0 && edit.offset + edit.length <= content.length);
assert(typeof edit.content === 'string');
assert(lastEditOffset >= edit.offset + edit.length); // make sure all edits are ordered
assert.ok(edit.offset >= 0 && edit.length >= 0 && edit.offset + edit.length <= content.length);
assert.ok(typeof edit.content === 'string');
assert.ok(lastEditOffset >= edit.offset + edit.length); // make sure all edits are ordered
lastEditOffset = edit.offset;
content = content.substring(0, edit.offset) + edit.content + content.substring(edit.offset + edit.length);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import * as assert from 'node:assert';
import { suite, test } from 'node:test';
import * as Formatter from '../impl/format';
import { Range } from '../main';
import * as Formatter from '../impl/format.js';
import { Range } from '../main.js';

suite('JSON - formatter', () => {

Expand Down
8 changes: 4 additions & 4 deletions src/test/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { suite, test } from 'node:test';
import {
SyntaxKind, createScanner, parse, getLocation, Node, ParseError, parseTree, ParseErrorCode,
ParseOptions, Segment, findNodeAtLocation, getNodeValue, getNodePath, ScanError, visit, JSONVisitor, JSONPath
} from '../main';
} from '../main.js';

function assertKinds(text: string, ...kinds: SyntaxKind[]): void {
var scanner = createScanner(text);
Expand Down Expand Up @@ -44,7 +44,7 @@ function assertInvalidParse(input: string, expected: any, options?: ParseOptions
var errors: ParseError[] = [];
var actual = parse(input, errors, options);

assert(errors.length > 0);
assert.ok(errors.length > 0);
assert.deepStrictEqual(actual, expected);
}

Expand Down Expand Up @@ -118,7 +118,7 @@ function assertLocation(input: string, expectedSegments: Segment[], expectedNode
var offset = input.indexOf('|');
input = input.substring(0, offset) + input.substring(offset + 1, input.length);
var actual = getLocation(input, offset);
assert(actual);
assert.ok(actual);
assert.deepStrictEqual(actual.path, expectedSegments, input);
assert.strictEqual(actual.previousNode && actual.previousNode.type, expectedNodeType, input);
assert.strictEqual(actual.isAtPropertyKey, expectedCompleteProperty, input);
Expand All @@ -128,7 +128,7 @@ function assertMatchesLocation(input: string, matchingSegments: Segment[], expec
var offset = input.indexOf('|');
input = input.substring(0, offset) + input.substring(offset + 1, input.length);
var actual = getLocation(input, offset);
assert(actual);
assert.ok(actual);
assert.strictEqual(actual.matches(matchingSegments), expectedResult);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/string-intern.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'node:assert';
import { suite, test } from 'node:test';
import { cachedBreakLinesWithSpaces, cachedSpaces, supportedEols } from '../impl/string-intern';
import { cachedBreakLinesWithSpaces, cachedSpaces, supportedEols } from '../impl/string-intern.js';

suite('string intern', () => {
test('should correctly define spaces intern', () => {
Expand Down
16 changes: 0 additions & 16 deletions src/tsconfig.esm.json

This file was deleted.

6 changes: 3 additions & 3 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"target": "es2020",
"module": "umd",
"moduleResolution": "node",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"sourceMap": true,
"declaration": true,
"stripInternal": true,
"outDir": "../lib/umd",
"outDir": "../lib/esm",
"strict": true,
"preserveConstEnums": true,
"lib": [
Expand Down