static-injector 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/import/commonjs/index.js +1248 -0
- package/import/es2015/decorator/injectable.js +14 -0
- package/import/es2015/decorator/interface/provider.js +8 -0
- package/import/es2015/di/forward_ref.js +53 -0
- package/import/es2015/di/inject_switch.js +31 -0
- package/import/es2015/di/injection_token.js +71 -0
- package/import/es2015/di/injector.js +63 -0
- package/import/es2015/di/injector_compatibility.js +172 -0
- package/import/es2015/di/injector_marker.js +8 -0
- package/import/es2015/di/injector_token.js +21 -0
- package/import/es2015/di/interface/defs.js +72 -0
- package/import/es2015/di/interface/injector.js +25 -0
- package/import/es2015/di/interface/provider.js +8 -0
- package/import/es2015/di/metadata.js +49 -0
- package/import/es2015/di/null_injector.js +19 -0
- package/import/es2015/di/provider_token.js +8 -0
- package/import/es2015/di/r3_injector.js +382 -0
- package/import/es2015/di/scope.js +14 -0
- package/import/es2015/index.js +11 -0
- package/import/es2015/interface/lifecycle_hooks.js +8 -0
- package/import/es2015/interface/type.js +8 -0
- package/import/es2015/render3/definition_factory.js +15 -0
- package/import/es2015/render3/error_code.js +29 -0
- package/import/es2015/render3/errors_di.js +14 -0
- package/import/es2015/render3/fields.js +11 -0
- package/import/es2015/render3/instructions/di.js +23 -0
- package/import/es2015/render3/util/stringify_utils.js +37 -0
- package/import/es2015/util/array_utils.js +17 -0
- package/import/es2015/util/closure.js +19 -0
- package/import/es2015/util/decorators.js +30 -0
- package/import/es2015/util/empty.js +14 -0
- package/import/es2015/util/property.js +15 -0
- package/import/es2015/util/stringify.js +30 -0
- package/import/fesm2015/index.js +1211 -0
- package/import/typings/decorator/injectable.d.ts +82 -0
- package/import/typings/decorator/interface/provider.d.ts +312 -0
- package/import/typings/di/forward_ref.d.ts +49 -0
- package/import/typings/di/inject_switch.d.ts +17 -0
- package/import/typings/di/injection_token.d.ts +57 -0
- package/import/typings/di/injector.d.ts +76 -0
- package/import/typings/di/injector_compatibility.d.ts +77 -0
- package/import/typings/di/injector_marker.d.ts +23 -0
- package/import/typings/di/injector_token.d.ts +18 -0
- package/import/typings/di/interface/defs.d.ts +155 -0
- package/import/typings/di/interface/injector.d.ts +48 -0
- package/import/typings/di/interface/provider.d.ts +312 -0
- package/import/typings/di/metadata.d.ts +176 -0
- package/import/typings/di/null_injector.d.ts +11 -0
- package/import/typings/di/provider_token.d.ts +17 -0
- package/import/typings/di/r3_injector.d.ts +92 -0
- package/import/typings/di/scope.d.ts +14 -0
- package/import/typings/index.d.ts +11 -0
- package/import/typings/interface/lifecycle_hooks.d.ts +28 -0
- package/import/typings/interface/type.d.ts +21 -0
- package/import/typings/render3/definition_factory.d.ts +24 -0
- package/import/typings/render3/error_code.d.ts +24 -0
- package/import/typings/render3/errors_di.d.ts +2 -0
- package/import/typings/render3/fields.d.ts +8 -0
- package/import/typings/render3/instructions/di.d.ts +20 -0
- package/import/typings/render3/util/stringify_utils.d.ts +20 -0
- package/import/typings/util/array_utils.d.ts +10 -0
- package/import/typings/util/closure.d.ts +17 -0
- package/import/typings/util/decorators.d.ts +27 -0
- package/import/typings/util/empty.d.ts +14 -0
- package/import/typings/util/property.d.ts +8 -0
- package/import/typings/util/stringify.d.ts +8 -0
- package/package.json +34 -0
- package/readme.md +27 -0
- package/transform/compiler/index.d.ts +5 -0
- package/transform/compiler/index.js +17 -0
- package/transform/compiler/src/core.d.ts +19 -0
- package/transform/compiler/src/core.js +9 -0
- package/transform/compiler/src/injectable_compiler_2.d.ts +53 -0
- package/transform/compiler/src/injectable_compiler_2.js +159 -0
- package/transform/compiler/src/output/output_ast.d.ts +534 -0
- package/transform/compiler/src/output/output_ast.js +986 -0
- package/transform/compiler/src/parse_util.d.ts +50 -0
- package/transform/compiler/src/parse_util.js +61 -0
- package/transform/compiler/src/render3/partial/api.d.ts +166 -0
- package/transform/compiler/src/render3/partial/api.js +11 -0
- package/transform/compiler/src/render3/partial/util.d.ts +16 -0
- package/transform/compiler/src/render3/partial/util.js +44 -0
- package/transform/compiler/src/render3/r3_factory.d.ts +97 -0
- package/transform/compiler/src/render3/r3_factory.js +239 -0
- package/transform/compiler/src/render3/r3_identifiers.d.ts +20 -0
- package/transform/compiler/src/render3/r3_identifiers.js +51 -0
- package/transform/compiler/src/render3/util.d.ts +21 -0
- package/transform/compiler/src/render3/util.js +41 -0
- package/transform/compiler/src/render3/view/util.d.ts +30 -0
- package/transform/compiler/src/render3/view/util.js +57 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/factory.d.ts +11 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/factory.js +21 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +42 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +278 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.d.ts +91 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +370 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +24 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +76 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +188 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +206 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +2 -0
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +14 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +1 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +13 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +36 -0
- package/transform/compiler-cli/src/ngtsc/imports/src/core.js +25 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +3 -0
- package/transform/compiler-cli/src/ngtsc/reflection/index.js +15 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +667 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +98 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +24 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +271 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +50 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +396 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +12 -0
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +45 -0
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +2 -0
- package/transform/compiler-cli/src/ngtsc/transform/index.js +14 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +115 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/api.js +30 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +15 -0
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +84 -0
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +5 -0
- package/transform/compiler-cli/src/ngtsc/translator/index.js +17 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +274 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js +9 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +27 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +9 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +18 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/context.js +27 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +29 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +70 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +58 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +270 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +54 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +245 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +13 -0
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +21 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +11 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +39 -0
- package/transform/index.d.ts +1 -0
- package/transform/index.js +13 -0
- package/transform/injectable-transform.d.ts +41 -0
- package/transform/injectable-transform.js +195 -0
- package/transform/node-Iteration.d.ts +2 -0
- package/transform/node-Iteration.js +12 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.InjectableTransformerFactory = exports.createTransformer = void 0;
|
|
23
|
+
const typescript_1 = __importStar(require("typescript"));
|
|
24
|
+
const injectable_1 = require("./compiler-cli/src/ngtsc/annotations/src/injectable");
|
|
25
|
+
const imports_1 = require("./compiler-cli/src/ngtsc/imports");
|
|
26
|
+
const reflection_1 = require("./compiler-cli/src/ngtsc/reflection");
|
|
27
|
+
const transform_1 = require("./compiler-cli/src/ngtsc/transform");
|
|
28
|
+
const translator_1 = require("./compiler-cli/src/ngtsc/translator");
|
|
29
|
+
const node_Iteration_1 = require("./node-Iteration");
|
|
30
|
+
const NO_DECORATORS = new Set();
|
|
31
|
+
function createTransformer(program, options) {
|
|
32
|
+
let factory = new InjectableTransformerFactory(program, options);
|
|
33
|
+
return factory.getTransform();
|
|
34
|
+
}
|
|
35
|
+
exports.createTransformer = createTransformer;
|
|
36
|
+
class InjectableTransformerFactory {
|
|
37
|
+
constructor(program, options = {}) {
|
|
38
|
+
this.program = program;
|
|
39
|
+
this.options = options;
|
|
40
|
+
this.typeChecker = this.program.getTypeChecker();
|
|
41
|
+
this.reflectionHost = new reflection_1.TypeScriptReflectionHost(this.typeChecker);
|
|
42
|
+
this.handler = new injectable_1.InjectableDecoratorHandler(this.reflectionHost, false, this.options.strictCtorDeps);
|
|
43
|
+
}
|
|
44
|
+
getTransform() {
|
|
45
|
+
return (context) => this.transform(context);
|
|
46
|
+
}
|
|
47
|
+
visit(node, context, map) {
|
|
48
|
+
return typescript_1.default.visitEachChild(node, (node) => {
|
|
49
|
+
let result = map.get(node);
|
|
50
|
+
if (result) {
|
|
51
|
+
let decoratorList = node.decorators.filter((item) => item !== result.decorator);
|
|
52
|
+
return typescript_1.factory.updateClassDeclaration(node, decoratorList.length ? decoratorList : undefined, node.modifiers, node.name, node.typeParameters, node.heritageClauses, [
|
|
53
|
+
...node.members.map((node) => this._stripAngularDecorators(node)),
|
|
54
|
+
...result.members,
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
return this.visit(node, context, map);
|
|
58
|
+
}, context);
|
|
59
|
+
}
|
|
60
|
+
transform(context) {
|
|
61
|
+
return (sf) => {
|
|
62
|
+
let map = this.preAnalysis(sf);
|
|
63
|
+
sf = this.updateStatements(sf, map.importManager);
|
|
64
|
+
return this.visit(sf, context, map.classMetadataMap);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
preAnalysis(sf) {
|
|
68
|
+
let classMetadataMap = new Map();
|
|
69
|
+
let write = new imports_1.NoopImportRewriter();
|
|
70
|
+
let importManager = new translator_1.ImportManager(write);
|
|
71
|
+
node_Iteration_1.nodeIteration(sf, (node) => {
|
|
72
|
+
if (typescript_1.default.isClassDeclaration(node) &&
|
|
73
|
+
node.decorators &&
|
|
74
|
+
this.reflectionHost.isClass(node)) {
|
|
75
|
+
const decorators = this.reflectionHost.getDecoratorsOfDeclaration(node);
|
|
76
|
+
let result = this.handler.detect(node, decorators);
|
|
77
|
+
let analysisOutput = this.handler.analyze(node, result.metadata);
|
|
78
|
+
let compileResult = this.handler.compileFull(node, analysisOutput.analysis);
|
|
79
|
+
let resultNode = this.translate(compileResult, importManager);
|
|
80
|
+
classMetadataMap.set(node, Object.assign(Object.assign({}, resultNode), { decorator: result.trigger }));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// this.sourceFileMetadataMap.set(sf, {
|
|
84
|
+
// classMetadataMap,
|
|
85
|
+
// importManager: importManager,
|
|
86
|
+
// });
|
|
87
|
+
return { classMetadataMap, importManager };
|
|
88
|
+
}
|
|
89
|
+
translate(compileResult, importManager) {
|
|
90
|
+
// There is at least one field to add.
|
|
91
|
+
const statements = [];
|
|
92
|
+
const members = [];
|
|
93
|
+
for (const field of compileResult) {
|
|
94
|
+
// Translate the initializer for the field into TS nodes.
|
|
95
|
+
const exprNode = translator_1.translateExpression(field.initializer, importManager);
|
|
96
|
+
// Create a static property declaration for the new field.
|
|
97
|
+
const property = typescript_1.default.createProperty(undefined, [typescript_1.default.createToken(typescript_1.default.SyntaxKind.StaticKeyword)], field.name, undefined, undefined, exprNode);
|
|
98
|
+
if (false) {
|
|
99
|
+
// Closure compiler transforms the form `Service.ɵprov = X` into `Service$ɵprov = X`. To
|
|
100
|
+
// prevent this transformation, such assignments need to be annotated with @nocollapse.
|
|
101
|
+
// Note that tsickle is typically responsible for adding such annotations, however it
|
|
102
|
+
// doesn't yet handle synthetic fields added during other transformations.
|
|
103
|
+
typescript_1.default.addSyntheticLeadingComment(property, typescript_1.default.SyntaxKind.MultiLineCommentTrivia, '* @nocollapse ',
|
|
104
|
+
/* hasTrailingNewLine */ false);
|
|
105
|
+
}
|
|
106
|
+
field.statements
|
|
107
|
+
.map((stmt) => translator_1.translateStatement(stmt, importManager))
|
|
108
|
+
.forEach((stmt) => statements.push(stmt));
|
|
109
|
+
members.push(property);
|
|
110
|
+
}
|
|
111
|
+
return { statements, members };
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Remove Angular decorators from a `ts.Node` in a shallow manner.
|
|
115
|
+
*
|
|
116
|
+
* This will remove decorators from class elements (getters, setters, properties, methods) as well
|
|
117
|
+
* as parameters of constructors.
|
|
118
|
+
*/
|
|
119
|
+
_stripAngularDecorators(node) {
|
|
120
|
+
if (typescript_1.default.isParameter(node)) {
|
|
121
|
+
// Strip decorators from parameters (probably of the constructor).
|
|
122
|
+
node = typescript_1.default.updateParameter(node, this._nonCoreDecoratorsOnly(node), node.modifiers, node.dotDotDotToken, node.name, node.questionToken, node.type, node.initializer);
|
|
123
|
+
}
|
|
124
|
+
else if (typescript_1.default.isConstructorDeclaration(node)) {
|
|
125
|
+
// For constructors, strip decorators of the parameters.
|
|
126
|
+
const parameters = node.parameters.map((param) => this._stripAngularDecorators(param));
|
|
127
|
+
node = typescript_1.default.updateConstructor(node, node.decorators, node.modifiers, parameters, node.body);
|
|
128
|
+
}
|
|
129
|
+
return node;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Return all decorators on a `Declaration` which are from static-injector, or an empty set if none
|
|
133
|
+
* are.
|
|
134
|
+
*/
|
|
135
|
+
_angularCoreDecorators(decl) {
|
|
136
|
+
const decorators = this.reflectionHost.getDecoratorsOfDeclaration(decl);
|
|
137
|
+
if (decorators === null) {
|
|
138
|
+
return NO_DECORATORS;
|
|
139
|
+
}
|
|
140
|
+
const coreDecorators = decorators
|
|
141
|
+
.filter((dec) => isFromAngularCore(dec))
|
|
142
|
+
.map((dec) => dec.node);
|
|
143
|
+
if (coreDecorators.length > 0) {
|
|
144
|
+
return new Set(coreDecorators);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return NO_DECORATORS;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Given a `ts.Node`, filter the decorators array and return a version containing only non-Angular
|
|
152
|
+
* decorators.
|
|
153
|
+
*
|
|
154
|
+
* If all decorators are removed (or none existed in the first place), this method returns
|
|
155
|
+
* `undefined`.
|
|
156
|
+
*/
|
|
157
|
+
_nonCoreDecoratorsOnly(node) {
|
|
158
|
+
// Shortcut if the node has no decorators.
|
|
159
|
+
if (node.decorators === undefined) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
// Build a Set of the decorators on this node from static-injector.
|
|
163
|
+
const coreDecorators = this._angularCoreDecorators(node);
|
|
164
|
+
if (coreDecorators.size === node.decorators.length) {
|
|
165
|
+
// If all decorators are to be removed, return `undefined`.
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
else if (coreDecorators.size === 0) {
|
|
169
|
+
// If no decorators need to be removed, return the original decorators array.
|
|
170
|
+
return node.decorators;
|
|
171
|
+
}
|
|
172
|
+
// Filter out the core decorators.
|
|
173
|
+
const filtered = node.decorators.filter((dec) => !coreDecorators.has(dec));
|
|
174
|
+
// If no decorators survive, return `undefined`. This can only happen if a core decorator is
|
|
175
|
+
// repeated on the node.
|
|
176
|
+
if (filtered.length === 0) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
// Create a new `NodeArray` with the filtered decorators that sourcemaps back to the original.
|
|
180
|
+
const array = typescript_1.default.createNodeArray(filtered);
|
|
181
|
+
array.pos = node.decorators.pos;
|
|
182
|
+
array.end = node.decorators.end;
|
|
183
|
+
return array;
|
|
184
|
+
}
|
|
185
|
+
updateStatements(node, importManager) {
|
|
186
|
+
return transform_1.addImports(importManager, node);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.InjectableTransformerFactory = InjectableTransformerFactory;
|
|
190
|
+
/**
|
|
191
|
+
* todo 引入
|
|
192
|
+
*/
|
|
193
|
+
function isFromAngularCore(decorator) {
|
|
194
|
+
return (decorator.import !== null && decorator.import.from === 'static-injector');
|
|
195
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.nodeIteration = void 0;
|
|
7
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
function nodeIteration(node, fn) {
|
|
9
|
+
fn(node);
|
|
10
|
+
typescript_1.default.forEachChild(node, (node) => nodeIteration(node, fn));
|
|
11
|
+
}
|
|
12
|
+
exports.nodeIteration = nodeIteration;
|