@nstudio/nativescript-compiler-angular 0.0.0-stage → 9.2.0-alpha.10
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 +173 -0
- package/dist/angular.js +2938 -0
- package/dist/component-bases.js +746 -0
- package/dist/core-api.js +8 -0
- package/dist/entry.js +120 -0
- package/dist/index.js +165 -0
- package/dist/kotlin.js +293 -0
- package/dist/modules.js +700 -0
- package/dist/ng-modules.js +66 -0
- package/dist/package.js +15 -0
- package/dist/refusals.js +5 -0
- package/dist/semantics.js +262 -0
- package/dist/swift.js +352 -0
- package/kit-android/fromcore/AngularAPI.kt +175 -0
- package/kit-android/fromcore/AngularRouter.kt +617 -0
- package/kit-android/main/AngularChangeDetection.kt +530 -0
- package/kit-android/main/AngularCore.kt +685 -0
- package/kit-android/main/AngularHttp.kt +431 -0
- package/kit-android/main/AngularRouterValues.kt +154 -0
- package/kit-android/main/AngularRx.kt +224 -0
- package/kit-apple/AngularAPI.swift +224 -0
- package/kit-apple/AngularChangeDetection.swift +510 -0
- package/kit-apple/AngularCore.swift +764 -0
- package/kit-apple/AngularHttp.swift +467 -0
- package/kit-apple/AngularRouter.swift +655 -0
- package/kit-apple/AngularRouterValues.swift +285 -0
- package/kit-apple/AngularRx.swift +246 -0
- package/kit-apple/kit-index.json +763 -0
- package/package.json +56 -4
- package/runtime/angular-forms.ts +3099 -0
- package/runtime/angular-rx.ts +550 -0
- package/runtime/angular.ts +826 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// What the back ends read of an Angular app's NgModules and standalone components' imports. Kept apart from the front
|
|
2
|
+
// end so that a back end importing it does not load @angular/compiler.
|
|
3
|
+
import { ts } from "./core-api.js";
|
|
4
|
+
/** The class's decorator of that name, called (`@Component({...})`). */
|
|
5
|
+
export function decorator(node, name) {
|
|
6
|
+
for (const d of ts.getDecorators(node) ?? []) {
|
|
7
|
+
if (ts.isCallExpression(d.expression) && ts.isIdentifier(d.expression.expression) && d.expression.expression.text === name)
|
|
8
|
+
return d.expression;
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
/** A class of the program's sources that carries `@NgModule`. */
|
|
13
|
+
function isNgModuleSource(decl) {
|
|
14
|
+
return !!decl && ts.isClassDeclaration(decl) && !decl.getSourceFile().isDeclarationFile && !!decorator(decl, 'NgModule');
|
|
15
|
+
}
|
|
16
|
+
const metaField = (o, name) => (o && ts.isObjectLiteralExpression(o) ? o.properties.find((p) => ts.isPropertyAssignment(p) && p.name.getText() === name)?.initializer : undefined);
|
|
17
|
+
/**
|
|
18
|
+
* Of an `imports` list, in order, the NgModules the program compiles, the `ModuleWithProviders` calls of their statics
|
|
19
|
+
* (not in a component, where Angular drops their providers), and in place of a standalone component the modules its own
|
|
20
|
+
* `imports` list. The rest (the kit's own modules) has no constructor or providers of its own in a compiled build.
|
|
21
|
+
*/
|
|
22
|
+
function ngImports(list, checker, compiles, inComponent, seen) {
|
|
23
|
+
const declOf = (e) => {
|
|
24
|
+
const s = checker.getSymbolAtLocation(e);
|
|
25
|
+
return (s && s.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(s) : s)?.declarations?.[0];
|
|
26
|
+
};
|
|
27
|
+
const compiledNgModule = (decl) => isNgModuleSource(decl) && compiles(decl);
|
|
28
|
+
const kept = (list, inComponent) => {
|
|
29
|
+
if (!list || !ts.isArrayLiteralExpression(list))
|
|
30
|
+
return [];
|
|
31
|
+
return list.elements.flatMap((e) => {
|
|
32
|
+
if (ts.isArrayLiteralExpression(e))
|
|
33
|
+
return kept(e, inComponent);
|
|
34
|
+
const decl = declOf(e);
|
|
35
|
+
if (compiledNgModule(decl))
|
|
36
|
+
return [e];
|
|
37
|
+
if (decl && ts.isClassDeclaration(decl) && !decl.getSourceFile().isDeclarationFile && !seen.has(decl)) {
|
|
38
|
+
const component = decorator(decl, 'Component')?.arguments[0];
|
|
39
|
+
if (component) {
|
|
40
|
+
seen.add(decl);
|
|
41
|
+
return kept(metaField(component, 'imports'), true);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!inComponent && ts.isCallExpression(e) && ts.isPropertyAccessExpression(e.expression) && compiledNgModule(declOf(e.expression.expression)))
|
|
45
|
+
return [e];
|
|
46
|
+
return [];
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
return kept(list, inComponent);
|
|
50
|
+
}
|
|
51
|
+
/** An `@NgModule` class's metadata as Angular's injector walks it (`walkProviderTree`): its `imports` and `providers`. */
|
|
52
|
+
export function ngModuleDef(cls, checker, compiles) {
|
|
53
|
+
const meta = decorator(cls, 'NgModule')?.arguments[0];
|
|
54
|
+
if (!meta)
|
|
55
|
+
return undefined;
|
|
56
|
+
return { imports: ngImports(metaField(meta, 'imports'), checker, compiles, false, new Set()), providers: metaField(meta, 'providers') };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A standalone component's imports that make it its own environment injector when it is created as a root view
|
|
60
|
+
* (`StandaloneService`); undefined when none of them has a provider in a compiled build.
|
|
61
|
+
*/
|
|
62
|
+
export function standaloneImports(cls, checker, compiles) {
|
|
63
|
+
const meta = decorator(cls, 'Component')?.arguments[0];
|
|
64
|
+
const imports = meta && ngImports(metaField(meta, 'imports'), checker, compiles, true, new Set([cls]));
|
|
65
|
+
return imports?.length ? imports : undefined;
|
|
66
|
+
}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
/** The adapter's package folder, the nearest holding a package.json: run as TypeScript or from its built dist/ alike. */
|
|
5
|
+
const ROOT = (() => {
|
|
6
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
while (!existsSync(join(dir, 'package.json')))
|
|
8
|
+
dir = dirname(dir);
|
|
9
|
+
return dir;
|
|
10
|
+
})();
|
|
11
|
+
const { name, version } = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
12
|
+
/** The package the adapter ships as. Its runtime is TypeScript, read from the package's own runtime/. */
|
|
13
|
+
export const PACKAGE = { name, version, root: ROOT };
|
|
14
|
+
/** The adapter's TypeScript compiled with an app: @angular/common's pipes and directives, @angular/forms, the Rx-based APIs. */
|
|
15
|
+
export const RUNTIME = join(ROOT, 'runtime');
|
package/dist/refusals.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const ISOLATE = 'move the code into a plain function of its own with typed parameters and result, so the rest of the module translates; the refusal then names only that function';
|
|
2
|
+
export const refusals = {
|
|
3
|
+
'library-injectable': { class: 'gap', title: "an injected class only a library's typings declare", suggestion: ISOLATE },
|
|
4
|
+
'view-container-ref': { class: 'gap', title: 'an injected ViewContainerRef', suggestion: ISOLATE },
|
|
5
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { core, ts } from "./core-api.js";
|
|
2
|
+
export const isStatic = (m) => ts.canHaveModifiers(m) && !!ts.getModifiers(m)?.some((x) => x.kind === ts.SyntaxKind.StaticKeyword);
|
|
3
|
+
export const hasModifier = (n, kind) => ts.canHaveModifiers(n) && !!ts.getModifiers(n)?.some((m) => m.kind === kind);
|
|
4
|
+
/** Tokens the kit provides an instance of (`inject(Router)`); any other is the app's service or the injector's. */
|
|
5
|
+
export const KIT_TOKENS = ['RouterExtensions', 'ActivatedRoute', 'Page', 'DestroyRef', 'ChangeDetectorRef', 'ElementRef', 'NativeDialogRef', 'NativeDialogService', 'Router', 'HttpClient', 'Injector', 'EnvironmentInjector', 'NgZone', 'ErrorHandler', 'Location', 'ViewContainerRef', 'ApplicationRef'];
|
|
6
|
+
/** The code giving a kit token's instance where it is not the token class's own `shared`, per back end. */
|
|
7
|
+
export const INJECTION_TOKENS = {
|
|
8
|
+
RouterExtensions: { swift: 'Router.shared', kotlin: 'Router.shared' },
|
|
9
|
+
EnvironmentInjector: { swift: 'Injector.shared', kotlin: 'Injector.shared' },
|
|
10
|
+
ErrorHandler: { swift: 'Injector.errorHandler', kotlin: 'Injector.errorHandler' },
|
|
11
|
+
ActivatedRoute: { swift: 'ActivatedRoute.current', kotlin: 'ActivatedRoute.current' },
|
|
12
|
+
Page: { swift: 'Page.injected()', kotlin: 'injectedPage()' },
|
|
13
|
+
DestroyRef: { swift: 'DestroyRef.current()', kotlin: 'DestroyRef.current()' },
|
|
14
|
+
ChangeDetectorRef: { swift: 'ChangeDetectorRef.current()', kotlin: 'ChangeDetectorRef.current()' },
|
|
15
|
+
ElementRef: { swift: 'ElementRef.current()', kotlin: 'ElementRef.current()' },
|
|
16
|
+
NativeDialogRef: { swift: 'NativeDialogRef.current', kotlin: 'NativeDialogRef.current' },
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* What `inject(token)` at `at` gives: the kit's instance for a framework token, else the app's service.
|
|
20
|
+
* `ChangeDetectorRef.current()` binds dynamically via `AngularView.construct` frames during component construction.
|
|
21
|
+
*/
|
|
22
|
+
export function injected(backend, token, _at, shared = 'shared') {
|
|
23
|
+
return Object.hasOwn(INJECTION_TOKENS, token) ? INJECTION_TOKENS[token][backend] : `${token}.${shared}`;
|
|
24
|
+
}
|
|
25
|
+
const CORE_MODULE = /[\\/]@angular[\\/]core[\\/]|^\/__shims__\/_angular_core\.d\.ts$/;
|
|
26
|
+
/** Whether `e` calls @angular/core's `name` (`computed`), by the callee's declaration (the package's, or the compiler's shim of it): a program's own function of that name is an ordinary call. */
|
|
27
|
+
export function angularCall(e, name, checker) {
|
|
28
|
+
if (!e || !ts.isCallExpression(e))
|
|
29
|
+
return false;
|
|
30
|
+
const at = ts.isPropertyAccessExpression(e.expression) ? e.expression.name : e.expression;
|
|
31
|
+
let sym = checker.getSymbolAtLocation(at);
|
|
32
|
+
if (sym && sym.flags & ts.SymbolFlags.Alias)
|
|
33
|
+
sym = checker.getAliasedSymbol(sym);
|
|
34
|
+
return sym?.name === name && !!sym.declarations?.some((d) => CORE_MODULE.test(d.getSourceFile().fileName));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* How a backend makes an `@Injectable` class. An app's is a service the injector makes, `'based'` when it extends a
|
|
38
|
+
* class (then translated as any class is). A package's is a plain class, as the providers of its tokens are not compiled,
|
|
39
|
+
* unless it names its own injector (`providedIn`): then `'root'`, a plain class the injector also makes, one per class.
|
|
40
|
+
*/
|
|
41
|
+
export function injectableRole(cls, pluginFiles) {
|
|
42
|
+
const decorator = (ts.getDecorators(cls) ?? []).find((d) => d.expression.getText().startsWith('Injectable'));
|
|
43
|
+
if (!decorator)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (pluginFiles.has(cls.getSourceFile().fileName)) {
|
|
46
|
+
const options = ts.isCallExpression(decorator.expression) ? decorator.expression.arguments[0] : undefined;
|
|
47
|
+
const providedIn = options && ts.isObjectLiteralExpression(options)
|
|
48
|
+
? options.properties.find((p) => ts.isPropertyAssignment(p) && p.name.getText() === 'providedIn')?.initializer
|
|
49
|
+
: undefined;
|
|
50
|
+
return providedIn && ts.isStringLiteral(providedIn) && ['root', 'platform', 'any'].includes(providedIn.text) ? 'root' : undefined;
|
|
51
|
+
}
|
|
52
|
+
return cls.heritageClauses?.some((h) => h.token === ts.SyntaxKind.ExtendsKeyword) ? 'based' : 'service';
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The static a backend reads an `@Injectable` class's root instance from. A package's class, and its subclasses, keep
|
|
56
|
+
* `shared` as a name of their own (a static `shared` of the package's is its member): theirs is the kit's `jsShared`.
|
|
57
|
+
*/
|
|
58
|
+
export function injectableShared(cls, pluginFiles, checker) {
|
|
59
|
+
for (let c = cls; c && ts.isClassDeclaration(c) && !c.getSourceFile().isDeclarationFile;) {
|
|
60
|
+
if (injectableRole(c, pluginFiles) === 'root')
|
|
61
|
+
return 'jsShared';
|
|
62
|
+
const h = c.heritageClauses?.find((x) => x.token === ts.SyntaxKind.ExtendsKeyword)?.types[0];
|
|
63
|
+
c = h && checker.getTypeAtLocation(h.expression).getSymbol()?.valueDeclaration;
|
|
64
|
+
}
|
|
65
|
+
return 'shared';
|
|
66
|
+
}
|
|
67
|
+
/** Whether a declaration is a class the injector makes: the app's `@Injectable`, a package's that names its injector, the runtime's services. */
|
|
68
|
+
export function isInjectableClass(decl, pluginFiles) {
|
|
69
|
+
if (!decl || !ts.isClassDeclaration(decl) || decl.getSourceFile().isDeclarationFile)
|
|
70
|
+
return false;
|
|
71
|
+
const fn = decl.getSourceFile().fileName;
|
|
72
|
+
if (core.adapterRuntimeFile(fn) === 'runtime/angular-rx.ts' || core.adapterRuntimeFile(fn) === 'runtime/angular.ts')
|
|
73
|
+
return true;
|
|
74
|
+
// @angular/forms' builders: services whose root instance is their static `shared`.
|
|
75
|
+
if (core.adapterRuntimeFile(fn) === 'runtime/angular-forms.ts')
|
|
76
|
+
return decl.members.some((m) => (ts.isPropertyDeclaration(m) || ts.isGetAccessorDeclaration(m)) && isStatic(m) && m.name.getText() === 'shared');
|
|
77
|
+
if (pluginFiles.has(fn))
|
|
78
|
+
return injectableRole(decl, pluginFiles) === 'root';
|
|
79
|
+
return (ts.getDecorators(decl) ?? []).some((d) => /^Injectable\b/.test(d.expression.getText()));
|
|
80
|
+
}
|
|
81
|
+
/** A constructor parameter's injection as its decorators say: the `@Inject(token)` token, whether it may be absent, whether it skips its own injector. */
|
|
82
|
+
export function parameterDecorators(p) {
|
|
83
|
+
let token;
|
|
84
|
+
let optional = !!(p.questionToken || p.initializer);
|
|
85
|
+
let skipSelf = false;
|
|
86
|
+
for (const d of ts.getDecorators(p) ?? []) {
|
|
87
|
+
const e = d.expression;
|
|
88
|
+
const which = ts.isCallExpression(e) ? e.expression.getText() : e.getText();
|
|
89
|
+
if (which === 'Inject' && ts.isCallExpression(e) && e.arguments[0])
|
|
90
|
+
token = e.arguments[0];
|
|
91
|
+
else if (which === 'Optional')
|
|
92
|
+
optional = true;
|
|
93
|
+
else if (which === 'SkipSelf')
|
|
94
|
+
skipSelf = true;
|
|
95
|
+
}
|
|
96
|
+
return { token, optional, skipSelf };
|
|
97
|
+
}
|
|
98
|
+
/** `forwardRef(() => X)` is `X`. */
|
|
99
|
+
export function forwardRefTarget(e) {
|
|
100
|
+
return ts.isCallExpression(e) && e.expression.getText() === 'forwardRef' && e.arguments[0] && (ts.isArrowFunction(e.arguments[0]) || ts.isFunctionExpression(e.arguments[0])) && !ts.isBlock(e.arguments[0].body) ? e.arguments[0].body : e;
|
|
101
|
+
}
|
|
102
|
+
/** The services `injectThrows` is working out, so that services injecting each other end. */
|
|
103
|
+
const injecting = new Set();
|
|
104
|
+
/**
|
|
105
|
+
* Angular's `inject(token)` makes a root service the first time, throwing what its constructor throws; core's Page
|
|
106
|
+
* is the kit's `Page.injected()`, which can make one.
|
|
107
|
+
*/
|
|
108
|
+
function injectThrows(token, t) {
|
|
109
|
+
if (ts.isCallExpression(token))
|
|
110
|
+
token = forwardRefTarget(token);
|
|
111
|
+
let s = t.checker.getSymbolAtLocation(token);
|
|
112
|
+
if (s && s.flags & ts.SymbolFlags.Alias)
|
|
113
|
+
s = t.checker.getAliasedSymbol(s);
|
|
114
|
+
const decl = s?.valueDeclaration;
|
|
115
|
+
if (!decl || !ts.isClassLike(decl))
|
|
116
|
+
return false;
|
|
117
|
+
if (/[\\/]@nativescript[\\/]core[\\/]/.test(decl.getSourceFile().fileName))
|
|
118
|
+
return decl.name?.text === 'Page';
|
|
119
|
+
if (core.adapterRuntimeFile(decl.getSourceFile().fileName) === 'runtime/angular-rx.ts')
|
|
120
|
+
return decl.name?.text === 'ActivatedRoute';
|
|
121
|
+
if (decl.getSourceFile().isDeclarationFile || /[\\/]node_modules[\\/]/.test(decl.getSourceFile().fileName) || injecting.has(decl))
|
|
122
|
+
return false;
|
|
123
|
+
if (ts.isClassDeclaration(decl) && core.adapterRuntimeFile(decl.getSourceFile().fileName) !== 'runtime/angular.ts' && !ts.getDecorators(decl)?.some((d) => /^Injectable\b/.test(d.expression.getText())))
|
|
124
|
+
return false;
|
|
125
|
+
injecting.add(decl);
|
|
126
|
+
try {
|
|
127
|
+
return t.initThrows(decl);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
injecting.delete(decl);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const throwsModel = {
|
|
134
|
+
rethrowing: ['untracked', 'runInInjectionContext', 'PurePipeCache.*', 'NgZone.run', 'NgZone.runOutsideAngular', 'NgZone.runGuarded', 'NgZone.runTask'],
|
|
135
|
+
injectsConstructor: (cls) => ts.isClassDeclaration(cls) && !!ts.getDecorators(cls)?.some((d) => /^Injectable\b/.test(d.expression.getText())),
|
|
136
|
+
injects(p, t) {
|
|
137
|
+
const { token, optional, skipSelf } = parameterDecorators(p);
|
|
138
|
+
if (optional && skipSelf)
|
|
139
|
+
return false;
|
|
140
|
+
if (token)
|
|
141
|
+
return injectThrows(token, t);
|
|
142
|
+
const ref = p.type && ts.isTypeReferenceNode(p.type)
|
|
143
|
+
? p.type
|
|
144
|
+
: p.type && ts.isUnionTypeNode(p.type)
|
|
145
|
+
? p.type.types.find(ts.isTypeReferenceNode)
|
|
146
|
+
: undefined;
|
|
147
|
+
return ref ? injectThrows(ref.typeName, t) : false;
|
|
148
|
+
},
|
|
149
|
+
injectCall(decl, args, t) {
|
|
150
|
+
if (!args[0] || !((ts.isFunctionDeclaration(decl) && decl.name?.text === 'inject') || (ts.isMethodDeclaration(decl) && decl.name.getText() === 'get' && ts.isClassDeclaration(decl.parent) && decl.parent.name?.text === 'Injector')))
|
|
151
|
+
return undefined;
|
|
152
|
+
return injectThrows(args[0], t);
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
/** Angular's class decorators, as @angular/core (or the compiler's shim of it) declares them. */
|
|
156
|
+
const CLASS_DECORATORS = new Set(['Component', 'Directive', 'Pipe', 'Injectable', 'NgModule']);
|
|
157
|
+
const METHOD_DECORATORS = new Set(['HostListener']);
|
|
158
|
+
const LIFECYCLE_HOOKS = new Set(['ngOnChanges', 'ngOnInit', 'ngDoCheck', 'ngAfterContentInit', 'ngAfterContentChecked', 'ngAfterViewInit', 'ngAfterViewChecked', 'ngOnDestroy']);
|
|
159
|
+
function angularDecorator(d, names, checker) {
|
|
160
|
+
const e = ts.isCallExpression(d.expression) ? d.expression.expression : d.expression;
|
|
161
|
+
let sym = checker.getSymbolAtLocation(e);
|
|
162
|
+
if (sym && sym.flags & ts.SymbolFlags.Alias)
|
|
163
|
+
sym = checker.getAliasedSymbol(sym);
|
|
164
|
+
return !!sym && names.has(sym.name) && !!sym.declarations?.some((x) => /^\/__shims__\/_angular_core\.d\.ts$|[\\/]@angular[\\/]core[\\/]/.test(x.getSourceFile().fileName));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The `equal` options of a signal `signal(v, options)` or `linkedSignal(…)` makes: the call's second argument, or
|
|
168
|
+
* `linkedSignal`'s first where it is given `{ source, computation }`.
|
|
169
|
+
*/
|
|
170
|
+
function signalOptions(call, checker) {
|
|
171
|
+
if (angularCall(call, 'signal', checker))
|
|
172
|
+
return { options: call.arguments[1] };
|
|
173
|
+
if (angularCall(call, 'linkedSignal', checker)) {
|
|
174
|
+
const first = call.arguments[0];
|
|
175
|
+
return { options: first && checker.getTypeAtLocation(first).getCallSignatures().length === 0 ? first : call.arguments[1] };
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
/** What reading a required input, or reading or updating a required model, throws before its parent's binding first sets it. */
|
|
180
|
+
const NG0950 = 'NG0950: Input is required but no value is available yet. Find more at https://v22.angular.dev/errors/NG0950';
|
|
181
|
+
const NG0952 = 'NG0952: Model is required but no value is available yet.';
|
|
182
|
+
/** What both back ends and their analyses read of Angular's API. */
|
|
183
|
+
export const model = {
|
|
184
|
+
plainFields: true,
|
|
185
|
+
wrapsRootViews: true,
|
|
186
|
+
signalTypes: { InputSignal: 'input', ModelSignal: 'model', Signal: 'computed' },
|
|
187
|
+
// `input()` outside a component (a directive's): a signal the template sets.
|
|
188
|
+
signalConstructors: { signal: { equality: 'identity', options: 1 }, model: 'identity', input: { equality: 'identity', typed: true }, linkedSignal: { equality: 'identity', linked: true } },
|
|
189
|
+
memos: { computed: '@angular/core' },
|
|
190
|
+
heldSignals: ['toSignal'],
|
|
191
|
+
pure: ['signal', 'computed'],
|
|
192
|
+
classDecorators: ['NgModule', 'Injectable'],
|
|
193
|
+
componentDecorator: 'Component',
|
|
194
|
+
componentValueType: 'ComponentFactory',
|
|
195
|
+
prefixedModules: { rxjs: 'Rx' },
|
|
196
|
+
untypedInterfaces: ['@angular#forms'],
|
|
197
|
+
untypedPackageInterfaces: ['@angular/'],
|
|
198
|
+
throwsModel,
|
|
199
|
+
unsetError(field) {
|
|
200
|
+
const init = field.initializer;
|
|
201
|
+
if (!init || !ts.isCallExpression(init) || !/^(input|model)\.required$/.test(init.expression.getText()))
|
|
202
|
+
return undefined;
|
|
203
|
+
if (!ts.isClassDeclaration(field.parent) || !ts.getDecorators(field.parent)?.some((d) => /^Component\b/.test(d.expression.getText())))
|
|
204
|
+
return undefined;
|
|
205
|
+
return init.expression.getText() === 'model.required' ? NG0952 : NG0950;
|
|
206
|
+
},
|
|
207
|
+
signalOptions,
|
|
208
|
+
classRole: injectableRole,
|
|
209
|
+
addedStatics: (cls, pluginFiles, checker) => (injectableRole(cls, pluginFiles) ? [injectableShared(cls, pluginFiles, checker), 'jsSharedInstance', 'jsConstruct'] : []),
|
|
210
|
+
frameworkCalled(cls, name, checker) {
|
|
211
|
+
if (!ts.getDecorators(cls).every((d) => angularDecorator(d, CLASS_DECORATORS, checker)))
|
|
212
|
+
return 'a method of a decorated class';
|
|
213
|
+
if (LIFECYCLE_HOOKS.has(name))
|
|
214
|
+
return 'an Angular lifecycle hook';
|
|
215
|
+
// The template glue this compiler writes calls its own methods (`$b3`, `$e4`) with whatever they declare.
|
|
216
|
+
if (name.startsWith('$') && !/^\$[be]\d+$/.test(name))
|
|
217
|
+
return "a template's binding";
|
|
218
|
+
return undefined;
|
|
219
|
+
},
|
|
220
|
+
calledByFramework(cls, m, checker) {
|
|
221
|
+
if (ts.getDecorators(m)?.some((d) => angularDecorator(d, METHOD_DECORATORS, checker)))
|
|
222
|
+
return true;
|
|
223
|
+
if (!ts.getDecorators(cls)?.some((d) => angularDecorator(d, CLASS_DECORATORS, checker)))
|
|
224
|
+
return false;
|
|
225
|
+
return LIFECYCLE_HOOKS.has(m.name.getText()) || !(ts.isPrivateIdentifier(m.name) || ts.getCombinedModifierFlags(m) & ts.ModifierFlags.Private);
|
|
226
|
+
},
|
|
227
|
+
unsetMembers: isLinkedSignalPreviousSource,
|
|
228
|
+
};
|
|
229
|
+
/** Whether `d` is `previous.source` of Angular's `linkedSignal({ source, computation })` (shim, package typings, or inline callback annotation). */
|
|
230
|
+
export function isLinkedSignalPreviousSource(d, checker) {
|
|
231
|
+
if (!ts.isPropertySignature(d) || !ts.isIdentifier(d.name) || d.name.text !== 'source' || !ts.isTypeLiteralNode(d.parent))
|
|
232
|
+
return false;
|
|
233
|
+
let t = d.parent;
|
|
234
|
+
while (t.parent && (ts.isParenthesizedTypeNode(t.parent) || ts.isUnionTypeNode(t.parent)))
|
|
235
|
+
t = t.parent;
|
|
236
|
+
const param = t.parent;
|
|
237
|
+
if (!param || !ts.isParameter(param) || !ts.isFunctionLike(param.parent))
|
|
238
|
+
return false;
|
|
239
|
+
const fn = param.parent;
|
|
240
|
+
if (fn.parameters[1] !== param)
|
|
241
|
+
return false;
|
|
242
|
+
if (CORE_MODULE.test(d.getSourceFile().fileName)) {
|
|
243
|
+
const compProp = fn.parent;
|
|
244
|
+
if (!compProp || !ts.isPropertySignature(compProp) || !ts.isIdentifier(compProp.name) || compProp.name.text !== 'computation')
|
|
245
|
+
return false;
|
|
246
|
+
if (ts.isInterfaceDeclaration(compProp.parent) && /LinkedSignalOptions$/.test(compProp.parent.name.text))
|
|
247
|
+
return true;
|
|
248
|
+
const optsParam = ts.isTypeLiteralNode(compProp.parent) ? compProp.parent.parent : undefined;
|
|
249
|
+
const linkedFn = optsParam && ts.isParameter(optsParam) ? optsParam.parent : undefined;
|
|
250
|
+
return !!linkedFn && ts.isFunctionDeclaration(linkedFn) && linkedFn.name?.text === 'linkedSignal';
|
|
251
|
+
}
|
|
252
|
+
let fnExpr = fn;
|
|
253
|
+
while (fnExpr.parent && (ts.isParenthesizedExpression(fnExpr.parent) || ts.isParenthesizedTypeNode(fnExpr.parent) || ts.isAsExpression(fnExpr.parent) || ts.isTypeAssertionExpression(fnExpr.parent) || ts.isSatisfiesExpression(fnExpr.parent) || ts.isConditionalExpression(fnExpr.parent)))
|
|
254
|
+
fnExpr = fnExpr.parent;
|
|
255
|
+
const prop = fnExpr.parent;
|
|
256
|
+
if (!prop || !ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name) || prop.name.text !== 'computation' || !ts.isObjectLiteralExpression(prop.parent))
|
|
257
|
+
return false;
|
|
258
|
+
let opts = prop.parent;
|
|
259
|
+
while (opts.parent && ts.isParenthesizedExpression(opts.parent))
|
|
260
|
+
opts = opts.parent;
|
|
261
|
+
return angularCall(opts.parent, 'linkedSignal', checker) && opts.parent.arguments[0] === opts;
|
|
262
|
+
}
|