static-injector 1.0.10 → 2.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 (78) hide show
  1. package/import/commonjs/index.js +331 -118
  2. package/import/es2015/di/create_injector.js +30 -0
  3. package/import/es2015/di/initializer_token.js +15 -0
  4. package/import/es2015/di/inject_switch.js +27 -6
  5. package/import/es2015/{decorator → di}/injectable.js +0 -0
  6. package/import/es2015/di/injection_token.js +6 -0
  7. package/import/es2015/di/injector.js +6 -8
  8. package/import/es2015/di/injector_compatibility.js +90 -34
  9. package/import/es2015/di/injector_token.js +1 -1
  10. package/import/es2015/di/interface/defs.js +39 -0
  11. package/import/es2015/di/interface/injector.js +1 -0
  12. package/import/es2015/di/internal_tokens.js +9 -0
  13. package/import/es2015/di/metadata.js +4 -4
  14. package/import/es2015/di/provider_collection.js +49 -0
  15. package/import/es2015/di/r3_injector.js +96 -66
  16. package/import/es2015/di/scope.js +2 -2
  17. package/import/es2015/index.js +1 -1
  18. package/import/es2015/render3/errors_di.js +1 -1
  19. package/import/fesm2015/index.js +322 -108
  20. package/import/typings/di/create_injector.d.ts +23 -0
  21. package/import/typings/di/initializer_token.d.ts +15 -0
  22. package/import/typings/di/inject_switch.d.ts +7 -2
  23. package/import/typings/{decorator → di}/injectable.d.ts +1 -1
  24. package/import/typings/di/injection_token.d.ts +4 -0
  25. package/import/typings/di/injector.d.ts +20 -7
  26. package/import/typings/di/injector_compatibility.d.ts +42 -21
  27. package/import/typings/di/interface/defs.d.ts +10 -0
  28. package/import/typings/di/interface/injector.d.ts +26 -0
  29. package/import/typings/di/interface/provider.d.ts +1 -6
  30. package/import/typings/di/internal_tokens.d.ts +10 -0
  31. package/import/typings/di/provider_collection.d.ts +30 -0
  32. package/import/typings/di/r3_injector.d.ts +67 -36
  33. package/import/typings/di/scope.d.ts +3 -2
  34. package/import/typings/index.d.ts +1 -1
  35. package/package.json +4 -2
  36. package/transform/compiler/index.js +5 -1
  37. package/transform/compiler/src/injectable_compiler_2.d.ts +7 -36
  38. package/transform/compiler/src/injectable_compiler_2.js +20 -23
  39. package/transform/compiler/src/output/output_ast.d.ts +29 -108
  40. package/transform/compiler/src/output/output_ast.js +66 -188
  41. package/transform/compiler/src/render3/r3_factory.js +11 -7
  42. package/transform/compiler/src/render3/util.d.ts +64 -0
  43. package/transform/compiler/src/render3/util.js +52 -9
  44. package/transform/compiler/src/render3/view/util.js +5 -1
  45. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +5 -4
  46. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.js +32 -23
  47. package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +1 -1
  48. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +33 -21
  49. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
  50. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +5 -1
  51. package/transform/compiler-cli/src/ngtsc/imports/index.js +5 -1
  52. package/transform/compiler-cli/src/ngtsc/reflection/index.js +5 -1
  53. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +1 -1
  54. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +6 -2
  55. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
  56. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +36 -23
  57. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +18 -13
  58. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +5 -1
  59. package/transform/compiler-cli/src/ngtsc/transform/index.js +5 -1
  60. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
  61. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +13 -8
  62. package/transform/compiler-cli/src/ngtsc/translator/index.js +5 -1
  63. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +3 -3
  64. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +7 -3
  65. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -4
  66. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +5 -17
  67. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
  68. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +67 -55
  69. package/{import/es2015/decorator/interface/provider.js → transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts} +1 -1
  70. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
  71. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +151 -0
  72. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +210 -0
  73. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +5 -1
  74. package/transform/index.js +5 -1
  75. package/transform/injectable-transform.js +30 -38
  76. package/import/typings/decorator/interface/provider.d.ts +0 -312
  77. package/transform/compiler/src/render3/partial/util.d.ts +0 -16
  78. package/transform/compiler/src/render3/partial/util.js +0 -44
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -26,11 +30,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
30
  return result;
