static-injector 2.0.0 → 2.1.1
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.
- package/import/commonjs/index.js +425 -163
- package/import/es2015/di/create_injector.js +5 -1
- package/import/es2015/di/forward_ref.js +3 -3
- package/import/es2015/di/injection_token.js +18 -11
- package/import/es2015/di/injector_compatibility.js +19 -10
- package/import/es2015/di/injector_token.js +3 -3
- package/import/es2015/di/interface/defs.js +21 -12
- package/import/es2015/di/interface/provider.js +3 -1
- package/import/es2015/di/null_injector.js +3 -3
- package/import/es2015/di/provider_collection.js +196 -1
- package/import/es2015/di/r3_injector.js +31 -28
- package/import/es2015/error_details_base_url.js +19 -0
- package/import/es2015/errors.js +42 -0
- package/import/es2015/interface/type.js +14 -1
- package/import/es2015/render3/definition_factory.js +2 -3
- package/import/es2015/render3/errors_di.js +2 -3
- package/import/es2015/render3/instructions/di.js +0 -7
- package/import/es2015/render3/util/stringify_utils.js +5 -5
- package/import/es2015/util/array_utils.js +0 -7
- package/import/es2015/util/decorators.js +24 -1
- package/import/es2015/util/empty.js +4 -0
- package/import/es2015/util/stringify.js +5 -5
- package/import/fesm2015/index.js +422 -161
- package/import/typings/di/forward_ref.d.ts +1 -1
- package/import/typings/di/injectable.d.ts +5 -4
- package/import/typings/di/injection_token.d.ts +21 -6
- package/import/typings/di/injector.d.ts +16 -0
- package/import/typings/di/injector_compatibility.d.ts +11 -5
- package/import/typings/di/injector_token.d.ts +2 -2
- package/import/typings/di/interface/defs.d.ts +15 -8
- package/import/typings/di/interface/provider.d.ts +62 -2
- package/import/typings/di/null_injector.d.ts +1 -1
- package/import/typings/di/provider_collection.d.ts +55 -2
- package/import/typings/di/provider_token.d.ts +3 -3
- package/import/typings/di/r3_injector.d.ts +3 -8
- package/import/typings/di/scope.d.ts +1 -1
- package/import/typings/error_details_base_url.d.ts +19 -0
- package/import/typings/errors.d.ts +89 -0
- package/import/typings/interface/type.d.ts +45 -0
- package/import/typings/render3/definition_factory.d.ts +1 -1
- package/import/typings/render3/errors_di.d.ts +7 -0
- package/import/typings/render3/instructions/di.d.ts +0 -7
- package/import/typings/util/array_utils.d.ts +15 -7
- package/import/typings/util/decorators.d.ts +2 -1
- package/import/typings/util/empty.d.ts +1 -0
- package/package.json +3 -3
- package/transform/compiler/compiler.d.ts +8 -0
- package/transform/compiler/compiler.js +28 -0
- package/transform/compiler/index.d.ts +8 -5
- package/transform/compiler/index.js +12 -5
- package/transform/compiler/public_api.d.ts +13 -0
- package/transform/compiler/public_api.js +30 -0
- package/transform/compiler/src/compiler.d.ts +27 -0
- package/transform/compiler/src/compiler.js +47 -0
- package/transform/compiler/src/output/output_ast.d.ts +1 -1
- package/transform/compiler/src/render3/partial/api.d.ts +1 -1
- package/transform/compiler/src/render3/partial/api.js +7 -0
- package/transform/compiler/src/render3/r3_factory.d.ts +8 -15
- package/transform/compiler/src/render3/r3_factory.js +37 -56
- package/transform/compiler/src/render3/view/util.d.ts +0 -8
- package/transform/compiler/src/render3/view/util.js +0 -8
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +10 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +26 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +37 -0
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +197 -0
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.d.ts +3 -3
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/factory.js +2 -2
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +3 -34
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +18 -216
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +31 -50
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +19 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/default.js +28 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +10 -3
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +12 -13
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +7 -28
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +17 -41
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +46 -65
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -27
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/transform/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +15 -35
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
- package/transform/compiler-cli/src/ngtsc/translator/index.js +7 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +5 -5
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +4 -24
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +1 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +76 -95
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +20 -126
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +23 -147
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -31
- package/transform/injectable-transform.js +36 -7
|
@@ -6,33 +6,12 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
-
var
|
|
10
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
11
|
};
|
|
32
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
13
|
exports.reflectObjectLiteral = exports.TypeScriptReflectionHost = void 0;
|
|
34
|
-
const
|
|
35
|
-
const ts_compatibility_1 = require("../../ts_compatibility");
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
36
15
|
const host_1 = require("./host");
|
|
37
16
|
const type_to_value_1 = require("./type_to_value");
|
|
38
17
|
const util_1 = require("./util");
|
|
@@ -44,7 +23,9 @@ class TypeScriptReflectionHost {
|
|
|
44
23
|
this.checker = checker;
|
|
45
24
|
}
|
|
46
25
|
getDecoratorsOfDeclaration(declaration) {
|
|
47
|
-
const decorators =
|
|
26
|
+
const decorators = typescript_1.default.canHaveDecorators(declaration)
|
|
27
|
+
? typescript_1.default.getDecorators(declaration)
|
|
28
|
+
: undefined;
|
|
48
29
|
return decorators !== undefined && decorators.length
|
|
49
30
|
? decorators
|
|
50
31
|
.map((decorator) => this._reflectDecorator(decorator))
|
|
@@ -64,7 +45,7 @@ class TypeScriptReflectionHost {
|
|
|
64
45
|
// without a `body` are overloads whereas we want the implementation since it's the one that'll
|
|
65
46
|
// be executed and which can have decorators. For declaration files, we take the first one that
|
|
66
47
|
// we get.
|
|
67
|
-
const ctor = tsClazz.members.find((member) =>
|
|
48
|
+
const ctor = tsClazz.members.find((member) => typescript_1.default.isConstructorDeclaration(member) &&
|
|
68
49
|
(isDeclaration || member.body !== undefined));
|
|
69
50
|
if (ctor === undefined) {
|
|
70
51
|
return null;
|
|
@@ -81,9 +62,9 @@ class TypeScriptReflectionHost {
|
|
|
81
62
|
// and extract the type. More complex union types e.g. `foo: Foo|Bar` are not supported.
|
|
82
63
|
// We also don't need to support `foo: Foo|undefined` because Angular's DI injects `null` for
|
|
83
64
|
// optional tokes that don't have providers.
|
|
84
|
-
if (typeNode &&
|
|
85
|
-
let childTypeNodes = typeNode.types.filter((childTypeNode) => !(
|
|
86
|
-
childTypeNode.literal.kind ===
|
|
65
|
+
if (typeNode && typescript_1.default.isUnionTypeNode(typeNode)) {
|
|
66
|
+
let childTypeNodes = typeNode.types.filter((childTypeNode) => !(typescript_1.default.isLiteralTypeNode(childTypeNode) &&
|
|
67
|
+
childTypeNode.literal.kind === typescript_1.default.SyntaxKind.NullKeyword));
|
|
87
68
|
if (childTypeNodes.length === 1) {
|
|
88
69
|
typeNode = childTypeNodes[0];
|
|
89
70
|
}
|
|
@@ -103,10 +84,10 @@ class TypeScriptReflectionHost {
|
|
|
103
84
|
if (directImport !== null) {
|
|
104
85
|
return directImport;
|
|
105
86
|
}
|
|
106
|
-
else if (
|
|
87
|
+
else if (typescript_1.default.isQualifiedName(id.parent) && id.parent.right === id) {
|
|
107
88
|
return this.getImportOfNamespacedIdentifier(id, getQualifiedNameRoot(id.parent));
|
|
108
89
|
}
|
|
109
|
-
else if (
|
|
90
|
+
else if (typescript_1.default.isPropertyAccessExpression(id.parent) &&
|
|
110
91
|
id.parent.name === id) {
|
|
111
92
|
return this.getImportOfNamespacedIdentifier(id, getFarLeftIdentifier(id.parent));
|
|
112
93
|
}
|
|
@@ -123,11 +104,11 @@ class TypeScriptReflectionHost {
|
|
|
123
104
|
return this.getBaseClassExpression(clazz) !== null;
|
|
124
105
|
}
|
|
125
106
|
getBaseClassExpression(clazz) {
|
|
126
|
-
if (!(
|
|
107
|
+
if (!(typescript_1.default.isClassDeclaration(clazz) || typescript_1.default.isClassExpression(clazz)) ||
|
|
127
108
|
clazz.heritageClauses === undefined) {
|
|
128
109
|
return null;
|
|
129
110
|
}
|
|
130
|
-
const extendsClause = clazz.heritageClauses.find((clause) => clause.token ===
|
|
111
|
+
const extendsClause = clazz.heritageClauses.find((clause) => clause.token === typescript_1.default.SyntaxKind.ExtendsKeyword);
|
|
131
112
|
if (extendsClause === undefined) {
|
|
132
113
|
return null;
|
|
133
114
|
}
|
|
@@ -138,7 +119,7 @@ class TypeScriptReflectionHost {
|
|
|
138
119
|
return extendsType.expression;
|
|
139
120
|
}
|
|
140
121
|
getGenericArityOfClass(clazz) {
|
|
141
|
-
if (!
|
|
122
|
+
if (!typescript_1.default.isClassDeclaration(clazz)) {
|
|
142
123
|
return null;
|
|
143
124
|
}
|
|
144
125
|
return clazz.typeParameters !== undefined ? clazz.typeParameters.length : 0;
|
|
@@ -166,7 +147,7 @@ class TypeScriptReflectionHost {
|
|
|
166
147
|
return null;
|
|
167
148
|
}
|
|
168
149
|
// The module specifier is guaranteed to be a string literal, so this should always pass.
|
|
169
|
-
if (!
|
|
150
|
+
if (!typescript_1.default.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
170
151
|
// Not allowed to happen in TypeScript ASTs.
|
|
171
152
|
return null;
|
|
172
153
|
}
|
|
@@ -207,14 +188,14 @@ class TypeScriptReflectionHost {
|
|
|
207
188
|
if (!declaration) {
|
|
208
189
|
return null;
|
|
209
190
|
}
|
|
210
|
-
const namespaceDeclaration =
|
|
191
|
+
const namespaceDeclaration = typescript_1.default.isNamespaceImport(declaration)
|
|
211
192
|
? declaration
|
|
212
193
|
: null;
|
|
213
194
|
if (!namespaceDeclaration) {
|
|
214
195
|
return null;
|
|
215
196
|
}
|
|
216
197
|
const importDeclaration = namespaceDeclaration.parent.parent;
|
|
217
|
-
if (!
|
|
198
|
+
if (!typescript_1.default.isStringLiteral(importDeclaration.moduleSpecifier)) {
|
|
218
199
|
// Should not happen as this would be invalid TypesScript
|
|
219
200
|
return null;
|
|
220
201
|
}
|
|
@@ -230,7 +211,7 @@ class TypeScriptReflectionHost {
|
|
|
230
211
|
let decoratorExpr = node.expression;
|
|
231
212
|
let args = null;
|
|
232
213
|
// Check for call expressions.
|
|
233
|
-
if (
|
|
214
|
+
if (typescript_1.default.isCallExpression(decoratorExpr)) {
|
|
234
215
|
args = Array.from(decoratorExpr.arguments);
|
|
235
216
|
decoratorExpr = decoratorExpr.expression;
|
|
236
217
|
}
|
|
@@ -239,7 +220,7 @@ class TypeScriptReflectionHost {
|
|
|
239
220
|
if (!(0, host_1.isDecoratorIdentifier)(decoratorExpr)) {
|
|
240
221
|
return null;
|
|
241
222
|
}
|
|
242
|
-
const decoratorIdentifier =
|
|
223
|
+
const decoratorIdentifier = typescript_1.default.isIdentifier(decoratorExpr)
|
|
243
224
|
? decoratorExpr
|
|
244
225
|
: decoratorExpr.name;
|
|
245
226
|
const importDecl = this.getImportOfIdentifier(decoratorIdentifier);
|
|
@@ -256,33 +237,33 @@ class TypeScriptReflectionHost {
|
|
|
256
237
|
let value = null;
|
|
257
238
|
let name = null;
|
|
258
239
|
let nameNode = null;
|
|
259
|
-
if (
|
|
240
|
+
if (typescript_1.default.isPropertyDeclaration(node)) {
|
|
260
241
|
kind = host_1.ClassMemberKind.Property;
|
|
261
242
|
value = node.initializer || null;
|
|
262
243
|
}
|
|
263
|
-
else if (
|
|
244
|
+
else if (typescript_1.default.isGetAccessorDeclaration(node)) {
|
|
264
245
|
kind = host_1.ClassMemberKind.Getter;
|
|
265
246
|
}
|
|
266
|
-
else if (
|
|
247
|
+
else if (typescript_1.default.isSetAccessorDeclaration(node)) {
|
|
267
248
|
kind = host_1.ClassMemberKind.Setter;
|
|
268
249
|
}
|
|
269
|
-
else if (
|
|
250
|
+
else if (typescript_1.default.isMethodDeclaration(node)) {
|
|
270
251
|
kind = host_1.ClassMemberKind.Method;
|
|
271
252
|
}
|
|
272
|
-
else if (
|
|
253
|
+
else if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
273
254
|
kind = host_1.ClassMemberKind.Constructor;
|
|
274
255
|
}
|
|
275
256
|
else {
|
|
276
257
|
return null;
|
|
277
258
|
}
|
|
278
|
-
if (
|
|
259
|
+
if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
279
260
|
name = 'constructor';
|
|
280
261
|
}
|
|
281
|
-
else if (
|
|
262
|
+
else if (typescript_1.default.isIdentifier(node.name)) {
|
|
282
263
|
name = node.name.text;
|
|
283
264
|
nameNode = node.name;
|
|
284
265
|
}
|
|
285
|
-
else if (
|
|
266
|
+
else if (typescript_1.default.isStringLiteral(node.name)) {
|
|
286
267
|
name = node.name.text;
|
|
287
268
|
nameNode = node.name;
|
|
288
269
|
}
|
|
@@ -290,9 +271,9 @@ class TypeScriptReflectionHost {
|
|
|
290
271
|
return null;
|
|
291
272
|
}
|
|
292
273
|
const decorators = this.getDecoratorsOfDeclaration(node);
|
|
293
|
-
const modifiers =
|
|
274
|
+
const modifiers = typescript_1.default.getModifiers(node);
|
|
294
275
|
const isStatic = modifiers !== undefined &&
|
|
295
|
-
modifiers.some((mod) => mod.kind ===
|
|
276
|
+
modifiers.some((mod) => mod.kind === typescript_1.default.SyntaxKind.StaticKeyword);
|
|
296
277
|
return {
|
|
297
278
|
node,
|
|
298
279
|
implementation: node,
|
|
@@ -310,14 +291,14 @@ exports.TypeScriptReflectionHost = TypeScriptReflectionHost;
|
|
|
310
291
|
function reflectObjectLiteral(node) {
|
|
311
292
|
const map = new Map();
|
|
312
293
|
node.properties.forEach((prop) => {
|
|
313
|
-
if (
|
|
294
|
+
if (typescript_1.default.isPropertyAssignment(prop)) {
|
|
314
295
|
const name = propertyNameToString(prop.name);
|
|
315
296
|
if (name === null) {
|
|
316
297
|
return;
|
|
317
298
|
}
|
|
318
299
|
map.set(name, prop.initializer);
|
|
319
300
|
}
|
|
320
|
-
else if (
|
|
301
|
+
else if (typescript_1.default.isShorthandPropertyAssignment(prop)) {
|
|
321
302
|
map.set(prop.name.text, prop.name);
|
|
322
303
|
}
|
|
323
304
|
else {
|
|
@@ -328,13 +309,13 @@ function reflectObjectLiteral(node) {
|
|
|
328
309
|
}
|
|
329
310
|
exports.reflectObjectLiteral = reflectObjectLiteral;
|
|
330
311
|
function castDeclarationToClassOrDie(declaration) {
|
|
331
|
-
if (!
|
|
332
|
-
throw new Error(`Reflecting on a ${
|
|
312
|
+
if (!typescript_1.default.isClassDeclaration(declaration)) {
|
|
313
|
+
throw new Error(`Reflecting on a ${typescript_1.default.SyntaxKind[declaration.kind]} instead of a ClassDeclaration.`);
|
|
333
314
|
}
|
|
334
315
|
return declaration;
|
|
335
316
|
}
|
|
336
317
|
function parameterName(name) {
|
|
337
|
-
if (
|
|
318
|
+
if (typescript_1.default.isIdentifier(name)) {
|
|
338
319
|
return name.text;
|
|
339
320
|
}
|
|
340
321
|
else {
|
|
@@ -342,9 +323,9 @@ function parameterName(name) {
|
|
|
342
323
|
}
|
|
343
324
|
}
|
|
344
325
|
function propertyNameToString(node) {
|
|
345
|
-
if (
|
|
346
|
-
|
|
347
|
-
|
|
326
|
+
if (typescript_1.default.isIdentifier(node) ||
|
|
327
|
+
typescript_1.default.isStringLiteral(node) ||
|
|
328
|
+
typescript_1.default.isNumericLiteral(node)) {
|
|
348
329
|
return node.text;
|
|
349
330
|
}
|
|
350
331
|
else {
|
|
@@ -358,10 +339,10 @@ function propertyNameToString(node) {
|
|
|
358
339
|
* @returns the left most identifier in the chain or `null` if it is not an identifier.
|
|
359
340
|
*/
|
|
360
341
|
function getQualifiedNameRoot(qualifiedName) {
|
|
361
|
-
while (
|
|
342
|
+
while (typescript_1.default.isQualifiedName(qualifiedName.left)) {
|
|
362
343
|
qualifiedName = qualifiedName.left;
|
|
363
344
|
}
|
|
364
|
-
return
|
|
345
|
+
return typescript_1.default.isIdentifier(qualifiedName.left) ? qualifiedName.left : null;
|
|
365
346
|
}
|
|
366
347
|
/**
|
|
367
348
|
* Compute the left most identifier in a property access chain. E.g. the `a` of `a.b.c.d`.
|
|
@@ -370,10 +351,10 @@ function getQualifiedNameRoot(qualifiedName) {
|
|
|
370
351
|
* @returns the left most identifier in the chain or `null` if it is not an identifier.
|
|
371
352
|
*/
|
|
372
353
|
function getFarLeftIdentifier(propertyAccess) {
|
|
373
|
-
while (
|
|
354
|
+
while (typescript_1.default.isPropertyAccessExpression(propertyAccess.expression)) {
|
|
374
355
|
propertyAccess = propertyAccess.expression;
|
|
375
356
|
}
|
|
376
|
-
return
|
|
357
|
+
return typescript_1.default.isIdentifier(propertyAccess.expression)
|
|
377
358
|
? propertyAccess.expression
|
|
378
359
|
: null;
|
|
379
360
|
}
|
|
@@ -382,9 +363,9 @@ function getFarLeftIdentifier(propertyAccess) {
|
|
|
382
363
|
* `NamespaceImport`. If not return `null`.
|
|
383
364
|
*/
|
|
384
365
|
function getContainingImportDeclaration(node) {
|
|
385
|
-
return
|
|
366
|
+
return typescript_1.default.isImportSpecifier(node)
|
|
386
367
|
? node.parent.parent.parent
|
|
387
|
-
:
|
|
368
|
+
: typescript_1.default.isNamespaceImport(node)
|
|
388
369
|
? node.parent.parent
|
|
389
370
|
: null;
|
|
390
371
|
}
|
|
@@ -394,8 +375,8 @@ function getContainingImportDeclaration(node) {
|
|
|
394
375
|
* then fallback to the `originalId`.
|
|
395
376
|
*/
|
|
396
377
|
function getExportedName(decl, originalId) {
|
|
397
|
-
return
|
|
378
|
+
return typescript_1.default.isImportSpecifier(decl)
|
|
398
379
|
? (decl.propertyName !== undefined ? decl.propertyName : decl.name).text
|
|
399
380
|
: originalId.text;
|
|
400
381
|
}
|
|
401
|
-
const
|
|
382
|
+
const LocalExportedDeclarations = Symbol('LocalExportedDeclarations');
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import { ClassDeclaration } from
|
|
8
|
+
import ts from 'typescript';
|
|
9
|
+
import { ClassDeclaration } from './host';
|
|
10
10
|
export declare function isNamedClassDeclaration(node: ts.Node): node is ClassDeclaration<ts.ClassDeclaration>;
|
|
11
11
|
export declare function isNamedFunctionDeclaration(node: ts.Node): node is ClassDeclaration<ts.FunctionDeclaration>;
|
|
12
12
|
export declare function isNamedVariableDeclaration(node: ts.Node): node is ClassDeclaration<ts.VariableDeclaration>;
|
|
@@ -6,44 +6,24 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
-
var
|
|
10
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
11
|
};
|
|
32
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
13
|
exports.isNamedVariableDeclaration = exports.isNamedFunctionDeclaration = exports.isNamedClassDeclaration = void 0;
|
|
34
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
35
15
|
function isNamedClassDeclaration(node) {
|
|
36
|
-
return
|
|
16
|
+
return typescript_1.default.isClassDeclaration(node) && isIdentifier(node.name);
|
|
37
17
|
}
|
|
38
18
|
exports.isNamedClassDeclaration = isNamedClassDeclaration;
|
|
39
19
|
function isNamedFunctionDeclaration(node) {
|
|
40
|
-
return
|
|
20
|
+
return typescript_1.default.isFunctionDeclaration(node) && isIdentifier(node.name);
|
|
41
21
|
}
|
|
42
22
|
exports.isNamedFunctionDeclaration = isNamedFunctionDeclaration;
|
|
43
23
|
function isNamedVariableDeclaration(node) {
|
|
44
|
-
return
|
|
24
|
+
return typescript_1.default.isVariableDeclaration(node) && isIdentifier(node.name);
|
|
45
25
|
}
|
|
46
26
|
exports.isNamedVariableDeclaration = isNamedVariableDeclaration;
|
|
47
27
|
function isIdentifier(node) {
|
|
48
|
-
return node !== undefined &&
|
|
28
|
+
return node !== undefined && typescript_1.default.isIdentifier(node);
|
|
49
29
|
}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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/api';
|
|
9
|
+
export * from './src/utils';
|
|
@@ -1,4 +1,11 @@
|
|
|
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
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -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 { Expression, Statement, Type } from
|
|
9
|
-
import
|
|
10
|
-
import { ClassDeclaration, Decorator } from
|
|
8
|
+
import { Expression, Statement, Type } from 'static-injector/transform/compiler';
|
|
9
|
+
import ts from 'typescript';
|
|
10
|
+
import { ClassDeclaration, Decorator } from '../../reflection';
|
|
11
11
|
/**
|
|
12
12
|
* A set of options which can be passed to a `DecoratorHandler` by a consumer, to tailor the output
|
|
13
13
|
* of compilation beyond the decorators themselves.
|
|
@@ -39,7 +39,7 @@ export declare enum HandlerFlags {
|
|
|
39
39
|
* @param `A` The type of analysis metadata produced by `analyze`.
|
|
40
40
|
* @param `R` The type of resolution metadata produced by `resolve`.
|
|
41
41
|
*/
|
|
42
|
-
export interface DecoratorHandler<D, A,
|
|
42
|
+
export interface DecoratorHandler<D, A, R> {
|
|
43
43
|
/**
|
|
44
44
|
* Scan a set of reflected decorators and determine if this handler is responsible for compilation
|
|
45
45
|
* of one of them.
|
|
@@ -5,7 +5,7 @@
|
|
|
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
|
|
8
|
+
import ts from 'typescript';
|
|
9
9
|
import { ImportManager } from '../../translator';
|
|
10
10
|
/**
|
|
11
11
|
* Adds extra imports in the import manage for this source file, after the existing imports
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.addImports = void 0;
|
|
@@ -31,7 +11,8 @@ exports.addImports = void 0;
|
|
|
31
11
|
* Use of this source code is governed by an MIT-style license that can be
|
|
32
12
|
* found in the LICENSE file at https://angular.io/license
|
|
33
13
|
*/
|
|
34
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
const ts_compatibility_1 = require("../../ts_compatibility");
|
|
35
16
|
/**
|
|
36
17
|
* Adds extra imports in the import manage for this source file, after the existing imports
|
|
37
18
|
* and before the module body.
|
|
@@ -40,16 +21,15 @@ const ts = __importStar(require("typescript"));
|
|
|
40
21
|
function addImports(importManager, sf, extraStatements = []) {
|
|
41
22
|
// Generate the import statements to prepend.
|
|
42
23
|
const addedImports = importManager.getAllImports(sf.fileName).map((i) => {
|
|
43
|
-
const qualifier =
|
|
44
|
-
const importClause =
|
|
24
|
+
const qualifier = typescript_1.default.factory.createIdentifier(i.qualifier.text);
|
|
25
|
+
const importClause = typescript_1.default.factory.createImportClause(
|
|
45
26
|
/* isTypeOnly */ false,
|
|
46
27
|
/* name */ undefined,
|
|
47
|
-
/* namedBindings */
|
|
48
|
-
const decl =
|
|
49
|
-
/* decorators */ undefined,
|
|
28
|
+
/* namedBindings */ typescript_1.default.factory.createNamespaceImport(qualifier));
|
|
29
|
+
const decl = (0, ts_compatibility_1.createImportDeclaration)(
|
|
50
30
|
/* modifiers */ undefined,
|
|
51
31
|
/* importClause */ importClause,
|
|
52
|
-
/* moduleSpecifier */
|
|
32
|
+
/* moduleSpecifier */ typescript_1.default.factory.createStringLiteral(i.specifier));
|
|
53
33
|
// Set the qualifier's original TS node to the `ts.ImportDeclaration`. This allows downstream
|
|
54
34
|
// transforms such as tsickle to properly process references to this import.
|
|
55
35
|
//
|
|
@@ -58,7 +38,7 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
58
38
|
//
|
|
59
39
|
// TODO(alxhub): add a test for this when tsickle is updated externally to depend on this
|
|
60
40
|
// behavior.
|
|
61
|
-
|
|
41
|
+
typescript_1.default.setOriginalNode(i.qualifier, decl);
|
|
62
42
|
return decl;
|
|
63
43
|
});
|
|
64
44
|
// Filter out the existing imports and the source file body. All new statements
|
|
@@ -70,8 +50,8 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
70
50
|
// If we prepend imports, we also prepend NotEmittedStatement to use it as an anchor
|
|
71
51
|
// for @fileoverview Closure annotation. If there is no @fileoverview annotations, this
|
|
72
52
|
// statement would be a noop.
|
|
73
|
-
const fileoverviewAnchorStmt =
|
|
74
|
-
return
|
|
53
|
+
const fileoverviewAnchorStmt = typescript_1.default.factory.createNotEmittedStatement(sf);
|
|
54
|
+
return typescript_1.default.factory.updateSourceFile(sf, typescript_1.default.factory.createNodeArray([
|
|
75
55
|
fileoverviewAnchorStmt,
|
|
76
56
|
...existingImports,
|
|
77
57
|
...addedImports,
|
|
@@ -83,7 +63,7 @@ function addImports(importManager, sf, extraStatements = []) {
|
|
|
83
63
|
}
|
|
84
64
|
exports.addImports = addImports;
|
|
85
65
|
function isImportStatement(stmt) {
|
|
86
|
-
return (
|
|
87
|
-
|
|
88
|
-
|
|
66
|
+
return (typescript_1.default.isImportDeclaration(stmt) ||
|
|
67
|
+
typescript_1.default.isImportEqualsDeclaration(stmt) ||
|
|
68
|
+
typescript_1.default.isNamespaceImport(stmt));
|
|
89
69
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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/context';
|
|
9
|
+
export * from './src/translator';
|
|
10
|
+
export * from './src/typescript_ast_factory';
|
|
11
|
+
export * from './src/typescript_translator';
|
|
12
|
+
export * from './src/import_manager';
|
|
@@ -1,4 +1,11 @@
|
|
|
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
|
+
*/
|
|
2
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
10
|
if (k2 === undefined) k2 = k;
|
|
4
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -21,7 +21,7 @@ export interface AstFactory<TStatement, TExpression> {
|
|
|
21
21
|
*/
|
|
22
22
|
attachComments(statement: TStatement, leadingComments: LeadingComment[]): void;
|
|
23
23
|
/**
|
|
24
|
-
* Create a literal array
|
|
24
|
+
* Create a literal array expression (e.g. `[expr1, expr2]`).
|
|
25
25
|
*
|
|
26
26
|
* @param elements a collection of the expressions to appear in each array slot.
|
|
27
27
|
*/
|
|
@@ -51,7 +51,7 @@ export interface AstFactory<TStatement, TExpression> {
|
|
|
51
51
|
* Create an expression that is calling the `callee` with the given `args`.
|
|
52
52
|
*
|
|
53
53
|
* @param callee an expression that evaluates to a function to be called.
|
|
54
|
-
* @param args the
|
|
54
|
+
* @param args the arguments to be passed to the call.
|
|
55
55
|
* @param pure whether to mark the call as pure (having no side-effects).
|
|
56
56
|
*/
|
|
57
57
|
createCallExpression(callee: TExpression, args: TExpression[], pure: boolean): TExpression;
|
|
@@ -198,15 +198,15 @@ export interface AstFactory<TStatement, TExpression> {
|
|
|
198
198
|
/**
|
|
199
199
|
* The type of a variable declaration.
|
|
200
200
|
*/
|
|
201
|
-
export
|
|
201
|
+
export type VariableDeclarationType = 'const' | 'let' | 'var';
|
|
202
202
|
/**
|
|
203
203
|
* The unary operators supported by the `AstFactory`.
|
|
204
204
|
*/
|
|
205
|
-
export
|
|
205
|
+
export type UnaryOperator = '+' | '-' | '!';
|
|
206
206
|
/**
|
|
207
207
|
* The binary operators supported by the `AstFactory`.
|
|
208
208
|
*/
|
|
209
|
-
export
|
|
209
|
+
export type BinaryOperator = '&&' | '>' | '>=' | '&' | '/' | '==' | '===' | '<' | '<=' | '-' | '%' | '*' | '!=' | '!==' | '||' | '+' | '??';
|
|
210
210
|
/**
|
|
211
211
|
* The original location of the start or end of a node created by the `AstFactory`.
|
|
212
212
|
*/
|
|
@@ -5,7 +5,7 @@
|
|
|
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
|
|
8
|
+
import ts from 'typescript';
|
|
9
9
|
import { ImportRewriter } from '../../imports';
|
|
10
10
|
import { ImportGenerator, NamedImport } from './api/import_generator';
|
|
11
11
|
/**
|
|
@@ -14,7 +14,7 @@ import { ImportGenerator, NamedImport } from './api/import_generator';
|
|
|
14
14
|
export interface Import {
|
|
15
15
|
/** The name of the module that has been imported. */
|
|
16
16
|
specifier: string;
|
|
17
|
-
/** The `ts.
|
|
17
|
+
/** The `ts.Identifier` by which the imported module is known. */
|
|
18
18
|
qualifier: ts.Identifier;
|
|
19
19
|
}
|
|
20
20
|
export declare class ImportManager implements ImportGenerator<ts.Identifier> {
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
6
|
exports.ImportManager = void 0;
|
|
@@ -31,7 +11,7 @@ exports.ImportManager = void 0;
|
|
|
31
11
|
* Use of this source code is governed by an MIT-style license that can be
|
|
32
12
|
* found in the LICENSE file at https://angular.io/license
|
|
33
13
|
*/
|
|
34
|
-
const
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
35
15
|
const imports_1 = require("../../imports");
|
|
36
16
|
class ImportManager {
|
|
37
17
|
constructor(rewriter = new imports_1.NoopImportRewriter(), prefix = 'i') {
|
|
@@ -42,7 +22,7 @@ class ImportManager {
|
|
|
42
22
|
}
|
|
43
23
|
generateNamespaceImport(moduleName) {
|
|
44
24
|
if (!this.specifierToIdentifier.has(moduleName)) {
|
|
45
|
-
this.specifierToIdentifier.set(moduleName,
|
|
25
|
+
this.specifierToIdentifier.set(moduleName, typescript_1.default.factory.createIdentifier(`${this.prefix}${this.nextIndex++}`));
|
|
46
26
|
}
|
|
47
27
|
return this.specifierToIdentifier.get(moduleName);
|
|
48
28
|
}
|