static-injector 1.0.8

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 (146) hide show
  1. package/import/commonjs/index.js +1248 -0
  2. package/import/es2015/decorator/injectable.js +14 -0
  3. package/import/es2015/decorator/interface/provider.js +8 -0
  4. package/import/es2015/di/forward_ref.js +53 -0
  5. package/import/es2015/di/inject_switch.js +31 -0
  6. package/import/es2015/di/injection_token.js +71 -0
  7. package/import/es2015/di/injector.js +63 -0
  8. package/import/es2015/di/injector_compatibility.js +172 -0
  9. package/import/es2015/di/injector_marker.js +8 -0
  10. package/import/es2015/di/injector_token.js +21 -0
  11. package/import/es2015/di/interface/defs.js +72 -0
  12. package/import/es2015/di/interface/injector.js +25 -0
  13. package/import/es2015/di/interface/provider.js +8 -0
  14. package/import/es2015/di/metadata.js +49 -0
  15. package/import/es2015/di/null_injector.js +19 -0
  16. package/import/es2015/di/provider_token.js +8 -0
  17. package/import/es2015/di/r3_injector.js +382 -0
  18. package/import/es2015/di/scope.js +14 -0
  19. package/import/es2015/index.js +11 -0
  20. package/import/es2015/interface/lifecycle_hooks.js +8 -0
  21. package/import/es2015/interface/type.js +8 -0
  22. package/import/es2015/render3/definition_factory.js +15 -0
  23. package/import/es2015/render3/error_code.js +29 -0
  24. package/import/es2015/render3/errors_di.js +14 -0
  25. package/import/es2015/render3/fields.js +11 -0
  26. package/import/es2015/render3/instructions/di.js +23 -0
  27. package/import/es2015/render3/util/stringify_utils.js +37 -0
  28. package/import/es2015/util/array_utils.js +17 -0
  29. package/import/es2015/util/closure.js +19 -0
  30. package/import/es2015/util/decorators.js +30 -0
  31. package/import/es2015/util/empty.js +14 -0
  32. package/import/es2015/util/property.js +15 -0
  33. package/import/es2015/util/stringify.js +30 -0
  34. package/import/fesm2015/index.js +1211 -0
  35. package/import/typings/decorator/injectable.d.ts +82 -0
  36. package/import/typings/decorator/interface/provider.d.ts +312 -0
  37. package/import/typings/di/forward_ref.d.ts +49 -0
  38. package/import/typings/di/inject_switch.d.ts +17 -0
  39. package/import/typings/di/injection_token.d.ts +57 -0
  40. package/import/typings/di/injector.d.ts +76 -0
  41. package/import/typings/di/injector_compatibility.d.ts +77 -0
  42. package/import/typings/di/injector_marker.d.ts +23 -0
  43. package/import/typings/di/injector_token.d.ts +18 -0
  44. package/import/typings/di/interface/defs.d.ts +155 -0
  45. package/import/typings/di/interface/injector.d.ts +48 -0
  46. package/import/typings/di/interface/provider.d.ts +312 -0
  47. package/import/typings/di/metadata.d.ts +176 -0
  48. package/import/typings/di/null_injector.d.ts +11 -0
  49. package/import/typings/di/provider_token.d.ts +17 -0
  50. package/import/typings/di/r3_injector.d.ts +92 -0
  51. package/import/typings/di/scope.d.ts +14 -0
  52. package/import/typings/index.d.ts +11 -0
  53. package/import/typings/interface/lifecycle_hooks.d.ts +28 -0
  54. package/import/typings/interface/type.d.ts +21 -0
  55. package/import/typings/render3/definition_factory.d.ts +24 -0
  56. package/import/typings/render3/error_code.d.ts +24 -0
  57. package/import/typings/render3/errors_di.d.ts +2 -0
  58. package/import/typings/render3/fields.d.ts +8 -0
  59. package/import/typings/render3/instructions/di.d.ts +20 -0
  60. package/import/typings/render3/util/stringify_utils.d.ts +20 -0
  61. package/import/typings/util/array_utils.d.ts +10 -0
  62. package/import/typings/util/closure.d.ts +17 -0
  63. package/import/typings/util/decorators.d.ts +27 -0
  64. package/import/typings/util/empty.d.ts +14 -0
  65. package/import/typings/util/property.d.ts +8 -0
  66. package/import/typings/util/stringify.d.ts +8 -0
  67. package/package.json +34 -0
  68. package/readme.md +27 -0
  69. package/transform/compiler/index.d.ts +5 -0
  70. package/transform/compiler/index.js +17 -0
  71. package/transform/compiler/src/core.d.ts +19 -0
  72. package/transform/compiler/src/core.js +9 -0
  73. package/transform/compiler/src/injectable_compiler_2.d.ts +53 -0
  74. package/transform/compiler/src/injectable_compiler_2.js +159 -0
  75. package/transform/compiler/src/output/output_ast.d.ts +534 -0
  76. package/transform/compiler/src/output/output_ast.js +986 -0
  77. package/transform/compiler/src/parse_util.d.ts +50 -0
  78. package/transform/compiler/src/parse_util.js +61 -0
  79. package/transform/compiler/src/render3/partial/api.d.ts +166 -0
  80. package/transform/compiler/src/render3/partial/api.js +11 -0
  81. package/transform/compiler/src/render3/partial/util.d.ts +16 -0
  82. package/transform/compiler/src/render3/partial/util.js +44 -0
  83. package/transform/compiler/src/render3/r3_factory.d.ts +97 -0
  84. package/transform/compiler/src/render3/r3_factory.js +239 -0
  85. package/transform/compiler/src/render3/r3_identifiers.d.ts +20 -0
  86. package/transform/compiler/src/render3/r3_identifiers.js +51 -0
  87. package/transform/compiler/src/render3/util.d.ts +21 -0
  88. package/transform/compiler/src/render3/util.js +41 -0
  89. package/transform/compiler/src/render3/view/util.d.ts +30 -0
  90. package/transform/compiler/src/render3/view/util.js +57 -0
  91. package/transform/compiler-cli/src/ngtsc/annotations/src/factory.d.ts +11 -0
  92. package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +21 -0
  93. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +42 -0
  94. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +278 -0
  95. package/transform/compiler-cli/src/ngtsc/annotations/src/util.d.ts +91 -0
  96. package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +370 -0
  97. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +24 -0
  98. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +76 -0
  99. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +188 -0
  100. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +206 -0
  101. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +2 -0
  102. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +14 -0
  103. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +1 -0
  104. package/transform/compiler-cli/src/ngtsc/imports/index.js +13 -0
  105. package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +36 -0
  106. package/transform/compiler-cli/src/ngtsc/imports/src/core.js +25 -0
  107. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +3 -0
  108. package/transform/compiler-cli/src/ngtsc/reflection/index.js +15 -0
  109. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +667 -0
  110. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +98 -0
  111. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +24 -0
  112. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +271 -0
  113. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +50 -0
  114. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +396 -0
  115. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +12 -0
  116. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +45 -0
  117. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +2 -0
  118. package/transform/compiler-cli/src/ngtsc/transform/index.js +14 -0
  119. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +115 -0
  120. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +30 -0
  121. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +15 -0
  122. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +84 -0
  123. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +5 -0
  124. package/transform/compiler-cli/src/ngtsc/translator/index.js +17 -0
  125. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +274 -0
  126. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js +9 -0
  127. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +27 -0
  128. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +9 -0
  129. package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +18 -0
  130. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +27 -0
  131. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +29 -0
  132. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +70 -0
  133. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +58 -0
  134. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +270 -0
  135. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +54 -0
  136. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +245 -0
  137. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +13 -0
  138. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +21 -0
  139. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +11 -0
  140. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +39 -0
  141. package/transform/index.d.ts +1 -0
  142. package/transform/index.js +13 -0
  143. package/transform/injectable-transform.d.ts +41 -0
  144. package/transform/injectable-transform.js +195 -0
  145. package/transform/node-Iteration.d.ts +2 -0
  146. package/transform/node-Iteration.js +12 -0
