@ball-lang/encoder 1.59.9 → 1.59.11
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/encoder.d.ts +82 -0
- package/dist/encoder.d.ts.map +1 -1
- package/dist/encoder.js +384 -71
- package/dist/encoder.js.map +1 -1
- package/package.json +1 -1
- package/src/encoder.ts +433 -75
package/dist/encoder.d.ts
CHANGED
|
@@ -2,12 +2,28 @@ import type { Program } from "./types.ts";
|
|
|
2
2
|
export interface EncodeOptions {
|
|
3
3
|
moduleName?: string;
|
|
4
4
|
entryFunction?: string;
|
|
5
|
+
/** Throw an `EncodeError` on ANY unhandled construct, lossy or not. */
|
|
5
6
|
strict?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Throw an `EncodeError` only for warnings that change what the program
|
|
9
|
+
* computes, while tolerating erasure-only ones (a type alias, an empty
|
|
10
|
+
* statement, a `satisfies` clause — none of which contribute to the
|
|
11
|
+
* program's value).
|
|
12
|
+
*
|
|
13
|
+
* `strict` is the blunt instrument: it rejects a file for a stray `;`.
|
|
14
|
+
* This mode is the one worth running over third-party code, because every
|
|
15
|
+
* warning it raises is a real semantic difference between the source and
|
|
16
|
+
* the encoded Ball program.
|
|
17
|
+
*/
|
|
18
|
+
strictBehaviorAffecting?: boolean;
|
|
6
19
|
}
|
|
7
20
|
export declare class TsEncoder {
|
|
8
21
|
private stdFunctions;
|
|
9
22
|
private warnings;
|
|
10
23
|
private strict;
|
|
24
|
+
private strictBehaviorAffecting;
|
|
25
|
+
/** Monotonic counter for the synthetic loop variables `.forEach` desugars to. */
|
|
26
|
+
private desugarCounter;
|
|
11
27
|
private static readonly OPERATOR_CANONICAL_NAMES;
|
|
12
28
|
encode(source: string, options?: EncodeOptions): Program;
|
|
13
29
|
private encodeFunction;
|
|
@@ -15,12 +31,61 @@ export declare class TsEncoder {
|
|
|
15
31
|
private encodeBlock;
|
|
16
32
|
private encodeStatement;
|
|
17
33
|
private encodeExpr;
|
|
34
|
+
/**
|
|
35
|
+
* `delete obj.a` / `delete obj[k]` -> `std_collections.map_delete(map, key)`.
|
|
36
|
+
*
|
|
37
|
+
* `map_delete` has been declared and Dart-engine-implemented all along
|
|
38
|
+
* (dart/shared/lib/std_collections.dart) — no encoder in the repo had ever
|
|
39
|
+
* emitted it, so `delete` fell through to a placeholder literal (#490).
|
|
40
|
+
*/
|
|
41
|
+
private encodeDelete;
|
|
42
|
+
/**
|
|
43
|
+
* A regex literal encodes to its PATTERN SOURCE as a plain string.
|
|
44
|
+
*
|
|
45
|
+
* The universal std regex functions (`regex_match`/`regex_find`/
|
|
46
|
+
* `regex_find_all`/`regex_replace`/`regex_replace_all`) all take the pattern
|
|
47
|
+
* as a string and model no flags at all, so `/abc/i` cannot round-trip
|
|
48
|
+
* faithfully. Dropping `i`/`g`/`m` genuinely changes behaviour, so it is
|
|
49
|
+
* reported as a behaviour-affecting warning rather than silently accepted.
|
|
50
|
+
*/
|
|
51
|
+
private encodeRegexLiteral;
|
|
18
52
|
private encodeBinary;
|
|
19
53
|
private isProvablyString;
|
|
20
54
|
private isStringExpr;
|
|
21
55
|
private encodePrefixUnary;
|
|
22
56
|
private encodePostfixUnary;
|
|
23
57
|
private encodeCall;
|
|
58
|
+
/**
|
|
59
|
+
* Lower `xs.forEach(cb)` to the native `std.for_each` control-flow node.
|
|
60
|
+
*
|
|
61
|
+
* Ball has no `list_for_each` base function in any module — iteration is
|
|
62
|
+
* control flow, not a runtime call (Core Invariant #4), which is exactly how
|
|
63
|
+
* the Dart encoder treats it. When `cb` is an inline single-parameter
|
|
64
|
+
* function its parameter becomes the loop variable and its body becomes the
|
|
65
|
+
* loop body, so the emitted IR is indistinguishable from the equivalent
|
|
66
|
+
* `for (const x of xs)`. Otherwise the callback is invoked per element
|
|
67
|
+
* through `std.invoke`.
|
|
68
|
+
*/
|
|
69
|
+
private desugarForEach;
|
|
70
|
+
/**
|
|
71
|
+
* Route the JS regex API onto the universal `std` regex base functions
|
|
72
|
+
* (#490). All five have been declared and Dart-engine-implemented since the
|
|
73
|
+
* std module was written; no encoder in the repo had ever emitted one, so
|
|
74
|
+
* `tests/conformance/STD_COVERAGE.md` marked them Encoder-emittable ❌.
|
|
75
|
+
*
|
|
76
|
+
* /re/.test(s) -> std.regex_match(left: s, right: "re")
|
|
77
|
+
* /re/.exec(s) -> std.regex_find(left: s, right: "re")
|
|
78
|
+
* s.match(/re/g) -> std.regex_find_all(left: s, right: "re")
|
|
79
|
+
* s.replace(/re/, x) -> std.regex_replace(value: s, from: "re", to: x)
|
|
80
|
+
* s.replace(/re/g, x) -> std.regex_replace_all(...) (`g` is honoured)
|
|
81
|
+
* s.replaceAll(/re/, x)-> std.regex_replace_all(...)
|
|
82
|
+
*
|
|
83
|
+
* Returns undefined when the call is not a regex shape, so the ordinary
|
|
84
|
+
* method-mapping path takes over.
|
|
85
|
+
*/
|
|
86
|
+
private tryEncodeRegexCall;
|
|
87
|
+
/** Warn about every regex flag that the chosen std routing does not honour. */
|
|
88
|
+
private warnDroppedRegexFlags;
|
|
24
89
|
private encodeLambda;
|
|
25
90
|
private encodeIf;
|
|
26
91
|
private encodeFor;
|
|
@@ -39,11 +104,28 @@ export declare class TsEncoder {
|
|
|
39
104
|
/**
|
|
40
105
|
* Map a JS/TS method name to its Ball std function equivalent.
|
|
41
106
|
* Returns null if no mapping exists (falls through to generic method call).
|
|
107
|
+
*
|
|
108
|
+
* Every entry names BOTH the canonical std function AND the field names that
|
|
109
|
+
* function's arguments carry. Names alone are not enough: `compileStdCall`
|
|
110
|
+
* looks arguments up by field name, so `string_replace` fed `other`/`arg1`
|
|
111
|
+
* (the old positional scheme) silently compiled to `''`, and
|
|
112
|
+
* `string_substring` fed the same way crashed. The field names below were
|
|
113
|
+
* each read off the corresponding `case` body in ts/compiler/src/compiler.ts
|
|
114
|
+
* (#489).
|
|
42
115
|
*/
|
|
43
116
|
private mapMethodToStd;
|
|
44
117
|
private stdCall;
|
|
45
118
|
private buildBaseModules;
|
|
46
119
|
private nullLiteral;
|
|
120
|
+
/**
|
|
121
|
+
* Record a warning, and turn it into a hard error when the caller asked for
|
|
122
|
+
* one.
|
|
123
|
+
*
|
|
124
|
+
* `kind` is the TS SyntaxKind name (or another marker) the warning is about;
|
|
125
|
+
* it is what `strictBehaviorAffecting` filters on, so the distinction between
|
|
126
|
+
* "erased a type alias" and "silently changed what this program computes" is
|
|
127
|
+
* mechanical rather than a substring match on the message.
|
|
128
|
+
*/
|
|
47
129
|
private warn;
|
|
48
130
|
getWarnings(): string[];
|
|
49
131
|
}
|
package/dist/encoder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../src/encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EAGR,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../src/encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EAGR,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;;;;OAUG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAmED,qBAAa,SAAS;IACpB,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,uBAAuB,CAAS;IACxC,iFAAiF;IACjF,OAAO,CAAC,cAAc,CAAK;IAQ3B,OAAO,CAAC,MAAM,CAAC,QA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