static-injector 1.0.10 → 2.1.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 (111) hide show
  1. package/import/commonjs/index.js +337 -124
  2. package/import/es2015/di/create_injector.js +30 -0
  3. package/import/es2015/di/initializer_token.js +15 -0
  4. package/import/es2015/di/inject_switch.js +27 -6
  5. package/import/es2015/di/injection_token.js +6 -0
  6. package/import/es2015/di/injector.js +6 -8
  7. package/import/es2015/di/injector_compatibility.js +90 -34
  8. package/import/es2015/di/injector_token.js +1 -1
  9. package/import/es2015/di/interface/defs.js +39 -0
  10. package/import/es2015/di/interface/injector.js +1 -0
  11. package/import/es2015/di/internal_tokens.js +9 -0
  12. package/import/es2015/di/metadata.js +4 -4
  13. package/import/es2015/di/provider_collection.js +49 -0
  14. package/import/es2015/di/r3_injector.js +102 -72
  15. package/import/es2015/di/scope.js +2 -2
  16. package/import/es2015/index.js +1 -1
  17. package/import/es2015/render3/errors_di.js +1 -1
  18. package/import/fesm2015/index.js +328 -114
  19. package/import/typings/di/create_injector.d.ts +23 -0
  20. package/import/typings/di/initializer_token.d.ts +15 -0
  21. package/import/typings/di/inject_switch.d.ts +7 -2
  22. package/import/typings/{decorator → di}/injectable.d.ts +2 -2
  23. package/import/typings/di/injection_token.d.ts +4 -0
  24. package/import/typings/di/injector.d.ts +20 -7
  25. package/import/typings/di/injector_compatibility.d.ts +42 -21
  26. package/import/typings/di/interface/defs.d.ts +10 -0
  27. package/import/typings/di/interface/injector.d.ts +26 -0
  28. package/import/typings/di/interface/provider.d.ts +3 -8
  29. package/import/typings/di/internal_tokens.d.ts +10 -0
  30. package/import/typings/di/provider_collection.d.ts +30 -0
  31. package/import/typings/di/provider_token.d.ts +1 -1
  32. package/import/typings/di/r3_injector.d.ts +68 -37
  33. package/import/typings/di/scope.d.ts +3 -2
  34. package/import/typings/index.d.ts +1 -1
  35. package/import/typings/render3/definition_factory.d.ts +1 -1
  36. package/package.json +5 -3
  37. package/{import/es2015/decorator/interface/provider.js → transform/compiler/compiler.d.ts} +1 -1
  38. package/transform/compiler/compiler.js +28 -0
  39. package/transform/compiler/index.d.ts +8 -5
  40. package/transform/compiler/index.js +17 -6
  41. package/transform/compiler/public_api.d.ts +13 -0
  42. package/transform/compiler/public_api.js +30 -0
  43. package/transform/compiler/src/compiler.d.ts +27 -0
  44. package/transform/compiler/src/compiler.js +47 -0
  45. package/transform/compiler/src/injectable_compiler_2.d.ts +7 -36
  46. package/transform/compiler/src/injectable_compiler_2.js +20 -23
  47. package/transform/compiler/src/output/output_ast.d.ts +30 -109
  48. package/transform/compiler/src/output/output_ast.js +66 -188
  49. package/transform/compiler/src/render3/partial/api.d.ts +1 -1
  50. package/transform/compiler/src/render3/partial/api.js +7 -0
  51. package/transform/compiler/src/render3/r3_factory.d.ts +8 -15
  52. package/transform/compiler/src/render3/r3_factory.js +46 -61
  53. package/transform/compiler/src/render3/util.d.ts +64 -0
  54. package/transform/compiler/src/render3/util.js +52 -9
  55. package/transform/compiler/src/render3/view/util.d.ts +0 -8
  56. package/transform/compiler/src/render3/view/util.js +5 -9
  57. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +10 -0
  58. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +26 -0
  59. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +37 -0
  60. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +197 -0
  61. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.d.ts +3 -3
  62. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.js +3 -3
  63. package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +4 -34
  64. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +181 -0
  65. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
  66. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +46 -53
  67. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
  68. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
  69. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +12 -1
  70. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
  71. package/transform/compiler-cli/src/ngtsc/imports/index.js +12 -1
  72. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +19 -0
  73. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +28 -0
  74. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +10 -3
  75. package/transform/compiler-cli/src/ngtsc/reflection/index.js +12 -1
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +13 -14
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +8 -25
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +44 -55
  80. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
  81. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +55 -69
  82. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
  83. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -23
  84. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
  85. package/transform/compiler-cli/src/ngtsc/transform/index.js +12 -1
  86. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
  87. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
  88. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +16 -31
  89. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
  90. package/transform/compiler-cli/src/ngtsc/translator/index.js +12 -1
  91. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +5 -5
  92. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +4 -4
  93. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +5 -21
  94. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -6
  95. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +6 -18
  96. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
  97. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +83 -90
  98. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
  99. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +8 -0
  100. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
  101. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +45 -0
  102. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +86 -0
  103. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
  104. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -27
  105. package/transform/index.js +5 -1
  106. package/transform/injectable-transform.js +59 -38
  107. package/import/typings/decorator/interface/provider.d.ts +0 -312
  108. package/transform/compiler/src/render3/partial/util.d.ts +0 -16
  109. package/transform/compiler/src/render3/partial/util.js +0 -44
  110. package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +0 -370
  111. /package/import/es2015/{decorator → di}/injectable.js +0 -0
