sh-ast 0.6.0 → 0.7.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/README.md +58 -11
- package/dist/analyze/enumerate-commands.d.ts +5 -1
- package/dist/analyze/enumerate-commands.d.ts.map +1 -1
- package/dist/analyze/enumerate-commands.js.map +1 -1
- package/dist/analyze/index.d.ts +8 -0
- package/dist/analyze/index.d.ts.map +1 -1
- package/dist/analyze/index.js +10 -0
- package/dist/analyze/index.js.map +1 -1
- package/dist/analyze/resolve-argv0.d.ts +16 -0
- package/dist/analyze/resolve-argv0.d.ts.map +1 -1
- package/dist/analyze/resolve-argv0.js +9 -5
- package/dist/analyze/resolve-argv0.js.map +1 -1
- package/dist/analyze.d.ts +169 -141
- package/dist/sh-ast.d.ts +11 -3
- package/dist/syntax-operator.d.ts +9 -0
- package/dist/syntax-operator.d.ts.map +1 -0
- package/dist/syntax-operator.js +22 -0
- package/dist/syntax-operator.js.map +1 -0
- package/dist/syntax-print.d.ts +3 -1
- package/dist/syntax-print.d.ts.map +1 -1
- package/dist/syntax-print.js +3 -1
- package/dist/syntax-print.js.map +1 -1
- package/dist/syntax-snapshot.d.ts +8 -6
- package/dist/syntax-snapshot.d.ts.map +1 -1
- package/dist/syntax-snapshot.js +86 -69
- package/dist/syntax-snapshot.js.map +1 -1
- package/dist/syntax.d.ts +9 -8
- package/dist/syntax.d.ts.map +1 -1
- package/dist/syntax.js +8 -21
- package/dist/syntax.js.map +1 -1
- package/generated/syntax-schema.d.ts +2 -2
- package/generated/syntax-schema.js +1 -1
- package/package.json +1 -1
- package/shim/sh-ast.wasm +0 -0
package/dist/sh-ast.d.ts
CHANGED
|
@@ -2265,6 +2265,9 @@ export declare interface ParseOptions {
|
|
|
2265
2265
|
* Parses exact source bytes, or well-formed Unicode text encoded as UTF-8. First
|
|
2266
2266
|
* use synchronously initializes WASM. The existing conservative nesting guard is
|
|
2267
2267
|
* an explicit binding resource limit, not an upstream grammar restriction.
|
|
2268
|
+
* The returned File and its Node subtrees are plain syntax data: ordinary
|
|
2269
|
+
* structuredClone(node), without transfers, makes an independent editable copy
|
|
2270
|
+
* while retaining position values, byte strings, typed nils and internal aliases.
|
|
2268
2271
|
* @public
|
|
2269
2272
|
*/
|
|
2270
2273
|
export declare function parseSync(source: string | Uint8Array, options?: ParseOptions): File_2;
|
|
@@ -2307,7 +2310,10 @@ export declare const Plus: 81;
|
|
|
2307
2310
|
|
|
2308
2311
|
/**
|
|
2309
2312
|
* Identity-based lookup of the original parse's bounds. A new or copied node has
|
|
2310
|
-
* no observation
|
|
2313
|
+
* no observation, including every node in a structuredClone of the syntax tree.
|
|
2314
|
+
* Clone File or a Node subtree, not this function-bearing lookup. Copied position
|
|
2315
|
+
* fields retain their values but do not transfer snapshot identity.
|
|
2316
|
+
* The index never calls WASM or recalculates edited node bounds.
|
|
2311
2317
|
* @public
|
|
2312
2318
|
*/
|
|
2313
2319
|
export declare interface PositionSnapshot {
|
|
@@ -2398,7 +2404,9 @@ export declare class PrintPanicError extends ShAstError {
|
|
|
2398
2404
|
/**
|
|
2399
2405
|
* Formats the current tree with a fresh upstream printer and collects all output.
|
|
2400
2406
|
* Supported roots are File, Stmt, Word, Assign, Command and WordPart; other Nodes
|
|
2401
|
-
* produce PrintError.
|
|
2407
|
+
* produce PrintError. An ordinary structuredClone of a supported syntax subtree
|
|
2408
|
+
* is accepted under the same input and failure rules; copying does not make nil
|
|
2409
|
+
* or unsupported roots printable. Only File output has upstream's trailing-newline behavior.
|
|
2402
2410
|
* Invalid UTF-8 output remains bytes. Upstream formatting can itself consume
|
|
2403
2411
|
* input bytes, including its tabwriter escape byte, so this is not source replay.
|
|
2404
2412
|
*
|
|
@@ -3092,7 +3100,7 @@ export declare interface SyntaxPos {
|
|
|
3092
3100
|
export declare interface SyntaxRecordSchema {
|
|
3093
3101
|
/** Whether the actual upstream type implements syntax.Node. */
|
|
3094
3102
|
readonly node: boolean;
|
|
3095
|
-
/** Every exported upstream field, retaining its original spelling. */
|
|
3103
|
+
/** Every exported upstream field, retaining its original spelling and lexicographic iteration order for internal position correlation. */
|
|
3096
3104
|
readonly fields: Readonly<Record<string, SyntaxFieldSchema>>;
|
|
3097
3105
|
}
|
|
3098
3106
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OperatorFamily, RawOperator } from '../generated/syntax-constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an unnamed value in an upstream uint32 operator family. Named
|
|
4
|
+
* constants remain precise literal unions; this explicit path preserves other Go
|
|
5
|
+
* values without claiming an operation such as Print accepts them.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare function rawOperator<Family extends OperatorFamily>(family: Family, value: number): RawOperator<Family>;
|
|
9
|
+
//# sourceMappingURL=syntax-operator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-operator.d.ts","sourceRoot":"","sources":["../src/syntax-operator.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAGpF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,cAAc,EACvD,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,WAAW,CAAC,MAAM,CAAC,CAarB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates unnamed operator values against the faithful field domains. This
|
|
3
|
+
* shared constructor owns numeric branding only; it does not parse syntax or
|
|
4
|
+
* promise that an upstream operation accepts every representable operator.
|
|
5
|
+
*/
|
|
6
|
+
import { SYNTAX_SCHEMA } from '../generated/syntax-schema.js';
|
|
7
|
+
import { InputError } from './syntax-errors.js';
|
|
8
|
+
/**
|
|
9
|
+
* Represents an unnamed value in an upstream uint32 operator family. Named
|
|
10
|
+
* constants remain precise literal unions; this explicit path preserves other Go
|
|
11
|
+
* values without claiming an operation such as Print accepts them.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export function rawOperator(family, value) {
|
|
15
|
+
const knownFamily = Object.values(SYNTAX_SCHEMA).some((record) => Object.values(record.fields).some((field) => field.kind === 'operator' && field.type === family));
|
|
16
|
+
if (!knownFamily || !Number.isInteger(value) || value < 0 || value > 0xffff_ffff) {
|
|
17
|
+
throw new InputError('An operator value must belong to a known family and be an integral uint32');
|
|
18
|
+
}
|
|
19
|
+
// The runtime check establishes the opaque numeric brand; no value is changed.
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=syntax-operator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-operator.js","sourceRoot":"","sources":["../src/syntax-operator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,KAAa;IAEb,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAC/D,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAC/B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,CAC9D,CACF,CAAC;IACF,IAAI,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,WAAW,EAAE,CAAC;QACjF,MAAM,IAAI,UAAU,CAClB,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,+EAA+E;IAC/E,OAAO,KAA4B,CAAC;AACtC,CAAC"}
|
package/dist/syntax-print.d.ts
CHANGED
|
@@ -34,7 +34,9 @@ export interface PrintOptions {
|
|
|
34
34
|
/**
|
|
35
35
|
* Formats the current tree with a fresh upstream printer and collects all output.
|
|
36
36
|
* Supported roots are File, Stmt, Word, Assign, Command and WordPart; other Nodes
|
|
37
|
-
* produce PrintError.
|
|
37
|
+
* produce PrintError. An ordinary structuredClone of a supported syntax subtree
|
|
38
|
+
* is accepted under the same input and failure rules; copying does not make nil
|
|
39
|
+
* or unsupported roots printable. Only File output has upstream's trailing-newline behavior.
|
|
38
40
|
* Invalid UTF-8 output remains bytes. Upstream formatting can itself consume
|
|
39
41
|
* input bytes, including its tabwriter escape byte, so this is not source replay.
|
|
40
42
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-print.d.ts","sourceRoot":"","sources":["../src/syntax-print.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAOnE;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,wFAAwF;IACxF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,wFAAwF;IACxF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,yFAAyF;IACzF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oFAAoF;IACpF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0DAA0D;IAC1D,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED
|
|
1
|
+
{"version":3,"file":"syntax-print.d.ts","sourceRoot":"","sources":["../src/syntax-print.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAOnE;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,wFAAwF;IACxF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,wFAAwF;IACxF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,yFAAyF;IACzF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oFAAoF;IACpF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0DAA0D;IAC1D,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,YAAiB,GAAG,QAAQ,CAoC1E"}
|
package/dist/syntax-print.js
CHANGED
|
@@ -6,7 +6,9 @@ import { callSyntax } from './wasm-instance.js';
|
|
|
6
6
|
/**
|
|
7
7
|
* Formats the current tree with a fresh upstream printer and collects all output.
|
|
8
8
|
* Supported roots are File, Stmt, Word, Assign, Command and WordPart; other Nodes
|
|
9
|
-
* produce PrintError.
|
|
9
|
+
* produce PrintError. An ordinary structuredClone of a supported syntax subtree
|
|
10
|
+
* is accepted under the same input and failure rules; copying does not make nil
|
|
11
|
+
* or unsupported roots printable. Only File output has upstream's trailing-newline behavior.
|
|
10
12
|
* Invalid UTF-8 output remains bytes. Upstream formatting can itself consume
|
|
11
13
|
* input bytes, including its tabwriter escape byte, so this is not source replay.
|
|
12
14
|
*
|
package/dist/syntax-print.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-print.js","sourceRoot":"","sources":["../src/syntax-print.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,aAA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AI,GAAG,CAAC;QACpB,gBAAgB;QAChB,kBAAkB;QAClB,gBAAgB;QAChB,aAAa;QACb,QAAQ;QACR,YAAY;QACZ,kBAAkB;KACnB,CAAC,CAAC;IACH,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,MAAM,KAAK,GACT,OAAO,KAAK,KAAK,QAAQ;gBACvB,CAAC,CAAC,KAAK,IAAI,EAAE,IAAI,KAAK,IAAI,mBAAsB;gBAChD,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;YAC7E,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,IAAI,UAAU,CAAC,4DAA4D,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,UAAU,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;QAC1D,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,kBAAkB,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -12,7 +12,10 @@ export interface NodePositions {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Identity-based lookup of the original parse's bounds. A new or copied node has
|
|
15
|
-
* no observation
|
|
15
|
+
* no observation, including every node in a structuredClone of the syntax tree.
|
|
16
|
+
* Clone File or a Node subtree, not this function-bearing lookup. Copied position
|
|
17
|
+
* fields retain their values but do not transfer snapshot identity.
|
|
18
|
+
* The index never calls WASM or recalculates edited node bounds.
|
|
16
19
|
* @public
|
|
17
20
|
*/
|
|
18
21
|
export interface PositionSnapshot {
|
|
@@ -37,11 +40,10 @@ export interface ParsedFile {
|
|
|
37
40
|
readonly Positions: PositionSnapshot;
|
|
38
41
|
}
|
|
39
42
|
/**
|
|
40
|
-
* Validates complete
|
|
41
|
-
* a weak identity map.
|
|
42
|
-
*
|
|
43
|
-
* The File must already have passed the full syntax boundary validator.
|
|
43
|
+
* Validates complete compact coverage and independent bound outcomes, then stores
|
|
44
|
+
* immutable observations in a weak identity map. No fallback calls can disguise
|
|
45
|
+
* malformed transport. The File must already pass the full boundary validator.
|
|
44
46
|
* @internal
|
|
45
47
|
*/
|
|
46
|
-
export declare function createPositionSnapshot(file: File, raw: unknown): PositionSnapshot;
|
|
48
|
+
export declare function createPositionSnapshot(file: File, raw: unknown, rawErrors: unknown): PositionSnapshot;
|
|
47
49
|
//# sourceMappingURL=syntax-snapshot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-snapshot.d.ts","sourceRoot":"","sources":["../src/syntax-snapshot.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAY,IAAI,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAKpF;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClC,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;CACnC;AAED
|
|
1
|
+
{"version":3,"file":"syntax-snapshot.d.ts","sourceRoot":"","sources":["../src/syntax-snapshot.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAY,IAAI,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAKpF;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClC,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;CACtC;AAuED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,OAAO,GACjB,gBAAgB,CA4DlB"}
|
package/dist/syntax-snapshot.js
CHANGED
|
@@ -19,101 +19,118 @@ function isNodeIdentity(value) {
|
|
|
19
19
|
SYNTAX_INTERFACES.Node.includes(value.Kind)));
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Visits child-bearing fields in the writer's lexical preorder, including children
|
|
23
|
+
* of auxiliary records. The complete File boundary has already been validated.
|
|
24
|
+
* Ordering is internal transport correlation, not the public Walk protocol.
|
|
25
25
|
*/
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
const visit = (value, path) => {
|
|
26
|
+
function visitNodes(file, observe) {
|
|
27
|
+
const visit = (value) => {
|
|
29
28
|
if (!isRecord(value) || typeof value.Type !== 'string')
|
|
30
29
|
return;
|
|
31
30
|
if (isNodeIdentity(value))
|
|
32
|
-
|
|
31
|
+
observe(value);
|
|
33
32
|
if (!Object.hasOwn(SYNTAX_SCHEMA, value.Type))
|
|
34
33
|
return;
|
|
35
34
|
for (const [name, field] of Object.entries(SYNTAX_SCHEMA[value.Type].fields)) {
|
|
36
35
|
if (field.kind !== 'struct' && field.kind !== 'interface')
|
|
37
36
|
continue;
|
|
38
37
|
const child = value[name];
|
|
39
|
-
if (Array.isArray(child))
|
|
40
|
-
child.forEach(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
visit(child, [...path, name]);
|
|
46
|
-
}
|
|
38
|
+
if (Array.isArray(child))
|
|
39
|
+
child.forEach(visit);
|
|
40
|
+
else
|
|
41
|
+
visit(child);
|
|
47
42
|
}
|
|
48
43
|
};
|
|
49
|
-
visit(file
|
|
50
|
-
return nodes;
|
|
44
|
+
visit(file);
|
|
51
45
|
}
|
|
52
|
-
/**
|
|
53
|
-
function
|
|
54
|
-
return
|
|
55
|
-
value.every((component) => typeof component === 'string' ||
|
|
56
|
-
(typeof component === 'number' && Number.isSafeInteger(component) && component >= 0)));
|
|
46
|
+
/** Own byte-bearing failures so neither transport holders nor catchers can alter captures. */
|
|
47
|
+
function copyError(error) {
|
|
48
|
+
return typeof error === 'string' ? error : error.slice();
|
|
57
49
|
}
|
|
58
|
-
/**
|
|
59
|
-
function
|
|
60
|
-
|
|
50
|
+
/** Reconstruct a bound only after checking flags and the unchanged SyntaxPos contract. */
|
|
51
|
+
function readBound(raw, offset, failed) {
|
|
52
|
+
const Offset = raw[offset];
|
|
53
|
+
const Line = raw[offset + 1];
|
|
54
|
+
const Col = raw[offset + 2];
|
|
55
|
+
const flags = raw[offset + 3];
|
|
56
|
+
if (typeof flags !== 'number' || !Number.isInteger(flags) || flags < 0 || flags > 7) {
|
|
57
|
+
throw new ShInternalError('The syntax snapshot contains invalid position flags');
|
|
58
|
+
}
|
|
59
|
+
const position = {
|
|
60
|
+
Offset,
|
|
61
|
+
Line,
|
|
62
|
+
Col,
|
|
63
|
+
IsValid: (flags & 1) !== 0,
|
|
64
|
+
IsRecovered: (flags & 2) !== 0,
|
|
65
|
+
OffsetOverflow: (flags & 4) !== 0,
|
|
66
|
+
};
|
|
67
|
+
if (!isSyntaxPos(position) ||
|
|
68
|
+
(failed && (Offset !== 0 || Line !== 0 || Col !== 0 || flags !== 0))) {
|
|
69
|
+
throw new ShInternalError('The syntax snapshot contains an invalid position observation');
|
|
70
|
+
}
|
|
71
|
+
return position;
|
|
61
72
|
}
|
|
62
73
|
/**
|
|
63
|
-
* Validates complete
|
|
64
|
-
* a weak identity map.
|
|
65
|
-
*
|
|
66
|
-
* The File must already have passed the full syntax boundary validator.
|
|
74
|
+
* Validates complete compact coverage and independent bound outcomes, then stores
|
|
75
|
+
* immutable observations in a weak identity map. No fallback calls can disguise
|
|
76
|
+
* malformed transport. The File must already pass the full boundary validator.
|
|
67
77
|
* @internal
|
|
68
78
|
*/
|
|
69
|
-
export function createPositionSnapshot(file, raw) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
for (const
|
|
76
|
-
if (!
|
|
77
|
-
|
|
78
|
-
!isPath(entry.Path) ||
|
|
79
|
-
!isObservation(entry.Pos, entry.PosError) ||
|
|
80
|
-
!isObservation(entry.End, entry.EndError)) {
|
|
81
|
-
throw new ShInternalError('The syntax snapshot contains an invalid position observation');
|
|
82
|
-
}
|
|
83
|
-
const path = JSON.stringify(entry.Path);
|
|
84
|
-
const node = remaining.get(path);
|
|
85
|
-
if (node === undefined)
|
|
86
|
-
throw new ShInternalError('The syntax snapshot contains an unknown or duplicate node path');
|
|
87
|
-
remaining.delete(path);
|
|
88
|
-
if (isGoString(entry.PosError)) {
|
|
89
|
-
observations.set(node, { error: entry.PosError });
|
|
90
|
-
}
|
|
91
|
-
else if (isGoString(entry.EndError)) {
|
|
92
|
-
observations.set(node, { error: entry.EndError });
|
|
93
|
-
}
|
|
94
|
-
else if (isSyntaxPos(entry.Pos) && isSyntaxPos(entry.End)) {
|
|
95
|
-
observations.set(node, {
|
|
96
|
-
positions: Object.freeze({
|
|
97
|
-
Pos: Object.freeze({ ...entry.Pos }),
|
|
98
|
-
End: Object.freeze({ ...entry.End }),
|
|
99
|
-
}),
|
|
100
|
-
});
|
|
79
|
+
export function createPositionSnapshot(file, raw, rawErrors) {
|
|
80
|
+
if (!Array.isArray(raw) || raw.length % 8 !== 0 || !Array.isArray(rawErrors)) {
|
|
81
|
+
throw new ShInternalError('The syntax snapshot has invalid compact metadata');
|
|
82
|
+
}
|
|
83
|
+
const count = raw.length / 8;
|
|
84
|
+
const failures = new Map();
|
|
85
|
+
for (const row of rawErrors) {
|
|
86
|
+
if (!Array.isArray(row) || row.length !== 3) {
|
|
87
|
+
throw new ShInternalError('The syntax snapshot contains an invalid failure row');
|
|
101
88
|
}
|
|
102
|
-
|
|
103
|
-
|
|
89
|
+
const values = row;
|
|
90
|
+
const [index, pos, end] = values;
|
|
91
|
+
if (typeof index !== 'number' ||
|
|
92
|
+
!Number.isInteger(index) ||
|
|
93
|
+
index < 0 ||
|
|
94
|
+
index >= count ||
|
|
95
|
+
failures.has(index) ||
|
|
96
|
+
!(pos === null || isGoString(pos)) ||
|
|
97
|
+
!(end === null || isGoString(end)) ||
|
|
98
|
+
(pos === null && end === null)) {
|
|
99
|
+
throw new ShInternalError('The syntax snapshot contains an invalid failure observation');
|
|
104
100
|
}
|
|
101
|
+
failures.set(index, [
|
|
102
|
+
pos === null ? null : copyError(pos),
|
|
103
|
+
end === null ? null : copyError(end),
|
|
104
|
+
]);
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
const observations = new WeakMap();
|
|
107
|
+
let index = 0;
|
|
108
|
+
visitNodes(file, (node) => {
|
|
109
|
+
if (index >= count)
|
|
110
|
+
throw new ShInternalError('The syntax snapshot omitted parsed nodes');
|
|
111
|
+
const errors = failures.get(index);
|
|
112
|
+
const posError = errors?.[0] ?? null;
|
|
113
|
+
const endError = errors?.[1] ?? null;
|
|
114
|
+
// Both bounds are validated even when get will replay the other bound's error.
|
|
115
|
+
const Pos = readBound(raw, index * 8, posError !== null);
|
|
116
|
+
const End = readBound(raw, index * 8 + 4, endError !== null);
|
|
117
|
+
const error = posError ?? endError;
|
|
118
|
+
observations.set(node, error !== null
|
|
119
|
+
? { error }
|
|
120
|
+
: {
|
|
121
|
+
positions: Object.freeze({ Pos: Object.freeze(Pos), End: Object.freeze(End) }),
|
|
122
|
+
});
|
|
123
|
+
index++;
|
|
124
|
+
});
|
|
125
|
+
if (index !== count)
|
|
126
|
+
throw new ShInternalError('The syntax snapshot contains excess observations');
|
|
108
127
|
return Object.freeze({
|
|
109
128
|
get(node) {
|
|
110
129
|
const observation = observations.get(node);
|
|
111
130
|
if (observation === undefined)
|
|
112
131
|
return undefined;
|
|
113
|
-
if ('error' in observation)
|
|
114
|
-
|
|
115
|
-
throw new InputError(typeof observation.error === 'string' ? observation.error : observation.error.slice());
|
|
116
|
-
}
|
|
132
|
+
if ('error' in observation)
|
|
133
|
+
throw new InputError(copyError(observation.error));
|
|
117
134
|
return observation.positions;
|
|
118
135
|
},
|
|
119
136
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax-snapshot.js","sourceRoot":"","sources":["../src/syntax-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"syntax-snapshot.js","sourceRoot":"","sources":["../src/syntax-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAA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CAAC,GAAG,CAAC,EAAE,CAAC;aAC/E,CACN,CAAC;QACF,KAAK,EAAE,CAAC;IACV,CAAC,CAAC,CAAC;IACH,IAAI,KAAK,KAAK,KAAK;QACjB,MAAM,IAAI,eAAe,CAAC,kDAAkD,CAAC,CAAC;IAChF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,GAAG,CAAC,IAAU;YACZ,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC3C,IAAI,WAAW,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAChD,IAAI,OAAO,IAAI,WAAW;gBAAE,MAAM,IAAI,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;YAC/E,OAAO,WAAW,CAAC,SAAS,CAAC;QAC/B,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/syntax.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous access to the pinned upstream syntax model. Parsing and derived
|
|
3
|
+
* node bounds run in Go; this module transports exact data and adapts errors,
|
|
4
|
+
* leaving ESLint locations, traversal, and policy to consumers.
|
|
5
|
+
*/
|
|
2
6
|
import type { File, GoString, Node, SyntaxPos } from '../generated/syntax-types.js';
|
|
3
7
|
import { type ParsedFile } from './syntax-snapshot.js';
|
|
4
8
|
export type { ParsedFile, PositionSnapshot, NodePositions } from './syntax-snapshot.js';
|
|
5
9
|
export { InputError, LangError, ParseError } from './syntax-errors.js';
|
|
10
|
+
export { rawOperator } from './syntax-operator.js';
|
|
6
11
|
/**
|
|
7
12
|
* Whole-file parser inputs corresponding to upstream controls. Defaults match
|
|
8
13
|
* NewParser; in particular comments are retained only when KeepComments is true.
|
|
@@ -25,6 +30,9 @@ export interface ParseOptions {
|
|
|
25
30
|
* Parses exact source bytes, or well-formed Unicode text encoded as UTF-8. First
|
|
26
31
|
* use synchronously initializes WASM. The existing conservative nesting guard is
|
|
27
32
|
* an explicit binding resource limit, not an upstream grammar restriction.
|
|
33
|
+
* The returned File and its Node subtrees are plain syntax data: ordinary
|
|
34
|
+
* structuredClone(node), without transfers, makes an independent editable copy
|
|
35
|
+
* while retaining position values, byte strings, typed nils and internal aliases.
|
|
28
36
|
* @public
|
|
29
37
|
*/
|
|
30
38
|
export declare function parseSync(source: string | Uint8Array, options?: ParseOptions): File;
|
|
@@ -55,11 +63,4 @@ export declare function nodeEnd(node: Node): SyntaxPos;
|
|
|
55
63
|
* @public
|
|
56
64
|
*/
|
|
57
65
|
export declare function newPos(offset: number | bigint, line: number | bigint, column: number | bigint): SyntaxPos;
|
|
58
|
-
/**
|
|
59
|
-
* Represents an unnamed value in an upstream uint32 operator family. Named
|
|
60
|
-
* constants remain precise literal unions; this explicit path preserves other Go
|
|
61
|
-
* values without claiming an operation such as Print accepts them.
|
|
62
|
-
* @public
|
|
63
|
-
*/
|
|
64
|
-
export declare function rawOperator<Family extends OperatorFamily>(family: Family, value: number): RawOperator<Family>;
|
|
65
66
|
//# sourceMappingURL=syntax.d.ts.map
|
package/dist/syntax.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAepF,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/E,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,mEAAmE;IACnE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,kFAAkF;IAClF,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,qFAAqF;IACrF,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CAEvF;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,GAAG,UAAU,EAC3B,OAAO,GAAE,YAAiB,GACzB,UAAU,CAMZ;AAwBD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,MAAM,EAAE,MAAM,GAAG,MAAM,GACtB,SAAS,CAQX"}
|
package/dist/syntax.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Synchronous access to the pinned upstream syntax model. Parsing and derived
|
|
3
|
-
* node bounds run in Go; this module transports exact data and adapts errors,
|
|
4
|
-
* leaving ESLint locations, traversal, and policy to consumers.
|
|
5
|
-
*/
|
|
6
|
-
import { SYNTAX_SCHEMA } from '../generated/syntax-schema.js';
|
|
7
1
|
import { ShInternalError } from './errors.js';
|
|
8
2
|
import { assertParseDepthWithinLimit } from './parse-depth-guard.js';
|
|
9
3
|
import { InputError, LangError, ParseError } from './syntax-errors.js';
|
|
@@ -11,10 +5,14 @@ import { assertUnicodeString, decodeWire, encodeWire, isGoString, isRecord, isSy
|
|
|
11
5
|
import { callSyntax } from './wasm-instance.js';
|
|
12
6
|
import { createPositionSnapshot } from './syntax-snapshot.js';
|
|
13
7
|
export { InputError, LangError, ParseError } from './syntax-errors.js';
|
|
8
|
+
export { rawOperator } from './syntax-operator.js';
|
|
14
9
|
/**
|
|
15
10
|
* Parses exact source bytes, or well-formed Unicode text encoded as UTF-8. First
|
|
16
11
|
* use synchronously initializes WASM. The existing conservative nesting guard is
|
|
17
12
|
* an explicit binding resource limit, not an upstream grammar restriction.
|
|
13
|
+
* The returned File and its Node subtrees are plain syntax data: ordinary
|
|
14
|
+
* structuredClone(node), without transfers, makes an independent editable copy
|
|
15
|
+
* while retaining position values, byte strings, typed nils and internal aliases.
|
|
18
16
|
* @public
|
|
19
17
|
*/
|
|
20
18
|
export function parseSync(source, options = {}) {
|
|
@@ -29,7 +27,10 @@ export function parseSync(source, options = {}) {
|
|
|
29
27
|
*/
|
|
30
28
|
export function parseWithPositionsSync(source, options = {}) {
|
|
31
29
|
const { file, response } = invokeParse('parse-with-positions', source, options);
|
|
32
|
-
return Object.freeze({
|
|
30
|
+
return Object.freeze({
|
|
31
|
+
File: file,
|
|
32
|
+
Positions: createPositionSnapshot(file, response.Positions, response.PositionErrors),
|
|
33
|
+
});
|
|
33
34
|
}
|
|
34
35
|
/** Shared source/options/error semantics for both whole-file parsing operations. */
|
|
35
36
|
function invokeParse(operation, source, options) {
|
|
@@ -75,20 +76,6 @@ export function newPos(offset, line, column) {
|
|
|
75
76
|
throw new ShInternalError('The syntax constructor returned an invalid position record');
|
|
76
77
|
return result.Position;
|
|
77
78
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Represents an unnamed value in an upstream uint32 operator family. Named
|
|
80
|
-
* constants remain precise literal unions; this explicit path preserves other Go
|
|
81
|
-
* values without claiming an operation such as Print accepts them.
|
|
82
|
-
* @public
|
|
83
|
-
*/
|
|
84
|
-
export function rawOperator(family, value) {
|
|
85
|
-
const knownFamily = Object.values(SYNTAX_SCHEMA).some((record) => Object.values(record.fields).some((field) => field.kind === 'operator' && field.type === family));
|
|
86
|
-
if (!knownFamily || !Number.isInteger(value) || value < 0 || value > 0xffff_ffff) {
|
|
87
|
-
throw new InputError('An operator value must belong to a known family and be an integral uint32');
|
|
88
|
-
}
|
|
89
|
-
// The runtime check establishes the opaque numeric brand; no value is changed.
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
79
|
/** Exact Go options are validated without silently ignoring misspelled keys. */
|
|
93
80
|
function validateOptions(options) {
|
|
94
81
|
if (!isRecord(options))
|
package/dist/syntax.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"syntax.js","sourceRoot":"","sources":["../src/syntax.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAmB,MAAM,sBAAsB,CAAC;AAG/E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAqBnD;;;;;;;;GAQG;AACH,M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YACtB,OAAO,KAAK,CAAC,UAAU,KAAK,SAAS,EACrC,CAAC;YACD,MAAM,IAAI,UAAU,CAClB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,UAAU,EAChB,IAAI,CACL,CAAC;QACJ,CAAC;QACD,IACE,KAAK,CAAC,IAAI,KAAK,WAAW;YAC1B,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC;YACzB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;YAC1B,KAAK,CAAC,KAAK,CAAC,KAAK,CACf,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAC1E;YACD,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,EAClC,CAAC;YACD,MAAM,IAAI,SAAS,CACjB,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,QAAQ,EACd,IAAI,CACL,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,eAAe,CAAC,oEAAoE,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -51,10 +51,10 @@ export interface SyntaxFieldSchema {
|
|
|
51
51
|
export interface SyntaxRecordSchema {
|
|
52
52
|
/** Whether the actual upstream type implements syntax.Node. */
|
|
53
53
|
readonly node: boolean;
|
|
54
|
-
/** Every exported upstream field, retaining its original spelling. */
|
|
54
|
+
/** Every exported upstream field, retaining its original spelling and lexicographic iteration order for internal position correlation. */
|
|
55
55
|
readonly fields: Readonly<Record<string, SyntaxFieldSchema>>;
|
|
56
56
|
}
|
|
57
|
-
/** Reflection metadata; field order is not upstream Walk order. @public */
|
|
57
|
+
/** Reflection metadata; lexicographic field order correlates internal position occurrences and is not upstream Walk order. @public */
|
|
58
58
|
export declare const SYNTAX_SCHEMA: Readonly<Record<string, SyntaxRecordSchema>>;
|
|
59
59
|
/** Concrete alternatives accepted by upstream interfaces. @public */
|
|
60
60
|
export declare const SYNTAX_INTERFACES: Readonly<Record<string, readonly string[]>>;
|
|
@@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Complete upstream field shapes for reflection and consumer adaptation.
|
|
34
|
+
* Complete upstream field shapes for reflection and consumer adaptation. Fields use lexicographic order to correlate internal parse-time position occurrences with the syntax writer. This order is not upstream Walk order. The public binding freezes this shared metadata; represented syntax records remain mutable.
|
|
35
35
|
*
|
|
36
36
|
* @public
|
|
37
37
|
*/
|
package/package.json
CHANGED
package/shim/sh-ast.wasm
CHANGED
|
Binary file
|