@ball-lang/compiler 1.7.6 → 1.7.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"preamble.d.ts","sourceRoot":"","sources":["../src/preamble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,QA++C/B,CAAC"}
1
+ {"version":3,"file":"preamble.d.ts","sourceRoot":"","sources":["../src/preamble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,QA0gD/B,CAAC"}
package/dist/preamble.js CHANGED
@@ -247,7 +247,11 @@ function __ball_to_string(v: any): string {
247
247
  }
248
248
  if (v instanceof Map) {
249
249
  const parts: string[] = [];
250
- for (const [k, val] of v.entries()) {
250
+ // v.entries() as a method call would hit the Dart-property-style
251
+ // getter of the same name (installed further down in this file) and
252
+ // try to invoke its return value -- an array -- as a function.
253
+ // _nativeMapEntries is the real, un-shadowed method (issue #259).
254
+ for (const [k, val] of _nativeMapEntries.call(v)) {
251
255
  parts.push(__ball_to_string(k) + ': ' + __ball_to_string(val));
252
256
  }
253
257
  return '{' + parts.join(', ') + '}';
@@ -719,6 +723,21 @@ function __ball_cascade(target: any, ops: any[]): any {
719
723
  // ── Dart \u2192 JS method-name polyfills ────────────────────────────────
720
724
  //
721
725
  // Idempotent: guarded so multiple preamble inclusions don't double-install.
726
+
727
+ // Native Map.prototype.entries/keys/values, captured BEFORE the
728
+ // installBallPolyfills IIFE below shadows them with Dart-property-style
729
+ // getters of the same name. Top-level (not IIFE-scoped) so every internal
730
+ // call site that needs the REAL iterator method -- not the property-style
731
+ // getter -- can reach it: the getters themselves (which must call the
732
+ // original to avoid recursing into themselves), __ball_to_string's Map
733
+ // printer, the Map-like constructor copy sites, and the map_keys/values/
734
+ // entries base-function helpers (issue #259 -- calling .entries()/etc.
735
+ // as a METHOD on a real Map after the shadow is installed throws, since
736
+ // the getter's return value -- an array -- isn't itself callable).
737
+ const _nativeMapEntries = Map.prototype.entries;
738
+ const _nativeMapKeys = Map.prototype.keys;
739
+ const _nativeMapValues = Map.prototype.values;
740
+
722
741
  (function installBallPolyfills() {
723
742
  const mp: any = Map.prototype;
724
743
  if (!mp.containsKey) mp.containsKey = function (k: any) { return this.has(k); };
@@ -731,7 +750,9 @@ function __ball_cascade(target: any, ops: any[]): any {
731
750
  if (!mp.addAll) {
732
751
  mp.addAll = function (other: any) {
733
752
  if (other instanceof Map) {
734
- for (const [k, v] of other.entries()) this.set(k, v);
753
+ // _nativeMapEntries, not other.entries() -- see __ball_to_string's
754
+ // Map printer above for why (issue #259).
755
+ for (const [k, v] of _nativeMapEntries.call(other)) this.set(k, v);
735
756
  } else if (other && typeof other === 'object') {
736
757
  for (const k of Object.keys(other)) this.set(k, other[k]);
737
758
  }
@@ -908,7 +929,8 @@ function __ball_cascade(target: any, ops: any[]): any {
908
929
  value: function (other: any) {
909
930
  if (this instanceof Map) {
910
931
  if (other instanceof Map) {
911
- for (const [k, v] of other.entries()) this.set(k, v);
932
+ // _nativeMapEntries, not other.entries() (issue #259).
933
+ for (const [k, v] of _nativeMapEntries.call(other)) this.set(k, v);
912
934
  } else if (other && typeof other === 'object') {
913
935
  for (const k of Object.keys(other)) this.set(k, other[k]);
914
936
  }
@@ -961,9 +983,9 @@ function __ball_cascade(target: any, ops: any[]): any {
961
983
  // JS Map has them as METHODS (need parens). The compiled engine
962
984
  // accesses map.entries as a getter. Shadow BOTH Map.prototype AND
963
985
  // Object.prototype so Map and plain-object dispatch tables work.
964
- const _nativeMapEntries = Map.prototype.entries;
965
- const _nativeMapKeys = Map.prototype.keys;
966
- const _nativeMapValues = Map.prototype.values;
986
+ // (_nativeMapEntries/_nativeMapKeys/_nativeMapValues are captured at
987
+ // top level above, not here, so other call sites outside this IIFE
988
+ // can reach them too -- issue #259.)
967
989
  // Shadow Map.prototype.entries with a getter (Dart uses it as a getter).
968
990
  Object.defineProperty(Map.prototype, 'entries', {
969
991
  configurable: true, enumerable: false,
@@ -1087,7 +1109,10 @@ function __ball_cascade(target: any, ops: any[]): any {
1087
1109
  // Map" check, exposed as top-level helpers so compileStdCall's emitted code
1088
1110
  // can call them (#218).
1089
1111
  function __ball_map_keys(m: any): any {
1090
- if (m instanceof Map) return [...m.keys()];
1112
+ // _nativeMapKeys, not m.keys() -- m.keys() would hit the Dart-property-
1113
+ // style getter shadowing Map.prototype.keys and try to invoke its
1114
+ // return value (an array) as a function (issue #259).
1115
+ if (m instanceof Map) return [..._nativeMapKeys.call(m)];
1091
1116
  if (typeof m !== 'object' || m === null || Array.isArray(m) ||
1092
1117
  m instanceof BallDouble || m instanceof Set ||
1093
1118
  m instanceof Number || m instanceof String || m instanceof Boolean) {
@@ -1096,7 +1121,8 @@ function __ball_map_keys(m: any): any {
1096
1121
  return Object.keys(m);
1097
1122
  }
1098
1123
  function __ball_map_values(m: any): any {
1099
- if (m instanceof Map) return [...m.values()];
1124
+ // _nativeMapValues, not m.values() (issue #259 -- see __ball_map_keys).
1125
+ if (m instanceof Map) return [..._nativeMapValues.call(m)];
1100
1126
  if (typeof m !== 'object' || m === null || Array.isArray(m) ||
1101
1127
  m instanceof BallDouble || m instanceof Set ||
1102
1128
  m instanceof Number || m instanceof String || m instanceof Boolean) {
@@ -1105,7 +1131,8 @@ function __ball_map_values(m: any): any {
1105
1131
  return Object.values(m);
1106
1132
  }
1107
1133
  function __ball_map_entries(m: any): any {
1108
- if (m instanceof Map) return [...m.entries()].map(([k, v]) => ({ key: k, value: v }));
1134
+ // _nativeMapEntries, not m.entries() (issue #259 -- see __ball_map_keys).
1135
+ if (m instanceof Map) return [..._nativeMapEntries.call(m)].map(([k, v]) => ({ key: k, value: v }));
1109
1136
  if (typeof m !== 'object' || m === null || Array.isArray(m) ||
1110
1137
  m instanceof BallDouble || m instanceof Set ||
1111
1138
  m instanceof Number || m instanceof String || m instanceof Boolean) {
@@ -1 +1 @@
1
-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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0gD5C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ball-lang/compiler",
3
- "version": "1.7.6",
3
+ "version": "1.7.8",
4
4
  "description": "Ball → TypeScript compiler. Consumes a Ball protobuf Program and emits idiomatic TypeScript via ts-morph. The canonical TS compiler for Ball — lives in TS land so TS syntax knowledge doesn't leak into other languages.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/compiler.ts CHANGED
@@ -3788,7 +3788,16 @@ function __isUnknownFnError(e: any): boolean {
3788
3788
  if (lit.listValue) {
3789
3789
  return this.compileListElements(lit.listValue.elements ?? []);
3790
3790
  }
3791
- if (lit.bytesValue !== undefined) return "/* bytes */ new Uint8Array()";
3791
+ if (lit.bytesValue !== undefined) {
3792
+ // lit.bytesValue is the raw proto3-JSON value: base64, un-decoded (this
3793
+ // compiler's Literal type is a plain JSON DTO, not a protobuf-es
3794
+ // message — unlike Dart's compiler, which reads a real protobuf
3795
+ // `Literal` whose bytes field is already raw). Emit a runtime decode
3796
+ // (Node has a global `atob` since v16) so the ACTUAL bytes land, rather
3797
+ // than discarding them. (issue #244: this previously always emitted an
3798
+ // empty Uint8Array regardless of the source bytes.)
3799
+ return `Uint8Array.from(atob(${jsStringLiteral(lit.bytesValue)}), c => c.charCodeAt(0))`;
3800
+ }
3792
3801
  return "null";
3793
3802
  }
3794
3803
 
package/src/preamble.ts CHANGED
@@ -247,7 +247,11 @@ function __ball_to_string(v: any): string {
247
247
  }
248
248
  if (v instanceof Map) {
249
249
  const parts: string[] = [];
250
- for (const [k, val] of v.entries()) {
250
+ // v.entries() as a method call would hit the Dart-property-style
251
+ // getter of the same name (installed further down in this file) and
252
+ // try to invoke its return value -- an array -- as a function.
253
+ // _nativeMapEntries is the real, un-shadowed method (issue #259).
254
+ for (const [k, val] of _nativeMapEntries.call(v)) {
251
255
  parts.push(__ball_to_string(k) + ': ' + __ball_to_string(val));
252
256
  }
253
257
  return '{' + parts.join(', ') + '}';
@@ -719,6 +723,21 @@ function __ball_cascade(target: any, ops: any[]): any {
719
723
  // ── Dart \u2192 JS method-name polyfills ────────────────────────────────
720
724
  //
721
725
  // Idempotent: guarded so multiple preamble inclusions don't double-install.
726
+
727
+ // Native Map.prototype.entries/keys/values, captured BEFORE the
728
+ // installBallPolyfills IIFE below shadows them with Dart-property-style
729
+ // getters of the same name. Top-level (not IIFE-scoped) so every internal
730
+ // call site that needs the REAL iterator method -- not the property-style
731
+ // getter -- can reach it: the getters themselves (which must call the
732
+ // original to avoid recursing into themselves), __ball_to_string's Map
733
+ // printer, the Map-like constructor copy sites, and the map_keys/values/
734
+ // entries base-function helpers (issue #259 -- calling .entries()/etc.
735
+ // as a METHOD on a real Map after the shadow is installed throws, since
736
+ // the getter's return value -- an array -- isn't itself callable).
737
+ const _nativeMapEntries = Map.prototype.entries;
738
+ const _nativeMapKeys = Map.prototype.keys;
739
+ const _nativeMapValues = Map.prototype.values;
740
+
722
741
  (function installBallPolyfills() {
723
742
  const mp: any = Map.prototype;
724
743
  if (!mp.containsKey) mp.containsKey = function (k: any) { return this.has(k); };
@@ -731,7 +750,9 @@ function __ball_cascade(target: any, ops: any[]): any {
731
750
  if (!mp.addAll) {
732
751
  mp.addAll = function (other: any) {
733
752
  if (other instanceof Map) {
734
- for (const [k, v] of other.entries()) this.set(k, v);
753
+ // _nativeMapEntries, not other.entries() -- see __ball_to_string's
754
+ // Map printer above for why (issue #259).
755
+ for (const [k, v] of _nativeMapEntries.call(other)) this.set(k, v);
735
756
  } else if (other && typeof other === 'object') {
736
757
  for (const k of Object.keys(other)) this.set(k, other[k]);
737
758
  }
@@ -908,7 +929,8 @@ function __ball_cascade(target: any, ops: any[]): any {
908
929
  value: function (other: any) {
909
930
  if (this instanceof Map) {
910
931
  if (other instanceof Map) {
911
- for (const [k, v] of other.entries()) this.set(k, v);
932
+ // _nativeMapEntries, not other.entries() (issue #259).
933
+ for (const [k, v] of _nativeMapEntries.call(other)) this.set(k, v);
912
934
  } else if (other && typeof other === 'object') {
913
935
  for (const k of Object.keys(other)) this.set(k, other[k]);
914
936
  }
@@ -961,9 +983,9 @@ function __ball_cascade(target: any, ops: any[]): any {
961
983
  // JS Map has them as METHODS (need parens). The compiled engine
962
984
  // accesses map.entries as a getter. Shadow BOTH Map.prototype AND
963
985
  // Object.prototype so Map and plain-object dispatch tables work.
964
- const _nativeMapEntries = Map.prototype.entries;
965
- const _nativeMapKeys = Map.prototype.keys;
966
- const _nativeMapValues = Map.prototype.values;
986
+ // (_nativeMapEntries/_nativeMapKeys/_nativeMapValues are captured at
987
+ // top level above, not here, so other call sites outside this IIFE
988
+ // can reach them too -- issue #259.)
967
989
  // Shadow Map.prototype.entries with a getter (Dart uses it as a getter).
968
990
  Object.defineProperty(Map.prototype, 'entries', {
969
991
  configurable: true, enumerable: false,
@@ -1087,7 +1109,10 @@ function __ball_cascade(target: any, ops: any[]): any {
1087
1109
  // Map" check, exposed as top-level helpers so compileStdCall's emitted code
1088
1110
  // can call them (#218).
1089
1111
  function __ball_map_keys(m: any): any {
1090
- if (m instanceof Map) return [...m.keys()];
1112
+ // _nativeMapKeys, not m.keys() -- m.keys() would hit the Dart-property-
1113
+ // style getter shadowing Map.prototype.keys and try to invoke its
1114
+ // return value (an array) as a function (issue #259).
1115
+ if (m instanceof Map) return [..._nativeMapKeys.call(m)];
1091
1116
  if (typeof m !== 'object' || m === null || Array.isArray(m) ||
1092
1117
  m instanceof BallDouble || m instanceof Set ||
1093
1118
  m instanceof Number || m instanceof String || m instanceof Boolean) {
@@ -1096,7 +1121,8 @@ function __ball_map_keys(m: any): any {
1096
1121
  return Object.keys(m);
1097
1122
  }
1098
1123
  function __ball_map_values(m: any): any {
1099
- if (m instanceof Map) return [...m.values()];
1124
+ // _nativeMapValues, not m.values() (issue #259 -- see __ball_map_keys).
1125
+ if (m instanceof Map) return [..._nativeMapValues.call(m)];
1100
1126
  if (typeof m !== 'object' || m === null || Array.isArray(m) ||
1101
1127
  m instanceof BallDouble || m instanceof Set ||
1102
1128
  m instanceof Number || m instanceof String || m instanceof Boolean) {
@@ -1105,7 +1131,8 @@ function __ball_map_values(m: any): any {
1105
1131
  return Object.values(m);
1106
1132
  }
1107
1133
  function __ball_map_entries(m: any): any {
1108
- if (m instanceof Map) return [...m.entries()].map(([k, v]) => ({ key: k, value: v }));
1134
+ // _nativeMapEntries, not m.entries() (issue #259 -- see __ball_map_keys).
1135
+ if (m instanceof Map) return [..._nativeMapEntries.call(m)].map(([k, v]) => ({ key: k, value: v }));
1109
1136
  if (typeof m !== 'object' || m === null || Array.isArray(m) ||
1110
1137
  m instanceof BallDouble || m instanceof Set ||
1111
1138
  m instanceof Number || m instanceof String || m instanceof Boolean) {