27
31
  };
28
32
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.toFactoryMetadata = exports.wrapTypeReference = exports.wrapFunctionExpressionsInParens = exports.tryUnwrapForwardRef = exports.unwrapExpression = exports.isAngularDecorator = exports.findAngularDecorator = exports.isAngularCore = exports.validateConstructorDependencies = exports.getValidConstructorDependencies = exports.unwrapConstructorDependencies = exports.valueReferenceToExpression = exports.getConstructorDependencies = void 0;
30
- const compiler_1 = require("../../../../../compiler");
33
+ exports.isAbstractClassDeclaration = exports.toFactoryMetadata = exports.wrapTypeReference = exports.wrapFunctionExpressionsInParens = exports.tryUnwrapForwardRef = exports.unwrapExpression = exports.isAngularDecorator = exports.findAngularDecorator = exports.isAngularCore = exports.validateConstructorDependencies = exports.getValidConstructorDependencies = exports.unwrapConstructorDependencies = exports.valueReferenceToExpression = exports.getConstructorDependencies = void 0;
34
+ const compiler_1 = require("../../../../../../compiler");
31
35
  const ts = __importStar(require("typescript"));
32
- const diagnostics_1 = require("../../diagnostics");
33
- const reflection_1 = require("../../reflection");
36
+ const diagnostics_1 = require("../../../diagnostics");
37
+ const reflection_1 = require("../../../reflection");
34
38
  function getConstructorDependencies(clazz, reflector, isCore) {
35
39
  const deps = [];
36
40
  const errors = [];
@@ -71,7 +75,7 @@ function getConstructorDependencies(clazz, reflector, isCore) {
71
75
  }
72
76
  });
