static-injector 3.0.0 → 4.0.0

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 (76) hide show
  1. package/import/commonjs/index.js +65 -43
  2. package/import/es2022/di/index.js +1 -0
  3. package/import/es2022/di/initializer_token.js +1 -1
  4. package/import/es2022/di/inject_switch.js +1 -2
  5. package/import/es2022/di/injection_token.js +2 -0
  6. package/import/es2022/di/injector.js +3 -3
  7. package/import/es2022/di/injector_compatibility.js +23 -0
  8. package/import/es2022/di/injector_token.js +2 -3
  9. package/import/es2022/di/internal_tokens.js +1 -1
  10. package/import/es2022/di/r3_injector.js +15 -14
  11. package/import/es2022/di/scope.js +1 -1
  12. package/import/es2022/di.js +24 -0
  13. package/import/es2022/render3/errors_di.js +2 -2
  14. package/import/es2022/render3/instructions/di.js +7 -0
  15. package/import/es2022/util/array_utils.js +7 -0
  16. package/import/es2022/util/stringify.js +1 -1
  17. package/import/fesm2022/index.js +59 -37
  18. package/import/typings/di/create_injector.d.ts +2 -2
  19. package/import/typings/di/forward_ref.d.ts +1 -1
  20. package/import/typings/di/index.d.ts +1 -0
  21. package/import/typings/di/injector.d.ts +3 -3
  22. package/import/typings/di/injector_compatibility.d.ts +2 -1
  23. package/import/typings/di/injector_token.d.ts +1 -1
  24. package/import/typings/di/interface/provider.d.ts +12 -12
  25. package/import/typings/di/metadata.d.ts +2 -2
  26. package/import/typings/di/null_injector.d.ts +1 -1
  27. package/import/typings/di/r3_injector.d.ts +1 -1
  28. package/import/typings/di.d.ts +24 -0
  29. package/import/typings/errors.d.ts +4 -1
  30. package/import/typings/render3/errors_di.d.ts +2 -1
  31. package/import/typings/render3/instructions/di.d.ts +7 -0
  32. package/import/typings/util/array_utils.d.ts +7 -0
  33. package/import/typings/util/empty.d.ts +1 -1
  34. package/import/typings/util/stringify.d.ts +1 -1
  35. package/package.json +7 -6
  36. package/transform/compiler/src/compiler.d.ts +0 -22
  37. package/transform/compiler/src/compiler.js +0 -26
  38. package/transform/compiler/src/core.d.ts +6 -0
  39. package/transform/compiler/src/core.js +13 -0
  40. package/transform/compiler/src/output/output_ast.d.ts +8 -6
  41. package/transform/compiler/src/output/output_ast.js +10 -6
  42. package/transform/compiler/src/render3/partial/api.d.ts +5 -0
  43. package/transform/compiler/src/render3/r3_identifiers.js +4 -0
  44. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +0 -7
  45. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +0 -7
  46. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +2 -3
  47. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +4 -31
  48. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +3 -0
  49. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +14 -2
  50. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +5 -5
  51. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +0 -7
  52. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +0 -7
  53. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +0 -7
  54. package/transform/compiler-cli/src/ngtsc/imports/index.js +0 -7
  55. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +0 -7
  56. package/transform/compiler-cli/src/ngtsc/reflection/index.js +0 -7
  57. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +7 -2
  58. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +3 -1
  59. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -1
  60. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +16 -5
  61. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +4 -3
  62. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +25 -9
  63. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +0 -7
  64. package/transform/compiler-cli/src/ngtsc/transform/index.js +0 -7
  65. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +1 -1
  66. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +35 -24
  67. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +0 -7
  68. package/transform/compiler-cli/src/ngtsc/translator/index.js +0 -7
  69. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +1 -1
  70. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +21 -3
  71. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +13 -3
  72. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +1 -0
  73. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.d.ts +12 -0
  74. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.js +27 -0
  75. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +3 -1
  76. package/transform/injectable-transform.js +1 -1
