@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
@@ -8,7 +8,7 @@ import { ambientAddedMemberOf, ambientBase, augmentedPropertyRead, evolvingArray
8
8
  import { nullishSignalType } from "../semantics/signals.js";
9
9
  import { hasModifier, isLibDeclaration, isSymbolIterator, isWriteTarget, implementationOf, declaresThis } from "../semantics/ast.js";
10
10
  import { isCoreDeclaration } from "../program/core-facts.js";
11
- import { coreTypeKind, eventDataTypeLiteral, isJsDocConstructorFunction, isKit, isLibObjectType, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType } from "../semantics/types.js";
11
+ import { coreTypeKind, eventDataTypeLiteral, hasMappedIntersection, isJsDocConstructorFunction, isKit, isLibObjectType, isUntyped, libraryNativeType, libraryType, mappedOrErasedType, nonNullableInner, nonOptionalSpelling, parseNativeType, spelledType, valueModuleKind } from "../semantics/types.js";
12
12
  import { keepsIdentity } from "../semantics/conversion.js";
13
13
  import { extendedClass, isEventData } from "../semantics/classes.js";
14
14
  import { otherPlatformTypings } from "../semantics/platform-globals.js";
@@ -55,10 +55,10 @@ export const typesMethods = {
55
55
  if (native)
56
56
  return optionalType(native);
57
57
  }
58
- // A namespace as a value (`{ Accuracy: CoreTypes.Accuracy }`): its enum's metatype.
59
- const nsDecl = t.flags & F.Object && t.getSymbol()?.flags & ts.SymbolFlags.ValueModule ? t.getSymbol().valueDeclaration : undefined;
60
- if (nsDecl && ts.isModuleDeclaration(nsDecl) && !nsDecl.getSourceFile().isDeclarationFile)
61
- return `${this.namespacePath(nsDecl)}.Type`;
58
+ // A namespace as a value (`{ Accuracy: CoreTypes.Accuracy }`) or an ES module namespace (`typeof import('...')`).
59
+ const ns = valueModuleKind(t);
60
+ if (ns)
61
+ return ns === 'module' ? 'Any?' : `${this.namespacePath(ns)}.Type`;
62
62
  // An enum as a value (`typeof AccessibilityRole`): the object JavaScript makes of it.
63
63
  // Not the enum's own name, through which its members are read (`Status.Denied`).
64
64
  const enumObject = t.flags & F.Object && (t.getSymbol()?.flags ?? 0) & ts.SymbolFlags.RegularEnum ? t.getSymbol().valueDeclaration : undefined;
@@ -78,13 +78,13 @@ export const typesMethods = {
78
78
  if (constraint)
79
79
  return this.type(constraint, where);
80
80
  const decl = t.symbol?.declarations?.[0];
81
+ if (decl && ts.isTypeParameterDeclaration(decl) && (this.erasesGenerics(decl.parent) || this.erasesTypeParameter(decl)))
82
+ return 'Any?';
81
83
  if (decl && this.pluginFiles.has(decl.getSourceFile().fileName) && !(ts.isTypeParameterDeclaration(decl) && this.keepsGenerics(decl.parent)))
82
84
  return 'Any?';
83
85
  // A library's generic signature (`ClassDecorator`'s `TFunction`) in library mode: erased as the program's own are.
84
86
  if (decl && this.library && decl.getSourceFile().isDeclarationFile)
85
87
  return 'Any?';
86
- if (decl && ts.isTypeParameterDeclaration(decl) && this.erasesTypeParameter(decl))
87
- return 'Any?';
88
88
  // Inside an object shape, a class of its own outside every generic scope: any value.
89
89
  if (this.shaping.size)
90
90
  return 'Any?';
@@ -122,7 +122,7 @@ export const typesMethods = {
122
122
  const inNarrowing = (u) => !!(u.flags & F.Object) && !u.getCallSignatures().length && u.getProperties().every((p) => c.getTypeOfSymbol(p).flags & F.Unknown);
123
123
  if (param && (isUntyped(spelledType(this.type(param, where))) || t.types.every((u) => u === param || inNarrowing(u))))
124
124
  return this.type(param, where);
125
- if (membersOverTypeParameter(t, c))
125
+ if (membersOverTypeParameter(t, c) || hasMappedIntersection(t))
126
126
  return 'Any?';
127
127
  // A function carrying properties (`((p: P) => R) & { type: string }`): an untyped value, called as script calls it.
128
128
  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])))
