@ball-lang/compiler 1.71.0 → 1.71.1
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/compiler.d.ts +7 -4
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js +63 -21
- package/dist/compiler.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler.ts +71 -21
package/dist/compiler.d.ts
CHANGED
|
@@ -180,10 +180,13 @@ export declare class BallCompiler {
|
|
|
180
180
|
* 0`), `this.`-formals (`Box.of(this.value)`), a plain body
|
|
181
181
|
* (`Bar.named(int x) { print(x); }`), or any combination. The instance comes
|
|
182
182
|
* from `Object.create(C.prototype)` so no user constructor runs, which means
|
|
183
|
-
* the class's inline field initializers
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
183
|
+
* neither the class's inline field initializers nor the real `super()` that
|
|
184
|
+
* would run the SUPERCLASS's inline initializers execute either: every
|
|
185
|
+
* declared field reachable from this class — inherited ones first, then the
|
|
186
|
+
* class's own — is seeded with its default FIRST (Dart's ordering — inline
|
|
187
|
+
* field initializers, then the initializer list, then the body), and only
|
|
188
|
+
* then do the constructor-specific writes land on top (#564, #581). The
|
|
189
|
+
* caller (`emitClass`) supplies that whole-chain `classProperties` list.
|
|
187
190
|
*
|
|
188
191
|
* A `factory` named constructor is the one exception: by definition it
|
|
189
192
|
* returns some other object, so its body runs as the static method's own
|
package/dist/compiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAMV,MAAM,EACN,OAAO,EAIR,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,uDAAuD;AACv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OAAO,CAAC,sBAAsB;IAqI9B,OAAO,CAAC,yBAAyB;IAqBjC,OAAO,CAAC,sBAAsB;IAI9B;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,aAAa;IA6BrB,OAAO,CAAC,WAAW;IAsHnB,OAAO,CAAC,cAAc;IAyhCtB,OAAO,CAAC,iBAAiB;IAoJzB,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,WAAW;IA2CnB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,iBAAiB;IA6HzB;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAqBxB,OAAO,CAAC,iBAAiB;IA2BzB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,YAAY;CAgDrB;AA+9BD,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CAE1E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,CAER;AAMD,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CA+HpF"}
|
package/dist/compiler.js
CHANGED
|
@@ -2181,7 +2181,17 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2181
2181
|
// Include inherited fields from the superclass chain so that
|
|
2182
2182
|
// references to inherited fields inside methods emit `this.name`
|
|
2183
2183
|
// instead of bare `name` (which would be undefined in JS).
|
|
2184
|
+
//
|
|
2185
|
+
// The walk also collects each ancestor level's own field SPECS (type +
|
|
2186
|
+
// inline initializer), not just the names: a named constructor builds its
|
|
2187
|
+
// instance with `Object.create`, which runs no constructor at all — so it
|
|
2188
|
+
// never runs the real `super()` that would otherwise execute the
|
|
2189
|
+
// superclass's inline field initializers as its own prologue. The seeding
|
|
2190
|
+
// loop in `buildNamedCtor` therefore has to reproduce the whole chain in
|
|
2191
|
+
// one flat pass, the way the Dart reference engine's constructor frame
|
|
2192
|
+
// recurses through `_invokeSuperConstructor` (#581).
|
|
2184
2193
|
const superclass = typeof meta["superclass"] === "string" ? meta["superclass"] : undefined;
|
|
2194
|
+
const inheritedLevels = [];
|
|
2185
2195
|
if (superclass) {
|
|
2186
2196
|
const entryMod = this.program.modules.find(m => m.name === this.program.entryModule);
|
|
2187
2197
|
let sup = superclass;
|
|
@@ -2191,17 +2201,41 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2191
2201
|
break;
|
|
2192
2202
|
const supMeta = supTd.metadata ?? {};
|
|
2193
2203
|
const supFields = Array.isArray(supMeta["fields"]) ? supMeta["fields"] : [];
|
|
2204
|
+
const level = [];
|
|
2194
2205
|
for (const sf of supFields) {
|
|
2195
|
-
if (sf?.name)
|
|
2196
|
-
|
|
2206
|
+
if (!sf?.name)
|
|
2207
|
+
continue;
|
|
2208
|
+
fieldNames.add(sf.name);
|
|
2209
|
+
// Statics live as module-level consts, never on the instance.
|
|
2210
|
+
if (sf.is_static === true)
|
|
2211
|
+
continue;
|
|
2212
|
+
level.push({
|
|
2213
|
+
name: sf.name,
|
|
2214
|
+
type: typeof sf.type === "string" ? this.dartTypeToTs(sf.type) : "any",
|
|
2215
|
+
rawDartType: typeof sf.type === "string" ? sf.type : "",
|
|
2216
|
+
dartInitializer: typeof sf.initializer === "string" ? sf.initializer : undefined,
|
|
2217
|
+
});
|
|
2197
2218
|
}
|
|
2198
2219
|
if (supTd.descriptor?.field) {
|
|
2199
2220
|
for (const f of supTd.descriptor.field)
|
|
2200
2221
|
fieldNames.add(f.name);
|
|
2201
2222
|
}
|
|
2223
|
+
// Descriptor fallback mirrors the own-class path above: only when the
|
|
2224
|
+
// ancestor carries no richer `metadata.fields` at all. A bare
|
|
2225
|
+
// descriptor field has no initializer, so it seeds nothing — it is
|
|
2226
|
+
// collected purely so the level list matches the name set.
|
|
2227
|
+
if (level.length === 0 && supTd.descriptor?.field) {
|
|
2228
|
+
for (const f of supTd.descriptor.field) {
|
|
2229
|
+
level.push({ name: f.name, type: "any", rawDartType: "" });
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
inheritedLevels.push(level);
|
|
2202
2233
|
sup = typeof supMeta["superclass"] === "string" ? supMeta["superclass"] : undefined;
|
|
2203
2234
|
}
|
|
2204
2235
|
}
|
|
2236
|
+
// Root ancestor first, matching Dart's superclass-initializes-before-
|
|
2237
|
+
// subclass ordering, so a subclass field that shadows an ancestor's wins.
|
|
2238
|
+
const inheritedProperties = inheritedLevels.slice().reverse().flat();
|
|
2205
2239
|
// Method-name set for `this.foo()` routing inside bodies.
|
|
2206
2240
|
// Exclude static fields — they're emitted as module-level consts
|
|
2207
2241
|
// and referenced WITHOUT `this.`.
|
|
@@ -2259,11 +2293,12 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2259
2293
|
}
|
|
2260
2294
|
else {
|
|
2261
2295
|
// Named constructors are static factory methods that return a new
|
|
2262
|
-
// instance.
|
|
2263
|
-
// them
|
|
2264
|
-
//
|
|
2265
|
-
// (
|
|
2266
|
-
|
|
2296
|
+
// instance. Every (non-static) field declaration reachable from this
|
|
2297
|
+
// class goes with them — inherited ones first, then the class's own:
|
|
2298
|
+
// the instance is built with `Object.create`, which runs no field
|
|
2299
|
+
// initializer AND no real `super()`, so the builder has to seed each
|
|
2300
|
+
// default along the whole superclass chain itself (#564, #581).
|
|
2301
|
+
methods.push(this.buildNamedCtor(fn, mMeta, fieldNames, tsName, [...inheritedProperties, ...properties.filter((p) => !p.isStatic)]));
|
|
2267
2302
|
}
|
|
2268
2303
|
}
|
|
2269
2304
|
else if (mMeta["is_getter"] === true) {
|
|
@@ -2485,10 +2520,13 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2485
2520
|
* 0`), `this.`-formals (`Box.of(this.value)`), a plain body
|
|
2486
2521
|
* (`Bar.named(int x) { print(x); }`), or any combination. The instance comes
|
|
2487
2522
|
* from `Object.create(C.prototype)` so no user constructor runs, which means
|
|
2488
|
-
* the class's inline field initializers
|
|
2489
|
-
*
|
|
2490
|
-
*
|
|
2491
|
-
*
|
|
2523
|
+
* neither the class's inline field initializers nor the real `super()` that
|
|
2524
|
+
* would run the SUPERCLASS's inline initializers execute either: every
|
|
2525
|
+
* declared field reachable from this class — inherited ones first, then the
|
|
2526
|
+
* class's own — is seeded with its default FIRST (Dart's ordering — inline
|
|
2527
|
+
* field initializers, then the initializer list, then the body), and only
|
|
2528
|
+
* then do the constructor-specific writes land on top (#564, #581). The
|
|
2529
|
+
* caller (`emitClass`) supplies that whole-chain `classProperties` list.
|
|
2492
2530
|
*
|
|
2493
2531
|
* A `factory` named constructor is the one exception: by definition it
|
|
2494
2532
|
* returns some other object, so its body runs as the static method's own
|
|
@@ -2502,13 +2540,14 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2502
2540
|
const bodyParts = [];
|
|
2503
2541
|
// Does the ctor have any field write of its own? Only WHETHER matters
|
|
2504
2542
|
// here; each value is resolved where the assignment is emitted, by
|
|
2505
|
-
// `resolveInitializerValue`.
|
|
2506
|
-
//
|
|
2507
|
-
//
|
|
2508
|
-
//
|
|
2543
|
+
// `resolveInitializerValue`. A `this.`-formal ALWAYS counts, whatever else
|
|
2544
|
+
// the initializer list holds: this used to also require
|
|
2545
|
+
// `initializers.length === 0`, so `Foo.named(this.x) : super(1)` — a
|
|
2546
|
+
// non-empty list with no `field` entry — took neither construct branch and
|
|
2547
|
+
// fell through to `return new Foo()`, silently dropping the formal (#582).
|
|
2509
2548
|
const thisParams = ctorParams.filter(p => p.isThis);
|
|
2510
2549
|
const hasFieldInitializers = initializers.some((i) => i?.kind === "field" && typeof i.name === "string");
|
|
2511
|
-
const hasCtorFieldWrites = hasFieldInitializers ||
|
|
2550
|
+
const hasCtorFieldWrites = hasFieldInitializers || thisParams.length > 0;
|
|
2512
2551
|
// A Dart `factory` returns some other object, so it is the ONE named
|
|
2513
2552
|
// constructor that must not synthesize an instance of its own class.
|
|
2514
2553
|
const isFactory = meta["is_factory"] === true;
|
|
@@ -2531,12 +2570,15 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2531
2570
|
const allAssignments = [...assignments, ...thisAssignments];
|
|
2532
2571
|
bodyParts.push(`const __inst = Object.create(${className}.prototype);`);
|
|
2533
2572
|
// `Object.create` deliberately runs no constructor — which also means it
|
|
2534
|
-
// runs none of the class's inline field initializers
|
|
2535
|
-
//
|
|
2536
|
-
//
|
|
2537
|
-
//
|
|
2573
|
+
// runs none of the class's inline field initializers, and none of the
|
|
2574
|
+
// SUPERCLASS's either (a real `super()` would have). `classProperties`
|
|
2575
|
+
// is therefore the whole superclass chain root-first, then this class's
|
|
2576
|
+
// own fields. Seed each with the SAME default its class declaration
|
|
2577
|
+
// emits, before any constructor-specific write, exactly as Dart orders
|
|
2578
|
+
// them (inline initializers, then the initializer list, then the body).
|
|
2538
2579
|
// Without this a field the named constructor never mentions stayed
|
|
2539
|
-
// `undefined` forever (#564: `Init.viaList`'s `w`, `Baz.bare`'s `v
|
|
2580
|
+
// `undefined` forever (#564: `Init.viaList`'s `w`, `Baz.bare`'s `v`;
|
|
2581
|
+
// #581: every field declared by an ancestor).
|
|
2540
2582
|
for (const p of classProperties) {
|
|
2541
2583
|
const def = dartInitializerToTs(p.dartInitializer, p.type, p.rawDartType);
|
|
2542
2584
|
if (def !== undefined)
|