@@ -83,12 +83,13 @@ export declare enum BinaryOperator {
83
83
  Modulo = 8,
84
84
  And = 9,
85
85
  Or = 10,
86
- BitwiseAnd = 11,
87
- Lower = 12,
88
- LowerEquals = 13,
89
- Bigger = 14,
90
- BiggerEquals = 15,
91
- NullishCoalesce = 16
86
+ BitwiseOr = 11,
87
+ BitwiseAnd = 12,
88
+ Lower = 13,
89
+ LowerEquals = 14,
90
+ Bigger = 15,
91
+ BiggerEquals = 16,
92
+ NullishCoalesce = 17
92
93
  }
93
94
  export declare function nullSafeIsEquivalent<T extends {
94
95
  isEquivalent(other: T): boolean;
@@ -114,6 +115,7 @@ export declare abstract class Expression {
114
115
  prop(name: string, sourceSpan?: ParseSourceSpan | null): ReadPropExpr;
115
116
  key(index: Expression, type?: Type | null, sourceSpan?: ParseSourceSpan | null): ReadKeyExpr;
116
117
  callFn(params: Expression[], sourceSpan?: ParseSourceSpan | null, pure?: boolean): InvokeFunctionExpr;
118
+ bitwiseOr(rhs: Expression, sourceSpan?: ParseSourceSpan | null, parens?: boolean): BinaryOperatorExpr;
117
119
  toStmt(): Statement;
118
120
  }
119
121
  export declare class ReadVarExpr extends Expression {
@@ -120,12 +120,13 @@ var BinaryOperator;
120
120
  BinaryOperator[BinaryOperator["Modulo"] = 8] = "Modulo";
121
121
  BinaryOperator[BinaryOperator["And"] = 9] = "And";
122
122
  BinaryOperator[BinaryOperator["Or"] = 10] = "Or";
123
- BinaryOperator[BinaryOperator["BitwiseAnd"] = 11] = "BitwiseAnd";
124
- BinaryOperator[BinaryOperator["Lower"] = 12] = "Lower";
125
- BinaryOperator[BinaryOperator["LowerEquals"] = 13] = "LowerEquals";
126
- BinaryOperator[BinaryOperator["Bigger"] = 14] = "Bigger";
127
- BinaryOperator[BinaryOperator["BiggerEquals"] = 15] = "BiggerEquals";
128
- BinaryOperator[BinaryOperator["NullishCoalesce"] = 16] = "NullishCoalesce";
123
+ BinaryOperator[BinaryOperator["BitwiseOr"] = 11] = "BitwiseOr";
124
+ BinaryOperator[BinaryOperator["BitwiseAnd"] = 12] = "BitwiseAnd";
125
+ BinaryOperator[BinaryOperator["Lower"] = 13] = "Lower";
126
+ BinaryOperator[BinaryOperator["LowerEquals"] = 14] = "LowerEquals";
127
+ BinaryOperator[BinaryOperator["Bigger"] = 15] = "Bigger";
128
+ BinaryOperator[BinaryOperator["BiggerEquals"] = 16] = "BiggerEquals";
129
+ BinaryOperator[BinaryOperator["NullishCoalesce"] = 17] = "NullishCoalesce";
129
130
  })(BinaryOperator || (exports.BinaryOperator = BinaryOperator = {}));