@@ -251,7 +251,7 @@ export const typesMethods = {
251
251
  // A function type reading the receiver it is called with (`(this: Action, state) => void`): a script function, as
252
252
  // `call`/`apply` pass that receiver and a Swift closure has none.
253
253
  const sd = s.getDeclaration();
254
- if (sd && (ts.isFunctionTypeNode(sd) || ts.isFunctionExpression(sd) || ts.isFunctionDeclaration(sd)) && declaresThis(sd))
254
+ if (sd && (ts.isFunctionTypeNode(sd) || ts.isFunctionExpression(sd) || ts.isFunctionDeclaration(sd) || ts.isMethodSignature(sd)) && declaresThis(sd))
255
255
  return 'Any?';
256
256
  if (sd && ts.isFunctionExpression(sd) && this.readsArguments(sd)) {
257
257
  const ret = this.widenedResultType(sd, this.type(s.getReturnType(), where));
@@ -61,7 +61,7 @@ export async function writeAndroid(b) {
61
61
  if (writes.length)
62
62
  throw sharedWorkerStateError(writes, b.app);
63
63
  }
64
- const moduleFiles = [...b.modules, ...b.components.map((c) => c.file), ...(b.compiledPlugins ?? [])];
64
+ const moduleFiles = [...new Set([...b.modules, ...b.components.map((c) => c.file), ...(b.compiledPlugins ?? [])])];
65
65
  // Which modules run on the main thread only; a worker's script reaching one stops the build with the import chain.
66
66
  const threads = moduleThreads({ program: b.program, modules: moduleFiles, workers: b.workers, resolved: b.resolved, coreModuleOf: (f) => /[\\/]@nativescript[\\/]core[\\/](.+)$/.exec(f)?.[1] ?? null });
67
67
  // A module only `await import(…)` reaches (and what only it imports) runs when it is imported, as the bundle evaluates
@@ -100,9 +100,13 @@ export async function writeAndroid(b) {
100
100
  // Components whose class could not be written (`--keep-going`): a root view of one is left as it is.
101
101
  const unwritten = new Set();
102
102
  const kotlinClass = (name) => programClassName(translator, name);
103
+ const componentClass = (name) => {
104
+ const c = b.components.find((x) => x.name === name);
105
+ const sf = c && b.program.getSourceFile(c.file);
106
+ return sf?.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === name) ?? sf?.statements.find(ts.isClassDeclaration);
107
+ };
103
108
  const rootView = (name, make) => {
104
- const c = b.translatorHooks?.wrapsRootViews && !unwritten.has(name) ? b.components.find((x) => x.name === name) : undefined;
105
- const cls = c && b.program.getSourceFile(c.file)?.statements.find(ts.isClassDeclaration);
109
+ const cls = b.translatorHooks?.wrapsRootViews && !unwritten.has(name) ? componentClass(name) : undefined;
106
110
  return cls ? translator.rootView(cls, kotlinClass(name), make) : make;
107
111
  };
108
112
  const table = {};
@@ -162,13 +166,8 @@ export async function writeAndroid(b) {
162
166
  const header = (from, template) => `${headerLine(sourceName(b.app, from, b.context.adapter), template && (dirname(template) === dirname(from) ? basename(template) : sourceName(b.app, template, b.context.adapter)))}\npackage ${pkg}\n\nimport org.nativescript.kit.*\n\n`;
163
167
  // A component's file is a module too: what it declares beside the component (its constants and helpers).
164
168
  const modules = translateKotlinModules(translator, b.program, moduleFiles, b.resolved, b.app);
165
- const componentClass = (name) => {
166
- const c = b.components.find((x) => x.name === name);
167
- return c && b.program.getSourceFile(c.file)?.statements.find(ts.isClassDeclaration);
168
- };
169
169
  for (const c of b.components) {
170
- const sf = b.program.getSourceFile(c.file);
171
- const cls = sf.statements.find(ts.isClassDeclaration);
170
+ const cls = componentClass(c.name);
172
171
  try {
173
172
  const { params, lines, statics } = translator.componentMembers(cls, c.props);
174
173
  const conformance = translator.componentConformance(cls);
@@ -265,6 +264,11 @@ export async function writeAndroid(b) {
265
264
  if ('branches' in n && Array.isArray(n.branches))
266
265
  for (const br of n.branches)
267
266
  visit(br.body);
267
+ if ('fallback' in n && Array.isArray(n.fallback))
268
+ visit(n.fallback);
269
+ if ('slots' in n && n.slots)
270
+ for (const slotNodes of Object.values(n.slots))
271
+ visit(slotNodes);
268
272
  }
269
273
  };
270
274
  for (const c of b.components)
@@ -106,11 +106,16 @@ export async function writeIos(b) {
106
106
  // A component's file declares more than the component (interfaces, constants): it is a module as well.
107
107
  // The SDK frameworks beyond UIKit the program's code names (CoreSpotlight, SafariServices), imported by every file once all are known.
108
108
  const SDK_IMPORTS = '// @sdk-imports\n';
109
- const translated = translateModules(translator, program, [...modules, ...components.map((c) => c.file), ...compiledPlugins], resolved);
109
+ const translated = translateModules(translator, program, [...new Set([...modules, ...components.map((c) => c.file), ...compiledPlugins])], resolved);
110
+ const componentClass = (name) => {
111
+ const c = components.find((x) => x.name === name);
112
+ const sf = c && program.getSourceFile(c.file);
113
+ return sf?.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === name) ?? sf?.statements.find(ts.isClassDeclaration);
114
+ };
110
115
  // Every component's members first: whether a constructor throws is known before any template creates the component.
111
116
  const members = new Map();
112
117
  for (const c of components) {
113
- const cls = program.getSourceFile(c.file).statements.find(ts.isClassDeclaration);
118
+ const cls = componentClass(c.name);
114
119
  try {
115
120
  members.set(c.name, located(translator.componentMembers(cls, c.props).join('\n')));
116
121
  }
@@ -122,17 +127,12 @@ export async function writeIos(b) {
122
127
  infos.get(c.name).initThrows = translator.initThrows(c.name);
123
128
  infos.get(c.name).throwingSetters = (c.setters ?? []).filter((p) => translator.memberThrows(cls, '$set_' + p));
124
129
  }
125
- const componentClass = (name) => {
126
- const c = components.find((x) => x.name === name);
127
- return c && program.getSourceFile(c.file)?.statements.find(ts.isClassDeclaration);
128
- };
129
130
  /** Components whose class could not be written (`--keep-going`): a root view of one is left as it is. */
130
131
  const unwritten = new Set();
131
132
  for (const c of components) {
132
- const sf = program.getSourceFile(c.file);
133
- const cls = sf.statements.find(ts.isClassDeclaration);
133
+ const cls = componentClass(c.name);
134
134
  try {
135
- const lines = [`final class ${swiftClass(c.name)} {`, NONISOLATED_DEINIT, members.get(c.name) ?? '', ...translator.componentStatics(cls), '', ...render(c, infos, (m) => translator.memberThrows(cls, m), behaviour, { itemType: (m) => translator.memberElementType(cls, m), propValue: (child, p, m) => translator.propValue(cls, componentClass(child), p, m), swiftClass: (name) => (elementClasses.has(name) || infos.has(name) ? swiftClass(name) : name) }), '}', translator.componentConformance(cls, swiftClass(c.name))];
135
+ const lines = [`final class ${swiftClass(c.name)}${translator.componentSuperclass(cls)} {`, NONISOLATED_DEINIT, members.get(c.name) ?? '', ...translator.componentStatics(cls), '', ...render(c, infos, (m) => translator.memberThrows(cls, m), behaviour, { itemType: (m) => translator.memberElementType(cls, m), propValue: (child, p, m) => translator.propValue(cls, componentClass(child), p, m), swiftClass: (name) => (elementClasses.has(name) || infos.has(name) ? swiftClass(name) : name) }), '}', translator.componentConformance(cls, swiftClass(c.name))];
136
136
  writeFileSync(join(sourcesDir, c.name + '.swift'), header(c.file) + lines.join('\n') + '\n');
137
137
  }
138
138
  catch (e) {
@@ -403,7 +403,8 @@ ${Object.entries(appSettings)
403
403
  /** The code making a component's root view, wrapped as the framework wraps root views. */
404
404
  function rootView(name, make) {
405
405
  const c = adapter?.swift?.wrapsRootViews && !unwritten.has(name) ? components.find((x) => x.name === name) : undefined;
406
- const cls = c && program.getSourceFile(c.file)?.statements.find(ts.isClassDeclaration);
406
+ const sf = c && program.getSourceFile(c.file);
407
+ const cls = sf?.statements.find((s) => ts.isClassDeclaration(s) && s.name?.text === name) ?? sf?.statements.find(ts.isClassDeclaration);
407
408
  return cls ? translator.rootView(cls, swiftClass(name), make) : make;
408
409
  }
409
410
  }
@@ -32,6 +32,18 @@ export function swiftPackages(app, stubbed = new Set()) {
32
32
  pkg.path = resolve(app, p.path);
33
33
  if (plugin && !existsSync(pkg.path) && existsSync(resolve(dir, p.path)))
34
34
  pkg.path = resolve(dir, p.path);
35
+ // In a hoisted monorepo, `node_modules/<pkg>/...` may live in an ancestor workspace directory or relative to the plugin's own directory.
36
+ if (!existsSync(pkg.path) && p.path.startsWith('node_modules/')) {
37
+ for (let cur = dirname(app);; cur = dirname(cur)) {
38
+ const probe = resolve(cur, p.path);
39
+ if (existsSync(probe)) {
40
+ pkg.path = probe;
41
+ break;
42
+ }
43
+ if (dirname(cur) === cur)
44
+ break;
45
+ }
46
+ }
35
47
  if (!existsSync(pkg.path))
36
48
  throw new Error(`${relative(app, join(dir, 'nativescript.config.ts')) || 'nativescript.config.ts'}: the Swift package ${name} is not at ${pkg.path}`);
37
49
  // The JavaScript engine's headers, which a plugin binding the engine ships: no engine runs a compiled app.
@@ -10,9 +10,20 @@ export function readConfig(app) {
10
10
  if (!file)
11
11
  return {};
12
12
  const sf = ts.createSourceFile(file, readFileSync(file, 'utf8'), ts.ScriptTarget.Latest, true);
13
+ const locals = new Map();
14
+ for (const st of sf.statements) {
15
+ if (ts.isVariableStatement(st)) {
16
+ for (const d of st.declarationList.declarations) {
17
+ if (ts.isIdentifier(d.name) && d.initializer)
18
+ locals.set(d.name.text, d.initializer);
19
+ }
20
+ }
21
+ }
13
22
  const value = (e) => {
14
23
  if (ts.isAsExpression(e) || ts.isSatisfiesExpression(e) || ts.isParenthesizedExpression(e))
15
24
  return value(e.expression);
25
+ if (ts.isIdentifier(e) && locals.has(e.text))
26
+ return value(locals.get(e.text));
16
27
  if (ts.isStringLiteralLike(e))
17
28
  return e.text;
18
29
  if (ts.isNumericLiteral(e))
@@ -25,9 +36,12 @@ export function readConfig(app) {
25
36
  return e.elements.map(value);
26
37
  if (ts.isObjectLiteralExpression(e)) {
27
38
  const out = {};
28
- for (const p of e.properties)
39
+ for (const p of e.properties) {
29
40
  if (ts.isPropertyAssignment(p))
30
41
  out[p.name.getText().replace(/^['"]|['"]$/g, '')] = value(p.initializer);
42
+ else if (ts.isShorthandPropertyAssignment(p))
43
+ out[p.name.text] = value(p.name);
44
+ }
31
45
  return out;
32
46
  }
33
47
  return undefined;
@@ -61,6 +61,8 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
61
61
  const viewMark = (nodes) => behaviour.effectScope === 'view' && hasRegion(nodes);
62
62
  // The steps being written, innermost last, and the template scopes whose deferred steps follow their own.
63
63
  const out = [];
64
+ /** Enclosing child component instance variables while emitting projected slot bodies (for `contentHost` queries). */
65
+ const slotTargets = [];
64
66
  const say = (step) => out.at(-1).push(step);
65
67
  const templates = [];
66
68
  /** A node's change, init and check hooks, which run once the next node bound is reached: a `let` before it precedes them. */
@@ -143,6 +145,7 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
143
145
  for (const u of uses ?? []) {
144
146
  const d = `d${n++}`;
145
147
  say({ kind: 'directive', name: d, view, make: call(u.make, loops) });
148
+ queried(u.queries, loops, view, d);
146
149
  const inner = [...loops, { item: u.name, itemExpr: d }];
147
150
  if (u.destroy)
148
151
  say({ kind: 'cleanup', call: call(u.destroy, inner) });
@@ -189,9 +192,10 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
189
192
  const queried = (hooks, loops, view, instance) => {
190
193
  for (const q of hooks ?? []) {
191
194
  const made = q.on === 'view' ? view : instance;
192
- say({ kind: 'run', call: call(q.set, loops, [made]) });
195
+ const args = q.contentHost && slotTargets.length ? [slotTargets.at(-1), made] : [made];
196
+ say({ kind: 'run', call: call(q.set, loops, args) });
193
197
  if (q.unset)
194
- say({ kind: 'cleanup', call: call(q.unset, loops, [made]) });
198
+ say({ kind: 'cleanup', call: call(q.unset, loops, args) });
195
199
  }
196
200
  };
197
201
  const component = (node, loops, view, parent, region) => {
@@ -220,6 +224,21 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
220
224
  });
221
225
  const passed = info.passed ? node.props.map((a) => a.name).concat(node.events.map((e) => 'on' + e.name[0].toUpperCase() + e.name.slice(1))) : null;
222
226
  say({ kind: 'component', name: cv, type: node.name, args, passed, initThrows: !!info.initThrows });
227
+ if (node.slots && info.slots?.length) {
228
+ slotTargets.push(cv);
229
+ try {
230
+ for (const [slotName, slotNodes] of Object.entries(node.slots)) {
231
+ if (!slotNodes.length || !info.slots.includes(slotName))
232
+ continue;
233
+ const f = `f${n++}`;
234
+ const b = template(block([], f, viewMark(slotNodes)), () => emit(slotNodes, loops, f, null), false);
235
+ say({ kind: 'setSlot', component: cv, name: slotName, scope: scoped('region'), viewMark: b.viewMark, body: b });
236
+ }
237
+ }
238
+ finally {
239
+ slotTargets.pop();
240
+ }
241
+ }
223
242
  const write = (p) => {
224
243
  const a = given(p);
225
244
  return { component: cv, prop: p, setter: setter(p), throwingSetter: !!info.throwingSetters?.includes(p), convert: a ? conversion(p, a) : null, changes: !!info.changes, inputChanged: onPush && !!info.onPush };
@@ -281,8 +300,10 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
281
300
  else {
282
301
  say({ kind: 'createView', view, component: cv, member: members(node.name).create, update: u });
283
302
  queried(node.queries, loops, view, cv);
303
+ const { end: endDir } = directed(node.directives, loops, view);
284
304
  events();
285
305
  attach(view, parent, region, 'created');
306
+ endDir();
286
307
  }
287
308
  props();
288
309
  if (!info.fragment)
@@ -407,10 +428,76 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
407
428
  }
408
429
  if (node.kind === 'template')
409
430
  throw new Error(`${c.name}: an item template outside a ListView or Pager`);
431
+ if (node.kind === 'slot') {
432
+ if (!parent)
433
+ throw new Error(`${c.name}: a slot at the root of a non-fragment template`);
434
+ const r = `r${n++}`;
435
+ say({ kind: 'region', name: r, parent, detached: false });
436
+ let fallback = null;
437
+ if (node.fallback?.length) {
438
+ const f = `f${n++}`;
439
+ fallback = template(block([], f, viewMark(node.fallback)), () => emit(node.fallback, loops, f, null), false);
440
+ }
441
+ say({ kind: 'slot', name: node.name, host: { region: r }, fallback });
442
+ continue;
443
+ }
444
+ if (node.kind === 'componentOutlet') {
445
+ if (!parent)
446
+ throw new Error(`${c.name}: a component outlet at the root of a non-fragment template`);
447
+ const r = `r${n++}`;
448
+ say({ kind: 'region', name: r, parent, detached: false });
449
+ (passes ? binding : say)({
450
+ kind: 'componentOutlet',
451
+ host: { region: r },
452
+ call: kit('componentOutlet'),
453
+ component: call(node.component, loops),
454
+ injector: node.injector ? call(node.injector, loops) : null,
455
+ inputs: node.inputs ? call(node.inputs, loops) : null,
456
+ });
457
+ continue;
458
+ }
459
+ if (node.kind === 'templateOutlet') {
460
+ if (!parent)
461
+ throw new Error(`${c.name}: a template outlet at the root of a non-fragment template`);
462
+ const r = `r${n++}`;
463
+ say({ kind: 'region', name: r, parent, detached: false });
464
+ (passes ? binding : say)({
465
+ kind: 'templateOutlet',
466
+ host: { region: r },
467
+ call: kit('templateOutlet'),
468
+ template: call(node.template, loops),
469
+ context: node.context ? call(node.context, loops) : null,
470
+ });
471
+ continue;
472
+ }
473
+ if (node.kind === 'bindTemplate') {
474
+ const f = `f${n++}`;
475
+ const innerLoops = [...loops, { item: node.ctxParam, itemExpr: node.ctxParam }];
476
+ const b = template(block([], f, viewMark(node.body)), () => emit(node.body, innerLoops, f, null), false);
477
+ say({ kind: 'bindTemplate', field: node.field, scope: scoped('region'), viewMark: b.viewMark, ctxParam: node.ctxParam, body: b });
478
+ continue;
479
+ }
480
+ if (node.kind === 'structural') {
481
+ if (!parent)
482
+ throw new Error(`${c.name}: a structural directive at the root of a non-fragment template`);
483
+ const r = `r${n++}`;
484
+ const tplName = `tpl${n++}`;
485
+ const f = `f${n++}`;
486
+ say({ kind: 'region', name: r, parent, detached: false });
487
+ const innerLoops = [...loops, { item: node.ctxParam, itemExpr: node.ctxParam }];
488
+ const tplBody = template(block([], f, viewMark(node.body)), () => emit(node.body, innerLoops, f, null), false);
489
+ const dirSteps = [];
490
+ out.push(dirSteps);
491
+ const { end: endDir } = directed([node.directive], loops, parent);
492
+ out.pop();
493
+ endDir();
494
+ say({ kind: 'structural', region: r, call: kit('structuralScope'), tplName, scope: scoped('region'), viewMark: tplBody.viewMark, ctxParam: node.ctxParam, body: tplBody, steps: dirSteps });
495
+ continue;
496
+ }
410
497
  if (!parent)
411
498
  throw new Error(`${c.name}: an if/for at the root of a template`);
412
499
  // A component whose views join its parent (no single root) is a region of the body it is in.
413
- const nested = (body) => withoutLocals(body).some((x) => x.kind === 'if' || x.kind === 'for' || (x.kind === 'component' && !!components.get(x.name)?.fragment));
500
+ const nested = (body) => withoutLocals(body).some((x) => x.kind === 'if' || x.kind === 'for' || x.kind === 'slot' || x.kind === 'componentOutlet' || x.kind === 'templateOutlet' || x.kind === 'structural' || (x.kind === 'component' && !!components.get(x.name)?.fragment));
414
501
  const nestedBody = node.kind === 'if' ? node.branches.some((b) => nested(b.body)) : nested(node.body);
415
502
  // A framework that inserts top-down puts a branch's views in place as it builds them; a body with regions of its own attaches as a fragment.
416
503
  const live = insertion !== 'built' && !nestedBody ? `r${n++}` : null;
@@ -529,6 +616,7 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
529
616
  };
530
617
  const plan = {
531
618
  fragment,
619
+ hasSlots: !!c.slots?.length,
532
620
  scope: scoped('template'),
533
621
  viewMark: viewMark(c.template),
534
622
  derived: (c.derived ?? []).map((x) => ({ name: x.name, call: member(x.method) })),
@@ -544,6 +632,14 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
544
632
  members: members(c.name),
545
633
  ...(passes ? { passes: rootHooks() } : {}),
546
634
  };
635
+ const emitTemplates = () => {
636
+ for (const t of c.templates ?? []) {
637
+ const f = `f${n++}`;
638
+ const innerLoops = [{ item: t.ctxParam, itemExpr: t.ctxParam }];
639
+ const b = template(block([], f, viewMark(t.body)), () => emit(t.body, innerLoops, f, null), false);
640
+ say({ kind: 'bindTemplate', field: t.field, scope: scoped('region'), viewMark: b.viewMark, ctxParam: t.ctxParam, body: b });
641
+ }
642
+ };
547
643
  if (c.page) {
548
644
  // A routed component's template is its page's content: the action bar and the view.
549
645
  const content = ledger.pageContentLayout ? behaviour.pageContentAttrs : undefined;
@@ -551,6 +647,7 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
551
647
  if (content) {
552
648
  const isBar = (x) => x.kind === 'element' && x.tag === 'ActionBar';
553
649
  template(body, () => {
650
+ emitTemplates();
554
651
  emit(c.template.filter(isBar), [], 'page', null);
555
652
  say({ kind: 'create', view: 'content', tag: 'FlexboxLayout' });
556
653
  for (const [name, value] of Object.entries(content))
@@ -559,18 +656,18 @@ export function renderPlan(c, components, behaviour = DEFAULT_BEHAVIOUR, ledger)
559
656
  }, true);
560
657
  }
561
658
  else
562
- template(body, () => emit(c.template, [], 'page', null), true);
659
+ template(body, () => { emitTemplates(); emit(c.template, [], 'page', null); }, true);
563
660
  return { ...plan, root: { kind: 'page', host: c.host ?? null, body, content: content ? 'content' : null } };
564
661
  }
565
662
  if (fragment)
566
- return { ...plan, root: { kind: 'fragment', body: template(block(), () => emit(c.template, [], 'root', null), true) } };
663
+ return { ...plan, root: { kind: 'fragment', body: template(block(), () => { emitTemplates(); emit(c.template, [], 'root', null); }, true) } };
567
664
  const roots = [];
568
- const body = template(block(roots), () => emit(c.template, [], null, roots), true);
665
+ const body = template(block(roots), () => { emitTemplates(); emit(c.template, [], null, roots); }, true);
569
666
  if (roots.length !== 1)
570
667
  throw new Error(`${c.name}: a template needs exactly one root element`);
571
668
  return { ...plan, root: { kind: 'view', body, view: roots[0] } };
572
669
  }
573
- /** Whether a template holds an `if` or `for` of its own (not inside an item template). */
670
+ /** Whether a template holds an `if`, `for`, or projected slot content of its own (not inside an item template). */
574
671
  function hasRegion(nodes) {
575
- return withoutLocals(nodes).some((n) => n.kind === 'if' || n.kind === 'for' || (n.kind === 'element' && !TEMPLATE_HOSTS.has(n.tag) && hasRegion(n.children)));
672
+ return withoutLocals(nodes).some((n) => n.kind === 'if' || n.kind === 'for' || n.kind === 'componentOutlet' || n.kind === 'templateOutlet' || n.kind === 'structural' || (n.kind === 'component' && !!n.slots && Object.keys(n.slots).length > 0) || (n.kind === 'slot' && !!n.fallback && hasRegion(n.fallback)) || (n.kind === 'element' && !TEMPLATE_HOSTS.has(n.tag) && hasRegion(n.children)));
576
673
  }
@@ -138,6 +138,9 @@ export interface EntryContext {
138
138
  readonly components: ReadonlyMap<string, {
139
139
  members: ComponentMembers;
140
140
  initThrows?: boolean;
141
+ fragment?: boolean;
142
+ props?: string[];
143
+ optional?: string[];
141
144
  }>;
142
145
  /** The code making a component's root view (`make`), wrapped as the translator wraps root views (`TranslatorHooks.wrapsRootViews`). */
143
146
  rootView(component: string, make: string): string;
@@ -253,6 +256,12 @@ export interface TemplateKit {
253
256
  call: string;
254
257
  primary: string;
255
258
  };
259
+ /** Mounts a dynamic component into a region (`[ngComponentOutlet]` / `*ngComponentOutlet`). */
260
+ componentOutlet?: string;
261
+ /** Mounts a dynamic or recursive template into a region (`[ngTemplateOutlet]` / `*ngTemplateOutlet`). */
262
+ templateOutlet?: string;
263
+ /** Runs a custom structural directive with its `TemplateRef` and `ViewContainerRef` bound to its region. */
264
+ structuralScope?: string;
256
265
  /** An attribute's bound value as the view takes it, under `slots`. */
257
266
  attributeValue?: string;
258
267
  /** A bound class name as the view takes it, under `slots`. */
@@ -461,6 +470,8 @@ export interface FrameworkModel {
461
470
  calledByFramework?(cls: ts.ClassLikeDeclaration, m: ts.MethodDeclaration | ts.SetAccessorDeclaration, checker: ts.TypeChecker): boolean;
462
471
  /** Whether a declared member may hold undefined at run time though its declared type leaves it out (e.g. `linkedSignal`'s `previous.source`). */
463
472
  unsetMembers?(d: ts.PropertySignature | ts.PropertyDeclaration, checker: ts.TypeChecker): boolean;
473
+ /** Whether a generic class managed by the framework's DI / template factory erases its type parameters on reified backends (Swift). */
474
+ erasesGenericClass?(cls: ts.ClassDeclaration): boolean;
464
475
  }
465
476
  /** A component's field the framework's call makes a prop of (`input(0)`): its value's type and the default a parent may leave it at. */
466
477
  export interface PropField {
@@ -494,6 +505,8 @@ export interface TranslatorHooks<V extends TranslatorView = TranslatorView> exte
494
505
  serviceClass?(t: V, cls: ts.ClassDeclaration, name: string): string;
495
506
  /** What a class's translation adds for the framework; `code` is the class's so far. */
496
507
  classExtras?(t: V, cls: ts.ClassDeclaration, name: string, code: string): ClassExtras | undefined;
508
+ /** A dynamic `import(specifier)` the framework handles itself (e.g. rejecting JIT-only compiler imports); undefined for any other. */
509
+ dynamicImport?(specifier: string): string | undefined;
497
510
  /** Code following a class's translation (`code`), as a Swift extension of it. */
498
511
  afterClass?(t: V, cls: ts.ClassDeclaration, code: string): string | undefined;
499
512
  }
@@ -28,6 +28,8 @@ export interface QueryHook {
28
28
  set: string;
29
29
  unset?: string;
30
30
  on: 'view' | 'instance';
31
+ /** A content query targeting the enclosing projected component instance (`$host` passed as first argument). */
32
+ contentHost?: boolean;
31
33
  }
32
34
  /**
33
35
  * A directive on an element, one per view of it. Its methods take the names in scope, then the directive
@@ -80,6 +82,8 @@ export interface DirectiveUse {
80
82
  * directives made after it on the element, the element's bindings and events, its children and the nodes after it.
81
83
  */
82
84
  exposed?: boolean;
85
+ /** Queries matched against this directive instance (e.g. `contentChild(SomeDirective)`). */
86
+ queries?: QueryHook[];
83
87
  }
84
88
  export type TNode = {
85
89
  kind: 'element';
@@ -101,6 +105,41 @@ export type TNode = {
101
105
  props: Attr[];
102
106
  events: Event[];
103
107
  queries?: QueryHook[];
108
+ slots?: Record<string, TNode[]>;
109
+ directives?: DirectiveUse[];
110
+ }
111
+ /** A content projection slot (`<ng-content>`): `name` is `'default'` or the `select` selector; `fallback` renders when the parent gives no content. */
112
+ | {
113
+ kind: 'slot';
114
+ name: string;
115
+ fallback?: TNode[];
116
+ }
117
+ /** A dynamic component outlet (`*ngComponentOutlet` / `[ngComponentOutlet]`): mounts the component type returned by `component`. */
118
+ | {
119
+ kind: 'componentOutlet';
120
+ component: string;
121
+ injector?: string;
122
+ inputs?: string;
123
+ }
124
+ /** A dynamic or recursive template outlet (`*ngTemplateOutlet` / `[ngTemplateOutlet]`): renders a `TemplateRef` with optional context. */
125
+ | {
126
+ kind: 'templateOutlet';
127
+ template: string;
128
+ context?: string;
129
+ }
130
+ /** Binds a `<ng-template #ref>` body to a component `TemplateRef` field in its enclosing scope (e.g. inside `@let`). */
131
+ | {
132
+ kind: 'bindTemplate';
133
+ field: string;
134
+ ctxParam: string;
135
+ body: TNode[];
136
+ }
137
+ /** A custom structural directive (`*myDir="expr"`): constructs `directive` with `TemplateRef` and `ViewContainerRef` scoped to its region. */
138
+ | {
139
+ kind: 'structural';
140
+ directive: DirectiveUse;
141
+ ctxParam: string;
142
+ body: TNode[];
104
143
  } | {
105
144
  kind: 'if';
106
145
  branches: {
@@ -169,6 +208,12 @@ export interface ComponentIR {
169
208
  /** A routed component whose template is a page's content (an ActionBar plus a view). */
170
209
  page?: boolean;
171
210
  template: TNode[];
211
+ /** Named `<ng-template #ref>` bodies bound to `TemplateRef` fields on the component for dynamic/recursive `*ngTemplateOutlet`. */
212
+ templates?: {
213
+ field: string;
214
+ ctxParam: string;
215
+ body: TNode[];
216
+ }[];
172
217
  /** Props a parent may leave out. */
173
218
  optional?: string[];
174
219
  /** Props set through the component's `$set_<prop>` method (an input's setter) when the binding changes, not passed to its constructor. */
@@ -220,6 +265,8 @@ export interface ComponentIR {
220
265
  onPush?: boolean;
221
266
  /** The component's own stylesheets, scoped by its framework, which the app's build adds after app.css. */
222
267
  styles?: ComponentStyle[];
268
+ /** Content projection slot names declared in this component's template (`'default'` or `select` selectors). */
269
+ slots?: string[];
223
270
  /** Lines of the virtual file (0-based) its template's bindings were made from, with their line (1-based) in `file`, the template's own. */
224
271
  templateLines?: {
225
272
  file: string;