@nstudio/nativescript-compiler-angular 0.0.0-stage → 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.
- package/LICENSE +19 -0
- package/README.md +27 -2
- package/dist/angular-libraries.js +386 -0
- package/dist/angular.js +4189 -0
- package/dist/component-bases.js +853 -0
- package/dist/core-api.js +8 -0
- package/dist/entry.js +150 -0
- package/dist/index.js +233 -0
- package/dist/kotlin.js +295 -0
- package/dist/modules.js +780 -0
- package/dist/ng-modules.js +66 -0
- package/dist/package.js +15 -0
- package/dist/refusals.js +4 -0
- package/dist/semantics.js +274 -0
- package/dist/swift.js +352 -0
- package/kit-android/fromcore/AngularAPI.kt +177 -0
- package/kit-android/fromcore/AngularRouter.kt +720 -0
- package/kit-android/main/AngularChangeDetection.kt +530 -0
- package/kit-android/main/AngularCore.kt +798 -0
- package/kit-android/main/AngularHttp.kt +431 -0
- package/kit-android/main/AngularRouterValues.kt +154 -0
- package/kit-android/main/AngularRx.kt +228 -0
- package/kit-apple/AngularAPI.swift +228 -0
- package/kit-apple/AngularChangeDetection.swift +510 -0
- package/kit-apple/AngularCore.swift +878 -0
- package/kit-apple/AngularHttp.swift +467 -0
- package/kit-apple/AngularRouter.swift +760 -0
- package/kit-apple/AngularRouterValues.swift +285 -0
- package/kit-apple/AngularRx.swift +250 -0
- package/kit-apple/kit-index.json +861 -0
- package/package.json +56 -4
- package/runtime/angular-cdk.ts +673 -0
- package/runtime/angular-forms.ts +3099 -0
- package/runtime/angular-rx.ts +586 -0
- package/runtime/angular.ts +826 -0
package/dist/core-api.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The compiler's own functions and state, from the compiler that loaded the adapter: set by its entry before any front end runs. */
|
|
2
|
+
export let core;
|
|
3
|
+
/** The compiler's TypeScript (`core.ts`), set with `core`: the adapter reads and makes the compiler's syntax trees with it, never with a TypeScript of its own. */
|
|
4
|
+
export let ts;
|
|
5
|
+
export function useCore(api) {
|
|
6
|
+
core = api;
|
|
7
|
+
ts = api.ts;
|
|
8
|
+
}
|
package/dist/entry.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { dirname, join, resolve } from 'node:path';
|
|
2
|
+
import { ts } from "./core-api.js";
|
|
3
|
+
/** A route tree as the Swift kit's `RouteConfig`s. */
|
|
4
|
+
export function swiftRouteConfig(routes, indent, ctx) {
|
|
5
|
+
const one = (r) => {
|
|
6
|
+
const named = [
|
|
7
|
+
r.outlet ? `outlet: ${JSON.stringify(r.outlet)}` : '',
|
|
8
|
+
r.redirectTo !== undefined ? `redirectTo: ${JSON.stringify(r.redirectTo)}` : '',
|
|
9
|
+
r.full ? 'full: true' : '',
|
|
10
|
+
r.emptyOutlet ? 'emptyOutlet: true' : '',
|
|
11
|
+
r.guards !== undefined ? `guards: ${r.guards}` : '',
|
|
12
|
+
r.data ? `data: [${r.data.map(([k, v]) => `(${ctx.string(k)}, ${v === null ? 'jsNull' : typeof v === 'string' ? ctx.string(v) : typeof v === 'number' ? `Double(${Object.is(v, -0) ? '-0.0' : v})` : v})`).join(', ')}]` : '',
|
|
13
|
+
r.children?.length ? `children: ${swiftRouteConfig(r.children, indent + ' ', ctx)}` : '',
|
|
14
|
+
].filter(Boolean);
|
|
15
|
+
// canDeactivate guards take the component: the router keeps the instance it renders.
|
|
16
|
+
const made = r.component ? `AngularView.construct { ${ctx.components.get(r.component)?.initThrows ? 'try ' : ''}${ctx.className(r.component)}() }` : '';
|
|
17
|
+
const make = r.deactivate ? `Router.shared.activating(${made})` : made;
|
|
18
|
+
return `RouteConfig(${[JSON.stringify(r.path), ...named].join(', ')})${r.component ? ` { ${ctx.rootView(r.component, `try ${make}.${ctx.components.get(r.component).members.render}()`)} }` : ''}`;
|
|
19
|
+
};
|
|
20
|
+
return `[\n${routes.map((r) => `${indent} ${one(r)}`).join(',\n')}\n${indent}]`;
|
|
21
|
+
}
|
|
22
|
+
const kotlinDouble = (n) => (Object.is(n, -0) ? '-0.0' : /[.e]/.test(String(n)) ? String(n) : `${n}.0`);
|
|
23
|
+
/** A route tree as the generated Android kit's `RouteConfig`s. */
|
|
24
|
+
export function kotlinRouteConfig(routes, indent, ctx) {
|
|
25
|
+
const one = (r) => {
|
|
26
|
+
const named = [
|
|
27
|
+
r.outlet ? `outlet = ${ctx.string(r.outlet)}` : '',
|
|
28
|
+
r.redirectTo !== undefined ? `redirectTo = ${ctx.string(r.redirectTo)}` : '',
|
|
29
|
+
r.full ? 'full = true' : '',
|
|
30
|
+
r.guards !== undefined ? `guards = ${r.guards}` : '',
|
|
31
|
+
r.data ? `data = listOf(${r.data.map(([k, v]) => `${ctx.string(k)} to ${v === null ? 'jsNull' : typeof v === 'string' ? ctx.string(v) : typeof v === 'number' ? kotlinDouble(v) : v}`).join(', ')})` : '',
|
|
32
|
+
r.children?.length ? `children = ${kotlinRouteConfig(r.children, indent + ' ', ctx)}` : '',
|
|
33
|
+
].filter(Boolean);
|
|
34
|
+
// canDeactivate guards take the component: the router keeps the instance it renders.
|
|
35
|
+
const made = r.component ? `AngularView.construct { ${r.component}() }` : '';
|
|
36
|
+
const make = r.deactivate ? `Router.shared.activating(${made})` : made;
|
|
37
|
+
return `RouteConfig(${[ctx.string(r.path), ...named].join(', ')})${r.component ? ` { ${ctx.rootView(r.component, `${make}.${ctx.components.get(r.component).members.render}()`)} }` : ''}`;
|
|
38
|
+
};
|
|
39
|
+
return `listOf(\n${routes.map((r) => `${indent} ${one(r)}`).join(',\n')}\n${indent})`;
|
|
40
|
+
}
|
|
41
|
+
/** The Angular entry without the call that bootstraps the app, or null when that is all it does. */
|
|
42
|
+
export function angularEntryModule(file, text, routeFiles, components, aliased) {
|
|
43
|
+
const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
|
|
44
|
+
const isBootstrap = (st) => ts.isExpressionStatement(st) && ts.isCallExpression(st.expression)
|
|
45
|
+
&& /^(runNativeScriptAngularApp|platformNativeScript|platformNativeScriptDynamic|bootstrapApplication)\b/.test(st.expression.expression.getText());
|
|
46
|
+
const isBuiltinProviderCall = (e) => {
|
|
47
|
+
if (!ts.isCallExpression(e))
|
|
48
|
+
return false;
|
|
49
|
+
const fn = e.expression.getText();
|
|
50
|
+
if (/^(provideNativeScriptRouter|provideRouter|provideFileRouter|provideZoneChangeDetection|provideZonelessChangeDetection|provideExperimentalZonelessChangeDetection|provideNativeScriptNgZone)$/.test(fn))
|
|
51
|
+
return true;
|
|
52
|
+
if (/^(provideNativeScriptHttpClient|provideHttpClient)$/.test(fn) && e.arguments.every((a) => ts.isCallExpression(a) && /^(withInterceptorsFromDi|withFetch|withJsonpSupport|withNoXsrfProtection)$/.test(a.expression.getText())))
|
|
53
|
+
return true;
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
56
|
+
let hasCustomProviders = false;
|
|
57
|
+
const blankRanges = [];
|
|
58
|
+
const nullFirstArgRanges = [];
|
|
59
|
+
const visit = (n) => {
|
|
60
|
+
if (ts.isCallExpression(n)) {
|
|
61
|
+
const fn = n.expression.getText();
|
|
62
|
+
if (fn === 'bootstrapApplication') {
|
|
63
|
+
if (n.arguments[0]) {
|
|
64
|
+
nullFirstArgRanges.push([n.arguments[0].getStart(), n.arguments[0].getEnd()]);
|
|
65
|
+
}
|
|
66
|
+
const cfg = n.arguments[1];
|
|
67
|
+
if (cfg) {
|
|
68
|
+
if (ts.isObjectLiteralExpression(cfg)) {
|
|
69
|
+
for (const prop of cfg.properties) {
|
|
70
|
+
if (ts.isPropertyAssignment(prop) && prop.name.getText() === 'providers' && ts.isArrayLiteralExpression(prop.initializer)) {
|
|
71
|
+
if (prop.initializer.elements.some((el) => !isBuiltinProviderCall(el))) {
|
|
72
|
+
hasCustomProviders = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
hasCustomProviders = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (fn === 'provideNativeScriptRouter' || fn === 'provideRouter') {
|
|
83
|
+
if (n.arguments.length) {
|
|
84
|
+
blankRanges.push([n.arguments[0].getStart(), n.arguments[n.arguments.length - 1].getEnd()]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
ts.forEachChild(n, visit);
|
|
89
|
+
};
|
|
90
|
+
visit(sf);
|
|
91
|
+
const rest = sf.statements.filter((st) => !ts.isImportDeclaration(st) && !isBootstrap(st));
|
|
92
|
+
if (!rest.length && !hasCustomProviders)
|
|
93
|
+
return null;
|
|
94
|
+
const componentFiles = new Set(components.map((c) => c.file.replace(/\.release\.ts$/, '.ts')));
|
|
95
|
+
const rewriteSpecRanges = [];
|
|
96
|
+
for (const st of sf.statements) {
|
|
97
|
+
if (ts.isImportDeclaration(st) && ts.isStringLiteral(st.moduleSpecifier)) {
|
|
98
|
+
const spec = st.moduleSpecifier.text;
|
|
99
|
+
const base = aliased(spec) ?? (spec.startsWith('.') ? resolve(dirname(file), spec) : undefined);
|
|
100
|
+
if (base) {
|
|
101
|
+
const candidates = [base, base + '.ts', join(base, 'index.ts')];
|
|
102
|
+
if (candidates.some((c) => routeFiles.has(c))) {
|
|
103
|
+
blankRanges.push([st.getStart(), st.getEnd()]);
|
|
104
|
+
}
|
|
105
|
+
else if (candidates.some((c) => componentFiles.has(c))) {
|
|
106
|
+
const importedNames = [];
|
|
107
|
+
const clause = st.importClause;
|
|
108
|
+
if (clause?.name)
|
|
109
|
+
importedNames.push(clause.name.text);
|
|
110
|
+
if (clause?.namedBindings && ts.isNamedImports(clause.namedBindings)) {
|
|
111
|
+
for (const el of clause.namedBindings.elements)
|
|
112
|
+
importedNames.push(el.name.text);
|
|
113
|
+
}
|
|
114
|
+
const maskedText = (() => {
|
|
115
|
+
let t = text;
|
|
116
|
+
for (const [s, e] of nullFirstArgRanges)
|
|
117
|
+
t = t.slice(0, s) + ' '.repeat(e - s) + t.slice(e);
|
|
118
|
+
for (const [s, e] of blankRanges)
|
|
119
|
+
t = t.slice(0, s) + ' '.repeat(e - s) + t.slice(e);
|
|
120
|
+
return t.slice(0, st.getStart()) + ' '.repeat(st.getEnd() - st.getStart()) + t.slice(st.getEnd());
|
|
121
|
+
})();
|
|
122
|
+
const stillUsed = importedNames.some((n) => new RegExp(`\\b${n}\\b`).test(maskedText));
|
|
123
|
+
if (stillUsed) {
|
|
124
|
+
const targetFile = candidates.find((c) => componentFiles.has(c));
|
|
125
|
+
rewriteSpecRanges.push([st.moduleSpecifier.getStart(), st.moduleSpecifier.getEnd(), JSON.stringify(targetFile.replace(/\.ts$/, '.release.ts'))]);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
blankRanges.push([st.getStart(), st.getEnd()]);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (isBootstrap(st) && !hasCustomProviders) {
|
|
134
|
+
blankRanges.push([st.getStart(), st.getEnd()]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
let out = text;
|
|
138
|
+
for (const [s, e] of nullFirstArgRanges) {
|
|
139
|
+
const len = e - s;
|
|
140
|
+
const rep = (len >= 4 ? 'null' : '0').padEnd(len, ' ');
|
|
141
|
+
out = out.slice(0, s) + rep + out.slice(e);
|
|
142
|
+
}
|
|
143
|
+
for (const [s, e] of blankRanges) {
|
|
144
|
+
out = out.slice(0, s) + out.slice(s, e).replace(/[^\n]/g, ' ') + out.slice(e);
|
|
145
|
+
}
|
|
146
|
+
for (const [s, e, rep] of rewriteSpecRanges.sort((a, b) => b[0] - a[0])) {
|
|
147
|
+
out = out.slice(0, s) + rep + out.slice(e);
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { angularComponents, angularDirectives, angularPipes, angularRoutes, angularRouteTree, componentsOf, declarableSource, declarablesIn, hostedComponents, routedComponents, selectorElements } from "./angular.js";
|
|
4
|
+
import { angularLibraries, registeredElements } from "./angular-libraries.js";
|
|
5
|
+
import { refuseBaseUses } from "./component-bases.js";
|
|
6
|
+
import { useCore } from "./core-api.js";
|
|
7
|
+
import { angularEntryModule, kotlinRouteConfig, swiftRouteConfig } from "./entry.js";
|
|
8
|
+
import { modules } from "./modules.js";
|
|
9
|
+
import { PACKAGE, RUNTIME } from "./package.js";
|
|
10
|
+
import { refusals } from "./refusals.js";
|
|
11
|
+
import { kotlinHooks } from "./kotlin.js";
|
|
12
|
+
import { swiftHooks } from "./swift.js";
|
|
13
|
+
/** @angular/common's pipes, NgClass, NgStyle and QueryList as TypeScript the app's components compile with. */
|
|
14
|
+
const COMMON = join(RUNTIME, 'angular.ts');
|
|
15
|
+
/** The build's own module of `COMMON`, in the app's folder: the components import it by a relative path. */
|
|
16
|
+
const COMMON_MODULE = '__angular.release.ts';
|
|
17
|
+
/**
|
|
18
|
+
* Angular makes a view in two passes (`passes`), a child component made without its inputs and then given them, appends
|
|
19
|
+
* each view as it is created, runs a template's bindings once its views are built, and re-reads every binding when change detection checks its view
|
|
20
|
+
* (`Check`); an OnPush component is checked only once marked dirty (`check+onPush`). A listener marks its view and the views above it dirty (`markViewDirty`). Views and
|
|
21
|
+
* embedded views order effects, an embedded view refreshed after its declaring view's bindings (`EmbeddedViews`); `ngDoCheck` runs on every
|
|
22
|
+
* check of the view its component or directive is in (`EveryCheck`), `ngAfterContentChecked` and `ngAfterViewChecked`
|
|
23
|
+
* at their points of it (`ContentChecked`, `ViewChecked`); a `@let` is read once per check into its slot (`LetSlot`);
|
|
24
|
+
* `@for` rows read their item and index as signals.
|
|
25
|
+
*/
|
|
26
|
+
const behaviour = {
|
|
27
|
+
schedule: 'task', eventScope: 'event+dirtyView', propsOrder: 'pre', deferBindings: true, insertion: 'created', listenersAfterBindings: false,
|
|
28
|
+
effectScope: 'view', checkEveryBinding: 'check+onPush', slots: false, rowSignals: 'array', fragments: true, inputsAfterConstruction: true, passes: true,
|
|
29
|
+
kit: {
|
|
30
|
+
scope: { template: 'EffectOrder.view', region: 'EffectOrder.embedded' },
|
|
31
|
+
currentView: 'EffectOrder.current.view',
|
|
32
|
+
check: 'Check',
|
|
33
|
+
inputChanged: 'Zone.inputChanged',
|
|
34
|
+
directiveHost: 'ElementRef.hosting',
|
|
35
|
+
routerOutlet: { call: 'Router.shared.outlet', primary: 'primary' },
|
|
36
|
+
componentOutlet: 'ComponentOutlet.mount',
|
|
37
|
+
templateOutlet: 'TemplateOutlet.mount',
|
|
38
|
+
structuralScope: 'StructuralDirective.scope',
|
|
39
|
+
embedded: { collect: 'EmbeddedViews.collect', later: 'EmbeddedViews.later' },
|
|
40
|
+
everyCheck: { check: 'EveryCheck', content: 'ContentChecked', view: 'ViewChecked' },
|
|
41
|
+
letSlot: 'LetSlot',
|
|
42
|
+
construct: 'AngularView.construct',
|
|
43
|
+
flushEffects: 'Zone.flushEffects',
|
|
44
|
+
rootScope: 'EffectOrder.root',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
export default function adapter(core) {
|
|
48
|
+
useCore(core);
|
|
49
|
+
return {
|
|
50
|
+
apiVersion: 1,
|
|
51
|
+
name: 'angular',
|
|
52
|
+
packages: ['@nativescript/angular', '@angular/*'],
|
|
53
|
+
behaviour,
|
|
54
|
+
reach: 'entry',
|
|
55
|
+
swift: swiftHooks,
|
|
56
|
+
kotlin: kotlinHooks,
|
|
57
|
+
modules,
|
|
58
|
+
runtimeRoots: [RUNTIME],
|
|
59
|
+
runtimeModules: [COMMON_MODULE],
|
|
60
|
+
package: PACKAGE,
|
|
61
|
+
kit: { apple: 'kit-apple', android: 'kit-android/main', androidGenerated: 'kit-android/fromcore' },
|
|
62
|
+
refusals,
|
|
63
|
+
frontEnd(app) {
|
|
64
|
+
const read = (f) => readFileSync(f, 'utf8');
|
|
65
|
+
const { sources, entry, entryText, appDir, platform } = app;
|
|
66
|
+
// The Angular components of plugins the app imports (`<package>/angular`), compiled from their source with the app's.
|
|
67
|
+
const libraries = angularLibraries(sources, app.nodeModules, app.plugins, app.replacedPackages);
|
|
68
|
+
sources.push(...libraries);
|
|
69
|
+
const selectors = new Map();
|
|
70
|
+
const hosts = [];
|
|
71
|
+
const componentSlots = new Map();
|
|
72
|
+
const componentContentQueries = new Map();
|
|
73
|
+
for (const f of sources) {
|
|
74
|
+
const text = read(f);
|
|
75
|
+
const found = componentsOf(f, text);
|
|
76
|
+
for (const c of found) {
|
|
77
|
+
for (const tag of c.selector ? selectorElements(c.selector) : [])
|
|
78
|
+
selectors.set(tag, c.name);
|
|
79
|
+
if (c.slots?.length)
|
|
80
|
+
componentSlots.set(c.name, c.slots);
|
|
81
|
+
if (c.contentQueries?.length)
|
|
82
|
+
componentContentQueries.set(c.name, { file: f, queries: c.contentQueries });
|
|
83
|
+
}
|
|
84
|
+
if (found.length)
|
|
85
|
+
hosts.push(...hostedComponents(f, text));
|
|
86
|
+
}
|
|
87
|
+
// The configuration the entry provides, lazy routes followed into their files; else one routes file read flat.
|
|
88
|
+
const tree = angularRouteTree(entry, read, app.aliased);
|
|
89
|
+
const routesFile = tree ? undefined : sources.find((f) => /Routes\b/.test(read(f)) && /component:/.test(read(f)));
|
|
90
|
+
const { routes, initial } = routesFile ? angularRoutes(read(routesFile), routesFile) : { routes: [], initial: '/' };
|
|
91
|
+
const routeFiles = new Set([...(tree?.files ?? []), ...(routesFile ? [routesFile] : [])]);
|
|
92
|
+
// Tags the entry registers too (`registerElement('Glass', …)` in main.ts, before the app bootstraps).
|
|
93
|
+
const elements = registeredElements([...(entry && !sources.includes(entry) ? [entry] : []), ...sources], app.nodeModules);
|
|
94
|
+
// Angular 22 checks with zone.js only when the app provides it (`provideZoneChangeDetection`, or @nativescript/angular's
|
|
95
|
+
// `provideNativeScriptNgZone`, which is `_internalProvideZoneChangeDetection` with its own NgZone) and not `provideZonelessChangeDetection`.
|
|
96
|
+
const texts = [entryText, ...sources.map(read)];
|
|
97
|
+
const zone = texts.some((t) => /\bprovide(ZoneChangeDetection|NativeScriptNgZone)\(/.test(t)) && !texts.some((t) => /\bprovideZonelessChangeDetection\(/.test(t));
|
|
98
|
+
// The pipes templates name: the app's and its libraries' `@Pipe` classes, published Angular library pipes (`ɵɵPipeDeclaration`), and @angular/common's.
|
|
99
|
+
const pipes = angularPipes([...(entry && !sources.includes(entry) ? [entry] : []), ...sources], read, app.nodeModules);
|
|
100
|
+
// The app's own directives: a library's are written against the view internals a compiled template replaces.
|
|
101
|
+
const directives = angularDirectives(sources.filter((f) => !libraries.includes(f)), read);
|
|
102
|
+
// What each NgModule declares, imports and exports: a component's directives are those in its scope.
|
|
103
|
+
const ngModuleNames = new Map(sources.flatMap((f) => [...declarablesIn(f, read(f), !libraries.includes(f)).modules]));
|
|
104
|
+
const runtimeModule = join(appDir, COMMON_MODULE);
|
|
105
|
+
refuseBaseUses(sources, undefined, app.aliased);
|
|
106
|
+
const components = sources.flatMap((f) => angularComponents(f, read(f), selectors, { platform, pipes, runtimeModule, directives, ngModules: ngModuleNames, hosts, componentSlots, componentContentQueries, aliased: app.aliased, elements: new Map([...elements].map(([tag, e]) => [tag, e.name])), elementMeta: new Map([...elements].flatMap(([tag, e]) => (e.meta === undefined || (e.meta === null && e.fromApp) ? [] : [[tag, e.meta]]))) }));
|
|
107
|
+
const routed = new Set(tree ? routedComponents(tree.routes) : routes.map((r) => r.component));
|
|
108
|
+
for (const c of components)
|
|
109
|
+
c.page = routed.has(c.name);
|
|
110
|
+
const overrides = new Map();
|
|
111
|
+
// The classes of registered tags, imported where the build can reach them: route files, which only configure, are not compiled.
|
|
112
|
+
if (elements.size) {
|
|
113
|
+
const file = join(appDir, '__elements.release.ts');
|
|
114
|
+
const entries = [...elements.entries()];
|
|
115
|
+
const unique = new Map();
|
|
116
|
+
const usedAliases = new Set();
|
|
117
|
+
const aliasOf = (e) => {
|
|
118
|
+
const key = `${e.from}\0${e.name}`;
|
|
119
|
+
const existing = unique.get(key);
|
|
120
|
+
if (existing)
|
|
121
|
+
return existing.alias;
|
|
122
|
+
let alias = e.name;
|
|
123
|
+
let i = 2;
|
|
124
|
+
while (usedAliases.has(alias))
|
|
125
|
+
alias = `${e.name}$${i++}`;
|
|
126
|
+
usedAliases.add(alias);
|
|
127
|
+
unique.set(key, { name: e.name, alias, from: e.from });
|
|
128
|
+
return alias;
|
|
129
|
+
};
|
|
130
|
+
for (const [, e] of entries)
|
|
131
|
+
aliasOf(e);
|
|
132
|
+
const withMeta = entries.filter(([, e]) => !!e.metaCode);
|
|
133
|
+
const imports = [
|
|
134
|
+
...(withMeta.length ? ["import { registerElement } from '@nativescript/angular';"] : []),
|
|
135
|
+
...[...unique.values()].map((u) => `import { ${u.alias === u.name ? u.name : `${u.name} as ${u.alias}`} } from '${u.from}';`),
|
|
136
|
+
].join('\n');
|
|
137
|
+
const registrations = withMeta.map(([tag, e]) => `registerElement(${JSON.stringify(tag)}, () => ${aliasOf(e)}, ${e.metaCode});`).join('\n');
|
|
138
|
+
overrides.set(file, `${imports}\n${registrations ? registrations + '\n' : ''}export function $elements(): any[] { return [${[...unique.values()].map((u) => `new ${u.alias}()`).join(', ')}]; }\n`);
|
|
139
|
+
}
|
|
140
|
+
const modules = [...sources.filter((f) => !routeFiles.has(f) && !components.some((c) => c.file === f.replace(/\.ts$/, '.release.ts'))), ...(elements.size ? [join(appDir, '__elements.release.ts')] : [])];
|
|
141
|
+
// Route files only configure and are not compiled; their guards are, each file's in a module of its own.
|
|
142
|
+
(tree?.guards ?? []).forEach((g, i) => {
|
|
143
|
+
const file = join(appDir, `__routes${i}.release.ts`);
|
|
144
|
+
overrides.set(file, g.source(appDir, platform));
|
|
145
|
+
modules.push(file);
|
|
146
|
+
});
|
|
147
|
+
if (components.some((c) => 'usesRuntime' in c && c.usesRuntime)) {
|
|
148
|
+
overrides.set(runtimeModule, read(COMMON));
|
|
149
|
+
modules.push(runtimeModule);
|
|
150
|
+
}
|
|
151
|
+
// `@Pipe` and `@Directive` classes without their decorators, made through the `$create` that injects their constructor's parameters.
|
|
152
|
+
for (const f of modules) {
|
|
153
|
+
if (overrides.has(f))
|
|
154
|
+
continue;
|
|
155
|
+
const declarable = declarableSource(f, read(f));
|
|
156
|
+
if (declarable)
|
|
157
|
+
overrides.set(f, declarable);
|
|
158
|
+
}
|
|
159
|
+
// The entry's own statements (an app delegate, a keyboard setup) run after the modules it imports, the bootstrap call aside.
|
|
160
|
+
const entryModule = angularEntryModule(entry, entryText, routeFiles, components, app.aliased);
|
|
161
|
+
if (entryModule) {
|
|
162
|
+
overrides.set(entry, entryModule);
|
|
163
|
+
modules.push(entry);
|
|
164
|
+
}
|
|
165
|
+
let root = /bootstrapApplication\(\s*(\w+)/.exec(entryText)?.[1] ?? '';
|
|
166
|
+
const appModule = /bootstrapModule\(\s*(\w+)/.exec(entryText)?.[1];
|
|
167
|
+
if (!root && appModule) {
|
|
168
|
+
const declaring = sources.map(read).find((t) => new RegExp(`class\\s+${appModule}\\b`).test(t));
|
|
169
|
+
root = (declaring && /bootstrap:\s*\[\s*(\w+)/.exec(declaring)?.[1]) ?? '';
|
|
170
|
+
}
|
|
171
|
+
if (!root)
|
|
172
|
+
throw new Error(`${entry}: no bootstrapApplication(Component) or bootstrapModule(AppModule) with a bootstrap component`);
|
|
173
|
+
const hasComponentOutlet = (() => {
|
|
174
|
+
const visit = (nodes) => nodes.some((n) => n.kind === 'componentOutlet'
|
|
175
|
+
|| (Array.isArray(n.children) && visit(n.children))
|
|
176
|
+
|| (Array.isArray(n.body) && visit(n.body))
|
|
177
|
+
|| (Array.isArray(n.branches) && n.branches.some((b) => visit(b.body)))
|
|
178
|
+
|| (Array.isArray(n.fallback) && visit(n.fallback))
|
|
179
|
+
|| (!!n.slots && Object.values(n.slots).some((s) => visit(s))));
|
|
180
|
+
return components.some((c) => visit(c.template));
|
|
181
|
+
})();
|
|
182
|
+
const zoneEnabled = zone ? ' Zone.enabled = true\n' : '';
|
|
183
|
+
return {
|
|
184
|
+
components,
|
|
185
|
+
modules,
|
|
186
|
+
overrides,
|
|
187
|
+
root,
|
|
188
|
+
behaviour,
|
|
189
|
+
elementClasses: new Set([...elements.values()].map((e) => e.name)),
|
|
190
|
+
entry: {
|
|
191
|
+
swift: (ctx) => {
|
|
192
|
+
const outlets = hasComponentOutlet
|
|
193
|
+
? [...ctx.components.entries()]
|
|
194
|
+
.filter(([, info]) => !(info.props ?? []).some((p) => !(info.optional ?? []).includes(p)))
|
|
195
|
+
.map(([name, info]) => {
|
|
196
|
+
const cls = ctx.className(name);
|
|
197
|
+
const make = `try AngularView.construct { ${info.initThrows ? 'try ' : ''}${cls}() }`;
|
|
198
|
+
const body = info.fragment ? `try ${make}.${info.members.render}(into: region)` : `region.set([try ${make}.${info.members.render}()])`;
|
|
199
|
+
return ` ComponentOutlet.register(${cls}.self) { region, _ in ${body} }\n`;
|
|
200
|
+
})
|
|
201
|
+
.join('')
|
|
202
|
+
: '';
|
|
203
|
+
return {
|
|
204
|
+
setup: zoneEnabled,
|
|
205
|
+
beforeRoot: outlets + (tree
|
|
206
|
+
? ` Router.shared.config = ${swiftRouteConfig(tree.routes, ' ', ctx)}\n`
|
|
207
|
+
: ` Router.shared.routes = [${routes.map((r) => `Route(${JSON.stringify(r.path)}) { ${ctx.rootView(r.component, `try AngularView.construct { ${ctx.components.get(r.component)?.initThrows ? 'try ' : ''}${ctx.className(r.component)}() }.${ctx.components.get(r.component).members.render}()`)} }`).join(', ')}]\n Router.shared.initial = ${JSON.stringify(initial)}\n`),
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
kotlin: (ctx) => {
|
|
211
|
+
const outlets = hasComponentOutlet
|
|
212
|
+
? [...ctx.components.entries()]
|
|
213
|
+
.filter(([, info]) => !(info.props ?? []).some((p) => !(info.optional ?? []).includes(p)))
|
|
214
|
+
.map(([name, info]) => {
|
|
215
|
+
const cls = ctx.className(name);
|
|
216
|
+
const make = `AngularView.construct { ${cls}() }`;
|
|
217
|
+
const body = info.fragment ? `${make}.${info.members.render}(region)` : `region.set(listOf(${make}.${info.members.render}()))`;
|
|
218
|
+
return ` ComponentOutlet.register(${cls}::class.java) { region, _ -> ${body} }\n`;
|
|
219
|
+
})
|
|
220
|
+
.join('')
|
|
221
|
+
: '';
|
|
222
|
+
return {
|
|
223
|
+
setup: zoneEnabled,
|
|
224
|
+
beforeRoot: outlets + (tree
|
|
225
|
+
? ` Router.shared.config = ${kotlinRouteConfig(tree.routes, ' ', ctx)}\n`
|
|
226
|
+
: ` Router.shared.routes = listOf(${routes.map((r) => `Route(${ctx.string(r.path)}) { ${ctx.rootView(r.component, `AngularView.construct { ${r.component}() }.${ctx.components.get(r.component).members.render}()`)} }`).join(', ')})\n Router.shared.initial = ${ctx.string(initial)}\n`),
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|