static-injector 2.1.0 → 2.2.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 (108) hide show
  1. package/import/commonjs/index.js +403 -211
  2. package/import/{es2015 → es2022}/di/create_injector.js +5 -3
  3. package/import/{es2015 → es2022}/di/forward_ref.js +32 -5
  4. package/import/{es2015 → es2022}/di/injection_token.js +20 -11
  5. package/import/{es2015 → es2022}/di/injector.js +15 -16
  6. package/import/{es2015 → es2022}/di/injector_compatibility.js +27 -13
  7. package/import/{es2015 → es2022}/di/injector_token.js +3 -3
  8. package/import/{es2015 → es2022}/di/interface/defs.js +22 -27
  9. package/import/{es2015 → es2022}/di/interface/injector.js +1 -1
  10. package/import/{es2015 → es2022}/di/interface/provider.js +3 -1
  11. package/import/{es2015 → es2022}/di/null_injector.js +3 -3
  12. package/import/es2022/di/provider_collection.js +104 -0
  13. package/import/{es2015 → es2022}/di/r3_injector.js +71 -37
  14. package/import/es2022/error_details_base_url.js +19 -0
  15. package/import/es2022/errors.js +44 -0
  16. package/import/es2022/interface/type.js +21 -0
  17. package/import/{es2015 → es2022}/render3/definition_factory.js +2 -3
  18. package/import/{es2015 → es2022}/render3/error_code.js +1 -0
  19. package/import/{es2015 → es2022}/render3/errors_di.js +2 -3
  20. package/import/es2022/render3/fields.js +22 -0
  21. package/import/{es2015 → es2022}/render3/instructions/di.js +0 -7
  22. package/import/{es2015 → es2022}/render3/util/stringify_utils.js +5 -5
  23. package/import/{es2015 → es2022}/util/array_utils.js +0 -7
  24. package/import/es2022/util/decorators.js +53 -0
  25. package/import/{es2015 → es2022}/util/empty.js +4 -0
  26. package/import/{es2015 → es2022}/util/stringify.js +5 -5
  27. package/import/{fesm2015 → fesm2022}/index.js +399 -209
  28. package/import/typings/di/create_injector.d.ts +3 -5
  29. package/import/typings/di/forward_ref.d.ts +30 -3
  30. package/import/typings/di/inject_switch.d.ts +1 -1
  31. package/import/typings/di/injectable.d.ts +4 -3
  32. package/import/typings/di/injection_token.d.ts +21 -6
  33. package/import/typings/di/injector.d.ts +19 -3
  34. package/import/typings/di/injector_compatibility.d.ts +12 -5
  35. package/import/typings/di/injector_token.d.ts +2 -2
  36. package/import/typings/di/interface/defs.d.ts +17 -9
  37. package/import/typings/di/interface/injector.d.ts +2 -2
  38. package/import/typings/di/interface/provider.d.ts +64 -4
  39. package/import/typings/di/metadata.d.ts +4 -4
  40. package/import/typings/di/null_injector.d.ts +1 -1
  41. package/import/typings/di/provider_collection.d.ts +53 -11
  42. package/import/typings/di/provider_token.d.ts +2 -2
  43. package/import/typings/di/r3_injector.d.ts +11 -14
  44. package/import/typings/di/scope.d.ts +1 -1
  45. package/import/typings/error_details_base_url.d.ts +19 -0
  46. package/import/typings/errors.d.ts +114 -0
  47. package/import/typings/interface/type.d.ts +45 -0
  48. package/import/typings/render3/errors_di.d.ts +7 -0
  49. package/import/typings/render3/fields.d.ts +9 -0
  50. package/import/typings/render3/instructions/di.d.ts +0 -7
  51. package/import/typings/util/array_utils.d.ts +15 -7
  52. package/import/typings/util/decorators.d.ts +3 -1
  53. package/import/typings/util/empty.d.ts +1 -0
  54. package/package.json +7 -7
  55. package/readme.md +4 -1
  56. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -1
  57. package/transform/compiler/src/injectable_compiler_2.js +31 -16
  58. package/transform/compiler/src/output/output_ast.d.ts +53 -10
  59. package/transform/compiler/src/output/output_ast.js +211 -12
  60. package/transform/compiler/src/parse_util.js +10 -0
  61. package/transform/compiler/src/render3/partial/api.js +1 -1
  62. package/transform/compiler/src/render3/r3_factory.d.ts +0 -8
  63. package/transform/compiler/src/render3/r3_factory.js +5 -4
  64. package/transform/compiler/src/render3/r3_identifiers.js +37 -37
  65. package/transform/compiler/src/render3/view/util.js +1 -3
  66. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +2 -4
  67. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +1 -0
  68. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +1 -1
  69. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +5 -9
  70. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +2 -1
  71. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +12 -8
  72. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +2 -2
  73. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +8 -4
  74. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +1 -1
  75. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +1 -2
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +24 -173
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +2 -51
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +5 -3
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +5 -10
  80. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +5 -23
  81. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -21
  82. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +1 -2
  83. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +7 -0
  84. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +1 -0
  85. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -2
  86. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +1 -0
  87. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +10 -4
  88. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +2 -1
  89. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +20 -16
  90. package/transform/injectable-transform.d.ts +2 -2
  91. package/transform/injectable-transform.js +32 -6
  92. package/import/es2015/di/provider_collection.js +0 -49
  93. package/import/es2015/interface/type.js +0 -8
  94. package/import/es2015/render3/fields.js +0 -11
  95. package/import/es2015/util/decorators.js +0 -30
  96. /package/import/{es2015 → es2022}/di/initializer_token.js +0 -0
  97. /package/import/{es2015 → es2022}/di/inject_switch.js +0 -0
  98. /package/import/{es2015 → es2022}/di/injectable.js +0 -0
  99. /package/import/{es2015 → es2022}/di/injector_marker.js +0 -0
  100. /package/import/{es2015 → es2022}/di/internal_tokens.js +0 -0
  101. /package/import/{es2015 → es2022}/di/metadata.js +0 -0
  102. /package/import/{es2015 → es2022}/di/provider_token.js +0 -0
  103. /package/import/{es2015 → es2022}/di/scope.js +0 -0
  104. /package/import/{es2015 → es2022}/index.js +0 -0
  105. /package/import/{es2015 → es2022}/interface/lifecycle_hooks.js +0 -0
  106. /package/import/{es2015 → es2022}/render3/di.js +0 -0
  107. /package/import/{es2015 → es2022}/util/closure.js +0 -0
  108. /package/import/{es2015 → es2022}/util/property.js +0 -0
