sh-ast 0.4.0 → 0.6.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 +124 -9
- package/dist/analyze/brace-observation.d.ts +18 -0
- package/dist/analyze/brace-observation.d.ts.map +1 -0
- package/dist/analyze/brace-observation.js +59 -0
- package/dist/analyze/brace-observation.js.map +1 -0
- package/dist/analyze/resolve-argv0.d.ts +32 -8
- package/dist/analyze/resolve-argv0.d.ts.map +1 -1
- package/dist/analyze/resolve-argv0.js +49 -9
- package/dist/analyze/resolve-argv0.js.map +1 -1
- package/dist/analyze/resolve-word.d.ts +21 -13
- package/dist/analyze/resolve-word.d.ts.map +1 -1
- package/dist/analyze/resolve-word.js +8 -3
- package/dist/analyze/resolve-word.js.map +1 -1
- package/dist/analyze.d.ts +53 -21
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/sh-ast.d.ts +120 -0
- package/dist/syntax-print-errors.d.ts +35 -0
- package/dist/syntax-print-errors.d.ts.map +1 -0
- package/dist/syntax-print-errors.js +37 -0
- package/dist/syntax-print-errors.js.map +1 -0
- package/dist/syntax-print.d.ts +49 -0
- package/dist/syntax-print.d.ts.map +1 -0
- package/dist/syntax-print.js +86 -0
- package/dist/syntax-print.js.map +1 -0
- package/dist/syntax-walk-bounds.d.ts +18 -0
- package/dist/syntax-walk-bounds.d.ts.map +1 -0
- package/dist/syntax-walk-bounds.js +188 -0
- package/dist/syntax-walk-bounds.js.map +1 -0
- package/dist/syntax-walk-errors.d.ts +19 -0
- package/dist/syntax-walk-errors.d.ts.map +1 -0
- package/dist/syntax-walk-errors.js +23 -0
- package/dist/syntax-walk-errors.js.map +1 -0
- package/dist/syntax-walk-license.d.ts +3 -0
- package/dist/syntax-walk-license.d.ts.map +1 -0
- package/dist/syntax-walk-license.js +37 -0
- package/dist/syntax-walk-license.js.map +1 -0
- package/dist/syntax-walk.d.ts +46 -0
- package/dist/syntax-walk.d.ts.map +1 -0
- package/dist/syntax-walk.js +322 -0
- package/dist/syntax-walk.js.map +1 -0
- package/dist/syntax-wire.d.ts +2 -0
- package/dist/syntax-wire.d.ts.map +1 -1
- package/dist/syntax-wire.js +28 -4
- package/dist/syntax-wire.js.map +1 -1
- package/package.json +1 -1
- package/shim/sh-ast.wasm +0 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { nilDereference, WalkPanicError } from './syntax-walk-errors.js';
|
|
2
|
+
/** Largest upstream source offset; the remaining high values are invalid sentinels. */
|
|
3
|
+
const OFFSET_MAX = 0xffff_fff4;
|
|
4
|
+
/** Ordinary zero Pos, distinct from a recovered token. */
|
|
5
|
+
const ZERO = { offset: 0, lineCol: 0 };
|
|
6
|
+
/** Serialized invalid offsets share all ordering behavior relevant to Walk. */
|
|
7
|
+
function unpack(pos) {
|
|
8
|
+
return {
|
|
9
|
+
offset: pos.OffsetOverflow ? OFFSET_MAX + 1 : pos.Offset,
|
|
10
|
+
lineCol: ((pos.Line << 14) | pos.Col) >>> 0,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Upstream validity depends on both packed coordinates and raw offset. */
|
|
14
|
+
function valid(pos) {
|
|
15
|
+
return pos.offset <= OFFSET_MAX && pos.lineCol !== 0;
|
|
16
|
+
}
|
|
17
|
+
/** Position arithmetic stops on invalid input and otherwise wraps both uint32 words. */
|
|
18
|
+
function add(pos, n) {
|
|
19
|
+
return valid(pos) ? { offset: (pos.offset + n) >>> 0, lineCol: (pos.lineCol + n) >>> 0 } : pos;
|
|
20
|
+
}
|
|
21
|
+
/** Only the left operand must be valid; a right ordinary-invalid offset still orders. */
|
|
22
|
+
function after(left, right) {
|
|
23
|
+
return valid(left) && left.offset > right.offset;
|
|
24
|
+
}
|
|
25
|
+
/** Upstream retains the first position unless the second is observably after it. */
|
|
26
|
+
function maximum(left, right) {
|
|
27
|
+
return after(right, left) ? right : left;
|
|
28
|
+
}
|
|
29
|
+
/** A nil list and an empty list share indexed-access panic behavior. */
|
|
30
|
+
function at(values, index) {
|
|
31
|
+
const length = values?.length ?? 0;
|
|
32
|
+
if (values === null || index < 0 || index >= length) {
|
|
33
|
+
throw new WalkPanicError(index < 0
|
|
34
|
+
? `runtime error: index out of range [${String(index)}]`
|
|
35
|
+
: `runtime error: index out of range [${String(index)}] with length ${String(length)}`);
|
|
36
|
+
}
|
|
37
|
+
return values[index];
|
|
38
|
+
}
|
|
39
|
+
/** Nil pointers and nil interfaces both fail when a bound method dereferences them. */
|
|
40
|
+
function concrete(node) {
|
|
41
|
+
if (node === null || node.Type === 'TypedNil') {
|
|
42
|
+
return nilDereference();
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
/** Only WordPart/ArithmExpr positions are reachable from comment placement. */
|
|
47
|
+
function position(value) {
|
|
48
|
+
const node = concrete(value);
|
|
49
|
+
switch (node.Type) {
|
|
50
|
+
case 'CaseItem':
|
|
51
|
+
return position(at(node.Patterns, 0));
|
|
52
|
+
case 'ArrayElem':
|
|
53
|
+
return position(node.Index ?? node.Value);
|
|
54
|
+
case 'Word':
|
|
55
|
+
return position(at(node.Parts, 0));
|
|
56
|
+
case 'Lit':
|
|
57
|
+
return unpack(node.ValuePos);
|
|
58
|
+
case 'SglQuoted':
|
|
59
|
+
case 'DblQuoted':
|
|
60
|
+
case 'CmdSubst':
|
|
61
|
+
case 'ArithmExp':
|
|
62
|
+
return unpack(node.Left);
|
|
63
|
+
case 'ParamExp':
|
|
64
|
+
return node.Dollar.IsValid ? unpack(node.Dollar) : position(node.Param);
|
|
65
|
+
case 'ProcSubst':
|
|
66
|
+
case 'ExtGlob':
|
|
67
|
+
return unpack(node.OpPos);
|
|
68
|
+
case 'BraceExp':
|
|
69
|
+
return add(position(at(node.Elems, 0)), -1);
|
|
70
|
+
case 'BinaryArithm':
|
|
71
|
+
return position(node.X);
|
|
72
|
+
case 'UnaryArithm':
|
|
73
|
+
return node.Post ? position(node.X) : unpack(node.OpPos);
|
|
74
|
+
case 'ParenArithm':
|
|
75
|
+
return unpack(node.Lparen);
|
|
76
|
+
case 'FlagsArithm':
|
|
77
|
+
return add(position(node.Flags), -1);
|
|
78
|
+
default:
|
|
79
|
+
throw new WalkPanicError(`syntax.Walk: unexpected position dependency *syntax.${node.Type}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** End follows the current fields, and is evaluated only when a Stmt has comments. */
|
|
83
|
+
function end(value) {
|
|
84
|
+
const node = concrete(value);
|
|
85
|
+
switch (node.Type) {
|
|
86
|
+
case 'Stmt': {
|
|
87
|
+
if (node.Semicolon.IsValid) {
|
|
88
|
+
const end = add(unpack(node.Semicolon), 1);
|
|
89
|
+
return node.Coprocess || node.Disown ? add(end, 1) : end;
|
|
90
|
+
}
|
|
91
|
+
let result = node.Negated ? add(unpack(node.Position), 1) : unpack(node.Position);
|
|
92
|
+
if (node.Cmd !== null) {
|
|
93
|
+
result = end(node.Cmd);
|
|
94
|
+
}
|
|
95
|
+
if (node.Redirs?.length) {
|
|
96
|
+
result = maximum(result, end(at(node.Redirs, node.Redirs.length - 1)));
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
case 'CallExpr':
|
|
101
|
+
return node.Args?.length
|
|
102
|
+
? end(at(node.Args, node.Args.length - 1))
|
|
103
|
+
: end(at(node.Assigns, (node.Assigns?.length ?? 0) - 1));
|
|
104
|
+
case 'Assign':
|
|
105
|
+
if (node.Value !== null) {
|
|
106
|
+
return end(node.Value);
|
|
107
|
+
}
|
|
108
|
+
if (node.Array !== null) {
|
|
109
|
+
return end(node.Array);
|
|
110
|
+
}
|
|
111
|
+
if (node.Index !== null) {
|
|
112
|
+
return add(end(node.Index), 2);
|
|
113
|
+
}
|
|
114
|
+
return node.Naked ? end(node.Name) : add(end(node.Name), 1);
|
|
115
|
+
case 'Redirect':
|
|
116
|
+
return end(node.Hdoc ?? node.Word);
|
|
117
|
+
case 'Subshell':
|
|
118
|
+
case 'ArrayExpr':
|
|
119
|
+
case 'ProcSubst':
|
|
120
|
+
case 'ParenArithm':
|
|
121
|
+
case 'ParenTest':
|
|
122
|
+
return add(unpack(node.Rparen), 1);
|
|
123
|
+
case 'Block':
|
|
124
|
+
return add(unpack(node.Rbrace), 1);
|
|
125
|
+
case 'IfClause':
|
|
126
|
+
return add(unpack(node.FiPos), 2);
|
|
127
|
+
case 'WhileClause':
|
|
128
|
+
case 'ForClause':
|
|
129
|
+
return add(unpack(node.DonePos), 4);
|
|
130
|
+
case 'BinaryCmd':
|
|
131
|
+
case 'BinaryArithm':
|
|
132
|
+
case 'BinaryTest':
|
|
133
|
+
return end(node.Y);
|
|
134
|
+
case 'FuncDecl':
|
|
135
|
+
case 'TestDecl':
|
|
136
|
+
return end(node.Body);
|
|
137
|
+
case 'Word':
|
|
138
|
+
return end(at(node.Parts, (node.Parts?.length ?? 0) - 1));
|
|
139
|
+
case 'Lit':
|
|
140
|
+
return unpack(node.ValueEnd);
|
|
141
|
+
case 'SglQuoted':
|
|
142
|
+
case 'DblQuoted':
|
|
143
|
+
case 'CmdSubst':
|
|
144
|
+
return add(unpack(node.Right), 1);
|
|
145
|
+
case 'ParamExp':
|
|
146
|
+
return !node.Short
|
|
147
|
+
? add(unpack(node.Rbrace), 1)
|
|
148
|
+
: node.Index !== null
|
|
149
|
+
? add(end(node.Index), 1)
|
|
150
|
+
: end(node.Param);
|
|
151
|
+
case 'ArithmExp':
|
|
152
|
+
return add(unpack(node.Right), node.Bracket ? 1 : 2);
|
|
153
|
+
case 'ArithmCmd':
|
|
154
|
+
case 'TestClause':
|
|
155
|
+
return add(unpack(node.Right), 2);
|
|
156
|
+
case 'UnaryArithm':
|
|
157
|
+
return node.Post ? add(unpack(node.OpPos), 2) : end(node.X);
|
|
158
|
+
case 'UnaryTest':
|
|
159
|
+
return end(node.X);
|
|
160
|
+
case 'FlagsArithm':
|
|
161
|
+
return node.X !== null ? end(node.X) : add(end(node.Flags), 1);
|
|
162
|
+
case 'CaseClause':
|
|
163
|
+
return add(unpack(node.Esac), 4);
|
|
164
|
+
case 'DeclClause':
|
|
165
|
+
return node.Args?.length ? end(at(node.Args, node.Args.length - 1)) : end(node.Variant);
|
|
166
|
+
case 'ExtGlob':
|
|
167
|
+
return add(end(node.Pattern), 1);
|
|
168
|
+
case 'TimeClause':
|
|
169
|
+
return node.Stmt === null ? add(unpack(node.Time), 4) : end(node.Stmt);
|
|
170
|
+
case 'CoprocClause':
|
|
171
|
+
return end(node.Stmt);
|
|
172
|
+
case 'LetClause':
|
|
173
|
+
return end(at(node.Exprs, (node.Exprs?.length ?? 0) - 1));
|
|
174
|
+
case 'BraceExp':
|
|
175
|
+
return add(node.Elems?.length ? end(at(node.Elems, node.Elems.length - 1)) : ZERO, 1);
|
|
176
|
+
default:
|
|
177
|
+
throw new WalkPanicError(`syntax.Walk: unexpected end dependency *syntax.${node.Type}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Stmt comments at or after the live end become the single deferred comment. @internal */
|
|
181
|
+
export function atStatementEnd(node, hash) {
|
|
182
|
+
return !after(end(node), unpack(hash));
|
|
183
|
+
}
|
|
184
|
+
/** Case/array comments strictly after the live start become deferred. @internal */
|
|
185
|
+
export function afterItemStart(node, hash) {
|
|
186
|
+
return after(unpack(hash), position(node));
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=syntax-walk-bounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk-bounds.js","sourceRoot":"","sources":["../src/syntax-walk-bounds.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAOzE,uFAAuF;AACvF,MAAM,UAAU,GAAG,WAAW,CAAC;AAC/B,0DAA0D;AAC1D,MAAM,IAAI,GAAc,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CA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AAG,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACxF;YACE,MAAM,IAAI,cAAc,CAAC,kDAAkD,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5F,CAAC;AACH,CAAC;AACD,2FAA2F;AAC3F,MAAM,UAAU,cAAc,CAAC,IAAqC,EAAE,IAAe;IACnF,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AACD,mFAAmF;AACnF,MAAM,UAAU,cAAc,CAC5B,IAAuD,EACvD,IAAe;IAEf,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Walk-specific panic adaptation keeps upstream failures distinct from caller exceptions. */
|
|
2
|
+
import type { GoString } from '../generated/syntax-types.js';
|
|
3
|
+
import { ShAstError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* A panic raised by upstream-equivalent traversal, such as a nil dereference or
|
|
6
|
+
* unsupported concrete node. Exceptions thrown by callbacks are never wrapped.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class WalkPanicError extends ShAstError {
|
|
10
|
+
/** Stable discriminator for traversal panics. @public */
|
|
11
|
+
readonly code = "SH_AST_WALK_PANIC";
|
|
12
|
+
/** Exact upstream panic bytes; Error.message is only a display rendering. @public */
|
|
13
|
+
readonly Message: GoString;
|
|
14
|
+
/** Retains the upstream panic text separately from its display rendering. @public */
|
|
15
|
+
constructor(message: GoString);
|
|
16
|
+
}
|
|
17
|
+
/** A concrete pointer dereference failed at the point upstream would access it. @internal */
|
|
18
|
+
export declare function nilDereference(): never;
|
|
19
|
+
//# sourceMappingURL=syntax-walk-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk-errors.d.ts","sourceRoot":"","sources":["../src/syntax-walk-errors.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,UAAU;IAC5C,yDAAyD;IACzD,QAAQ,CAAC,IAAI,uBAAuB;IAEpC,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAE3B,qFAAqF;gBACzE,OAAO,EAAE,QAAQ;CAK9B;AAED,6FAA6F;AAC7F,wBAAgB,cAAc,IAAI,KAAK,CAEtC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ShAstError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* A panic raised by upstream-equivalent traversal, such as a nil dereference or
|
|
4
|
+
* unsupported concrete node. Exceptions thrown by callbacks are never wrapped.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class WalkPanicError extends ShAstError {
|
|
8
|
+
/** Stable discriminator for traversal panics. @public */
|
|
9
|
+
code = 'SH_AST_WALK_PANIC';
|
|
10
|
+
/** Exact upstream panic bytes; Error.message is only a display rendering. @public */
|
|
11
|
+
Message;
|
|
12
|
+
/** Retains the upstream panic text separately from its display rendering. @public */
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(typeof message === 'string' ? message : new TextDecoder().decode(message));
|
|
15
|
+
this.Message = message;
|
|
16
|
+
this.name = 'WalkPanicError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** A concrete pointer dereference failed at the point upstream would access it. @internal */
|
|
20
|
+
export function nilDereference() {
|
|
21
|
+
throw new WalkPanicError('runtime error: invalid memory address or nil pointer dereference');
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=syntax-walk-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk-errors.js","sourceRoot":"","sources":["../src/syntax-walk-errors.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAC5C,yDAAyD;IAChD,IAAI,GAAG,mBAAmB,CAAC;IAEpC,qFAAqF;IAC5E,OAAO,CAAW;IAE3B,qFAAqF;IACrF,YAAY,OAAiB;QAC3B,KAAK,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QACjF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,6FAA6F;AAC7F,MAAM,UAAU,cAAc;IAC5B,MAAM,IAAI,cAAc,CAAC,kEAAkE,CAAC,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk-license.d.ts","sourceRoot":"","sources":["../src/syntax-walk-license.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAmC/E,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Upstream license for the walk dispatcher and private boundary evaluator. */
|
|
2
|
+
/*
|
|
3
|
+
The walk dispatcher and private bounds evaluator adapt code from
|
|
4
|
+
mvdan.cc/sh/v3/syntax (walk.go and nodes.go)
|
|
5
|
+
(https://github.com/mvdan/sh), which is distributed under the following
|
|
6
|
+
license:
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2016, Daniel Martí. All rights reserved.
|
|
9
|
+
|
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
|
11
|
+
modification, are permitted provided that the following conditions are
|
|
12
|
+
met:
|
|
13
|
+
|
|
14
|
+
* Redistributions of source code must retain the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer.
|
|
16
|
+
* Redistributions in binary form must reproduce the above
|
|
17
|
+
copyright notice, this list of conditions and the following disclaimer
|
|
18
|
+
in the documentation and/or other materials provided with the
|
|
19
|
+
distribution.
|
|
20
|
+
* Neither the name of the copyright holder nor the names of its
|
|
21
|
+
contributors may be used to endorse or promote products derived from
|
|
22
|
+
this software without specific prior written permission.
|
|
23
|
+
|
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
25
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
26
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
27
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
28
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
29
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
30
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
31
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
32
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
33
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
34
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
35
|
+
*/
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=syntax-walk-license.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk-license.js","sourceRoot":"","sources":["../src/syntax-walk-license.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCE;AACF,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous live dispatch of mvdan/sh's Walk case ordering. Child reads
|
|
3
|
+
* occur when upstream reaches them; no precomputed trace or subtree transfer can
|
|
4
|
+
* hide callback edits. Ordinary JavaScript arrays retain their own object identity;
|
|
5
|
+
* distinct Go slice headers, capacity and value-slot addresses over shared backing
|
|
6
|
+
* storage are not represented. Ordinary JavaScript aliases remain shared.
|
|
7
|
+
* Positional work is limited to live comment placement.
|
|
8
|
+
*
|
|
9
|
+
* Adapted from mvdan.cc/sh/v3 v3.13.1 syntax/walk.go, copyright Daniel Martí.
|
|
10
|
+
* The upstream BSD license is retained in syntax-walk-license.ts.
|
|
11
|
+
*/
|
|
12
|
+
import type { Node } from '../generated/syntax-types.js';
|
|
13
|
+
export { WalkPanicError } from './syntax-walk-errors.js';
|
|
14
|
+
/**
|
|
15
|
+
* Walks synchronously using the pinned upstream case ordering. Each accepted entry is followed by its
|
|
16
|
+
* children and a null exit. Returning false prunes the entry without an exit;
|
|
17
|
+
* boolean exit return values are ignored. Every callback must return a boolean
|
|
18
|
+
* synchronously; other results produce InputError. Callback exceptions retain their identity,
|
|
19
|
+
* and upstream deferred comment callbacks still run during exception unwinding.
|
|
20
|
+
*
|
|
21
|
+
* Children and later fields are read live. Each list captures its array reference
|
|
22
|
+
* and length when traversal reaches that list, then reads existing later slots
|
|
23
|
+
* when reached. Replacing or reordering later slots is observed and can cause
|
|
24
|
+
* a node to be skipped or revisited. Indices added beyond the captured extent
|
|
25
|
+
* are not visited by that active list. Replacing the owner's array field does not
|
|
26
|
+
* redirect an active list, but a later walk or print sees the current field.
|
|
27
|
+
* Changes made before a list is reached are observed when it starts.
|
|
28
|
+
*
|
|
29
|
+
* Supported edits preserve each node's Type (and TypedNil.Kind), required field
|
|
30
|
+
* shapes and every index within each active list's captured extent. Leaving
|
|
31
|
+
* holes or shrinking an array below that extent (for example through truncation,
|
|
32
|
+
* deletion, or length-reducing splice/shift) is outside the mutation contract.
|
|
33
|
+
* These are not runtime validation rules. Ordinary JavaScript object and array
|
|
34
|
+
* aliases remain shared; the binding does not model distinct Go slice headers or
|
|
35
|
+
* capacity-dependent allocation over shared backing storage.
|
|
36
|
+
*
|
|
37
|
+
* Comments on Stmt, CaseItem and ArrayElem are copied before their callbacks,
|
|
38
|
+
* including position and byte-string values; editing a copy does not edit the
|
|
39
|
+
* stored comment. Last/CondLast/ThenLast/DoLast callbacks receive the stored
|
|
40
|
+
* JavaScript Comment object. Replacing its array slot leaves any previously
|
|
41
|
+
* retained callback object unchanged: there is no Go value-slot pointer identity.
|
|
42
|
+
* Reentrant walks maintain independent traversal state.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare function walk(node: Node, callback: (node: Node | null) => boolean): void;
|
|
46
|
+
//# sourceMappingURL=syntax-walk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk.d.ts","sourceRoot":"","sources":["../src/syntax-walk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAIlE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAOzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,GAAG,IAAI,CAE/E"}
|