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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { observeBraces } from './brace-observation.js';
|
|
1
2
|
import { decodeAnsiCString } from './ansi-c-escapes.js';
|
|
2
3
|
import { decodeDblQuotedLit, decodeUnquotedLit } from './decode-lit.js';
|
|
3
4
|
import { nodeArray } from './node-helpers.js';
|
|
@@ -148,8 +149,7 @@ function resolvePart(part, quoting) {
|
|
|
148
149
|
case 'ExtGlob':
|
|
149
150
|
return { ok: false, reason: 'glob' };
|
|
150
151
|
case 'BraceExp':
|
|
151
|
-
//
|
|
152
|
-
// bridge's parser today, handled for forward-compatibility.
|
|
152
|
+
// Caller-constructed or transformed records can already contain braces.
|
|
153
153
|
return { ok: false, reason: 'brace' };
|
|
154
154
|
default:
|
|
155
155
|
// Any word-part node type this module doesn't specifically know
|
|
@@ -171,7 +171,7 @@ function resolvePart(part, quoting) {
|
|
|
171
171
|
* resolves to `"rm"`). A word containing any expansion (`ParamExp`,
|
|
172
172
|
* `CmdSubst`, `ArithmExp`, `ProcSubst`), a triggering unquoted `~` (see
|
|
173
173
|
* `options.context`), an unquoted glob metacharacter/bracket
|
|
174
|
-
* expression/`ExtGlob`, a `$"..."` locale translation, or an unrepresentable
|
|
174
|
+
* expression/`ExtGlob`, potential brace expansion, a `$"..."` locale translation, or an unrepresentable
|
|
175
175
|
* `$'\U...'` escape is `static: false` with a reason — never an error, and
|
|
176
176
|
* never a safety judgment (see {@link WordResolution}).
|
|
177
177
|
*
|
|
@@ -198,6 +198,11 @@ export function resolveWord(word, options) {
|
|
|
198
198
|
if (parts.length === 0) {
|
|
199
199
|
return { static: true, text: '' };
|
|
200
200
|
}
|
|
201
|
+
const braces = observeBraces(word);
|
|
202
|
+
if (braces === 'unsupported')
|
|
203
|
+
return { static: false, reason: 'unsupported' };
|
|
204
|
+
if (braces)
|
|
205
|
+
return { static: false, reason: 'brace' };
|
|
201
206
|
// `parts.length === 0` returned above, so `parts[0]` is a real element.
|
|
202
207
|
const first = parts[0];
|
|
203
208
|
if (first.Type === 'Lit' &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-word.js","sourceRoot":"","sources":["../../src/analyze/resolve-word.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve-word.js","sourceRoot":"","sources":["../../src/analyze/resolve-word.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAsJ9C;;;;;;;;;GASG;AACH,SAAS,wBAAwB,CAAC,GAAW;IAC3C,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,qBAAqB,CAAC,KAAsB;IACnD,IAAI,qBAAqB,GAAG,KAAK,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACxB,qBAAqB,GAAG,KAAK,CAAC;YAC9B,SAAS;QACX,CAAC;QACD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AAE,OAAO,EAAE,CAAC;IACtD,wEAAwE;IACxE,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,IACE,KAAK,CAAC,IAAI,KAAK,KAAK;QACpB,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC/B,wBAAwB,CAAC,KAAK,CAAC,KAAK,CAAC,EACrC,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC5C,CAAC;IACD,IAAI,OAAO,EAAE,OAAO,KAAK,kBAAkB,IAAI,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC5C,CAAC;IACD,IAAI,4BAA4B,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC3C,CAAC;IACD,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QAClD,CAAC;QACD,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC;IACtB,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC"}
|
package/dist/analyze.d.ts
CHANGED
|
@@ -195,6 +195,11 @@ export declare interface Argv0Resolution {
|
|
|
195
195
|
* the real command rather than naming it as a separate word (e.g.
|
|
196
196
|
* `env -S 'rm -rf /'` — see {@link WrapperSpec.unresolvableFlags}'s doc
|
|
197
197
|
* comment).
|
|
198
|
+
* - `'ambiguous-assignment'` — a statically known assignment operand whose
|
|
199
|
+
* acceptance differs across supported utility implementations, such as
|
|
200
|
+
* `env =value cmd` (GNU/glibc accepts an empty name; BSD rejects it).
|
|
201
|
+
* Neither the following command nor the operand itself is guessed as
|
|
202
|
+
* the effective command.
|
|
198
203
|
*
|
|
199
204
|
* This union may grow in a **minor** release (mirroring
|
|
200
205
|
* `WordResolutionReason`'s and `CommandContext`'s semver policy in
|
|
@@ -204,7 +209,7 @@ export declare interface Argv0Resolution {
|
|
|
204
209
|
*
|
|
205
210
|
* @public
|
|
206
211
|
*/
|
|
207
|
-
export declare type Argv0UnresolvedReason = 'unknown-flag' | 'embedded-command';
|
|
212
|
+
export declare type Argv0UnresolvedReason = 'unknown-flag' | 'embedded-command' | 'ambiguous-assignment';
|
|
208
213
|
|
|
209
214
|
/**
|
|
210
215
|
* A word position {@link resolveArgv0} could not resolve to either a known
|
|
@@ -2747,7 +2752,7 @@ declare const DplOut: 68;
|
|
|
2747
2752
|
* resolves to `"rm"`). A word containing any expansion (`ParamExp`,
|
|
2748
2753
|
* `CmdSubst`, `ArithmExp`, `ProcSubst`), a triggering unquoted `~` (see
|
|
2749
2754
|
* `options.context`), an unquoted glob metacharacter/bracket
|
|
2750
|
-
* expression/`ExtGlob`, a `$"..."` locale translation, or an unrepresentable
|
|
2755
|
+
* expression/`ExtGlob`, potential brace expansion, a `$"..."` locale translation, or an unrepresentable
|
|
2751
2756
|
* `$'\U...'` escape is `static: false` with a reason — never an error, and
|
|
2752
2757
|
* never a safety judgment (see {@link WordResolution}).
|
|
2753
2758
|
*
|
|
@@ -3929,7 +3934,7 @@ declare const DplOut: 68;
|
|
|
3929
3934
|
/** The word's exact resolved text (quotes and escapes removed). */
|
|
3930
3935
|
readonly text: string;
|
|
3931
3936
|
} | {
|
|
3932
|
-
/** The word
|
|
3937
|
+
/** The word has potential expansion or cannot be resolved reliably by this analyzer. */
|
|
3933
3938
|
readonly static: false;
|
|
3934
3939
|
/** Why this word cannot be statically resolved. */
|
|
3935
3940
|
readonly reason: WordResolutionReason;
|
|
@@ -3937,7 +3942,7 @@ declare const DplOut: 68;
|
|
|
3937
3942
|
|
|
3938
3943
|
/**
|
|
3939
3944
|
* Why a {@link resolveWord} result is `static: false`: the word's exact
|
|
3940
|
-
*
|
|
3945
|
+
* value cannot be classified as one reliably known literal word.
|
|
3941
3946
|
*
|
|
3942
3947
|
* - `'expansion'` — the word contains a `ParamExp` (`$x`, `${x}`), a
|
|
3943
3948
|
* `CmdSubst` (command substitution, either `$(...)` or backtick form), an
|
|
@@ -3959,15 +3964,12 @@ declare const DplOut: 68;
|
|
|
3959
3964
|
* Reference Manual §3.5.8.1, "Pattern Matching"), or an `ExtGlob` part
|
|
3960
3965
|
* (Bash Reference Manual §3.5.8, "Filename Expansion"): its value depends
|
|
3961
3966
|
* on which filesystem entries exist at run time.
|
|
3962
|
-
* - `'brace'` — the word contains a `BraceExp` part
|
|
3963
|
-
*
|
|
3964
|
-
*
|
|
3965
|
-
*
|
|
3966
|
-
*
|
|
3967
|
-
*
|
|
3968
|
-
* from literal `{`/`,`/`}` characters) rather than as a `BraceExp` part.
|
|
3969
|
-
* This reason is handled here for forward-compatibility with that node
|
|
3970
|
-
* type and is not reachable through {@link resolveWord} today.
|
|
3967
|
+
* - `'brace'` — the word contains a `BraceExp` part or the pinned upstream
|
|
3968
|
+
* `syntax.SplitBraces` produces one on a private observation copy (Bash
|
|
3969
|
+
* Reference Manual §3.5.1, "Brace Expansion"). Parser output is unchanged.
|
|
3970
|
+
* This reports potential expansion in supporting dialects; a bare Word has
|
|
3971
|
+
* no dialect or shell-option state, so even POSIX-parsed words receive the
|
|
3972
|
+
* conservative classification. It does not claim POSIX sh expands braces.
|
|
3971
3973
|
* - `'locale'` — the word contains a `$"..."` locale-translated string
|
|
3972
3974
|
* (Bash Reference Manual §3.1.2.5, "Locale-Specific Translation"): its
|
|
3973
3975
|
* value is looked up in the current locale's translation catalog at run
|
|
@@ -3976,7 +3978,10 @@ declare const DplOut: 68;
|
|
|
3976
3978
|
* `$"..."` word's *contents* would otherwise report — the `DblQuoted`
|
|
3977
3979
|
* node's own `dollar` flag is checked before its children are visited at
|
|
3978
3980
|
* all, so e.g. `$"hi $x"` reports `'locale'`, never `'expansion'`.
|
|
3979
|
-
* - `'unsupported'` — a
|
|
3981
|
+
* - `'unsupported'` — a brace candidate contains backslashes whose handling
|
|
3982
|
+
* differs between pinned mvdan/sh and Bash (rather than guessing through
|
|
3983
|
+
* that discrepancy), an unquoted backslash escape crosses word-part
|
|
3984
|
+
* boundaries in a caller-constructed word, a word contains a nil or typed nil part, a literal carries a byte-preserving `Uint8Array`
|
|
3980
3985
|
* rather than Unicode text, or the word contains a `$'...'` (ANSI-C quoted) `\u`/`\U`
|
|
3981
3986
|
* escape whose value has no corresponding Unicode character (greater than
|
|
3982
3987
|
* `U+10FFFF`, e.g. `$'\UFFFFFFFF'`): real bash's output for this case is
|
|
@@ -3986,6 +3991,14 @@ declare const DplOut: 68;
|
|
|
3986
3991
|
* package declines to claim a `static: true` text bash never actually
|
|
3987
3992
|
* produces.
|
|
3988
3993
|
*
|
|
3994
|
+
* Reason descriptions do not establish universal precedence among features.
|
|
3995
|
+
* Whole-word `unsupported` preflight takes precedence even when a caller has
|
|
3996
|
+
* already supplied a `BraceExp`: an escape crossing parts can invalidate the
|
|
3997
|
+
* apparent quoting boundaries, and an escape-uncertain brace candidate remains
|
|
3998
|
+
* uncertain. Independently quoted or fully protected literal siblings do not
|
|
3999
|
+
* suppress a known `BraceExp`. After preflight, existing resolution order can
|
|
4000
|
+
* select a triggering tilde or earlier glob before visiting that part.
|
|
4001
|
+
*
|
|
3989
4002
|
* This union may grow in a **minor** release — new mvdan/sh word-part node
|
|
3990
4003
|
* types, or new statically-shaped-but-dynamic categories, can add new reason
|
|
3991
4004
|
* strings without that being a breaking change. It is deliberately not
|
|
@@ -4044,15 +4057,34 @@ declare const DplOut: 68;
|
|
|
4044
4057
|
*/
|
|
4045
4058
|
readonly names: readonly string[];
|
|
4046
4059
|
/**
|
|
4047
|
-
*
|
|
4048
|
-
*
|
|
4049
|
-
*
|
|
4050
|
-
*
|
|
4051
|
-
*
|
|
4052
|
-
*
|
|
4053
|
-
* counts.
|
|
4060
|
+
* Legacy shorthand for {@link WrapperSpec.assignmentOperands}'s
|
|
4061
|
+
* `'shell-identifier'` grammar: skip statically resolved `NAME=value`
|
|
4062
|
+
* words with an ASCII shell identifier before `--`. Options may follow
|
|
4063
|
+
* these operands. Quote removal has already happened during word resolution.
|
|
4064
|
+
* An explicit `assignmentOperands` takes precedence, even when this is false.
|
|
4065
|
+
* These operands never contribute to shell-prefix `assignmentsSkipped`.
|
|
4054
4066
|
*/
|
|
4055
4067
|
readonly skipAssignmentOperands?: boolean;
|
|
4068
|
+
/**
|
|
4069
|
+
* Assignment-operand scanning grammar, independent of the wrapper's name.
|
|
4070
|
+
* Each preset defines both which static words are assignments and where
|
|
4071
|
+
* option scanning stops; it does not model the utility's other options.
|
|
4072
|
+
*
|
|
4073
|
+
* - `'shell-identifier'`: the legacy ASCII `NAME=value` rule before `--`;
|
|
4074
|
+
* options may resume after an assignment.
|
|
4075
|
+
* - `'env'`: after options, consume words containing `=` (including after
|
|
4076
|
+
* `--`). The first assignment ends option scanning permanently. Empty
|
|
4077
|
+
* names (`=value`) produce `'ambiguous-assignment'` because GNU/glibc
|
|
4078
|
+
* and BSD differ on whether they can be installed in the environment.
|
|
4079
|
+
* - `'sudo'`: before `--`, consume words containing `=` unless they start
|
|
4080
|
+
* with `/` or `=`; option scanning may resume after each assignment.
|
|
4081
|
+
*
|
|
4082
|
+
* Active option parsing always takes precedence over utility assignments:
|
|
4083
|
+
* `--unset=NAME` is an option, whereas `env A=1 --unset=NAME cmd` treats
|
|
4084
|
+
* that same word as an assignment. This field overrides the legacy
|
|
4085
|
+
* {@link WrapperSpec.skipAssignmentOperands} boolean when present.
|
|
4086
|
+
*/
|
|
4087
|
+
readonly assignmentOperands?: 'shell-identifier' | 'env' | 'sudo';
|
|
4056
4088
|
/** Exact flag tokens that take no operand of their own (e.g. `-i`, `-c`). */
|
|
4057
4089
|
readonly noArgFlags?: readonly string[];
|
|
4058
4090
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { InputError, LangError, ParseError, newPos, nodeEnd, nodePos, parseSync, parseWithPositionsSync, rawOperator, } from './syntax.js';
|
|
2
2
|
export type { ParseOptions, ParsedFile, PositionSnapshot, NodePositions } from './syntax.js';
|
|
3
|
+
export { printSync } from './syntax-print.js';
|
|
4
|
+
export type { PrintOptions } from './syntax-print.js';
|
|
5
|
+
export { PrintError, PrintPanicError } from './syntax-print-errors.js';
|
|
6
|
+
export { walk, WalkPanicError } from './syntax-walk.js';
|
|
3
7
|
export type * from '../generated/syntax-types.js';
|
|
4
8
|
export * from '../generated/syntax-constants.js';
|
|
5
9
|
export type { SyntaxFieldSchema, SyntaxRecordSchema } from '../generated/syntax-schema.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7F,mBAAmB,8BAA8B,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EACL,gCAAgC,EAChC,sBAAsB,EACtB,UAAU,EACV,eAAe,EACf,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,eAAO,MAAM,aAAa,gGAAqB,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,uDAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACxD,mBAAmB,8BAA8B,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EACL,gCAAgC,EAChC,sBAAsB,EACtB,UAAU,EACV,eAAe,EACf,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,eAAO,MAAM,aAAa,gGAAqB,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,uDAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A faithful synchronous interface to mvdan/sh syntax. The root exposes upstream
|
|
3
|
-
* records, constants, parser controls and position operations. Consumer-specific
|
|
3
|
+
* records, constants, parser controls, traversal, printing and position operations. Consumer-specific
|
|
4
4
|
* source views and semantic analysis are separate responsibilities.
|
|
5
5
|
*/
|
|
6
6
|
import { SYNTAX_INTERFACES as interfaces, SYNTAX_SCHEMA as schema, } from '../generated/syntax-schema.js';
|
|
7
7
|
import { deepFreeze } from './deep-freeze.js';
|
|
8
8
|
export { InputError, LangError, ParseError, newPos, nodeEnd, nodePos, parseSync, parseWithPositionsSync, rawOperator, } from './syntax.js';
|
|
9
|
+
export { printSync } from './syntax-print.js';
|
|
10
|
+
export { PrintError, PrintPanicError } from './syntax-print-errors.js';
|
|
11
|
+
export { walk, WalkPanicError } from './syntax-walk.js';
|
|
9
12
|
export * from '../generated/syntax-constants.js';
|
|
10
13
|
export { ShAnalyzeInvalidWrapperSpecError, ShAnalyzeMaxDepthError, ShAstError, ShInternalError, ShParseMaxDepthError, } from './errors.js';
|
|
11
14
|
/**
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,iBAAiB,IAAI,UAAU,EAC/B,aAAa,IAAI,MAAM,GACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,iBAAiB,IAAI,UAAU,EAC/B,aAAa,IAAI,MAAM,GACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAExD,cAAc,kCAAkC,CAAC;AAEjD,OAAO,EACL,gCAAgC,EAChC,sBAAsB,EACtB,UAAU,EACV,eAAe,EACf,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/sh-ast.d.ts
CHANGED
|
@@ -2338,6 +2338,79 @@ export declare const Pow: 44;
|
|
|
2338
2338
|
*/
|
|
2339
2339
|
export declare const PowAssgn: 62;
|
|
2340
2340
|
|
|
2341
|
+
/**
|
|
2342
|
+
* An error returned by upstream Printer.Print, such as an unsupported root or
|
|
2343
|
+
* incompatible formatting options. No partial writer output is exposed.
|
|
2344
|
+
* @public
|
|
2345
|
+
*/
|
|
2346
|
+
export declare class PrintError extends ShAstError {
|
|
2347
|
+
/** Stable identity for an ordinary error returned by upstream Print. @public */
|
|
2348
|
+
readonly code = "SH_AST_SYNTAX_PRINT";
|
|
2349
|
+
/** Exact upstream error bytes; Error.message is only a display rendering. @public */
|
|
2350
|
+
readonly Message: GoString;
|
|
2351
|
+
/** Retains the upstream error without interpreting its human-readable text. @public */
|
|
2352
|
+
constructor(message: GoString);
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
/**
|
|
2356
|
+
* Upstream NewPrinter controls applied to a fresh printer for each call. All
|
|
2357
|
+
* flags default to false; zero indentation selects tabs. The pinned WASM uint
|
|
2358
|
+
* domain is 64-bit, so Indent accepts bigint beyond JavaScript's safe integers.
|
|
2359
|
+
* @public
|
|
2360
|
+
*/
|
|
2361
|
+
export declare interface PrintOptions {
|
|
2362
|
+
/** Spaces per level, or zero for tabs. Large values can request expensive output. */
|
|
2363
|
+
Indent?: number | bigint;
|
|
2364
|
+
/** Places multiline binary operators on the next line with a backslash continuation. */
|
|
2365
|
+
BinaryNextLine?: boolean;
|
|
2366
|
+
/** Indents case alternatives, placing their bodies two levels below the case clause. */
|
|
2367
|
+
SwitchCaseIndent?: boolean;
|
|
2368
|
+
/** Adds space after redirection operators except `>&`, `<&`, `>(` and `<(`. */
|
|
2369
|
+
SpaceRedirects?: boolean;
|
|
2370
|
+
/**
|
|
2371
|
+
* Preserves token columns on a best-effort basis.
|
|
2372
|
+
* @deprecated Upstream marks this option as flawed and plans removal in v4.
|
|
2373
|
+
*/
|
|
2374
|
+
KeepPadding?: boolean;
|
|
2375
|
+
/** Omits comments, indentation and optional whitespace. Incompatible with SingleLine. */
|
|
2376
|
+
Minify?: boolean;
|
|
2377
|
+
/** Reduces newlines except where comments, heredocs or File output require them. */
|
|
2378
|
+
SingleLine?: boolean;
|
|
2379
|
+
/** Places a function's opening brace on the next line. */
|
|
2380
|
+
FunctionNextLine?: boolean;
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
/**
|
|
2384
|
+
* Upstream Printer.Print panicked for a representable tree or option value.
|
|
2385
|
+
* Partial and typed-nil trees can trigger this independently of root support.
|
|
2386
|
+
* Catching the panic preserves reuse of the binding's shared runtime.
|
|
2387
|
+
* @public
|
|
2388
|
+
*/
|
|
2389
|
+
export declare class PrintPanicError extends ShAstError {
|
|
2390
|
+
/** Stable identity for an upstream panic caught at the Print operation. @public */
|
|
2391
|
+
readonly code = "SH_AST_SYNTAX_PRINT_PANIC";
|
|
2392
|
+
/** Exact panic rendering from Go; Error.message is only a display rendering. @public */
|
|
2393
|
+
readonly Message: GoString;
|
|
2394
|
+
/** Retains the panic message separately from ordinary returned Print errors. @public */
|
|
2395
|
+
constructor(message: GoString);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
/**
|
|
2399
|
+
* Formats the current tree with a fresh upstream printer and collects all output.
|
|
2400
|
+
* Supported roots are File, Stmt, Word, Assign, Command and WordPart; other Nodes
|
|
2401
|
+
* produce PrintError. Only File output has upstream's trailing-newline behavior.
|
|
2402
|
+
* Invalid UTF-8 output remains bytes. Upstream formatting can itself consume
|
|
2403
|
+
* input bytes, including its tabwriter escape byte, so this is not source replay.
|
|
2404
|
+
*
|
|
2405
|
+
* InputError identifies unrepresentable input; PrintError is an ordinary returned
|
|
2406
|
+
* upstream error; PrintPanicError retains an upstream operation panic. No partial
|
|
2407
|
+
* output or arbitrary writer lifecycle is exposed. Full tree reconstruction and
|
|
2408
|
+
* collected output require memory proportional to the values involved; extreme
|
|
2409
|
+
* indentation or tree size is not made resource-safe by panic adaptation.
|
|
2410
|
+
* @public
|
|
2411
|
+
*/
|
|
2412
|
+
export declare function printSync(node: Node_2, options?: PrintOptions): GoString;
|
|
2413
|
+
|
|
2341
2414
|
/**
|
|
2342
2415
|
* The upstream ProcOperator domain: exact named tokens, the Go zero value, and explicitly validated unnamed uint32 values. Constants shared by upstream families retain their shared numeric identity.
|
|
2343
2416
|
*
|
|
@@ -3695,6 +3768,53 @@ export declare const UpperAll: 97;
|
|
|
3695
3768
|
*/
|
|
3696
3769
|
export declare const UpperFirst: 96;
|
|
3697
3770
|
|
|
3771
|
+
/**
|
|
3772
|
+
* Walks synchronously using the pinned upstream case ordering. Each accepted entry is followed by its
|
|
3773
|
+
* children and a null exit. Returning false prunes the entry without an exit;
|
|
3774
|
+
* boolean exit return values are ignored. Every callback must return a boolean
|
|
3775
|
+
* synchronously; other results produce InputError. Callback exceptions retain their identity,
|
|
3776
|
+
* and upstream deferred comment callbacks still run during exception unwinding.
|
|
3777
|
+
*
|
|
3778
|
+
* Children and later fields are read live. Each list captures its array reference
|
|
3779
|
+
* and length when traversal reaches that list, then reads existing later slots
|
|
3780
|
+
* when reached. Replacing or reordering later slots is observed and can cause
|
|
3781
|
+
* a node to be skipped or revisited. Indices added beyond the captured extent
|
|
3782
|
+
* are not visited by that active list. Replacing the owner's array field does not
|
|
3783
|
+
* redirect an active list, but a later walk or print sees the current field.
|
|
3784
|
+
* Changes made before a list is reached are observed when it starts.
|
|
3785
|
+
*
|
|
3786
|
+
* Supported edits preserve each node's Type (and TypedNil.Kind), required field
|
|
3787
|
+
* shapes and every index within each active list's captured extent. Leaving
|
|
3788
|
+
* holes or shrinking an array below that extent (for example through truncation,
|
|
3789
|
+
* deletion, or length-reducing splice/shift) is outside the mutation contract.
|
|
3790
|
+
* These are not runtime validation rules. Ordinary JavaScript object and array
|
|
3791
|
+
* aliases remain shared; the binding does not model distinct Go slice headers or
|
|
3792
|
+
* capacity-dependent allocation over shared backing storage.
|
|
3793
|
+
*
|
|
3794
|
+
* Comments on Stmt, CaseItem and ArrayElem are copied before their callbacks,
|
|
3795
|
+
* including position and byte-string values; editing a copy does not edit the
|
|
3796
|
+
* stored comment. Last/CondLast/ThenLast/DoLast callbacks receive the stored
|
|
3797
|
+
* JavaScript Comment object. Replacing its array slot leaves any previously
|
|
3798
|
+
* retained callback object unchanged: there is no Go value-slot pointer identity.
|
|
3799
|
+
* Reentrant walks maintain independent traversal state.
|
|
3800
|
+
* @public
|
|
3801
|
+
*/
|
|
3802
|
+
export declare function walk(node: Node_2, callback: (node: Node_2 | null) => boolean): void;
|
|
3803
|
+
|
|
3804
|
+
/**
|
|
3805
|
+
* A panic raised by upstream-equivalent traversal, such as a nil dereference or
|
|
3806
|
+
* unsupported concrete node. Exceptions thrown by callbacks are never wrapped.
|
|
3807
|
+
* @public
|
|
3808
|
+
*/
|
|
3809
|
+
export declare class WalkPanicError extends ShAstError {
|
|
3810
|
+
/** Stable discriminator for traversal panics. @public */
|
|
3811
|
+
readonly code = "SH_AST_WALK_PANIC";
|
|
3812
|
+
/** Exact upstream panic bytes; Error.message is only a display rendering. @public */
|
|
3813
|
+
readonly Message: GoString;
|
|
3814
|
+
/** Retains the upstream panic text separately from its display rendering. @public */
|
|
3815
|
+
constructor(message: GoString);
|
|
3816
|
+
}
|
|
3817
|
+
|
|
3698
3818
|
/**
|
|
3699
3819
|
* WhileClause represents a while or an until clause.
|
|
3700
3820
|
*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Printing has two upstream failure modes: returned errors and panics raised by
|
|
3
|
+
* the operation. Both retain exact message bytes; neither is a parser failure
|
|
4
|
+
* or a claim that the transport itself malfunctioned.
|
|
5
|
+
*/
|
|
6
|
+
import type { GoString } from '../generated/syntax-types.js';
|
|
7
|
+
import { ShAstError } from './errors.js';
|
|
8
|
+
/**
|
|
9
|
+
* An error returned by upstream Printer.Print, such as an unsupported root or
|
|
10
|
+
* incompatible formatting options. No partial writer output is exposed.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare class PrintError extends ShAstError {
|
|
14
|
+
/** Stable identity for an ordinary error returned by upstream Print. @public */
|
|
15
|
+
readonly code = "SH_AST_SYNTAX_PRINT";
|
|
16
|
+
/** Exact upstream error bytes; Error.message is only a display rendering. @public */
|
|
17
|
+
readonly Message: GoString;
|
|
18
|
+
/** Retains the upstream error without interpreting its human-readable text. @public */
|
|
19
|
+
constructor(message: GoString);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Upstream Printer.Print panicked for a representable tree or option value.
|
|
23
|
+
* Partial and typed-nil trees can trigger this independently of root support.
|
|
24
|
+
* Catching the panic preserves reuse of the binding's shared runtime.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare class PrintPanicError extends ShAstError {
|
|
28
|
+
/** Stable identity for an upstream panic caught at the Print operation. @public */
|
|
29
|
+
readonly code = "SH_AST_SYNTAX_PRINT_PANIC";
|
|
30
|
+
/** Exact panic rendering from Go; Error.message is only a display rendering. @public */
|
|
31
|
+
readonly Message: GoString;
|
|
32
|
+
/** Retains the panic message separately from ordinary returned Print errors. @public */
|
|
33
|
+
constructor(message: GoString);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=syntax-print-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-print-errors.d.ts","sourceRoot":"","sources":["../src/syntax-print-errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACxC,gFAAgF;IAChF,QAAQ,CAAC,IAAI,yBAAyB;IAEtC,qFAAqF;IACrF,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAE3B,uFAAuF;gBAC3E,OAAO,EAAE,QAAQ;CAK9B;AAED;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IAC7C,mFAAmF;IACnF,QAAQ,CAAC,IAAI,+BAA+B;IAE5C,wFAAwF;IACxF,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAE3B,wFAAwF;gBAC5E,OAAO,EAAE,QAAQ;CAK9B"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ShAstError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* An error returned by upstream Printer.Print, such as an unsupported root or
|
|
4
|
+
* incompatible formatting options. No partial writer output is exposed.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class PrintError extends ShAstError {
|
|
8
|
+
/** Stable identity for an ordinary error returned by upstream Print. @public */
|
|
9
|
+
code = 'SH_AST_SYNTAX_PRINT';
|
|
10
|
+
/** Exact upstream error bytes; Error.message is only a display rendering. @public */
|
|
11
|
+
Message;
|
|
12
|
+
/** Retains the upstream error without interpreting its human-readable text. @public */
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(typeof message === 'string' ? message : new TextDecoder().decode(message));
|
|
15
|
+
this.Message = message;
|
|
16
|
+
this.name = 'PrintError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Upstream Printer.Print panicked for a representable tree or option value.
|
|
21
|
+
* Partial and typed-nil trees can trigger this independently of root support.
|
|
22
|
+
* Catching the panic preserves reuse of the binding's shared runtime.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export class PrintPanicError extends ShAstError {
|
|
26
|
+
/** Stable identity for an upstream panic caught at the Print operation. @public */
|
|
27
|
+
code = 'SH_AST_SYNTAX_PRINT_PANIC';
|
|
28
|
+
/** Exact panic rendering from Go; Error.message is only a display rendering. @public */
|
|
29
|
+
Message;
|
|
30
|
+
/** Retains the panic message separately from ordinary returned Print errors. @public */
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(typeof message === 'string' ? message : new TextDecoder().decode(message));
|
|
33
|
+
this.Message = message;
|
|
34
|
+
this.name = 'PrintPanicError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=syntax-print-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-print-errors.js","sourceRoot":"","sources":["../src/syntax-print-errors.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;IACxC,gFAAgF;IACvE,IAAI,GAAG,qBAAqB,CAAC;IAEtC,qFAAqF;IAC5E,OAAO,CAAW;IAE3B,uFAAuF;IACvF,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,YAAY,CAAC;IAC3B,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAC7C,mFAAmF;IAC1E,IAAI,GAAG,2BAA2B,CAAC;IAE5C,wFAAwF;IAC/E,OAAO,CAAW;IAE3B,wFAAwF;IACxF,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,iBAAiB,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collected-output access to upstream Printer.Print. The reverse codec rebuilds
|
|
3
|
+
* the current faithful tree, and Go owns formatting decisions. This module has
|
|
4
|
+
* no source cache, parser round trip, writer callbacks, or reusable printer state.
|
|
5
|
+
*/
|
|
6
|
+
import type { GoString, Node } from '../generated/syntax-types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Upstream NewPrinter controls applied to a fresh printer for each call. All
|
|
9
|
+
* flags default to false; zero indentation selects tabs. The pinned WASM uint
|
|
10
|
+
* domain is 64-bit, so Indent accepts bigint beyond JavaScript's safe integers.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface PrintOptions {
|
|
14
|
+
/** Spaces per level, or zero for tabs. Large values can request expensive output. */
|
|
15
|
+
Indent?: number | bigint;
|
|
16
|
+
/** Places multiline binary operators on the next line with a backslash continuation. */
|
|
17
|
+
BinaryNextLine?: boolean;
|
|
18
|
+
/** Indents case alternatives, placing their bodies two levels below the case clause. */
|
|
19
|
+
SwitchCaseIndent?: boolean;
|
|
20
|
+
/** Adds space after redirection operators except `>&`, `<&`, `>(` and `<(`. */
|
|
21
|
+
SpaceRedirects?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Preserves token columns on a best-effort basis.
|
|
24
|
+
* @deprecated Upstream marks this option as flawed and plans removal in v4.
|
|
25
|
+
*/
|
|
26
|
+
KeepPadding?: boolean;
|
|
27
|
+
/** Omits comments, indentation and optional whitespace. Incompatible with SingleLine. */
|
|
28
|
+
Minify?: boolean;
|
|
29
|
+
/** Reduces newlines except where comments, heredocs or File output require them. */
|
|
30
|
+
SingleLine?: boolean;
|
|
31
|
+
/** Places a function's opening brace on the next line. */
|
|
32
|
+
FunctionNextLine?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Formats the current tree with a fresh upstream printer and collects all output.
|
|
36
|
+
* Supported roots are File, Stmt, Word, Assign, Command and WordPart; other Nodes
|
|
37
|
+
* produce PrintError. Only File output has upstream's trailing-newline behavior.
|
|
38
|
+
* Invalid UTF-8 output remains bytes. Upstream formatting can itself consume
|
|
39
|
+
* input bytes, including its tabwriter escape byte, so this is not source replay.
|
|
40
|
+
*
|
|
41
|
+
* InputError identifies unrepresentable input; PrintError is an ordinary returned
|
|
42
|
+
* upstream error; PrintPanicError retains an upstream operation panic. No partial
|
|
43
|
+
* output or arbitrary writer lifecycle is exposed. Full tree reconstruction and
|
|
44
|
+
* collected output require memory proportional to the values involved; extreme
|
|
45
|
+
* indentation or tree size is not made resource-safe by panic adaptation.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare function printSync(node: Node, options?: PrintOptions): GoString;
|
|
49
|
+
//# sourceMappingURL=syntax-print.d.ts.map
|
|
@@ -0,0 +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;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,YAAiB,GAAG,QAAQ,CAoC1E"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ShInternalError } from './errors.js';
|
|
2
|
+
import { InputError } from './syntax-errors.js';
|
|
3
|
+
import { PrintError, PrintPanicError } from './syntax-print-errors.js';
|
|
4
|
+
import { decodeWire, encodeWire, isGoString, isRecord, isSyntaxNode } from './syntax-wire.js';
|
|
5
|
+
import { callSyntax } from './wasm-instance.js';
|
|
6
|
+
/**
|
|
7
|
+
* Formats the current tree with a fresh upstream printer and collects all output.
|
|
8
|
+
* Supported roots are File, Stmt, Word, Assign, Command and WordPart; other Nodes
|
|
9
|
+
* produce PrintError. Only File output has upstream's trailing-newline behavior.
|
|
10
|
+
* Invalid UTF-8 output remains bytes. Upstream formatting can itself consume
|
|
11
|
+
* input bytes, including its tabwriter escape byte, so this is not source replay.
|
|
12
|
+
*
|
|
13
|
+
* InputError identifies unrepresentable input; PrintError is an ordinary returned
|
|
14
|
+
* upstream error; PrintPanicError retains an upstream operation panic. No partial
|
|
15
|
+
* output or arbitrary writer lifecycle is exposed. Full tree reconstruction and
|
|
16
|
+
* collected output require memory proportional to the values involved; extreme
|
|
17
|
+
* indentation or tree size is not made resource-safe by panic adaptation.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export function printSync(node, options = {}) {
|
|
21
|
+
validatePrintOptions(options);
|
|
22
|
+
if (!isSyntaxNode(node)) {
|
|
23
|
+
throw new InputError('Expected a complete, acyclic upstream Node record');
|
|
24
|
+
}
|
|
25
|
+
const payload = new TextEncoder().encode(encodeWire(node));
|
|
26
|
+
const result = decodeWire(callSyntax('print', payload, encodeWire(options)));
|
|
27
|
+
if (!isRecord(result)) {
|
|
28
|
+
throw new ShInternalError('The syntax printer returned a non-record response');
|
|
29
|
+
}
|
|
30
|
+
if (result.Error !== undefined) {
|
|
31
|
+
const error = result.Error;
|
|
32
|
+
if (!isRecord(error) || !isGoString(error.Message)) {
|
|
33
|
+
throw new ShInternalError('The syntax printer returned a malformed error');
|
|
34
|
+
}
|
|
35
|
+
switch (error.Kind) {
|
|
36
|
+
case 'PrintError':
|
|
37
|
+
throw new PrintError(error.Message);
|
|
38
|
+
case 'PrintPanicError':
|
|
39
|
+
throw new PrintPanicError(error.Message);
|
|
40
|
+
case 'InputError':
|
|
41
|
+
throw new InputError(error.Message);
|
|
42
|
+
case 'InternalError':
|
|
43
|
+
throw new ShInternalError(typeof error.Message === 'string'
|
|
44
|
+
? error.Message
|
|
45
|
+
: new TextDecoder().decode(error.Message));
|
|
46
|
+
default:
|
|
47
|
+
throw new ShInternalError('The syntax printer returned an unknown error kind');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!isGoString(result.Output)) {
|
|
51
|
+
throw new ShInternalError('The syntax printer returned an invalid output value');
|
|
52
|
+
}
|
|
53
|
+
return result.Output;
|
|
54
|
+
}
|
|
55
|
+
/** Validates exact option domains without imposing a formatting or indentation policy. */
|
|
56
|
+
function validatePrintOptions(options) {
|
|
57
|
+
if (!isRecord(options)) {
|
|
58
|
+
throw new InputError('Printer options must be a data record');
|
|
59
|
+
}
|
|
60
|
+
const flags = new Set([
|
|
61
|
+
'BinaryNextLine',
|
|
62
|
+
'SwitchCaseIndent',
|
|
63
|
+
'SpaceRedirects',
|
|
64
|
+
'KeepPadding',
|
|
65
|
+
'Minify',
|
|
66
|
+
'SingleLine',
|
|
67
|
+
'FunctionNextLine',
|
|
68
|
+
]);
|
|
69
|
+
for (const [name, value] of Object.entries(options)) {
|
|
70
|
+
if (name === 'Indent') {
|
|
71
|
+
const valid = typeof value === 'bigint'
|
|
72
|
+
? value >= 0n && value <= 0xffffffffffffffffn
|
|
73
|
+
: typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
74
|
+
if (!valid) {
|
|
75
|
+
throw new InputError('Indent must be a safe nonnegative integer or uint64 bigint');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (!flags.has(name)) {
|
|
79
|
+
throw new InputError(`Unknown printer option: ${name}`);
|
|
80
|
+
}
|
|
81
|
+
else if (typeof value !== 'boolean') {
|
|
82
|
+
throw new InputError(`${name} must be boolean`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=syntax-print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-print.js","sourceRoot":"","sources":["../src/syntax-print.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AA8BhD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,IAAU,EAAE,UAAwB,EAAE;IAC9D,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAC9B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,UAAU,CAAC,mDAAmD,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,OAA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|
+
/**
|
|
2
|
+
* Private live boundary evaluation for Walk's comment placement. These methods
|
|
3
|
+
* mirror the pinned mvdan/sh node methods so callback edits are visible without
|
|
4
|
+
* repeatedly serializing subtrees to WASM. They are not public position APIs.
|
|
5
|
+
*
|
|
6
|
+
* Adapted from mvdan.cc/sh/v3 v3.13.1 syntax/nodes.go, copyright Daniel Martí.
|
|
7
|
+
* The upstream BSD license is retained in syntax-walk-license.ts.
|
|
8
|
+
*/
|
|
9
|
+
import type { Node, SyntaxPos } from '../generated/syntax-types.js';
|
|
10
|
+
/** Stmt comments at or after the live end become the single deferred comment. @internal */
|
|
11
|
+
export declare function atStatementEnd(node: Extract<Node, {
|
|
12
|
+
Type: 'Stmt';
|
|
13
|
+
}>, hash: SyntaxPos): boolean;
|
|
14
|
+
/** Case/array comments strictly after the live start become deferred. @internal */
|
|
15
|
+
export declare function afterItemStart(node: Extract<Node, {
|
|
16
|
+
Type: 'CaseItem' | 'ArrayElem';
|
|
17
|
+
}>, hash: SyntaxPos): boolean;
|
|
18
|
+
//# sourceMappingURL=syntax-walk-bounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syntax-walk-bounds.d.ts","sourceRoot":"","sources":["../src/syntax-walk-bounds.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AA6LpE,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAE9F;AACD,mFAAmF;AACnF,wBAAgB,cAAc,CAC5B,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,UAAU,GAAG,WAAW,CAAA;CAAE,CAAC,EACvD,IAAI,EAAE,SAAS,GACd,OAAO,CAET"}
|