@nstudio/nativescript-compiler 9.2.0-alpha.10 → 9.2.0-alpha.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.
Files changed (135) hide show
  1. package/dist/api/ir.js +7 -1
  2. package/dist/driver/cli.js +2 -0
  3. package/dist/driver/compile.js +22 -10
  4. package/dist/driver/unimplemented.js +15 -0
  5. package/dist/kotlin/access.js +22 -4
  6. package/dist/kotlin/arguments.js +5 -0
  7. package/dist/kotlin/builtins.js +0 -4
  8. package/dist/kotlin/calls.js +6 -2
  9. package/dist/kotlin/class-methods.js +9 -3
  10. package/dist/kotlin/components.js +13 -8
  11. package/dist/kotlin/core-api.js +2 -13
  12. package/dist/kotlin/declarations.js +2 -0
  13. package/dist/kotlin/expression-statements.js +5 -4
  14. package/dist/kotlin/functions.js +13 -4
  15. package/dist/kotlin/global-calls.js +11 -0
  16. package/dist/kotlin/literals.js +51 -5
  17. package/dist/kotlin/names.js +2 -2
  18. package/dist/kotlin/native/api.js +9 -1
  19. package/dist/kotlin/native/subclasses.js +4 -3
  20. package/dist/kotlin/native/types.js +8 -5
  21. package/dist/kotlin/operators.js +4 -1
  22. package/dist/kotlin/prototype-calls.js +5 -0
  23. package/dist/kotlin/render.js +62 -0
  24. package/dist/kotlin/statements.js +9 -0
  25. package/dist/kotlin/static-calls.js +4 -3
  26. package/dist/kotlin/types.js +6 -6
  27. package/dist/plugins/native-android.js +7 -3
  28. package/dist/plugins/native-ios.js +2 -0
  29. package/dist/plugins/source.js +73 -23
  30. package/dist/program/app-modules.js +91 -16
  31. package/dist/program/app-paths.js +80 -12
  32. package/dist/program/class-mixins.js +463 -0
  33. package/dist/program/core-facts.js +7 -0
  34. package/dist/program/glob.js +274 -0
  35. package/dist/program/platform.js +32 -4
  36. package/dist/program/program.js +212 -20
  37. package/dist/program/source-lines.js +4 -1
  38. package/dist/program/vite-plugins.js +144 -0
  39. package/dist/semantics/apis/globals.js +2 -2
  40. package/dist/semantics/apis/object.js +1 -0
  41. package/dist/semantics/apis/statics.js +6 -0
  42. package/dist/semantics/ast.js +20 -2
  43. package/dist/semantics/classes.js +36 -1
  44. package/dist/semantics/globals.js +3 -0
  45. package/dist/semantics/lang.js +13 -1
  46. package/dist/semantics/nullish.js +29 -11
  47. package/dist/semantics/refuse-receivers.js +3 -3
  48. package/dist/semantics/refuse-scope.js +2 -7
  49. package/dist/semantics/runtime.js +1 -0
  50. package/dist/semantics/states/value-states.js +1 -1
  51. package/dist/semantics/throws.js +1 -0
  52. package/dist/semantics/translator-methods.js +1 -1
  53. package/dist/semantics/types.js +21 -1
  54. package/dist/swift/access.js +25 -10
  55. package/dist/swift/arguments.js +10 -2
  56. package/dist/swift/assignment.js +12 -1
  57. package/dist/swift/builtins.js +0 -4
  58. package/dist/swift/calls.js +6 -2
  59. package/dist/swift/class-methods.js +3 -3
  60. package/dist/swift/components.js +28 -8
  61. package/dist/swift/construction.js +4 -0
  62. package/dist/swift/core-api.js +9 -12
  63. package/dist/swift/functions.js +13 -2
  64. package/dist/swift/generics.js +5 -1
  65. package/dist/swift/global-calls.js +2 -0
  66. package/dist/swift/literals.js +53 -6
  67. package/dist/swift/names.js +1 -1
  68. package/dist/swift/native/sdk-tables.js +52 -4
  69. package/dist/swift/native/sdk.js +9 -1
  70. package/dist/swift/operators.js +4 -1
  71. package/dist/swift/parameters.js +5 -2
  72. package/dist/swift/placement.js +42 -1
  73. package/dist/swift/prototype-calls.js +17 -2
  74. package/dist/swift/render.js +64 -0
  75. package/dist/swift/results.js +1 -1
  76. package/dist/swift/statements.js +9 -0
  77. package/dist/swift/static-calls.js +8 -3
  78. package/dist/swift/types.js +9 -9
  79. package/dist/targets/android/build.js +13 -9
  80. package/dist/targets/ios/build.js +11 -10
  81. package/dist/targets/ios/dependencies.js +12 -0
  82. package/dist/targets/resources.js +15 -1
  83. package/dist/template/plan.js +105 -8
  84. package/dist/types/adapter-api.d.ts +13 -0
  85. package/dist/types/ir.d.ts +47 -0
  86. package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +102 -7485
  87. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -3
  88. package/kit-android/generated/source-lines.json +1 -1
  89. package/kit-android/src/fromcore/kotlin/org/nativescript/kit/CoreBridge.kt +67 -1
  90. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +26 -0
  91. package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +4 -4
  92. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +24 -146
  93. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +0 -281
  94. package/kit-apple/Sources/NativeScriptKit/Core/{Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_91b5f3.swift → Object_iterator_prototype_for_keyFor_hasInstance_isConcatSpreadable_and_19_more_fa18e1.swift} +28 -103
  95. package/kit-apple/Sources/NativeScriptKit/Core/__Namespace.Utils.swift +17 -15
  96. package/kit-apple/Sources/NativeScriptKit/Core/application-settings.index.ios.swift +8 -8
  97. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +4 -4
  98. package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +7 -7
  99. package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +2 -1
  100. package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +1 -1
  101. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +34 -244
  102. package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +1 -2
  103. package/kit-apple/Sources/NativeScriptKit/Core/ui.action-bar.index.ios.swift +3 -3
  104. package/kit-apple/Sources/NativeScriptKit/Core/ui.button.index.ios.swift +4 -4
  105. package/kit-apple/Sources/NativeScriptKit/Core/ui.content-view.index.swift +8 -8
  106. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +4 -4
  107. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
  108. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -3
  109. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-helper.view-helper-common.swift +7 -7
  110. package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +4 -4
  111. package/kit-apple/Sources/NativeScriptKit/Core/ui.html-view.index.ios.swift +4 -4
  112. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.image-common.swift +2 -2
  113. package/kit-apple/Sources/NativeScriptKit/Core/ui.image.index.ios.swift +4 -4
  114. package/kit-apple/Sources/NativeScriptKit/Core/ui.label.index.ios.swift +4 -4
  115. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.absolute-layout.index.ios.swift +4 -4
  116. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.dock-layout.index.ios.swift +4 -4
  117. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +3 -3
  118. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.grid-layout.index.ios.swift +4 -4
  119. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.stack-layout.index.ios.swift +4 -4
  120. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.wrap-layout.index.ios.swift +4 -4
  121. package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +3 -3
  122. package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +4 -4
  123. package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +4 -4
  124. package/kit-apple/Sources/NativeScriptKit/Core/ui.scroll-view.index.ios.swift +4 -4
  125. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +4 -4
  126. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +1 -1
  127. package/kit-apple/Sources/NativeScriptKit/Core/ui.tab-view.index.ios.swift +4 -4
  128. package/kit-apple/Sources/NativeScriptKit/Core/utils.common.swift +9 -9
  129. package/kit-apple/Sources/NativeScriptKit/Core/utils.layout-helper.index.ios.swift +10 -10
  130. package/kit-apple/Sources/NativeScriptKit/CoreBridge.swift +67 -1
  131. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +4 -0
  132. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +25 -0
  133. package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +6 -0
  134. package/package.json +1 -1
  135. package/kit-apple/Sources/NativeScriptKit/Core/Object_toString_charAt_charCodeAt_concat_indexOf_lastIndexOf_and_44_more_fc25df.swift +0 -481
