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.
- package/import/commonjs/index.js +337 -124
- 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/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 +102 -72
- 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 +328 -114
- 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 +2 -2
- 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 +3 -8
- package/import/typings/di/internal_tokens.d.ts +10 -0
- package/import/typings/di/provider_collection.d.ts +30 -0
- package/import/typings/di/provider_token.d.ts +1 -1
- package/import/typings/di/r3_injector.d.ts +68 -37
- package/import/typings/di/scope.d.ts +3 -2
- package/import/typings/index.d.ts +1 -1
- package/import/typings/render3/definition_factory.d.ts +1 -1
- package/package.json +5 -3
- package/{import/es2015/decorator/interface/provider.js → transform/compiler/compiler.d.ts} +1 -1
- package/transform/compiler/compiler.js +28 -0
- package/transform/compiler/index.d.ts +8 -5
- package/transform/compiler/index.js +17 -6
- 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/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 +30 -109
- package/transform/compiler/src/output/output_ast.js +66 -188
- 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 +46 -61
- 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.d.ts +0 -8
- package/transform/compiler/src/render3/view/util.js +5 -9
- 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 +3 -3
- package/transform/compiler-cli/src/ngtsc/annotations/{src → common/src}/util.d.ts +4 -34
- package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +181 -0
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +3 -4
- package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +46 -53
- package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +6 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +12 -1
- package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +7 -0
- package/transform/compiler-cli/src/ngtsc/imports/index.js +12 -1
- 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 +12 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +13 -14
- package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +8 -25
- 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 +44 -55
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +1 -1
- package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +55 -69
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +7 -23
- package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +9 -2
- package/transform/compiler-cli/src/ngtsc/transform/index.js +12 -1
- package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +2 -2
- package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +16 -31
- package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +12 -5
- package/transform/compiler-cli/src/ngtsc/translator/index.js +12 -1
- 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 +4 -4
- package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +5 -21
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +2 -6
- package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +6 -18
- 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 +83 -90
- package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +4 -4
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +8 -0
- 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 +45 -0
- package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +86 -0
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +1 -8
- package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +4 -27
- package/transform/index.js +5 -1
- package/transform/injectable-transform.js +59 -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
- package/transform/compiler-cli/src/ngtsc/annotations/src/util.js +0 -370
- /package/import/es2015/{decorator → di}/injectable.js +0 -0
|
@@ -1,14 +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
|
-
*/
|
|
9
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
3
|
if (k2 === undefined) k2 = k;
|
|
11
|
-
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);
|
|
12
9
|
}) : (function(o, m, k, k2) {
|
|
13
10
|
if (k2 === undefined) k2 = k;
|
|
14
11
|
o[k2] = m[k];
|
|
@@ -27,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
27
24
|
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.isExpressionFactoryMetadata = exports.isDelegatedFactoryMetadata = exports.createFactoryType = exports.compileFactoryFunction = exports.FactoryTarget = exports.R3FactoryDelegateType = void 0;
|
|
30
|
-
const
|
|
27
|
+
const o = __importStar(require("../output/output_ast"));
|
|
31
28
|
const r3_identifiers_1 = require("../render3/r3_identifiers");
|
|
32
29
|
const util_1 = require("./util");
|
|
33
30
|
var R3FactoryDelegateType;
|
|
@@ -47,7 +44,7 @@ var FactoryTarget;
|
|
|
47
44
|
* Construct a factory function expression for the given `R3FactoryMetadata`.
|
|
48
45
|
*/
|
|
49
46
|
function compileFactoryFunction(meta) {
|
|
50
|
-
const t =
|
|
47
|
+
const t = o.variable('t');
|
|
51
48
|
let baseFactoryVar = null;
|
|
52
49
|
// The type to instantiate via constructor invocation. If there is no delegated factory, meaning
|
|
53
50
|
// this type is always created by constructor invocation, then this is the type-to-create
|
|
@@ -55,29 +52,29 @@ function compileFactoryFunction(meta) {
|
|
|
55
52
|
// delegated factory (which is used to create the current type) then this is only the type-to-
|
|
56
53
|
// create parameter (t).
|
|
57
54
|
const typeForCtor = !isDelegatedFactoryMetadata(meta)
|
|
58
|
-
? new
|
|
55
|
+
? new o.BinaryOperatorExpr(o.BinaryOperator.Or, t, meta.internalType)
|
|
59
56
|
: t;
|
|
60
57
|
let ctorExpr = null;
|
|
61
58
|
if (meta.deps !== null) {
|
|
62
59
|
// There is a constructor (either explicitly or implicitly defined).
|
|
63
60
|
if (meta.deps !== 'invalid') {
|
|
64
|
-
ctorExpr = new
|
|
61
|
+
ctorExpr = new o.InstantiateExpr(typeForCtor, injectDependencies(meta.deps, meta.target));
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
else {
|
|
68
65
|
// There is no constructor, use the base class' factory to construct typeForCtor.
|
|
69
|
-
baseFactoryVar =
|
|
66
|
+
baseFactoryVar = o.variable(`ɵ${meta.name}_BaseFactory`);
|
|
70
67
|
ctorExpr = baseFactoryVar.callFn([typeForCtor]);
|
|
71
68
|
}
|
|
72
69
|
const body = [];
|
|
73
70
|
let retExpr = null;
|
|
74
71
|
function makeConditionalFactory(nonCtorExpr) {
|
|
75
|
-
const r =
|
|
76
|
-
body.push(r.set(
|
|
72
|
+
const r = o.variable('r');
|
|
73
|
+
body.push(r.set(o.NULL_EXPR).toDeclStmt());
|
|
77
74
|
const ctorStmt = ctorExpr !== null
|
|
78
75
|
? r.set(ctorExpr).toStmt()
|
|
79
|
-
:
|
|
80
|
-
body.push(
|
|
76
|
+
: o.importExpr(r3_identifiers_1.Identifiers.invalidFactory).callFn([]).toStmt();
|
|
77
|
+
body.push(o.ifStmt(t, [ctorStmt], [r.set(nonCtorExpr).toStmt()]));
|
|
81
78
|
return r;
|
|
82
79
|
}
|
|
83
80
|
if (isDelegatedFactoryMetadata(meta)) {
|
|
@@ -86,8 +83,8 @@ function compileFactoryFunction(meta) {
|
|
|
86
83
|
const delegateArgs = injectDependencies(meta.delegateDeps, meta.target);
|
|
87
84
|
// Either call `new delegate(...)` or `delegate(...)` depending on meta.delegateType.
|
|
88
85
|
const factoryExpr = new (meta.delegateType === R3FactoryDelegateType.Class
|
|
89
|
-
?
|
|
90
|
-
:
|
|
86
|
+
? o.InstantiateExpr
|
|
87
|
+
: o.InvokeFunctionExpr)(meta.delegate, delegateArgs);
|
|
91
88
|
retExpr = makeConditionalFactory(factoryExpr);
|
|
92
89
|
}
|
|
93
90
|
else if (isExpressionFactoryMetadata(meta)) {
|
|
@@ -99,29 +96,29 @@ function compileFactoryFunction(meta) {
|
|
|
99
96
|
}
|
|
100
97
|
if (retExpr === null) {
|
|
101
98
|
// The expression cannot be formed so render an `ɵɵinvalidFactory()` call.
|
|
102
|
-
body.push(
|
|
99
|
+
body.push(o.importExpr(r3_identifiers_1.Identifiers.invalidFactory).callFn([]).toStmt());
|
|
103
100
|
}
|
|
104
101
|
else if (baseFactoryVar !== null) {
|
|
105
102
|
// This factory uses a base factory, so call `ɵɵgetInheritedFactory()` to compute it.
|
|
106
|
-
const getInheritedFactoryCall =
|
|
103
|
+
const getInheritedFactoryCall = o
|
|
107
104
|
.importExpr(r3_identifiers_1.Identifiers.getInheritedFactory)
|
|
108
105
|
.callFn([meta.internalType]);
|
|
109
106
|
// Memoize the base factoryFn: `baseFactory || (baseFactory = ɵɵgetInheritedFactory(...))`
|
|
110
|
-
const baseFactory = new
|
|
111
|
-
body.push(new
|
|
107
|
+
const baseFactory = new o.BinaryOperatorExpr(o.BinaryOperator.Or, baseFactoryVar, baseFactoryVar.set(getInheritedFactoryCall));
|
|
108
|
+
body.push(new o.ReturnStatement(baseFactory.callFn([typeForCtor])));
|
|
112
109
|
}
|
|
113
110
|
else {
|
|
114
111
|
// This is straightforward factory, just return it.
|
|
115
|
-
body.push(new
|
|
112
|
+
body.push(new o.ReturnStatement(retExpr));
|
|
116
113
|
}
|
|
117
|
-
let factoryFn =
|
|
114
|
+
let factoryFn = o.fn([new o.FnParam('t', o.DYNAMIC_TYPE)], body, o.INFERRED_TYPE, undefined, `${meta.name}_Factory`);
|
|
118
115
|
if (baseFactoryVar !== null) {
|
|
119
116
|
// There is a base factory variable so wrap its declaration along with the factory function into
|
|
120
117
|
// an IIFE.
|
|
121
|
-
factoryFn =
|
|
118
|
+
factoryFn = o
|
|
122
119
|
.fn([], [
|
|
123
|
-
new
|
|
124
|
-
new
|
|
120
|
+
new o.DeclareVarStmt(baseFactoryVar.name),
|
|
121
|
+
new o.ReturnStatement(factoryFn),
|
|
125
122
|
])
|
|
126
123
|
.callFn([], /* sourceSpan */ undefined, /* pure */ true);
|
|
127
124
|
}
|
|
@@ -135,9 +132,9 @@ exports.compileFactoryFunction = compileFactoryFunction;
|
|
|
135
132
|
function createFactoryType(meta) {
|
|
136
133
|
const ctorDepsType = meta.deps !== null && meta.deps !== 'invalid'
|
|
137
134
|
? createCtorDepsType(meta.deps)
|
|
138
|
-
:
|
|
139
|
-
return
|
|
140
|
-
util_1.typeWithParameters(meta.type.type, meta.typeArgumentCount),
|
|
135
|
+
: o.NONE_TYPE;
|
|
136
|
+
return o.expressionType(o.importExpr(r3_identifiers_1.Identifiers.FactoryDeclaration, [
|
|
137
|
+
(0, util_1.typeWithParameters)(meta.type.type, meta.typeArgumentCount),
|
|
141
138
|
ctorDepsType,
|
|
142
139
|
]));
|
|
143
140
|
}
|
|
@@ -148,29 +145,29 @@ function injectDependencies(deps, target) {
|
|
|
148
145
|
function compileInjectDependency(dep, target, index) {
|
|
149
146
|
// Interpret the dependency according to its resolved type.
|
|
150
147
|
if (dep.token === null) {
|
|
151
|
-
return
|
|
152
|
-
.importExpr(r3_identifiers_1.Identifiers.invalidFactoryDep)
|
|
153
|
-
.callFn([outputAst.literal(index)]);
|
|
148
|
+
return o.importExpr(r3_identifiers_1.Identifiers.invalidFactoryDep).callFn([o.literal(index)]);
|
|
154
149
|
}
|
|
155
150
|
else if (dep.attributeNameType === null) {
|
|
156
151
|
// Build up the injection flags according to the metadata.
|
|
157
|
-
const flags = 0 /* Default */ |
|
|
158
|
-
(dep.self ? 2 /* Self */ : 0) |
|
|
159
|
-
(dep.skipSelf ? 4 /* SkipSelf */ : 0) |
|
|
160
|
-
|
|
152
|
+
const flags = 0 /* InjectFlags.Default */ |
|
|
153
|
+
(dep.self ? 2 /* InjectFlags.Self */ : 0) |
|
|
154
|
+
(dep.skipSelf ? 4 /* InjectFlags.SkipSelf */ : 0) |
|
|
155
|
+
0 |
|
|
156
|
+
(dep.optional ? 8 /* InjectFlags.Optional */ : 0) |
|
|
157
|
+
0;
|
|
161
158
|
// If this dependency is optional or otherwise has non-default flags, then additional
|
|
162
159
|
// parameters describing how to inject the dependency must be passed to the inject function
|
|
163
160
|
// that's being used.
|
|
164
|
-
let flagsParam = flags !== 0 /* Default */ || dep.optional
|
|
165
|
-
? outputAst.literal(flags)
|
|
166
|
-
: null;
|
|
161
|
+
let flagsParam = flags !== 0 /* InjectFlags.Default */ || dep.optional ? o.literal(flags) : null;
|
|
167
162
|
// Build up the arguments to the injectFn call.
|
|
168
163
|
const injectArgs = [dep.token];
|
|
169
164
|
if (flagsParam) {
|
|
170
165
|
injectArgs.push(flagsParam);
|
|
171
166
|
}
|
|
172
167
|
const injectFn = getInjectFn(target);
|
|
173
|
-
return
|
|
168
|
+
return o.importExpr(injectFn).callFn(injectArgs);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
173
|
function createCtorDepsType(deps) {
|
|
@@ -182,40 +179,28 @@ function createCtorDepsType(deps) {
|
|
|
182
179
|
return type;
|
|
183
180
|
}
|
|
184
181
|
else {
|
|
185
|
-
return
|
|
182
|
+
return o.literal(null);
|
|
186
183
|
}
|
|
187
184
|
});
|
|
188
185
|
if (hasTypes) {
|
|
189
|
-
return
|
|
186
|
+
return o.expressionType(o.literalArr(attributeTypes));
|
|
190
187
|
}
|
|
191
188
|
else {
|
|
192
|
-
return
|
|
189
|
+
return o.NONE_TYPE;
|
|
193
190
|
}
|
|
194
191
|
}
|
|
195
192
|
function createCtorDepType(dep) {
|
|
196
193
|
const entries = [];
|
|
197
194
|
if (dep.optional) {
|
|
198
|
-
entries.push({
|
|
199
|
-
key: 'optional',
|
|
200
|
-
value: outputAst.literal(true),
|
|
201
|
-
quoted: false,
|
|
202
|
-
});
|
|
195
|
+
entries.push({ key: 'optional', value: o.literal(true), quoted: false });
|
|
203
196
|
}
|
|
204
197
|
if (dep.self) {
|
|
205
|
-
entries.push({
|
|
206
|
-
key: 'self',
|
|
207
|
-
value: outputAst.literal(true),
|
|
208
|
-
quoted: false,
|
|
209
|
-
});
|
|
198
|
+
entries.push({ key: 'self', value: o.literal(true), quoted: false });
|
|
210
199
|
}
|
|
211
200
|
if (dep.skipSelf) {
|
|
212
|
-
entries.push({
|
|
213
|
-
key: 'skipSelf',
|
|
214
|
-
value: outputAst.literal(true),
|
|
215
|
-
quoted: false,
|
|
216
|
-
});
|
|
201
|
+
entries.push({ key: 'skipSelf', value: o.literal(true), quoted: false });
|
|
217
202
|
}
|
|
218
|
-
return entries.length > 0 ?
|
|
203
|
+
return entries.length > 0 ? o.literalMap(entries) : null;
|
|
219
204
|
}
|
|
220
205
|
function isDelegatedFactoryMetadata(meta) {
|
|
221
206
|
return meta.delegateType !== undefined;
|
|
@@ -19,3 +19,67 @@ export interface R3CompiledExpression {
|
|
|
19
19
|
type: o.Type;
|
|
20
20
|
statements: o.Statement[];
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Describes an expression that may have been wrapped in a `forwardRef()` guard.
|
|
24
|
+
*
|
|
25
|
+
* This is used when describing expressions that can refer to types that may eagerly reference types
|
|
26
|
+
* that have not yet been defined.
|
|
27
|
+
*/
|
|
28
|
+
export interface MaybeForwardRefExpression<T extends o.Expression = o.Expression> {
|
|
29
|
+
/**
|
|
30
|
+
* The unwrapped expression.
|
|
31
|
+
*/
|
|
32
|
+
expression: T;
|
|
33
|
+
/**
|
|
34
|
+
* Specified whether the `expression` contains a reference to something that has not yet been
|
|
35
|
+
* defined, and whether the expression is still wrapped in a `forwardRef()` call.
|
|
36
|
+
*
|
|
37
|
+
* If this value is `ForwardRefHandling.None` then the `expression` is safe to use as-is.
|
|
38
|
+
*
|
|
39
|
+
* Otherwise the `expression` was wrapped in a call to `forwardRef()` and must not be eagerly
|
|
40
|
+
* evaluated. Instead it must be wrapped in a function closure that will be evaluated lazily to
|
|
41
|
+
* allow the definition of the expression to be evaluated first.
|
|
42
|
+
*
|
|
43
|
+
* In full AOT compilation it can be safe to unwrap the `forwardRef()` call up front if the
|
|
44
|
+
* expression will actually be evaluated lazily inside a function call after the value of
|
|
45
|
+
* `expression` has been defined.
|
|
46
|
+
*
|
|
47
|
+
* But in other cases, such as partial AOT compilation or JIT compilation the expression will be
|
|
48
|
+
* evaluated eagerly in top level code so will need to continue to be wrapped in a `forwardRef()`
|
|
49
|
+
* call.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
forwardRef: ForwardRefHandling;
|
|
53
|
+
}
|
|
54
|
+
export declare function createMayBeForwardRefExpression<T extends o.Expression>(expression: T, forwardRef: ForwardRefHandling): MaybeForwardRefExpression<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Convert a `MaybeForwardRefExpression` to an `Expression`, possibly wrapping its expression in a
|
|
57
|
+
* `forwardRef()` call.
|
|
58
|
+
*
|
|
59
|
+
* If `MaybeForwardRefExpression.forwardRef` is `ForwardRefHandling.Unwrapped` then the expression
|
|
60
|
+
* was originally wrapped in a `forwardRef()` call to prevent the value from being eagerly evaluated
|
|
61
|
+
* in the code.
|
|
62
|
+
*
|
|
63
|
+
* See `packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts` and
|
|
64
|
+
* `packages/compiler/src/jit_compiler_facade.ts` for more information.
|
|
65
|
+
*/
|
|
66
|
+
export declare function convertFromMaybeForwardRefExpression({ expression, forwardRef, }: MaybeForwardRefExpression): o.Expression;
|
|
67
|
+
/**
|
|
68
|
+
* Generate an expression that has the given `expr` wrapped in the following form:
|
|
69
|
+
*
|
|
70
|
+
* ```
|
|
71
|
+
* forwardRef(() => expr)
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function generateForwardRef(expr: o.Expression): o.Expression;
|
|
75
|
+
/**
|
|
76
|
+
* Specifies how a forward ref has been handled in a MaybeForwardRefExpression
|
|
77
|
+
*/
|
|
78
|
+
export declare const enum ForwardRefHandling {
|
|
79
|
+
/** The expression was not wrapped in a `forwardRef()` call in the first place. */
|
|
80
|
+
None = 0,
|
|
81
|
+
/** The expression is still wrapped in a `forwardRef()` call. */
|
|
82
|
+
Wrapped = 1,
|
|
83
|
+
/** The expression was wrapped in a `forwardRef()` call but has since been unwrapped. */
|
|
84
|
+
Unwrapped = 2
|
|
85
|
+
}
|
|
@@ -1,7 +1,18 @@
|
|
|
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
|
-
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);
|
|
5
16
|
}) : (function(o, m, k, k2) {
|
|
6
17
|
if (k2 === undefined) k2 = k;
|
|
7
18
|
o[k2] = m[k];
|
|
@@ -19,15 +30,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
30
|
return result;
|
|
20
31
|
};
|
|
21
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.typeWithParameters = void 0;
|
|
23
|
-
/**
|
|
24
|
-
* @license
|
|
25
|
-
* Copyright Google LLC All Rights Reserved.
|
|
26
|
-
*
|
|
27
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
28
|
-
* found in the LICENSE file at https://angular.io/license
|
|
29
|
-
*/
|
|
33
|
+
exports.generateForwardRef = exports.convertFromMaybeForwardRefExpression = exports.createMayBeForwardRefExpression = exports.typeWithParameters = void 0;
|
|
30
34
|
const o = __importStar(require("../output/output_ast"));
|
|
35
|
+
const r3_identifiers_1 = require("./r3_identifiers");
|
|
31
36
|
function typeWithParameters(type, numParams) {
|
|
32
37
|
if (numParams === 0) {
|
|
33
38
|
return o.expressionType(type);
|
|
@@ -39,3 +44,41 @@ function typeWithParameters(type, numParams) {
|
|
|
39
44
|
return o.expressionType(type, undefined, params);
|
|
40
45
|
}
|
|
41
46
|
exports.typeWithParameters = typeWithParameters;
|
|
47
|
+
function createMayBeForwardRefExpression(expression, forwardRef) {
|
|
48
|
+
return { expression, forwardRef };
|
|
49
|
+
}
|
|
50
|
+
exports.createMayBeForwardRefExpression = createMayBeForwardRefExpression;
|
|
51
|
+
/**
|
|
52
|
+
* Convert a `MaybeForwardRefExpression` to an `Expression`, possibly wrapping its expression in a
|
|
53
|
+
* `forwardRef()` call.
|
|
54
|
+
*
|
|
55
|
+
* If `MaybeForwardRefExpression.forwardRef` is `ForwardRefHandling.Unwrapped` then the expression
|
|
56
|
+
* was originally wrapped in a `forwardRef()` call to prevent the value from being eagerly evaluated
|
|
57
|
+
* in the code.
|
|
58
|
+
*
|
|
59
|
+
* See `packages/compiler-cli/src/ngtsc/annotations/src/injectable.ts` and
|
|
60
|
+
* `packages/compiler/src/jit_compiler_facade.ts` for more information.
|
|
61
|
+
*/
|
|
62
|
+
function convertFromMaybeForwardRefExpression({ expression, forwardRef, }) {
|
|
63
|
+
switch (forwardRef) {
|
|
64
|
+
case 0 /* ForwardRefHandling.None */:
|
|
65
|
+
case 1 /* ForwardRefHandling.Wrapped */:
|
|
66
|
+
return expression;
|
|
67
|
+
case 2 /* ForwardRefHandling.Unwrapped */:
|
|
68
|
+
return generateForwardRef(expression);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.convertFromMaybeForwardRefExpression = convertFromMaybeForwardRefExpression;
|
|
72
|
+
/**
|
|
73
|
+
* Generate an expression that has the given `expr` wrapped in the following form:
|
|
74
|
+
*
|
|
75
|
+
* ```
|
|
76
|
+
* forwardRef(() => expr)
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function generateForwardRef(expr) {
|
|
80
|
+
return o
|
|
81
|
+
.importExpr(r3_identifiers_1.Identifiers.forwardRef)
|
|
82
|
+
.callFn([o.fn([], [new o.ReturnStatement(expr)])]);
|
|
83
|
+
}
|
|
84
|
+
exports.generateForwardRef = generateForwardRef;
|
|
@@ -6,14 +6,6 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
import * as o from '../../output/output_ast';
|
|
9
|
-
/**
|
|
10
|
-
* Checks whether an object key contains potentially unsafe chars, thus the key should be wrapped in
|
|
11
|
-
* quotes. Note: we do not wrap all keys into quotes, as it may have impact on minification and may
|
|
12
|
-
* bot work in some cases when object keys are mangled by minifier.
|
|
13
|
-
*
|
|
14
|
-
* TODO(FW-1136): this is a temporary solution, we need to come up with a better way of working with
|
|
15
|
-
* inputs that contain potentially unsafe chars.
|
|
16
|
-
*/
|
|
17
9
|
/**
|
|
18
10
|
* A representation for an object literal used during codegen of definition objects. The generic
|
|
19
11
|
* type `T` allows to reference a documented type of the generated structure, such that the
|
|
@@ -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];
|
|
@@ -28,14 +32,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
28
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
33
|
exports.DefinitionMap = void 0;
|
|
30
34
|
const o = __importStar(require("../../output/output_ast"));
|
|
31
|
-
/**
|
|
32
|
-
* Checks whether an object key contains potentially unsafe chars, thus the key should be wrapped in
|
|
33
|
-
* quotes. Note: we do not wrap all keys into quotes, as it may have impact on minification and may
|
|
34
|
-
* bot work in some cases when object keys are mangled by minifier.
|
|
35
|
-
*
|
|
36
|
-
* TODO(FW-1136): this is a temporary solution, we need to come up with a better way of working with
|
|
37
|
-
* inputs that contain potentially unsafe chars.
|
|
38
|
-
*/
|
|
39
35
|
/**
|
|
40
36
|
* A representation for an object literal used during codegen of definition objects. The generic
|
|
41
37
|
* type `T` allows to reference a documented type of the generated structure, such that the
|
|
@@ -0,0 +1,10 @@
|
|
|
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/di';
|
|
9
|
+
export * from './src/factory';
|
|
10
|
+
export * from './src/util';
|
|
@@ -0,0 +1,26 @@
|
|
|
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/di"), exports);
|
|
25
|
+
__exportStar(require("./src/factory"), exports);
|
|
26
|
+
__exportStar(require("./src/util"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { R3DependencyMetadata } from 'static-injector/transform/compiler';
|
|
9
|
+
import { ClassDeclaration, CtorParameter, ReflectionHost, UnavailableValue } from '../../../reflection';
|
|
10
|
+
export type ConstructorDeps = {
|
|
11
|
+
deps: R3DependencyMetadata[];
|
|
12
|
+
} | {
|
|
13
|
+
deps: null;
|
|
14
|
+
errors: ConstructorDepError[];
|
|
15
|
+
};
|
|
16
|
+
export interface ConstructorDepError {
|
|
17
|
+
index: number;
|
|
18
|
+
param: CtorParameter;
|
|
19
|
+
reason: UnavailableValue;
|
|
20
|
+
}
|
|
21
|
+
export declare function getConstructorDependencies(clazz: ClassDeclaration, reflector: ReflectionHost, isCore: boolean): ConstructorDeps | null;
|
|
22
|
+
/**
|
|
23
|
+
* Convert `ConstructorDeps` into the `R3DependencyMetadata` array for those deps if they're valid,
|
|
24
|
+
* or into an `'invalid'` signal if they're not.
|
|
25
|
+
*
|
|
26
|
+
* This is a companion function to `validateConstructorDependencies` which accepts invalid deps.
|
|
27
|
+
*/
|
|
28
|
+
export declare function unwrapConstructorDependencies(deps: ConstructorDeps | null): R3DependencyMetadata[] | 'invalid' | null;
|
|
29
|
+
export declare function getValidConstructorDependencies(clazz: ClassDeclaration, reflector: ReflectionHost, isCore: boolean): R3DependencyMetadata[] | null;
|
|
30
|
+
/**
|
|
31
|
+
* Validate that `ConstructorDeps` does not have any invalid dependencies and convert them into the
|
|
32
|
+
* `R3DependencyMetadata` array if so, or raise a diagnostic if some deps are invalid.
|
|
33
|
+
*
|
|
34
|
+
* This is a companion function to `unwrapConstructorDependencies` which does not accept invalid
|
|
35
|
+
* deps.
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateConstructorDependencies(clazz: ClassDeclaration, deps: ConstructorDeps | null): R3DependencyMetadata[] | null;
|