@@ -10,19 +10,8 @@ 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.isConcreteDeclaration = exports.KnownDeclaration = exports.ClassMemberKind = exports.isDecoratorIdentifier = exports.Decorator = void 0;
13
+ exports.ClassMemberKind = exports.isDecoratorIdentifier = void 0;
14
14
  const typescript_1 = __importDefault(require("typescript"));
15
- exports.Decorator = {
16
- nodeForError: (decorator) => {
17
- if (decorator.node !== null) {
18
- return decorator.node;
19
- }
20
- else {
21
- // TODO(alxhub): we can't rely on narrowing until TS 3.6 is in g3.
22
- return decorator.synthesizedFor;
23
- }
24
- },
25
- };
26
15
  function isDecoratorIdentifier(exp) {
27
16
  return (typescript_1.default.isIdentifier(exp) ||
28
17
  (typescript_1.default.isPropertyAccessExpression(exp) &&
@@ -40,42 +29,4 @@ var ClassMemberKind;
40
29
  ClassMemberKind[ClassMemberKind["Setter"] = 2] = "Setter";
41
30
  ClassMemberKind[ClassMemberKind["Property"] = 3] = "Property";
42
31
  ClassMemberKind[ClassMemberKind["Method"] = 4] = "Method";
43
- })(ClassMemberKind = exports.ClassMemberKind || (exports.ClassMemberKind = {}));
44
- /**
45
- * Possible declarations of known values, such as built-in objects/functions or TypeScript helpers.
46
- */
47
- var KnownDeclaration;
48
- (function (KnownDeclaration) {
49
- /**
50
- * Indicates the JavaScript global `Object` class.
51
- */
52
- KnownDeclaration[KnownDeclaration["JsGlobalObject"] = 0] = "JsGlobalObject";
53
- /**
54
- * Indicates the `__assign` TypeScript helper function.
55
- */
56
- KnownDeclaration[KnownDeclaration["TsHelperAssign"] = 1] = "TsHelperAssign";
57
- /**
58
- * Indicates the `__spread` TypeScript helper function.
59
- */
60
- KnownDeclaration[KnownDeclaration["TsHelperSpread"] = 2] = "TsHelperSpread";
61
- /**
62
- * Indicates the `__spreadArrays` TypeScript helper function.
63
- */
64
- KnownDeclaration[KnownDeclaration["TsHelperSpreadArrays"] = 3] = "TsHelperSpreadArrays";
65
- /**
66
- * Indicates the `__spreadArray` TypeScript helper function.
67
- */
68
- KnownDeclaration[KnownDeclaration["TsHelperSpreadArray"] = 4] = "TsHelperSpreadArray";
69
- /**
70
- * Indicates the `__read` TypeScript helper function.
71
- */
72
- KnownDeclaration[KnownDeclaration["TsHelperRead"] = 5] = "TsHelperRead";
73
- })(KnownDeclaration = exports.KnownDeclaration || (exports.KnownDeclaration = {}));
74
- /**
75
- * Returns true if the `decl` is a `ConcreteDeclaration` (ie. that its `node` property is a
76
- * `ts.Declaration`).
77
- */
78
- function isConcreteDeclaration(decl) {
79
- return decl.kind === 0 /* DeclarationKind.Concrete */;
80
- }
81
- exports.isConcreteDeclaration = isConcreteDeclaration;
32
+ })(ClassMemberKind || (exports.ClassMemberKind = ClassMemberKind = {}));
@@ -21,9 +21,6 @@ export declare class TypeScriptReflectionHost implements ReflectionHost {
21
21
  hasBaseClass(clazz: ClassDeclaration): boolean;
22
22
  getBaseClassExpression(clazz: ClassDeclaration): ts.Expression | null;
23
23
  getGenericArityOfClass(clazz: ClassDeclaration): number | null;
24
- getDtsDeclaration(_: ClassDeclaration): ts.Declaration | null;
25
- getInternalNameOfClass(clazz: ClassDeclaration): ts.Identifier;
26
- getAdjacentNameOfClass(clazz: ClassDeclaration): ts.Identifier;
27
24
  protected getDirectImportOfIdentifier(id: ts.Identifier): Import | null;
28
25
  /**
29
26
  * Try to get the import info for this identifier as though it is a namespaced import.
@@ -48,3 +45,8 @@ export declare class TypeScriptReflectionHost implements ReflectionHost {
48
45
  private _reflectMember;
49
46
  }
50
47
  export declare function reflectObjectLiteral(node: ts.ObjectLiteralExpression): Map<string, ts.Expression>;
48
+ /**
49
+ * Return the ImportDeclaration for the given `node` if it is either an `ImportSpecifier` or a
50
+ * `NamespaceImport`. If not return `null`.
51
+ */
52
+ export declare function getContainingImportDeclaration(node: ts.Node): ts.ImportDeclaration | 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.reflectObjectLiteral = exports.TypeScriptReflectionHost = void 0;
13
+ exports.getContainingImportDeclaration = exports.reflectObjectLiteral = exports.TypeScriptReflectionHost = void 0;
14
14
  const typescript_1 = __importDefault(require("typescript"));
15
15
  const host_1 = require("./host");
16
16
  const type_to_value_1 = require("./type_to_value");
@@ -19,6 +19,7 @@ const util_1 = require("./util");
19
19
  * reflector.ts implements static reflection of declarations using the TypeScript `ts.TypeChecker`.
20
20
  */
21
21
  class TypeScriptReflectionHost {
22
+ checker;
22
23
  constructor(checker) {
23
24
  this.checker = checker;
24
25
  }
@@ -124,15 +125,6 @@ class TypeScriptReflectionHost {
124
125
  }
125
126
  return clazz.typeParameters !== undefined ? clazz.typeParameters.length : 0;
126
127
  }
127
- getDtsDeclaration(_) {
128
- return null;
129
- }
130
- getInternalNameOfClass(clazz) {
131
- return clazz.name;
132
- }
133
- getAdjacentNameOfClass(clazz) {
134
- return clazz.name;
135
- }
136
128
  getDirectImportOfIdentifier(id) {
137
129
  const symbol = this.checker.getSymbolAtLocation(id);
138
130
  if (symbol === undefined ||
@@ -154,6 +146,7 @@ class TypeScriptReflectionHost {
154
146
  return {
155
147
  from: importDecl.moduleSpecifier.text,
156
148
  name: getExportedName(decl, id),
149
+ node: importDecl,
157
150
  };
158
151
  }
159
152
  /**
@@ -202,6 +195,7 @@ class TypeScriptReflectionHost {
202
195
  return {
203
196
  from: importDeclaration.moduleSpecifier.text,
204
197
  name: id.text,
198
+ node: namespaceDeclaration.parent.parent,
205
199
  };
206
200
  }
207
201
  _reflectDecorator(node) {
@@ -369,6 +363,7 @@ function getContainingImportDeclaration(node) {
369
363
  ? node.parent.parent
370
364
  : null;
371
365
  }
366
+ exports.getContainingImportDeclaration = getContainingImportDeclaration;
372
367
  /**
373
368
  * Compute the name by which the `decl` was exported, not imported.
374
369
  * If no such declaration can be found (e.g. it is a namespace import)
@@ -8,25 +8,6 @@
8
8
  import { Expression, Statement, Type } from 'static-injector/transform/compiler';
9
9
  import ts from 'typescript';
10
10
  import { ClassDeclaration, Decorator } from '../../reflection';
11
- /**
12
- * A set of options which can be passed to a `DecoratorHandler` by a consumer, to tailor the output
13
- * of compilation beyond the decorators themselves.
14
- */
15
- export declare enum HandlerFlags {
16
- /**
17
- * No flags set.
18
- */
19
- NONE = 0,
20
- /**
21
- * Indicates that this decorator is fully inherited from its parent at runtime. In addition to
22
- * normally inherited aspects such as inputs and queries, full inheritance applies to every aspect
23
- * of the component or directive, such as the template function itself.
24
- *
25
- * Its primary effect is to cause the `CopyDefinitionFeature` to be applied to the definition
26
- * being compiled. See that class for more information.
27
- */
28
- FULL_INHERITANCE = 1
29
- }
30
11
  /**
31
12
  * Provides the interface between a decorator compiler from @angular/compiler and the Typescript
32
13
  * compiler/transform.
@@ -64,13 +45,13 @@ export interface DecoratorHandler<D, A, R> {
64
45
  * builds. Any side effects required for compilation (e.g. registration of metadata) should happen
65
46
  * in the `register` phase, which is guaranteed to run even for incremental builds.
66
47
  */
67
- analyze(node: ClassDeclaration, metadata: Readonly<D>, handlerFlags?: HandlerFlags): AnalysisOutput<A>;
48
+ analyze(node: ClassDeclaration, metadata: Readonly<D>): AnalysisOutput<A>;
68
49
  /**
69
50
  * Generate a description of the field which should be added to the class, including any
70
51
  * initialization code to be generated.
71
52
  *
72
- * If the compilation mode is configured as partial, and an implementation of `compilePartial` is
73
- * provided, then this method is not called.
53
+ * If the compilation mode is configured as other than full but an implementation of the
54
+ * corresponding method is not provided, then this method is called as a fallback.
74
55
  */
75
56
  compileFull(node: ClassDeclaration, analysis: Readonly<A>): CompileResult | CompileResult[];
76
57
  }
@@ -109,7 +90,8 @@ export interface AnalysisOutput<A> {
109
90
  */
110
91
  export interface CompileResult {
111
92
  name: string;
112
- initializer: Expression;
93
+ initializer: Expression | null;
113
94
  statements: Statement[];
114
95
  type: Type;
96
+ deferrableImports: Set<ts.ImportDeclaration> | null;
115
97
  }
@@ -7,24 +7,3 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.HandlerFlags = void 0;
11
- /**
12
- * A set of options which can be passed to a `DecoratorHandler` by a consumer, to tailor the output
13
- * of compilation beyond the decorators themselves.
14
- */
15
- var HandlerFlags;
16
- (function (HandlerFlags) {
17
- /**
18
- * No flags set.
19
- */
20
- HandlerFlags[HandlerFlags["NONE"] = 0] = "NONE";
21
- /**
22
- * Indicates that this decorator is fully inherited from its parent at runtime. In addition to
23
- * normally inherited aspects such as inputs and queries, full inheritance applies to every aspect
24
- * of the component or directive, such as the template function itself.
25
- *
26
- * Its primary effect is to cause the `CopyDefinitionFeature` to be applied to the definition
27
- * being compiled. See that class for more information.
28
- */
29
- HandlerFlags[HandlerFlags["FULL_INHERITANCE"] = 1] = "FULL_INHERITANCE";
30
- })(HandlerFlags = exports.HandlerFlags || (exports.HandlerFlags = {}));
@@ -12,7 +12,6 @@ exports.addImports = void 0;
12
12
  * found in the LICENSE file at https://angular.io/license
13
13
  */
14
14
  const typescript_1 = __importDefault(require("typescript"));
15
- const ts_compatibility_1 = require("../../ts_compatibility");
16
15
  /**
17
16
  * Adds extra imports in the import manage for this source file, after the existing imports
18
17
  * and before the module body.
@@ -26,7 +25,7 @@ function addImports(importManager, sf, extraStatements = []) {
26
25
  /* isTypeOnly */ false,
27
26
  /* name */ undefined,
28
27
  /* namedBindings */ typescript_1.default.factory.createNamespaceImport(qualifier));
29
- const decl = (0, ts_compatibility_1.createImportDeclaration)(
28
+ const decl = typescript_1.default.factory.createImportDeclaration(
30
29
  /* modifiers */ undefined,
31
30
  /* importClause */ importClause,
32
31
  /* moduleSpecifier */ typescript_1.default.factory.createStringLiteral(i.specifier));
@@ -93,6 +93,13 @@ export interface AstFactory<TStatement, TExpression> {
93
93
  * @param body a statement (or a block of statements) that are the body of the function.
94
94
  */
95
95
  createFunctionExpression(functionName: string | null, parameters: string[], body: TStatement): TExpression;
96
+ /**
97
+ * Creates an expression that represents a dynamic import
98
+ * (e.g. `import('./some/path')`)
99
+ *
100
+ * @param url the URL that should by used in the dynamic import
101
+ */
102
+ createDynamicImport(url: string): TExpression;
96
103
  /**
97
104
  * Create an identifier.
98
105
  *
@@ -14,6 +14,7 @@ exports.Context = void 0;
14
14
  * It tracks whether we are in the process of outputting a statement or an expression.
15
15
  */
16
16
  class Context {
17
+ isStatement;
17
18
  constructor(isStatement) {
18
19
  this.isStatement = isStatement;
19
20
  }
@@ -14,11 +14,13 @@ exports.ImportManager = void 0;
14
14
  const typescript_1 = __importDefault(require("typescript"));
15
15
  const imports_1 = require("../../imports");
16
16
  class ImportManager {
17
+ rewriter;
18
+ prefix;
19
+ specifierToIdentifier = new Map();
20
+ nextIndex = 0;
17
21
  constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = 'i') {
18
22
  this.rewriter = rewriter;
19
23
  this.prefix = prefix;
20
- this.specifierToIdentifier = new Map();
21
- this.nextIndex = 0;
22
24
  }
23
25
  generateNamespaceImport(moduleName) {
24
26
  if (!this.specifierToIdentifier.has(moduleName)) {
@@ -37,6 +37,7 @@ export declare class ExpressionTranslatorVisitor<TStatement, TExpression> implem
37
37
  visitLiteralExpr(ast: o.LiteralExpr, _context: Context): TExpression;
38
38
  visitExternalExpr(ast: o.ExternalExpr, _context: Context): TExpression;
39
39
  visitConditionalExpr(ast: o.ConditionalExpr, context: Context): TExpression;
40
+ visitDynamicImportExpr(ast: o.DynamicImportExpr, context: any): TExpression;
40
41
  visitNotExpr(ast: o.NotExpr, context: Context): TExpression;
41
42
  visitFunctionExpr(ast: o.FunctionExpr, context: Context): TExpression;
42
43
  visitBinaryOperatorExpr(ast: o.BinaryOperatorExpr, context: Context): TExpression;
@@ -56,6 +56,11 @@ const BINARY_OPERATORS = new Map([
56
56
  [o.BinaryOperator.NullishCoalesce, '??'],
57
57
  ]);
58
58
  class ExpressionTranslatorVisitor {
59
+ factory;
60
+ imports;
61
+ downlevelTaggedTemplates;
62
+ downlevelVariableDeclarations;
63
+ recordWrappedNode;
59
64
  constructor(factory, imports, options) {
60
65
  this.factory = factory;
61
66
  this.imports = imports;
@@ -65,13 +70,12 @@ class ExpressionTranslatorVisitor {
65
70
  this.recordWrappedNode = options.recordWrappedNode || (() => { });
66
71
  }
67
72
  visitDeclareVarStmt(stmt, context) {
68
- var _a;
69
73
  const varType = this.downlevelVariableDeclarations
70
74
  ? 'var'
71
75
  : stmt.hasModifier(o.StmtModifier.Final)
72
76
  ? 'const'
73
77
  : 'let';
74
- return this.attachComments(this.factory.createVariableDeclaration(stmt.name, (_a = stmt.value) === null || _a === void 0 ? void 0 : _a.visitExpression(this, context.withExpressionMode), varType), stmt.leadingComments);
78
+ return this.attachComments(this.factory.createVariableDeclaration(stmt.name, stmt.value?.visitExpression(this, context.withExpressionMode), varType), stmt.leadingComments);
75
79
  }
76
80
  visitDeclareFunctionStmt(stmt, context) {
77
81
  return this.attachComments(this.factory.createFunctionDeclaration(stmt.name, stmt.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(stmt.statements, context.withStatementMode))), stmt.leadingComments);
@@ -173,12 +177,14 @@ class ExpressionTranslatorVisitor {
173
177
  }
174
178
  return this.factory.createConditional(cond, ast.trueCase.visitExpression(this, context), ast.falseCase.visitExpression(this, context));
175
179
  }
180
+ visitDynamicImportExpr(ast, context) {
181
+ return this.factory.createDynamicImport(ast.url);
182
+ }
176
183
  visitNotExpr(ast, context) {
177
184
  return this.factory.createUnaryExpression('!', ast.condition.visitExpression(this, context));
178
185
  }
179
186
  visitFunctionExpr(ast, context) {
180
- var _a;
181
- return this.factory.createFunctionExpression((_a = ast.name) !== null && _a !== void 0 ? _a : null, ast.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(ast.statements, context)));
187
+ return this.factory.createFunctionExpression(ast.name ?? null, ast.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(ast.statements, context)));
182
188
  }
183
189
  visitBinaryOperatorExpr(ast, context) {
184
190
  if (!BINARY_OPERATORS.has(ast.operator)) {
@@ -15,7 +15,7 @@ export declare class TypeScriptAstFactory implements AstFactory<ts.Statement, ts
15
15
  private externalSourceFiles;
16
16
  constructor(annotateForClosureCompiler: boolean);
17
17
  attachComments: typeof attachComments;
18
- createArrayLiteral: (elements?: readonly ts.Expression[], multiLine?: boolean) => ts.ArrayLiteralExpression;
18
+ createArrayLiteral: (elements?: readonly ts.Expression[] | undefined, multiLine?: boolean | undefined) => ts.ArrayLiteralExpression;
19
19
  createAssignment(target: ts.Expression, value: ts.Expression): ts.Expression;
20
20
  createBinaryExpression(leftOperand: ts.Expression, operator: BinaryOperator, rightOperand: ts.Expression): ts.Expression;
21
21
  createBlock(body: ts.Statement[]): ts.Statement;
@@ -23,6 +23,7 @@ export declare class TypeScriptAstFactory implements AstFactory<ts.Statement, ts
23
23
  createConditional(condition: ts.Expression, whenTrue: ts.Expression, whenFalse: ts.Expression): ts.Expression;
24
24
  createElementAccess: (expression: ts.Expression, index: number | ts.Expression) => ts.ElementAccessExpression;
25
25
  createExpressionStatement: (expression: ts.Expression) => ts.ExpressionStatement;
26
+ createDynamicImport(url: string): ts.CallExpression;
26
27
  createFunctionDeclaration(functionName: string, parameters: string[], body: ts.Statement): ts.Statement;
27
28
  createFunctionExpression(functionName: string | null, parameters: string[], body: ts.Statement): ts.Expression;
28
29
  createIdentifier: (text: string) => ts.Identifier;
@@ -12,7 +12,6 @@ exports.attachComments = exports.createTemplateTail = exports.createTemplateMidd
12
12
  * found in the LICENSE file at https://angular.io/license
13
13
  */
14
14
  const typescript_1 = __importDefault(require("typescript"));
15
- const ts_compatibility_1 = require("../../ts_compatibility");
16
15
  /**
17
16
  * Different optimizers use different annotations on a function or method call to indicate its pure
18
17
  * status.
@@ -60,19 +59,13 @@ const VAR_TYPES = {
60
59
  * A TypeScript flavoured implementation of the AstFactory.
61
60
  */
62
61
  class TypeScriptAstFactory {
62
+ annotateForClosureCompiler;
63
+ externalSourceFiles = new Map();
63
64
  constructor(annotateForClosureCompiler) {
64
65
  this.annotateForClosureCompiler = annotateForClosureCompiler;
65
- this.externalSourceFiles = new Map();
66
- this.attachComments = attachComments;
67
- this.createArrayLiteral = typescript_1.default.factory.createArrayLiteralExpression;
68
- this.createElementAccess = typescript_1.default.factory.createElementAccessExpression;
69
- this.createExpressionStatement = typescript_1.default.factory.createExpressionStatement;
70
- this.createIdentifier = typescript_1.default.factory.createIdentifier;
71
- this.createParenthesizedExpression = typescript_1.default.factory.createParenthesizedExpression;
72
- this.createPropertyAccess = typescript_1.default.factory.createPropertyAccessExpression;
73
- this.createThrowStatement = typescript_1.default.factory.createThrowStatement;
74
- this.createTypeOfExpression = typescript_1.default.factory.createTypeOfExpression;
75
66
  }
67
+ attachComments = attachComments;
68
+ createArrayLiteral = typescript_1.default.factory.createArrayLiteralExpression;
76
69
  createAssignment(target, value) {
77
70
  return typescript_1.default.factory.createBinaryExpression(target, typescript_1.default.SyntaxKind.EqualsToken, value);
78
71
  }
@@ -95,20 +88,27 @@ class TypeScriptAstFactory {
95
88
  createConditional(condition, whenTrue, whenFalse) {
96
89
  return typescript_1.default.factory.createConditionalExpression(condition, undefined, whenTrue, undefined, whenFalse);
97
90
  }
91
+ createElementAccess = typescript_1.default.factory.createElementAccessExpression;
92
+ createExpressionStatement = typescript_1.default.factory.createExpressionStatement;
93
+ createDynamicImport(url) {
94
+ return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.ImportKeyword),
95
+ /* type */ undefined, [typescript_1.default.factory.createStringLiteral(url)]);
96
+ }
98
97
  createFunctionDeclaration(functionName, parameters, body) {
99
98
  if (!typescript_1.default.isBlock(body)) {
100
99
  throw new Error(`Invalid syntax, expected a block, but got ${typescript_1.default.SyntaxKind[body.kind]}.`);
101
100
  }
102
- return (0, ts_compatibility_1.createFunctionDeclaration)(undefined, undefined, functionName, undefined, parameters.map((param) => (0, ts_compatibility_1.createParameterDeclaration)(undefined, undefined, param)), undefined, body);
101
+ return typescript_1.default.factory.createFunctionDeclaration(undefined, undefined, functionName, undefined, parameters.map((param) => typescript_1.default.factory.createParameterDeclaration(undefined, undefined, param)), undefined, body);
103
102
  }
104
103
  createFunctionExpression(functionName, parameters, body) {
105
104
  if (!typescript_1.default.isBlock(body)) {
106
105
  throw new Error(`Invalid syntax, expected a block, but got ${typescript_1.default.SyntaxKind[body.kind]}.`);
107
106
  }
108
- return typescript_1.default.factory.createFunctionExpression(undefined, undefined, functionName !== null && functionName !== void 0 ? functionName : undefined, undefined, parameters.map((param) => (0, ts_compatibility_1.createParameterDeclaration)(undefined, undefined, param)), undefined, body);
107
+ return typescript_1.default.factory.createFunctionExpression(undefined, undefined, functionName ?? undefined, undefined, parameters.map((param) => typescript_1.default.factory.createParameterDeclaration(undefined, undefined, param)), undefined, body);
109
108
  }
109
+ createIdentifier = typescript_1.default.factory.createIdentifier;
110
110
  createIfStatement(condition, thenStatement, elseStatement) {
111
- return typescript_1.default.factory.createIfStatement(condition, thenStatement, elseStatement !== null && elseStatement !== void 0 ? elseStatement : undefined);
111
+ return typescript_1.default.factory.createIfStatement(condition, thenStatement, elseStatement ?? undefined);
112
112
  }
113
113
  createLiteral(value) {
114
114
  if (value === undefined) {
@@ -135,8 +135,10 @@ class TypeScriptAstFactory {
135
135
  ? typescript_1.default.factory.createStringLiteral(prop.propertyName)
136
136
  : typescript_1.default.factory.createIdentifier(prop.propertyName), prop.value)));
137
137
  }
138
+ createParenthesizedExpression = typescript_1.default.factory.createParenthesizedExpression;
139
+ createPropertyAccess = typescript_1.default.factory.createPropertyAccessExpression;
138
140
  createReturnStatement(expression) {
139
- return typescript_1.default.factory.createReturnStatement(expression !== null && expression !== void 0 ? expression : undefined);
141
+ return typescript_1.default.factory.createReturnStatement(expression ?? undefined);
140
142
  }
141
143
  createTaggedTemplate(tag, template) {
142
144
  let templateLiteral;
@@ -172,12 +174,14 @@ class TypeScriptAstFactory {
172
174
  }
173
175
  return typescript_1.default.factory.createTaggedTemplateExpression(tag, undefined, templateLiteral);
174
176
  }
177
+ createThrowStatement = typescript_1.default.factory.createThrowStatement;
178
+ createTypeOfExpression = typescript_1.default.factory.createTypeOfExpression;
175
179
  createUnaryExpression(operator, operand) {
176
180
  return typescript_1.default.factory.createPrefixUnaryExpression(UNARY_OPERATORS[operator], operand);
177
181
  }
178
182
  createVariableDeclaration(variableName, initializer, type) {
179
183
  return typescript_1.default.factory.createVariableStatement(undefined, typescript_1.default.factory.createVariableDeclarationList([
180
- typescript_1.default.factory.createVariableDeclaration(variableName, undefined, undefined, initializer !== null && initializer !== void 0 ? initializer : undefined),
184
+ typescript_1.default.factory.createVariableDeclaration(variableName, undefined, undefined, initializer ?? undefined),
181
185
  ], VAR_TYPES[type]));
182
186
  }
183
187
  setSourceMapRange(node, sourceMapRange) {
@@ -4,7 +4,7 @@ import { TypeScriptReflectionHost } from './compiler-cli/src/ngtsc/reflection';
4
4
  export interface InjectableTransformerFactoryOptions {
5
5
  strictCtorDeps?: boolean;
6
6
  }
7
- export declare function createTransformer(program: ts.Program, options?: InjectableTransformerFactoryOptions): (context: ts.TransformationContext) => (sf: ts.SourceFile) => any;
7
+ export declare function createTransformer(program: ts.Program, options?: InjectableTransformerFactoryOptions): (context: ts.TransformationContext) => (sf: ts.SourceFile) => ts.SourceFile;
8
8
  export declare class InjectableTransformerFactory {
9
9
  private program;
10
10
  private options;
@@ -12,7 +12,7 @@ export declare class InjectableTransformerFactory {
12
12
  reflectionHost: TypeScriptReflectionHost;
13
13
  handler: InjectableDecoratorHandler;
14
14
  constructor(program: ts.Program, options?: InjectableTransformerFactoryOptions);
15
- getTransform(): (context: ts.TransformationContext) => (sf: ts.SourceFile) => any;
15
+ getTransform(): (context: ts.TransformationContext) => (sf: ts.SourceFile) => ts.SourceFile;
16
16
  private visit;
17
17
  private transform;
18
18
  private preAnalysis;
@@ -18,12 +18,17 @@ function createTransformer(program, options) {
18
18
  }
19
19
  exports.createTransformer = createTransformer;
20
20
  class InjectableTransformerFactory {
21
+ program;
22
+ options;
23
+ typeChecker;
24
+ reflectionHost;
25
+ handler;
21
26
  constructor(program, options = {}) {
22
27
  this.program = program;
23
28
  this.options = options;
24
29
  this.typeChecker = this.program.getTypeChecker();
25
30
  this.reflectionHost = new reflection_1.TypeScriptReflectionHost(this.typeChecker);
26
- this.handler = new injectable_1.InjectableDecoratorHandler(this.reflectionHost, false, this.options.strictCtorDeps);
31
+ this.handler = new injectable_1.InjectableDecoratorHandler(this.reflectionHost, false, !!this.options.strictCtorDeps, false);
27
32
  }
28
33
  getTransform() {
29
34
  return (context) => this.transform(context);
@@ -34,16 +39,18 @@ class InjectableTransformerFactory {
34
39
  if (result) {
35
40
  const filteredDecorators =
36
41
  // Remove the decorator which triggered this compilation, leaving the others alone.
37
- maybeFilterDecorator(typescript_1.default.getDecorators(node), [result.decorator]);
42
+ maybeFilterDecorator(typescript_1.default.getDecorators(node), [
43
+ result.decorator,
44
+ ]);
38
45
  const nodeModifiers = typescript_1.default.getModifiers(node);
39
46
  let updatedModifiers;
40
- if ((filteredDecorators === null || filteredDecorators === void 0 ? void 0 : filteredDecorators.length) || (nodeModifiers === null || nodeModifiers === void 0 ? void 0 : nodeModifiers.length)) {
47
+ if (filteredDecorators?.length || nodeModifiers?.length) {
41
48
  updatedModifiers = [
42
49
  ...(filteredDecorators || []),
43
50
  ...(nodeModifiers || []),
44
51
  ];
45
52
  }
46
- return typescript_1.default.factory.updateClassDeclaration(node, updatedModifiers, node.name, node.typeParameters, node.heritageClauses, [
53
+ return typescript_1.default.factory.updateClassDeclaration(node, updatedModifiers, node.name, node.typeParameters, node.heritageClauses || [], [
47
54
  ...node.members.map((node) => this._stripAngularDecorators(node)),
48
55
  ...result.members,
49
56
  ]);
@@ -66,7 +73,7 @@ class InjectableTransformerFactory {
66
73
  if (typescript_1.default.isClassDeclaration(node) &&
67
74
  typescript_1.default.getDecorators(node) &&
68
75
  this.reflectionHost.isClass(node)) {
69
- const decorators = this.reflectionHost.getDecoratorsOfDeclaration(node);
76
+ const decorators = this.reflectionHost.getDecoratorsOfDeclaration(node) || [];
70
77
  let result = this.handler.detect(node, decorators);
71
78
  if (!result) {
72
79
  return;
@@ -74,7 +81,10 @@ class InjectableTransformerFactory {
74
81
  let analysisOutput = this.handler.analyze(node, result.metadata);
75
82
  let compileResult = this.handler.compileFull(node, analysisOutput.analysis);
76
83
  let resultNode = this.translate(compileResult, importManager);
77
- classMetadataMap.set(node, Object.assign(Object.assign({}, resultNode), { decorator: result.trigger }));
84
+ classMetadataMap.set(node, {
85
+ ...resultNode,
86
+ decorator: result.trigger,
87
+ });
78
88
  }
79
89
  });
80
90
  // this.sourceFileMetadataMap.set(sf, {
@@ -128,6 +138,22 @@ class InjectableTransformerFactory {
128
138
  // Strip decorators from parameters (probably of the constructor).
129
139
  node = typescript_1.default.factory.updateParameterDeclaration(node, combinedModifiers, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer);
130
140
  }
141
+ else if (typescript_1.default.isMethodDeclaration(node)) {
142
+ // Strip decorators of methods.
143
+ node = typescript_1.default.factory.updateMethodDeclaration(node, combinedModifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body);
144
+ }
145
+ else if (typescript_1.default.isPropertyDeclaration(node)) {
146
+ // Strip decorators of properties.
147
+ node = typescript_1.default.factory.updatePropertyDeclaration(node, combinedModifiers, node.name, node.questionToken, node.type, node.initializer);
148
+ }
149
+ else if (typescript_1.default.isGetAccessor(node)) {
150
+ // Strip decorators of getters.
151
+ node = typescript_1.default.factory.updateGetAccessorDeclaration(node, combinedModifiers, node.name, node.parameters, node.type, node.body);
152
+ }
153
+ else if (typescript_1.default.isSetAccessor(node)) {
154
+ // Strip decorators of setters.
155
+ node = typescript_1.default.factory.updateSetAccessorDeclaration(node, combinedModifiers, node.name, node.parameters, node.body);
156
+ }
131
157
  else if (typescript_1.default.isConstructorDeclaration(node)) {
132
158
  // For constructors, strip decorators of the parameters.
133
159
  const parameters = node.parameters.map((param) => this._stripAngularDecorators(param));
@@ -1,49 +0,0 @@
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 { getClosureSafeProperty } from '../util/property';
9
- import { resolveForwardRef } from './forward_ref';
10
- /**
11
- * The logic visits an `InjectorType`, an `InjectorTypeWithProviders`, or a standalone
12
- * `ComponentType`, and all of its transitive providers and collects providers.
13
- *
14
- * If an `InjectorTypeWithProviders` that declares providers besides the type is specified,
15
- * the function will return "true" to indicate that the providers of the type definition need
16
- * to be processed. This allows us to process providers of injector types after all imports of
17
- * an injector definition are processed. (following View Engine semantics: see FW-1349)
18
- */
19
- export function walkProviderTree(container, providersOut, parents, dedup) {
20
- container = resolveForwardRef(container);
21
- if (!container)
22
- return false;
23
- // The actual type which had the definition. Usually `container`, but may be an unwrapped type
24
- // from `InjectorTypeWithProviders`.
25
- let defType = null;
26
- defType = container;
27
- // Check for multiple imports of the same module
28
- return (defType !== container &&
29
- container.providers !== undefined);
30
- }
31
- export const USE_VALUE = getClosureSafeProperty({
32
- provide: String,
33
- useValue: getClosureSafeProperty,
34
- });
35
- export function isValueProvider(value) {
36
- return value !== null && typeof value == 'object' && USE_VALUE in value;
37
- }
38
- export function isExistingProvider(value) {
39
- return !!(value && value.useExisting);
40
- }
41
- export function isFactoryProvider(value) {
42
- return !!(value && value.useFactory);
43
- }
44
- export function isTypeProvider(value) {
45
- return typeof value === 'function';
46
- }
47
- export function isClassProvider(value) {
48
- return !!value.useClass;
49
- }
@@ -1,8 +0,0 @@
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 {};
@@ -1,11 +0,0 @@
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 { getClosureSafeProperty } from '../util/property';
9
- export const NG_FACTORY_DEF = getClosureSafeProperty({
10
- ɵfac: getClosureSafeProperty,
11
- });
@@ -1,30 +0,0 @@
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 { noSideEffects } from './closure';
9
- function makeMetadataCtor(props) {
10
- return function ctor(...args) {
11
- if (props) {
12
- const values = props(...args);
13
- for (const propName in values) {
14
- this[propName] = values[propName];
15
- }
16
- }
17
- };
18
- }
19
- export function makeParamDecorator(name, props) {
20
- return noSideEffects(() => {
21
- const metaCtor = makeMetadataCtor(props);
22
- function ParamDecoratorFactory(...args) {
23
- if (this instanceof ParamDecoratorFactory) {
24
- metaCtor.apply(this, args);
25
- return this;
26
- }
27
- }
28
- return ParamDecoratorFactory;
29
- });
30
- }
File without changes