@angular/compiler-cli 18.0.0-next.1 → 18.0.0-next.3

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 (73) hide show
  1. package/bundles/{chunk-WCD6LVCP.js → chunk-2WQIUGOU.js} +7 -7
  2. package/bundles/{chunk-C4L7A7U3.js → chunk-45SUUHP7.js} +74 -35
  3. package/bundles/chunk-45SUUHP7.js.map +6 -0
  4. package/bundles/{chunk-R4KQI5XI.js → chunk-64JBPJBS.js} +5 -5
  5. package/bundles/{chunk-ALDR4XSX.js → chunk-75Z2LUBT.js} +1189 -934
  6. package/bundles/chunk-75Z2LUBT.js.map +6 -0
  7. package/bundles/{chunk-B454JZVO.js → chunk-KVMNPNPQ.js} +5 -5
  8. package/bundles/{chunk-SBDNBITT.js → chunk-LYJKWJUC.js} +3 -3
  9. package/bundles/{chunk-AWB4ZG2D.js → chunk-QA6MINWF.js} +52 -50
  10. package/bundles/chunk-QA6MINWF.js.map +6 -0
  11. package/bundles/{chunk-GGJA4IFT.js → chunk-RUNTWSSX.js} +170 -91
  12. package/bundles/chunk-RUNTWSSX.js.map +6 -0
  13. package/bundles/{chunk-75YFKYUJ.js → chunk-UM6JO3VZ.js} +7 -7
  14. package/bundles/{chunk-OHOBDHII.js → chunk-UYDKSYFP.js} +180 -106
  15. package/bundles/chunk-UYDKSYFP.js.map +6 -0
  16. package/bundles/{chunk-YUMIYLNL.js → chunk-XIYC7KSQ.js} +5 -5
  17. package/bundles/index.js +14 -12
  18. package/bundles/index.js.map +1 -1
  19. package/bundles/linker/babel/index.js +20 -13
  20. package/bundles/linker/babel/index.js.map +1 -1
  21. package/bundles/linker/index.js +4 -4
  22. package/bundles/ngcc/index.js +1 -1
  23. package/bundles/private/bazel.js +1 -1
  24. package/bundles/private/localize.js +3 -3
  25. package/bundles/private/migrations.js +5 -5
  26. package/bundles/private/tooling.js +5 -5
  27. package/bundles/src/bin/ng_xi18n.js +10 -10
  28. package/bundles/src/bin/ngc.js +8 -8
  29. package/bundles_metadata.json +1 -1
  30. package/index.d.ts +1 -0
  31. package/linker/babel/src/ast/babel_ast_host.d.ts +2 -1
  32. package/linker/src/ast/ast_host.d.ts +4 -0
  33. package/linker/src/ast/ast_value.d.ts +5 -0
  34. package/linker/src/ast/typescript/typescript_ast_host.d.ts +1 -0
  35. package/linker/src/file_linker/partial_linkers/partial_class_metadata_async_linker_1.d.ts +16 -0
  36. package/linker/src/file_linker/partial_linkers/partial_linker_selector.d.ts +1 -0
  37. package/linker/src/file_linker/partial_linkers/util.d.ts +1 -1
  38. package/package.json +4 -4
  39. package/src/ngtsc/annotations/component/src/handler.d.ts +1 -1
  40. package/src/ngtsc/annotations/directive/index.d.ts +1 -0
  41. package/src/ngtsc/annotations/directive/src/initializer_function_access.d.ts +17 -0
  42. package/src/ngtsc/annotations/directive/src/initializer_functions.d.ts +10 -6
  43. package/src/ngtsc/annotations/directive/src/input_function.d.ts +4 -1
  44. package/src/ngtsc/annotations/directive/src/model_function.d.ts +4 -1
  45. package/src/ngtsc/annotations/directive/src/output_function.d.ts +4 -1
  46. package/src/ngtsc/annotations/directive/src/query_functions.d.ts +8 -2
  47. package/src/ngtsc/annotations/index.d.ts +1 -1
  48. package/src/ngtsc/diagnostics/src/error_code.d.ts +19 -0
  49. package/src/ngtsc/docs/src/entities.d.ts +36 -1
  50. package/src/ngtsc/docs/src/function_extractor.d.ts +3 -2
  51. package/src/ngtsc/docs/src/initializer_api_function_extractor.d.ts +24 -0
  52. package/src/ngtsc/docs/src/internal.d.ts +8 -0
  53. package/src/ngtsc/imports/src/imported_symbols_tracker.d.ts +13 -0
  54. package/src/ngtsc/reflection/src/host.d.ts +13 -3
  55. package/src/ngtsc/reflection/src/typescript.d.ts +8 -1
  56. package/src/ngtsc/reflection/src/util.d.ts +6 -1
  57. package/src/ngtsc/typecheck/src/oob.d.ts +3 -3
  58. package/src/ngtsc/validation/index.d.ts +8 -0
  59. package/src/ngtsc/validation/src/rules/api.d.ts +24 -0
  60. package/src/ngtsc/validation/src/rules/initializer_api_usage_rule.d.ts +21 -0
  61. package/src/ngtsc/validation/src/source_file_validator.d.ts +22 -0
  62. package/src/transformers/jit_transforms/initializer_api_transforms/transform_api.d.ts +3 -3
  63. package/bundles/chunk-ALDR4XSX.js.map +0 -6
  64. package/bundles/chunk-AWB4ZG2D.js.map +0 -6
  65. package/bundles/chunk-C4L7A7U3.js.map +0 -6
  66. package/bundles/chunk-GGJA4IFT.js.map +0 -6
  67. package/bundles/chunk-OHOBDHII.js.map +0 -6
  68. /package/bundles/{chunk-WCD6LVCP.js.map → chunk-2WQIUGOU.js.map} +0 -0
  69. /package/bundles/{chunk-R4KQI5XI.js.map → chunk-64JBPJBS.js.map} +0 -0
  70. /package/bundles/{chunk-B454JZVO.js.map → chunk-KVMNPNPQ.js.map} +0 -0
  71. /package/bundles/{chunk-SBDNBITT.js.map → chunk-LYJKWJUC.js.map} +0 -0
  72. /package/bundles/{chunk-75YFKYUJ.js.map → chunk-UM6JO3VZ.js.map} +0 -0
  73. /package/bundles/{chunk-YUMIYLNL.js.map → chunk-XIYC7KSQ.js.map} +0 -0
