sh-ast 0.1.0 → 0.3.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/dist/analyze/enumerate-commands.d.ts +7 -1
- package/dist/analyze/enumerate-commands.d.ts.map +1 -1
- package/dist/analyze/enumerate-commands.js +7 -1
- package/dist/analyze/enumerate-commands.js.map +1 -1
- package/dist/analyze/index.d.ts +12 -4
- package/dist/analyze/index.d.ts.map +1 -1
- package/dist/analyze/index.js +18 -15
- package/dist/analyze/index.js.map +1 -1
- package/dist/analyze/resolve-argv0.d.ts +335 -0
- package/dist/analyze/resolve-argv0.d.ts.map +1 -0
- package/dist/analyze/resolve-argv0.js +510 -0
- package/dist/analyze/resolve-argv0.js.map +1 -0
- package/dist/analyze/resolve-word.d.ts +5 -0
- package/dist/analyze/resolve-word.d.ts.map +1 -1
- package/dist/analyze/resolve-word.js +5 -0
- package/dist/analyze/resolve-word.js.map +1 -1
- package/dist/analyze.d.ts +592 -211
- package/dist/errors.d.ts +81 -16
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +90 -17
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/parse-depth-guard.d.ts +11 -0
- package/dist/parse-depth-guard.d.ts.map +1 -0
- package/dist/parse-depth-guard.js +633 -0
- package/dist/parse-depth-guard.js.map +1 -0
- package/dist/parse.d.ts +7 -2
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +15 -8
- package/dist/parse.js.map +1 -1
- package/dist/sh-ast.d.ts +165 -45
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/wasm-instance.js +3 -3
- package/dist/wasm-instance.js.map +1 -1
- package/generated/node-types.d.ts +44 -0
- package/package.json +1 -1
package/dist/parse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG1E,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,EAAE,MAAM,YAAY,CAAC;AAcrE,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAoCD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAKxE;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAsCtE"}
|
package/dist/parse.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ShInternalError, ShInvalidDialectError, ShParseError } from './errors.js';
|
|
2
2
|
import { normalize, toUtf16Column } from './normalize.js';
|
|
3
|
+
import { assertParseDepthWithinLimit } from './parse-depth-guard.js';
|
|
3
4
|
import { callParse } from './wasm-instance.js';
|
|
4
5
|
/**
|
|
5
6
|
* The full set of dialects {@link parseSync} accepts, in the order surfaced
|
|
@@ -52,10 +53,10 @@ export function isResultEnvelope(value) {
|
|
|
52
53
|
}
|
|
53
54
|
function asShFile(node) {
|
|
54
55
|
if (node.type !== 'File') {
|
|
55
|
-
throw new
|
|
56
|
+
throw new ShInternalError(`bridge: expected root node of type "File", got "${node.type}"`);
|
|
56
57
|
}
|
|
57
58
|
if (!Array.isArray(node.stmts)) {
|
|
58
|
-
throw new
|
|
59
|
+
throw new ShInternalError('bridge: expected root node to have an array "stmts" field');
|
|
59
60
|
}
|
|
60
61
|
return node;
|
|
61
62
|
}
|
|
@@ -74,9 +75,14 @@ function asShFile(node) {
|
|
|
74
75
|
* position appears only inside `.message`, which is mvdan/sh's own
|
|
75
76
|
* formatted string, verbatim. Throws {@link ShInvalidDialectError} when
|
|
76
77
|
* {@link ParseOptions.dialect} is not a supported dialect. Throws
|
|
77
|
-
* {@link
|
|
78
|
+
* {@link ShInternalError} for failures that should never happen given
|
|
78
79
|
* a correctly-behaving shim (malformed envelope, unexpected root node
|
|
79
|
-
* type, shim contract violations).
|
|
80
|
+
* type, shim contract violations). Throws {@link ShParseMaxDepthError} if
|
|
81
|
+
* `text`'s conservatively estimated structural nesting depth exceeds the
|
|
82
|
+
* limit this bridge accepts — checked, and thrown, *before* `text` is ever
|
|
83
|
+
* handed to the WASM shim, since mvdan/sh's own parser has no recovery path
|
|
84
|
+
* for exhausting its stack on pathological nesting (see that error's doc
|
|
85
|
+
* comment and `parse-depth-guard.ts`).
|
|
80
86
|
*
|
|
81
87
|
* @public
|
|
82
88
|
*/
|
|
@@ -86,10 +92,11 @@ export function parseSync(text, options) {
|
|
|
86
92
|
if (!isSupportedShellDialect(dialect)) {
|
|
87
93
|
throw new ShInvalidDialectError(dialect, SUPPORTED_SHELL_DIALECTS);
|
|
88
94
|
}
|
|
95
|
+
assertParseDepthWithinLimit(text);
|
|
89
96
|
const raw = callParse(text, dialect, filename);
|
|
90
97
|
const result = JSON.parse(raw);
|
|
91
98
|
if (!isResultEnvelope(result)) {
|
|
92
|
-
throw new
|
|
99
|
+
throw new ShInternalError('bridge: WASM shim returned an unexpected payload shape');
|
|
93
100
|
}
|
|
94
101
|
if (result.parseError) {
|
|
95
102
|
// mvdan/sh reports `column` as a byte count on the source line, not a
|
|
@@ -108,10 +115,10 @@ export function parseSync(text, options) {
|
|
|
108
115
|
});
|
|
109
116
|
}
|
|
110
117
|
if (result.error) {
|
|
111
|
-
throw new
|
|
118
|
+
throw new ShInternalError(result.error.message);
|
|
112
119
|
}
|
|
113
120
|
if (result.file === undefined) {
|
|
114
|
-
throw new
|
|
121
|
+
throw new ShInternalError('bridge: WASM shim returned neither a file nor an error');
|
|
115
122
|
}
|
|
116
123
|
return asShFile(normalize(result.file, text));
|
|
117
124
|
}
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C;;;;;GAKG;AACH,MAAM,wBAAwB,GAA4B,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAEnG,SAAS,uBAAuB,CAAC,KAAa;IAC5C,OAAQ,wBAA8C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzE,CAAC;AAoBD;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,KAAK,CAAC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C,QAAQ;SACrC,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,IAAI,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,MAAM,IAAI,eAAe,CAAC,wDAAwD,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/sh-ast.d.ts
CHANGED
|
@@ -32,9 +32,14 @@ export declare interface ParseOptions {
|
|
|
32
32
|
* position appears only inside `.message`, which is mvdan/sh's own
|
|
33
33
|
* formatted string, verbatim. Throws {@link ShInvalidDialectError} when
|
|
34
34
|
* {@link ParseOptions.dialect} is not a supported dialect. Throws
|
|
35
|
-
* {@link
|
|
35
|
+
* {@link ShInternalError} for failures that should never happen given
|
|
36
36
|
* a correctly-behaving shim (malformed envelope, unexpected root node
|
|
37
|
-
* type, shim contract violations).
|
|
37
|
+
* type, shim contract violations). Throws {@link ShParseMaxDepthError} if
|
|
38
|
+
* `text`'s conservatively estimated structural nesting depth exceeds the
|
|
39
|
+
* limit this bridge accepts — checked, and thrown, *before* `text` is ever
|
|
40
|
+
* handed to the WASM shim, since mvdan/sh's own parser has no recovery path
|
|
41
|
+
* for exhausting its stack on pathological nesting (see that error's doc
|
|
42
|
+
* comment and `parse-depth-guard.ts`).
|
|
38
43
|
*
|
|
39
44
|
* @public
|
|
40
45
|
*/
|
|
@@ -51,6 +56,22 @@ export declare interface Position {
|
|
|
51
56
|
readonly column: number;
|
|
52
57
|
}
|
|
53
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Thrown by `sh-ast/analyze`'s `resolveArgv0` when a caller-supplied
|
|
61
|
+
* `options.transparentWrappers` array contains a malformed `WrapperSpec`
|
|
62
|
+
* entry — e.g. a non-array or empty `names`, or a flag field that isn't an
|
|
63
|
+
* array of strings. Fails closed with a clear, specific message at the
|
|
64
|
+
* point the malformed table is supplied, rather than letting the bad shape
|
|
65
|
+
* reach flag-matching logic and surface as a confusing native `TypeError`
|
|
66
|
+
* (or, worse, a silently wrong match) far from its actual cause.
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export declare class ShAnalyzeInvalidWrapperSpecError extends ShAstError {
|
|
71
|
+
readonly code = "SH_AST_ANALYZE_INVALID_WRAPPER_SPEC";
|
|
72
|
+
constructor(message: string);
|
|
73
|
+
}
|
|
74
|
+
|
|
54
75
|
/**
|
|
55
76
|
* Thrown by `sh-ast/analyze`'s `enumerateCommands` when a tree's genuinely
|
|
56
77
|
* nested structure — subshells within subshells, chained command/process
|
|
@@ -71,8 +92,8 @@ export declare interface Position {
|
|
|
71
92
|
*
|
|
72
93
|
* @public
|
|
73
94
|
*/
|
|
74
|
-
export declare class ShAnalyzeMaxDepthError extends
|
|
75
|
-
readonly code = "
|
|
95
|
+
export declare class ShAnalyzeMaxDepthError extends ShAstError {
|
|
96
|
+
readonly code = "SH_AST_ANALYZE_MAX_DEPTH";
|
|
76
97
|
/** The maximum nesting depth `enumerateCommands` supports; the same value every time (not caller-configurable). */
|
|
77
98
|
readonly maxDepth: number;
|
|
78
99
|
constructor(maxDepth: number);
|
|
@@ -144,6 +165,7 @@ declare interface ShArithmCmdNode {
|
|
|
144
165
|
readonly end: { readonly line: number; readonly column: number };
|
|
145
166
|
};
|
|
146
167
|
[field: string]: unknown;
|
|
168
|
+
readonly unsigned?: boolean;
|
|
147
169
|
readonly x?: ShArithmExprNode;
|
|
148
170
|
}
|
|
149
171
|
|
|
@@ -160,6 +182,8 @@ declare interface ShArithmExpNode {
|
|
|
160
182
|
readonly end: { readonly line: number; readonly column: number };
|
|
161
183
|
};
|
|
162
184
|
[field: string]: unknown;
|
|
185
|
+
readonly bracket?: boolean;
|
|
186
|
+
readonly unsigned?: boolean;
|
|
163
187
|
readonly x?: ShArithmExprNode;
|
|
164
188
|
}
|
|
165
189
|
|
|
@@ -220,12 +244,45 @@ declare interface ShAssignNode {
|
|
|
220
244
|
readonly end: { readonly line: number; readonly column: number };
|
|
221
245
|
};
|
|
222
246
|
[field: string]: unknown;
|
|
247
|
+
readonly append?: boolean;
|
|
223
248
|
readonly array?: ShArrayExprNode;
|
|
224
249
|
readonly index?: ShArithmExprNode;
|
|
250
|
+
readonly naked?: boolean;
|
|
225
251
|
readonly name?: ShLitNode;
|
|
226
252
|
readonly value?: ShWordNode;
|
|
227
253
|
}
|
|
228
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Common base class for every error this package throws — originally just
|
|
257
|
+
* {@link sh-ast#parseSync | parseSync}'s errors, now also the
|
|
258
|
+
* `sh-ast/analyze` layer's (see {@link ShAnalyzeMaxDepthError},
|
|
259
|
+
* {@link ShAnalyzeInvalidWrapperSpecError}). Provides a stable, documented
|
|
260
|
+
* `code` discriminator (e.g. `"SH_AST_PARSE_ERROR"`) alongside the usual
|
|
261
|
+
* `instanceof` narrowing, so consumers can branch on failure kind
|
|
262
|
+
* programmatically without parsing `.message` strings. Never thrown directly
|
|
263
|
+
* — only via its concrete subclasses
|
|
264
|
+
* ({@link sh-ast#ShParseError | ShParseError},
|
|
265
|
+
* {@link sh-ast#ShInvalidDialectError | ShInvalidDialectError},
|
|
266
|
+
* {@link sh-ast#ShInternalError | ShInternalError},
|
|
267
|
+
* {@link ShAnalyzeMaxDepthError},
|
|
268
|
+
* {@link sh-ast#ShParseMaxDepthError | ShParseMaxDepthError},
|
|
269
|
+
* {@link ShAnalyzeInvalidWrapperSpecError}).
|
|
270
|
+
*
|
|
271
|
+
* Re-exported from `sh-ast/analyze` as well as the root `sh-ast` entry
|
|
272
|
+
* point (see #23) — every subclass thrown by `sh-ast/analyze`'s own
|
|
273
|
+
* functions extends this, so a consumer of that subpath alone can
|
|
274
|
+
* `catch`/reference the base without also importing from root.
|
|
275
|
+
*
|
|
276
|
+
* @public
|
|
277
|
+
*/
|
|
278
|
+
export declare abstract class ShAstError extends Error {
|
|
279
|
+
/**
|
|
280
|
+
* Stable, machine-readable discriminator for this error kind. Distinct
|
|
281
|
+
* per subclass and will not change once published.
|
|
282
|
+
*/
|
|
283
|
+
abstract readonly code: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
229
286
|
/**
|
|
230
287
|
* mvdan/sh's `syntax.BinaryArithm`, normalized.
|
|
231
288
|
*
|
|
@@ -239,6 +296,7 @@ declare interface ShBinaryArithmNode {
|
|
|
239
296
|
readonly end: { readonly line: number; readonly column: number };
|
|
240
297
|
};
|
|
241
298
|
[field: string]: unknown;
|
|
299
|
+
readonly op?: number;
|
|
242
300
|
readonly x?: ShArithmExprNode;
|
|
243
301
|
readonly y?: ShArithmExprNode;
|
|
244
302
|
}
|
|
@@ -256,6 +314,7 @@ declare interface ShBinaryCmdNode {
|
|
|
256
314
|
readonly end: { readonly line: number; readonly column: number };
|
|
257
315
|
};
|
|
258
316
|
[field: string]: unknown;
|
|
317
|
+
readonly op?: number;
|
|
259
318
|
readonly x?: ShStmtNode;
|
|
260
319
|
readonly y?: ShStmtNode;
|
|
261
320
|
}
|
|
@@ -273,6 +332,7 @@ declare interface ShBinaryTestNode {
|
|
|
273
332
|
readonly end: { readonly line: number; readonly column: number };
|
|
274
333
|
};
|
|
275
334
|
[field: string]: unknown;
|
|
335
|
+
readonly op?: number;
|
|
276
336
|
readonly x?: ShTestExprNode;
|
|
277
337
|
readonly y?: ShTestExprNode;
|
|
278
338
|
}
|
|
@@ -308,42 +368,7 @@ declare interface ShBraceExpNode {
|
|
|
308
368
|
};
|
|
309
369
|
[field: string]: unknown;
|
|
310
370
|
readonly elems: readonly ShWordNode[];
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Common base class for every error this package throws — originally just
|
|
315
|
-
* {@link parseSync}'s errors, now also the `sh-ast/analyze` layer's (see
|
|
316
|
-
* {@link ShAnalyzeMaxDepthError}). Provides a stable, documented `code`
|
|
317
|
-
* discriminator (e.g. `"ESLINT_SH_PARSE_ERROR"`) alongside the usual
|
|
318
|
-
* `instanceof` narrowing, so consumers can branch on failure kind
|
|
319
|
-
* programmatically without parsing `.message` strings. Never thrown
|
|
320
|
-
* directly — only via its concrete subclasses ({@link ShParseError},
|
|
321
|
-
* {@link ShInvalidDialectError}, {@link ShBridgeInternalError},
|
|
322
|
-
* {@link ShAnalyzeMaxDepthError}).
|
|
323
|
-
*
|
|
324
|
-
* @public
|
|
325
|
-
*/
|
|
326
|
-
export declare abstract class ShBridgeError extends Error {
|
|
327
|
-
/**
|
|
328
|
-
* Stable, machine-readable discriminator for this error kind. Distinct
|
|
329
|
-
* per subclass and will not change once published.
|
|
330
|
-
*/
|
|
331
|
-
abstract readonly code: string;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Thrown by {@link parseSync} for failures that should never happen given a
|
|
336
|
-
* correctly-behaving WASM shim: a malformed result envelope, an unexpected
|
|
337
|
-
* root node type, or any other shim contract violation. Distinct from
|
|
338
|
-
* {@link ShInvalidDialectError} and {@link ShParseError}, both of which
|
|
339
|
-
* indicate a foreseeable, actionable user mistake rather than an internal
|
|
340
|
-
* defect.
|
|
341
|
-
*
|
|
342
|
-
* @public
|
|
343
|
-
*/
|
|
344
|
-
export declare class ShBridgeInternalError extends ShBridgeError {
|
|
345
|
-
readonly code = "ESLINT_SH_BRIDGE_INTERNAL";
|
|
346
|
-
constructor(message: string);
|
|
371
|
+
readonly sequence?: boolean;
|
|
347
372
|
}
|
|
348
373
|
|
|
349
374
|
/**
|
|
@@ -376,6 +401,7 @@ declare interface ShCaseClauseNode {
|
|
|
376
401
|
readonly end: { readonly line: number; readonly column: number };
|
|
377
402
|
};
|
|
378
403
|
[field: string]: unknown;
|
|
404
|
+
readonly braces?: boolean;
|
|
379
405
|
readonly items: readonly ShCaseItemNode[];
|
|
380
406
|
readonly last: readonly ShCommentNode[];
|
|
381
407
|
readonly word?: ShWordNode;
|
|
@@ -396,6 +422,7 @@ declare interface ShCaseItemNode {
|
|
|
396
422
|
[field: string]: unknown;
|
|
397
423
|
readonly comments: readonly ShCommentNode[];
|
|
398
424
|
readonly last: readonly ShCommentNode[];
|
|
425
|
+
readonly op?: number;
|
|
399
426
|
readonly patterns: readonly ShWordNode[];
|
|
400
427
|
readonly stmts: readonly ShStmtNode[];
|
|
401
428
|
}
|
|
@@ -413,8 +440,11 @@ declare interface ShCmdSubstNode {
|
|
|
413
440
|
readonly end: { readonly line: number; readonly column: number };
|
|
414
441
|
};
|
|
415
442
|
[field: string]: unknown;
|
|
443
|
+
readonly backquotes?: boolean;
|
|
416
444
|
readonly last: readonly ShCommentNode[];
|
|
445
|
+
readonly replyvar?: boolean;
|
|
417
446
|
readonly stmts: readonly ShStmtNode[];
|
|
447
|
+
readonly tempfile?: boolean;
|
|
418
448
|
}
|
|
419
449
|
|
|
420
450
|
/**
|
|
@@ -454,6 +484,7 @@ declare interface ShCommentNode {
|
|
|
454
484
|
readonly end: { readonly line: number; readonly column: number };
|
|
455
485
|
};
|
|
456
486
|
[field: string]: unknown;
|
|
487
|
+
readonly text?: string;
|
|
457
488
|
}
|
|
458
489
|
|
|
459
490
|
/**
|
|
@@ -504,6 +535,7 @@ declare interface ShDblQuotedNode {
|
|
|
504
535
|
readonly end: { readonly line: number; readonly column: number };
|
|
505
536
|
};
|
|
506
537
|
[field: string]: unknown;
|
|
538
|
+
readonly dollar?: boolean;
|
|
507
539
|
readonly parts: readonly ShWordPartNode[];
|
|
508
540
|
}
|
|
509
541
|
|
|
@@ -548,6 +580,7 @@ declare interface ShExpansionNode {
|
|
|
548
580
|
readonly end: { readonly line: number; readonly column: number };
|
|
549
581
|
};
|
|
550
582
|
[field: string]: unknown;
|
|
583
|
+
readonly op?: number;
|
|
551
584
|
readonly word?: ShWordNode;
|
|
552
585
|
}
|
|
553
586
|
|
|
@@ -564,6 +597,7 @@ declare interface ShExtGlobNode {
|
|
|
564
597
|
readonly end: { readonly line: number; readonly column: number };
|
|
565
598
|
};
|
|
566
599
|
[field: string]: unknown;
|
|
600
|
+
readonly op?: number;
|
|
567
601
|
readonly pattern?: ShLitNode;
|
|
568
602
|
}
|
|
569
603
|
|
|
@@ -591,6 +625,7 @@ declare interface ShFileNode {
|
|
|
591
625
|
};
|
|
592
626
|
[field: string]: unknown;
|
|
593
627
|
readonly last: readonly ShCommentNode[];
|
|
628
|
+
readonly name?: string;
|
|
594
629
|
readonly stmts: readonly ShStmtNode[];
|
|
595
630
|
}
|
|
596
631
|
|
|
@@ -624,9 +659,11 @@ declare interface ShForClauseNode {
|
|
|
624
659
|
readonly end: { readonly line: number; readonly column: number };
|
|
625
660
|
};
|
|
626
661
|
[field: string]: unknown;
|
|
662
|
+
readonly braces?: boolean;
|
|
627
663
|
readonly do: readonly ShStmtNode[];
|
|
628
664
|
readonly dolast: readonly ShCommentNode[];
|
|
629
665
|
readonly loop?: ShLoopNode;
|
|
666
|
+
readonly select?: boolean;
|
|
630
667
|
}
|
|
631
668
|
|
|
632
669
|
/**
|
|
@@ -645,6 +682,8 @@ declare interface ShFuncDeclNode {
|
|
|
645
682
|
readonly body?: ShStmtNode;
|
|
646
683
|
readonly name?: ShLitNode;
|
|
647
684
|
readonly names: readonly ShLitNode[];
|
|
685
|
+
readonly parens?: boolean;
|
|
686
|
+
readonly rsrvword?: boolean;
|
|
648
687
|
}
|
|
649
688
|
|
|
650
689
|
/**
|
|
@@ -668,6 +707,21 @@ declare interface ShIfClauseNode {
|
|
|
668
707
|
readonly thenlast: readonly ShCommentNode[];
|
|
669
708
|
}
|
|
670
709
|
|
|
710
|
+
/**
|
|
711
|
+
* Thrown by {@link parseSync} for failures that should never happen given a
|
|
712
|
+
* correctly-behaving WASM shim: a malformed result envelope, an unexpected
|
|
713
|
+
* root node type, or any other shim contract violation. Distinct from
|
|
714
|
+
* {@link ShInvalidDialectError} and {@link ShParseError}, both of which
|
|
715
|
+
* indicate a foreseeable, actionable user mistake rather than an internal
|
|
716
|
+
* defect.
|
|
717
|
+
*
|
|
718
|
+
* @public
|
|
719
|
+
*/
|
|
720
|
+
export declare class ShInternalError extends ShAstError {
|
|
721
|
+
readonly code = "SH_AST_INTERNAL";
|
|
722
|
+
constructor(message: string);
|
|
723
|
+
}
|
|
724
|
+
|
|
671
725
|
/**
|
|
672
726
|
* Thrown by {@link parseSync} when {@link ParseOptions.dialect} is not one
|
|
673
727
|
* of the supported {@link ShellDialect} values. Carries the rejected value
|
|
@@ -676,8 +730,8 @@ declare interface ShIfClauseNode {
|
|
|
676
730
|
*
|
|
677
731
|
* @public
|
|
678
732
|
*/
|
|
679
|
-
export declare class ShInvalidDialectError extends
|
|
680
|
-
readonly code = "
|
|
733
|
+
export declare class ShInvalidDialectError extends ShAstError {
|
|
734
|
+
readonly code = "SH_AST_INVALID_DIALECT";
|
|
681
735
|
/** The rejected dialect value, exactly as passed to {@link parseSync}. */
|
|
682
736
|
readonly dialect: string;
|
|
683
737
|
constructor(dialect: string, supportedDialects: readonly ShellDialect[]);
|
|
@@ -712,6 +766,7 @@ declare interface ShLitNode {
|
|
|
712
766
|
readonly end: { readonly line: number; readonly column: number };
|
|
713
767
|
};
|
|
714
768
|
[field: string]: unknown;
|
|
769
|
+
readonly value?: string;
|
|
715
770
|
}
|
|
716
771
|
|
|
717
772
|
/**
|
|
@@ -723,7 +778,7 @@ declare interface ShLitNode {
|
|
|
723
778
|
declare type ShLoopNode = ShCStyleLoopNode | ShWordIterNode;
|
|
724
779
|
|
|
725
780
|
/**
|
|
726
|
-
* A normalized AST node produced by {@link parseSync}.
|
|
781
|
+
* A normalized AST node produced by {@link sh-ast#parseSync | parseSync}.
|
|
727
782
|
*
|
|
728
783
|
* `range` and `loc` are expressed in UTF-16 code units, so
|
|
729
784
|
* `code.slice(node.range[0], node.range[1])` reproduces the node's exact
|
|
@@ -733,6 +788,10 @@ declare type ShLoopNode = ShCStyleLoopNode | ShWordIterNode;
|
|
|
733
788
|
* typedjson tree keeps its original value but with the field name
|
|
734
789
|
* lowercased (`Stmts` becomes `stmts`, `CondLast` becomes `condlast`, etc.).
|
|
735
790
|
*
|
|
791
|
+
* Also re-exported from `sh-ast/analyze` (see #23) — the subpath's public
|
|
792
|
+
* surface consumes and exposes `ShNode`, so a consumer can reference the type
|
|
793
|
+
* without also importing from the root `sh-ast` entry point.
|
|
794
|
+
*
|
|
736
795
|
* @public
|
|
737
796
|
*/
|
|
738
797
|
export declare interface ShNode {
|
|
@@ -869,14 +928,20 @@ declare interface ShParamExpNode {
|
|
|
869
928
|
readonly end: { readonly line: number; readonly column: number };
|
|
870
929
|
};
|
|
871
930
|
[field: string]: unknown;
|
|
931
|
+
readonly excl?: boolean;
|
|
872
932
|
readonly exp?: ShExpansionNode;
|
|
873
933
|
readonly flags?: ShLitNode;
|
|
874
934
|
readonly index?: ShArithmExprNode;
|
|
935
|
+
readonly isset?: boolean;
|
|
936
|
+
readonly length?: boolean;
|
|
875
937
|
readonly modifiers: readonly ShLitNode[];
|
|
938
|
+
readonly names?: number;
|
|
876
939
|
readonly nestedparam?: ShWordPartNode;
|
|
877
940
|
readonly param?: ShLitNode;
|
|
878
941
|
readonly repl?: ShReplaceNode;
|
|
942
|
+
readonly short?: boolean;
|
|
879
943
|
readonly slice?: ShSliceNode;
|
|
944
|
+
readonly width?: boolean;
|
|
880
945
|
}
|
|
881
946
|
|
|
882
947
|
/**
|
|
@@ -923,8 +988,8 @@ declare interface ShParenTestNode {
|
|
|
923
988
|
*
|
|
924
989
|
* @public
|
|
925
990
|
*/
|
|
926
|
-
export declare class ShParseError extends
|
|
927
|
-
readonly code = "
|
|
991
|
+
export declare class ShParseError extends ShAstError {
|
|
992
|
+
readonly code = "SH_AST_PARSE_ERROR";
|
|
928
993
|
readonly line: number;
|
|
929
994
|
readonly column: number;
|
|
930
995
|
readonly filename: string;
|
|
@@ -952,6 +1017,47 @@ export declare interface ShParseErrorInfo {
|
|
|
952
1017
|
filename: string;
|
|
953
1018
|
}
|
|
954
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* Thrown by {@link parseSync} when `text`'s conservatively estimated
|
|
1022
|
+
* structural nesting depth (subshells, command/process substitutions,
|
|
1023
|
+
* `if`/`case`/loop/function bodies, `{ }` blocks, backtick or `$(...)`
|
|
1024
|
+
* command substitution, `$((...))` arithmetic — see
|
|
1025
|
+
* `parse-depth-guard.ts`'s module doc for the exact heuristic) exceeds the
|
|
1026
|
+
* limit `parseSync` accepts. Thrown *before* `text` is ever handed to the
|
|
1027
|
+
* WASM shim: mvdan/sh's own recursive-descent parser has no recovery path
|
|
1028
|
+
* for exhausting its call stack on pathologically deep input (a stack
|
|
1029
|
+
* overflow deep inside the shared WASM instance is not a normal, catchable
|
|
1030
|
+
* JS error the way a parse syntax error is), so this bridge estimates the
|
|
1031
|
+
* risk up front and fails closed with a typed error instead of ever making
|
|
1032
|
+
* that call — the shared WASM instance is therefore never put at risk of
|
|
1033
|
+
* wedging on this class of input; a `parseSync` call right after catching
|
|
1034
|
+
* this error works exactly as it would if this input had never been
|
|
1035
|
+
* attempted.
|
|
1036
|
+
*
|
|
1037
|
+
* Like {@link ShAnalyzeMaxDepthError}, this is pathological-input
|
|
1038
|
+
* protection, not a normal-usage ceiling: a legitimately deep (but
|
|
1039
|
+
* realistic) script parses fine. The estimate can *over*-count relative to
|
|
1040
|
+
* mvdan/sh's real grammar (rejecting some legitimate-but-unusually-deep
|
|
1041
|
+
* input) but is designed to never *under*-count relative to it — see
|
|
1042
|
+
* `parse-depth-guard.ts` for the documented false-positive sources this
|
|
1043
|
+
* trades off against ever letting a genuinely crash-inducing input
|
|
1044
|
+
* through.
|
|
1045
|
+
*
|
|
1046
|
+
* @public
|
|
1047
|
+
*/
|
|
1048
|
+
export declare class ShParseMaxDepthError extends ShAstError {
|
|
1049
|
+
readonly code = "SH_AST_PARSE_MAX_DEPTH";
|
|
1050
|
+
/** The maximum structural nesting depth `parseSync` accepts; the same value every time (not caller-configurable). */
|
|
1051
|
+
readonly maxDepth: number;
|
|
1052
|
+
/**
|
|
1053
|
+
* The conservatively estimated nesting depth that tripped the guard.
|
|
1054
|
+
* Not necessarily `text`'s "true" nesting depth under a real parse — see
|
|
1055
|
+
* {@link ShParseMaxDepthError}'s doc comment — only ever `> maxDepth`.
|
|
1056
|
+
*/
|
|
1057
|
+
readonly estimatedDepth: number;
|
|
1058
|
+
constructor(maxDepth: number, estimatedDepth: number);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
955
1061
|
/**
|
|
956
1062
|
* mvdan/sh's `syntax.ProcSubst`, normalized.
|
|
957
1063
|
*
|
|
@@ -966,6 +1072,7 @@ declare interface ShProcSubstNode {
|
|
|
966
1072
|
};
|
|
967
1073
|
[field: string]: unknown;
|
|
968
1074
|
readonly last: readonly ShCommentNode[];
|
|
1075
|
+
readonly op?: number;
|
|
969
1076
|
readonly stmts: readonly ShStmtNode[];
|
|
970
1077
|
}
|
|
971
1078
|
|
|
@@ -984,6 +1091,7 @@ declare interface ShRedirectNode {
|
|
|
984
1091
|
[field: string]: unknown;
|
|
985
1092
|
readonly hdoc?: ShWordNode;
|
|
986
1093
|
readonly n?: ShLitNode;
|
|
1094
|
+
readonly op?: number;
|
|
987
1095
|
readonly word?: ShWordNode;
|
|
988
1096
|
}
|
|
989
1097
|
|
|
@@ -1000,6 +1108,7 @@ declare interface ShReplaceNode {
|
|
|
1000
1108
|
readonly end: { readonly line: number; readonly column: number };
|
|
1001
1109
|
};
|
|
1002
1110
|
[field: string]: unknown;
|
|
1111
|
+
readonly all?: boolean;
|
|
1003
1112
|
readonly orig?: ShWordNode;
|
|
1004
1113
|
readonly with?: ShWordNode;
|
|
1005
1114
|
}
|
|
@@ -1017,6 +1126,8 @@ declare interface ShSglQuotedNode {
|
|
|
1017
1126
|
readonly end: { readonly line: number; readonly column: number };
|
|
1018
1127
|
};
|
|
1019
1128
|
[field: string]: unknown;
|
|
1129
|
+
readonly dollar?: boolean;
|
|
1130
|
+
readonly value?: string;
|
|
1020
1131
|
}
|
|
1021
1132
|
|
|
1022
1133
|
/**
|
|
@@ -1049,8 +1160,12 @@ declare interface ShStmtNode {
|
|
|
1049
1160
|
readonly end: { readonly line: number; readonly column: number };
|
|
1050
1161
|
};
|
|
1051
1162
|
[field: string]: unknown;
|
|
1163
|
+
readonly background?: boolean;
|
|
1052
1164
|
readonly cmd?: ShCommandNode;
|
|
1053
1165
|
readonly comments: readonly ShCommentNode[];
|
|
1166
|
+
readonly coprocess?: boolean;
|
|
1167
|
+
readonly disown?: boolean;
|
|
1168
|
+
readonly negated?: boolean;
|
|
1054
1169
|
readonly redirs: readonly ShRedirectNode[];
|
|
1055
1170
|
}
|
|
1056
1171
|
|
|
@@ -1125,6 +1240,7 @@ declare interface ShTimeClauseNode {
|
|
|
1125
1240
|
readonly end: { readonly line: number; readonly column: number };
|
|
1126
1241
|
};
|
|
1127
1242
|
[field: string]: unknown;
|
|
1243
|
+
readonly posixformat?: boolean;
|
|
1128
1244
|
readonly stmt?: ShStmtNode;
|
|
1129
1245
|
}
|
|
1130
1246
|
|
|
@@ -1141,6 +1257,8 @@ declare interface ShUnaryArithmNode {
|
|
|
1141
1257
|
readonly end: { readonly line: number; readonly column: number };
|
|
1142
1258
|
};
|
|
1143
1259
|
[field: string]: unknown;
|
|
1260
|
+
readonly op?: number;
|
|
1261
|
+
readonly post?: boolean;
|
|
1144
1262
|
readonly x?: ShArithmExprNode;
|
|
1145
1263
|
}
|
|
1146
1264
|
|
|
@@ -1157,6 +1275,7 @@ declare interface ShUnaryTestNode {
|
|
|
1157
1275
|
readonly end: { readonly line: number; readonly column: number };
|
|
1158
1276
|
};
|
|
1159
1277
|
[field: string]: unknown;
|
|
1278
|
+
readonly op?: number;
|
|
1160
1279
|
readonly x?: ShTestExprNode;
|
|
1161
1280
|
}
|
|
1162
1281
|
|
|
@@ -1177,6 +1296,7 @@ declare interface ShWhileClauseNode {
|
|
|
1177
1296
|
readonly condlast: readonly ShCommentNode[];
|
|
1178
1297
|
readonly do: readonly ShStmtNode[];
|
|
1179
1298
|
readonly dolast: readonly ShCommentNode[];
|
|
1299
|
+
readonly until?: boolean;
|
|
1180
1300
|
}
|
|
1181
1301
|
|
|
1182
1302
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface Position {
|
|
|
37
37
|
readonly column: number;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* A normalized AST node produced by {@link parseSync}.
|
|
40
|
+
* A normalized AST node produced by {@link sh-ast#parseSync | parseSync}.
|
|
41
41
|
*
|
|
42
42
|
* `range` and `loc` are expressed in UTF-16 code units, so
|
|
43
43
|
* `code.slice(node.range[0], node.range[1])` reproduces the node's exact
|
|
@@ -47,6 +47,10 @@ export interface Position {
|
|
|
47
47
|
* typedjson tree keeps its original value but with the field name
|
|
48
48
|
* lowercased (`Stmts` becomes `stmts`, `CondLast` becomes `condlast`, etc.).
|
|
49
49
|
*
|
|
50
|
+
* Also re-exported from `sh-ast/analyze` (see #23) — the subpath's public
|
|
51
|
+
* surface consumes and exposes `ShNode`, so a consumer can reference the type
|
|
52
|
+
* without also importing from the root `sh-ast` entry point.
|
|
53
|
+
*
|
|
50
54
|
* @public
|
|
51
55
|
*/
|
|
52
56
|
export interface ShNode {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAEtE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;AAEtE;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;IAEhC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,GAAG,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAA;KAAE,CAAC;IACnE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,MAAO,SAAQ,MAAM;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC"}
|
package/dist/wasm-instance.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import '../shim/wasm_exec.js';
|
|
5
|
-
import {
|
|
5
|
+
import { ShInternalError } from './errors.js';
|
|
6
6
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
// `shim/` is a sibling of both `src/` (test-time) and `dist/` (build-time).
|
|
8
8
|
const wasmPath = path.join(here, '..', 'shim', 'sh-ast.wasm');
|
|
@@ -30,7 +30,7 @@ function ensureInstance() {
|
|
|
30
30
|
const instance = new WebAssembly.Instance(wasmModule, go.importObject);
|
|
31
31
|
void go.run(instance);
|
|
32
32
|
if (!isShimExports(instance.exports)) {
|
|
33
|
-
throw new
|
|
33
|
+
throw new ShInternalError('bridge: WASM shim did not export the expected alloc/process/free/mem linear-memory ABI');
|
|
34
34
|
}
|
|
35
35
|
shimExports = instance.exports;
|
|
36
36
|
return shimExports;
|
|
@@ -72,7 +72,7 @@ export function callParse(text, dialect, filename) {
|
|
|
72
72
|
exports.free(d.ptr);
|
|
73
73
|
exports.free(f.ptr);
|
|
74
74
|
if (resultPtr === 0) {
|
|
75
|
-
throw new
|
|
75
|
+
throw new ShInternalError('bridge: WASM shim returned a null result pointer');
|
|
76
76
|
}
|
|
77
77
|
// Re-read `mem.buffer` fresh (see `writeString`'s comment) and scan for the
|
|
78
78
|
// shim's NUL sentinel — valid JSON from Go's encoding/json never contains
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-instance.js","sourceRoot":"","sources":["../src/wasm-instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,sBAAsB,CAAC;AAM9B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"wasm-instance.js","sourceRoot":"","sources":["../src/wasm-instance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO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