130
131
  function nullSafeIsEquivalent(base, other) {
131
132
  if (base == null || other == null) {
@@ -166,6 +167,9 @@ class Expression {
166
167
  callFn(params, sourceSpan, pure) {
167
168
  return new InvokeFunctionExpr(this, params, null, sourceSpan, pure);
168
169
  }
170
+ bitwiseOr(rhs, sourceSpan, parens = true) {
171
+ return new BinaryOperatorExpr(BinaryOperator.BitwiseOr, this, rhs, null, sourceSpan, parens);
172
+ }
169
173
  toStmt() {
170
174
  return new ExpressionStatement(this, null);
171
175
  }
@@ -26,6 +26,11 @@ export interface R3PartialDeclaration {
26
26
  */
27
27
  type: o.Expression;
28
28
  }
29
+ export type LegacyInputPartialMapping = string | [
30
+ bindingPropertyName: string,
31
+ classPropertyName: string,
32
+ transformFunction?: o.Expression
33
+ ];
29
34
  /**
30
35
  * Describes the shape of the objects that the `ɵɵngDeclareInjector()` accepts.
31
36
  */
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.Identifiers = void 0;
11
11
  const CORE = 'static-injector';
12
12
  class Identifiers {
13
+ /* Methods */
14
+ /* Instructions */
13
15
  static inject = { name: 'ɵɵinject', moduleName: CORE };
14
16
  static directiveInject = {
15
17
  name: 'ɵɵdirectiveInject',
@@ -43,6 +45,8 @@ class Identifiers {
43
45
  name: 'ɵɵFactoryDeclaration',
44
46
  moduleName: CORE,
45
47
  };
48
+ // Signal queries
49
+ // Two-way bindings
46
50
  static getInheritedFactory = {
47
51
  name: 'ɵɵgetInheritedFactory',
48
52
  moduleName: CORE,
@@ -1,10 +1,3 @@
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
1
  export * from './src/di';
9
2
  export * from './src/factory';
10
3
  export * from './src/util';
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
3
  if (k2 === undefined) k2 = k;
11
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -7,7 +7,6 @@
7
7
  */
8
8
  import { R3DependencyMetadata } from 'static-injector/transform/compiler';
9
9
  import { ClassDeclaration, CtorParameter, ReflectionHost, UnavailableValue } from '../../../reflection';
10
- import { CompilationMode } from '../../../transform';
11
10
  export type ConstructorDeps = {
12
11
  deps: R3DependencyMetadata[];
13
12
  } | {
@@ -19,7 +18,7 @@ export interface ConstructorDepError {
19
18
  param: CtorParameter;
20
19
  reason: UnavailableValue;
21
20
  }
22
- export declare function getConstructorDependencies(clazz: ClassDeclaration, reflector: ReflectionHost, isCore: boolean, compilationMode: CompilationMode): ConstructorDeps | null;
21
+ export declare function getConstructorDependencies(clazz: ClassDeclaration, reflector: ReflectionHost, isCore: boolean): ConstructorDeps | null;
23
22
  /**
24
23
  * Convert `ConstructorDeps` into the `R3DependencyMetadata` array for those deps if they're valid,
25
24
  * or into an `'invalid'` signal if they're not.
@@ -27,7 +26,7 @@ export declare function getConstructorDependencies(clazz: ClassDeclaration, refl
27
26
  * This is a companion function to `validateConstructorDependencies` which accepts invalid deps.
28
27
  */
29
28
  export declare function unwrapConstructorDependencies(deps: ConstructorDeps | null): R3DependencyMetadata[] | 'invalid' | null;
30
- export declare function getValidConstructorDependencies(clazz: ClassDeclaration, reflector: ReflectionHost, isCore: boolean, compilationMode: CompilationMode): R3DependencyMetadata[] | null;
29
+ export declare function getValidConstructorDependencies(clazz: ClassDeclaration, reflector: ReflectionHost, isCore: boolean): R3DependencyMetadata[] | null;
31
30
  /**
32
31
  * Validate that `ConstructorDeps` does not have any invalid dependencies and convert them into the
33
32
  * `R3DependencyMetadata` array if so, or raise a diagnostic if some deps are invalid.
@@ -14,9 +14,8 @@ exports.validateConstructorDependencies = exports.getValidConstructorDependencie
14
14
  const compiler_1 = require("static-injector/transform/compiler");
15
15
  const typescript_1 = __importDefault(require("typescript"));
16
16
  const diagnostics_1 = require("../../../diagnostics");
17
- const transform_1 = require("../../../transform");
18
17
  const util_1 = require("./util");
19
- function getConstructorDependencies(clazz, reflector, isCore, compilationMode) {
18
+ function getConstructorDependencies(clazz, reflector, isCore) {
20
19
  const deps = [];
21
20
  const errors = [];
22
21
  let ctorParams = reflector.getConstructorParameters(clazz);
@@ -29,26 +28,7 @@ function getConstructorDependencies(clazz, reflector, isCore, compilationMode) {
29
28
  }
30
29
  }
31
30
  ctorParams.forEach((param, idx) => {
32
- let token = null;
33
- if (compilationMode === transform_1.CompilationMode.LOCAL &&
34
- param.typeValueReference.kind === 2 /* TypeValueReferenceKind.UNAVAILABLE */ &&
35
- param.typeValueReference.reason.kind !== 0 /* ValueUnavailableKind.MISSING_TYPE */) {
36
- // The case of local compilation where injection token cannot be resolved because it is
37
- // "probably" imported from another file
38
- const typeNode = param.typeValueReference.reason.typeNode;
39
- if (typescript_1.default.isTypeReferenceNode(typeNode)) {
40
- // Here we manually create the token out of the typeName without caring about its
41
- // references for better TS tracking. This is because in this code path the typeNode is
42
- // imported from another file and since we are in local compilation mode (=single file
43
- // mode) the reference of this node (or its typeName node) cannot be resolved. So all we
44
- // can do is just to create a new expression.
45
- token = toQualifiedExpression(typeNode.typeName);
46
- }
47
- }
48
- else {
49
- // In all other cases resolve the injection token
50
- token = (0, util_1.valueReferenceToExpression)(param.typeValueReference);
51
- }
31
+ let token = (0, util_1.valueReferenceToExpression)(param.typeValueReference);
52
32
  let attributeNameType = null;
53
33
  let optional = false, self = false, skipSelf = false, host = false;
54
34
  (param.decorators || [])
@@ -100,13 +80,6 @@ function getConstructorDependencies(clazz, reflector, isCore, compilationMode) {
100
80
  }
101
81
  }
102
82
  exports.getConstructorDependencies = getConstructorDependencies;
103
- /** Converts a TS qualified name to output expression. */
104
- function toQualifiedExpression(entity) {
105
- if (typescript_1.default.isIdentifier(entity)) {
106
- return new compiler_1.WrappedNodeExpr(entity);
107
- }
108
- return new compiler_1.ReadPropExpr(toQualifiedExpression(entity.left), entity.right.text);
109
- }
110
83
  /**
111
84
  * Convert `ConstructorDeps` into the `R3DependencyMetadata` array for those deps if they're valid,
112
85
  * or into an `'invalid'` signal if they're not.
@@ -127,8 +100,8 @@ function unwrapConstructorDependencies(deps) {
127
100
  }
128
101
  }
129
102
  exports.unwrapConstructorDependencies = unwrapConstructorDependencies;
130
- function getValidConstructorDependencies(clazz, reflector, isCore, compilationMode) {
131
- return validateConstructorDependencies(clazz, getConstructorDependencies(clazz, reflector, isCore, compilationMode));
103
+ function getValidConstructorDependencies(clazz, reflector, isCore) {
104
+ return validateConstructorDependencies(clazz, getConstructorDependencies(clazz, reflector, isCore));
132
105
  }
133
106
  exports.getValidConstructorDependencies = getValidConstructorDependencies;
134
107
  /**
@@ -8,6 +8,8 @@
8
8
  import { Expression, FactoryTarget, R3FactoryMetadata, R3Reference } from 'static-injector/transform/compiler';
9
9
  import ts from 'typescript';
10
10
  import { ClassDeclaration, Decorator, Import, ImportedTypeValueReference, LocalTypeValueReference, ReflectionHost, TypeValueReference } from '../../../reflection';
11
+ /** Module name of the framework core. */
12
+ export declare const CORE_MODULE = "static-injector";
11
13
  /**
12
14
  * Convert a `TypeValueReference` to an `Expression` which refers to the type as a value.
13
15
  *
@@ -22,6 +24,7 @@ export declare function isAngularCore(decorator: Decorator): decorator is Decora
22
24
  };
23
25
  export declare function findAngularDecorator(decorators: Decorator[], name: string, isCore: boolean): Decorator | undefined;
24
26
  export declare function isAngularDecorator(decorator: Decorator, name: string, isCore: boolean): boolean;
27
+ export declare function getAngularDecorators(decorators: Decorator[], names: readonly string[], isCore: boolean): Decorator[];
25
28
  /**
26
29
  * Unwrap a `ts.Expression`, removing outer type-casts or parentheses until the expression is in its
27
30
  * lowest level form.
@@ -10,9 +10,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.isAbstractClassDeclaration = exports.toFactoryMetadata = exports.wrapTypeReference = exports.wrapFunctionExpressionsInParens = exports.tryUnwrapForwardRef = exports.unwrapExpression = exports.isAngularDecorator = exports.findAngularDecorator = exports.isAngularCore = exports.valueReferenceToExpression = void 0;
13
+ exports.isAbstractClassDeclaration = exports.toFactoryMetadata = exports.wrapTypeReference = exports.wrapFunctionExpressionsInParens = exports.tryUnwrapForwardRef = exports.unwrapExpression = exports.getAngularDecorators = exports.isAngularDecorator = exports.findAngularDecorator = exports.isAngularCore = exports.valueReferenceToExpression = exports.CORE_MODULE = void 0;
14
14
  const compiler_1 = require("static-injector/transform/compiler");
15
15
  const typescript_1 = __importDefault(require("typescript"));
16
+ /** Module name of the framework core. */
17
+ exports.CORE_MODULE = 'static-injector';
16
18
  function valueReferenceToExpression(valueRef) {
17
19
  if (valueRef.kind === 2 /* TypeValueReferenceKind.UNAVAILABLE */) {
18
20
  return null;
@@ -36,7 +38,7 @@ function valueReferenceToExpression(valueRef) {
36
38
  }
37
39
  exports.valueReferenceToExpression = valueReferenceToExpression;
38
40
  function isAngularCore(decorator) {
39
- return (decorator.import !== null && decorator.import.from === 'static-injector');
41
+ return decorator.import !== null && decorator.import.from === exports.CORE_MODULE;
40
42
  }
41
43
  exports.isAngularCore = isAngularCore;
42
44
  function findAngularDecorator(decorators, name, isCore) {
@@ -53,6 +55,16 @@ function isAngularDecorator(decorator, name, isCore) {
53
55
  return false;
54
56
  }
55
57
  exports.isAngularDecorator = isAngularDecorator;
58
+ function getAngularDecorators(decorators, names, isCore) {
59
+ return decorators.filter((decorator) => {
60
+ const name = isCore ? decorator.name : decorator.import?.name;
61
+ if (name === undefined || !names.includes(name)) {
62
+ return false;
63
+ }
64
+ return isCore || isAngularCore(decorator);
65
+ });
66
+ }
67
+ exports.getAngularDecorators = getAngularDecorators;
56
68
  /**
57
69
  * Unwrap a `ts.Expression`, removing outer type-casts or parentheses until the expression is in its
58
70
  * lowest level form.
@@ -63,7 +63,7 @@ class InjectableDecoratorHandler {
63
63
  return {
64
64
  analysis: {
65
65
  meta,
66
- ctorDeps: extractInjectableCtorDeps(node, meta, decorator, this.reflector, this.isCore, this.strictCtorDeps, this.compilationMode),
66
+ ctorDeps: extractInjectableCtorDeps(node, meta, decorator, this.reflector, this.isCore, this.strictCtorDeps),
67
67
  // Avoid generating multiple factories if a class has
68
68
  // more Angular decorators, apart from Injectable.
69
69
  },
@@ -181,7 +181,7 @@ function getProviderExpression(expression, reflector) {
181
181
  ? 2 /* ForwardRefHandling.Unwrapped */
182
182
  : 0 /* ForwardRefHandling.None */);
183
183
  }
184
- function extractInjectableCtorDeps(clazz, meta, decorator, reflector, isCore, strictCtorDeps, compilationMode) {
184
+ function extractInjectableCtorDeps(clazz, meta, decorator, reflector, isCore, strictCtorDeps) {
185
185
  if (decorator.args === null) {
186
186
  throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_NOT_CALLED, decorator.node, '@Injectable must be called');
187
187
  }
@@ -196,15 +196,15 @@ function extractInjectableCtorDeps(clazz, meta, decorator, reflector, isCore, st
196
196
  // constructor signature does not work for DI then a factory definition (ɵfac) that throws is
197
197
  // generated.
198
198
  if (strictCtorDeps && !(0, common_1.isAbstractClassDeclaration)(clazz)) {
199
- ctorDeps = (0, common_2.getValidConstructorDependencies)(clazz, reflector, isCore, compilationMode);
199
+ ctorDeps = (0, common_2.getValidConstructorDependencies)(clazz, reflector, isCore);
200
200
  }
201
201
  else {
202
- ctorDeps = (0, common_2.unwrapConstructorDependencies)((0, common_2.getConstructorDependencies)(clazz, reflector, isCore, compilationMode));
202
+ ctorDeps = (0, common_2.unwrapConstructorDependencies)((0, common_2.getConstructorDependencies)(clazz, reflector, isCore));
203
203
  }
204
204
  return ctorDeps;
205
205
  }
206
206
  else if (decorator.args.length === 1) {
207
- const rawCtorDeps = (0, common_2.getConstructorDependencies)(clazz, reflector, isCore, compilationMode);
207
+ const rawCtorDeps = (0, common_2.getConstructorDependencies)(clazz, reflector, isCore);
208
208
  if (strictCtorDeps &&
209
209
  !(0, common_1.isAbstractClassDeclaration)(clazz) &&
210
210
  requiresValidCtor(meta)) {
@@ -1,9 +1,2 @@
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
1
  export * from './error';
9
2
  export * from './error_code';
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
3
  if (k2 === undefined) k2 = k;
11
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,8 +1 @@
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
1
  export * from './src/core';
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
3
  if (k2 === undefined) k2 = k;
11
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,10 +1,3 @@
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
1
  export * from './src/host';
9
2
  export * from './src/typescript';
10
3
  export * from './src/util';
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
3
  if (k2 === undefined) k2 = k;
11
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -209,7 +209,7 @@ export interface ImportedTypeValueReference {
209
209
  * When `null` or empty, the `importedName` itself is the symbol being referenced.
210
210
  */
211
211
  nestedPath: string[] | null;
212
- valueDeclaration: DeclarationNode;
212
+ valueDeclaration: DeclarationNode | null;
213
213
  }
214
214
  /**
215
215
  * A representation for a type value reference that is used when no value is available. This can
@@ -410,6 +410,11 @@ export interface Import {
410
410
  * A type that is used to identify a declaration.
411
411
  */
412
412
  export type DeclarationNode = ts.Declaration;
413
+ export type AmbientImport = {
414
+ __brand: 'AmbientImport';
415
+ };
416
+ /** Indicates that a declaration is referenced through an ambient type. */
417
+ export declare const AmbientImport: AmbientImport;
413
418
  /**
414
419
  * The declaration of a symbol, along with information about how it was imported into the
415
420
  * application.
@@ -420,7 +425,7 @@ export interface Declaration<T extends ts.Declaration = ts.Declaration> {
420
425
  * was imported via an absolute module (even through a chain of re-exports). If the symbol is part
421
426
  * of the application and was not imported from an absolute path, this will be `null`.
422
427
  */
423
- viaModule: string | null;
428
+ viaModule: string | AmbientImport | null;
424
429
  /**
425
430
  * TypeScript reference to the declaration itself, if one exists.
426
431
  */
@@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.ClassMemberKind = exports.isDecoratorIdentifier = void 0;
13
+ exports.AmbientImport = exports.ClassMemberKind = exports.isDecoratorIdentifier = void 0;
14
14
  const typescript_1 = __importDefault(require("typescript"));
15
15
  function isDecoratorIdentifier(exp) {
16
16
  return (typescript_1.default.isIdentifier(exp) ||
@@ -30,3 +30,5 @@ var ClassMemberKind;
30
30
  ClassMemberKind[ClassMemberKind["Property"] = 3] = "Property";
31
31
  ClassMemberKind[ClassMemberKind["Method"] = 4] = "Method";
32
32
  })(ClassMemberKind || (exports.ClassMemberKind = ClassMemberKind = {}));
33
+ /** Indicates that a declaration is referenced through an ambient type. */
34
+ exports.AmbientImport = {};
@@ -14,7 +14,7 @@ import { TypeValueReference } from './host';
14
14
  * This can return `null` if the `typeNode` is `null`, if it does not refer to a symbol with a value
15
15
  * declaration, or if it is not possible to statically understand.
16
16
  */
17
- export declare function typeToValue(typeNode: ts.TypeNode | null, checker: ts.TypeChecker): TypeValueReference;
17
+ export declare function typeToValue(typeNode: ts.TypeNode | null, checker: ts.TypeChecker, isLocalCompilation: boolean): TypeValueReference;
18
18
  /**
19
19
  * Attempt to extract a `ts.Expression` that's equivalent to a `ts.TypeNode`, as the two have
20
20
  * different AST shapes but can reference the same symbols.
@@ -22,3 +22,4 @@ export declare function typeToValue(typeNode: ts.TypeNode | null, checker: ts.Ty
22
22
  * This will return `null` if an equivalent expression cannot be constructed.
23
23
  */
24
24
  export declare function typeNodeToValueExpr(node: ts.TypeNode): ts.Expression | null;
25
+ export declare function entityNameToValue(node: ts.EntityName): ts.Expression | null;
@@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.typeNodeToValueExpr = exports.typeToValue = void 0;
13
+ exports.entityNameToValue = exports.typeNodeToValueExpr = exports.typeToValue = void 0;
14
14
  const typescript_1 = __importDefault(require("typescript"));
15
15
  /**
16
16
  * Potentially convert a `ts.TypeNode` to a `TypeValueReference`, which indicates how to use the
@@ -19,7 +19,7 @@ const typescript_1 = __importDefault(require("typescript"));
19
19
  * This can return `null` if the `typeNode` is `null`, if it does not refer to a symbol with a value
20
20
  * declaration, or if it is not possible to statically understand.
21
21
  */
22
- function typeToValue(typeNode, checker) {
22
+ function typeToValue(typeNode, checker, isLocalCompilation) {
23
23
  // It's not possible to get a value expression if the parameter doesn't even have a type.
24
24
  if (typeNode === null) {
25
25
  return missingType();
@@ -41,7 +41,17 @@ function typeToValue(typeNode, checker) {
41
41
  if (decl.declarations !== undefined && decl.declarations.length > 0) {
42
42
  typeOnlyDecl = decl.declarations[0];
43
43
  }
44
- return noValueDeclaration(typeNode, typeOnlyDecl);
44
+ // In local compilation mode a declaration is considered invalid only if it is a type related
45
+ // declaration.
46
+ if (!isLocalCompilation ||
47
+ (typeOnlyDecl &&
48
+ [
49
+ typescript_1.default.SyntaxKind.TypeParameter,
50
+ typescript_1.default.SyntaxKind.TypeAliasDeclaration,
51
+ typescript_1.default.SyntaxKind.InterfaceDeclaration,
52
+ ].includes(typeOnlyDecl.kind))) {
53
+ return noValueDeclaration(typeNode, typeOnlyDecl);
54
+ }
45
55
  }
46
56
  // The type points to a valid value declaration. Rewrite the TypeReference into an
47
57
  // Expression which references the value pointed to by the TypeReference, if possible.
@@ -85,7 +95,7 @@ function typeToValue(typeNode, checker) {
85
95
  const moduleName = extractModuleName(firstDecl.parent.parent.parent);
86
96
  return {
87
97
  kind: 1 /* TypeValueReferenceKind.IMPORTED */,
88
- valueDeclaration: decl.valueDeclaration,
98
+ valueDeclaration: decl.valueDeclaration ?? null,
89
99
  moduleName,
90
100
  importedName,
91
101
  nestedPath,
@@ -109,7 +119,7 @@ function typeToValue(typeNode, checker) {
109
119
  const moduleName = extractModuleName(firstDecl.parent.parent);
110
120
  return {
111
121
  kind: 1 /* TypeValueReferenceKind.IMPORTED */,
112
- valueDeclaration: decl.valueDeclaration,
122
+ valueDeclaration: decl.valueDeclaration ?? null,
113
123
  moduleName,
114
124
  importedName,
115
125
  nestedPath,
@@ -252,6 +262,7 @@ function entityNameToValue(node) {
252
262
  return null;
253
263
  }
254
264
  }
265
+ exports.entityNameToValue = entityNameToValue;
255
266
  function extractModuleName(node) {
256
267
  if (!typescript_1.default.isStringLiteral(node.moduleSpecifier)) {
257
268
  throw new Error('not a module specifier');
@@ -12,7 +12,8 @@ import { ClassDeclaration, ClassMember, CtorParameter, DeclarationNode, Decorato
12
12
  */
13
13
  export declare class TypeScriptReflectionHost implements ReflectionHost {
14
14
  protected checker: ts.TypeChecker;
15
- constructor(checker: ts.TypeChecker);
15
+ private readonly isLocalCompilation;
16
+ constructor(checker: ts.TypeChecker, isLocalCompilation?: boolean);
16
17
  getDecoratorsOfDeclaration(declaration: DeclarationNode): Decorator[] | null;
17
18
  getMembersOfClass(clazz: ClassDeclaration): ClassMember[];
18
19
  getConstructorParameters(clazz: ClassDeclaration): CtorParameter[] | null;
@@ -43,10 +44,10 @@ export declare class TypeScriptReflectionHost implements ReflectionHost {
43
44
  protected getImportOfNamespacedIdentifier(id: ts.Identifier, namespaceIdentifier: ts.Identifier | null): Import | null;
44
45
  private _reflectDecorator;
45
46
  private _reflectMember;
47
+ private _viaModule;
46
48
  }
47
49
  export declare function reflectObjectLiteral(node: ts.ObjectLiteralExpression): Map<string, ts.Expression>;
48
50
  /**
49
- * Return the ImportDeclaration for the given `node` if it is either an `ImportSpecifier` or a
50
- * `NamespaceImport`. If not return `null`.
51
+ * Gets the closest ancestor `ImportDeclaration` to a node.
51
52
  */
52
53
  export declare function getContainingImportDeclaration(node: ts.Node): ts.ImportDeclaration | null;
@@ -20,8 +20,10 @@ const util_1 = require("./util");
20
20
  */
21
21
  class TypeScriptReflectionHost {
22
22
  checker;
23
- constructor(checker) {
23
+ isLocalCompilation;
24
+ constructor(checker, isLocalCompilation = false) {
24
25
  this.checker = checker;
26
+ this.isLocalCompilation = isLocalCompilation;
25
27
  }
26
28
  getDecoratorsOfDeclaration(declaration) {
27
29
  const decorators = typescript_1.default.canHaveDecorators(declaration)
@@ -70,7 +72,7 @@ class TypeScriptReflectionHost {
70
72
  typeNode = childTypeNodes[0];
71
73
  }
72
74
  }
73
- const typeValueReference = (0, type_to_value_1.typeToValue)(typeNode, this.checker);
75
+ const typeValueReference = (0, type_to_value_1.typeToValue)(typeNode, this.checker, this.isLocalCompilation);
74
76
  return {
75
77
  name,
76
78
  nameNode: node.name,
@@ -280,6 +282,18 @@ class TypeScriptReflectionHost {
280
282
  isStatic,
281
283
  };
282
284
  }
285
+ _viaModule(declaration, originalId, importInfo) {
286
+ if (importInfo === null &&
287
+ originalId !== null &&
288
+ declaration.getSourceFile() !== originalId.getSourceFile()) {
289
+ return host_1.AmbientImport;
290
+ }
291
+ return importInfo !== null &&
292
+ importInfo.from !== null &&
293
+ !importInfo.from.startsWith('.')
294
+ ? importInfo.from
295
+ : null;
296
+ }
283
297
  }
284
298
  exports.TypeScriptReflectionHost = TypeScriptReflectionHost;
285
299
  function reflectObjectLiteral(node) {
@@ -353,15 +367,17 @@ function getFarLeftIdentifier(propertyAccess) {
353
367
  : null;
354
368
  }
355
369
  /**
356
- * Return the ImportDeclaration for the given `node` if it is either an `ImportSpecifier` or a
357
- * `NamespaceImport`. If not return `null`.
370
+ * Gets the closest ancestor `ImportDeclaration` to a node.
358
371
  */
359
372
  function getContainingImportDeclaration(node) {
360
- return typescript_1.default.isImportSpecifier(node)
361
- ? node.parent.parent.parent
362
- : typescript_1.default.isNamespaceImport(node)
363
- ? node.parent.parent
364
- : null;
373
+ let parent = node.parent;
374
+ while (parent && !typescript_1.default.isSourceFile(parent)) {
375
+ if (typescript_1.default.isImportDeclaration(parent)) {
376
+ return parent;
377
+ }
378
+ parent = parent.parent;
379
+ }
380
+ return null;
365
381
  }
366
382
  exports.getContainingImportDeclaration = getContainingImportDeclaration;
367
383
  /**
@@ -1,9 +1,2 @@
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
1
  export * from './src/api';
9
2
  export * from './src/utils';
@@ -1,11 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
3
  if (k2 === undefined) k2 = k;
11
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -12,4 +12,4 @@ import { ImportManager } from '../../translator';
12
12
  * and before the module body.
13
13
  * Can optionally add extra statements (e.g. new constants) before the body as well.
14
14
  */
15
- export declare function addImports(importManager: ImportManager, sf: ts.SourceFile, extraStatements?: ts.Statement[]): ts.SourceFile;
15
+ export declare function addImports(factory: ts.NodeFactory | undefined, importManager: ImportManager, sf: ts.SourceFile, extraStatements?: ts.Statement[]): ts.SourceFile;