@@ -199,9 +199,9 @@ export const namesMethods = {
199
199
  const ref = this.refName(e);
200
200
  const self = fnDecl.parameters.find((q) => isThisParameter(q) && !this.voidThis(q));
201
201
  // A function taking `this` as a value (a property descriptor's `set`): the receiver is the caller's.
202
- if ((self || this.implicitThis(fnDecl)) && !this.readsArguments(fnDecl)) {
202
+ if (self || this.implicitThis(fnDecl)) {
203
203
  const thisType = self ? this.type(this.checker.getTypeAtLocation(self.name), self) : 'Any?';
204
- const args = fnDecl.parameters.filter((q) => !isThisParameter(q)).map((q, k) => (q.dotDotDotToken ? `JSArray(__a.drop(${k}).map { ${this.fromAnyCode('it', this.typeOf(q.name).replace(/^JSArray<(.*)>$/, '$1'), true)} }.toMutableList())` : this.fromAnyCode(this.marks.pureCode(`__a.getOrNull(${k})`), this.paramType(q), true)));
204
+ const args = this.readsArguments(fnDecl) ? ['JSArray(__a.toMutableList())'] : fnDecl.parameters.filter((q) => !isThisParameter(q)).map((q, k) => (q.dotDotDotToken ? `JSArray(__a.drop(${k}).map { ${this.fromAnyCode('it', this.typeOf(q.name).replace(/^JSArray<(.*)>$/, '$1'), true)} }.toMutableList())` : this.fromAnyCode(this.marks.pureCode(`__a.getOrNull(${k})`), this.paramType(q), true)));
205
205
  return `JSMethod ${lambda(['__self', '__a'], `${ref}(${[isUntyped(spelledType(thisType)) ? '__self' : this.fromAnyCode('__self', thisType, true), ...args].join(', ')})`)}`;
206
206
  }
207
207
  // Library mode: a function of an optional string, number or boolean held as a value (a shorthand's converter) may be given
@@ -1,5 +1,5 @@
1
1
  import ts from 'typescript';
2
- import { ACC_FINAL, ACC_STATIC, methodTypes } from "./classfiles.js";
2
+ import { ACC_BRIDGE, ACC_FINAL, ACC_STATIC, ACC_SYNTHETIC, methodTypes } from "./classfiles.js";
3
3
  import { ANDROID_TYPINGS } from "./bridging.js";
4
4
  import { nativeTypesMethods } from "./types.js";
5
5
  import { nativeMembersMethods } from "./members.js";
@@ -106,6 +106,14 @@ export class AndroidNativeAPI {
106
106
  const fits = pool.filter((c) => kinds.every((k, i) => k.kind === 'any' || this.score(k, c.params[i]) !== null));
107
107
  if (fits.length === 1 || (every && fits.length))
108
108
  return fits;
109
+ if (fits.length > 1) {
110
+ const nonBridge = fits.filter((c) => !(c.m.access & (ACC_BRIDGE | ACC_SYNTHETIC)));
111
+ if (nonBridge.length === 1)
112
+ return nonBridge;
113
+ const concrete = (nonBridge.length ? nonBridge : fits).filter((c) => !c.params.some((p) => p === 'Ljava/lang/Object;'));
114
+ if (concrete.length === 1)
115
+ return concrete;
116
+ }
109
117
  throw this.t.error(fn, `${name} (matches ${pool.map((c) => this.display(c.m.owner, name, c)).join(' and ')}; declare its parameter types)`, 'native');
110
118
  }
111
119
  /** What `Base.extend({ … })` calls make (extend.ts), by call and by the variable holding one, and the files scanned for them. */
@@ -210,8 +210,9 @@ ${indent}}`;
210
210
  for (const p of literal.properties) {
211
211
  const name = p.name?.getText().replace(/^['"]|['"]$/g, '') ?? '';
212
212
  const fn = ts.isMethodDeclaration(p) ? p : ts.isPropertyAssignment(p) && (ts.isArrowFunction(p.initializer) || ts.isFunctionExpression(p.initializer)) ? p.initializer : null;
213
- // A function value (`this.onTouch.bind(this)`): the override calls it.
214
- const value = !fn && ts.isPropertyAssignment(p) ? t.checker.getTypeAtLocation(p.initializer).getCallSignatures()[0] : undefined;
213
+ // A function value (`this.onTouch.bind(this)`, `{ onDismiss }`): the override calls it.
214
+ const valueExpr = !fn && ts.isPropertyAssignment(p) ? p.initializer : !fn && ts.isShorthandPropertyAssignment(p) ? p.name : undefined;
215
+ const value = valueExpr ? t.checker.getTypeAtLocation(valueExpr).getCallSignatures()[0] : undefined;
215
216
  const declared = value?.getDeclaration();
216
217
  if (!fn && !(declared && !ts.isJSDocSignature(declared)))
217
218
  throw t.error(p, `${name} in an implementation of ${javaTypeName(`L${cls.name};`)} (only methods and functions)`, 'native');
@@ -219,7 +220,7 @@ ${indent}}`;
219
220
  if (!target)
220
221
  throw t.error(p, `${name} (${javaTypeName(`L${cls.name};`)} has no method of that name to implement)`, 'native');
221
222
  provided.add(name);
222
- members.push(fn ? this.overrideMethod(fn, name, target, base + ' ', ownerVar(target.m.owner)) : this.overrideWithValue(p.initializer, declared, name, target, base + ' ', ownerVar(target.m.owner)));
223
+ members.push(fn ? this.overrideMethod(fn, name, target, base + ' ', ownerVar(target.m.owner)) : this.overrideWithValue(valueExpr, declared, name, target, base + ' ', ownerVar(target.m.owner)));
223
224
  }
