yuku-parser 0.5.41 → 0.5.43
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/README.md +0 -15
- package/decode.js +7 -37
- package/index.d.ts +0 -12
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -58,19 +58,6 @@ sourceTypeFromPath("foo.cjs"); // "script"
|
|
|
58
58
|
sourceTypeFromPath("foo.mjs"); // "module"
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
## Resolving offsets to `(line, column)`
|
|
62
|
-
|
|
63
|
-
Nodes and diagnostics carry `start`/`end` offsets (UTF-16 code units). To turn an offset into a `{ line, column }` pair, call `locOf` on the parse result:
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
import { parse } from "yuku-parser";
|
|
67
|
-
|
|
68
|
-
const result = parse(source);
|
|
69
|
-
const { line, column } = result.locOf(result.program.body[0].start);
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
Lines are 1-based and columns are 0-based, matching ESTree's `loc` convention. The lookup is an O(log n) binary search: tens of nanoseconds per call, safe to invoke per node during a walk.
|
|
73
|
-
|
|
74
61
|
## Walking the AST
|
|
75
62
|
|
|
76
63
|
A typed, mutating walker is built in:
|
|
@@ -149,8 +136,6 @@ interface ParseResult {
|
|
|
149
136
|
program: Program;
|
|
150
137
|
comments: Comment[]; // every comment in source order
|
|
151
138
|
diagnostics: Diagnostic[];
|
|
152
|
-
lineStarts: number[];
|
|
153
|
-
locOf(offset: number): { line: number; column: number };
|
|
154
139
|
}
|
|
155
140
|
```
|
|
156
141
|
|
package/decode.js
CHANGED
|
@@ -245,15 +245,14 @@ function decode(buffer, source) {
|
|
|
245
245
|
extraCount = _u32[1],
|
|
246
246
|
spLen = _u32[2];
|
|
247
247
|
const commentCount = _u32[4],
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
progIdx = _u32[8];
|
|
248
|
+
diagCount = _u32[6],
|
|
249
|
+
progIdx = _u32[7];
|
|
251
250
|
const attachedCommentCount = _u32[5];
|
|
252
|
-
const _flags = _u32[
|
|
251
|
+
const _flags = _u32[8];
|
|
253
252
|
const _isTs = !!(_flags & 1);
|
|
254
253
|
const _attached = !!(_flags & 2);
|
|
255
|
-
const _firstNa = _u32[
|
|
256
|
-
const _nodesOff =
|
|
254
|
+
const _firstNa = _u32[9];
|
|
255
|
+
const _nodesOff = 40;
|
|
257
256
|
const eOff = _nodesOff + nodeCount * 48;
|
|
258
257
|
const _extraBase = eOff >> 2;
|
|
259
258
|
const _spOff = eOff + extraCount * 4;
|
|
@@ -778,8 +777,7 @@ function decode(buffer, source) {
|
|
|
778
777
|
}
|
|
779
778
|
}
|
|
780
779
|
const node = _attached ? nodeWithComments : _decode;
|
|
781
|
-
const
|
|
782
|
-
const dOff = lsOff + lineStartsCount * 4;
|
|
780
|
+
const dOff = _cOff + commentCount * 20;
|
|
783
781
|
function _decodeComments() {
|
|
784
782
|
const out = Array.from({ length: commentCount });
|
|
785
783
|
for (let j = 0; j < commentCount; j++) {
|
|
@@ -798,20 +796,6 @@ function decode(buffer, source) {
|
|
|
798
796
|
}
|
|
799
797
|
return out;
|
|
800
798
|
}
|
|
801
|
-
function _decodeLineStarts() {
|
|
802
|
-
const out = Array.from({ length: lineStartsCount });
|
|
803
|
-
if (_firstNa >= _srcLen) {
|
|
804
|
-
for (let j = 0; j < lineStartsCount; j++) {
|
|
805
|
-
out[j] = dv.getUint32(lsOff + j * 4, true);
|
|
806
|
-
}
|
|
807
|
-
return out;
|
|
808
|
-
}
|
|
809
|
-
for (let j = 0; j < lineStartsCount; j++) {
|
|
810
|
-
const v = dv.getUint32(lsOff + j * 4, true);
|
|
811
|
-
out[j] = v < _firstNa ? v : (v >= _srcLen ? pm[pm.length - 1] : pm[v - _firstNa]);
|
|
812
|
-
}
|
|
813
|
-
return out;
|
|
814
|
-
}
|
|
815
799
|
function _decodeDiagnostics() {
|
|
816
800
|
const out = Array.from({ length: diagCount });
|
|
817
801
|
let dp = dOff;
|
|
@@ -844,11 +828,7 @@ function decode(buffer, source) {
|
|
|
844
828
|
}
|
|
845
829
|
return out;
|
|
846
830
|
}
|
|
847
|
-
let _program,
|
|
848
|
-
function _getLineStarts() {
|
|
849
|
-
if (_lineStarts === undefined) _lineStarts = _decodeLineStarts();
|
|
850
|
-
return _lineStarts;
|
|
851
|
-
}
|
|
831
|
+
let _program, _diagnostics, _comments;
|
|
852
832
|
return {
|
|
853
833
|
get program() {
|
|
854
834
|
return _program !== undefined ? _program : (_program = node(progIdx));
|
|
@@ -863,16 +843,6 @@ function decode(buffer, source) {
|
|
|
863
843
|
? _diagnostics
|
|
864
844
|
: (_diagnostics = _decodeDiagnostics());
|
|
865
845
|
},
|
|
866
|
-
get lineStarts() { return _getLineStarts(); },
|
|
867
|
-
locOf(offset) {
|
|
868
|
-
const ls = _getLineStarts();
|
|
869
|
-
let lo = 0, hi = ls.length;
|
|
870
|
-
while (lo < hi) {
|
|
871
|
-
const mid = (lo + hi) >>> 1;
|
|
872
|
-
if (ls[mid] <= offset) lo = mid + 1; else hi = mid;
|
|
873
|
-
}
|
|
874
|
-
return { line: lo, column: offset - ls[lo - 1] };
|
|
875
|
-
},
|
|
876
846
|
};
|
|
877
847
|
}
|
|
878
848
|
export { decode, CHILD_KEYS };
|
package/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import type {
|
|
|
10
10
|
NodeType,
|
|
11
11
|
Program,
|
|
12
12
|
SourceLang,
|
|
13
|
-
SourceLocation,
|
|
14
13
|
SourceType,
|
|
15
14
|
WalkContext,
|
|
16
15
|
} from "@yuku-toolchain/types";
|
|
@@ -70,17 +69,6 @@ interface ParseResult {
|
|
|
70
69
|
comments: Comment[];
|
|
71
70
|
/** Syntax diagnostics, and semantic diagnostics when {@link ParseOptions.semanticErrors} is enabled. */
|
|
72
71
|
diagnostics: Diagnostic[];
|
|
73
|
-
/**
|
|
74
|
-
* Sorted UTF-16 offsets where each line begins. Index `i` is the start of
|
|
75
|
-
* line `i + 1`. Used internally by {@link locOf}, and required by
|
|
76
|
-
* `yuku-codegen` for source maps.
|
|
77
|
-
*/
|
|
78
|
-
lineStarts: number[];
|
|
79
|
-
/**
|
|
80
|
-
* Resolves an offset to a `{ line, column }` pair. Lines are
|
|
81
|
-
* 1-based, columns are 0-based, matching ESTree's `loc` convention.
|
|
82
|
-
*/
|
|
83
|
-
locOf(offset: number): SourceLocation;
|
|
84
72
|
}
|
|
85
73
|
|
|
86
74
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuku-parser",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.43",
|
|
4
4
|
"description": "High-performance JavaScript/TypeScript parser",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"walk.js"
|
|
19
19
|
],
|
|
20
20
|
"optionalDependencies": {
|
|
21
|
-
"@yuku-parser/binding-linux-x64-gnu": "0.5.
|
|
22
|
-
"@yuku-parser/binding-linux-arm64-gnu": "0.5.
|
|
23
|
-
"@yuku-parser/binding-linux-arm-gnu": "0.5.
|
|
24
|
-
"@yuku-parser/binding-linux-x64-musl": "0.5.
|
|
25
|
-
"@yuku-parser/binding-linux-arm64-musl": "0.5.
|
|
26
|
-
"@yuku-parser/binding-linux-arm-musl": "0.5.
|
|
27
|
-
"@yuku-parser/binding-darwin-x64": "0.5.
|
|
28
|
-
"@yuku-parser/binding-darwin-arm64": "0.5.
|
|
29
|
-
"@yuku-parser/binding-win32-x64": "0.5.
|
|
30
|
-
"@yuku-parser/binding-win32-arm64": "0.5.
|
|
31
|
-
"@yuku-parser/binding-freebsd-x64": "0.5.
|
|
21
|
+
"@yuku-parser/binding-linux-x64-gnu": "0.5.43",
|
|
22
|
+
"@yuku-parser/binding-linux-arm64-gnu": "0.5.43",
|
|
23
|
+
"@yuku-parser/binding-linux-arm-gnu": "0.5.43",
|
|
24
|
+
"@yuku-parser/binding-linux-x64-musl": "0.5.43",
|
|
25
|
+
"@yuku-parser/binding-linux-arm64-musl": "0.5.43",
|
|
26
|
+
"@yuku-parser/binding-linux-arm-musl": "0.5.43",
|
|
27
|
+
"@yuku-parser/binding-darwin-x64": "0.5.43",
|
|
28
|
+
"@yuku-parser/binding-darwin-arm64": "0.5.43",
|
|
29
|
+
"@yuku-parser/binding-win32-x64": "0.5.43",
|
|
30
|
+
"@yuku-parser/binding-win32-arm64": "0.5.43",
|
|
31
|
+
"@yuku-parser/binding-freebsd-x64": "0.5.43"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@yuku-toolchain/types": "0.5.
|
|
34
|
+
"@yuku-toolchain/types": "0.5.42"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"acorn",
|