@speclynx/apidom-parser-adapter-json 1.12.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/NOTICE +16 -7
  3. package/README.md +36 -25
  4. package/dist/167.apidom-parser-adapter-json.browser.min.js +1 -1
  5. package/dist/451.apidom-parser-adapter-json.browser.min.js +1 -1
  6. package/dist/apidom-parser-adapter-json.browser.js +3101 -12890
  7. package/dist/apidom-parser-adapter-json.browser.min.js +1 -1
  8. package/package.json +7 -11
  9. package/src/adapter.cjs +29 -34
  10. package/src/adapter.mjs +26 -31
  11. package/src/native/index.cjs +30 -0
  12. package/src/native/index.mjs +25 -0
  13. package/src/tree-sitter/index.cjs +54 -0
  14. package/src/tree-sitter/index.mjs +48 -0
  15. package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.cjs +1 -1
  16. package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.mjs +1 -1
  17. package/src/tree-sitter/syntactic-analysis/index.cjs +223 -0
  18. package/src/tree-sitter/syntactic-analysis/index.mjs +219 -0
  19. package/types/apidom-parser-adapter-json.d.ts +14 -33
  20. package/src/syntactic-analysis/TreeCursorIterator.cjs +0 -62
  21. package/src/syntactic-analysis/TreeCursorIterator.mjs +0 -57
  22. package/src/syntactic-analysis/TreeCursorSyntaxNode.cjs +0 -51
  23. package/src/syntactic-analysis/TreeCursorSyntaxNode.mjs +0 -47
  24. package/src/syntactic-analysis/direct/index.cjs +0 -64
  25. package/src/syntactic-analysis/direct/index.mjs +0 -59
  26. package/src/syntactic-analysis/direct/visitors/CstVisitor.cjs +0 -163
  27. package/src/syntactic-analysis/direct/visitors/CstVisitor.mjs +0 -158
  28. package/src/syntactic-analysis/indirect/index.cjs +0 -56
  29. package/src/syntactic-analysis/indirect/index.mjs +0 -49
  30. package/src/syntactic-analysis/indirect/visitors/CstVisitor.cjs +0 -177
  31. package/src/syntactic-analysis/indirect/visitors/CstVisitor.mjs +0 -172
  32. package/src/syntactic-analysis/indirect/visitors/JsonAstVisitor.cjs +0 -189
  33. package/src/syntactic-analysis/indirect/visitors/JsonAstVisitor.mjs +0 -183