@@ -0,0 +1,12 @@
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 ts from "typescript";
9
+ import { ClassDeclaration } from "./host";
10
+ export declare function isNamedClassDeclaration(node: ts.Node): node is ClassDeclaration<ts.ClassDeclaration>;
11
+ export declare function isNamedFunctionDeclaration(node: ts.Node): node is ClassDeclaration<ts.FunctionDeclaration>;
12
+ export declare function isNamedVariableDeclaration(node: ts.Node): node is ClassDeclaration<ts.VariableDeclaration>;
@@ -0,0 +1,45 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.isNamedVariableDeclaration = exports.isNamedFunctionDeclaration = exports.isNamedClassDeclaration = void 0;
30
+ const ts = __importStar(require("typescript"));
31
+ function isNamedClassDeclaration(node) {
32
+ return ts.isClassDeclaration(node) && isIdentifier(node.name);
33
+ }
34
+ exports.isNamedClassDeclaration = isNamedClassDeclaration;
35
+ function isNamedFunctionDeclaration(node) {
36
+ return ts.isFunctionDeclaration(node) && isIdentifier(node.name);
37
+ }
38
+ exports.isNamedFunctionDeclaration = isNamedFunctionDeclaration;
39
+ function isNamedVariableDeclaration(node) {
40
+ return ts.isVariableDeclaration(node) && isIdentifier(node.name);
41
+ }
42
+ exports.isNamedVariableDeclaration = isNamedVariableDeclaration;
43
+ function isIdentifier(node) {
44
+ return node !== undefined && ts.isIdentifier(node);
45
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./src/api";
2
+ export * from "./src/utils";
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./src/api"), exports);
14
+ __exportStar(require("./src/utils"), exports);
@@ -0,0 +1,115 @@
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 { Expression, Statement, Type } from "../../../../../compiler";
9
+ import * as ts from "typescript";
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
+ /**
31
+ * Provides the interface between a decorator compiler from @angular/compiler and the Typescript
32
+ * compiler/transform.
33
+ *
34
+ * The decorator compilers in @angular/compiler do not depend on Typescript. The handler is
35
+ * responsible for extracting the information required to perform compilation from the decorators
36
+ * and Typescript source, invoking the decorator compiler, and returning the result.
37
+ *
38
+ * @param `D` The type of decorator metadata produced by `detect`.
39
+ * @param `A` The type of analysis metadata produced by `analyze`.
40
+ * @param `R` The type of resolution metadata produced by `resolve`.
41
+ */
42
+ export interface DecoratorHandler<D, A, S extends null, R> {
43
+ /**
44
+ * Scan a set of reflected decorators and determine if this handler is responsible for compilation
45
+ * of one of them.
46
+ */
47
+ detect(node: ClassDeclaration, decorators: Decorator[] | null): DetectResult<D> | undefined;
48
+ /**
49
+ * Asynchronously perform pre-analysis on the decorator/class combination.
50
+ *
51
+ * `preanalyze` is optional and is not guaranteed to be called through all compilation flows. It
52
+ * will only be called if asynchronicity is supported in the CompilerHost.
53
+ */
54
+ preanalyze?(node: ClassDeclaration, metadata: Readonly<D>): Promise<void> | undefined;
55
+ /**
56
+ * Perform analysis on the decorator/class combination, extracting information from the class
57
+ * required for compilation.
58
+ *
59
+ * Returns analyzed metadata if successful, or an array of diagnostic messages if the analysis
60
+ * fails or the decorator isn't valid.
61
+ *
62
+ * Analysis should always be a "pure" operation, with no side effects. This is because the
63
+ * detect/analysis steps might be skipped for files which have not changed during incremental
64
+ * builds. Any side effects required for compilation (e.g. registration of metadata) should happen
65
+ * in the `register` phase, which is guaranteed to run even for incremental builds.
66
+ */
67
+ analyze(node: ClassDeclaration, metadata: Readonly<D>, handlerFlags?: HandlerFlags): AnalysisOutput<A>;
68
+ /**
69
+ * Generate a description of the field which should be added to the class, including any
70
+ * initialization code to be generated.
71
+ *
72
+ * If the compilation mode is configured as partial, and an implementation of `compilePartial` is
73
+ * provided, then this method is not called.
74
+ */
75
+ compileFull(node: ClassDeclaration, analysis: Readonly<A>): CompileResult | CompileResult[];
76
+ }
77
+ /**
78
+ * The output of detecting a trait for a declaration as the result of the first phase of the
79
+ * compilation pipeline.
80
+ */
81
+ export interface DetectResult<M> {
82
+ /**
83
+ * The node that triggered the match, which is typically a decorator.
84
+ */
85
+ trigger: ts.Node | null;
86
+ /**
87
+ * Refers to the decorator that was recognized for this detection, if any. This can be a concrete
88
+ * decorator that is actually present in a file, or a synthetic decorator as inserted
89
+ * programmatically.
90
+ */
91
+ decorator: Decorator | null;
92
+ /**
93
+ * An arbitrary object to carry over from the detection phase into the analysis phase.
94
+ */
95
+ metadata: Readonly<M>;
96
+ }
97
+ /**
98
+ * The output of an analysis operation, consisting of possibly an arbitrary analysis object (used as
99
+ * the input to code generation) and potentially diagnostics if there were errors uncovered during
100
+ * analysis.
101
+ */
102
+ export interface AnalysisOutput<A> {
103
+ analysis?: Readonly<A>;
104
+ diagnostics?: ts.Diagnostic[];
105
+ }
106
+ /**
107
+ * A description of the static field to add to a class, including an initialization expression
108
+ * and a type for the .d.ts file.
109
+ */
110
+ export interface CompileResult {
111
+ name: string;
112
+ initializer: Expression;
113
+ statements: Statement[];
114
+ type: Type;
115
+ }
@@ -0,0 +1,30 @@
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.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 = {}));
@@ -0,0 +1,15 @@
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 ts from "typescript";
9
+ import { ImportManager } from "../../translator";
10
+ /**
11
+ * Adds extra imports in the import manage for this source file, after the existing imports
12
+ * and before the module body.
13
+ * Can optionally add extra statements (e.g. new constants) before the body as well.
14
+ */
15
+ export declare function addImports(importManager: ImportManager, sf: ts.SourceFile, extraStatements?: ts.Statement[]): ts.SourceFile;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.addImports = void 0;
23
+ /**
24
+ * @license
25
+ * Copyright Google LLC All Rights Reserved.
26
+ *
27
+ * Use of this source code is governed by an MIT-style license that can be
28
+ * found in the LICENSE file at https://angular.io/license
29
+ */
30
+ const ts = __importStar(require("typescript"));
31
+ /**
32
+ * Adds extra imports in the import manage for this source file, after the existing imports
33
+ * and before the module body.
34
+ * Can optionally add extra statements (e.g. new constants) before the body as well.
35
+ */
36
+ function addImports(importManager, sf, extraStatements = []) {
37
+ // Generate the import statements to prepend.
38
+ const addedImports = importManager.getAllImports(sf.fileName).map((i) => {
39
+ const qualifier = ts.createIdentifier(i.qualifier.text);
40
+ const importClause = ts.createImportClause(
41
+ /* name */ undefined,
42
+ /* namedBindings */ ts.createNamespaceImport(qualifier));
43
+ const decl = ts.createImportDeclaration(
44
+ /* decorators */ undefined,
45
+ /* modifiers */ undefined,
46
+ /* importClause */ importClause,
47
+ /* moduleSpecifier */ ts.createLiteral(i.specifier));
48
+ // Set the qualifier's original TS node to the `ts.ImportDeclaration`. This allows downstream
49
+ // transforms such as tsickle to properly process references to this import.
50
+ //
51
+ // This operation is load-bearing in g3 as some imported modules contain special metadata
52
+ // generated by clutz, which tsickle uses to transform imports and references to those imports.
53
+ //
54
+ // TODO(alxhub): add a test for this when tsickle is updated externally to depend on this
55
+ // behavior.
56
+ ts.setOriginalNode(i.qualifier, decl);
57
+ return decl;
58
+ });
59
+ // Filter out the existing imports and the source file body. All new statements
60
+ // will be inserted between them.
61
+ const existingImports = sf.statements.filter((stmt) => isImportStatement(stmt));
62
+ const body = sf.statements.filter((stmt) => !isImportStatement(stmt));
63
+ // Prepend imports if needed.
64
+ if (addedImports.length > 0) {
65
+ // If we prepend imports, we also prepend NotEmittedStatement to use it as an anchor
66
+ // for @fileoverview Closure annotation. If there is no @fileoverview annotations, this
67
+ // statement would be a noop.
68
+ const fileoverviewAnchorStmt = ts.createNotEmittedStatement(sf);
69
+ return ts.updateSourceFileNode(sf, ts.createNodeArray([
70
+ fileoverviewAnchorStmt,
71
+ ...existingImports,
72
+ ...addedImports,
73
+ ...extraStatements,
74
+ ...body,
75
+ ]));
76
+ }
77
+ return sf;
78
+ }
79
+ exports.addImports = addImports;
80
+ function isImportStatement(stmt) {
81
+ return (ts.isImportDeclaration(stmt) ||
82
+ ts.isImportEqualsDeclaration(stmt) ||
83
+ ts.isNamespaceImport(stmt));
84
+ }
@@ -0,0 +1,5 @@
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";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./src/context"), exports);
14
+ __exportStar(require("./src/translator"), exports);
15
+ __exportStar(require("./src/typescript_ast_factory"), exports);
16
+ __exportStar(require("./src/typescript_translator"), exports);
17
+ __exportStar(require("./src/import_manager"), exports);
@@ -0,0 +1,274 @@
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 expresion (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 arugments 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 identifier.
98
+ *
99
+ * @param name the name of the identifier.
100
+ */
101
+ createIdentifier(name: string): TExpression;
102
+ /**
103
+ * Create an if statement (e.g. `if (testExpr) { trueStmt; } else { falseStmt; }`).
104
+ *
105
+ * @param condition an expression that will be tested for truthiness.
106
+ * @param thenStatement a statement (or block of statements) that is executed if `condition` is
107
+ * truthy.
108
+ * @param elseStatement a statement (or block of statements) that is executed if `condition` is
109
+ * falsy.
110
+ */
111
+ createIfStatement(condition: TExpression, thenStatement: TStatement, elseStatement: TStatement | null): TStatement;
112
+ /**
113
+ * Create a simple literal (e.g. `"string"`, `123`, `false`, etc).
114
+ *
115
+ * @param value the value of the literal.
116
+ */
117
+ createLiteral(value: string | number | boolean | null | undefined): TExpression;
118
+ /**
119
+ * Create an expression that is instantiating the `expression` as a class.
120
+ *
121
+ * @param expression an expression that evaluates to a constructor to be instantiated.
122
+ * @param args the arguments to be passed to the constructor.
123
+ */
124
+ createNewExpression(expression: TExpression, args: TExpression[]): TExpression;
125
+ /**
126
+ * Create a literal object expression (e.g. `{ prop1: expr1, prop2: expr2 }`).
127
+ *
128
+ * @param properties the properties (key and value) to appear in the object.
129
+ */
130
+ createObjectLiteral(properties: ObjectLiteralProperty<TExpression>[]): TExpression;
131
+ /**
132
+ * Wrap an expression in parentheses.
133
+ *
134
+ * @param expression the expression to wrap in parentheses.
135
+ */
136
+ createParenthesizedExpression(expression: TExpression): TExpression;
137
+ /**
138
+ * Create a property access (e.g. `obj.prop`).
139
+ *
140
+ * @param expression an expression that evaluates to the object to be accessed.
141
+ * @param propertyName the name of the property to access.
142
+ */
143
+ createPropertyAccess(expression: TExpression, propertyName: string): TExpression;
144
+ /**
145
+ * Create a return statement (e.g `return expr;`).
146
+ *
147
+ * @param expression the expression to be returned.
148
+ */
149
+ createReturnStatement(expression: TExpression | null): TStatement;
150
+ /**
151
+ * Create a tagged template literal string. E.g.
152
+ *
153
+ * ```
154
+ * tag`str1${expr1}str2${expr2}str3`
155
+ * ```
156
+ *
157
+ * @param tag an expression that is applied as a tag handler for this template string.
158
+ * @param template the collection of strings and expressions that constitute an interpolated
159
+ * template literal.
160
+ */
161
+ createTaggedTemplate(tag: TExpression, template: TemplateLiteral<TExpression>): TExpression;
162
+ /**
163
+ * Create a throw statement (e.g. `throw expr;`).
164
+ *
165
+ * @param expression the expression to be thrown.
166
+ */
167
+ createThrowStatement(expression: TExpression): TStatement;
168
+ /**
169
+ * Create an expression that extracts the type of an expression (e.g. `typeof expr`).
170
+ *
171
+ * @param expression the expression whose type we want.
172
+ */
173
+ createTypeOfExpression(expression: TExpression): TExpression;
174
+ /**
175
+ * Prefix the `operand` with the given `operator` (e.g. `-expr`).
176
+ *
177
+ * @param operator the text of the operator to apply (e.g. `+`, `-` or `!`).
178
+ * @param operand the expression that the operator applies to.
179
+ */
180
+ createUnaryExpression(operator: UnaryOperator, operand: TExpression): TExpression;
181
+ /**
182
+ * Create an expression that declares a new variable, possibly initialized to `initializer`.
183
+ *
184
+ * @param variableName the name of the variable.
185
+ * @param initializer if not `null` then this expression is assigned to the declared variable.
186
+ * @param type whether this variable should be declared as `var`, `let` or `const`.
187
+ */
188
+ createVariableDeclaration(variableName: string, initializer: TExpression | null, type: VariableDeclarationType): TStatement;
189
+ /**
190
+ * Attach a source map range to the given node.
191
+ *
192
+ * @param node the node to which the range should be attached.
193
+ * @param sourceMapRange the range to attach to the node, or null if there is no range to attach.
194
+ * @returns the `node` with the `sourceMapRange` attached.
195
+ */
196
+ setSourceMapRange<T extends TStatement | TExpression>(node: T, sourceMapRange: SourceMapRange | null): T;
197
+ }
198
+ /**
199
+ * The type of a variable declaration.
200
+ */
201
+ export declare type VariableDeclarationType = "const" | "let" | "var";
202
+ /**
203
+ * The unary operators supported by the `AstFactory`.
204
+ */
205
+ export declare type UnaryOperator = "+" | "-" | "!";
206
+ /**
207
+ * The binary operators supported by the `AstFactory`.
208
+ */
209
+ export declare type BinaryOperator = "&&" | ">" | ">=" | "&" | "/" | "==" | "===" | "<" | "<=" | "-" | "%" | "*" | "!=" | "!==" | "||" | "+" | "??";
210
+ /**
211
+ * The original location of the start or end of a node created by the `AstFactory`.
212
+ */
213
+ export interface SourceMapLocation {
214
+ /** 0-based character position of the location in the original source file. */
215
+ offset: number;
216
+ /** 0-based line index of the location in the original source file. */
217
+ line: number;
218
+ /** 0-based column position of the location in the original source file. */
219
+ column: number;
220
+ }
221
+ /**
222
+ * The original range of a node created by the `AstFactory`.
223
+ */
224
+ export interface SourceMapRange {
225
+ url: string;
226
+ content: string;
227
+ start: SourceMapLocation;
228
+ end: SourceMapLocation;
229
+ }
230
+ /**
231
+ * Information used by the `AstFactory` to create a property on an object literal expression.
232
+ */
233
+ export interface ObjectLiteralProperty<TExpression> {
234
+ propertyName: string;
235
+ value: TExpression;
236
+ /**
237
+ * Whether the `propertyName` should be enclosed in quotes.
238
+ */
239
+ quoted: boolean;
240
+ }
241
+ /**
242
+ * Information used by the `AstFactory` to create a template literal string (i.e. a back-ticked
243
+ * string with interpolations).
244
+ */
245
+ export interface TemplateLiteral<TExpression> {
246
+ /**
247
+ * A collection of the static string pieces of the interpolated template literal string.
248
+ */
249
+ elements: TemplateElement[];
250
+ /**
251
+ * A collection of the interpolated expressions that are interleaved between the elements.
252
+ */
253
+ expressions: TExpression[];
254
+ }
255
+ /**
256
+ * Information about a static string piece of an interpolated template literal string.
257
+ */
258
+ export interface TemplateElement {
259
+ /** The raw string as it was found in the original source code. */
260
+ raw: string;
261
+ /** The parsed string, with escape codes etc processed. */
262
+ cooked: string;
263
+ /** The original location of this piece of the template literal string. */
264
+ range: SourceMapRange | null;
265
+ }
266
+ /**
267
+ * Information used by the `AstFactory` to prepend a comment to a statement that was created by the
268
+ * `AstFactory`.
269
+ */
270
+ export interface LeadingComment {
271
+ toString(): string;
272
+ multiline: boolean;
273
+ trailingNewline: boolean;
274
+ }