@@ -1,22 +1,6 @@
1
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;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
21
5
  Object.defineProperty(exports, "__esModule", { value: true });
22
6
  exports.attachComments = exports.createTemplateTail = exports.createTemplateMiddle = exports.TypeScriptAstFactory = void 0;
@@ -27,7 +11,8 @@ exports.attachComments = exports.createTemplateTail = exports.createTemplateMidd
27
11
  * Use of this source code is governed by an MIT-style license that can be
28
12
  * found in the LICENSE file at https://angular.io/license
29
13
  */
30
- const ts = __importStar(require("typescript"));
14
+ const typescript_1 = __importDefault(require("typescript"));
15
+ const ts_compatibility_1 = require("../../ts_compatibility");
31
16
  /**
32
17
  * Different optimizers use different annotations on a function or method call to indicate its pure
33
18
  * status.
@@ -43,33 +28,33 @@ var PureAnnotation;
43
28
  PureAnnotation["TERSER"] = "@__PURE__";
44
29
  })(PureAnnotation || (PureAnnotation = {}));
45
30
  const UNARY_OPERATORS = {
46
- "+": ts.SyntaxKind.PlusToken,
47
- "-": ts.SyntaxKind.MinusToken,
48
- "!": ts.SyntaxKind.ExclamationToken,
31
+ '+': typescript_1.default.SyntaxKind.PlusToken,
32
+ '-': typescript_1.default.SyntaxKind.MinusToken,
33
+ '!': typescript_1.default.SyntaxKind.ExclamationToken,
49
34
  };
50
35
  const BINARY_OPERATORS = {
51
- "&&": ts.SyntaxKind.AmpersandAmpersandToken,
52
- ">": ts.SyntaxKind.GreaterThanToken,
53
- ">=": ts.SyntaxKind.GreaterThanEqualsToken,
54
- "&": ts.SyntaxKind.AmpersandToken,
55
- "/": ts.SyntaxKind.SlashToken,
56
- "==": ts.SyntaxKind.EqualsEqualsToken,
57
- "===": ts.SyntaxKind.EqualsEqualsEqualsToken,
58
- "<": ts.SyntaxKind.LessThanToken,
59
- "<=": ts.SyntaxKind.LessThanEqualsToken,
60
- "-": ts.SyntaxKind.MinusToken,
61
- "%": ts.SyntaxKind.PercentToken,
62
- "*": ts.SyntaxKind.AsteriskToken,
63
- "!=": ts.SyntaxKind.ExclamationEqualsToken,
64
- "!==": ts.SyntaxKind.ExclamationEqualsEqualsToken,
65
- "||": ts.SyntaxKind.BarBarToken,
66
- "+": ts.SyntaxKind.PlusToken,
67
- "??": ts.SyntaxKind.QuestionQuestionToken,
36
+ '&&': typescript_1.default.SyntaxKind.AmpersandAmpersandToken,
37
+ '>': typescript_1.default.SyntaxKind.GreaterThanToken,
38
+ '>=': typescript_1.default.SyntaxKind.GreaterThanEqualsToken,
39
+ '&': typescript_1.default.SyntaxKind.AmpersandToken,
40
+ '/': typescript_1.default.SyntaxKind.SlashToken,
41
+ '==': typescript_1.default.SyntaxKind.EqualsEqualsToken,
42
+ '===': typescript_1.default.SyntaxKind.EqualsEqualsEqualsToken,
43
+ '<': typescript_1.default.SyntaxKind.LessThanToken,
44
+ '<=': typescript_1.default.SyntaxKind.LessThanEqualsToken,
45
+ '-': typescript_1.default.SyntaxKind.MinusToken,
46
+ '%': typescript_1.default.SyntaxKind.PercentToken,
47
+ '*': typescript_1.default.SyntaxKind.AsteriskToken,
48
+ '!=': typescript_1.default.SyntaxKind.ExclamationEqualsToken,
49
+ '!==': typescript_1.default.SyntaxKind.ExclamationEqualsEqualsToken,
50
+ '||': typescript_1.default.SyntaxKind.BarBarToken,
51
+ '+': typescript_1.default.SyntaxKind.PlusToken,
52
+ '??': typescript_1.default.SyntaxKind.QuestionQuestionToken,
68
53
  };
69
54
  const VAR_TYPES = {
70
- const: ts.NodeFlags.Const,
71
- let: ts.NodeFlags.Let,
72
- var: ts.NodeFlags.None,
55
+ const: typescript_1.default.NodeFlags.Const,
56
+ let: typescript_1.default.NodeFlags.Let,
57
+ var: typescript_1.default.NodeFlags.None,
73
58
  };
74
59
  /**
75
60
  * A TypeScript flavoured implementation of the AstFactory.
@@ -79,78 +64,86 @@ class TypeScriptAstFactory {
79
64
  this.annotateForClosureCompiler = annotateForClosureCompiler;
80
65
  this.externalSourceFiles = new Map();
81
66
  this.attachComments = attachComments;
82
- this.createArrayLiteral = ts.createArrayLiteral;
83
- this.createConditional = ts.createConditional;
84
- this.createElementAccess = ts.createElementAccess;
85
- this.createExpressionStatement = ts.createExpressionStatement;
86
- this.createIdentifier = ts.createIdentifier;
87
- this.createParenthesizedExpression = ts.createParen;
88
- this.createPropertyAccess = ts.createPropertyAccess;
89
- this.createThrowStatement = ts.createThrow;
90
- this.createTypeOfExpression = ts.createTypeOf;
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;
91
75
  }
92
76
  createAssignment(target, value) {
93
- return ts.createBinary(target, ts.SyntaxKind.EqualsToken, value);
77
+ return typescript_1.default.factory.createBinaryExpression(target, typescript_1.default.SyntaxKind.EqualsToken, value);
94
78
  }
95
79
  createBinaryExpression(leftOperand, operator, rightOperand) {
96
- return ts.createBinary(leftOperand, BINARY_OPERATORS[operator], rightOperand);
80
+ return typescript_1.default.factory.createBinaryExpression(leftOperand, BINARY_OPERATORS[operator], rightOperand);
97
81
  }
98
82
  createBlock(body) {
99
- return ts.createBlock(body);
83
+ return typescript_1.default.factory.createBlock(body);
100
84
  }
101
85
  createCallExpression(callee, args, pure) {
102
- const call = ts.createCall(callee, undefined, args);
86
+ const call = typescript_1.default.factory.createCallExpression(callee, undefined, args);
103
87
  if (pure) {
104
- ts.addSyntheticLeadingComment(call, ts.SyntaxKind.MultiLineCommentTrivia, this.annotateForClosureCompiler
88
+ typescript_1.default.addSyntheticLeadingComment(call, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, this.annotateForClosureCompiler
105
89
  ? PureAnnotation.CLOSURE
106
90
  : PureAnnotation.TERSER,
107
91
  /* trailing newline */ false);