package/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.0.1](https://github.com/speclynx/apidom/compare/v2.0.0...v2.0.1) (2026-01-14)
7
+
8
+ **Note:** Version bump only for package @speclynx/apidom-parser-adapter-json
9
+
10
+ # [2.0.0](https://github.com/speclynx/apidom/compare/v1.12.2...v2.0.0) (2026-01-14)
11
+
12
+ ### Bug Fixes
13
+
14
+ - limit source maps memory consuption ([#20](https://github.com/speclynx/apidom/issues/20)) ([4a0574f](https://github.com/speclynx/apidom/commit/4a0574fd6d466be7c33c8a5871baacd384918d22))
15
+
16
+ ### Features
17
+
18
+ - add support for strict mode in JSON/YAML parser adapters ([#22](https://github.com/speclynx/apidom/issues/22)) ([a9c5f11](https://github.com/speclynx/apidom/commit/a9c5f11e8748135e7ba578b61d2f1807e11d34aa))
19
+ - apply innovations learned during last 3 years ([#11](https://github.com/speclynx/apidom/issues/11)) ([cfdbbfc](https://github.com/speclynx/apidom/commit/cfdbbfc2721b0dadc77eeba31dd4e8768c078d22))
20
+
21
+ ### BREAKING CHANGES
22
+
23
+ - source maps have been completely rewritten
24
+ - breaking changes introduced to every package public API
25
+
26
+ ## [1.12.2](https://github.com/speclynx/apidom/compare/v1.12.1...v1.12.2) (2025-12-23)
27
+
28
+ **Note:** Version bump only for package @speclynx/apidom-parser-adapter-json
29
+
6
30
  ## [1.12.1](https://github.com/speclynx/apidom/compare/v1.12.0...v1.12.1) (2025-12-23)
7
31
 
8
32
  **Note:** Version bump only for package @speclynx/apidom-parser-adapter-json
package/NOTICE CHANGED
@@ -5,11 +5,6 @@ This distribution includes modifications by SpecLynx.
5
5
  All such modifications are licensed under the Apache License, Version 2.0.
6
6
  A copy of the Apache 2.0 license can be found in `LICENSES/Apache-2.0.txt`.
7
7
 
8
- ApiDOM
9
- Copyright 2020 SmartBear Software Inc.
10
- ApiDOM is licensed under Apache 2.0 license.
11
- Copy of the Apache 2.0 license can be found in `LICENSES/Apache-2.0.txt` file.
12
-
13
8
  json-schema-ref-parser
14
9
  Copyright (c) 2015 James Messinger
15
10
  File packages/apidom-reference/src/util/url.ts (the file) was originally created under MIT license in https://github.com/APIDevTools/json-schema-ref-parser repository.
@@ -18,8 +13,8 @@ Copy of the MIT license can be found in `LICENSES/MIT.txt` file.
18
13
 
19
14
  graphql-js
20
15
  Copyright (c) GraphQL Contributors
21
- File packages/apidom-ast/src/traversal/visitor.ts (the file) was originally created under MIT license in https://github.com/graphql/graphql-js repository.
22
- The file has been copied into this project and modified. All modifications are licensed under Apache 2.0 License.
16
+ File packages/apidom-traverse/src/traversal.ts (the file) was originally inspired by https://github.com/graphql/graphql-js repository.
17
+ All modifications are licensed under Apache 2.0 License.
23
18
  Copy of the MIT license can be found in `LICENSES/MIT.txt` file.
24
19
 
25
20
  babel-plugin-add-import-extension
@@ -54,6 +49,20 @@ Copyright (c) 2012 James Halliday, Josh Duff, and other contributors
54
49
  Copy of the MIT license can be found in `LICENSES/MIT.txt` file.
55
50
  All modifications are licensed under Apache 2.0 License.
56
51
 
52
+ ApiDOM
53
+ Copyright 2020 SmartBear Software Inc.
54
+ ApiDOM is licensed under Apache 2.0 license.
55
+ Copy of the Apache 2.0 license can be found in `LICENSES/Apache-2.0.txt` file.
56
+
57
+ minim
58
+ Copyright (c) 2014 Stephen Mizell
59
+ The apidom-datamodel package contains code originally created under the MIT
60
+ License as part of the Minim project (https://github.com/refractproject/minim).
61
+ This code has been copied into this project and modified.
62
+ The original portions remain licensed under the MIT License. Our modifications
63
+ to that code are licensed under the Apache License 2.0.
64
+ Copy of the MIT license can be found in `LICENSES/MIT.txt` file.
65
+
57
66
  ---
58
67
 
59
68
  If the SPDX-FileCopyrightText and SPDX-License-Identifier tags are not present in the file,
package/README.md CHANGED
@@ -29,31 +29,12 @@ Syntactic Analysis will take a stream of tokens and turn it into an ApiDOM repre
29
29
  [CST](https://tree-sitter.github.io/tree-sitter/using-parsers#syntax-nodes) produced by lexical analysis is [syntactically analyzed](https://github.com/speclynx/apidom/blob/main/packages/apidom-parser-adapter-json/src/syntactic-analysis)
30
30
  and ApiDOM structure using [base ApiDOM namespace](https://github.com/speclynx/apidom/tree/main/packages/apidom#base-namespace) is produced.
31
31
 
32
- #### [Direct Syntactical analysis](https://github.com/speclynx/apidom/blob/main/packages/apidom-parser-adapter-json/src/syntactic-analysis/direct)
33
-
34
- This analysis directly turns tree-sitter CST into ApiDOM. Single traversal is required which makes
35
- it super performant, and it's the default analysis used.
32
+ This analysis directly turns tree-sitter CST into ApiDOM in a single traversal pass, making it highly performant.
36
33
 
37
34
  ```js
38
35
  import { parse } from '@speclynx/apidom-parser-adapter-json';
39
36
 
40
- const parseResult = await parse('{"prop": "value"}', {
41
- syntacticAnalysis: 'direct',
42
- });
43
- ```
44
-
45
- #### [Indirect Syntactic analysis]((https://github.com/speclynx/apidom/blob/main/packages/apidom-parser-adapter-json/src/syntactic-analysis/indirect))
46
-
47
- This analysis turns trees-sitter CST into [JSON AST](https://github.com/speclynx/apidom/tree/main/packages/apidom-ast#json-ast-nodes) representation.
48
- Then JSON AST is turned into ApiDOM. Two traversals are required, which makes indirect analysis less performant than direct one.
49
- Thought less performant, having JSON AST representation allows us to do further complex analysis.
50
-
51
- ```js
52
- import { parse } from '@speclynx/apidom-parser-adapter-json';
53
-
54
- const parseResult = await parse('{"prop": "value"}', {
55
- syntacticAnalysis: 'indirect',
56
- });
37
+ const parseResult = await parse('{"prop": "value"}');
57
38
  ```
58
39
 
59
40
  ## Parser adapter API
@@ -71,7 +52,14 @@ Defines list of media types that this parser adapter recognizes.
71
52
 
72
53
  ### detect
73
54
 
74
- [Detection](https://github.com/speclynx/apidom/blob/main/packages/apidom-parser-adapter-json/src/adapter.ts#L3) is based on using [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) to indicate whether the provided source string is or isn't JSON string.
55
+ Detection indicates whether the provided source string is valid JSON.
56
+
57
+ Option | Type | Default | Description
58
+ --- | --- | --- | ---
59
+ <a name="detect-strict"></a>`strict` | `Boolean` | `false` | Use strict detection mode (native `JSON.parse`).
60
+
61
+ In default mode, detection uses tree-sitter for parsing with error recovery.
62
+ In strict mode, detection uses native `JSON.parse` which is faster but requires valid JSON.
75
63
 
76
64
  ### namespace
77
65
 
@@ -84,10 +72,26 @@ This adapter exposes an instance of [base ApiDOM namespace](https://github.com/s
84
72
  Option | Type | Default | Description
85
73
  --- | --- | --- | ---
86
74
  <a name="sourceMap"></a>`sourceMap` | `Boolean` | `false` | Indicate whether to generate source maps.
87
- <a name="syntacticAnalysis"></a>`syntacticAnalysis` | `String` | `direct` | Indicate type of syntactic analysis
75
+ <a name="strict"></a>`strict` | `Boolean` | `false` | Use strict parsing mode (native `JSON.parse`). When `true`, parsing is faster but throws on invalid JSON and doesn't support source maps.
88
76
 
89
77
  All unrecognized arbitrary options will be ignored.
90
78
 
79
+ #### Parsing modes
80
+
81
+ This adapter supports two parsing modes:
82
+
83
+ **Tree-sitter mode** (default, `strict: false`):
84
+ - Uses [web-tree-sitter](https://www.npmjs.com/package/web-tree-sitter) for parsing
85
+ - Provides error recovery for malformed JSON
86
+ - Supports source map generation
87
+ - Slightly slower but more resilient
88
+
89
+ **Strict mode** (`strict: true`):
90
+ - Uses native `JSON.parse` for parsing
91
+ - Faster performance
92
+ - Throws `SyntaxError` on invalid JSON
93
+ - Does not support source maps (throws error if both `strict` and `sourceMap` are `true`)
94
+
91
95
  ## Usage
92
96
 
93
97
  This parser adapter can be used directly or indirectly via [@speclynx/apidom-parser](https://github.com/speclynx/apidom/tree/main/packages/apidom-parser).
@@ -100,12 +104,19 @@ with [supported media types](#mediatypes).
100
104
  ```js
101
105
  import { parse, detect } from '@speclynx/apidom-parser-adapter-json';
102
106
 
103
- // detecting
107
+ // detecting (tree-sitter mode - default)
104
108
  await detect('{"prop": "value"}'); // => true
105
109
  await detect('test'); // => false
106
110
 
107
- // parsing
111
+ // detecting (strict mode)
112
+ await detect('{"prop": "value"}', { strict: true }); // => true
113
+ await detect('{invalid}', { strict: true }); // => false
114
+
115
+ // parsing (tree-sitter mode - default, with source maps)
108
116
  const parseResult = await parse('{"prop": "value"}', { sourceMap: true });
117
+
118
+ // parsing (strict mode - faster, no source maps)
119
+ const parseResultStrict = await parse('{"prop": "value"}', { strict: true });
109
120
  ```
110
121
 
111
122
  ### Indirect usage
@@ -1 +1 @@
1
- (self.webpackChunkapidomParserAdapterJson=self.webpackChunkapidomParserAdapterJson||[]).push([[167],{9167:()=>{}}]);
1
+ (self.webpackChunkapidomParserAdapterJson=self.webpackChunkapidomParserAdapterJson||[]).push([[167],{167:()=>{}}]);
@@ -1 +1 @@
1
- (self.webpackChunkapidomParserAdapterJson=self.webpackChunkapidomParserAdapterJson||[]).push([[451],{9451:()=>{}}]);
1
+ (self.webpackChunkapidomParserAdapterJson=self.webpackChunkapidomParserAdapterJson||[]).push([[451],{451:()=>{}}]);