@speclynx/apidom-parser-adapter-json 2.11.0 → 2.12.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.
- package/CHANGELOG.md +10 -0
- package/README.md +8 -2
- package/dist/apidom-parser-adapter-json.browser.js +174 -10
- package/dist/apidom-parser-adapter-json.browser.min.js +1 -1
- package/package.json +5 -5
- package/src/adapter.cjs +6 -1
- package/src/adapter.mjs +6 -1
- package/src/tree-sitter/index.cjs +4 -2
- package/src/tree-sitter/index.mjs +4 -2
- package/src/tree-sitter/syntactic-analysis/index.cjs +58 -1
- package/src/tree-sitter/syntactic-analysis/index.mjs +58 -1
- package/types/apidom-parser-adapter-json.d.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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.12.1](https://github.com/speclynx/apidom/compare/v2.12.0...v2.12.1) (2026-02-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @speclynx/apidom-parser-adapter-json
|
|
9
|
+
|
|
10
|
+
# [2.12.0](https://github.com/speclynx/apidom/compare/v2.11.0...v2.12.0) (2026-02-18)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- add support for lossless JSON/YAML roundtrips ([#97](https://github.com/speclynx/apidom/issues/97)) ([dc17c9a](https://github.com/speclynx/apidom/commit/dc17c9a78fbc7df07a91e8f35b12be6409117d91))
|
|
15
|
+
|
|
6
16
|
# [2.11.0](https://github.com/speclynx/apidom/compare/v2.10.3...v2.11.0) (2026-02-12)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @speclynx/apidom-parser-adapter-json
|
package/README.md
CHANGED
|
@@ -72,7 +72,8 @@ This adapter exposes an instance of [base ApiDOM namespace](https://github.com/s
|
|
|
72
72
|
Option | Type | Default | Description
|
|
73
73
|
--- | --- | --- | ---
|
|
74
74
|
<a name="sourceMap"></a>`sourceMap` | `Boolean` | `false` | Indicate whether to generate source maps.
|
|
75
|
-
<a name="
|
|
75
|
+
<a name="style"></a>`style` | `Boolean` | `false` | Indicate whether to capture format-specific style information for round-trip preservation.
|
|
76
|
+
<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 or style preservation.
|
|
76
77
|
|
|
77
78
|
All unrecognized arbitrary options will be ignored.
|
|
78
79
|
|
|
@@ -84,6 +85,7 @@ This adapter supports two parsing modes:
|
|
|
84
85
|
- Uses [web-tree-sitter](https://www.npmjs.com/package/web-tree-sitter) for parsing
|
|
85
86
|
- Provides error recovery for malformed JSON
|
|
86
87
|
- Supports source map generation
|
|
88
|
+
- Supports style preservation (indentation, raw number representation)
|
|
87
89
|
- Slightly slower but more resilient
|
|
88
90
|
|
|
89
91
|
**Strict mode** (`strict: true`):
|
|
@@ -91,6 +93,7 @@ This adapter supports two parsing modes:
|
|
|
91
93
|
- Faster performance
|
|
92
94
|
- Throws `SyntaxError` on invalid JSON
|
|
93
95
|
- Does not support source maps (throws error if both `strict` and `sourceMap` are `true`)
|
|
96
|
+
- Does not support style preservation (throws error if both `strict` and `style` are `true`)
|
|
94
97
|
|
|
95
98
|
## Usage
|
|
96
99
|
|
|
@@ -115,7 +118,10 @@ await detect('{invalid}', { strict: true }); // => false
|
|
|
115
118
|
// parsing (tree-sitter mode - default, with source maps)
|
|
116
119
|
const parseResult = await parse('{"prop": "value"}', { sourceMap: true });
|
|
117
120
|
|
|
118
|
-
// parsing (
|
|
121
|
+
// parsing (tree-sitter mode, with style preservation)
|
|
122
|
+
const parseResultStyled = await parse('{"prop": "value"}', { style: true });
|
|
123
|
+
|
|
124
|
+
// parsing (strict mode - faster, no source maps or style)
|
|
119
125
|
const parseResultStrict = await parse('{"prop": "value"}', { strict: true });
|
|
120
126
|
```
|
|
121
127
|
|
|
@@ -136,12 +136,14 @@ const detect = async source => {
|
|
|
136
136
|
* @public
|
|
137
137
|
*/
|
|
138
138
|
const parse = async (source, {
|
|
139
|
-
sourceMap = false
|
|
139
|
+
sourceMap = false,
|
|
140
|
+
style = false
|
|
140
141
|
} = {}) => {
|
|
141
142
|
const cst = await (0,_lexical_analysis_index_ts__WEBPACK_IMPORTED_MODULE_0__["default"])(source);
|
|
142
143
|
try {
|
|
143
144
|
return (0,_syntactic_analysis_index_ts__WEBPACK_IMPORTED_MODULE_1__["default"])(cst, {
|
|
144
|
-
sourceMap
|
|
145
|
+
sourceMap,
|
|
146
|
+
style
|
|
145
147
|
});
|
|
146
148
|
} finally {
|
|
147
149
|
cst.delete();
|
|
@@ -244,6 +246,24 @@ const maybeAddSourceMap = (info, element, ctx) => {
|
|
|
244
246
|
element.endCharacter = info.endPosition.column;
|
|
245
247
|
element.endOffset = info.endIndex;
|
|
246
248
|
};
|
|
249
|
+
|
|
250
|
+
// build json style object for an element
|
|
251
|
+
const buildJsonStyle = (ctx, extras) => {
|
|
252
|
+
const jsonStyle = {
|
|
253
|
+
indent: ctx.indent
|
|
254
|
+
};
|
|
255
|
+
if (extras) Object.assign(jsonStyle, extras);
|
|
256
|
+
return {
|
|
257
|
+
json: jsonStyle
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// detect indent from an object's first pair child position
|
|
262
|
+
// called during transformChildren when we encounter the first pair
|
|
263
|
+
const detectIndent = (objectColumn, firstPairColumn) => {
|
|
264
|
+
const diff = firstPairColumn - objectColumn;
|
|
265
|
+
return diff > 0 ? diff : 2;
|
|
266
|
+
};
|
|
247
267
|
const transform = (cursor, transformerMap, ctx) => {
|
|
248
268
|
const info = getCursorInfo(cursor);
|
|
249
269
|
|
|
@@ -307,11 +327,27 @@ const createTransformers = transformerMap => ({
|
|
|
307
327
|
const element = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_7__["default"]();
|
|
308
328
|
maybeAddSourceMap(info, element, ctx);
|
|
309
329
|
|
|
330
|
+
// Detect indent from first pair if style is enabled and not yet detected
|
|
331
|
+
if (ctx.style && ctx.indent === 0) {
|
|
332
|
+
if (cursor.gotoFirstChild()) {
|
|
333
|
+
do {
|
|
334
|
+
if (cursor.nodeType === 'pair') {
|
|
335
|
+
ctx.indent = detectIndent(info.startPosition.column, cursor.startPosition.column);
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
} while (cursor.gotoNextSibling());
|
|
339
|
+
cursor.gotoParent();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
310
343
|
// Transform children (pairs)
|
|
311
344
|
const children = transformChildren(cursor, transformerMap, ctx);
|
|
312
345
|
for (const child of children) {
|
|
313
346
|
element.push(child);
|
|
314
347
|
}
|
|
348
|
+
if (ctx.style) {
|
|
349
|
+
element.style = buildJsonStyle(ctx);
|
|
350
|
+
}
|
|
315
351
|
return element;
|
|
316
352
|
},
|
|
317
353
|
array(cursor, ctx) {
|
|
@@ -324,6 +360,9 @@ const createTransformers = transformerMap => ({
|
|
|
324
360
|
for (const child of children) {
|
|
325
361
|
element.push(child);
|
|
326
362
|
}
|
|
363
|
+
if (ctx.style) {
|
|
364
|
+
element.style = buildJsonStyle(ctx);
|
|
365
|
+
}
|
|
327
366
|
return element;
|
|
328
367
|
},
|
|
329
368
|
pair(cursor, ctx) {
|
|
@@ -365,30 +404,47 @@ const createTransformers = transformerMap => ({
|
|
|
365
404
|
});
|
|
366
405
|
}
|
|
367
406
|
}
|
|
407
|
+
if (ctx.style) {
|
|
408
|
+
element.style = buildJsonStyle(ctx);
|
|
409
|
+
}
|
|
368
410
|
maybeAddSourceMap(info, element, ctx);
|
|
369
411
|
return element;
|
|
370
412
|
},
|
|
371
413
|
number(cursor, ctx) {
|
|
372
414
|
const info = getCursorInfo(cursor);
|
|
373
415
|
const element = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_3__["default"](Number(info.text));
|
|
416
|
+
if (ctx.style) {
|
|
417
|
+
element.style = buildJsonStyle(ctx, {
|
|
418
|
+
rawContent: info.text
|
|
419
|
+
});
|
|
420
|
+
}
|
|
374
421
|
maybeAddSourceMap(info, element, ctx);
|
|
375
422
|
return element;
|
|
376
423
|
},
|
|
377
424
|
null(cursor, ctx) {
|
|
378
425
|
const info = getCursorInfo(cursor);
|
|
379
426
|
const element = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_1__["default"]();
|
|
427
|
+
if (ctx.style) {
|
|
428
|
+
element.style = buildJsonStyle(ctx);
|
|
429
|
+
}
|
|
380
430
|
maybeAddSourceMap(info, element, ctx);
|
|
381
431
|
return element;
|
|
382
432
|
},
|
|
383
433
|
true(cursor, ctx) {
|
|
384
434
|
const info = getCursorInfo(cursor);
|
|
385
435
|
const element = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_4__["default"](true);
|
|
436
|
+
if (ctx.style) {
|
|
437
|
+
element.style = buildJsonStyle(ctx);
|
|
438
|
+
}
|
|
386
439
|
maybeAddSourceMap(info, element, ctx);
|
|
387
440
|
return element;
|
|
388
441
|
},
|
|
389
442
|
false(cursor, ctx) {
|
|
390
443
|
const info = getCursorInfo(cursor);
|
|
391
444
|
const element = new _speclynx_apidom_datamodel__WEBPACK_IMPORTED_MODULE_4__["default"](false);
|
|
445
|
+
if (ctx.style) {
|
|
446
|
+
element.style = buildJsonStyle(ctx);
|
|
447
|
+
}
|
|
392
448
|
maybeAddSourceMap(info, element, ctx);
|
|
393
449
|
return element;
|
|
394
450
|
},
|
|
@@ -419,11 +475,14 @@ Object.assign(transformers, createTransformers(transformers));
|
|
|
419
475
|
* @public
|
|
420
476
|
*/
|
|
421
477
|
const analyze = (cst, {
|
|
422
|
-
sourceMap = false
|
|
478
|
+
sourceMap = false,
|
|
479
|
+
style = false
|
|
423
480
|
} = {}) => {
|
|
424
481
|
const cursor = cst.walk();
|
|
425
482
|
const ctx = {
|
|
426
483
|
sourceMap,
|
|
484
|
+
style,
|
|
485
|
+
indent: 0,
|
|
427
486
|
annotations: []
|
|
428
487
|
};
|
|
429
488
|
const result = transform(cursor, transformers, ctx);
|
|
@@ -5924,6 +5983,66 @@ function unpackSourceMap(packed) {
|
|
|
5924
5983
|
|
|
5925
5984
|
/***/ },
|
|
5926
5985
|
|
|
5986
|
+
/***/ 9686
|
|
5987
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
5988
|
+
|
|
5989
|
+
"use strict";
|
|
5990
|
+
__webpack_require__.r(__webpack_exports__);
|
|
5991
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5992
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
5993
|
+
/* harmony export */ });
|
|
5994
|
+
/* harmony import */ var _primitives_ObjectElement_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7071);
|
|
5995
|
+
|
|
5996
|
+
/**
|
|
5997
|
+
* Shape with optional style property.
|
|
5998
|
+
* @public
|
|
5999
|
+
*/
|
|
6000
|
+
/**
|
|
6001
|
+
* StyleElement stores format-specific style information for round-trip preservation.
|
|
6002
|
+
*
|
|
6003
|
+
* The style data is stored as a plain object with format-specific namespaces
|
|
6004
|
+
* (e.g., `yaml`, `json`). This element exists only during serialization/deserialization
|
|
6005
|
+
* (refract format) - in memory, style lives directly on `element.style`.
|
|
6006
|
+
*
|
|
6007
|
+
* Follows the same pattern as SourceMapElement with __mappings__.
|
|
6008
|
+
*
|
|
6009
|
+
* @public
|
|
6010
|
+
*/
|
|
6011
|
+
class StyleElement extends _primitives_ObjectElement_mjs__WEBPACK_IMPORTED_MODULE_0__["default"] {
|
|
6012
|
+
constructor(content, meta, attributes) {
|
|
6013
|
+
super(content, meta, attributes);
|
|
6014
|
+
this.element = '__styles__';
|
|
6015
|
+
}
|
|
6016
|
+
|
|
6017
|
+
/**
|
|
6018
|
+
* Transfers style property from one element to another.
|
|
6019
|
+
*/
|
|
6020
|
+
static transfer(from, to) {
|
|
6021
|
+
to.style = from.style;
|
|
6022
|
+
}
|
|
6023
|
+
|
|
6024
|
+
/**
|
|
6025
|
+
* Creates a StyleElement from an element's style property.
|
|
6026
|
+
* Returns undefined if the element has no style.
|
|
6027
|
+
*/
|
|
6028
|
+
static from(source) {
|
|
6029
|
+
if (!source.style) {
|
|
6030
|
+
return undefined;
|
|
6031
|
+
}
|
|
6032
|
+
return new StyleElement(source.style);
|
|
6033
|
+
}
|
|
6034
|
+
|
|
6035
|
+
/**
|
|
6036
|
+
* Restores the style property on the target element from this StyleElement.
|
|
6037
|
+
*/
|
|
6038
|
+
applyTo(target) {
|
|
6039
|
+
target.style = this.toValue();
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (StyleElement);
|
|
6043
|
+
|
|
6044
|
+
/***/ },
|
|
6045
|
+
|
|
5927
6046
|
/***/ 6911
|
|
5928
6047
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
5929
6048
|
|
|
@@ -5988,6 +6107,7 @@ const isSourceMapElement = element => element instanceof _elements_SourceMap_mjs
|
|
|
5988
6107
|
__webpack_require__.r(__webpack_exports__);
|
|
5989
6108
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
5990
6109
|
/* harmony export */ hasElementSourceMap: () => (/* binding */ hasElementSourceMap),
|
|
6110
|
+
/* harmony export */ hasElementStyle: () => (/* binding */ hasElementStyle),
|
|
5991
6111
|
/* harmony export */ includesClasses: () => (/* binding */ includesClasses),
|
|
5992
6112
|
/* harmony export */ includesSymbols: () => (/* binding */ includesSymbols),
|
|
5993
6113
|
/* harmony export */ isAnnotationElement: () => (/* reexport safe */ _elements_mjs__WEBPACK_IMPORTED_MODULE_1__.isAnnotationElement),
|
|
@@ -6012,6 +6132,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
6012
6132
|
|
|
6013
6133
|
|
|
6014
6134
|
|
|
6135
|
+
/**
|
|
6136
|
+
* Checks if an element has format-specific style information.
|
|
6137
|
+
* @public
|
|
6138
|
+
*/
|
|
6139
|
+
const hasElementStyle = element => {
|
|
6140
|
+
return element.style !== undefined;
|
|
6141
|
+
};
|
|
6142
|
+
|
|
6015
6143
|
/**
|
|
6016
6144
|
* Checks if an element has complete source position information.
|
|
6017
6145
|
* Returns true only if all 6 position properties are numbers.
|
|
@@ -6553,6 +6681,12 @@ class Element {
|
|
|
6553
6681
|
*/
|
|
6554
6682
|
parent;
|
|
6555
6683
|
|
|
6684
|
+
/**
|
|
6685
|
+
* Format-specific style information for round-trip preservation.
|
|
6686
|
+
* Each format owns its own namespace (e.g., `yaml`, `json`).
|
|
6687
|
+
*/
|
|
6688
|
+
style;
|
|
6689
|
+
|
|
6556
6690
|
// ============================================================================
|
|
6557
6691
|
// Source Position (LSP-compatible, TextDocument-compatible, UTF-16 code units)
|
|
6558
6692
|
// web-tree-sitter automatically provides position data in UTF-16 code units.
|
|
@@ -7442,17 +7576,18 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7442
7576
|
/* harmony export */ CollectionElement: () => (/* reexport safe */ _primitives_CollectionElement_mjs__WEBPACK_IMPORTED_MODULE_1__["default"]),
|
|
7443
7577
|
/* harmony export */ CommentElement: () => (/* reexport safe */ _elements_Comment_mjs__WEBPACK_IMPORTED_MODULE_12__["default"]),
|
|
7444
7578
|
/* harmony export */ Element: () => (/* reexport safe */ _primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]),
|
|
7445
|
-
/* harmony export */ KeyValuePair: () => (/* reexport safe */
|
|
7579
|
+
/* harmony export */ KeyValuePair: () => (/* reexport safe */ _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_17__["default"]),
|
|
7446
7580
|
/* harmony export */ LinkElement: () => (/* reexport safe */ _elements_LinkElement_mjs__WEBPACK_IMPORTED_MODULE_9__["default"]),
|
|
7447
7581
|
/* harmony export */ MemberElement: () => (/* reexport safe */ _primitives_MemberElement_mjs__WEBPACK_IMPORTED_MODULE_7__["default"]),
|
|
7448
7582
|
/* harmony export */ NullElement: () => (/* reexport safe */ _primitives_NullElement_mjs__WEBPACK_IMPORTED_MODULE_2__["default"]),
|
|
7449
7583
|
/* harmony export */ NumberElement: () => (/* reexport safe */ _primitives_NumberElement_mjs__WEBPACK_IMPORTED_MODULE_4__["default"]),
|
|
7450
7584
|
/* harmony export */ ObjectElement: () => (/* reexport safe */ _primitives_ObjectElement_mjs__WEBPACK_IMPORTED_MODULE_8__["default"]),
|
|
7451
|
-
/* harmony export */ ObjectSlice: () => (/* reexport safe */
|
|
7585
|
+
/* harmony export */ ObjectSlice: () => (/* reexport safe */ _ObjectSlice_mjs__WEBPACK_IMPORTED_MODULE_16__["default"]),
|
|
7452
7586
|
/* harmony export */ ParseResultElement: () => (/* reexport safe */ _elements_ParseResult_mjs__WEBPACK_IMPORTED_MODULE_13__["default"]),
|
|
7453
7587
|
/* harmony export */ RefElement: () => (/* reexport safe */ _elements_RefElement_mjs__WEBPACK_IMPORTED_MODULE_10__["default"]),
|
|
7454
7588
|
/* harmony export */ SourceMapElement: () => (/* reexport safe */ _elements_SourceMap_mjs__WEBPACK_IMPORTED_MODULE_14__["default"]),
|
|
7455
7589
|
/* harmony export */ StringElement: () => (/* reexport safe */ _primitives_StringElement_mjs__WEBPACK_IMPORTED_MODULE_3__["default"]),
|
|
7590
|
+
/* harmony export */ StyleElement: () => (/* reexport safe */ _elements_Style_mjs__WEBPACK_IMPORTED_MODULE_15__["default"]),
|
|
7456
7591
|
/* harmony export */ refract: () => (/* binding */ refract)
|
|
7457
7592
|
/* harmony export */ });
|
|
7458
7593
|
/* harmony import */ var _primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(728);
|
|
@@ -7470,8 +7605,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7470
7605
|
/* harmony import */ var _elements_Comment_mjs__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(94);
|
|
7471
7606
|
/* harmony import */ var _elements_ParseResult_mjs__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(4823);
|
|
7472
7607
|
/* harmony import */ var _elements_SourceMap_mjs__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(5810);
|
|
7473
|
-
/* harmony import */ var
|
|
7474
|
-
/* harmony import */ var
|
|
7608
|
+
/* harmony import */ var _elements_Style_mjs__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(9686);
|
|
7609
|
+
/* harmony import */ var _ObjectSlice_mjs__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(8504);
|
|
7610
|
+
/* harmony import */ var _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(6663);
|
|
7611
|
+
|
|
7475
7612
|
|
|
7476
7613
|
|
|
7477
7614
|
|
|
@@ -7558,6 +7695,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7558
7695
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
7559
7696
|
/* harmony export */ });
|
|
7560
7697
|
/* harmony import */ var _elements_SourceMap_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5810);
|
|
7698
|
+
/* harmony import */ var _elements_Style_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9686);
|
|
7699
|
+
|
|
7561
7700
|
|
|
7562
7701
|
/**
|
|
7563
7702
|
* Serialized representation of an Element in JSON Refract format.
|
|
@@ -7616,6 +7755,17 @@ class JSONSerialiser {
|
|
|
7616
7755
|
payload.meta.__mappings__ = this.serialise(sourceMap);
|
|
7617
7756
|
}
|
|
7618
7757
|
}
|
|
7758
|
+
|
|
7759
|
+
// Serialize style as __styles__ in meta (skip for StyleElement itself)
|
|
7760
|
+
if (!(element instanceof _elements_Style_mjs__WEBPACK_IMPORTED_MODULE_1__["default"])) {
|
|
7761
|
+
const styleElement = _elements_Style_mjs__WEBPACK_IMPORTED_MODULE_1__["default"].from(element);
|
|
7762
|
+
if (styleElement) {
|
|
7763
|
+
if (!payload.meta) {
|
|
7764
|
+
payload.meta = {};
|
|
7765
|
+
}
|
|
7766
|
+
payload.meta.__styles__ = this.serialise(styleElement);
|
|
7767
|
+
}
|
|
7768
|
+
}
|
|
7619
7769
|
const content = this.serialiseContent(element.content);
|
|
7620
7770
|
if (content !== undefined) {
|
|
7621
7771
|
payload.content = content;
|
|
@@ -7636,15 +7786,18 @@ class JSONSerialiser {
|
|
|
7636
7786
|
element.element = value.element;
|
|
7637
7787
|
}
|
|
7638
7788
|
|
|
7639
|
-
// Extract __mappings__ without mutating input, filter remaining meta
|
|
7789
|
+
// Extract __mappings__ and __styles__ without mutating input, filter remaining meta
|
|
7640
7790
|
let mappingsDoc;
|
|
7791
|
+
let stylesDoc;
|
|
7641
7792
|
let metaToDeserialize = value.meta;
|
|
7642
|
-
if (value.meta?.__mappings__) {
|
|
7793
|
+
if (value.meta?.__mappings__ || value.meta?.__styles__) {
|
|
7643
7794
|
const {
|
|
7644
7795
|
__mappings__,
|
|
7796
|
+
__styles__,
|
|
7645
7797
|
...rest
|
|
7646
7798
|
} = value.meta;
|
|
7647
7799
|
mappingsDoc = __mappings__;
|
|
7800
|
+
stylesDoc = __styles__;
|
|
7648
7801
|
metaToDeserialize = Object.keys(rest).length > 0 ? rest : undefined;
|
|
7649
7802
|
}
|
|
7650
7803
|
if (metaToDeserialize) {
|
|
@@ -7656,6 +7809,12 @@ class JSONSerialiser {
|
|
|
7656
7809
|
const sourceMap = this.deserialise(mappingsDoc);
|
|
7657
7810
|
sourceMap.applyTo(element);
|
|
7658
7811
|
}
|
|
7812
|
+
|
|
7813
|
+
// Restore style from __styles__
|
|
7814
|
+
if (stylesDoc) {
|
|
7815
|
+
const styleElement = this.deserialise(stylesDoc);
|
|
7816
|
+
styleElement.applyTo(element);
|
|
7817
|
+
}
|
|
7659
7818
|
if (value.attributes) {
|
|
7660
7819
|
this.deserialiseObject(value.attributes, element.attributes);
|
|
7661
7820
|
}
|
|
@@ -7999,16 +8158,21 @@ const detect = async (source, {
|
|
|
7999
8158
|
*/
|
|
8000
8159
|
const parse = async (source, {
|
|
8001
8160
|
sourceMap = false,
|
|
8161
|
+
style = false,
|
|
8002
8162
|
strict = false
|
|
8003
8163
|
} = {}) => {
|
|
8004
8164
|
if (strict && sourceMap) {
|
|
8005
8165
|
throw new _speclynx_apidom_error__WEBPACK_IMPORTED_MODULE_1__["default"]('Cannot use sourceMap with strict parsing. Strict parsing does not support source maps.');
|
|
8006
8166
|
}
|
|
8167
|
+
if (strict && style) {
|
|
8168
|
+
throw new _speclynx_apidom_error__WEBPACK_IMPORTED_MODULE_1__["default"]('Cannot use style with strict parsing. Strict parsing does not support style preservation.');
|
|
8169
|
+
}
|
|
8007
8170
|
if (strict) {
|
|
8008
8171
|
return _native_index_ts__WEBPACK_IMPORTED_MODULE_2__.parse(source);
|
|
8009
8172
|
}
|
|
8010
8173
|
return _tree_sitter_index_ts__WEBPACK_IMPORTED_MODULE_3__.parse(source, {
|
|
8011
|
-
sourceMap
|
|
8174
|
+
sourceMap,
|
|
8175
|
+
style
|
|
8012
8176
|
});
|
|
8013
8177
|
};
|
|
8014
8178
|
})();
|