@speclynx/apidom-parser-adapter-json 2.10.3 → 2.12.0
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 +211 -19
- 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.0](https://github.com/speclynx/apidom/compare/v2.11.0...v2.12.0) (2026-02-18)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- add support for lossless JSON/YAML roundtrips ([#97](https://github.com/speclynx/apidom/issues/97)) ([dc17c9a](https://github.com/speclynx/apidom/commit/dc17c9a78fbc7df07a91e8f35b12be6409117d91))
|
|
11
|
+
|
|
12
|
+
# [2.11.0](https://github.com/speclynx/apidom/compare/v2.10.3...v2.11.0) (2026-02-12)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @speclynx/apidom-parser-adapter-json
|
|
15
|
+
|
|
6
16
|
## [2.10.3](https://github.com/speclynx/apidom/compare/v2.10.2...v2.10.3) (2026-02-10)
|
|
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.
|
|
@@ -6761,7 +6895,13 @@ class Element {
|
|
|
6761
6895
|
|
|
6762
6896
|
/** Unique identifier for this element. */
|
|
6763
6897
|
get id() {
|
|
6764
|
-
|
|
6898
|
+
if (this.isFrozen) {
|
|
6899
|
+
return this.getMetaProperty('id', '');
|
|
6900
|
+
}
|
|
6901
|
+
if (!this.hasMetaProperty('id')) {
|
|
6902
|
+
this.setMetaProperty('id', '');
|
|
6903
|
+
}
|
|
6904
|
+
return this.meta.get('id');
|
|
6765
6905
|
}
|
|
6766
6906
|
set id(value) {
|
|
6767
6907
|
this.setMetaProperty('id', value);
|
|
@@ -6769,7 +6909,13 @@ class Element {
|
|
|
6769
6909
|
|
|
6770
6910
|
/** CSS-like class names. */
|
|
6771
6911
|
get classes() {
|
|
6772
|
-
|
|
6912
|
+
if (this.isFrozen) {
|
|
6913
|
+
return this.getMetaProperty('classes', []);
|
|
6914
|
+
}
|
|
6915
|
+
if (!this.hasMetaProperty('classes')) {
|
|
6916
|
+
this.setMetaProperty('classes', []);
|
|
6917
|
+
}
|
|
6918
|
+
return this.meta.get('classes');
|
|
6773
6919
|
}
|
|
6774
6920
|
set classes(value) {
|
|
6775
6921
|
this.setMetaProperty('classes', value);
|
|
@@ -6777,7 +6923,13 @@ class Element {
|
|
|
6777
6923
|
|
|
6778
6924
|
/** Hyperlinks associated with this element. */
|
|
6779
6925
|
get links() {
|
|
6780
|
-
|
|
6926
|
+
if (this.isFrozen) {
|
|
6927
|
+
return this.getMetaProperty('links', []);
|
|
6928
|
+
}
|
|
6929
|
+
if (!this.hasMetaProperty('links')) {
|
|
6930
|
+
this.setMetaProperty('links', []);
|
|
6931
|
+
}
|
|
6932
|
+
return this.meta.get('links');
|
|
6781
6933
|
}
|
|
6782
6934
|
set links(value) {
|
|
6783
6935
|
this.setMetaProperty('links', value);
|
|
@@ -6928,16 +7080,26 @@ class Element {
|
|
|
6928
7080
|
}
|
|
6929
7081
|
|
|
6930
7082
|
/**
|
|
6931
|
-
* Gets a meta property
|
|
7083
|
+
* Gets a meta property.
|
|
7084
|
+
*
|
|
7085
|
+
* When the property doesn't exist:
|
|
7086
|
+
* - With defaultValue: returns a new refracted element instance (not cached)
|
|
7087
|
+
* - Without defaultValue: returns undefined
|
|
7088
|
+
*
|
|
7089
|
+
* Note: Each call with a default creates a new instance. Use setMetaProperty
|
|
7090
|
+
* first if you need reference equality across multiple accesses.
|
|
6932
7091
|
*/
|
|
7092
|
+
|
|
6933
7093
|
getMetaProperty(name, defaultValue) {
|
|
6934
|
-
if (!this.
|
|
6935
|
-
if (
|
|
6936
|
-
|
|
7094
|
+
if (!this.hasMetaProperty(name)) {
|
|
7095
|
+
if (defaultValue === undefined) {
|
|
7096
|
+
return undefined;
|
|
7097
|
+
}
|
|
7098
|
+
const element = this.refract(defaultValue);
|
|
7099
|
+
if (element && this.isFrozen) {
|
|
6937
7100
|
element.freeze();
|
|
6938
|
-
return element;
|
|
6939
7101
|
}
|
|
6940
|
-
|
|
7102
|
+
return element;
|
|
6941
7103
|
}
|
|
6942
7104
|
return this.meta.get(name);
|
|
6943
7105
|
}
|
|
@@ -7414,17 +7576,18 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7414
7576
|
/* harmony export */ CollectionElement: () => (/* reexport safe */ _primitives_CollectionElement_mjs__WEBPACK_IMPORTED_MODULE_1__["default"]),
|
|
7415
7577
|
/* harmony export */ CommentElement: () => (/* reexport safe */ _elements_Comment_mjs__WEBPACK_IMPORTED_MODULE_12__["default"]),
|
|
7416
7578
|
/* harmony export */ Element: () => (/* reexport safe */ _primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__["default"]),
|
|
7417
|
-
/* harmony export */ KeyValuePair: () => (/* reexport safe */
|
|
7579
|
+
/* harmony export */ KeyValuePair: () => (/* reexport safe */ _KeyValuePair_mjs__WEBPACK_IMPORTED_MODULE_17__["default"]),
|
|
7418
7580
|
/* harmony export */ LinkElement: () => (/* reexport safe */ _elements_LinkElement_mjs__WEBPACK_IMPORTED_MODULE_9__["default"]),
|
|
7419
7581
|
/* harmony export */ MemberElement: () => (/* reexport safe */ _primitives_MemberElement_mjs__WEBPACK_IMPORTED_MODULE_7__["default"]),
|
|
7420
7582
|
/* harmony export */ NullElement: () => (/* reexport safe */ _primitives_NullElement_mjs__WEBPACK_IMPORTED_MODULE_2__["default"]),
|
|
7421
7583
|
/* harmony export */ NumberElement: () => (/* reexport safe */ _primitives_NumberElement_mjs__WEBPACK_IMPORTED_MODULE_4__["default"]),
|
|
7422
7584
|
/* harmony export */ ObjectElement: () => (/* reexport safe */ _primitives_ObjectElement_mjs__WEBPACK_IMPORTED_MODULE_8__["default"]),
|
|
7423
|
-
/* harmony export */ ObjectSlice: () => (/* reexport safe */
|
|
7585
|
+
/* harmony export */ ObjectSlice: () => (/* reexport safe */ _ObjectSlice_mjs__WEBPACK_IMPORTED_MODULE_16__["default"]),
|
|
7424
7586
|
/* harmony export */ ParseResultElement: () => (/* reexport safe */ _elements_ParseResult_mjs__WEBPACK_IMPORTED_MODULE_13__["default"]),
|
|
7425
7587
|
/* harmony export */ RefElement: () => (/* reexport safe */ _elements_RefElement_mjs__WEBPACK_IMPORTED_MODULE_10__["default"]),
|
|
7426
7588
|
/* harmony export */ SourceMapElement: () => (/* reexport safe */ _elements_SourceMap_mjs__WEBPACK_IMPORTED_MODULE_14__["default"]),
|
|
7427
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"]),
|
|
7428
7591
|
/* harmony export */ refract: () => (/* binding */ refract)
|
|
7429
7592
|
/* harmony export */ });
|
|
7430
7593
|
/* harmony import */ var _primitives_Element_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(728);
|
|
@@ -7442,8 +7605,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7442
7605
|
/* harmony import */ var _elements_Comment_mjs__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(94);
|
|
7443
7606
|
/* harmony import */ var _elements_ParseResult_mjs__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(4823);
|
|
7444
7607
|
/* harmony import */ var _elements_SourceMap_mjs__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(5810);
|
|
7445
|
-
/* harmony import */ var
|
|
7446
|
-
/* 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
|
+
|
|
7447
7612
|
|
|
7448
7613
|
|
|
7449
7614
|
|
|
@@ -7530,6 +7695,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
7530
7695
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
7531
7696
|
/* harmony export */ });
|
|
7532
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
|
+
|
|
7533
7700
|
|
|
7534
7701
|
/**
|
|
7535
7702
|
* Serialized representation of an Element in JSON Refract format.
|
|
@@ -7588,6 +7755,17 @@ class JSONSerialiser {
|
|
|
7588
7755
|
payload.meta.__mappings__ = this.serialise(sourceMap);
|
|
7589
7756
|
}
|
|
7590
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
|
+
}
|
|
7591
7769
|
const content = this.serialiseContent(element.content);
|
|
7592
7770
|
if (content !== undefined) {
|
|
7593
7771
|
payload.content = content;
|
|
@@ -7608,15 +7786,18 @@ class JSONSerialiser {
|
|
|
7608
7786
|
element.element = value.element;
|
|
7609
7787
|
}
|
|
7610
7788
|
|
|
7611
|
-
// Extract __mappings__ without mutating input, filter remaining meta
|
|
7789
|
+
// Extract __mappings__ and __styles__ without mutating input, filter remaining meta
|
|
7612
7790
|
let mappingsDoc;
|
|
7791
|
+
let stylesDoc;
|
|
7613
7792
|
let metaToDeserialize = value.meta;
|
|
7614
|
-
if (value.meta?.__mappings__) {
|
|
7793
|
+
if (value.meta?.__mappings__ || value.meta?.__styles__) {
|
|
7615
7794
|
const {
|
|
7616
7795
|
__mappings__,
|
|
7796
|
+
__styles__,
|
|
7617
7797
|
...rest
|
|
7618
7798
|
} = value.meta;
|
|
7619
7799
|
mappingsDoc = __mappings__;
|
|
7800
|
+
stylesDoc = __styles__;
|
|
7620
7801
|
metaToDeserialize = Object.keys(rest).length > 0 ? rest : undefined;
|
|
7621
7802
|
}
|
|
7622
7803
|
if (metaToDeserialize) {
|
|
@@ -7628,6 +7809,12 @@ class JSONSerialiser {
|
|
|
7628
7809
|
const sourceMap = this.deserialise(mappingsDoc);
|
|
7629
7810
|
sourceMap.applyTo(element);
|
|
7630
7811
|
}
|
|
7812
|
+
|
|
7813
|
+
// Restore style from __styles__
|
|
7814
|
+
if (stylesDoc) {
|
|
7815
|
+
const styleElement = this.deserialise(stylesDoc);
|
|
7816
|
+
styleElement.applyTo(element);
|
|
7817
|
+
}
|
|
7631
7818
|
if (value.attributes) {
|
|
7632
7819
|
this.deserialiseObject(value.attributes, element.attributes);
|
|
7633
7820
|
}
|
|
@@ -7971,16 +8158,21 @@ const detect = async (source, {
|
|
|
7971
8158
|
*/
|
|
7972
8159
|
const parse = async (source, {
|
|
7973
8160
|
sourceMap = false,
|
|
8161
|
+
style = false,
|
|
7974
8162
|
strict = false
|
|
7975
8163
|
} = {}) => {
|
|
7976
8164
|
if (strict && sourceMap) {
|
|
7977
8165
|
throw new _speclynx_apidom_error__WEBPACK_IMPORTED_MODULE_1__["default"]('Cannot use sourceMap with strict parsing. Strict parsing does not support source maps.');
|
|
7978
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
|
+
}
|
|
7979
8170
|
if (strict) {
|
|
7980
8171
|
return _native_index_ts__WEBPACK_IMPORTED_MODULE_2__.parse(source);
|
|
7981
8172
|
}
|
|
7982
8173
|
return _tree_sitter_index_ts__WEBPACK_IMPORTED_MODULE_3__.parse(source, {
|
|
7983
|
-
sourceMap
|
|
8174
|
+
sourceMap,
|
|
8175
|
+
style
|
|
7984
8176
|
});
|
|
7985
8177
|
};
|
|
7986
8178
|
})();
|