static-injector 1.0.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/import/commonjs/index.js +331 -118
- package/import/es2015/di/create_injector.js +30 -0
- package/import/es2015/di/initializer_token.js +15 -0
- package/import/es2015/di/inject_switch.js +27 -6
- package/import/es2015/{decorator → di}/injectable.js +0 -0
- package/import/es2015/di/injection_token.js +6 -0
- package/import/es2015/di/injector.js +6 -8
- package/import/es2015/di/injector_compatibility.js +90 -34
- package/import/es2015/di/injector_token.js +1 -1
- package/import/es2015/di/interface/defs.js +39 -0
- package/import/es2015/di/interface/injector.js +1 -0
- package/import/es2015/di/internal_tokens.js +9 -0
- package/import/es2015/di/metadata.js +4 -4
- package/import/es2015/di/provider_collection.js +49 -0
- package/import/es2015/di/r3_injector.js +96 -66
- package/import/es2015/di/scope.js +2 -2
- package/import/es2015/index.js +1 -1
- package/import/es2015/render3/errors_di.js +1 -1
- package/import/fesm2015/index.js +322 -108
- package/import/typings/di/create_injector.d.ts +23 -0
- package/import/typings/di/initializer_token.d.ts +15 -0
- package/import/typings/di/inject_switch.d.ts +7 -2
- package/import/typings/{decorator → di}/injectable.d.ts +1 -1
- package/import/typings/di/injection_token.d.ts +4 -0
- package/import/typings/di/injector.d.ts +20 -7
- package/import/typings/di/injector_compatibility.d.ts +42 -21
- package/import/typings/di/interface/defs.d.ts +10 -0
- package/import/typings/di/interface/injector.d.ts +26 -0
- package/import/typings/di/interface/provider.d.ts +1 -6
- package/import/typings/di/internal_tokens.d.ts +10 -0
- package/import/typings/di/provider_collection.d.ts +30 -0
- package/import/typings/di/r3_injector.d.ts +67 -36
- package/import/typings/di/scope.d.ts +3 -2
- package/import/typings/index.d.ts +1 -1
- package/package.json +4 -2
- package/transform/compiler/index.js +5 -1
- package/transform/compiler/src/injectable_compiler_2.d.ts +7 -36
- package/transform/compiler/src/injectable_compiler_2.js +20 -23
- package/transform/compiler/src/output/output_ast.d.ts +29 -108
- package/transform/compiler/src/output/output_ast.js +66 -188
- package/transform/compiler/src/render3/r3_factory.js +11 -7
- package/transform/compiler/src/render3/util.d.ts +64 -0
- package/transform/compiler/src/render3/util.js +52 -9
- package/transform/compiler/src/render3/view/util.js +5 -1
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +5 -4
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.js +32 -23
- package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +1 -1
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +33 -21
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +5 -1
- package/transform/compiler-cli/src/ngtsc/imports/index.js +5 -1
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +5 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +6 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +36 -23
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +18 -13
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +5 -1
- package/transform/compiler-cli/src/ngtsc/transform/index.js +5 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +13 -8
- package/transform/compiler-cli/src/ngtsc/translator/index.js +5 -1
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +3 -3
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +7 -3
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -4
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +5 -17
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +3 -6
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +67 -55
- package/{import/es2015/decorator/interface/provider.js → transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts} +1 -1
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +24 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +151 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +210 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +5 -1
- package/transform/index.js +5 -1
- package/transform/injectable-transform.js +33 -38
- package/import/typings/decorator/interface/provider.d.ts +0 -312
- package/transform/compiler/src/render3/partial/util.d.ts +0 -16
- package/transform/compiler/src/render3/partial/util.js +0 -44
|
@@ -0,0 +1,210 @@
|
|
|
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.combineModifiers = exports.getModifiers = exports.getDecorators = exports.updateConstructorDeclaration = exports.createSetAccessorDeclaration = exports.updateSetAccessorDeclaration = exports.createGetAccessorDeclaration = exports.updateGetAccessorDeclaration = exports.createPropertyDeclaration = exports.updatePropertyDeclaration = exports.createMethodDeclaration = exports.updateMethodDeclaration = exports.createClassDeclaration = exports.updateClassDeclaration = exports.updateImportDeclaration = exports.updateParameterDeclaration = void 0;
|
|
14
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
/** Whether the current TypeScript version is after 4.8. */
|
|
16
|
+
const IS_AFTER_TS_48 = isAfterVersion(4, 8);
|
|
17
|
+
/**
|
|
18
|
+
* Updates a `ts.ParameterDeclaration` declaration.
|
|
19
|
+
*
|
|
20
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
21
|
+
* We should remove it once we have dropped support for the older versions.
|
|
22
|
+
*/
|
|
23
|
+
exports.updateParameterDeclaration = IS_AFTER_TS_48
|
|
24
|
+
? typescript_1.default.factory.updateParameterDeclaration
|
|
25
|
+
: (node, modifiers, dotDotDotToken, name, questionToken, type, initializer) => typescript_1.default.factory.updateParameterDeclaration(node, ...splitModifiers(modifiers), dotDotDotToken, name, questionToken, type, initializer);
|
|
26
|
+
/**
|
|
27
|
+
* Updates a `ts.ImportDeclaration` declaration.
|
|
28
|
+
*
|
|
29
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
30
|
+
* We should remove it once we have dropped support for the older versions.
|
|
31
|
+
*/
|
|
32
|
+
exports.updateImportDeclaration = IS_AFTER_TS_48
|
|
33
|
+
? typescript_1.default.factory.updateImportDeclaration
|
|
34
|
+
: (node, modifiers, importClause, moduleSpecifier, assertClause) => typescript_1.default.factory.updateImportDeclaration(node, undefined, modifiers, importClause, moduleSpecifier, assertClause);
|
|
35
|
+
/**
|
|
36
|
+
* Updates a `ts.ClassDeclaration` declaration.
|
|
37
|
+
*
|
|
38
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
39
|
+
* We should remove it once we have dropped support for the older versions.
|
|
40
|
+
*/
|
|
41
|
+
exports.updateClassDeclaration = IS_AFTER_TS_48
|
|
42
|
+
? typescript_1.default.factory.updateClassDeclaration
|
|
43
|
+
: (node, combinedModifiers, name, typeParameters, heritageClauses, members) => typescript_1.default.factory.updateClassDeclaration(node, ...splitModifiers(combinedModifiers), name, typeParameters, heritageClauses, members);
|
|
44
|
+
/**
|
|
45
|
+
* Creates a `ts.ClassDeclaration` declaration.
|
|
46
|
+
*
|
|
47
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
48
|
+
* We should remove it once we have dropped support for the older versions.
|
|
49
|
+
*/
|
|
50
|
+
exports.createClassDeclaration = IS_AFTER_TS_48
|
|
51
|
+
? typescript_1.default.factory.createClassDeclaration
|
|
52
|
+
: (combinedModifiers, name, typeParameters, heritageClauses, members) => typescript_1.default.factory.createClassDeclaration(...splitModifiers(combinedModifiers), name, typeParameters, heritageClauses, members);
|
|
53
|
+
/**
|
|
54
|
+
* Updates a `ts.MethodDeclaration` declaration.
|
|
55
|
+
*
|
|
56
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
57
|
+
* We should remove it once we have dropped support for the older versions.
|
|
58
|
+
*/
|
|
59
|
+
exports.updateMethodDeclaration = IS_AFTER_TS_48
|
|
60
|
+
? typescript_1.default.factory.updateMethodDeclaration
|
|
61
|
+
: (node, modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body) => typescript_1.default.factory.updateMethodDeclaration(node, ...splitModifiers(modifiers), asteriskToken, name, questionToken, typeParameters, parameters, type, body);
|
|
62
|
+
/**
|
|
63
|
+
* Creates a `ts.MethodDeclaration` declaration.
|
|
64
|
+
*
|
|
65
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
66
|
+
* We should remove it once we have dropped support for the older versions.
|
|
67
|
+
*/
|
|
68
|
+
exports.createMethodDeclaration = IS_AFTER_TS_48
|
|
69
|
+
? typescript_1.default.factory.createMethodDeclaration
|
|
70
|
+
: (modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body) => typescript_1.default.factory.createMethodDeclaration(...splitModifiers(modifiers), asteriskToken, name, questionToken, typeParameters, parameters, type, body);
|
|
71
|
+
/**
|
|
72
|
+
* Updates a `ts.PropertyDeclaration` declaration.
|
|
73
|
+
*
|
|
74
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
75
|
+
* We should remove it once we have dropped support for the older versions.
|
|
76
|
+
*/
|
|
77
|
+
exports.updatePropertyDeclaration = IS_AFTER_TS_48
|
|
78
|
+
? typescript_1.default.factory.updatePropertyDeclaration
|
|
79
|
+
: (node, modifiers, name, questionOrExclamationToken, type, initializer) => typescript_1.default.factory.updatePropertyDeclaration(node, ...splitModifiers(modifiers), name, questionOrExclamationToken, type, initializer);
|
|
80
|
+
/**
|
|
81
|
+
* Creates a `ts.PropertyDeclaration` declaration.
|
|
82
|
+
*
|
|
83
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
84
|
+
* We should remove it once we have dropped support for the older versions.
|
|
85
|
+
*/
|
|
86
|
+
exports.createPropertyDeclaration = IS_AFTER_TS_48
|
|
87
|
+
? typescript_1.default.factory.createPropertyDeclaration
|
|
88
|
+
: (modifiers, name, questionOrExclamationToken, type, initializer) => typescript_1.default.factory.createPropertyDeclaration(...splitModifiers(modifiers), name, questionOrExclamationToken, type, initializer);
|
|
89
|
+
/**
|
|
90
|
+
* Updates a `ts.GetAccessorDeclaration` declaration.
|
|
91
|
+
*
|
|
92
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
93
|
+
* We should remove it once we have dropped support for the older versions.
|
|
94
|
+
*/
|
|
95
|
+
exports.updateGetAccessorDeclaration = IS_AFTER_TS_48
|
|
96
|
+
? typescript_1.default.factory.updateGetAccessorDeclaration
|
|
97
|
+
: (node, modifiers, name, parameters, type, body) => typescript_1.default.factory.updateGetAccessorDeclaration(node, ...splitModifiers(modifiers), name, parameters, type, body);
|
|
98
|
+
/**
|
|
99
|
+
* Creates a `ts.GetAccessorDeclaration` declaration.
|
|
100
|
+
*
|
|
101
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
102
|
+
* We should remove it once we have dropped support for the older versions.
|
|
103
|
+
*/
|
|
104
|
+
exports.createGetAccessorDeclaration = IS_AFTER_TS_48
|
|
105
|
+
? typescript_1.default.factory.createGetAccessorDeclaration
|
|
106
|
+
: (modifiers, name, parameters, type, body) => typescript_1.default.factory.createGetAccessorDeclaration(...splitModifiers(modifiers), name, parameters, type, body);
|
|
107
|
+
/**
|
|
108
|
+
* Updates a `ts.GetAccessorDeclaration` declaration.
|
|
109
|
+
*
|
|
110
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
111
|
+
* We should remove it once we have dropped support for the older versions.
|
|
112
|
+
*/
|
|
113
|
+
exports.updateSetAccessorDeclaration = IS_AFTER_TS_48
|
|
114
|
+
? typescript_1.default.factory.updateSetAccessorDeclaration
|
|
115
|
+
: (node, modifiers, name, parameters, body) => typescript_1.default.factory.updateSetAccessorDeclaration(node, ...splitModifiers(modifiers), name, parameters, body);
|
|
116
|
+
/**
|
|
117
|
+
* Creates a `ts.GetAccessorDeclaration` declaration.
|
|
118
|
+
*
|
|
119
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
120
|
+
* We should remove it once we have dropped support for the older versions.
|
|
121
|
+
*/
|
|
122
|
+
exports.createSetAccessorDeclaration = IS_AFTER_TS_48
|
|
123
|
+
? typescript_1.default.factory.createSetAccessorDeclaration
|
|
124
|
+
: (modifiers, name, parameters, body) => typescript_1.default.factory.createSetAccessorDeclaration(...splitModifiers(modifiers), name, parameters, body);
|
|
125
|
+
/**
|
|
126
|
+
* Updates a `ts.ConstructorDeclaration` declaration.
|
|
127
|
+
*
|
|
128
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
129
|
+
* We should remove it once we have dropped support for the older versions.
|
|
130
|
+
*/
|
|
131
|
+
exports.updateConstructorDeclaration = IS_AFTER_TS_48
|
|
132
|
+
? typescript_1.default.factory.updateConstructorDeclaration
|
|
133
|
+
: (node, modifiers, parameters, body) => typescript_1.default.factory.updateConstructorDeclaration(node, undefined, modifiers, parameters, body);
|
|
134
|
+
/**
|
|
135
|
+
* Gets the decorators that have been applied to a node.
|
|
136
|
+
*
|
|
137
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
138
|
+
* We should remove it once we have dropped support for the older versions.
|
|
139
|
+
*/
|
|
140
|
+
exports.getDecorators = IS_AFTER_TS_48
|
|
141
|
+
? typescript_1.default.getDecorators
|
|
142
|
+
: (node) => node.decorators;
|
|
143
|
+
/**
|
|
144
|
+
* Gets the modifiers that have been set on a node.
|
|
145
|
+
*
|
|
146
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
147
|
+
* We should remove it once we have dropped support for the older versions.
|
|
148
|
+
*/
|
|
149
|
+
exports.getModifiers = IS_AFTER_TS_48
|
|
150
|
+
? typescript_1.default.getModifiers
|
|
151
|
+
: (node) => node.modifiers;
|
|
152
|
+
/**
|
|
153
|
+
* Combines an optional array of decorators with an optional array of modifiers into a single
|
|
154
|
+
* `ts.ModifierLike` array. Used in version of TypeScript after 4.8 where the `decorators` and
|
|
155
|
+
* `modifiers` arrays have been combined.
|
|
156
|
+
*
|
|
157
|
+
* TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
|
|
158
|
+
* We should remove it once we have dropped support for the older versions.
|
|
159
|
+
*/
|
|
160
|
+
function combineModifiers(decorators, modifiers) {
|
|
161
|
+
const hasDecorators = decorators === null || decorators === void 0 ? void 0 : decorators.length;
|
|
162
|
+
const hasModifiers = modifiers === null || modifiers === void 0 ? void 0 : modifiers.length;
|
|
163
|
+
// This function can be written more compactly, but it is somewhat performance-sensitive
|
|
164
|
+
// so we have some additional logic only to create new arrays when necessary.
|
|
165
|
+
if (hasDecorators && hasModifiers) {
|
|
166
|
+
return [...decorators, ...modifiers];
|
|
167
|
+
}
|
|
168
|
+
if (hasDecorators && !hasModifiers) {
|
|
169
|
+
return decorators;
|
|
170
|
+
}
|
|
171
|
+
if (hasModifiers && !hasDecorators) {
|
|
172
|
+
return modifiers;
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
exports.combineModifiers = combineModifiers;
|
|
177
|
+
/**
|
|
178
|
+
* Splits a `ModifierLike` into two arrays: decorators and modifiers. Used for backwards
|
|
179
|
+
* compatibility with TS 4.7 and below where most factory functions require separate `decorators`
|
|
180
|
+
* and `modifiers` arrays.
|
|
181
|
+
*/
|
|
182
|
+
function splitModifiers(allModifiers) {
|
|
183
|
+
if (!allModifiers) {
|
|
184
|
+
return [undefined, undefined];
|
|
185
|
+
}
|
|
186
|
+
const decorators = [];
|
|
187
|
+
const modifiers = [];
|
|
188
|
+
for (const current of allModifiers) {
|
|
189
|
+
if (typescript_1.default.isDecorator(current)) {
|
|
190
|
+
decorators.push(current);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
modifiers.push(current);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return [
|
|
197
|
+
decorators.length ? decorators : undefined,
|
|
198
|
+
modifiers.length ? modifiers : undefined,
|
|
199
|
+
];
|
|
200
|
+
}
|
|
201
|
+
/** Checks if the current version of TypeScript is after the specified major/minor versions. */
|
|
202
|
+
function isAfterVersion(targetMajor, targetMinor) {
|
|
203
|
+
const [major, minor] = typescript_1.default.versionMajorMinor
|
|
204
|
+
.split('.')
|
|
205
|
+
.map((part) => parseInt(part));
|
|
206
|
+
if (major < targetMajor) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
return major === targetMajor ? minor >= targetMinor : true;
|
|
210
|
+
}
|
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
|
-
Object.
|
|
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);
|
|
12
16
|
}) : (function(o, m, k, k2) {
|
|
13
17
|
if (k2 === undefined) k2 = k;
|
|
14
18
|
o[k2] = m[k];
|
package/transform/index.js
CHANGED
|
@@ -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.
|
|
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];
|
|
@@ -1,31 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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.InjectableTransformerFactory = exports.createTransformer = void 0;
|
|
23
|
-
const typescript_1 =
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
24
8
|
const injectable_1 = require("./compiler-cli/src/ngtsc/annotations/src/injectable");
|
|
25
9
|
const imports_1 = require("./compiler-cli/src/ngtsc/imports");
|
|
26
10
|
const reflection_1 = require("./compiler-cli/src/ngtsc/reflection");
|
|
27
11
|
const transform_1 = require("./compiler-cli/src/ngtsc/transform");
|
|
28
12
|
const translator_1 = require("./compiler-cli/src/ngtsc/translator");
|
|
13
|
+
const ts_compatibility_1 = require("./compiler-cli/src/ngtsc/ts_compatibility");
|
|
29
14
|
const node_Iteration_1 = require("./node-Iteration");
|
|
30
15
|
const NO_DECORATORS = new Set();
|
|
31
16
|
function createTransformer(program, options) {
|
|
@@ -48,8 +33,8 @@ class InjectableTransformerFactory {
|
|
|
48
33
|
return typescript_1.default.visitEachChild(node, (node) => {
|
|
49
34
|
let result = map.get(node);
|
|
50
35
|
if (result) {
|
|
51
|
-
let decoratorList = node.
|
|
52
|
-
return
|
|
36
|
+
let decoratorList = (0, ts_compatibility_1.getDecorators)(node).filter((item) => item !== result.decorator);
|
|
37
|
+
return (0, ts_compatibility_1.updateClassDeclaration)(node, (0, ts_compatibility_1.combineModifiers)(decoratorList.length ? decoratorList : undefined, (0, ts_compatibility_1.getModifiers)(node)), node.name, node.typeParameters, node.heritageClauses, [
|
|
53
38
|
...node.members.map((node) => this._stripAngularDecorators(node)),
|
|
54
39
|
...result.members,
|
|
55
40
|
]);
|
|
@@ -68,12 +53,15 @@ class InjectableTransformerFactory {
|
|
|
68
53
|
let classMetadataMap = new Map();
|
|
69
54
|
let write = new imports_1.NoopImportRewriter();
|
|
70
55
|
let importManager = new translator_1.ImportManager(write);
|
|
71
|
-
node_Iteration_1.nodeIteration(sf, (node) => {
|
|
56
|
+
(0, node_Iteration_1.nodeIteration)(sf, (node) => {
|
|
72
57
|
if (typescript_1.default.isClassDeclaration(node) &&
|
|
73
|
-
node
|
|
58
|
+
typescript_1.default.getDecorators(node) &&
|
|
74
59
|
this.reflectionHost.isClass(node)) {
|
|
75
60
|
const decorators = this.reflectionHost.getDecoratorsOfDeclaration(node);
|
|
76
61
|
let result = this.handler.detect(node, decorators);
|
|
62
|
+
if (!result) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
77
65
|
let analysisOutput = this.handler.analyze(node, result.metadata);
|
|
78
66
|
let compileResult = this.handler.compileFull(node, analysisOutput.analysis);
|
|
79
67
|
let resultNode = this.translate(compileResult, importManager);
|
|
@@ -92,9 +80,9 @@ class InjectableTransformerFactory {
|
|
|
92
80
|
const members = [];
|
|
93
81
|
for (const field of compileResult) {
|
|
94
82
|
// Translate the initializer for the field into TS nodes.
|
|
95
|
-
const exprNode = translator_1.translateExpression(field.initializer, importManager);
|
|
83
|
+
const exprNode = (0, translator_1.translateExpression)(field.initializer, importManager);
|
|
96
84
|
// Create a static property declaration for the new field.
|
|
97
|
-
const property =
|
|
85
|
+
const property = (0, ts_compatibility_1.createPropertyDeclaration)([typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.StaticKeyword)], field.name, undefined, undefined, exprNode);
|
|
98
86
|
if (false) {
|
|
99
87
|
// Closure compiler transforms the form `Service.ɵprov = X` into `Service$ɵprov = X`. To
|
|
100
88
|
// prevent this transformation, such assignments need to be annotated with @nocollapse.
|
|
@@ -104,7 +92,7 @@ class InjectableTransformerFactory {
|
|
|
104
92
|
/* hasTrailingNewLine */ false);
|
|
105
93
|
}
|
|
106
94
|
field.statements
|
|
107
|
-
.map((stmt) => translator_1.translateStatement(stmt, importManager))
|
|
95
|
+
.map((stmt) => (0, translator_1.translateStatement)(stmt, importManager))
|
|
108
96
|
.forEach((stmt) => statements.push(stmt));
|
|
109
97
|
members.push(property);
|
|
110
98
|
}
|
|
@@ -119,12 +107,12 @@ class InjectableTransformerFactory {
|
|
|
119
107
|
_stripAngularDecorators(node) {
|
|
120
108
|
if (typescript_1.default.isParameter(node)) {
|
|
121
109
|
// Strip decorators from parameters (probably of the constructor).
|
|
122
|
-
node =
|
|
110
|
+
node = (0, ts_compatibility_1.updateParameterDeclaration)(node, (0, ts_compatibility_1.combineModifiers)(this._nonCoreDecoratorsOnly(node), (0, ts_compatibility_1.getModifiers)(node)), node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer);
|
|
123
111
|
}
|
|
124
112
|
else if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
125
113
|
// For constructors, strip decorators of the parameters.
|
|
126
114
|
const parameters = node.parameters.map((param) => this._stripAngularDecorators(param));
|
|
127
|
-
node =
|
|
115
|
+
node = (0, ts_compatibility_1.updateConstructorDeclaration)(node, (0, ts_compatibility_1.getModifiers)(node), parameters, node.body);
|
|
128
116
|
}
|
|
129
117
|
return node;
|
|
130
118
|
}
|
|
@@ -155,35 +143,33 @@ class InjectableTransformerFactory {
|
|
|
155
143
|
* `undefined`.
|
|
156
144
|
*/
|
|
157
145
|
_nonCoreDecoratorsOnly(node) {
|
|
146
|
+
const decorators = (0, ts_compatibility_1.getDecorators)(node);
|
|
158
147
|
// Shortcut if the node has no decorators.
|
|
159
|
-
if (
|
|
148
|
+
if (decorators === undefined) {
|
|
160
149
|
return undefined;
|
|
161
150
|
}
|
|
162
|
-
// Build a Set of the decorators on this node from
|
|
151
|
+
// Build a Set of the decorators on this node from @angular/core.
|
|
163
152
|
const coreDecorators = this._angularCoreDecorators(node);
|
|
164
|
-
if (coreDecorators.size ===
|
|
153
|
+
if (coreDecorators.size === decorators.length) {
|
|
165
154
|
// If all decorators are to be removed, return `undefined`.
|
|
166
155
|
return undefined;
|
|
167
156
|
}
|
|
168
157
|
else if (coreDecorators.size === 0) {
|
|
169
158
|
// If no decorators need to be removed, return the original decorators array.
|
|
170
|
-
return
|
|
159
|
+
return nodeArrayFromDecoratorsArray(decorators);
|
|
171
160
|
}
|
|
172
161
|
// Filter out the core decorators.
|
|
173
|
-
const filtered =
|
|
162
|
+
const filtered = decorators.filter((dec) => !coreDecorators.has(dec));
|
|
174
163
|
// If no decorators survive, return `undefined`. This can only happen if a core decorator is
|
|
175
164
|
// repeated on the node.
|
|
176
165
|
if (filtered.length === 0) {
|
|
177
166
|
return undefined;
|
|
178
167
|
}
|
|
179
168
|
// Create a new `NodeArray` with the filtered decorators that sourcemaps back to the original.
|
|
180
|
-
|
|
181
|
-
array.pos = node.decorators.pos;
|
|
182
|
-
array.end = node.decorators.end;
|
|
183
|
-
return array;
|
|
169
|
+
return nodeArrayFromDecoratorsArray(filtered);
|
|
184
170
|
}
|
|
185
171
|
updateStatements(node, importManager) {
|
|
186
|
-
return transform_1.addImports(importManager, node);
|
|
172
|
+
return (0, transform_1.addImports)(importManager, node);
|
|
187
173
|
}
|
|
188
174
|
}
|
|
189
175
|
exports.InjectableTransformerFactory = InjectableTransformerFactory;
|
|
@@ -193,3 +179,12 @@ exports.InjectableTransformerFactory = InjectableTransformerFactory;
|
|
|
193
179
|
function isFromAngularCore(decorator) {
|
|
194
180
|
return (decorator.import !== null && decorator.import.from === 'static-injector');
|
|
195
181
|
}
|
|
182
|
+
/** Creates a `NodeArray` with the correct offsets from an array of decorators. */
|
|
183
|
+
function nodeArrayFromDecoratorsArray(decorators) {
|
|
184
|
+
const array = typescript_1.default.factory.createNodeArray(decorators);
|
|
185
|
+
if (array.length > 0) {
|
|
186
|
+
array.pos = decorators[0].pos;
|
|
187
|
+
array.end = decorators[decorators.length - 1].end;
|
|
188
|
+
}
|
|
189
|
+
return array;
|
|
190
|
+
}
|