73
77
  if (token === null) {
74
- if (param.typeValueReference.kind !== 2 /* UNAVAILABLE */) {
78
+ if (param.typeValueReference.kind !== 2 /* TypeValueReferenceKind.UNAVAILABLE */) {
75
79
  throw new Error('Illegal state: expected value reference to be unavailable if no token is present');
76
80
  }
77
81
  errors.push({
@@ -93,10 +97,10 @@ function getConstructorDependencies(clazz, reflector, isCore) {
93
97
  }
94
98
  exports.getConstructorDependencies = getConstructorDependencies;
95
99
  function valueReferenceToExpression(valueRef) {
96
- if (valueRef.kind === 2 /* UNAVAILABLE */) {
100
+ if (valueRef.kind === 2 /* TypeValueReferenceKind.UNAVAILABLE */) {
97
101
  return null;
98
102
  }
99
- else if (valueRef.kind === 0 /* LOCAL */) {
103
+ else if (valueRef.kind === 0 /* TypeValueReferenceKind.LOCAL */) {
100
104
  const expr = new compiler_1.WrappedNodeExpr(valueRef.expression);
101
105
  return expr;
102
106
  }
@@ -170,46 +174,46 @@ function createUnsuitableInjectionTokenError(clazz, error) {
170
174
  let chainMessage = undefined;
171
175
  let hints = undefined;
172
176
  switch (reason.kind) {
173
- case 5 /* UNSUPPORTED */:
177
+ case 5 /* ValueUnavailableKind.UNSUPPORTED */:
174
178
  chainMessage =
175
179
  'Consider using the @Inject decorator to specify an injection token.';
176
180
  hints = [
177
- diagnostics_1.makeRelatedInformation(reason.typeNode, 'This type is not supported as injection token.'),
181
+ (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type is not supported as injection token.'),
178
182
  ];
179
183
  break;
180
- case 1 /* NO_VALUE_DECLARATION */:
184
+ case 1 /* ValueUnavailableKind.NO_VALUE_DECLARATION */:
181
185
  chainMessage =
182
186
  'Consider using the @Inject decorator to specify an injection token.';
183
187
  hints = [
184
- diagnostics_1.makeRelatedInformation(reason.typeNode, 'This type does not have a value, so it cannot be used as injection token.'),
188
+ (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type does not have a value, so it cannot be used as injection token.'),
185
189
  ];
186
190
  if (reason.decl !== null) {
187
- hints.push(diagnostics_1.makeRelatedInformation(reason.decl, 'The type is declared here.'));
191
+ hints.push((0, diagnostics_1.makeRelatedInformation)(reason.decl, 'The type is declared here.'));
188
192
  }
189
193
  break;
190
- case 2 /* TYPE_ONLY_IMPORT */:
194
+ case 2 /* ValueUnavailableKind.TYPE_ONLY_IMPORT */:
191
195
  chainMessage =
192
196
  'Consider changing the type-only import to a regular import, or use the @Inject decorator to specify an injection token.';
193
197
  hints = [
194
- diagnostics_1.makeRelatedInformation(reason.typeNode, 'This type is imported using a type-only import, which prevents it from being usable as an injection token.'),
195
- diagnostics_1.makeRelatedInformation(reason.importClause, 'The type-only import occurs here.'),
198
+ (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type is imported using a type-only import, which prevents it from being usable as an injection token.'),
199
+ (0, diagnostics_1.makeRelatedInformation)(reason.node, 'The type-only import occurs here.'),
196
200
  ];
197
201
  break;
198
- case 4 /* NAMESPACE */:
202
+ case 4 /* ValueUnavailableKind.NAMESPACE */:
199
203
  chainMessage =
200
204
  'Consider using the @Inject decorator to specify an injection token.';
201
205
  hints = [
202
- diagnostics_1.makeRelatedInformation(reason.typeNode, 'This type corresponds with a namespace, which cannot be used as injection token.'),
203
- diagnostics_1.makeRelatedInformation(reason.importClause, 'The namespace import occurs here.'),
206
+ (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type corresponds with a namespace, which cannot be used as injection token.'),
207
+ (0, diagnostics_1.makeRelatedInformation)(reason.importClause, 'The namespace import occurs here.'),
204
208
  ];
205
209
  break;
206
- case 3 /* UNKNOWN_REFERENCE */:
210
+ case 3 /* ValueUnavailableKind.UNKNOWN_REFERENCE */:
207
211
  chainMessage = 'The type should reference a known declaration.';
208
212
  hints = [
209
- diagnostics_1.makeRelatedInformation(reason.typeNode, 'This type could not be resolved.'),
213
+ (0, diagnostics_1.makeRelatedInformation)(reason.typeNode, 'This type could not be resolved.'),
210
214
  ];
211
215
  break;
212
- case 0 /* MISSING_TYPE */:
216
+ case 0 /* ValueUnavailableKind.MISSING_TYPE */:
213
217
  chainMessage =
214
218
  'Consider adding a type to the parameter or use the @Inject decorator to specify an injection token.';
215
219
  break;
@@ -351,7 +355,7 @@ exports.wrapFunctionExpressionsInParens = wrapFunctionExpressionsInParens;
351
355
  function wrapTypeReference(reflector, clazz) {
352
356
  const dtsClass = reflector.getDtsDeclaration(clazz);
353
357
  const value = new compiler_1.WrappedNodeExpr(clazz.name);
354
- const type = dtsClass !== null && reflection_1.isNamedClassDeclaration(dtsClass)
358
+ const type = dtsClass !== null && (0, reflection_1.isNamedClassDeclaration)(dtsClass)
355
359
  ? new compiler_1.WrappedNodeExpr(dtsClass.name)
356
360
  : value;
357
361
  return { value, type };
@@ -368,3 +372,8 @@ function toFactoryMetadata(meta, target) {
368
372
  };
369
373
  }
370
374
  exports.toFactoryMetadata = toFactoryMetadata;
375
+ function isAbstractClassDeclaration(clazz) {
376
+ return (clazz.modifiers !== undefined &&
377
+ clazz.modifiers.some((mod) => mod.kind === ts.SyntaxKind.AbstractKeyword));
378
+ }
379
+ exports.isAbstractClassDeclaration = isAbstractClassDeclaration;
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.compileNgFactoryDefField = void 0;
11
11
  const compiler_1 = require("../../../../../compiler");
12
12
  function compileNgFactoryDefField(metadata) {
13
- const res = compiler_1.compileFactoryFunction(metadata);
13
+ const res = (0, compiler_1.compileFactoryFunction)(metadata);
14
14
  return {
15
15
  name: "ɵfac",
16
16
  initializer: res.expression,
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -32,7 +36,8 @@ const ts = __importStar(require("typescript"));
32
36
  const diagnostics_1 = require("../../diagnostics");
33
37
  const reflection_1 = require("../../reflection");
34
38
  const factory_1 = require("./factory");
35
- const util_1 = require("./util");
39
+ const util_1 = require("../common/src/util");
40
+ const util_2 = require("../common/src/util");
36
41
  /**
37
42
  * Adapts the `compileInjectable` compiler for `@Injectable` decorators to the Ivy compiler.
38
43
  */
@@ -54,7 +59,7 @@ class InjectableDecoratorHandler {
54
59
  if (!decorators) {
55
60
  return undefined;
56
61
  }
57
- const decorator = util_1.findAngularDecorator(decorators, 'Injectable', this.isCore);
62
+ const decorator = (0, util_1.findAngularDecorator)(decorators, 'Injectable', this.isCore);
58
63
  if (decorator !== undefined) {
59
64
  return {
60
65
  trigger: decorator.node,
@@ -78,12 +83,12 @@ class InjectableDecoratorHandler {
78
83
  };
79
84
  }
80
85
  compileFull(node, analysis) {
81
- return this.compile(factory_1.compileNgFactoryDefField, (meta) => compiler_1.compileInjectable(meta, false), node, analysis);
86
+ return this.compile(factory_1.compileNgFactoryDefField, (meta) => (0, compiler_1.compileInjectable)(meta, false), node, analysis);
82
87
  }
83
88
  compile(compileFactoryFn, compileInjectableFn, node, analysis) {
84
89
  const results = [];
85
90
  const meta = analysis.meta;
86
- const factoryRes = compileFactoryFn(util_1.toFactoryMetadata(Object.assign(Object.assign({}, meta), { deps: analysis.ctorDeps }), compiler_1.FactoryTarget.Injectable));
91
+ const factoryRes = compileFactoryFn((0, util_1.toFactoryMetadata)(Object.assign(Object.assign({}, meta), { deps: analysis.ctorDeps }), compiler_1.FactoryTarget.Injectable));
87
92
  results.push(factoryRes);
88
93
  const ɵprov = this.reflector
89
94
  .getMembersOfClass(node)
@@ -113,7 +118,7 @@ exports.InjectableDecoratorHandler = InjectableDecoratorHandler;
113
118
  */
114
119
  function extractInjectableMetadata(clazz, decorator, reflector) {
115
120
  const name = clazz.name.text;
116
- const type = util_1.wrapTypeReference(reflector, clazz);
121
+ const type = (0, util_1.wrapTypeReference)(reflector, clazz);
117
122
  const internalType = new compiler_1.WrappedNodeExpr(reflector.getInternalNameOfClass(clazz));
118
123
  const typeArgumentCount = reflector.getGenericArityOfClass(clazz) || 0;
119
124
  if (decorator.args === null) {
@@ -125,7 +130,7 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
125
130
  type,
126
131
  typeArgumentCount,
127
132
  internalType,
128
- providedIn: compiler_1.createR3ProviderExpression(new compiler_1.LiteralExpr(null), false),
133
+ providedIn: (0, compiler_1.createMayBeForwardRefExpression)(new compiler_1.LiteralExpr(null), 0 /* ForwardRefHandling.None */),
129
134
  };
130
135
  }
131
136
  else if (decorator.args.length === 1) {
@@ -137,10 +142,10 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
137
142
  throw new diagnostics_1.FatalDiagnosticError(diagnostics_1.ErrorCode.DECORATOR_ARG_NOT_LITERAL, metaNode, `@Injectable argument must be an object literal`);
138
143
  }
139
144
  // Resolve the fields of the literal into a map of field name to expression.
140
- const meta = reflection_1.reflectObjectLiteral(metaNode);
145
+ const meta = (0, reflection_1.reflectObjectLiteral)(metaNode);
141
146
  const providedIn = meta.has('providedIn')
142
147
  ? getProviderExpression(meta.get('providedIn'), reflector)
143
- : compiler_1.createR3ProviderExpression(new compiler_1.LiteralExpr(null), false);
148
+ : (0, compiler_1.createMayBeForwardRefExpression)(new compiler_1.LiteralExpr(null), 0 /* ForwardRefHandling.None */);
144
149
  let deps = undefined;
145
150
  if ((meta.has('useClass') || meta.has('useFactory')) && meta.has('deps')) {
146
151
  const depsExpr = meta.get('deps');
@@ -184,8 +189,10 @@ function extractInjectableMetadata(clazz, decorator, reflector) {
184
189
  * object to indicate whether the value needed unwrapping.
185
190
  */
186
191
  function getProviderExpression(expression, reflector) {
187
- const forwardRefValue = util_1.tryUnwrapForwardRef(expression, reflector);
188
- return compiler_1.createR3ProviderExpression(new compiler_1.WrappedNodeExpr(forwardRefValue !== null && forwardRefValue !== void 0 ? forwardRefValue : expression), forwardRefValue !== null);
192
+ const forwardRefValue = (0, util_1.tryUnwrapForwardRef)(expression, reflector);
193
+ return (0, compiler_1.createMayBeForwardRefExpression)(new compiler_1.WrappedNodeExpr(forwardRefValue !== null && forwardRefValue !== void 0 ? forwardRefValue : expression), forwardRefValue !== null
194
+ ? 2 /* ForwardRefHandling.Unwrapped */
195
+ : 0 /* ForwardRefHandling.None */);
189
196
  }
190
197
  function extractInjectableCtorDeps(clazz, meta, decorator, reflector, isCore, strictCtorDeps) {
191
198
  if (decorator.args === null) {
@@ -202,29 +209,34 @@ function extractInjectableCtorDeps(clazz, meta, decorator, reflector, isCore, st
202
209
  // constructor signature does not work for DI then a factory definition (ɵfac) that throws is
203
210
  // generated.
204
211
  if (strictCtorDeps) {
205
- ctorDeps = util_1.getValidConstructorDependencies(clazz, reflector, isCore);
212
+ ctorDeps = (0, util_1.getValidConstructorDependencies)(clazz, reflector, isCore);
206
213
  }
207
214
  else {
208
- ctorDeps = util_1.unwrapConstructorDependencies(util_1.getConstructorDependencies(clazz, reflector, isCore));
215
+ ctorDeps = (0, util_1.unwrapConstructorDependencies)((0, util_1.getConstructorDependencies)(clazz, reflector, isCore));
209
216
  }
210
217
  return ctorDeps;
211
218
  }
212
219
  else if (decorator.args.length === 1) {
213
- const rawCtorDeps = util_1.getConstructorDependencies(clazz, reflector, isCore);
220
+ const rawCtorDeps = (0, util_1.getConstructorDependencies)(clazz, reflector, isCore);
214
221
  if (strictCtorDeps &&
215
- meta.useValue === undefined &&
216
- meta.useExisting === undefined &&
217
- meta.useClass === undefined &&
218
- meta.useFactory === undefined) {
219
- // Since use* was not provided, validate the deps according to strictCtorDeps.
220
- ctorDeps = util_1.validateConstructorDependencies(clazz, rawCtorDeps);
222
+ !(0, util_2.isAbstractClassDeclaration)(clazz) &&
223
+ requiresValidCtor(meta)) {
224
+ // Since use* was not provided for a concrete class, validate the deps according to
225
+ // strictCtorDeps.
226
+ ctorDeps = (0, util_1.validateConstructorDependencies)(clazz, rawCtorDeps);
221
227
  }
222
228
  else {
223
- ctorDeps = util_1.unwrapConstructorDependencies(rawCtorDeps);
229
+ ctorDeps = (0, util_1.unwrapConstructorDependencies)(rawCtorDeps);
224
230
  }
225
231
  }
226
232
  return ctorDeps;
227
233
  }
234
+ function requiresValidCtor(meta) {
235
+ return (meta.useValue === undefined &&
236
+ meta.useExisting === undefined &&
237
+ meta.useClass === undefined &&
238
+ meta.useFactory === undefined);
239
+ }
228
240
  function getDep(dep, reflector) {
229
241
  const meta = {
230
242
  token: new compiler_1.WrappedNodeExpr(dep),
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -49,7 +53,7 @@ function makeDiagnostic(code, node, messageText, relatedInformation) {
49
53
  node = ts.getOriginalNode(node);
50
54
  return {
51
55
  category: ts.DiagnosticCategory.Error,
52
- code: error_code_1.ngErrorCode(code),
56
+ code: (0, error_code_1.ngErrorCode)(code),
53
57
  file: ts.getOriginalNode(node).getSourceFile(),
54
58
  start: node.getStart(undefined, false),
55
59
  length: node.getWidth(),
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -290,7 +290,7 @@ export interface NoValueDeclaration {
290
290
  export interface TypeOnlyImport {
291
291
  kind: ValueUnavailableKind.TYPE_ONLY_IMPORT;
292
292
  typeNode: ts.TypeNode;
293
- importClause: ts.ImportClause;
293
+ node: ts.ImportClause | ts.ImportSpecifier;
294
294
  }
295
295
  export interface NamespaceImport {
296
296
  kind: ValueUnavailableKind.NAMESPACE;
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -93,6 +97,6 @@ var KnownDeclaration;
93
97
  * `ts.Declaration`).
94
98
  */
95
99
  function isConcreteDeclaration(decl) {
96
- return decl.kind === 0 /* Concrete */;
100
+ return decl.kind === 0 /* DeclarationKind.Concrete */;
97
101
  }
98
102
  exports.isConcreteDeclaration = isConcreteDeclaration;
@@ -5,8 +5,8 @@
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 * as ts from "typescript";
9
- import { TypeValueReference } from "./host";
8
+ import * as ts from 'typescript';
9
+ import { TypeValueReference } from './host';
10
10
  /**
11
11
  * Potentially convert a `ts.TypeNode` to a `TypeValueReference`, which indicates how to use the
12
12
  * type given in the `ts.TypeNode` in a value position.
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -73,7 +77,7 @@ function typeToValue(typeNode, checker) {
73
77
  return typeOnlyImport(typeNode, firstDecl);
74
78
  }
75
79
  return {
76
- kind: 0 /* LOCAL */,
80
+ kind: 0 /* TypeValueReferenceKind.LOCAL */,
77
81
  expression: firstDecl.name,
78
82
  defaultImportStatement: firstDecl.parent,
79
83
  };
@@ -83,8 +87,13 @@ function typeToValue(typeNode, checker) {
83
87
  // import {Foo} from 'foo';
84
88
  // or
85
89
  // import {Foo as Bar} from 'foo';
90
+ if (firstDecl.isTypeOnly) {
91
+ // The import specifier can't be type-only (e.g. `import {type Foo} from '...')`.
92
+ return typeOnlyImport(typeNode, firstDecl);
93
+ }
86
94
  if (firstDecl.parent.parent.isTypeOnly) {
87
- // Type-only imports cannot be represented as value.
95
+ // The import specifier can't be inside a type-only import clause
96
+ // (e.g. `import type {Foo} from '...')`.
88
97
  return typeOnlyImport(typeNode, firstDecl.parent.parent);
89
98
  }
90
99
  // Determine the name to import (`Foo`) from the import specifier, as the symbol names of
@@ -95,7 +104,7 @@ function typeToValue(typeNode, checker) {
95
104
  const [_localName, ...nestedPath] = symbols.symbolNames;
96
105
  const moduleName = extractModuleName(firstDecl.parent.parent.parent);
97
106
  return {
98
- kind: 1 /* IMPORTED */,
107
+ kind: 1 /* TypeValueReferenceKind.IMPORTED */,
99
108
  valueDeclaration: decl.valueDeclaration,
100
109
  moduleName,
101
110
  importedName,
@@ -119,7 +128,7 @@ function typeToValue(typeNode, checker) {
119
128
  const [_ns, importedName, ...nestedPath] = symbols.symbolNames;
120
129
  const moduleName = extractModuleName(firstDecl.parent.parent);
121
130
  return {
122
- kind: 1 /* IMPORTED */,
131
+ kind: 1 /* TypeValueReferenceKind.IMPORTED */,
123
132
  valueDeclaration: decl.valueDeclaration,
124
133
  moduleName,
125
134
  importedName,
@@ -131,7 +140,7 @@ function typeToValue(typeNode, checker) {
131
140
  const expression = typeNodeToValueExpr(typeNode);
132
141
  if (expression !== null) {
133
142
  return {
134
- kind: 0 /* LOCAL */,
143
+ kind: 0 /* TypeValueReferenceKind.LOCAL */,
135
144
  expression,
136
145
  defaultImportStatement: null,
137
146
  };
@@ -143,42 +152,42 @@ function typeToValue(typeNode, checker) {
143
152
  exports.typeToValue = typeToValue;
144
153
  function unsupportedType(typeNode) {
145
154
  return {
146
- kind: 2 /* UNAVAILABLE */,
147
- reason: { kind: 5 /* UNSUPPORTED */, typeNode },
155
+ kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
156
+ reason: { kind: 5 /* ValueUnavailableKind.UNSUPPORTED */, typeNode },
148
157
  };
149
158
  }
150
159
  function noValueDeclaration(typeNode, decl) {
151
160
  return {
152
- kind: 2 /* UNAVAILABLE */,
153
- reason: { kind: 1 /* NO_VALUE_DECLARATION */, typeNode, decl },
161
+ kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
162
+ reason: { kind: 1 /* ValueUnavailableKind.NO_VALUE_DECLARATION */, typeNode, decl },
154
163
  };
155
164
  }
156
- function typeOnlyImport(typeNode, importClause) {
165
+ function typeOnlyImport(typeNode, node) {
157
166
  return {
158
- kind: 2 /* UNAVAILABLE */,
167
+ kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
159
168
  reason: {
160
- kind: 2 /* TYPE_ONLY_IMPORT */,
169
+ kind: 2 /* ValueUnavailableKind.TYPE_ONLY_IMPORT */,
161
170
  typeNode,
162
- importClause,
171
+ node: node,
163
172
  },
164
173
  };
165
174
  }
166
175
  function unknownReference(typeNode) {
167
176
  return {
168
- kind: 2 /* UNAVAILABLE */,
169
- reason: { kind: 3 /* UNKNOWN_REFERENCE */, typeNode },
177
+ kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
178
+ reason: { kind: 3 /* ValueUnavailableKind.UNKNOWN_REFERENCE */, typeNode },
170
179
  };
171
180
  }
172
181
  function namespaceImport(typeNode, importClause) {
173
182
  return {
174
- kind: 2 /* UNAVAILABLE */,
175
- reason: { kind: 4 /* NAMESPACE */, typeNode, importClause },
183
+ kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
184
+ reason: { kind: 4 /* ValueUnavailableKind.NAMESPACE */, typeNode, importClause },
176
185
  };
177
186
  }
178
187
  function missingType() {
179
188
  return {
180
- kind: 2 /* UNAVAILABLE */,
181
- reason: { kind: 0 /* MISSING_TYPE */ },
189
+ kind: 2 /* TypeValueReferenceKind.UNAVAILABLE */,
190
+ reason: { kind: 0 /* ValueUnavailableKind.MISSING_TYPE */ },
182
191
  };
183
192
  }
184
193
  /**
@@ -254,10 +263,14 @@ function resolveTypeSymbols(typeRef, checker) {
254
263
  function entityNameToValue(node) {
255
264
  if (ts.isQualifiedName(node)) {
256
265
  const left = entityNameToValue(node.left);
257
- return left !== null ? ts.createPropertyAccess(left, node.right) : null;
266
+ return left !== null
267
+ ? ts.factory.createPropertyAccessExpression(left, node.right)
268
+ : null;
258
269
  }
259
270
  else if (ts.isIdentifier(node)) {
260
- return ts.getMutableClone(node);
271
+ const clone = ts.setOriginalNode(ts.factory.createIdentifier(node.text), node);
272
+ clone.parent = node.parent;
273
+ return clone;
261
274
  }
262
275
  else {
263
276
  return null;
@@ -265,7 +278,7 @@ function entityNameToValue(node) {
265
278
  }
266
279
  function extractModuleName(node) {
267
280
  if (!ts.isStringLiteral(node.moduleSpecifier)) {
268
- throw new Error("not a module specifier");
281
+ throw new Error('not a module specifier');
269
282
  }
270
283
  return node.moduleSpecifier.text;
271
284
  }
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -28,6 +32,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
32
  Object.defineProperty(exports, "__esModule", { value: true });
29
33
  exports.reflectObjectLiteral = exports.TypeScriptReflectionHost = void 0;
30
34
  const ts = __importStar(require("typescript"));
35
+ const ts_compatibility_1 = require("../../ts_compatibility");
31
36
  const host_1 = require("./host");
32
37
  const type_to_value_1 = require("./type_to_value");
33
38
  const util_1 = require("./util");
@@ -39,13 +44,12 @@ class TypeScriptReflectionHost {
39
44
  this.checker = checker;
40
45
  }
41
46
  getDecoratorsOfDeclaration(declaration) {
42
- if (declaration.decorators === undefined ||
43
- declaration.decorators.length === 0) {
44
- return null;
45
- }
46
- return declaration.decorators
47
- .map((decorator) => this._reflectDecorator(decorator))
48
- .filter((dec) => dec !== null);
47
+ const decorators = (0, ts_compatibility_1.getDecorators)(declaration);
48
+ return decorators !== undefined && decorators.length
49
+ ? decorators
50
+ .map((decorator) => this._reflectDecorator(decorator))
51
+ .filter((dec) => dec !== null)
52
+ : null;
49
53
  }
50
54
  getMembersOfClass(clazz) {
51
55
  const tsClazz = castDeclarationToClassOrDie(clazz);
@@ -84,7 +88,7 @@ class TypeScriptReflectionHost {
84
88
  typeNode = childTypeNodes[0];
85
89
  }
86
90
  }
87
- const typeValueReference = type_to_value_1.typeToValue(typeNode, this.checker);
91
+ const typeValueReference = (0, type_to_value_1.typeToValue)(typeNode, this.checker);
88
92
  return {
89
93
  name,
90
94
  nameNode: node.name,
@@ -113,7 +117,7 @@ class TypeScriptReflectionHost {
113
117
  isClass(node) {
114
118
  // For our purposes, classes are "named" ts.ClassDeclarations;
115
119
  // (`node.name` can be undefined in unnamed default exports: `default export class { ... }`).
116
- return util_1.isNamedClassDeclaration(node);
120
+ return (0, util_1.isNamedClassDeclaration)(node);
117
121
  }
118
122
  hasBaseClass(clazz) {
119
123
  return this.getBaseClassExpression(clazz) !== null;
@@ -232,7 +236,7 @@ class TypeScriptReflectionHost {
232
236
  }
233
237
  // The final resolved decorator should be a `ts.Identifier` - if it's not, then something is
234
238
  // wrong and the decorator can't be resolved statically.
235
- if (!host_1.isDecoratorIdentifier(decoratorExpr)) {
239
+ if (!(0, host_1.isDecoratorIdentifier)(decoratorExpr)) {
236
240
  return null;
237
241
  }
238
242
  const decoratorIdentifier = ts.isIdentifier(decoratorExpr)
@@ -286,8 +290,9 @@ class TypeScriptReflectionHost {
286
290
  return null;
287
291
  }
288
292
  const decorators = this.getDecoratorsOfDeclaration(node);
289
- const isStatic = node.modifiers !== undefined &&
290
- node.modifiers.some((mod) => mod.kind === ts.SyntaxKind.StaticKeyword);
293
+ const modifiers = (0, ts_compatibility_1.getModifiers)(node);
294
+ const isStatic = modifiers !== undefined &&
295
+ modifiers.some((mod) => mod.kind === ts.SyntaxKind.StaticKeyword);
291
296
  return {
292
297
  node,
293
298
  implementation: node,
@@ -8,7 +8,11 @@
8
8
  */
9
9
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
10
  if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
12
16
  }) : (function(o, m, k, k2) {
13
17
  if (k2 === undefined) k2 = k;
14
18
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -5,8 +5,8 @@
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 * as ts from "typescript";
9
- import { ImportManager } from "../../translator";
8
+ import * as ts from 'typescript';
9
+ import { ImportManager } from '../../translator';
10
10
  /**
11
11
  * Adds extra imports in the import manage for this source file, after the existing imports
12
12
  * and before the module body.