224
225
  if (isInterface) {
225
226
  const objectMethods = new Set((this.classpath.get('java/lang/Object')?.methods ?? []).map((m) => m.name + m.descriptor));
@@ -23,8 +23,8 @@ export const nativeTypesMethods = {
23
23
  for (let k = segs.length - 1; k >= 1 && !found; k--)
24
24
  found = this.classpath.get(`${segs.slice(0, k).join('/')}/${segs.slice(k).join('$')}`);
25
25
  this.symbols.set(sym, found);
26
- // Library mode: a type core's code names that no Android version has (`View.androidviewViewAccessibilityDelegate`), untyped.
27
- if (!found && this.t.library)
26
+ // Library mode or plugin code naming another platform's class (`NativeScript.Mason.TextNode`, `MasonTextWrap`), untyped.
27
+ if (!found && (this.t.library || this.t.pluginFiles.has(where?.getSourceFile().fileName ?? this.t.currentFile ?? '')))
28
28
  return null;
29
29
  if (!found)
30
30
  throw this.t.error(where, `${segs.join('.')} (no class file on the classpath: android.jar, the widgets AAR, androidx in the Gradle cache)`, 'native');
@@ -403,15 +403,18 @@ export const nativeTypesMethods = {
403
403
  if (!base)
404
404
  return null;
405
405
  const interfaces = [];
406
- const add = (e) => {
407
- const i = this.classOf(this.t.resolve(e), e);
406
+ const add = (e, skipNonNative = false) => {
407
+ const sym = this.t.resolve(e);
408
+ if (skipNonNative && !this.isNativeSymbol(sym))
409
+ return;
410
+ const i = this.classOf(sym, e);
408
411
  if (!i || !(i.access & ACC_INTERFACE))
409
412
  throw this.t.error(e, `${e.getText()} (not a Java interface)`, 'native');
410
413
  if (!interfaces.includes(i))
411
414
  interfaces.push(i);
412
415
  };
413
416
  for (const i of cls.heritageClauses?.find((h) => h.token === ts.SyntaxKind.ImplementsKeyword)?.types ?? [])
414
- add(i.expression);
417
+ add(i.expression, true);
415
418
  const listed = cls.members.find((m) => ts.isPropertyDeclaration(m) && m.name.getText() === 'interfaces' && hasStatic(m));
416
419
  if (listed?.initializer && ts.isArrayLiteralExpression(listed.initializer))
417
420
  for (const e of listed.initializer.elements)
@@ -8,7 +8,7 @@ import { located } from "../semantics/refusals.js";
8
8
  import { notedField } from "../semantics/shapes.js";
9
9
  import { isKit, isUntyped, spelledType } from "../semantics/types.js";
10
10
  import { assertedFrom, emptyComparison, scriptComparison } from "../semantics/placement.js";
11
- import { constClassExpr } from "../semantics/classes.js";
11
+ import { constClassExpr, hasInstanceClass } from "../semantics/classes.js";
12
12
  import { isLibDeclaration } from "../semantics/ast.js";
13
13
  import { nullAs } from "./expressions.js";
14
14
  import { bigIntArithmetic, bigIntCompare, bigIntPlan } from "../semantics/apis/bigint.js";
@@ -250,6 +250,9 @@ export const operatorsMethods = {
250
250
  return heldRight ? this.undefinedAs(chosen, t) : chosen;
251
251
  }
252
252
  case K.InstanceOfKeyword: {
253
+ const hi = hasInstanceClass(e.right, this.checker);
254
+ if (hi)
255
+ return `${this.className(hi)}.jsHasInstance(${this.coerce(e.left, 'Any?')})`;
253
256
  const rhsExpr = constClassExpr(e.right, this.checker);
254
257
  if (rhsExpr)
255
258
  return `(${this.observed(e.left)} is ${this.emitClassExprCode(rhsExpr)})`;
@@ -125,6 +125,11 @@ export const prototypeCallsMethods = {
125
125
  .map((n, k) => `${n}: ${parts.params[given.length + k]}`)
126
126
  .join(', ')} -> ${fn}(${[...fixed, ...names.slice(given.length)].join(', ')}) }`;
127
127
  }
128
+ const targetDecl = ts.isIdentifier(target) ? this.resolve(target)?.valueDeclaration : undefined;
129
+ if (method === 'call' && targetDecl && !ts.isJSDocSignature(targetDecl) && ts.isFunctionLike(targetDecl) && this.readsArguments(targetDecl)) {
130
+ const selfArg = takesThis ? [thisArg ? this.coerce(thisArg, parts.params[0]) : 'null'] : [];
131
+ return `${fn}(${[...selfArg, this.packed(rest, 'JSArray<Any?>', this.restSlot(e, 'Any?'))].join(', ')})`;
132
+ }
128
133
  const args = parts.params.map((t, k) => (given[k] ? this.coerce(given[k], t) : t.endsWith('?') ? 'null' : (this.zero(t) ?? 'null')));
129
134
  return `${fn}(${args.join(', ')})`;
130
135
  },
@@ -173,6 +173,66 @@ export function render(c, components, options = {}) {
173
173
  return say(depth, s.detached ? `val ${s.name} = Region(null)` : `val ${s.name} = ${s.parent}.kitAddRegion()`);
174
174
  case 'addRegion':
175
175
  return say(depth, `${s.parent}.kitAddRegion(${s.region})`);
176
+ case 'setSlot': {
177
+ say(depth, `${s.component}.__slots[${kotlinString(s.name)}] = { __sr: Region ->`);
178
+ const wrap = s.scope ? scope(s.scope) : null;
179
+ const d = wrap ? depth + 2 : depth + 1;
180
+ if (wrap)
181
+ say(depth + 1, wrap);
182
+ if (s.viewMark)
183
+ say(d, 'val __view = EffectOrder.current');
184
+ say(d, `val ${s.body.fragment} = RegionFragment(__sr)`);
185
+ steps(s.body.steps, d);
186
+ say(d, `${s.body.fragment}.fill()`);
187
+ if (wrap)
188
+ say(depth + 1, '}');
189
+ return say(depth, '}');
190
+ }
191
+ case 'slot': {
192
+ const host = regionHost(s.host);
193
+ if (s.fallback) {
194
+ say(depth, `this.__slots[${kotlinString(s.name)}]?.invoke(${host}) ?: run {`);
195
+ say(depth + 1, `val ${s.fallback.fragment} = RegionFragment(${host})`);
196
+ steps(s.fallback.steps, depth + 1);
197
+ say(depth + 1, `${s.fallback.fragment}.fill()`);
198
+ return say(depth, '}');
199
+ }
200
+ return say(depth, `this.__slots[${kotlinString(s.name)}]?.invoke(${host})`);
201
+ }
202
+ case 'componentOutlet': {
203
+ const host = regionHost(s.host);
204
+ const inj = s.injector ? `, injector = { ${call(s.injector)} }` : '';
205
+ const inp = s.inputs ? `, inputs = { ${call(s.inputs)} }` : '';
206
+ return say(depth, `${s.call}(${host}, { ${call(s.component)} }${inj}${inp})`);
207
+ }
208
+ case 'templateOutlet': {
209
+ const host = regionHost(s.host);
210
+ const ctx = s.context ? `, context = { ${call(s.context)} }` : '';
211
+ return say(depth, `${s.call}(${host}, { ${call(s.template)} }${ctx})`);
212
+ }
213
+ case 'bindTemplate':
214
+ case 'structural': {
215
+ const open = s.kind === 'bindTemplate' ? `TemplateOutlet.bind(this.${ident(s.field)})` : `val ${s.tplName} = TemplateOutlet.make`;
216
+ say(depth, `${open} { __sr: Region, ${s.ctxParam}: Any? ->`);
217
+ const wrap = s.scope ? scope(s.scope) : null;
218
+ const d = wrap ? depth + 2 : depth + 1;
219
+ if (wrap)
220
+ say(depth + 1, wrap);
221
+ if (s.viewMark)
222
+ say(d, 'val __view = EffectOrder.current');
223
+ say(d, `val ${s.body.fragment} = RegionFragment(__sr)`);
224
+ steps(s.body.steps, d);
225
+ say(d, `${s.body.fragment}.fill()`);
226
+ if (wrap)
227
+ say(depth + 1, '}');
228
+ say(depth, '}');
229
+ if (s.kind === 'structural') {
230
+ say(depth, `${s.call}(${s.region}, ${s.tplName}) {`);
231
+ steps(s.steps, depth + 1);
232
+ say(depth, '}');
233
+ }
234
+ return;
235
+ }
176
236
  case 'choose': {
177
237
  const host = regionHost(s.host);
178
238
  const which = s.conds.map((k, i) => (k ? `if (${cond(k, s.caught)}) ${i} else ` : `${i}`)).join('') + (s.conds.at(-1) ? `${s.conds.length}` : '');
@@ -262,6 +322,8 @@ export function render(c, components, options = {}) {
262
322
  };
263
323
  const passes = plan.passes;
264
324
  const m = plan.members;
325
+ if (plan.hasSlots)
326
+ say(1, 'var __slots: MutableMap<String, (Region) -> Unit> = mutableMapOf()');
265
327
  if (passes) {
266
328
  // Both passes, with the hooks a parent runs for its child between and after them.
267
329
  const hooks = (list) => list.map((h) => (h.flush ? `${h.flush}(this)` : h.every ? `${h.every} { this.${h.member}() }` : `this.${h.member}()`)).join('; ');
@@ -255,6 +255,15 @@ export const statementsMethods = {
255
255
  });
256
256
  }
257
257
  if (ts.isForInStatement(s)) {
258
+ if (!ts.isVariableDeclarationList(s.initializer)) {
259
+ const k = this.fresh('__key');
260
+ const assigns = this.assignIterated(s.initializer, k, this.checker.getStringType(), s.expression);
261
+ return this.loopBody(() => {
262
+ const label = this.takeLabel();
263
+ const body = this.block(s.statement);
264
+ return `${i}${label}for (${k} in ${RT.jsKeysOf}(${this.expr(s.expression)})) {\n${assigns.map((a) => `${i} ${a}`).join('\n')}\n${body.slice(2)}`;
265
+ });
266
+ }
258
267
  const list = s.initializer;
259
268
  const name = ident(list.declarations[0].name.text);
260
269
  if (!assignsTo(s.statement, this.checker.getSymbolAtLocation(list.declarations[0].name), this.checker))
@@ -4,6 +4,7 @@ import ts from 'typescript';
4
4
  import { TYPED_ARRAYS } from "../semantics/globals.js";
5
5
  import { ident, isThisParameter, optionalType, RT } from "./syntax.js";
6
6
  import { undefinedLiteral } from "../semantics/lang.js";
7
+ import { arrayFromLengthInit } from "../semantics/ast.js";
7
8
  import { assignsArrayIntoObject } from "../semantics/shapes.js";
8
9
  import { CONSOLE } from "../semantics/apis/console.js";
9
10
  import { staticFunction } from "../semantics/apis/statics.js";
@@ -125,9 +126,9 @@ export const staticCallsMethods = {
125
126
  if (method === 'from' && e.arguments.length === 1)
126
127
  return `JSArray(${this.iterable(arg(0))}.toList())`;
127
128
  if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3) && ts.isObjectLiteralExpression(arg(0))) {
128
- const length = arg(0).properties.find((p) => p.name?.getText() === 'length');
129
+ const lenExpr = arrayFromLengthInit(arg(0));
129
130
  const fn = arg(1);
130
- if (!length || !ts.isPropertyAssignment(length) || !(ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)))
131
+ if (!lenExpr || !(ts.isArrowFunction(fn) || ts.isFunctionExpression(fn)))
131
132
  throw this.error(e, 'Array.from of this object');
132
133
  const el = T().replace(/^JSArray<(.*)>$/, '$1');
133
134
  const params = fn.parameters.filter((p) => !isThisParameter(p));
@@ -135,7 +136,7 @@ export const staticCallsMethods = {
135
136
  const value = params[0] && ts.isIdentifier(params[0].name) && params[0].name.text !== '_' ? `val ${ident(params[0].name.text)}: Any? = null; ` : '';
136
137
  return this.ignoringThisArg(e, arg(0), () => {
137
138
  const body = ts.isBlock(fn.body) ? this.functionBody(fn, el, this.indent) : `{ return ${this.coerce(fn.body, el)} }`;
138
- return `JSArray.fromLength<${el}>(${this.toNumber(length.initializer)}, fun(${index}: Double): ${el} { ${value}${body.slice(1, -1)} })`;
139
+ return `JSArray.fromLength<${el}>(${this.toNumber(lenExpr)}, fun(${index}: Double): ${el} { ${value}${body.slice(1, -1)} })`;
139
140
  });
140
141
  }
141
142
  if (method === 'from' && (e.arguments.length === 2 || e.arguments.length === 3))
@@ -7,7 +7,7 @@ import { ambientBase, evolvingArrayRead, evolvingArrayType, isAmbientClass, isRe
7
7
  import { nullishSignalType } from "../semantics/signals.js";
8
8
  import { hasModifier, isLibDeclaration, thisNodes, isWriteTarget, implementationOf, takesOwnThis } from "../semantics/ast.js";
9
9
  import { isCoreDeclaration } from "../program/core-facts.js";
10
- import { coreTypeKind, eventDataTypeLiteral, isJsDocConstructorFunction, isKit, isLibObjectType, isNamed, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType } from "../semantics/types.js";
10
+ import { coreTypeKind, eventDataTypeLiteral, hasMappedIntersection, isJsDocConstructorFunction, isKit, isLibObjectType, isNamed, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType, valueModuleKind } from "../semantics/types.js";
11
11
  import { isStatic } from "../semantics/throws.js";
12
12
  import { literalOverArray, membersOverTypeParameter, untypedResultBinding, untypedResultField } from "../semantics/shapes.js";
13
13
  import { extendedClass, isEventData } from "../semantics/classes.js";
@@ -34,10 +34,10 @@ export const typesMethods = {
34
34
  const component = t.getSymbol()?.flags & ts.SymbolFlags.Class ? t.getSymbol().declarations?.[0] : undefined;
35
35
  if (component && ts.isClassDeclaration(component) && this.pluginFiles.has(component.getSourceFile().fileName) && this.framework.componentClass(component))
36
36
  return 'Any?';
37
- // A namespace as a value (`{ Kinds: Trace.Kinds }`): its object.
38
- const nsDecl = t.flags & F.Object && t.getSymbol()?.flags & ts.SymbolFlags.ValueModule ? t.getSymbol().valueDeclaration : undefined;
39
- if (nsDecl && ts.isModuleDeclaration(nsDecl) && !nsDecl.getSourceFile().isDeclarationFile)
40
- return this.namespacePath(nsDecl);
37
+ // A namespace as a value (`{ Kinds: Trace.Kinds }`) or an ES module namespace (`typeof import('...')`).
38
+ const ns = valueModuleKind(t);
39
+ if (ns)
40
+ return ns === 'module' ? 'Any?' : this.namespacePath(ns);
41
41
  // An enum as a value (`typeof Color`) in app code: the object JavaScript makes of it. Not the enum's own name, through
42
42
  // which its members are read (`Color.Red`).
43
43
  const enumObject = !this.library && t.flags & F.Object && (t.getSymbol()?.flags ?? 0) & ts.SymbolFlags.RegularEnum ? t.getSymbol().valueDeclaration : undefined;
@@ -103,7 +103,7 @@ export const typesMethods = {
103
103
  const bound = t.types.map((u) => (u.flags & F.TypeParameter ? this.checker.getBaseConstraintOfType(u) : undefined)).find((u) => u && u.flags & (F.String | F.Number | F.Boolean));
104
104
  if (bound && t.types.every((u) => u.flags & (F.TypeParameter | F.Conditional)))
105
105
  return this.type(bound, where);
106
- if (membersOverTypeParameter(t, this.checker))
106
+ if (membersOverTypeParameter(t, this.checker) || hasMappedIntersection(t))
107
107
  return 'Any?';
108
108
  // A function carrying properties (`((p: P) => R) & { type: string }`): an untyped value, called as script calls it.
109
109
  if (t.types.some((u) => u.getCallSignatures().length) && t.types.some((u) => !u.getCallSignatures().length && u.getProperties().length) && !t.types.some((u) => isLibDeclaration(u.getSymbol()?.declarations?.[0])))
@@ -88,10 +88,12 @@ export function pluginNativeAndroid(sources, options) {
88
88
  if (errors.length)
89
89
  throw new Error(`plugins' Android code that cannot be built yet:\n ${errors.join('\n ')}`);
90
90
  const dependencies = includes.flatMap((i) => i.dependencies);
91
+ const sharedDeps = [...new Map(dependencies.filter((d) => d.configuration !== 'annotationProcessor').map((d) => [d.coords, d.coords])).values()];
92
+ const sharedRepos = [...new Set(includes.flatMap((i) => i.repositories))];
91
93
  // A cached AAR is rebuilt when a dependency it declares is not in Gradle's cache: the translation reads its classes from there.
92
94
  const stale = libraries.filter((l) => !existsSync(l.aar) || l.include?.dependencies.some((d) => !inGradleCache(d.coords)));
93
95
  if (stale.length || fetches.length)
94
- buildLibraries([...stale, ...fetches], options);
96
+ buildLibraries([...stale, ...fetches], options, sharedDeps, sharedRepos);
95
97
  archives.push(...libraries.map((l) => l.aar));
96
98
  return {
97
99
  archives,
@@ -129,7 +131,7 @@ function inGradleCache(coords) {
129
131
  return !version || /[+\[\]()]/.test(version) || existsSync(join(GRADLE_CACHE, group, artifact, version));
130
132
  }
131
133
  /** One Gradle build of every library not in the cache, a subproject each, with the kit's wrapper. */
132
- function buildLibraries(libraries, options) {
134
+ function buildLibraries(libraries, options, sharedDeps = [], sharedRepos = []) {
133
135
  const cache = options.cache ?? DEFAULT_CACHE;
134
136
  mkdirSync(cache, { recursive: true });
135
137
  const root = mkdtempSync(join(cache, '.build-'));
@@ -182,8 +184,10 @@ kotlin {
182
184
  repositories {
183
185
  google()
184
186
  mavenCentral()
187
+ ${sharedRepos.map((r) => ` maven { url = ${q(r)} }`).join('\n')}
185
188
  }
186
189
 
190
+ ${sharedDeps.length ? `dependencies {\n${sharedDeps.map((c) => ` implementation ${q(c)}`).join('\n')}\n}\n` : ''}
187
191
  ${l.include?.libraryBlocks.join('\n\n') ?? ''}
188
192
  `);
189
193
  });
@@ -207,7 +211,7 @@ ${l.include?.libraryBlocks.join('\n\n') ?? ''}
207
211
  rmSync(root, { recursive: true, force: true });
208
212
  }
209
213
  }
210
- const CONFIGURATIONS = { implementation: 'implementation', api: 'implementation', compileOnly: 'compileOnly', runtimeOnly: 'runtimeOnly' };
214
+ const CONFIGURATIONS = { implementation: 'implementation', api: 'implementation', compileOnly: 'compileOnly', runtimeOnly: 'runtimeOnly', annotationProcessor: 'annotationProcessor' };
211
215
  const KNOWN_REPOSITORIES = new Set(['google', 'mavenCentral']);
212
216
  /**
213
217
  * The parts of an include.gradle the app's build takes: `dependencies` of
@@ -261,6 +261,8 @@ function targetsOf(source, errors, deps) {
261
261
  else
262
262
  walk(p);
263
263
  }
264
+ else if (f === 'Package.swift')
265
+ continue;
264
266
  else if (f.endsWith('.swift'))
265
267
  swift.push(p);
266
268
  else if (/\.(h|hh|hpp|m|mm|c|cc|cpp)$/.test(f))
@@ -48,7 +48,19 @@ export class PluginSources {
48
48
  * Checks source files the build compiles against the published files they
49
49
  * were built from, once each: what is compiled is what npm installed.
50
50
  */
51
- verify(sources) {
51
+ verify(sources, onMismatch) {
52
+ const check = (fn) => {
53
+ if (!onMismatch) {
54
+ fn();
55
+ return;
56
+ }
57
+ try {
58
+ fn();
59
+ }
60
+ catch (e) {
61
+ onMismatch(e.message.split('\n')[0]);
62
+ }
63
+ };
52
64
  for (const src of sources) {
53
65
  for (const source of this.packages.values()) {
54
66
  // A bundle is checked when any source it bundles is compiled: its entry may be an index that only re-exports.
@@ -56,15 +68,15 @@ export class PluginSources {
56
68
  const matches = [...source.files].filter(([j, s]) => s === src || !!source.bundles.get(j)?.files.includes(src)).map(([j]) => j);
57
69
  const js = matches.find((j) => isEsModule(j)) ?? matches[0];
58
70
  if (js && !source.checked.has(js) && source.verified === 'shipped')
59
- verifyMap(source.name, js, this.options.app, source.version);
60
- if (!js)
71
+ check(() => verifyMap(source.name, js, this.options.app, source.version));
72
+ if (!js || src === js)
61
73
  continue;
62
74
  if (!source.checked.has(js) && source.verified === 'published') {
63
75
  const bundle = source.bundles.get(js);
64
76
  if (bundle)
65
- verifyBundle(source.name, js, bundle, this.options.app, source.version);
77
+ check(() => verifyBundle(source.name, js, bundle, this.options.app, source.version));
66
78
  else
67
- verify(source.name, js, src, this.options.app, source.version);
79
+ check(() => verify(source.name, js, src, this.options.app, source.version));
68
80
  }
69
81
  source.checked.add(js);
70
82
  }
@@ -390,13 +402,17 @@ function shipsJsSource(dir, pkg) {
390
402
  }
391
403
  return true;
392
404
  }
393
- /** Whether a JavaScript file uses CommonJS syntax (`require(...)` or `module.exports`/`exports.`). */
405
+ /** Whether a JavaScript file uses CommonJS syntax (`require(...)` or unconditional `module.exports`/`exports.`). */
394
406
  function isCommonJsModule(js) {
395
407
  try {
396
408
  const text = readFileSync(js, 'utf8');
397
409
  if (/(?:^|\n)\s*(?:import\s|export\s)/.test(text))
398
410
  return false;
399
- return /\b(?:module\.exports|exports\.[A-Za-z_$]|require\s*\()/.test(text);
411
+ if (/\brequire\s*\(/.test(text))
412
+ return true;
413
+ // Standard UMD default export guard (`if (typeof module !== 'undefined' && module.exports) { module.exports = X; }`) can be desugared to ESM.
414
+ const stripped = text.replace(/if\s*\(\s*typeof\s+module\s*!==?\s*['"]undefined['"]\s*&&\s*module\.exports\s*\)\s*(?:\{\s*module\.exports\s*=\s*[^;{}]+;?\s*\}|module\.exports\s*=\s*[^;]+;?)/g, '');
415
+ return /\b(?:module\.exports|exports\.[A-Za-z_$])/.test(stripped);
400
416
  }
401
417
  catch {
402
418
  return false;
@@ -672,10 +688,10 @@ function mapFiles(dir, root, repoFiles, packageDir, bundles, pkg) {
672
688
  const sources = repoFiles.filter((f) => /\.tsx?$/.test(f) && !f.endsWith('.d.ts'));
673
689
  const out = new Map();
674
690
  const installed = listFiles(dir).filter((f) => /\.m?js$/.test(f) && !f.includes(`${sep}platforms${sep}`) && !/\.(config|webpack)\.js$/.test(f));
675
- // Pure-JavaScript package (no TypeScript source in package or checkout): compile installed ES modules directly.
691
+ // Pure-JavaScript package (no TypeScript source in package or checkout): compile installed ES modules and non-CommonJS scripts directly.
676
692
  if (sources.length === 0) {
677
693
  for (const js of installed)
678
- out.set(js, isEsModule(js, pkg) ? js : null);
694
+ out.set(js, isEsModule(js, pkg) || !isCommonJsModule(js) ? js : null);
679
695
  return out;
680
696
  }
681
697
  const reexportTarget = (js) => {
@@ -758,7 +774,23 @@ function mapFiles(dir, root, repoFiles, packageDir, bundles, pkg) {
758
774
  for (const ext of ['.ts', '.tsx'])
759
775
  src ??= bySuffix(base + ext);
760
776
  }
777
+ // Monorepo re-bundled sibling workspace folder (e.g. `dist/scales/point.js` -> `packages/charts-scales/src/point.ts`).
778
+ const parts = stripped.split(sep);
779
+ if (!src && parts.length >= 2) {
780
+ const [seg, ...rest] = parts;
781
+ const tail = join('src', ...rest);
782
+ for (const ext of ['.ts', '.tsx']) {
783
+ const hits = sources.filter((f) => f.endsWith(`-${seg}${sep}${tail}${ext}`) || f.endsWith(`${sep}${seg}${sep}${tail}${ext}`));
784
+ if (hits.length === 1) {
785
+ src = hits[0];
786
+ break;
787
+ }
788
+ }
789
+ }
761
790
  }
791
+ // Unmapped standalone ES module in a directory without source maps (e.g. a monorepo package re-exporting sibling workspace files into `dist/`) or pure-JS script in a repo with no TypeScript sources: compile the installed JS directly.
792
+ if (!src && !bundles.has(js) && !existsSync(js + '.map') && ((isEsModule(js, pkg) && !installed.some((f) => dirname(f) === dirname(js) && existsSync(f + '.map'))) || (!sources.length && !isCommonJsModule(js))))
793
+ src = js;
762
794
  resolved.set(js, src);
763
795
  return src;
764
796
  };
@@ -953,7 +985,7 @@ function normalize(text, file, jsReference) {
953
985
  const tsf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
954
986
  const drops = [];
955
987
  for (const st of tsf.statements) {
956
- if (ts.isEnumDeclaration(st) && st.modifiers?.some((m) => m.kind === ts.SyntaxKind.ConstKeyword) && !new RegExp(`\\b${st.name.text}\\b`).test(jsReference)) {
988
+ if (ts.isEnumDeclaration(st) && st.modifiers?.some((m) => m.kind === ts.SyntaxKind.ConstKeyword) && !new RegExp(`\\b(?:var|let|const)\\s+${st.name.text}\\b`).test(jsReference)) {
957
989
  drops.push({ start: st.getStart(tsf), end: st.end });
958
990
  }
959
991
  }
@@ -990,7 +1022,7 @@ function normalize(text, file, jsReference) {
990
1022
  const trimmed = line.trim();
991
1023
  if (!trimmed)
992
1024
  continue;
993
- if (outLines.length && ((!/[;{}]$/.test(outLines[outLines.length - 1]) && !/^(?:case |default:)/.test(outLines[outLines.length - 1]) && !/^[{}]/.test(trimmed)) || (/^\}\s*$/.test(outLines[outLines.length - 1]) && /^:\s*\{$/.test(trimmed)))) {
1025
+ if (outLines.length && ((!/[;{}]$/.test(outLines[outLines.length - 1]) && !/^(?:case |default:)/.test(outLines[outLines.length - 1]) && !/^[{}]/.test(trimmed)) || (/^\}\s*$/.test(outLines[outLines.length - 1]) && /^:\s*\{$/.test(trimmed)) || /^:\s+/.test(trimmed) || /^\]/.test(trimmed))) {
994
1026
  outLines[outLines.length - 1] += (trimmed.startsWith('.') ? '' : ' ') + trimmed;
995
1027
  }
996
1028
  else {
@@ -999,24 +1031,33 @@ function normalize(text, file, jsReference) {
999
1031
  }
1000
1032
  return outLines.join('\n');
1001
1033
  };
1002
- // Decorator metadata (`__metadata("design:paramtypes", [])`), which a build with emitDecoratorMetadata adds.
1034
+ // Decorator metadata (`__metadata("design:paramtypes", [])`), which a build with emitDecoratorMetadata adds,
1035
+ // plus SWC arrow-parameter destructuring (`(acc, param) => { let [k, v] = param; ... }`).
1003
1036
  const printed = kept
1004
1037
  .map(singleLine)
1005
1038
  .join('\n')
1006
- .replace(/,?\s*(?:\b(?:tslib_\d+|tslib)\.)?__metadata\("design:\w+",\s*(?:\[[^\]]*\]|[\w.$]+|void 0)\)/g, '');
1039
+ .replace(/,?\s*(?:\b(?:tslib_\d+|tslib)\.)?__metadata\("design:\w+",\s*(?:\[[^\]]*\]|[\w.$]+|void 0)\)/g, '')
1040
+ .replace(/\(([^()]*,\s*)?param\)\s*=>\s*\{\n(?:let|var|const)\s+(\[[^\]]+\])\s*=\s*param;\nreturn\s+([^\n]+);\n\}/g, '($1$2) => $3')
1041
+ .replace(/\(([^()]*,\s*)?param\)\s*=>\s*\{\n(?:let|var|const)\s+(\[[^\]]+\])\s*=\s*param;\n/g, '($1$2) => {\n')
1042
+ .replace(/=>\s*\{\s*(?:var\s+(?:_[a-zA-Z0-9_]+,\s*)*_[a-zA-Z0-9_]+;\s*)?return\s+([^;\n]+);\s*\}/g, '=> {\nreturn $1;\n}')
1043
+ .replace(/\{\n\}/g, '{}')
1044
+ .replace(/^\}\s*([\]):,])/gm, '}\n$1');
1007
1045
  return printed
1008
1046
  .split('\n')
1009
1047
  .map((l) => l
1010
1048
  .trim()
1011
1049
  .replace(/\b(tslib_\d+|tslib)\.(__\w+)/g, '$2')
1012
1050
  .replace(/\bvoid 0\b/g, 'undefined')
1051
+ .replace(/"(?:\\.|[^"\\])*"|'((?:\\.|[^'\\])*)'/g, (m, sq) => (sq !== undefined && !sq.includes('"') && !sq.includes('\\') ? `"${sq}"` : m))
1013
1052
  .replace(/\b0[xX][0-9a-fA-F]+\b/g, (h) => String(parseInt(h, 16)))
1014
1053
  .replace(/\b\d+(?:\.\d+)?[eE][+-]?\d+\b/g, (n) => String(Number(n)))
1015
1054
  .replace(/,\s*([}\]])/g, ' $1')
1055
+ .replace(/\s+([}\]])/g, '$1')
1016
1056
  .replace(/,$/, '')
1017
1057
  .replace(/^var ([A-Za-z_$][\w$]*) = \(\(\1\d*\) => \{$/, '(function ($1) {')
1018
- .replace(/^\}\)\(([A-Za-z_$][\w$]*) \|\| \{\}\);$/, '})($1 || ($1 = {}));'))
1019
- .filter((l) => l && !l.startsWith('//# sourceMappingURL') && l !== 'export {};' && l !== '"use strict";' && l !== "'use strict';" && !/^var (?:_[a-z],\s*)*_[a-z];$/.test(l));
1058
+ .replace(/^\}\)\(([A-Za-z_$][\w$]*) \|\| \{\}\);$/, '})($1 || ($1 = {}));')
1059
+ .replace(/^\)\(([A-Za-z_$][\w$]*) \|\| \{\}\);$/, ')($1 || ($1 = {}));'))
1060
+ .filter((l) => l && !l.startsWith('//# sourceMappingURL') && l !== 'export {};' && l !== '"use strict";' && l !== "'use strict';" && !/^var (?:_[a-zA-Z0-9_]+,\s*)*_[a-zA-Z0-9_]+;$/.test(l));
1020
1061
  }
1021
1062
  /** Lines of a diff between the source's output `a` and the published `b` that no benign difference explains. */
1022
1063
  function unexplained(a, b) {
@@ -1024,20 +1065,27 @@ function unexplained(a, b) {
1024
1065
  const bad = [];
1025
1066
  // Inlined enum members and emitter temp aliases (`_a`, `_b`): a line whose only difference is `E.Member` against a literal or `_a` vs `_b`.
1026
1067
  const shape = (l) => l
1027
- .replace(/^export\s+(?=(?:async\s+|function|class|const|let|var)\s+)/, '')
1068
+ .replace(/^export\s+(?=(?:async\s+)?(?:function|class|const|let|var)\s+)/, '')
1028
1069
  .replace(/^__exportStar\(require\(([^)]+)\),\s*exports\);$/, '__export(require($1));')
1029
1070
  .replace(/^\}\)\((\w+)\s*\|\|\s*\(exports\.\1\s*=\s*\1\s*=\s*\{\}\)\);$/, '})($1 = exports.$1 || (exports.$1 = {}));')
1071
+ .replace(/^\}\s*([\]):,])/, '$1')
1030
1072
  .replace(/\(([A-Za-z_$][\w$]*)\)\s*=>/g, '$1 =>')
1031
- .replace(/(?<=^|[{,\s])([A-Za-z_$][\w$]*)\s*:\s*\1(?=\s*[,}]|$)/g, '$1')
1073
+ .replace(/(?<=^|[{,\s])([A-Za-z_$][\w$]*)\s*:\s*\1\d*(?=\s*[,}]|$)/g, '$1')
1032
1074
  .replace(/^(?:const|let)\s+\{\s*(\w+)\s*\}\s*=\s*(\w+);$/, 'var $1 = $2.$1;')
1033
1075
  .replace(/(?:^|(?<=for\s*\(\s*))(?:const|let)\s+/, 'var ')
1034
- .replace(/`[^`]*`|"[^"]*"\.concat\([^)]*\)/g, '"#"')
1035
- .replace(/\s*\{\s*$/, '')
1076
+ .replace(/"[^"]*"|'[^']*'|`[^`]*`/g, '"#"')
1077
+ .replace(/"#"(?:\s*\+\s*"#")+/g, '"#"')
1078
+ .replace(/"#"\.concat\([^)]*\)/g, '"#"')
1079
+ .replace(/\s*\{\s*\}?\s*$/, '')
1080
+ .replace(/var\s+(_[a-z])\s*=\s*([A-Za-z_$][\w$.]*),\s*(\{[^}]+\})\s*=\s*\1,\s*([A-Za-z_$][\w$]*)\s*=\s*__rest\(\1,/g, 'var $3 = $2, $4 = __rest($2,')
1081
+ .replace(/\((_[a-z])\s*=\s*\((_[a-z])\s*=\s*([A-Za-z_$][\w$.]*)\)\.([A-Za-z_$][\w$]*)\)\s*===\s*null\s*\|\|\s*\1\s*===\s*undefined\s*\?\s*undefined\s*:\s*\1\.call\(\2/g, '(_a = $3.$4) === null || _a === undefined ? undefined : _a.call($3')
1082
+ .replace(/\((_[a-zA-Z0-9_]+)\s*=\s*([^()]+?)\s*===\s*null\s*\|\|\s*\2\s*===\s*undefined\s*\?\s*undefined\s*:\s*([^()]+?)\)\s*===\s*null\s*\|\|\s*\1\s*===\s*undefined\s*\?\s*undefined\s*:\s*\1\./g, '$3?.')
1083
+ .replace(/([A-Za-z_$][\w$.]*)\s*===\s*null\s*\|\|\s*\1\s*===\s*undefined\s*\?\s*undefined\s*:\s*\((_[a-zA-Z0-9_]+)\s*=\s*([^()]+?)\)\s*===\s*null\s*\|\|\s*\2\s*===\s*undefined\s*\?\s*undefined\s*:\s*\2\./g, '$3?.')
1036
1084
  .replace(/\((_[a-z])\s*=\s*([A-Za-z_$][\w$]*)\)\s*!==\s*null\s*&&\s*\1\s*!==\s*undefined\s*\?\s*\1\s*:/g, '$2 !== null && $2 !== undefined ? $2 :')
1037
- .replace(/\b_[a-z]\b/g, '_a')
1038
- .replace(/\b[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)+\b|-?\b\d+(\.\d+)?\b|"[^"]*"|'[^']*'/g, '#');
1085
+ .replace(/\b(?:_[a-z]|param)\b/g, '_a')
1086
+ .replace(/\b[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)+\b|-?\b\d+(\.\d+)?\b/g, '#');
1039
1087
  const stripParens = (s) => s.replace(/[()]/g, '').replace(/\s+/g, ' ').trim();
1040
- const stripShadowSuffix = (s) => s.replace(/\b([A-Za-z$](?:[A-Za-z_$]*[A-Za-z$])?)\d+(_\d+)?\b/g, '$1$2');
1088
+ const stripShadowSuffix = (s) => s.replace(/\b([A-Za-z_$](?:[A-Za-z0-9_$]*[A-Za-z_$])?)\d+(_\d+)?\b/g, '$1$2');
1041
1089
  const isImportOrReexport = (l) => /^(?:import\b|export\s+(?:\*|\{))/.test(l);
1042
1090
  for (let i = 0; i < ops.length;) {
1043
1091
  if (ops[i].op === '=') {
@@ -1050,11 +1098,13 @@ function unexplained(a, b) {
1050
1098
  i++;
1051
1099
  }
1052
1100
  const filteredDel = del.filter((l) => l !== '}' && !/^export var [A-Za-z_$][\w$]*;$/.test(l) && !isImportOrReexport(l));
1053
- const filteredAdd = add.filter((l) => l !== '}' && !isImportOrReexport(l) && !/^return [A-Za-z_$][A-Za-z_$]*\d+;$/.test(l));
1101
+ const filteredAdd = add.filter((l) => l !== '}' && !isImportOrReexport(l));
1054
1102
  for (let k = 0; k < Math.max(filteredDel.length, filteredAdd.length); k++) {
1055
1103
  const x = filteredDel[k], y = filteredAdd[k];
1056
1104
  if (x !== undefined && y !== undefined && (shape(x) === shape(y) || stripShadowSuffix(stripParens(shape(x))) === stripShadowSuffix(stripParens(shape(y)))))
1057
1105
  continue;
1106
+ if (x === undefined && y !== undefined && /^return [A-Za-z_$][A-Za-z_$]*\d+;$/.test(y))
1107
+ continue;
1058
1108
  // Imports and re-exports a whole-program build elides as type-only, or esbuild/rollup rewrites (`export { x } from './y'` -> `import { x as x2 } from './y'`).
1059
1109
  if (x !== undefined && y === undefined && /^(import|export) \{?/.test(x) && !/^export (default |const |let |var |function |class |async )/.test(x))
1060
1110
  continue;