static-injector 4.0.2 → 5.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 (179) hide show
  1. package/{import/commonjs → commonjs}/index.js +29 -197
  2. package/{import/es2022 → es2022}/di/interface/defs.js +5 -1
  3. package/{import/es2022 → es2022}/index.js +0 -1
  4. package/{transform/compiler/index.d.ts → es2022/interface/lifecycle_hooks.js} +1 -1
  5. package/{transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js → es2022/render3/definition_factory.js} +3 -2
  6. package/es2022/util/decorators.js +31 -0
  7. package/{import/fesm2022 → fesm2022}/index.js +30 -196
  8. package/package.json +17 -14
  9. package/readme.md +35 -13
  10. package/{import/typings → typings}/di/injectable.d.ts +0 -7
  11. package/{import/typings → typings}/index.d.ts +0 -1
  12. package/import/es2022/di/injectable.js +0 -14
  13. package/import/es2022/error_details_base_url.js +0 -19
  14. package/import/es2022/render3/definition_factory.js +0 -14
  15. package/import/es2022/render3/di.js +0 -49
  16. package/import/es2022/render3/error_code.js +0 -30
  17. package/import/es2022/util/array_utils.js +0 -17
  18. package/import/es2022/util/decorators.js +0 -53
  19. package/import/typings/error_details_base_url.d.ts +0 -19
  20. package/import/typings/render3/di.d.ts +0 -12
  21. package/import/typings/render3/error_code.d.ts +0 -24
  22. package/import/typings/util/array_utils.d.ts +0 -25
  23. package/transform/compiler/compiler.d.ts +0 -8
  24. package/transform/compiler/compiler.js +0 -28
  25. package/transform/compiler/index.js +0 -28
  26. package/transform/compiler/public_api.d.ts +0 -13
  27. package/transform/compiler/public_api.js +0 -30
  28. package/transform/compiler/src/compiler.d.ts +0 -5
  29. package/transform/compiler/src/compiler.js +0 -21
  30. package/transform/compiler/src/core.d.ts +0 -25
  31. package/transform/compiler/src/core.js +0 -22
  32. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -23
  33. package/transform/compiler/src/injectable_compiler_2.js +0 -171
  34. package/transform/compiler/src/output/output_ast.d.ts +0 -512
  35. package/transform/compiler/src/output/output_ast.js +0 -1109
  36. package/transform/compiler/src/parse_util.d.ts +0 -50
  37. package/transform/compiler/src/parse_util.js +0 -71
  38. package/transform/compiler/src/render3/partial/api.d.ts +0 -171
  39. package/transform/compiler/src/render3/partial/api.js +0 -18
  40. package/transform/compiler/src/render3/r3_factory.d.ts +0 -82
  41. package/transform/compiler/src/render3/r3_factory.js +0 -225
  42. package/transform/compiler/src/render3/r3_identifiers.d.ts +0 -20
  43. package/transform/compiler/src/render3/r3_identifiers.js +0 -55
  44. package/transform/compiler/src/render3/util.d.ts +0 -85
  45. package/transform/compiler/src/render3/util.js +0 -82
  46. package/transform/compiler/src/render3/view/util.d.ts +0 -24
  47. package/transform/compiler/src/render3/view/util.js +0 -59
  48. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +0 -3
  49. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +0 -19
  50. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +0 -37
  51. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +0 -195
  52. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.d.ts +0 -11
  53. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +0 -22
  54. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +0 -64
  55. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +0 -189
  56. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +0 -43
  57. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +0 -277
  58. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +0 -24
  59. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +0 -84
  60. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +0 -188
  61. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +0 -206
  62. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +0 -2
  63. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +0 -18
  64. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +0 -1
  65. package/transform/compiler-cli/src/ngtsc/imports/index.js +0 -17
  66. package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +0 -36
  67. package/transform/compiler-cli/src/ngtsc/imports/src/core.js +0 -25
  68. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +0 -19
  69. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +0 -27
  70. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +0 -3
  71. package/transform/compiler-cli/src/ngtsc/reflection/index.js +0 -19
  72. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +0 -522
  73. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +0 -34
  74. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +0 -25
  75. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +0 -271
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +0 -53
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +0 -393
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +0 -12
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +0 -29
  80. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +0 -2
  81. package/transform/compiler-cli/src/ngtsc/transform/index.js +0 -18
  82. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +0 -115
  83. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -29
  84. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +0 -15
  85. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +0 -79
  86. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +0 -5
  87. package/transform/compiler-cli/src/ngtsc/translator/index.js +0 -21
  88. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +0 -289
  89. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +0 -27
  90. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +0 -9
  91. package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +0 -18
  92. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +0 -28
  93. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +0 -47
  94. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +0 -66
  95. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -56
  96. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +0 -270
  97. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.d.ts +0 -12
  98. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.js +0 -27
  99. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +0 -53
  100. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +0 -250
  101. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +0 -13
  102. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +0 -21
  103. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +0 -8
  104. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +0 -24
  105. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +0 -45
  106. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +0 -86
  107. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +0 -4
  108. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +0 -16
  109. package/transform/index.d.ts +0 -1
  110. package/transform/index.js +0 -17
  111. package/transform/injectable-transform.d.ts +0 -41
  112. package/transform/injectable-transform.js +0 -245
  113. package/transform/node-Iteration.d.ts +0 -2
  114. package/transform/node-Iteration.js +0 -12
  115. /package/{import/es2022 → es2022}/di/create_injector.js +0 -0
  116. /package/{import/es2022 → es2022}/di/forward_ref.js +0 -0
  117. /package/{import/es2022 → es2022}/di/index.js +0 -0
  118. /package/{import/es2022 → es2022}/di/initializer_token.js +0 -0
  119. /package/{import/es2022 → es2022}/di/inject_switch.js +0 -0
  120. /package/{import/es2022/di/injector_marker.js → es2022/di/injectable.js} +0 -0
  121. /package/{import/es2022 → es2022}/di/injection_token.js +0 -0
  122. /package/{import/es2022 → es2022}/di/injector.js +0 -0
  123. /package/{import/es2022 → es2022}/di/injector_compatibility.js +0 -0
  124. /package/{import/es2022/di/provider_token.js → es2022/di/injector_marker.js} +0 -0
  125. /package/{import/es2022 → es2022}/di/injector_token.js +0 -0
  126. /package/{import/es2022 → es2022}/di/interface/injector.js +0 -0
  127. /package/{import/es2022 → es2022}/di/interface/provider.js +0 -0
  128. /package/{import/es2022 → es2022}/di/internal_tokens.js +0 -0
  129. /package/{import/es2022 → es2022}/di/metadata.js +0 -0
  130. /package/{import/es2022 → es2022}/di/null_injector.js +0 -0
  131. /package/{import/es2022 → es2022}/di/provider_collection.js +0 -0
  132. /package/{import/es2022/interface/lifecycle_hooks.js → es2022/di/provider_token.js} +0 -0
  133. /package/{import/es2022 → es2022}/di/r3_injector.js +0 -0
  134. /package/{import/es2022 → es2022}/di/scope.js +0 -0
  135. /package/{import/es2022 → es2022}/di.js +0 -0
  136. /package/{import/es2022 → es2022}/errors.js +0 -0
  137. /package/{import/es2022 → es2022}/interface/type.js +0 -0
  138. /package/{import/es2022 → es2022}/render3/errors_di.js +0 -0
  139. /package/{import/es2022 → es2022}/render3/fields.js +0 -0
  140. /package/{import/es2022 → es2022}/render3/instructions/di.js +0 -0
  141. /package/{import/es2022 → es2022}/render3/util/stringify_utils.js +0 -0
  142. /package/{import/es2022 → es2022}/util/closure.js +0 -0
  143. /package/{import/es2022 → es2022}/util/empty.js +0 -0
  144. /package/{import/es2022 → es2022}/util/property.js +0 -0
  145. /package/{import/es2022 → es2022}/util/stringify.js +0 -0
  146. /package/{import/typings → typings}/di/create_injector.d.ts +0 -0
  147. /package/{import/typings → typings}/di/forward_ref.d.ts +0 -0
  148. /package/{import/typings → typings}/di/index.d.ts +0 -0
  149. /package/{import/typings → typings}/di/initializer_token.d.ts +0 -0
  150. /package/{import/typings → typings}/di/inject_switch.d.ts +0 -0
  151. /package/{import/typings → typings}/di/injection_token.d.ts +0 -0
  152. /package/{import/typings → typings}/di/injector.d.ts +0 -0
  153. /package/{import/typings → typings}/di/injector_compatibility.d.ts +0 -0
  154. /package/{import/typings → typings}/di/injector_marker.d.ts +0 -0
  155. /package/{import/typings → typings}/di/injector_token.d.ts +0 -0
  156. /package/{import/typings → typings}/di/interface/defs.d.ts +0 -0
  157. /package/{import/typings → typings}/di/interface/injector.d.ts +0 -0
  158. /package/{import/typings → typings}/di/interface/provider.d.ts +0 -0
  159. /package/{import/typings → typings}/di/internal_tokens.d.ts +0 -0
  160. /package/{import/typings → typings}/di/metadata.d.ts +0 -0
  161. /package/{import/typings → typings}/di/null_injector.d.ts +0 -0
  162. /package/{import/typings → typings}/di/provider_collection.d.ts +0 -0
  163. /package/{import/typings → typings}/di/provider_token.d.ts +0 -0
  164. /package/{import/typings → typings}/di/r3_injector.d.ts +0 -0
  165. /package/{import/typings → typings}/di/scope.d.ts +0 -0
  166. /package/{import/typings → typings}/di.d.ts +0 -0
  167. /package/{import/typings → typings}/errors.d.ts +0 -0
  168. /package/{import/typings → typings}/interface/lifecycle_hooks.d.ts +0 -0
  169. /package/{import/typings → typings}/interface/type.d.ts +0 -0
  170. /package/{import/typings → typings}/render3/definition_factory.d.ts +0 -0
  171. /package/{import/typings → typings}/render3/errors_di.d.ts +0 -0
  172. /package/{import/typings → typings}/render3/fields.d.ts +0 -0
  173. /package/{import/typings → typings}/render3/instructions/di.d.ts +0 -0
  174. /package/{import/typings → typings}/render3/util/stringify_utils.d.ts +0 -0
  175. /package/{import/typings → typings}/util/closure.d.ts +0 -0
  176. /package/{import/typings → typings}/util/decorators.d.ts +0 -0
  177. /package/{import/typings → typings}/util/empty.d.ts +0 -0
  178. /package/{import/typings → typings}/util/property.d.ts +0 -0
  179. /package/{import/typings → typings}/util/stringify.d.ts +0 -0
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.addImports = void 0;
7
- /**
8
- * @license
9
- * Copyright Google LLC All Rights Reserved.
10
- *
11
- * Use of this source code is governed by an MIT-style license that can be
12
- * found in the LICENSE file at https://angular.io/license
13
- */
14
- const typescript_1 = __importDefault(require("typescript"));
15
- /**
16
- * Adds extra imports in the import manage for this source file, after the existing imports
17
- * and before the module body.
18
- * Can optionally add extra statements (e.g. new constants) before the body as well.
19
- */
20
- function addImports(factory = typescript_1.default.factory, importManager, sf, extraStatements = []) {
21
- // Generate the import statements to prepend.
22
- const addedImports = importManager
23
- .getAllImports(sf.fileName)
24
- .map((i) => i.qualifier !== null
25
- ? createNamespaceImportDecl(i, factory)
26
- : createSideEffectImportDecl(i, factory));
27
- // Filter out the existing imports and the source file body. All new statements
28
- // will be inserted between them.
29
- const existingImports = sf.statements.filter((stmt) => isImportStatement(stmt));
30
- const body = sf.statements.filter((stmt) => !isImportStatement(stmt));
31
- // Prepend imports if needed.
32
- if (addedImports.length > 0) {
33
- // If we prepend imports, we also prepend NotEmittedStatement to use it as an anchor
34
- // for @fileoverview Closure annotation. If there is no @fileoverview annotations, this
35
- // statement would be a noop.
36
- const fileoverviewAnchorStmt = factory.createNotEmittedStatement(sf);
37
- return factory.updateSourceFile(sf, factory.createNodeArray([
38
- fileoverviewAnchorStmt,
39
- ...existingImports,
40
- ...addedImports,
41
- ...extraStatements,
42
- ...body,
43
- ]));
44
- }
45
- return sf;
46
- }
47
- exports.addImports = addImports;
48
- function createNamespaceImportDecl(i, factory) {
49
- const qualifier = factory.createIdentifier(i.qualifier.text);
50
- const importClause = factory.createImportClause(
51
- /* isTypeOnly */ false,
52
- /* name */ undefined,
53
- /* namedBindings */ factory.createNamespaceImport(qualifier));
54
- const decl = factory.createImportDeclaration(
55
- /* modifiers */ undefined,
56
- /* importClause */ importClause,
57
- /* moduleSpecifier */ factory.createStringLiteral(i.specifier));
58
- // Set the qualifier's original TS node to the `ts.ImportDeclaration`. This allows downstream
59
- // transforms such as tsickle to properly process references to this import.
60
- //
61
- // This operation is load-bearing in g3 as some imported modules contain special metadata
62
- // generated by clutz, which tsickle uses to transform imports and references to those imports.
63
- //
64
- // TODO(alxhub): add a test for this when tsickle is updated externally to depend on this
65
- // behavior.
66
- typescript_1.default.setOriginalNode(i.qualifier, decl);
67
- return decl;
68
- }
69
- function createSideEffectImportDecl(i, factory) {
70
- return factory.createImportDeclaration(
71
- /* modifiers */ undefined,
72
- /* importClause */ undefined,
73
- /* moduleSpecifier */ typescript_1.default.factory.createStringLiteral(i.specifier));
74
- }
75
- function isImportStatement(stmt) {
76
- return (typescript_1.default.isImportDeclaration(stmt) ||
77
- typescript_1.default.isImportEqualsDeclaration(stmt) ||
78
- typescript_1.default.isNamespaceImport(stmt));
79
- }
@@ -1,5 +0,0 @@
1
- export * from './src/context';
2
- export * from './src/translator';
3
- export * from './src/typescript_ast_factory';
4
- export * from './src/typescript_translator';
5
- export * from './src/import_manager';
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./src/context"), exports);
18
- __exportStar(require("./src/translator"), exports);
19
- __exportStar(require("./src/typescript_ast_factory"), exports);
20
- __exportStar(require("./src/typescript_translator"), exports);
21
- __exportStar(require("./src/import_manager"), exports);
@@ -1,289 +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
- /**
9
- * Used to create transpiler specific AST nodes from Angular Output AST nodes in an abstract way.
10
- *
11
- * Note that the `AstFactory` makes no assumptions about the target language being generated.
12
- * It is up to the caller to do this - e.g. only call `createTaggedTemplate()` or pass `let`|`const`
13
- * to `createVariableDeclaration()` if the final JS will allow it.
14
- */
15
- export interface AstFactory<TStatement, TExpression> {
16
- /**
17
- * Attach the `leadingComments` to the given `statement` node.
18
- *
19
- * @param statement the statement where the comments are to be attached.
20
- * @param leadingComments the comments to attach.
21
- */
22
- attachComments(statement: TStatement, leadingComments: LeadingComment[]): void;
23
- /**
24
- * Create a literal array expression (e.g. `[expr1, expr2]`).
25
- *
26
- * @param elements a collection of the expressions to appear in each array slot.
27
- */
28
- createArrayLiteral(elements: TExpression[]): TExpression;
29
- /**
30
- * Create an assignment expression (e.g. `lhsExpr = rhsExpr`).
31
- *
32
- * @param target an expression that evaluates to the left side of the assignment.
33
- * @param value an expression that evaluates to the right side of the assignment.
34
- */
35
- createAssignment(target: TExpression, value: TExpression): TExpression;
36
- /**
37
- * Create a binary expression (e.g. `lhs && rhs`).
38
- *
39
- * @param leftOperand an expression that will appear on the left of the operator.
40
- * @param operator the binary operator that will be applied.
41
- * @param rightOperand an expression that will appear on the right of the operator.
42
- */
43
- createBinaryExpression(leftOperand: TExpression, operator: BinaryOperator, rightOperand: TExpression): TExpression;
44
- /**
45
- * Create a block of statements (e.g. `{ stmt1; stmt2; }`).
46
- *
47
- * @param body an array of statements to be wrapped in a block.
48
- */
49
- createBlock(body: TStatement[]): TStatement;
50
- /**
51
- * Create an expression that is calling the `callee` with the given `args`.
52
- *
53
- * @param callee an expression that evaluates to a function to be called.
54
- * @param args the arguments to be passed to the call.
55
- * @param pure whether to mark the call as pure (having no side-effects).
56
- */
57
- createCallExpression(callee: TExpression, args: TExpression[], pure: boolean): TExpression;
58
- /**
59
- * Create a ternary expression (e.g. `testExpr ? trueExpr : falseExpr`).
60
- *
61
- * @param condition an expression that will be tested for truthiness.
62
- * @param thenExpression an expression that is executed if `condition` is truthy.
63
- * @param elseExpression an expression that is executed if `condition` is falsy.
64
- */
65
- createConditional(condition: TExpression, thenExpression: TExpression, elseExpression: TExpression): TExpression;
66
- /**
67
- * Create an element access (e.g. `obj[expr]`).
68
- *
69
- * @param expression an expression that evaluates to the object to be accessed.
70
- * @param element an expression that evaluates to the element on the object.
71
- */
72
- createElementAccess(expression: TExpression, element: TExpression): TExpression;
73
- /**
74
- * Create a statement that is simply executing the given `expression` (e.g. `x = 10;`).
75
- *
76
- * @param expression the expression to be converted to a statement.
77
- */
78
- createExpressionStatement(expression: TExpression): TStatement;
79
- /**
80
- * Create a statement that declares a function (e.g. `function foo(param1, param2) { stmt; }`).
81
- *
82
- * @param functionName the name of the function.
83
- * @param parameters the names of the function's parameters.
84
- * @param body a statement (or a block of statements) that are the body of the function.
85
- */
86
- createFunctionDeclaration(functionName: string, parameters: string[], body: TStatement): TStatement;
87
- /**
88
- * Create an expression that represents a function
89
- * (e.g. `function foo(param1, param2) { stmt; }`).
90
- *
91
- * @param functionName the name of the function.
92
- * @param parameters the names of the function's parameters.
93
- * @param body a statement (or a block of statements) that are the body of the function.
94
- */
95
- createFunctionExpression(functionName: string | null, parameters: string[], body: TStatement): TExpression;
96
- /**
97
- * Create an expression that represents an arrow function
98
- * (e.g. `(param1, param2) => body`).
99
- *
100
- * @param parameters the names of the function's parameters.
101
- * @param body an expression or block of statements that are the body of the function.
102
- */
103
- createArrowFunctionExpression(parameters: string[], body: TExpression | TStatement): TExpression;
104
- /**
105
- * Creates an expression that represents a dynamic import
106
- * (e.g. `import('./some/path')`)
107
- *
108
- * @param url the URL that should by used in the dynamic import
109
- */
110
- createDynamicImport(url: string): TExpression;
111
- /**
112
- * Create an identifier.
113
- *
114
- * @param name the name of the identifier.
115
- */
116
- createIdentifier(name: string): TExpression;
117
- /**
118
- * Create an if statement (e.g. `if (testExpr) { trueStmt; } else { falseStmt; }`).
119
- *
120
- * @param condition an expression that will be tested for truthiness.
121
- * @param thenStatement a statement (or block of statements) that is executed if `condition` is
122
- * truthy.
123
- * @param elseStatement a statement (or block of statements) that is executed if `condition` is
124
- * falsy.
125
- */
126
- createIfStatement(condition: TExpression, thenStatement: TStatement, elseStatement: TStatement | null): TStatement;
127
- /**
128
- * Create a simple literal (e.g. `"string"`, `123`, `false`, etc).
129
- *
130
- * @param value the value of the literal.
131
- */
132
- createLiteral(value: string | number | boolean | null | undefined): TExpression;
133
- /**
134
- * Create an expression that is instantiating the `expression` as a class.
135
- *
136
- * @param expression an expression that evaluates to a constructor to be instantiated.
137
- * @param args the arguments to be passed to the constructor.
138
- */
139
- createNewExpression(expression: TExpression, args: TExpression[]): TExpression;
140
- /**
141
- * Create a literal object expression (e.g. `{ prop1: expr1, prop2: expr2 }`).
142
- *
143
- * @param properties the properties (key and value) to appear in the object.
144
- */
145
- createObjectLiteral(properties: ObjectLiteralProperty<TExpression>[]): TExpression;
146
- /**
147
- * Wrap an expression in parentheses.
148
- *
149
- * @param expression the expression to wrap in parentheses.
150
- */
151
- createParenthesizedExpression(expression: TExpression): TExpression;
152
- /**
153
- * Create a property access (e.g. `obj.prop`).
154
- *
155
- * @param expression an expression that evaluates to the object to be accessed.
156
- * @param propertyName the name of the property to access.
157
- */
158
- createPropertyAccess(expression: TExpression, propertyName: string): TExpression;
159
- /**
160
- * Create a return statement (e.g `return expr;`).
161
- *
162
- * @param expression the expression to be returned.
163
- */
164
- createReturnStatement(expression: TExpression | null): TStatement;
165
- /**
166
- * Create a tagged template literal string. E.g.
167
- *
168
- * ```
169
- * tag`str1${expr1}str2${expr2}str3`
170
- * ```
171
- *
172
- * @param tag an expression that is applied as a tag handler for this template string.
173
- * @param template the collection of strings and expressions that constitute an interpolated
174
- * template literal.
175
- */
176
- createTaggedTemplate(tag: TExpression, template: TemplateLiteral<TExpression>): TExpression;
177
- /**
178
- * Create a throw statement (e.g. `throw expr;`).
179
- *
180
- * @param expression the expression to be thrown.
181
- */
182
- createThrowStatement(expression: TExpression): TStatement;
183
- /**
184
- * Create an expression that extracts the type of an expression (e.g. `typeof expr`).
185
- *
186
- * @param expression the expression whose type we want.
187
- */
188
- createTypeOfExpression(expression: TExpression): TExpression;
189
- /**
190
- * Prefix the `operand` with the given `operator` (e.g. `-expr`).
191
- *
192
- * @param operator the text of the operator to apply (e.g. `+`, `-` or `!`).
193
- * @param operand the expression that the operator applies to.
194
- */
195
- createUnaryExpression(operator: UnaryOperator, operand: TExpression): TExpression;
196
- /**
197
- * Create an expression that declares a new variable, possibly initialized to `initializer`.
198
- *
199
- * @param variableName the name of the variable.
200
- * @param initializer if not `null` then this expression is assigned to the declared variable.
201
- * @param type whether this variable should be declared as `var`, `let` or `const`.
202
- */
203
- createVariableDeclaration(variableName: string, initializer: TExpression | null, type: VariableDeclarationType): TStatement;
204
- /**
205
- * Attach a source map range to the given node.
206
- *
207
- * @param node the node to which the range should be attached.
208
- * @param sourceMapRange the range to attach to the node, or null if there is no range to attach.
209
- * @returns the `node` with the `sourceMapRange` attached.
210
- */
211
- setSourceMapRange<T extends TStatement | TExpression>(node: T, sourceMapRange: SourceMapRange | null): T;
212
- }
213
- /**
214
- * The type of a variable declaration.
215
- */
216
- export type VariableDeclarationType = 'const' | 'let' | 'var';
217
- /**
218
- * The unary operators supported by the `AstFactory`.
219
- */
220
- export type UnaryOperator = '+' | '-' | '!';
221
- /**
222
- * The binary operators supported by the `AstFactory`.
223
- */
224
- export type BinaryOperator = '&&' | '>' | '>=' | '&' | '|' | '/' | '==' | '===' | '<' | '<=' | '-' | '%' | '*' | '!=' | '!==' | '||' | '+' | '??';
225
- /**
226
- * The original location of the start or end of a node created by the `AstFactory`.
227
- */
228
- export interface SourceMapLocation {
229
- /** 0-based character position of the location in the original source file. */
230
- offset: number;
231
- /** 0-based line index of the location in the original source file. */
232
- line: number;
233
- /** 0-based column position of the location in the original source file. */
234
- column: number;
235
- }
236
- /**
237
- * The original range of a node created by the `AstFactory`.
238
- */
239
- export interface SourceMapRange {
240
- url: string;
241
- content: string;
242
- start: SourceMapLocation;
243
- end: SourceMapLocation;
244
- }
245
- /**
246
- * Information used by the `AstFactory` to create a property on an object literal expression.
247
- */
248
- export interface ObjectLiteralProperty<TExpression> {
249
- propertyName: string;
250
- value: TExpression;
251
- /**
252
- * Whether the `propertyName` should be enclosed in quotes.
253
- */
254
- quoted: boolean;
255
- }
256
- /**
257
- * Information used by the `AstFactory` to create a template literal string (i.e. a back-ticked
258
- * string with interpolations).
259
- */
260
- export interface TemplateLiteral<TExpression> {
261
- /**
262
- * A collection of the static string pieces of the interpolated template literal string.
263
- */
264
- elements: TemplateElement[];
265
- /**
266
- * A collection of the interpolated expressions that are interleaved between the elements.
267
- */
268
- expressions: TExpression[];
269
- }
270
- /**
271
- * Information about a static string piece of an interpolated template literal string.
272
- */
273
- export interface TemplateElement {
274
- /** The raw string as it was found in the original source code. */
275
- raw: string;
276
- /** The parsed string, with escape codes etc processed. */
277
- cooked: string;
278
- /** The original location of this piece of the template literal string. */
279
- range: SourceMapRange | null;
280
- }
281
- /**
282
- * Information used by the `AstFactory` to prepend a comment to a statement that was created by the
283
- * `AstFactory`.
284
- */
285
- export interface LeadingComment {
286
- toString(): string;
287
- multiline: boolean;
288
- trailingNewline: boolean;
289
- }
@@ -1,27 +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
- /**
9
- * The symbol name and import namespace of an imported symbol,
10
- * which has been registered through the ImportGenerator.
11
- */
12
- export interface NamedImport<TExpression> {
13
- /** The import namespace containing this imported symbol. */
14
- moduleImport: TExpression | null;
15
- /** The (possibly rewritten) name of the imported symbol. */
16
- symbol: string;
17
- }
18
- /**
19
- * Generate import information based on the context of the code being generated.
20
- *
21
- * Implementations of these methods return a specific identifier that corresponds to the imported
22
- * module.
23
- */
24
- export interface ImportGenerator<TExpression> {
25
- generateNamespaceImport(moduleName: string): TExpression;
26
- generateNamedImport(moduleName: string, originalSymbol: string): NamedImport<TExpression>;
27
- }
@@ -1,9 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,18 +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
- /**
9
- * The current context of a translator visitor as it traverses the AST tree.
10
- *
11
- * It tracks whether we are in the process of outputting a statement or an expression.
12
- */
13
- export declare class Context {
14
- readonly isStatement: boolean;
15
- constructor(isStatement: boolean);
16
- get withExpressionMode(): Context;
17
- get withStatementMode(): Context;
18
- }
@@ -1,28 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Context = void 0;
11
- /**
12
- * The current context of a translator visitor as it traverses the AST tree.
13
- *
14
- * It tracks whether we are in the process of outputting a statement or an expression.
15
- */
16
- class Context {
17
- isStatement;
18
- constructor(isStatement) {
19
- this.isStatement = isStatement;
20
- }
21
- get withExpressionMode() {
22
- return this.isStatement ? new Context(false) : this;
23
- }
24
- get withStatementMode() {
25
- return !this.isStatement ? new Context(true) : this;
26
- }
27
- }
28
- exports.Context = Context;
@@ -1,47 +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 ts from 'typescript';
9
- import { ImportRewriter } from '../../imports';
10
- import { ImportGenerator, NamedImport } from './api/import_generator';
11
- /**
12
- * Information about a namespace import that has been added to a module.
13
- */
14
- export interface NamespaceImport {
15
- /** The name of the module that has been imported. */
16
- specifier: string;
17
- /** The `ts.Identifier` by which the imported module is known. */
18
- qualifier: ts.Identifier;
19
- }
20
- /**
21
- * Information about a side effect import that has been added to a module.
22
- */
23
- export interface SideEffectImport {
24
- /** The name of the module that has been imported. */
25
- specifier: string;
26
- /**
27
- * The qualifier of a side effect import is always non-existent, and that can be used to check
28
- * whether the import is side effect or not.
29
- */
30
- qualifier: null;
31
- }
32
- /**
33
- * Information about an import that has been added to a module.
34
- */
35
- export type Import = NamespaceImport | SideEffectImport;
36
- export declare class ImportManager implements ImportGenerator<ts.Identifier> {
37
- protected rewriter: ImportRewriter;
38
- private prefix;
39
- private factory;
40
- private specifierToIdentifier;
41
- private nextIndex;
42
- constructor(rewriter?: ImportRewriter, prefix?: string, factory?: ts.NodeFactory);
43
- generateNamespaceImport(moduleName: string): ts.Identifier;
44
- generateNamedImport(moduleName: string, originalSymbol: string): NamedImport<ts.Identifier>;
45
- generateSideEffectImport(moduleName: string): void;
46
- getAllImports(contextPath: string): Import[];
47
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ImportManager = void 0;
7
- /**
8
- * @license
9
- * Copyright Google LLC All Rights Reserved.
10
- *
11
- * Use of this source code is governed by an MIT-style license that can be
12
- * found in the LICENSE file at https://angular.io/license
13
- */
14
- const typescript_1 = __importDefault(require("typescript"));
15
- const imports_1 = require("../../imports");
16
- class ImportManager {
17
- rewriter;
18
- prefix;
19
- factory;
20
- specifierToIdentifier = new Map();
21
- nextIndex = 0;
22
- constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = 'i', factory = typescript_1.default.factory) {
23
- this.rewriter = rewriter;
24
- this.prefix = prefix;
25
- this.factory = factory;
26
- }
27
- generateNamespaceImport(moduleName) {
28
- // The case `specifierToIdentifier.get(moduleName) === null` is also considered to overwrite the
29
- // side effect import since namedspace import is enough.
30
- if (!this.specifierToIdentifier.has(moduleName) ||
31
- this.specifierToIdentifier.get(moduleName) === null) {
32
- this.specifierToIdentifier.set(moduleName, this.factory.createIdentifier(`${this.prefix}${this.nextIndex++}`));
33
- }
34
- return this.specifierToIdentifier.get(moduleName);
35
- }
36
- generateNamedImport(moduleName, originalSymbol) {
37
- // First, rewrite the symbol name.
38
- const symbol = this.rewriter.rewriteSymbol(originalSymbol, moduleName);
39
- // Ask the rewriter if this symbol should be imported at all. If not, it can be referenced
40
- // directly (moduleImport: null).
41
- if (!this.rewriter.shouldImportSymbol(symbol, moduleName)) {
42
- // The symbol should be referenced directly.
43
- return { moduleImport: null, symbol };
44
- }
45
- // If not, this symbol will be imported using a generated namespace import.
46
- const moduleImport = this.generateNamespaceImport(moduleName);
47
- return { moduleImport, symbol };
48
- }
49
- generateSideEffectImport(moduleName) {
50
- if (!this.specifierToIdentifier.has(moduleName)) {
51
- this.specifierToIdentifier.set(moduleName, null);
52
- }
53
- }
54
- getAllImports(contextPath) {
55
- const imports = [];
56
- for (const [originalSpecifier, qualifier] of this.specifierToIdentifier) {
57
- const specifier = this.rewriter.rewriteSpecifier(originalSpecifier, contextPath);
58
- imports.push({
59
- specifier,
60
- qualifier,
61
- });
62
- }
63
- return imports;
64
- }
65
- }
66
- exports.ImportManager = ImportManager;
@@ -1,56 +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 * as o from 'static-injector/transform/compiler';
9
- import { AstFactory } from './api/ast_factory';
10
- import { ImportGenerator } from './api/import_generator';
11
- import { Context } from './context';
12
- export type RecordWrappedNodeFn<TExpression> = (node: o.WrappedNodeExpr<TExpression>) => void;
13
- export interface TranslatorOptions<TExpression> {
14
- downlevelTaggedTemplates?: boolean;
15
- downlevelVariableDeclarations?: boolean;
16
- recordWrappedNode?: RecordWrappedNodeFn<TExpression>;
17
- annotateForClosureCompiler?: boolean;
18
- }
19
- export declare class ExpressionTranslatorVisitor<TStatement, TExpression> implements o.ExpressionVisitor, o.StatementVisitor {
20
- private factory;
21
- private imports;
22
- private downlevelTaggedTemplates;
23
- private downlevelVariableDeclarations;
24
- private recordWrappedNode;
25
- constructor(factory: AstFactory<TStatement, TExpression>, imports: ImportGenerator<TExpression>, options: TranslatorOptions<TExpression>);
26
- visitDeclareVarStmt(stmt: o.DeclareVarStmt, context: Context): TStatement;
27
- visitDeclareFunctionStmt(stmt: o.DeclareFunctionStmt, context: Context): TStatement;
28
- visitExpressionStmt(stmt: o.ExpressionStatement, context: Context): TStatement;
29
- visitReturnStmt(stmt: o.ReturnStatement, context: Context): TStatement;
30
- visitIfStmt(stmt: o.IfStmt, context: Context): TStatement;
31
- visitReadVarExpr(ast: o.ReadVarExpr, _context: Context): TExpression;
32
- visitWriteVarExpr(expr: o.WriteVarExpr, context: Context): TExpression;
33
- visitWriteKeyExpr(expr: o.WriteKeyExpr, context: Context): TExpression;
34
- visitWritePropExpr(expr: o.WritePropExpr, context: Context): TExpression;
35
- visitInvokeFunctionExpr(ast: o.InvokeFunctionExpr, context: Context): TExpression;
36
- visitInstantiateExpr(ast: o.InstantiateExpr, context: Context): TExpression;
37
- visitLiteralExpr(ast: o.LiteralExpr, _context: Context): TExpression;
38
- visitExternalExpr(ast: o.ExternalExpr, _context: Context): TExpression;
39
- visitConditionalExpr(ast: o.ConditionalExpr, context: Context): TExpression;
40
- visitDynamicImportExpr(ast: o.DynamicImportExpr, context: any): TExpression;
41
- visitNotExpr(ast: o.NotExpr, context: Context): TExpression;
42
- visitFunctionExpr(ast: o.FunctionExpr, context: Context): TExpression;
43
- visitArrowFunctionExpr(ast: o.ArrowFunctionExpr, context: any): TExpression;
44
- visitBinaryOperatorExpr(ast: o.BinaryOperatorExpr, context: Context): TExpression;
45
- visitReadPropExpr(ast: o.ReadPropExpr, context: Context): TExpression;
46
- visitReadKeyExpr(ast: o.ReadKeyExpr, context: Context): TExpression;
47
- visitLiteralArrayExpr(ast: o.LiteralArrayExpr, context: Context): TExpression;
48
- visitLiteralMapExpr(ast: o.LiteralMapExpr, context: Context): TExpression;
49
- visitCommaExpr(ast: o.CommaExpr, context: Context): never;
50
- visitWrappedNodeExpr(ast: o.WrappedNodeExpr<any>, _context: Context): any;
51
- visitTypeofExpr(ast: o.TypeofExpr, context: Context): TExpression;
52
- visitUnaryOperatorExpr(ast: o.UnaryOperatorExpr, context: Context): TExpression;
53
- private visitStatements;
54
- private setSourceMapRange;
55
- private attachComments;
56
- }