package/index.d.ts CHANGED
@@ -13,4 +13,5 @@ export { OptimizeFor } from './src/ngtsc/typecheck/api';
13
13
  export { ConsoleLogger, Logger, LogLevel } from './src/ngtsc/logging';
14
14
  export { NodeJSFileSystem, absoluteFrom } from './src/ngtsc/file_system';
15
15
  export * from './src/ngtsc/docs/src/entities';
16
+ export * from './src/ngtsc/docs';
16
17
  export { isLocalCompilationDiagnostics } from './src/ngtsc/diagnostics';
@@ -24,8 +24,9 @@ export declare class BabelAstHost implements AstHost<t.Expression> {
24
24
  parseArrayLiteral(array: t.Expression): t.Expression[];
25
25
  isObjectLiteral: typeof t.isObjectExpression;
26
26
  parseObjectLiteral(obj: t.Expression): Map<string, t.Expression>;
27
- isFunctionExpression(node: t.Expression): node is Extract<t.Function, t.Expression>;
27
+ isFunctionExpression(node: t.Expression): node is Extract<t.Function | t.ArrowFunctionExpression, t.Expression>;
28
28
  parseReturnValue(fn: t.Expression): t.Expression;
29
+ parseParameters(fn: t.Expression): t.Expression[];
29
30
  isCallExpression: typeof t.isCallExpression;
30
31
  parseCallee(call: t.Expression): t.Expression;
31
32
  parseArguments(call: t.Expression): t.Expression[];
@@ -76,6 +76,10 @@ export interface AstHost<TExpression> {
76
76
  * statement, extracting the returned expression, or throw if it is not possible.
77
77
  */
78
78
  parseReturnValue(fn: TExpression): TExpression;
79
+ /**
80
+ * Returns the parameter expressions for the function, or throw if it is not a function.
81
+ */
82
+ parseParameters(fn: TExpression): TExpression[];
79
83
  /**
80
84
  * Return true if the given expression is a call expression, or false otherwise.
81
85
  */
@@ -188,6 +188,11 @@ export declare class AstValue<T, TExpression> {
188
188
  * it is not a function expression.
189
189
  */
190
190
  getFunctionReturnValue<R>(this: ConformsTo<this, T, Function>): AstValue<R, TExpression>;
191
+ /**
192
+ * Extract the parameters from this value as a function expression, or error if it is not a
193
+ * function expression.
194
+ */
195
+ getFunctionParameters<R>(this: ConformsTo<this, T, Function>): AstValue<R, TExpression>[];
191
196
  isCallExpression(): boolean;
192
197
  getCallee(): AstValue<unknown, TExpression>;
193
198
  getArguments(): AstValue<unknown, TExpression>[];
@@ -31,6 +31,7 @@ export declare class TypeScriptAstHost implements AstHost<ts.Expression> {
31
31
  parseObjectLiteral(obj: ts.Expression): Map<string, ts.Expression>;
32
32
  isFunctionExpression(node: ts.Expression): node is ts.FunctionExpression | ts.ArrowFunction;
33
33
  parseReturnValue(fn: ts.Expression): ts.Expression;
34
+ parseParameters(fn: ts.Expression): ts.Expression[];
34
35
  isCallExpression: typeof ts.isCallExpression;
35
36
  parseCallee(call: ts.Expression): ts.Expression;
36
37
  parseArguments(call: ts.Expression): ts.Expression[];
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { ConstantPool, R3DeclareClassMetadataAsync } from '@angular/compiler';
9
+ import { AstObject } from '../../ast/ast_value';
10
+ import { LinkedDefinition, PartialLinker } from './partial_linker';
11
+ /**
12
+ * A `PartialLinker` that is designed to process `ɵɵngDeclareClassMetadataAsync()` call expressions.
13
+ */
14
+ export declare class PartialClassMetadataAsyncLinkerVersion1<TExpression> implements PartialLinker<TExpression> {
15
+ linkPartialDeclaration(constantPool: ConstantPool, metaObj: AstObject<R3DeclareClassMetadataAsync, TExpression>): LinkedDefinition;
16
+ }
@@ -18,6 +18,7 @@ export declare const ɵɵngDeclareInjectable = "\u0275\u0275ngDeclareInjectable"
18
18
  export declare const ɵɵngDeclareInjector = "\u0275\u0275ngDeclareInjector";
19
19
  export declare const ɵɵngDeclareNgModule = "\u0275\u0275ngDeclareNgModule";
20
20
  export declare const ɵɵngDeclarePipe = "\u0275\u0275ngDeclarePipe";
21
+ export declare const ɵɵngDeclareClassMetadataAsync = "\u0275\u0275ngDeclareClassMetadataAsync";
21
22
  export declare const declarationFunctions: string[];
22
23
  export interface LinkerRange<TExpression> {
23
24
  range: semver.Range;
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { MaybeForwardRefExpression, outputAst as o, R3DeclareDependencyMetadata, R3DependencyMetadata, R3Reference } from '@angular/compiler';
9
9
  import { AstObject, AstValue } from '../../ast/ast_value';
10
- export declare const PLACEHOLDER_VERSION = "18.0.0-next.1";
10
+ export declare const PLACEHOLDER_VERSION = "18.0.0-next.3";
11
11
  export declare function wrapReference<TExpression>(wrapped: o.WrappedNodeExpr<TExpression>): R3Reference;
12
12
  /**
13
13
  * Parses the value of an enum from the AST value's symbol name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular/compiler-cli",
3
- "version": "18.0.0-next.1",
3
+ "version": "18.0.0-next.3",
4
4
  "description": "Angular - the compiler CLI for Node.js",
5
5
  "typings": "index.d.ts",
6
6
  "bin": {
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@babel/core": "7.24.1",
46
+ "@babel/core": "7.24.3",
47
47
  "@jridgewell/sourcemap-codec": "^1.4.14",
48
48
  "reflect-metadata": "^0.2.0",
49
49
  "chokidar": "^3.0.0",
@@ -53,8 +53,8 @@
53
53
  "yargs": "^17.2.1"
54
54
  },
55
55
  "peerDependencies": {
56
- "@angular/compiler": "18.0.0-next.1",
57
- "typescript": ">=5.2 <5.5"
56
+ "@angular/compiler": "18.0.0-next.3",
57
+ "typescript": ">=5.4 <5.5"
58
58
  },
59
59
  "repository": {
60
60
  "type": "git",
@@ -102,7 +102,7 @@ export declare class ComponentDecoratorHandler implements DecoratorHandler<Decor
102
102
  * Computes a list of deferrable symbols based on dependencies from
103
103
  * the `@Component.imports` field and their usage in `@defer` blocks.
104
104
  */
105
- private collectDeferredSymbols;
105
+ private resolveAllDeferredDependencies;
106
106
  /**
107
107
  * Collects deferrable symbols from the `@Component.deferredImports` field.
108
108
  */
@@ -12,3 +12,4 @@ export * from './src/input_function';
12
12
  export * from './src/output_function';
13
13
  export * from './src/query_functions';
14
14
  export * from './src/model_function';
15
+ export * from './src/initializer_functions';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { ClassMember } from '../../../reflection';
9
+ import { InitializerFunctionMetadata } from './initializer_functions';
10
+ /**
11
+ * Validates that the initializer member is compatible with the given class
12
+ * member in terms of field access and visibility.
13
+ *
14
+ * @throws {FatalDiagnosticError} If the recognized initializer API is
15
+ * incompatible.
16
+ */
17
+ export declare function validateAccessOfInitializerApiMember({ api, call }: InitializerFunctionMetadata, member: Pick<ClassMember, 'accessLevel'>): void;
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import ts from 'typescript';
9
9
  import { ImportedSymbolsTracker } from '../../../imports';
10
- import { ClassMember, ReflectionHost } from '../../../reflection';
10
+ import { ClassMemberAccessLevel, ReflectionHost } from '../../../reflection';
11
11
  /**
12
12
  * @fileoverview
13
13
  *
@@ -20,14 +20,18 @@ import { ClassMember, ReflectionHost } from '../../../reflection';
20
20
  * declared through initializer APIs.
21
21
  */
22
22
  export interface InitializerApiFunction {
23
+ /** Module name where the initializer function is imported from. */
23
24
  owningModule: '@angular/core' | '@angular/core/rxjs-interop';
25
+ /** Export name of the initializer function. */
24
26
  functionName: ('input' | 'model' | 'output' | 'outputFromObservable' | 'viewChild' | 'viewChildren' | 'contentChild' | 'contentChildren');
27
+ /** Class member access levels compatible with the API. */
28
+ allowedAccessLevels: ClassMemberAccessLevel[];
25
29
  }
26
30
  /**
27
31
  * Metadata describing an Angular class member that was recognized through
28
32
  * a function initializer. Like `input`, `input.required` or `viewChild`.
29
33
  */
30
- interface InitializerFunctionMetadata {
34
+ export interface InitializerFunctionMetadata {
31
35
  /** Initializer API function that was recognized. */
32
36
  api: InitializerApiFunction;
33
37
  /** Node referring to the call expression. */
@@ -36,13 +40,13 @@ interface InitializerFunctionMetadata {
36
40
  isRequired: boolean;
37
41
  }
38
42
  /**
39
- * Attempts to identify an Angular class member that is declared via
40
- * its initializer referring to a given initializer API function.
43
+ * Attempts to identify an Angular initializer function call.
41
44
  *
42
45
  * Note that multiple possible initializer API function names can be specified,
43
46
  * allowing for checking multiple types in one pass.
47
+ *
48
+ * @returns The parsed initializer API, or null if none was found.
44
49
  */
45
- export declare function tryParseInitializerApiMember<Functions extends InitializerApiFunction[]>(functions: Functions, member: Pick<ClassMember, 'value'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): (InitializerFunctionMetadata & {
50
+ export declare function tryParseInitializerApi<Functions extends InitializerApiFunction[]>(functions: Functions, expression: ts.Expression, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): (InitializerFunctionMetadata & {
46
51
  api: Functions[number];
47
52
  } | null);
48
- export {};
@@ -8,8 +8,11 @@
8
8
  import { ImportedSymbolsTracker } from '../../../imports';
9
9
  import { InputMapping } from '../../../metadata';
10
10
  import { ClassMember, ReflectionHost } from '../../../reflection';
11
+ import { InitializerApiFunction } from './initializer_functions';
12
+ /** Represents a function that can declare an input. */
13
+ export declare const INPUT_INITIALIZER_FN: InitializerApiFunction;
11
14
  /**
12
15
  * Attempts to parse a signal input class member. Returns the parsed
13
16
  * input mapping if possible.
14
17
  */
15
- export declare function tryParseSignalInputMapping(member: Pick<ClassMember, 'name' | 'value'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): InputMapping | null;
18
+ export declare function tryParseSignalInputMapping(member: Pick<ClassMember, 'name' | 'value' | 'accessLevel'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): InputMapping | null;
@@ -8,7 +8,10 @@
8
8
  import { ImportedSymbolsTracker } from '../../../imports';
9
9
  import { ModelMapping } from '../../../metadata';
10
10
  import { ClassMember, ReflectionHost } from '../../../reflection';
11
+ import { InitializerApiFunction } from './initializer_functions';
12
+ /** Represents a function that can declare a model. */
13
+ export declare const MODEL_INITIALIZER_FN: InitializerApiFunction;
11
14
  /**
12
15
  * Attempts to parse a model class member. Returns the parsed model mapping if possible.
13
16
  */
14
- export declare function tryParseSignalModelMapping(member: Pick<ClassMember, 'name' | 'value'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): ModelMapping | null;
17
+ export declare function tryParseSignalModelMapping(member: Pick<ClassMember, 'name' | 'value' | 'accessLevel'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): ModelMapping | null;
@@ -9,11 +9,14 @@ import ts from 'typescript';
9
9
  import { ImportedSymbolsTracker } from '../../../imports';
10
10
  import { InputOrOutput } from '../../../metadata';
11
11
  import { ClassMember, ReflectionHost } from '../../../reflection';
12
+ import { InitializerApiFunction } from './initializer_functions';
13
+ /** Possible functions that can declare an output. */
14
+ export declare const OUTPUT_INITIALIZER_FNS: InitializerApiFunction[];
12
15
  /**
13
16
  * Attempts to parse a signal output class member. Returns the parsed
14
17
  * input mapping if possible.
15
18
  */
16
- export declare function tryParseInitializerBasedOutput(member: Pick<ClassMember, 'name' | 'value'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): {
19
+ export declare function tryParseInitializerBasedOutput(member: Pick<ClassMember, 'name' | 'value' | 'accessLevel'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): {
17
20
  call: ts.CallExpression;
18
21
  metadata: InputOrOutput;
19
22
  } | null;
@@ -8,9 +8,15 @@
8
8
  import { R3QueryMetadata } from '@angular/compiler';
9
9
  import ts from 'typescript';
10
10
  import { ImportedSymbolsTracker } from '../../../imports';
11
- import { ClassMember, ReflectionHost } from '../../../reflection';
11
+ import { ClassMember, ClassMemberAccessLevel, ReflectionHost } from '../../../reflection';
12
12
  /** Possible query initializer API functions. */
13
13
  export type QueryFunctionName = 'viewChild' | 'contentChild' | 'viewChildren' | 'contentChildren';
14
+ /** Possible query initializer API functions. */
15
+ export declare const QUERY_INITIALIZER_FNS: {
16
+ functionName: QueryFunctionName;
17
+ owningModule: "@angular/core";
18
+ allowedAccessLevels: ClassMemberAccessLevel[];
19
+ }[];
14
20
  /**
15
21
  * Attempts to detect a possible query definition for the given class member.
16
22
  *
@@ -19,7 +25,7 @@ export type QueryFunctionName = 'viewChild' | 'contentChild' | 'viewChildren' |
19
25
  *
20
26
  * @returns Resolved query metadata, or null if no query is declared.
21
27
  */
22
- export declare function tryParseSignalQueryFromInitializer(member: Pick<ClassMember, 'name' | 'value'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): {
28
+ export declare function tryParseSignalQueryFromInitializer(member: Pick<ClassMember, 'name' | 'value' | 'accessLevel'>, reflector: ReflectionHost, importTracker: ImportedSymbolsTracker): {
23
29
  name: QueryFunctionName;
24
30
  metadata: R3QueryMetadata;
25
31
  call: ts.CallExpression;
@@ -7,7 +7,7 @@
7
7
  */
8
8
  export { forwardRefResolver, getAngularDecorators, isAngularDecorator, NoopReferencesRegistry, ReferencesRegistry, ResourceLoader, ResourceLoaderContext } from './common';
9
9
  export { ComponentDecoratorHandler } from './component';
10
- export { DirectiveDecoratorHandler, queryDecoratorNames, QueryFunctionName, tryParseInitializerBasedOutput, tryParseSignalInputMapping, tryParseSignalModelMapping, tryParseSignalQueryFromInitializer } from './directive';
10
+ export { DirectiveDecoratorHandler, InitializerApiFunction, INPUT_INITIALIZER_FN, MODEL_INITIALIZER_FN, OUTPUT_INITIALIZER_FNS, QUERY_INITIALIZER_FNS, queryDecoratorNames, QueryFunctionName, tryParseInitializerApi, tryParseInitializerBasedOutput, tryParseSignalInputMapping, tryParseSignalModelMapping, tryParseSignalQueryFromInitializer } from './directive';
11
11
  export { NgModuleDecoratorHandler } from './ng_module';
12
12
  export { InjectableDecoratorHandler } from './src/injectable';
13
13
  export { PipeDecoratorHandler } from './src/pipe';
@@ -37,6 +37,11 @@ export declare enum ErrorCode {
37
37
  * function, but is still detected unexpectedly.
38
38
  */
39
39
  INITIALIZER_API_NO_REQUIRED_FUNCTION = 1052,
40
+ /**
41
+ * Raised whenever an initializer API is used on a class member
42
+ * and the given access modifiers (e.g. `private`) are not allowed.
43
+ */
44
+ INITIALIZER_API_DISALLOWED_MEMBER_VISIBILITY = 1053,
40
45
  /**
41
46
  * An Angular feature, like inputs, outputs or queries is incorrectly
42
47
  * declared on a static member.
@@ -387,6 +392,20 @@ export declare enum ErrorCode {
387
392
  * ```
388
393
  */
389
394
  INTERPOLATED_SIGNAL_NOT_INVOKED = 8109,
395
+ /**
396
+ * Initializer-based APIs can only be invoked from inside of an initializer.
397
+ *
398
+ * ```
399
+ * // Allowed
400
+ * myInput = input();
401
+ *
402
+ * // Not allowed
403
+ * function myInput() {
404
+ * return input();
405
+ * }
406
+ * ```
407
+ */
408
+ UNSUPPORTED_INITIALIZER_API_USAGE = 8110,
390
409
  /**
391
410
  * The template type-checking engine would need to generate an inline type check block for a
392
411
  * component, but the current type-checking environment doesn't support it.
@@ -19,7 +19,8 @@ export declare enum EntryType {
19
19
  NgModule = "ng_module",
20
20
  Pipe = "pipe",
21
21
  TypeAlias = "type_alias",
22
- UndecoratedClass = "undecorated_class"
22
+ UndecoratedClass = "undecorated_class",
23
+ InitializerApiFunction = "initializer_api_function"
23
24
  }
24
25
  /** Types of class members */
25
26
  export declare enum MemberType {
@@ -133,3 +134,37 @@ export interface ParameterEntry {
133
134
  isOptional: boolean;
134
135
  isRestParam: boolean;
135
136
  }
137
+ /** Interface describing a function with overload signatures. */
138
+ export interface FunctionWithOverloads {
139
+ name: string;
140
+ signatures: FunctionEntry[];
141
+ implementation: FunctionEntry | null;
142
+ }
143
+ /**
144
+ * Docs entry describing an initializer API function.
145
+ *
146
+ * An initializer API function is a function that is invoked as
147
+ * initializer of class members. The function may hold additional
148
+ * sub functions, like `.required`.
149
+ *
150
+ * Known popular initializer APIs are `input()`, `output()`, `model()`.
151
+ *
152
+ * Initializer APIs are often constructed typed in complex ways so this
153
+ * entry type allows for readable "parsing" and interpretation of such
154
+ * constructs. Initializer APIs are explicitly denoted via a JSDoc tag.
155
+ */
156
+ export interface InitializerApiFunctionEntry extends DocEntry {
157
+ callFunction: FunctionWithOverloads;
158
+ subFunctions: FunctionWithOverloads[];
159
+ __docsMetadata__?: {
160
+ /**
161
+ * Whether types should be shown in the signature
162
+ * preview of docs.
163
+ *
164
+ * By default, for readability purposes, types are omitted, but
165
+ * shorter initializer API functions like `output` may decide to
166
+ * render these types.
167
+ */
168
+ showTypesInSignaturePreview?: boolean;
169
+ };
170
+ }
@@ -6,7 +6,7 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import ts from 'typescript';
9
- import { FunctionEntry } from './entities';
9
+ import { FunctionEntry, ParameterEntry } from './entities';
10
10
  export type FunctionLike = ts.FunctionDeclaration | ts.MethodDeclaration | ts.MethodSignature | ts.CallSignatureDeclaration | ts.ConstructSignatureDeclaration;
11
11
  export declare class FunctionExtractor {
12
12
  private name;
@@ -14,8 +14,9 @@ export declare class FunctionExtractor {
14
14
  private typeChecker;
15
15
  constructor(name: string, declaration: FunctionLike, typeChecker: ts.TypeChecker);
16
16
  extract(): FunctionEntry;
17
- private extractAllParams;
18
17
  /** Gets all overloads for the function (excluding this extractor's FunctionDeclaration). */
19
18
  getOverloads(): ts.FunctionDeclaration[];
20
19
  private getSymbol;
21
20
  }
21
+ /** Extracts parameters of the given parameter declaration AST nodes. */
22
+ export declare function extractAllParams(params: ts.NodeArray<ts.ParameterDeclaration>, typeChecker: ts.TypeChecker): ParameterEntry[];
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import ts from 'typescript';
9
+ import { InitializerApiFunctionEntry } from './entities';
10
+ /**
11
+ * Checks whether the given node corresponds to an initializer API function.
12
+ *
13
+ * An initializer API function is a function declaration or variable declaration
14
+ * that is explicitly annotated with `@initializerApiFunction`.
15
+ *
16
+ * Note: The node may be a function overload signature that is automatically
17
+ * resolved to its implementation to detect the JSDoc tag.
18
+ */
19
+ export declare function isInitializerApiFunction(node: ts.Node, typeChecker: ts.TypeChecker): node is ts.VariableDeclaration | ts.FunctionDeclaration;
20
+ /**
21
+ * Extracts the given node as initializer API function and returns
22
+ * a docs entry that can be rendered to represent the API function.
23
+ */
24
+ export declare function extractInitializerApiFunction(node: ts.VariableDeclaration | ts.FunctionDeclaration, typeChecker: ts.TypeChecker): InitializerApiFunctionEntry;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export {};
@@ -32,6 +32,19 @@ export declare class ImportedSymbolsTracker {
32
32
  * @param moduleName Module from which the namespace is imported.
33
33
  */
34
34
  isPotentialReferenceToNamespaceImport(node: ts.Identifier, moduleName: string): boolean;
35
+ /**
36
+ * Checks if a file has a named imported of a certain symbol.
37
+ * @param sourceFile File to be checked.
38
+ * @param exportedName Name of the exported symbol that is being checked.
39
+ * @param moduleName Module that exports the symbol.
40
+ */
41
+ hasNamedImport(sourceFile: ts.SourceFile, exportedName: string, moduleName: string): boolean;
42
+ /**
43
+ * Checks if a file has namespace imports of a certain symbol.
44
+ * @param sourceFile File to be checked.
45
+ * @param moduleName Module whose namespace import is being searched for.
46
+ */
47
+ hasNamespaceImport(sourceFile: ts.SourceFile, moduleName: string): boolean;
35
48
  /** Scans a `SourceFile` for import statements and caches them for later use. */
36
49
  private scanImports;
37
50
  }
@@ -77,6 +77,14 @@ export declare enum ClassMemberKind {
77
77
  Property = 3,
78
78
  Method = 4
79
79
  }
80
+ /** Possible access levels of a class member. */
81
+ export declare enum ClassMemberAccessLevel {
82
+ PublicWritable = 0,
83
+ PublicReadonly = 1,
84
+ Protected = 2,
85
+ Private = 3,
86
+ EcmaScriptPrivate = 4
87
+ }
80
88
  /**
81
89
  * A member of a class, such as a property, method, or constructor.
82
90
  */
@@ -89,6 +97,8 @@ export interface ClassMember {
89
97
  * Indication of which type of member this is (property, method, etc).
90
98
  */
91
99
  kind: ClassMemberKind;
100
+ /** Access level describing the class member modifiers. */
101
+ accessLevel: ClassMemberAccessLevel;
92
102
  /**
93
103
  * TypeScript `ts.TypeNode` representing the type of the member, or `null` if not present or
94
104
  * applicable.
@@ -99,13 +109,13 @@ export interface ClassMember {
99
109
  */
100
110
  name: string;
101
111
  /**
102
- * TypeScript `ts.Identifier` or `ts.StringLiteral` representing the name of the member, or `null`
103
- * if no such node is present.
112
+ * TypeScript `ts.Identifier`, `ts.PrivateIdentifier`, or `ts.StringLiteral` representing the
113
+ * name of the member, or `null` if no such node is present.
104
114
  *
105
115
  * The `nameNode` is useful in writing references to this member that will be correctly source-
106
116
  * mapped back to the original file.
107
117
  */
108
- nameNode: ts.Identifier | ts.StringLiteral | null;
118
+ nameNode: ts.Identifier | ts.PrivateIdentifier | ts.StringLiteral | null;
109
119
  /**
110
120
  * TypeScript `ts.Expression` which represents the value of the member.
111
121
  *
@@ -52,7 +52,6 @@ export declare class TypeScriptReflectionHost implements ReflectionHost {
52
52
  */
53
53
  protected getDeclarationOfSymbol(symbol: ts.Symbol, originalId: ts.Identifier | null): Declaration | null;
54
54
  private _reflectDecorator;
55
- private _reflectMember;
56
55
  /**
57
56
  * Get the set of declarations declared in `file` which are exported.
58
57
  */
@@ -69,6 +68,14 @@ export declare function filterToMembersWithDecorator(members: ClassMember[], nam
69
68
  member: ClassMember;
70
69
  decorators: Decorator[];
71
70
  }[];
71
+ /**
72
+ * Reflects a class element and returns static information about the
73
+ * class member.
74
+ *
75
+ * Note: Decorator information is not included in this helper as it relies
76
+ * on type checking to resolve originating import.
77
+ */
78
+ export declare function reflectClassMember(node: ts.ClassElement): Omit<ClassMember, 'decorators'> | null;
72
79
  export declare function findMember(members: ClassMember[], name: string, isStatic?: boolean): ClassMember | null;
73
80
  export declare function reflectObjectLiteral(node: ts.ObjectLiteralExpression): Map<string, ts.Expression>;
74
81
  /**
@@ -6,7 +6,12 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import ts from 'typescript';
9
- import { ClassDeclaration } from './host';
9
+ import { ClassDeclaration, ClassMemberAccessLevel } from './host';
10
10
  export declare function isNamedClassDeclaration(node: ts.Node): node is ClassDeclaration<ts.ClassDeclaration>;
11
11
  export declare function isNamedFunctionDeclaration(node: ts.Node): node is ClassDeclaration<ts.FunctionDeclaration>;
12
12
  export declare function isNamedVariableDeclaration(node: ts.Node): node is ClassDeclaration<ts.VariableDeclaration>;
13
+ /**
14
+ * Converts the given class member access level to a string.
15
+ * Useful fo error messages.
16
+ */
17
+ export declare function classMemberAccessLevelToString(level: ClassMemberAccessLevel): string;
@@ -5,7 +5,7 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { BindingPipe, PropertyRead, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstForLoopBlock, TmplAstForLoopBlockEmpty, TmplAstHoverDeferredTrigger, TmplAstIfBlockBranch, TmplAstInteractionDeferredTrigger, TmplAstReference, TmplAstTemplate, TmplAstVariable, TmplAstViewportDeferredTrigger } from '@angular/compiler';
8
+ import { BindingPipe, PropertyRead, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstForLoopBlock, TmplAstForLoopBlockEmpty, TmplAstHoverDeferredTrigger, TmplAstIfBlockBranch, TmplAstInteractionDeferredTrigger, TmplAstReference, TmplAstSwitchBlockCase, TmplAstTemplate, TmplAstVariable, TmplAstViewportDeferredTrigger } from '@angular/compiler';
9
9
  import ts from 'typescript';
10
10
  import { ClassDeclaration } from '../../reflection';
11
11
  import { TemplateDiagnostic, TemplateId } from '../api';
@@ -90,7 +90,7 @@ export interface OutOfBandDiagnosticRecorder {
90
90
  /**
91
91
  * Reports cases where control flow nodes prevent content projection.
92
92
  */
93
- controlFlowPreventingContentProjection(templateId: TemplateId, category: ts.DiagnosticCategory, projectionNode: TmplAstElement | TmplAstTemplate, componentName: string, slotSelector: string, controlFlowNode: TmplAstIfBlockBranch | TmplAstForLoopBlock | TmplAstForLoopBlockEmpty, preservesWhitespaces: boolean): void;
93
+ controlFlowPreventingContentProjection(templateId: TemplateId, category: ts.DiagnosticCategory, projectionNode: TmplAstElement | TmplAstTemplate, componentName: string, slotSelector: string, controlFlowNode: TmplAstIfBlockBranch | TmplAstSwitchBlockCase | TmplAstForLoopBlock | TmplAstForLoopBlockEmpty, preservesWhitespaces: boolean): void;
94
94
  }
95
95
  export declare class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnosticRecorder {
96
96
  private resolver;
@@ -114,5 +114,5 @@ export declare class OutOfBandDiagnosticRecorderImpl implements OutOfBandDiagnos
114
114
  missingRequiredInputs(templateId: TemplateId, element: TmplAstElement | TmplAstTemplate, directiveName: string, isComponent: boolean, inputAliases: string[]): void;
115
115
  illegalForLoopTrackAccess(templateId: TemplateId, block: TmplAstForLoopBlock, access: PropertyRead): void;
116
116
  inaccessibleDeferredTriggerElement(templateId: TemplateId, trigger: TmplAstHoverDeferredTrigger | TmplAstInteractionDeferredTrigger | TmplAstViewportDeferredTrigger): void;
117
- controlFlowPreventingContentProjection(templateId: TemplateId, category: ts.DiagnosticCategory, projectionNode: TmplAstElement | TmplAstTemplate, componentName: string, slotSelector: string, controlFlowNode: TmplAstIfBlockBranch | TmplAstForLoopBlock | TmplAstForLoopBlockEmpty, preservesWhitespaces: boolean): void;
117
+ controlFlowPreventingContentProjection(templateId: TemplateId, category: ts.DiagnosticCategory, projectionNode: TmplAstElement | TmplAstTemplate, componentName: string, slotSelector: string, controlFlowNode: TmplAstIfBlockBranch | TmplAstSwitchBlockCase | TmplAstForLoopBlock | TmplAstForLoopBlockEmpty, preservesWhitespaces: boolean): void;
118
118
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ export { SourceFileValidator } from './src/source_file_validator';
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import ts from 'typescript';
9
+ /**
10
+ * Rule that checks a source file a specific issue.
11
+ */
12
+ export interface SourceFileValidatorRule {
13
+ /**
14
+ * Whether the file should be checked. Used to stop the traversal of the file early.
15
+ * @param sourceFile File to be checked.
16
+ */
17
+ shouldCheck(sourceFile: ts.SourceFile): boolean;
18
+ /**
19
+ * Produces diagnostics for a specific node that may
20
+ * contain the issue that the rule is enforcing.
21
+ * @param node Node to be checked.
22
+ */
23
+ checkNode(node: ts.Node): ts.Diagnostic | ts.Diagnostic[] | null;
24
+ }
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import ts from 'typescript';
9
+ import { ImportedSymbolsTracker } from '../../../imports';
10
+ import { ReflectionHost } from '../../../reflection';
11
+ import { SourceFileValidatorRule } from './api';
12
+ /**
13
+ * Rule that flags any initializer APIs that are used outside of an initializer.
14
+ */
15
+ export declare class InitializerApiUsageRule implements SourceFileValidatorRule {
16
+ private reflector;
17
+ private importedSymbolsTracker;
18
+ constructor(reflector: ReflectionHost, importedSymbolsTracker: ImportedSymbolsTracker);
19
+ shouldCheck(sourceFile: ts.SourceFile): boolean;
20
+ checkNode(node: ts.Node): ts.Diagnostic | null;
21
+ }
@@ -0,0 +1,22 @@
1
+ /*!
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import ts from 'typescript';
9
+ import { ImportedSymbolsTracker } from '../../imports';
10
+ import { ReflectionHost } from '../../reflection';
11
+ /**
12
+ * Validates that TypeScript files match a specific set of rules set by the Angular compiler.
13
+ */
14
+ export declare class SourceFileValidator {
15
+ private rules;
16
+ constructor(reflector: ReflectionHost, importedSymbolsTracker: ImportedSymbolsTracker);
17
+ /**
18
+ * Gets the diagnostics for a specific file, or null if the file is valid.
19
+ * @param sourceFile File to be checked.
20
+ */
21
+ getDiagnosticsForFile(sourceFile: ts.SourceFile): ts.Diagnostic[] | null;
22
+ }