@speclynx/apidom-datamodel 1.12.2 → 2.0.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 +20 -0
- package/LICENSE +202 -0
- package/NOTICE +2 -2
- package/README.md +151 -19
- package/dist/apidom-datamodel.browser.js +1141 -167
- package/dist/apidom-datamodel.browser.min.js +1 -1
- package/package.json +6 -3
- package/src/KeyValuePair.cjs +0 -7
- package/src/KeyValuePair.mjs +0 -7
- package/src/Namespace.cjs +1 -1
- package/src/Namespace.mjs +1 -1
- package/src/ObjectSlice.cjs +0 -7
- package/src/ObjectSlice.mjs +0 -7
- package/src/clone/errors/CloneError.cjs +22 -0
- package/src/clone/errors/CloneError.mjs +19 -0
- package/src/clone/errors/DeepCloneError.cjs +11 -0
- package/src/clone/errors/DeepCloneError.mjs +6 -0
- package/src/clone/errors/ShallowCloneError.cjs +11 -0
- package/src/clone/errors/ShallowCloneError.mjs +6 -0
- package/src/clone/index.cjs +184 -0
- package/src/clone/index.mjs +174 -0
- package/src/elements/Annotation.cjs +35 -0
- package/src/elements/Annotation.mjs +30 -0
- package/src/elements/Comment.cjs +18 -0
- package/src/elements/Comment.mjs +13 -0
- package/src/elements/LinkElement.cjs +8 -2
- package/src/elements/LinkElement.mjs +8 -2
- package/src/elements/ParseResult.cjs +91 -0
- package/src/elements/ParseResult.mjs +86 -0
- package/src/elements/RefElement.cjs +4 -1
- package/src/elements/RefElement.mjs +4 -1
- package/src/elements/SourceMap.cjs +140 -0
- package/src/elements/SourceMap.mjs +134 -0
- package/src/index.cjs +31 -2
- package/src/index.mjs +7 -3
- package/src/predicates/elements.cjs +46 -0
- package/src/predicates/elements.mjs +35 -0
- package/src/predicates/index.cjs +68 -0
- package/src/predicates/index.mjs +48 -0
- package/src/predicates/primitives.cjs +69 -0
- package/src/predicates/primitives.mjs +56 -0
- package/src/primitives/ArrayElement.cjs +0 -21
- package/src/primitives/ArrayElement.mjs +0 -21
- package/src/primitives/CollectionElement.cjs +5 -19
- package/src/primitives/CollectionElement.mjs +5 -19
- package/src/primitives/Element.cjs +110 -60
- package/src/primitives/Element.mjs +110 -60
- package/src/primitives/MemberElement.cjs +6 -2
- package/src/primitives/MemberElement.mjs +6 -2
- package/src/primitives/ObjectElement.cjs +0 -2
- package/src/primitives/ObjectElement.mjs +0 -2
- package/src/registration.cjs +8 -0
- package/src/registration.mjs +5 -1
- package/src/serialisers/JSONSerialiser.cjs +35 -4
- package/src/serialisers/JSONSerialiser.mjs +34 -8
- package/types/apidom-datamodel.d.ts +347 -51
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _StringElement = _interopRequireDefault(require("../primitives/StringElement.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* AnnotationElement represents a parsing annotation (warning or error).
|
|
9
|
+
*
|
|
10
|
+
* The annotation's class indicates its severity:
|
|
11
|
+
* - 'warning' - A non-fatal issue
|
|
12
|
+
* - 'error' - A fatal issue
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
class AnnotationElement extends _StringElement.default {
|
|
17
|
+
constructor(content, meta, attributes) {
|
|
18
|
+
super(content, meta, attributes);
|
|
19
|
+
this.element = 'annotation';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The annotation code identifying the type of annotation.
|
|
24
|
+
*/
|
|
25
|
+
get code() {
|
|
26
|
+
if (this.hasAttributesProperty('code')) {
|
|
27
|
+
return this.attributes.get('code');
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
set code(value) {
|
|
32
|
+
this.attributes.set('code', value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var _default = exports.default = AnnotationElement;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import StringElement from "../primitives/StringElement.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* AnnotationElement represents a parsing annotation (warning or error).
|
|
4
|
+
*
|
|
5
|
+
* The annotation's class indicates its severity:
|
|
6
|
+
* - 'warning' - A non-fatal issue
|
|
7
|
+
* - 'error' - A fatal issue
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class AnnotationElement extends StringElement {
|
|
12
|
+
constructor(content, meta, attributes) {
|
|
13
|
+
super(content, meta, attributes);
|
|
14
|
+
this.element = 'annotation';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The annotation code identifying the type of annotation.
|
|
19
|
+
*/
|
|
20
|
+
get code() {
|
|
21
|
+
if (this.hasAttributesProperty('code')) {
|
|
22
|
+
return this.attributes.get('code');
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
set code(value) {
|
|
27
|
+
this.attributes.set('code', value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export default AnnotationElement;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _StringElement = _interopRequireDefault(require("../primitives/StringElement.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* CommentElement represents a comment in the source document.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
class CommentElement extends _StringElement.default {
|
|
13
|
+
constructor(content, meta, attributes) {
|
|
14
|
+
super(content, meta, attributes);
|
|
15
|
+
this.element = 'comment';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var _default = exports.default = CommentElement;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import StringElement from "../primitives/StringElement.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* CommentElement represents a comment in the source document.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
class CommentElement extends StringElement {
|
|
8
|
+
constructor(content, meta, attributes) {
|
|
9
|
+
super(content, meta, attributes);
|
|
10
|
+
this.element = 'comment';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export default CommentElement;
|
|
@@ -25,7 +25,10 @@ class LinkElement extends _Element.default {
|
|
|
25
25
|
* The relation identifier for the link, as defined in RFC 5988.
|
|
26
26
|
*/
|
|
27
27
|
get relation() {
|
|
28
|
-
|
|
28
|
+
if (this.hasAttributesProperty('relation')) {
|
|
29
|
+
return this.attributes.get('relation');
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
29
32
|
}
|
|
30
33
|
set relation(relation) {
|
|
31
34
|
this.attributes.set('relation', relation);
|
|
@@ -35,7 +38,10 @@ class LinkElement extends _Element.default {
|
|
|
35
38
|
* The URI for the given link.
|
|
36
39
|
*/
|
|
37
40
|
get href() {
|
|
38
|
-
|
|
41
|
+
if (this.hasAttributesProperty('href')) {
|
|
42
|
+
return this.attributes.get('href');
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
39
45
|
}
|
|
40
46
|
set href(href) {
|
|
41
47
|
this.attributes.set('href', href);
|
|
@@ -20,7 +20,10 @@ class LinkElement extends Element {
|
|
|
20
20
|
* The relation identifier for the link, as defined in RFC 5988.
|
|
21
21
|
*/
|
|
22
22
|
get relation() {
|
|
23
|
-
|
|
23
|
+
if (this.hasAttributesProperty('relation')) {
|
|
24
|
+
return this.attributes.get('relation');
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
24
27
|
}
|
|
25
28
|
set relation(relation) {
|
|
26
29
|
this.attributes.set('relation', relation);
|
|
@@ -30,7 +33,10 @@ class LinkElement extends Element {
|
|
|
30
33
|
* The URI for the given link.
|
|
31
34
|
*/
|
|
32
35
|
get href() {
|
|
33
|
-
|
|
36
|
+
if (this.hasAttributesProperty('href')) {
|
|
37
|
+
return this.attributes.get('href');
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
34
40
|
}
|
|
35
41
|
set href(href) {
|
|
36
42
|
this.attributes.set('href', href);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ArrayElement = _interopRequireDefault(require("../primitives/ArrayElement.cjs"));
|
|
7
|
+
var _index = require("../predicates/index.cjs");
|
|
8
|
+
/**
|
|
9
|
+
* ParseResultElement represents the result of parsing a document.
|
|
10
|
+
*
|
|
11
|
+
* Contains the parsed API element, any result elements, and annotations
|
|
12
|
+
* (warnings and errors) from the parsing process.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
class ParseResultElement extends _ArrayElement.default {
|
|
17
|
+
constructor(content, meta, attributes) {
|
|
18
|
+
super(content, meta, attributes);
|
|
19
|
+
this.element = 'parseResult';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The main API element from the parse result.
|
|
24
|
+
*/
|
|
25
|
+
get api() {
|
|
26
|
+
return this.filter(item => (0, _index.includesClasses)(item, ['api'])).first;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* All result elements from the parse result.
|
|
31
|
+
*/
|
|
32
|
+
get results() {
|
|
33
|
+
return this.filter(item => (0, _index.includesClasses)(item, ['result']));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The first result element.
|
|
38
|
+
*/
|
|
39
|
+
get result() {
|
|
40
|
+
return this.results.first;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* All annotation elements (warnings and errors).
|
|
45
|
+
*/
|
|
46
|
+
get annotations() {
|
|
47
|
+
return this.filter(item => item.element === 'annotation');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* All warning annotations.
|
|
52
|
+
*/
|
|
53
|
+
get warnings() {
|
|
54
|
+
return this.filter(item => item.element === 'annotation' && (0, _index.includesClasses)(item, ['warning']));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* All error annotations.
|
|
59
|
+
*/
|
|
60
|
+
get errors() {
|
|
61
|
+
return this.filter(item => item.element === 'annotation' && (0, _index.includesClasses)(item, ['error']));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Whether the parse result is empty (contains only annotations).
|
|
66
|
+
*/
|
|
67
|
+
get isEmpty() {
|
|
68
|
+
return this.reject(item => item.element === 'annotation').length === 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Replaces the first result element with the given replacement.
|
|
73
|
+
* @returns true if replacement was successful, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
replaceResult(replacement) {
|
|
76
|
+
const {
|
|
77
|
+
result
|
|
78
|
+
} = this;
|
|
79
|
+
if (result === undefined) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const content = this._content;
|
|
83
|
+
const searchIndex = content.findIndex(e => e === result);
|
|
84
|
+
if (searchIndex === -1) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
content[searchIndex] = replacement;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
var _default = exports.default = ParseResultElement;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import ArrayElement from "../primitives/ArrayElement.mjs";
|
|
2
|
+
import { includesClasses } from "../predicates/index.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* ParseResultElement represents the result of parsing a document.
|
|
5
|
+
*
|
|
6
|
+
* Contains the parsed API element, any result elements, and annotations
|
|
7
|
+
* (warnings and errors) from the parsing process.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class ParseResultElement extends ArrayElement {
|
|
12
|
+
constructor(content, meta, attributes) {
|
|
13
|
+
super(content, meta, attributes);
|
|
14
|
+
this.element = 'parseResult';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The main API element from the parse result.
|
|
19
|
+
*/
|
|
20
|
+
get api() {
|
|
21
|
+
return this.filter(item => includesClasses(item, ['api'])).first;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* All result elements from the parse result.
|
|
26
|
+
*/
|
|
27
|
+
get results() {
|
|
28
|
+
return this.filter(item => includesClasses(item, ['result']));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The first result element.
|
|
33
|
+
*/
|
|
34
|
+
get result() {
|
|
35
|
+
return this.results.first;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* All annotation elements (warnings and errors).
|
|
40
|
+
*/
|
|
41
|
+
get annotations() {
|
|
42
|
+
return this.filter(item => item.element === 'annotation');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* All warning annotations.
|
|
47
|
+
*/
|
|
48
|
+
get warnings() {
|
|
49
|
+
return this.filter(item => item.element === 'annotation' && includesClasses(item, ['warning']));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* All error annotations.
|
|
54
|
+
*/
|
|
55
|
+
get errors() {
|
|
56
|
+
return this.filter(item => item.element === 'annotation' && includesClasses(item, ['error']));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Whether the parse result is empty (contains only annotations).
|
|
61
|
+
*/
|
|
62
|
+
get isEmpty() {
|
|
63
|
+
return this.reject(item => item.element === 'annotation').length === 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Replaces the first result element with the given replacement.
|
|
68
|
+
* @returns true if replacement was successful, false otherwise
|
|
69
|
+
*/
|
|
70
|
+
replaceResult(replacement) {
|
|
71
|
+
const {
|
|
72
|
+
result
|
|
73
|
+
} = this;
|
|
74
|
+
if (result === undefined) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const content = this._content;
|
|
78
|
+
const searchIndex = content.findIndex(e => e === result);
|
|
79
|
+
if (searchIndex === -1) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
content[searchIndex] = replacement;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export default ParseResultElement;
|
|
@@ -22,7 +22,10 @@ class RefElement extends _Element.default {
|
|
|
22
22
|
* @defaultValue 'element'
|
|
23
23
|
*/
|
|
24
24
|
get path() {
|
|
25
|
-
|
|
25
|
+
if (this.hasAttributesProperty('path')) {
|
|
26
|
+
return this.attributes.get('path');
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
26
29
|
}
|
|
27
30
|
set path(newValue) {
|
|
28
31
|
this.attributes.set('path', newValue);
|
|
@@ -17,7 +17,10 @@ class RefElement extends Element {
|
|
|
17
17
|
* @defaultValue 'element'
|
|
18
18
|
*/
|
|
19
19
|
get path() {
|
|
20
|
-
|
|
20
|
+
if (this.hasAttributesProperty('path')) {
|
|
21
|
+
return this.attributes.get('path');
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
21
24
|
}
|
|
22
25
|
set path(newValue) {
|
|
23
26
|
this.attributes.set('path', newValue);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _StringElement = _interopRequireDefault(require("../primitives/StringElement.cjs"));
|
|
7
|
+
/**
|
|
8
|
+
* Shape with optional source position properties.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* SourceMapElement stores source position as a compact VLQ-encoded string.
|
|
14
|
+
*
|
|
15
|
+
* The encoded string contains 6 values: startLine, startCharacter, startOffset,
|
|
16
|
+
* endLine, endCharacter, endOffset. All values use UTF-16 code units,
|
|
17
|
+
* compatible with LSP, TextDocument, and JavaScript string indexing.
|
|
18
|
+
*
|
|
19
|
+
* web-tree-sitter automatically provides position data in UTF-16 code units.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
class SourceMapElement extends _StringElement.default {
|
|
24
|
+
constructor(content, meta, attributes) {
|
|
25
|
+
super(content, meta, attributes);
|
|
26
|
+
this.element = 'sourceMap';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Transfers source position properties from one object to another.
|
|
31
|
+
*/
|
|
32
|
+
static transfer(from, to) {
|
|
33
|
+
to.startLine = from.startLine;
|
|
34
|
+
to.startCharacter = from.startCharacter;
|
|
35
|
+
to.startOffset = from.startOffset;
|
|
36
|
+
to.endLine = from.endLine;
|
|
37
|
+
to.endCharacter = from.endCharacter;
|
|
38
|
+
to.endOffset = from.endOffset;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates a SourceMapElement from source position properties.
|
|
43
|
+
* Returns undefined if any position property is not a number.
|
|
44
|
+
* Also assigns position properties to the instance for inspection.
|
|
45
|
+
*/
|
|
46
|
+
static from(source) {
|
|
47
|
+
const {
|
|
48
|
+
startLine,
|
|
49
|
+
startCharacter,
|
|
50
|
+
startOffset,
|
|
51
|
+
endLine,
|
|
52
|
+
endCharacter,
|
|
53
|
+
endOffset
|
|
54
|
+
} = source;
|
|
55
|
+
if (typeof startLine !== 'number' || typeof startCharacter !== 'number' || typeof startOffset !== 'number' || typeof endLine !== 'number' || typeof endCharacter !== 'number' || typeof endOffset !== 'number') {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const packed = packSourceMap([startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]);
|
|
59
|
+
const sourceMap = new SourceMapElement(packed);
|
|
60
|
+
sourceMap.startLine = startLine;
|
|
61
|
+
sourceMap.startCharacter = startCharacter;
|
|
62
|
+
sourceMap.startOffset = startOffset;
|
|
63
|
+
sourceMap.endLine = endLine;
|
|
64
|
+
sourceMap.endCharacter = endCharacter;
|
|
65
|
+
sourceMap.endOffset = endOffset;
|
|
66
|
+
return sourceMap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Decodes the VLQ string and applies source position properties to the target.
|
|
71
|
+
*/
|
|
72
|
+
applyTo(target) {
|
|
73
|
+
if (!this.content) return;
|
|
74
|
+
[target.startLine, target.startCharacter, target.startOffset, target.endLine, target.endCharacter, target.endOffset] = unpackSourceMap(this.content);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
78
|
+
|
|
79
|
+
// Encode one unsigned integer to Base64-VLQ
|
|
80
|
+
function vlqEncodeInt(value) {
|
|
81
|
+
let vlq = value >>> 0; // ensure unsigned 32-bit
|
|
82
|
+
let out = '';
|
|
83
|
+
do {
|
|
84
|
+
let digit = vlq & 31; // 5 bits
|
|
85
|
+
vlq >>>= 5;
|
|
86
|
+
if (vlq !== 0) digit |= 32; // continuation bit
|
|
87
|
+
out += BASE64[digit];
|
|
88
|
+
} while (vlq !== 0);
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Decode one unsigned integer from Base64-VLQ, starting at `index`
|
|
93
|
+
function vlqDecodeInt(str, index = 0) {
|
|
94
|
+
let result = 0;
|
|
95
|
+
let shift = 0;
|
|
96
|
+
let i = index;
|
|
97
|
+
while (true) {
|
|
98
|
+
const ch = str[i++];
|
|
99
|
+
const digit = BASE64.indexOf(ch);
|
|
100
|
+
if (digit === -1) throw new Error(`Invalid Base64 VLQ char: ${ch}`);
|
|
101
|
+
const cont = (digit & 32) !== 0;
|
|
102
|
+
result |= (digit & 31) << shift;
|
|
103
|
+
shift += 5;
|
|
104
|
+
if (!cont) break;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
value: result >>> 0,
|
|
108
|
+
next: i
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Span of 6 position values: [startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Encodes 6 position values into a compact VLQ string.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
function packSourceMap(v) {
|
|
122
|
+
return 'sm1:' + v.map(vlqEncodeInt).join('');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Decodes a VLQ string into 6 position values.
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
function unpackSourceMap(packed) {
|
|
130
|
+
const s = packed.startsWith('sm1:') ? packed.slice(4) : packed;
|
|
131
|
+
const out = [];
|
|
132
|
+
let i = 0;
|
|
133
|
+
for (let k = 0; k < 6; k++) {
|
|
134
|
+
const r = vlqDecodeInt(s, i);
|
|
135
|
+
out.push(r.value);
|
|
136
|
+
i = r.next;
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
var _default = exports.default = SourceMapElement;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import StringElement from "../primitives/StringElement.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Shape with optional source position properties.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* SourceMapElement stores source position as a compact VLQ-encoded string.
|
|
8
|
+
*
|
|
9
|
+
* The encoded string contains 6 values: startLine, startCharacter, startOffset,
|
|
10
|
+
* endLine, endCharacter, endOffset. All values use UTF-16 code units,
|
|
11
|
+
* compatible with LSP, TextDocument, and JavaScript string indexing.
|
|
12
|
+
*
|
|
13
|
+
* web-tree-sitter automatically provides position data in UTF-16 code units.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class SourceMapElement extends StringElement {
|
|
18
|
+
constructor(content, meta, attributes) {
|
|
19
|
+
super(content, meta, attributes);
|
|
20
|
+
this.element = 'sourceMap';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Transfers source position properties from one object to another.
|
|
25
|
+
*/
|
|
26
|
+
static transfer(from, to) {
|
|
27
|
+
to.startLine = from.startLine;
|
|
28
|
+
to.startCharacter = from.startCharacter;
|
|
29
|
+
to.startOffset = from.startOffset;
|
|
30
|
+
to.endLine = from.endLine;
|
|
31
|
+
to.endCharacter = from.endCharacter;
|
|
32
|
+
to.endOffset = from.endOffset;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates a SourceMapElement from source position properties.
|
|
37
|
+
* Returns undefined if any position property is not a number.
|
|
38
|
+
* Also assigns position properties to the instance for inspection.
|
|
39
|
+
*/
|
|
40
|
+
static from(source) {
|
|
41
|
+
const {
|
|
42
|
+
startLine,
|
|
43
|
+
startCharacter,
|
|
44
|
+
startOffset,
|
|
45
|
+
endLine,
|
|
46
|
+
endCharacter,
|
|
47
|
+
endOffset
|
|
48
|
+
} = source;
|
|
49
|
+
if (typeof startLine !== 'number' || typeof startCharacter !== 'number' || typeof startOffset !== 'number' || typeof endLine !== 'number' || typeof endCharacter !== 'number' || typeof endOffset !== 'number') {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const packed = packSourceMap([startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]);
|
|
53
|
+
const sourceMap = new SourceMapElement(packed);
|
|
54
|
+
sourceMap.startLine = startLine;
|
|
55
|
+
sourceMap.startCharacter = startCharacter;
|
|
56
|
+
sourceMap.startOffset = startOffset;
|
|
57
|
+
sourceMap.endLine = endLine;
|
|
58
|
+
sourceMap.endCharacter = endCharacter;
|
|
59
|
+
sourceMap.endOffset = endOffset;
|
|
60
|
+
return sourceMap;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Decodes the VLQ string and applies source position properties to the target.
|
|
65
|
+
*/
|
|
66
|
+
applyTo(target) {
|
|
67
|
+
if (!this.content) return;
|
|
68
|
+
[target.startLine, target.startCharacter, target.startOffset, target.endLine, target.endCharacter, target.endOffset] = unpackSourceMap(this.content);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
72
|
+
|
|
73
|
+
// Encode one unsigned integer to Base64-VLQ
|
|
74
|
+
function vlqEncodeInt(value) {
|
|
75
|
+
let vlq = value >>> 0; // ensure unsigned 32-bit
|
|
76
|
+
let out = '';
|
|
77
|
+
do {
|
|
78
|
+
let digit = vlq & 31; // 5 bits
|
|
79
|
+
vlq >>>= 5;
|
|
80
|
+
if (vlq !== 0) digit |= 32; // continuation bit
|
|
81
|
+
out += BASE64[digit];
|
|
82
|
+
} while (vlq !== 0);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Decode one unsigned integer from Base64-VLQ, starting at `index`
|
|
87
|
+
function vlqDecodeInt(str, index = 0) {
|
|
88
|
+
let result = 0;
|
|
89
|
+
let shift = 0;
|
|
90
|
+
let i = index;
|
|
91
|
+
while (true) {
|
|
92
|
+
const ch = str[i++];
|
|
93
|
+
const digit = BASE64.indexOf(ch);
|
|
94
|
+
if (digit === -1) throw new Error(`Invalid Base64 VLQ char: ${ch}`);
|
|
95
|
+
const cont = (digit & 32) !== 0;
|
|
96
|
+
result |= (digit & 31) << shift;
|
|
97
|
+
shift += 5;
|
|
98
|
+
if (!cont) break;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
value: result >>> 0,
|
|
102
|
+
next: i
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Span of 6 position values: [startLine, startCharacter, startOffset, endLine, endCharacter, endOffset]
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Encodes 6 position values into a compact VLQ string.
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
function packSourceMap(v) {
|
|
116
|
+
return 'sm1:' + v.map(vlqEncodeInt).join('');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Decodes a VLQ string into 6 position values.
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
function unpackSourceMap(packed) {
|
|
124
|
+
const s = packed.startsWith('sm1:') ? packed.slice(4) : packed;
|
|
125
|
+
const out = [];
|
|
126
|
+
let i = 0;
|
|
127
|
+
for (let k = 0; k < 6; k++) {
|
|
128
|
+
const r = vlqDecodeInt(s, i);
|
|
129
|
+
out.push(r.value);
|
|
130
|
+
i = r.next;
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
export default SourceMapElement;
|
package/src/index.cjs
CHANGED
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
exports.__esModule = true;
|
|
5
|
-
exports.refract = exports.StringElement = exports.RefElement = exports.ObjectSlice = exports.ObjectElement = exports.NumberElement = exports.NullElement = exports.Namespace = exports.MemberElement = exports.LinkElement = exports.KeyValuePair = exports.JSONSerialiser = exports.Element = exports.CollectionElement = exports.BooleanElement = exports.ArrayElement = void 0;
|
|
5
|
+
exports.refract = exports.isStringElement = exports.isSourceMapElement = exports.isRefElement = exports.isPrimitiveElement = exports.isParseResultElement = exports.isObjectElement = exports.isNumberElement = exports.isNullElement = exports.isMemberElement = exports.isLinkElement = exports.isElement = exports.isCommentElement = exports.isBooleanElement = exports.isArrayElement = exports.isAnnotationElement = exports.includesSymbols = exports.includesClasses = exports.hasElementSourceMap = exports.cloneShallow = exports.cloneDeep = exports.StringElement = exports.SourceMapElement = exports.ShallowCloneError = exports.RefElement = exports.ParseResultElement = exports.ObjectSlice = exports.ObjectElement = exports.NumberElement = exports.NullElement = exports.Namespace = exports.MemberElement = exports.LinkElement = exports.KeyValuePair = exports.JSONSerialiser = exports.Element = exports.DeepCloneError = exports.CommentElement = exports.CollectionElement = exports.CloneError = exports.BooleanElement = exports.ArrayElement = exports.AnnotationElement = void 0;
|
|
6
6
|
var _Namespace = _interopRequireDefault(require("./Namespace.cjs"));
|
|
7
7
|
exports.Namespace = _Namespace.default;
|
|
8
8
|
var _KeyValuePair = _interopRequireDefault(require("./KeyValuePair.cjs"));
|
|
9
9
|
exports.KeyValuePair = _KeyValuePair.default;
|
|
10
|
+
var _index = require("./clone/index.cjs");
|
|
11
|
+
exports.cloneShallow = _index.cloneShallow;
|
|
12
|
+
exports.cloneDeep = _index.cloneDeep;
|
|
13
|
+
exports.CloneError = _index.CloneError;
|
|
14
|
+
exports.DeepCloneError = _index.DeepCloneError;
|
|
15
|
+
exports.ShallowCloneError = _index.ShallowCloneError;
|
|
10
16
|
var _registration = require("./registration.cjs");
|
|
11
17
|
exports.ObjectSlice = _registration.ObjectSlice;
|
|
12
18
|
exports.Element = _registration.Element;
|
|
@@ -20,6 +26,29 @@ exports.ObjectElement = _registration.ObjectElement;
|
|
|
20
26
|
exports.MemberElement = _registration.MemberElement;
|
|
21
27
|
exports.RefElement = _registration.RefElement;
|
|
22
28
|
exports.LinkElement = _registration.LinkElement;
|
|
29
|
+
exports.AnnotationElement = _registration.AnnotationElement;
|
|
30
|
+
exports.CommentElement = _registration.CommentElement;
|
|
31
|
+
exports.ParseResultElement = _registration.ParseResultElement;
|
|
32
|
+
exports.SourceMapElement = _registration.SourceMapElement;
|
|
23
33
|
exports.refract = _registration.refract;
|
|
24
34
|
var _JSONSerialiser = _interopRequireDefault(require("./serialisers/JSONSerialiser.cjs"));
|
|
25
|
-
exports.JSONSerialiser = _JSONSerialiser.default;
|
|
35
|
+
exports.JSONSerialiser = _JSONSerialiser.default;
|
|
36
|
+
var _index2 = require("./predicates/index.cjs");
|
|
37
|
+
exports.isElement = _index2.isElement;
|
|
38
|
+
exports.isStringElement = _index2.isStringElement;
|
|
39
|
+
exports.isNumberElement = _index2.isNumberElement;
|
|
40
|
+
exports.isNullElement = _index2.isNullElement;
|
|
41
|
+
exports.isBooleanElement = _index2.isBooleanElement;
|
|
42
|
+
exports.isObjectElement = _index2.isObjectElement;
|
|
43
|
+
exports.isArrayElement = _index2.isArrayElement;
|
|
44
|
+
exports.isMemberElement = _index2.isMemberElement;
|
|
45
|
+
exports.isLinkElement = _index2.isLinkElement;
|
|
46
|
+
exports.isRefElement = _index2.isRefElement;
|
|
47
|
+
exports.isAnnotationElement = _index2.isAnnotationElement;
|
|
48
|
+
exports.isCommentElement = _index2.isCommentElement;
|
|
49
|
+
exports.isParseResultElement = _index2.isParseResultElement;
|
|
50
|
+
exports.isSourceMapElement = _index2.isSourceMapElement;
|
|
51
|
+
exports.isPrimitiveElement = _index2.isPrimitiveElement;
|
|
52
|
+
exports.hasElementSourceMap = _index2.hasElementSourceMap;
|
|
53
|
+
exports.includesSymbols = _index2.includesSymbols;
|
|
54
|
+
exports.includesClasses = _index2.includesClasses;
|