@nstudio/nativescript-compiler-angular 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.
- package/dist/angular-libraries.js +225 -12
- package/dist/angular.js +1453 -202
- package/dist/component-bases.js +144 -37
- package/dist/entry.js +32 -2
- package/dist/index.js +93 -25
- package/dist/kotlin.js +9 -7
- package/dist/modules.js +100 -20
- package/dist/refusals.js +0 -1
- package/dist/semantics.js +16 -4
- package/dist/swift.js +9 -9
- package/kit-android/fromcore/AngularAPI.kt +3 -1
- package/kit-android/fromcore/AngularRouter.kt +105 -2
- package/kit-android/main/AngularCore.kt +121 -8
- package/kit-android/main/AngularRx.kt +4 -0
- package/kit-apple/AngularAPI.swift +6 -2
- package/kit-apple/AngularCore.swift +119 -5
- package/kit-apple/AngularRouter.swift +105 -0
- package/kit-apple/AngularRx.swift +4 -0
- package/kit-apple/kit-index.json +103 -5
- package/package.json +2 -2
- package/runtime/angular-cdk.ts +673 -0
- package/runtime/angular-rx.ts +38 -2
|
@@ -105,13 +105,128 @@ export function angularLibraries(sources, modulesDir, plugins, replaced) {
|
|
|
105
105
|
}
|
|
106
106
|
return out;
|
|
107
107
|
}
|
|
108
|
+
/** Annotates untyped parameters of JS function/arrow/method expressions inside a node so it compiles in strict TS. */
|
|
109
|
+
function typedMetaLiteral(sf, node) {
|
|
110
|
+
const edits = [];
|
|
111
|
+
const visit = (n) => {
|
|
112
|
+
if (ts.isParameter(n) && !n.type)
|
|
113
|
+
edits.push({ at: n.name.getEnd(), text: ': any' });
|
|
114
|
+
ts.forEachChild(n, visit);
|
|
115
|
+
};
|
|
116
|
+
visit(node);
|
|
117
|
+
const start = node.getStart(sf);
|
|
118
|
+
let text = node.getText(sf);
|
|
119
|
+
for (const e of edits.sort((a, b) => b.at - a.at)) {
|
|
120
|
+
const pos = e.at - start;
|
|
121
|
+
text = text.slice(0, pos) + e.text + text.slice(pos);
|
|
122
|
+
}
|
|
123
|
+
return text;
|
|
124
|
+
}
|
|
125
|
+
/** Collects top-level constant and helper function declarations referenced by `obj` (e.g. `MAINCONTENT = 'MainContent'`, `rawChildIndex(...)`). */
|
|
126
|
+
function metaLiteralCode(sf, obj) {
|
|
127
|
+
const decls = new Map();
|
|
128
|
+
for (const st of sf.statements) {
|
|
129
|
+
if (ts.isFunctionDeclaration(st) && st.name) {
|
|
130
|
+
decls.set(st.name.text, { node: st, code: typedMetaLiteral(sf, st) });
|
|
131
|
+
}
|
|
132
|
+
else if (ts.isVariableStatement(st) && (st.declarationList.flags & ts.NodeFlags.Const)) {
|
|
133
|
+
for (const d of st.declarationList.declarations) {
|
|
134
|
+
if (!ts.isIdentifier(d.name) || !d.initializer)
|
|
135
|
+
continue;
|
|
136
|
+
if (ts.isStringLiteralLike(d.initializer) || ts.isNumericLiteral(d.initializer) || d.initializer.kind === ts.SyntaxKind.TrueKeyword || d.initializer.kind === ts.SyntaxKind.FalseKeyword) {
|
|
137
|
+
decls.set(d.name.text, { node: d.initializer, code: `const ${d.name.text} = ${d.initializer.getText(sf)};` });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const used = new Set();
|
|
143
|
+
const scanIds = (n) => {
|
|
144
|
+
if (ts.isIdentifier(n) && decls.has(n.text) && !used.has(n.text) && !(ts.isPropertyAccessExpression(n.parent) && n.parent.name === n) && !(ts.isPropertyAssignment(n.parent) && n.parent.name === n) && !(ts.isFunctionDeclaration(n.parent) && n.parent.name === n)) {
|
|
145
|
+
used.add(n.text);
|
|
146
|
+
scanIds(decls.get(n.text).node);
|
|
147
|
+
}
|
|
148
|
+
ts.forEachChild(n, scanIds);
|
|
149
|
+
};
|
|
150
|
+
scanIds(obj);
|
|
151
|
+
const body = typedMetaLiteral(sf, obj);
|
|
152
|
+
if (!used.size)
|
|
153
|
+
return body;
|
|
154
|
+
return `(() => { ${[...used].map((k) => decls.get(k).code).join(' ')} return ${body}; })()`;
|
|
155
|
+
}
|
|
156
|
+
/** Discovers elements registered via a plugin helper module (e.g. `<pkg>/elements.js` + `@CSSType` decorators in `<pkg>/web.js`). */
|
|
157
|
+
function scanPluginElementTable(pkg, helperSubpath, modulesDir, metaObj, fesmSf, found) {
|
|
158
|
+
const pkgDir = join(modulesDir, pkg);
|
|
159
|
+
const candidates = [join(pkgDir, helperSubpath + '.js'), join(pkgDir, helperSubpath, 'index.js'), join(pkgDir, helperSubpath + '.mjs')];
|
|
160
|
+
const helperFile = candidates.find(existsSync);
|
|
161
|
+
if (!helperFile)
|
|
162
|
+
return;
|
|
163
|
+
const helperText = readFileSync(helperFile, 'utf8');
|
|
164
|
+
const helperSf = ts.createSourceFile(helperFile, helperText, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
165
|
+
const helperImports = new Map();
|
|
166
|
+
const namespaceImports = [];
|
|
167
|
+
for (const st of helperSf.statements) {
|
|
168
|
+
if (!ts.isImportDeclaration(st) || !ts.isStringLiteral(st.moduleSpecifier))
|
|
169
|
+
continue;
|
|
170
|
+
const spec = st.moduleSpecifier.text;
|
|
171
|
+
const from = spec === '.' || spec === './' || spec === './index' ? pkg : spec.startsWith('./') ? `${pkg}/${spec.slice(2).replace(/\.js$/, '')}` : spec;
|
|
172
|
+
const clause = st.importClause;
|
|
173
|
+
if (clause?.namedBindings && ts.isNamedImports(clause.namedBindings)) {
|
|
174
|
+
for (const el of clause.namedBindings.elements) {
|
|
175
|
+
helperImports.set(el.name.text, [(el.propertyName ?? el.name).text, from]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else if (clause?.namedBindings && ts.isNamespaceImport(clause.namedBindings)) {
|
|
179
|
+
namespaceImports.push({ local: clause.namedBindings.name.text, spec });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const seen = new Set();
|
|
183
|
+
const metaCode = metaObj ? metaLiteralCode(fesmSf, metaObj) : undefined;
|
|
184
|
+
const add = (tag, name, from) => {
|
|
185
|
+
const key = tag.toLowerCase();
|
|
186
|
+
if (!key || seen.has(key) || found.has(tag))
|
|
187
|
+
return;
|
|
188
|
+
seen.add(key);
|
|
189
|
+
found.set(tag, { name, from, ...(metaObj ? { meta: ['insertChild', 'removeChild'] } : {}), ...(metaCode ? { metaCode } : {}) });
|
|
190
|
+
};
|
|
191
|
+
// Scan namespace-imported modules (e.g. `./web.js`) for `__decorate([CSSType('tag'), ...], Class)` via AST.
|
|
192
|
+
for (const ns of namespaceImports) {
|
|
193
|
+
const nsBase = resolve(dirname(helperFile), ns.spec);
|
|
194
|
+
const nsFile = [nsBase, nsBase + '.js', join(nsBase, 'index.js')].find(existsSync);
|
|
195
|
+
if (!nsFile)
|
|
196
|
+
continue;
|
|
197
|
+
const nsFrom = ns.spec.startsWith('./') ? `${pkg}/${ns.spec.slice(2).replace(/\.js$/, '')}` : ns.spec;
|
|
198
|
+
const nsSf = ts.createSourceFile(nsFile, readFileSync(nsFile, 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
199
|
+
const visitNs = (n) => {
|
|
200
|
+
if (ts.isCallExpression(n) && ts.isIdentifier(n.expression) && n.expression.text === '__decorate' && n.arguments.length >= 2 && ts.isArrayLiteralExpression(n.arguments[0]) && ts.isIdentifier(n.arguments[1])) {
|
|
201
|
+
const clsName = n.arguments[1].text;
|
|
202
|
+
for (const el of n.arguments[0].elements) {
|
|
203
|
+
if (ts.isCallExpression(el) && ts.isIdentifier(el.expression) && el.expression.text === 'CSSType' && el.arguments.length >= 1 && ts.isStringLiteralLike(el.arguments[0])) {
|
|
204
|
+
add(el.arguments[0].text, clsName, nsFrom);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
ts.forEachChild(n, visitNs);
|
|
209
|
+
};
|
|
210
|
+
visitNs(nsSf);
|
|
211
|
+
}
|
|
212
|
+
// Scan tuple arrays `[['View', View], ['Scroll', Scroll], ...]` inside the helper module.
|
|
213
|
+
const visitTuples = (n) => {
|
|
214
|
+
if (ts.isArrayLiteralExpression(n) && n.elements.length === 2 && ts.isStringLiteralLike(n.elements[0]) && ts.isIdentifier(n.elements[1])) {
|
|
215
|
+
const imp = helperImports.get(n.elements[1].text);
|
|
216
|
+
if (imp)
|
|
217
|
+
add(n.elements[0].text, imp[0], imp[1]);
|
|
218
|
+
}
|
|
219
|
+
ts.forEachChild(n, visitTuples);
|
|
220
|
+
};
|
|
221
|
+
visitTuples(helperSf);
|
|
222
|
+
}
|
|
108
223
|
/**
|
|
109
224
|
* Tags registered for plugin views: `registerElement('Tag', () => Class)` or `registerElement('Tag', () => Class, meta)`
|
|
110
225
|
* in the app, and in the Angular entry (`<package>/angular`) of a plugin the app imports, with the module each class is from.
|
|
111
226
|
*/
|
|
112
227
|
export function registeredElements(sources, modulesDir) {
|
|
113
228
|
const found = new Map();
|
|
114
|
-
const scan = (text, file) => {
|
|
229
|
+
const scan = (text, file, pluginPkg) => {
|
|
115
230
|
if (!text.includes('registerElement'))
|
|
116
231
|
return;
|
|
117
232
|
const imports = new Map();
|
|
@@ -137,14 +252,56 @@ export function registeredElements(sources, modulesDir) {
|
|
|
137
252
|
}
|
|
138
253
|
return null;
|
|
139
254
|
};
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
return;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
255
|
+
const stringArrays = new Map();
|
|
256
|
+
const stringsOf = (e) => {
|
|
257
|
+
if (ts.isAsExpression(e))
|
|
258
|
+
return stringsOf(e.expression);
|
|
259
|
+
if (ts.isIdentifier(e))
|
|
260
|
+
return stringArrays.get(e.text) ?? null;
|
|
261
|
+
if (!ts.isArrayLiteralExpression(e))
|
|
262
|
+
return null;
|
|
263
|
+
const items = [];
|
|
264
|
+
for (const el of e.elements) {
|
|
265
|
+
if (ts.isStringLiteralLike(el))
|
|
266
|
+
items.push(el.text);
|
|
267
|
+
else if (ts.isSpreadElement(el)) {
|
|
268
|
+
const inner = stringsOf(el.expression);
|
|
269
|
+
if (!inner)
|
|
270
|
+
return null;
|
|
271
|
+
items.push(...inner);
|
|
272
|
+
}
|
|
273
|
+
else
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
return items;
|
|
277
|
+
};
|
|
278
|
+
for (const st of sf.statements) {
|
|
279
|
+
if (!ts.isVariableStatement(st) || !(st.declarationList.flags & ts.NodeFlags.Const))
|
|
280
|
+
continue;
|
|
281
|
+
for (const d of st.declarationList.declarations) {
|
|
282
|
+
if (ts.isIdentifier(d.name) && d.initializer) {
|
|
283
|
+
const arr = stringsOf(d.initializer);
|
|
284
|
+
if (arr)
|
|
285
|
+
stringArrays.set(d.name.text, arr);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const localBaseClass = (name, scope) => {
|
|
290
|
+
for (let cur = scope; cur; cur = cur.parent) {
|
|
291
|
+
if (ts.isBlock(cur) || ts.isSourceFile(cur)) {
|
|
292
|
+
for (const st of cur.statements) {
|
|
293
|
+
if (ts.isClassDeclaration(st) && st.name?.text === name) {
|
|
294
|
+
const ext = st.heritageClauses?.find((h) => h.token === ts.SyntaxKind.ExtendsKeyword)?.types[0]?.expression;
|
|
295
|
+
if (ext && ts.isIdentifier(ext))
|
|
296
|
+
return ext.text;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return undefined;
|
|
302
|
+
};
|
|
303
|
+
const record = (tagText, clsId, meta, scope) => {
|
|
304
|
+
const imported = imports.get(clsId) ?? (localBaseClass(clsId, scope) ? imports.get(localBaseClass(clsId, scope)) : undefined);
|
|
148
305
|
if (!imported)
|
|
149
306
|
return;
|
|
150
307
|
const [name, from] = JSON.parse(imported);
|
|
@@ -152,8 +309,64 @@ export function registeredElements(sources, modulesDir) {
|
|
|
152
309
|
if (from === '@nativescript/core' || core.stubbedPlugins.has(core.packageOf(from)))
|
|
153
310
|
return;
|
|
154
311
|
const object = meta ? objectOf(meta) : null;
|
|
155
|
-
const keys = object && object.properties.every((p) => p.name && !ts.isComputedPropertyName(p.name))
|
|
156
|
-
|
|
312
|
+
const keys = object && object.properties.every((p) => p.name && !ts.isComputedPropertyName(p.name))
|
|
313
|
+
? object.properties.flatMap((p) => {
|
|
314
|
+
const key = p.name.getText().replace(/^['"]|['"]$/g, '');
|
|
315
|
+
// `skipAddToDom: false` explicitly opts in to the visual tree (e.g. MasonKit's `masonMeta`).
|
|
316
|
+
if (key === 'skipAddToDom' && ts.isPropertyAssignment(p) && p.initializer.kind === ts.SyntaxKind.FalseKeyword)
|
|
317
|
+
return [];
|
|
318
|
+
return [key];
|
|
319
|
+
})
|
|
320
|
+
: null;
|
|
321
|
+
const hasChildHooks = !!keys && keys.some((k) => k === 'insertChild' || k === 'removeChild');
|
|
322
|
+
const metaCode = !file && object && hasChildHooks ? metaLiteralCode(sf, object) : undefined;
|
|
323
|
+
found.set(tagText, {
|
|
324
|
+
name,
|
|
325
|
+
from: from.startsWith('.') && file ? resolve(dirname(file), from) : from,
|
|
326
|
+
...(meta ? { meta: keys } : {}),
|
|
327
|
+
...(metaCode ? { metaCode } : {}),
|
|
328
|
+
...(file ? { fromApp: true } : {}),
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
const loopTags = new Map();
|
|
332
|
+
const visit = (n) => {
|
|
333
|
+
if (ts.isForOfStatement(n)) {
|
|
334
|
+
const decl = ts.isVariableDeclarationList(n.initializer) ? n.initializer.declarations[0] : undefined;
|
|
335
|
+
if (decl && ts.isIdentifier(decl.name)) {
|
|
336
|
+
const tags = stringsOf(n.expression);
|
|
337
|
+
if (tags) {
|
|
338
|
+
loopTags.set(decl.name.text, tags);
|
|
339
|
+
ts.forEachChild(n.statement, visit);
|
|
340
|
+
loopTags.delete(decl.name.text);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// Plugin FESM loop over an imported element-table helper (`for (const { tag, ctor } of getMasonKitElements(...))`).
|
|
345
|
+
if (!file && pluginPkg && ts.isCallExpression(n.expression) && ts.isIdentifier(n.expression.expression)) {
|
|
346
|
+
const imp = imports.get(n.expression.expression.text);
|
|
347
|
+
if (imp) {
|
|
348
|
+
const [, helperFrom] = JSON.parse(imp);
|
|
349
|
+
if (helperFrom.startsWith(pluginPkg + '/')) {
|
|
350
|
+
const metaIdent = /\bregisterElement\([^,]+,\s*[^,]+,\s*[^?]*\?\s*(\w+)/.exec(n.statement.getText(sf))?.[1];
|
|
351
|
+
const metaObj = metaIdent ? objectOf(ts.factory.createIdentifier(metaIdent)) : null;
|
|
352
|
+
scanPluginElementTable(pluginPkg, helperFrom.slice(pluginPkg.length + 1), modulesDir, metaObj, sf, found);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
ts.forEachChild(n, visit);
|
|
358
|
+
if (!ts.isCallExpression(n) || !ts.isIdentifier(n.expression) || n.expression.text !== 'registerElement')
|
|
359
|
+
return;
|
|
360
|
+
const [tag, resolver, meta] = n.arguments;
|
|
361
|
+
if (!tag || !resolver || !ts.isArrowFunction(resolver) || resolver.parameters.length || !ts.isIdentifier(resolver.body))
|
|
362
|
+
return;
|
|
363
|
+
if (ts.isStringLiteralLike(tag)) {
|
|
364
|
+
record(tag.text, resolver.body.text, meta, n);
|
|
365
|
+
}
|
|
366
|
+
else if (ts.isIdentifier(tag) && loopTags.has(tag.text)) {
|
|
367
|
+
for (const t of loopTags.get(tag.text))
|
|
368
|
+
record(t, resolver.body.text, meta, n);
|
|
369
|
+
}
|
|
157
370
|
};
|
|
158
371
|
visit(sf);
|
|
159
372
|
};
|
|
@@ -166,7 +379,7 @@ export function registeredElements(sources, modulesDir) {
|
|
|
166
379
|
const dir = join(modulesDir, m[1], 'angular');
|
|
167
380
|
const entry = existsSync(dir) ? readdirSync(dir).flatMap((d) => (/^fesm/.test(d) ? readdirSync(join(dir, d)).filter((x) => x.endsWith('.mjs')).map((x) => join(dir, d, x)) : [])).sort().reverse()[0] : undefined;
|
|
168
381
|
if (entry)
|
|
169
|
-
scan(readFileSync(entry, 'utf8'), null);
|
|
382
|
+
scan(readFileSync(entry, 'utf8'), null, m[1]);
|
|
170
383
|
}
|
|
171
384
|
}
|
|
172
385
|
return found;
|