108
92
  }
109
93
  return call;
110
94
  }
95
+ createConditional(condition, whenTrue, whenFalse) {
96
+ return typescript_1.default.factory.createConditionalExpression(condition, undefined, whenTrue, undefined, whenFalse);
97
+ }
111
98
  createFunctionDeclaration(functionName, parameters, body) {
112
- if (!ts.isBlock(body)) {
113
- throw new Error(`Invalid syntax, expected a block, but got ${ts.SyntaxKind[body.kind]}.`);
99
+ if (!typescript_1.default.isBlock(body)) {
100
+ throw new Error(`Invalid syntax, expected a block, but got ${typescript_1.default.SyntaxKind[body.kind]}.`);
114
101
  }
115
- return ts.createFunctionDeclaration(undefined, undefined, undefined, functionName, undefined, parameters.map((param) => ts.createParameter(undefined, undefined, undefined, param)), undefined, body);
102
+ return (0, ts_compatibility_1.createFunctionDeclaration)(undefined, undefined, functionName, undefined, parameters.map((param) => (0, ts_compatibility_1.createParameterDeclaration)(undefined, undefined, param)), undefined, body);
116
103
  }
117
104
  createFunctionExpression(functionName, parameters, body) {
118
- if (!ts.isBlock(body)) {
119
- throw new Error(`Invalid syntax, expected a block, but got ${ts.SyntaxKind[body.kind]}.`);
105
+ if (!typescript_1.default.isBlock(body)) {
106
+ throw new Error(`Invalid syntax, expected a block, but got ${typescript_1.default.SyntaxKind[body.kind]}.`);
120
107
  }
121
- return ts.createFunctionExpression(undefined, undefined, functionName !== null && functionName !== void 0 ? functionName : undefined, undefined, parameters.map((param) => ts.createParameter(undefined, undefined, undefined, param)), undefined, body);
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);
122
109
  }
123
110
  createIfStatement(condition, thenStatement, elseStatement) {
124
- return ts.createIf(condition, thenStatement, elseStatement !== null && elseStatement !== void 0 ? elseStatement : undefined);
111
+ return typescript_1.default.factory.createIfStatement(condition, thenStatement, elseStatement !== null && elseStatement !== void 0 ? elseStatement : undefined);
125
112
  }
126
113
  createLiteral(value) {
127
114
  if (value === undefined) {
128
- return ts.createIdentifier("undefined");
115
+ return typescript_1.default.factory.createIdentifier('undefined');
129
116
  }
130
117
  else if (value === null) {
131
- return ts.createNull();
118
+ return typescript_1.default.factory.createNull();
119
+ }
120
+ else if (typeof value === 'boolean') {
121
+ return value ? typescript_1.default.factory.createTrue() : typescript_1.default.factory.createFalse();
122
+ }
123
+ else if (typeof value === 'number') {
124
+ return typescript_1.default.factory.createNumericLiteral(value);
132
125
  }
133
126
  else {
134
- return ts.createLiteral(value);
127
+ return typescript_1.default.factory.createStringLiteral(value);
135
128
  }
136
129
  }
137
130
  createNewExpression(expression, args) {
138
- return ts.createNew(expression, undefined, args);
131
+ return typescript_1.default.factory.createNewExpression(expression, undefined, args);
139
132
  }
140
133
  createObjectLiteral(properties) {
141
- return ts.createObjectLiteral(properties.map((prop) => ts.createPropertyAssignment(prop.quoted
142
- ? ts.createLiteral(prop.propertyName)
143
- : ts.createIdentifier(prop.propertyName), prop.value)));
134
+ return typescript_1.default.factory.createObjectLiteralExpression(properties.map((prop) => typescript_1.default.factory.createPropertyAssignment(prop.quoted
135
+ ? typescript_1.default.factory.createStringLiteral(prop.propertyName)
136
+ : typescript_1.default.factory.createIdentifier(prop.propertyName), prop.value)));
144
137
  }
145
138
  createReturnStatement(expression) {
146
- return ts.createReturn(expression !== null && expression !== void 0 ? expression : undefined);
139
+ return typescript_1.default.factory.createReturnStatement(expression !== null && expression !== void 0 ? expression : undefined);
147
140
  }
148
141
  createTaggedTemplate(tag, template) {
149
142
  let templateLiteral;
150
143
  const length = template.elements.length;
151
144
  const head = template.elements[0];
152
145
  if (length === 1) {
153
- templateLiteral = ts.createNoSubstitutionTemplateLiteral(head.cooked, head.raw);
146
+ templateLiteral = typescript_1.default.factory.createNoSubstitutionTemplateLiteral(head.cooked, head.raw);
154
147
  }
155
148
  else {
156
149
  const spans = [];
@@ -161,7 +154,7 @@ class TypeScriptAstFactory {
161
154
  if (range !== null) {
162
155
  this.setSourceMapRange(middle, range);
163
156
  }
164
- spans.push(ts.createTemplateSpan(template.expressions[i - 1], middle));
157
+ spans.push(typescript_1.default.factory.createTemplateSpan(template.expressions[i - 1], middle));
165
158
  }
166
159
  // Create the tail part
167
160
  const resolvedExpression = template.expressions[length - 2];
@@ -170,21 +163,21 @@ class TypeScriptAstFactory {
170
163
  if (templatePart.range !== null) {
171
164
  this.setSourceMapRange(templateTail, templatePart.range);
172
165
  }
173
- spans.push(ts.createTemplateSpan(resolvedExpression, templateTail));
166
+ spans.push(typescript_1.default.factory.createTemplateSpan(resolvedExpression, templateTail));
174
167
  // Put it all together
175
- templateLiteral = ts.createTemplateExpression(ts.createTemplateHead(head.cooked, head.raw), spans);
168
+ templateLiteral = typescript_1.default.factory.createTemplateExpression(typescript_1.default.factory.createTemplateHead(head.cooked, head.raw), spans);
176
169
  }
177
170
  if (head.range !== null) {
178
171
  this.setSourceMapRange(templateLiteral, head.range);
179
172
  }
180
- return ts.createTaggedTemplate(tag, templateLiteral);
173
+ return typescript_1.default.factory.createTaggedTemplateExpression(tag, undefined, templateLiteral);
181
174
  }
182
175
  createUnaryExpression(operator, operand) {
183
- return ts.createPrefix(UNARY_OPERATORS[operator], operand);
176
+ return typescript_1.default.factory.createPrefixUnaryExpression(UNARY_OPERATORS[operator], operand);
184
177
  }
185
178
  createVariableDeclaration(variableName, initializer, type) {
186
- return ts.createVariableStatement(undefined, ts.createVariableDeclarationList([
187
- ts.createVariableDeclaration(variableName, undefined, initializer !== null && initializer !== void 0 ? initializer : undefined),
179
+ 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),
188
181
  ], VAR_TYPES[type]));
189
182
  }
190
183
  setSourceMapRange(node, sourceMapRange) {
@@ -193,10 +186,10 @@ class TypeScriptAstFactory {
193
186
  }
194
187
  const url = sourceMapRange.url;
195
188
  if (!this.externalSourceFiles.has(url)) {
196
- this.externalSourceFiles.set(url, ts.createSourceMapSource(url, sourceMapRange.content, (pos) => pos));
189
+ this.externalSourceFiles.set(url, typescript_1.default.createSourceMapSource(url, sourceMapRange.content, (pos) => pos));
197
190
  }
198
191
  const source = this.externalSourceFiles.get(url);
199
- ts.setSourceMapRange(node, {
192
+ typescript_1.default.setSourceMapRange(node, {
200
193
  pos: sourceMapRange.start.offset,
201
194
  end: sourceMapRange.end.offset,
202
195
  source,
@@ -208,16 +201,16 @@ exports.TypeScriptAstFactory = TypeScriptAstFactory;
208
201
  // HACK: Use this in place of `ts.createTemplateMiddle()`.
209
202
  // Revert once https://github.com/microsoft/TypeScript/issues/35374 is fixed.
210
203
  function createTemplateMiddle(cooked, raw) {
211
- const node = ts.createTemplateHead(cooked, raw);
212
- node.kind = ts.SyntaxKind.TemplateMiddle;
204
+ const node = typescript_1.default.factory.createTemplateHead(cooked, raw);
205
+ node.kind = typescript_1.default.SyntaxKind.TemplateMiddle;
213
206
  return node;
214
207
  }
215
208
  exports.createTemplateMiddle = createTemplateMiddle;
216
209
  // HACK: Use this in place of `ts.createTemplateTail()`.
217
210
  // Revert once https://github.com/microsoft/TypeScript/issues/35374 is fixed.
218
211
  function createTemplateTail(cooked, raw) {
219
- const node = ts.createTemplateHead(cooked, raw);
220
- node.kind = ts.SyntaxKind.TemplateTail;
212
+ const node = typescript_1.default.factory.createTemplateHead(cooked, raw);
213
+ node.kind = typescript_1.default.SyntaxKind.TemplateTail;
221
214
  return node;
222
215
  }
223
216
  exports.createTemplateTail = createTemplateTail;
@@ -230,14 +223,14 @@ exports.createTemplateTail = createTemplateTail;
230
223
  function attachComments(statement, leadingComments) {
231
224
  for (const comment of leadingComments) {
232
225
  const commentKind = comment.multiline
233
- ? ts.SyntaxKind.MultiLineCommentTrivia
234
- : ts.SyntaxKind.SingleLineCommentTrivia;
226
+ ? typescript_1.default.SyntaxKind.MultiLineCommentTrivia
227
+ : typescript_1.default.SyntaxKind.SingleLineCommentTrivia;
235
228
  if (comment.multiline) {
236
- ts.addSyntheticLeadingComment(statement, commentKind, comment.toString(), comment.trailingNewline);
229
+ typescript_1.default.addSyntheticLeadingComment(statement, commentKind, comment.toString(), comment.trailingNewline);
237
230
  }
238
231
  else {
239
- for (const line of comment.toString().split("\n")) {
240
- ts.addSyntheticLeadingComment(statement, commentKind, line, comment.trailingNewline);
232
+ for (const line of comment.toString().split('\n')) {
233
+ typescript_1.default.addSyntheticLeadingComment(statement, commentKind, line, comment.trailingNewline);
241
234
  }
242
235
  }
243
236
  }
@@ -5,9 +5,9 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import * as o from "../../../../../compiler";
9
- import * as ts from "typescript";
10
- import { ImportGenerator } from "./api/import_generator";
11
- import { TranslatorOptions } from "./translator";
8
+ import * as o from 'static-injector/transform/compiler';
9
+ import ts from 'typescript';
10
+ import { ImportGenerator } from './api/import_generator';
11
+ import { TranslatorOptions } from './translator';
12
12
  export declare function translateExpression(expression: o.Expression, imports: ImportGenerator<ts.Expression>, options?: TranslatorOptions<ts.Expression>): ts.Expression;
13
13
  export declare function translateStatement(statement: o.Statement, imports: ImportGenerator<ts.Expression>, options?: TranslatorOptions<ts.Expression>): ts.Statement;
@@ -0,0 +1,8 @@
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 * from './src/ts_cross_version_utils';
@@ -0,0 +1,24 @@
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
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ __exportStar(require("./src/ts_cross_version_utils"), exports);
@@ -0,0 +1,45 @@
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
+ /** Type of `ts.factory.CreateParameterDeclaration` in TS 4.9+. */
10
+ type Ts49CreateParameterDeclarationFn = (modifiers: readonly ts.ModifierLike[] | undefined, dotDotDotToken: ts.DotDotDotToken | undefined, name: string | ts.BindingName, questionToken?: ts.QuestionToken | undefined, type?: ts.TypeNode | undefined, initializer?: ts.Expression) => ts.ParameterDeclaration;
11
+ /**
12
+ * Creates a `ts.ParameterDeclaration` declaration.
13
+ *
14
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
15
+ * We should remove it once we have dropped support for the older versions.
16
+ */
17
+ export declare const createParameterDeclaration: Ts49CreateParameterDeclarationFn;
18
+ /** Type of `ts.factory.createImportDeclaration` in TS 4.9+. */
19
+ type Ts49CreateImportDeclarationFn = (modifiers: readonly ts.Modifier[] | undefined, importClause: ts.ImportClause | undefined, moduleSpecifier: ts.Expression, assertClause?: ts.AssertClause) => ts.ImportDeclaration;
20
+ /**
21
+ * Creates a `ts.ImportDeclaration` declaration.
22
+ *
23
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
24
+ * We should remove it once we have dropped support for the older versions.
25
+ */
26
+ export declare const createImportDeclaration: Ts49CreateImportDeclarationFn;
27
+ /** Type of `ts.factory.createFunctionDeclaration` in TS 4.9+. */
28
+ type Ts49CreateFunctionDeclarationFn = (modifiers: readonly ts.ModifierLike[] | undefined, asteriskToken: ts.AsteriskToken | undefined, name: string | ts.Identifier | undefined, typeParameters: readonly ts.TypeParameterDeclaration[] | undefined, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode | undefined, body: ts.Block | undefined) => ts.FunctionDeclaration;
29
+ /**
30
+ * Creates a `ts.FunctionDeclaration` declaration.
31
+ *
32
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
33
+ * We should remove it once we have dropped support for the older versions.
34
+ */
35
+ export declare const createFunctionDeclaration: Ts49CreateFunctionDeclarationFn;
36
+ /** Type of `ts.factory.createIndexSignature` in TS 4.9+. */
37
+ type Ts49CreateIndexSignatureFn = (modifiers: readonly ts.Modifier[] | undefined, parameters: readonly ts.ParameterDeclaration[], type: ts.TypeNode) => ts.IndexSignatureDeclaration;
38
+ /**
39
+ * Creates a `ts.IndexSignatureDeclaration` declaration.
40
+ *
41
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
42
+ * We should remove it once we have dropped support for the older versions.
43
+ */
44
+ export declare const createIndexSignature: Ts49CreateIndexSignatureFn;
45
+ export {};
@@ -0,0 +1,86 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.createIndexSignature = exports.createFunctionDeclaration = exports.createImportDeclaration = exports.createParameterDeclaration = void 0;
14
+ const typescript_1 = __importDefault(require("typescript"));
15
+ /** Whether the current TypeScript version is after 4.9. */
16
+ const IS_AFTER_TS_49 = isAfterVersion(4, 9);
17
+ /**
18
+ * Creates a `ts.ParameterDeclaration` declaration.
19
+ *
20
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
21
+ * We should remove it once we have dropped support for the older versions.
22
+ */
23
+ exports.createParameterDeclaration = IS_AFTER_TS_49
24
+ ? typescript_1.default.factory.createParameterDeclaration
25
+ : (modifiers, dotDotDotToken, name, questionToken, type, initializer) => typescript_1.default.factory.createParameterDeclaration(...splitModifiers(modifiers), dotDotDotToken, name, questionToken, type, initializer);
26
+ /**
27
+ * Creates a `ts.ImportDeclaration` declaration.
28
+ *
29
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
30
+ * We should remove it once we have dropped support for the older versions.
31
+ */
32
+ exports.createImportDeclaration = IS_AFTER_TS_49
33
+ ? typescript_1.default.factory.createImportDeclaration
34
+ : (modifiers, importClause, moduleSpecifier, assertClause) => typescript_1.default.factory.createImportDeclaration(undefined, modifiers, importClause, moduleSpecifier, assertClause);
35
+ /**
36
+ * Creates a `ts.FunctionDeclaration` declaration.
37
+ *
38
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
39
+ * We should remove it once we have dropped support for the older versions.
40
+ */
41
+ exports.createFunctionDeclaration = IS_AFTER_TS_49
42
+ ? typescript_1.default.factory.createFunctionDeclaration
43
+ : (modifiers, asteriskToken, name, typeParameters, parameters, type, body) => typescript_1.default.factory.createFunctionDeclaration(...splitModifiers(modifiers), asteriskToken, name, typeParameters, parameters, type, body);
44
+ /**
45
+ * Creates a `ts.IndexSignatureDeclaration` declaration.
46
+ *
47
+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.9.
48
+ * We should remove it once we have dropped support for the older versions.
49
+ */
50
+ exports.createIndexSignature = IS_AFTER_TS_49
51
+ ? typescript_1.default.factory.createIndexSignature
52
+ : (modifiers, parameters, type) => typescript_1.default.factory.createIndexSignature(modifiers, parameters, type);
53
+ /**
54
+ * Splits a `ModifierLike` into two arrays: decorators and modifiers. Used for backwards
55
+ * compatibility with TS 4.7 and below where most factory functions require separate `decorators`
56
+ * and `modifiers` arrays.
57
+ */
58
+ function splitModifiers(allModifiers) {
59
+ if (!allModifiers) {
60
+ return [undefined, undefined];
61
+ }
62
+ const decorators = [];
63
+ const modifiers = [];
64
+ for (const current of allModifiers) {
65
+ if (typescript_1.default.isDecorator(current)) {
66
+ decorators.push(current);
67
+ }
68
+ else {
69
+ modifiers.push(current);
70
+ }
71
+ }
72
+ return [
73
+ decorators.length ? decorators : undefined,
74
+ modifiers.length ? modifiers : undefined,
75
+ ];
76
+ }
77
+ /** Checks if the current version of TypeScript is after the specified major/minor versions. */
78
+ function isAfterVersion(targetMajor, targetMinor) {
79
+ const [major, minor] = typescript_1.default.versionMajorMinor
80
+ .split('.')
81
+ .map((part) => parseInt(part));
82
+ if (major < targetMajor) {
83
+ return false;
84
+ }
85
+ return major === targetMajor ? minor >= targetMinor : true;
86
+ }
@@ -1,11 +1,4 @@
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";
1
+ import ts from 'typescript';
9
2
  export declare function identifierOfNode(decl: ts.Node & {
10
3
  name?: ts.Node;
11
4
  }): ts.Identifier | null;
@@ -1,35 +1,12 @@
1
1
  "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
- 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;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
6
  exports.identifierOfNode = void 0;
30
- const ts = __importStar(require("typescript"));
7
+ const typescript_1 = __importDefault(require("typescript"));
31
8
  function identifierOfNode(decl) {
32
- if (decl.name !== undefined && ts.isIdentifier(decl.name)) {
9
+ if (decl.name !== undefined && typescript_1.default.isIdentifier(decl.name)) {
33
10
  return decl.name;
34
11
  }
35
12
  else {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];