static-injector 1.0.10 → 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 +30 -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
|
@@ -7,19 +7,20 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
11
|
-
exports.isNull = exports.literal = exports.ifStmt = exports.fn = exports.
|
|
10
|
+
exports.LeadingComment = exports.StmtModifier = exports.TYPED_NULL_EXPR = exports.NULL_EXPR = exports.CommaExpr = exports.LiteralMapExpr = exports.LiteralMapEntry = exports.LiteralArrayExpr = exports.ReadKeyExpr = exports.ReadPropExpr = exports.BinaryOperatorExpr = exports.UnaryOperatorExpr = exports.FunctionExpr = exports.FnParam = exports.NotExpr = exports.ConditionalExpr = exports.ExternalReference = exports.ExternalExpr = exports.LiteralPiece = exports.TemplateLiteralElement = exports.TemplateLiteral = exports.LiteralExpr = exports.InstantiateExpr = exports.InvokeFunctionExpr = exports.WritePropExpr = exports.WriteKeyExpr = exports.WriteVarExpr = exports.WrappedNodeExpr = exports.TypeofExpr = exports.ReadVarExpr = exports.Expression = exports.areAllEquivalent = exports.nullSafeIsEquivalent = exports.BinaryOperator = exports.UnaryOperator = exports.NONE_TYPE = exports.FUNCTION_TYPE = exports.STRING_TYPE = exports.NUMBER_TYPE = exports.INT_TYPE = exports.BOOL_TYPE = exports.INFERRED_TYPE = exports.DYNAMIC_TYPE = exports.MapType = exports.ArrayType = exports.ExpressionType = exports.BuiltinType = exports.BuiltinTypeName = exports.Type = exports.TypeModifier = void 0;
|
|
11
|
+
exports.isNull = exports.literal = exports.ifStmt = exports.fn = exports.not = exports.unary = exports.literalMap = exports.literalArr = exports.typeofExpr = exports.expressionType = exports.importType = exports.importExpr = exports.variable = exports.jsDocComment = exports.leadingComment = exports.IfStmt = exports.ReturnStatement = exports.ExpressionStatement = exports.DeclareFunctionStmt = exports.DeclareVarStmt = exports.Statement = exports.JSDocComment = void 0;
|
|
12
12
|
//// Types
|
|
13
13
|
var TypeModifier;
|
|
14
14
|
(function (TypeModifier) {
|
|
15
|
-
TypeModifier[TypeModifier["
|
|
15
|
+
TypeModifier[TypeModifier["None"] = 0] = "None";
|
|
16
|
+
TypeModifier[TypeModifier["Const"] = 1] = "Const";
|
|
16
17
|
})(TypeModifier = exports.TypeModifier || (exports.TypeModifier = {}));
|
|
17
18
|
class Type {
|
|
18
|
-
constructor(modifiers =
|
|
19
|
+
constructor(modifiers = TypeModifier.None) {
|
|
19
20
|
this.modifiers = modifiers;
|
|
20
21
|
}
|
|
21
22
|
hasModifier(modifier) {
|
|
22
|
-
return this.modifiers
|
|
23
|
+
return (this.modifiers & modifier) !== 0;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
exports.Type = Type;
|
|
@@ -140,8 +141,8 @@ class Expression {
|
|
|
140
141
|
prop(name, sourceSpan) {
|
|
141
142
|
return new ReadPropExpr(this, name, null, sourceSpan);
|
|
142
143
|
}
|
|
143
|
-
|
|
144
|
-
return new
|
|
144
|
+
key(index, type, sourceSpan) {
|
|
145
|
+
return new ReadKeyExpr(this, index, type, sourceSpan);
|
|
145
146
|
}
|
|
146
147
|
callFn(params, sourceSpan, pure) {
|
|
147
148
|
return new InvokeFunctionExpr(this, params, null, sourceSpan, pure);
|
|
@@ -151,29 +152,13 @@ class Expression {
|
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
exports.Expression = Expression;
|
|
154
|
-
var BuiltinVar;
|
|
155
|
-
(function (BuiltinVar) {
|
|
156
|
-
BuiltinVar[BuiltinVar["This"] = 0] = "This";
|
|
157
|
-
BuiltinVar[BuiltinVar["Super"] = 1] = "Super";
|
|
158
|
-
BuiltinVar[BuiltinVar["CatchError"] = 2] = "CatchError";
|
|
159
|
-
BuiltinVar[BuiltinVar["CatchStack"] = 3] = "CatchStack";
|
|
160
|
-
})(BuiltinVar = exports.BuiltinVar || (exports.BuiltinVar = {}));
|
|
161
155
|
class ReadVarExpr extends Expression {
|
|
162
156
|
constructor(name, type, sourceSpan) {
|
|
163
157
|
super(type, sourceSpan);
|
|
164
|
-
|
|
165
|
-
this.name = name;
|
|
166
|
-
this.builtin = null;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
this.name = null;
|
|
170
|
-
this.builtin = name;
|
|
171
|
-
}
|
|
158
|
+
this.name = name;
|
|
172
159
|
}
|
|
173
160
|
isEquivalent(e) {
|
|
174
|
-
return
|
|
175
|
-
this.name === e.name &&
|
|
176
|
-
this.builtin === e.builtin);
|
|
161
|
+
return e instanceof ReadVarExpr && this.name === e.name;
|
|
177
162
|
}
|
|
178
163
|
isConstant() {
|
|
179
164
|
return false;
|
|
@@ -182,9 +167,6 @@ class ReadVarExpr extends Expression {
|
|
|
182
167
|
return visitor.visitReadVarExpr(this, context);
|
|
183
168
|
}
|
|
184
169
|
set(value) {
|
|
185
|
-
if (!this.name) {
|
|
186
|
-
throw new Error(`Built in variable ${this.builtin} can not be assigned to.`);
|
|
187
|
-
}
|
|
188
170
|
return new WriteVarExpr(this.name, value, null, this.sourceSpan);
|
|
189
171
|
}
|
|
190
172
|
}
|
|
@@ -242,7 +224,7 @@ class WriteVarExpr extends Expression {
|
|
|
242
224
|
return new DeclareVarStmt(this.name, this.value, type, modifiers, this.sourceSpan);
|
|
243
225
|
}
|
|
244
226
|
toConstDecl() {
|
|
245
|
-
return this.toDeclStmt(exports.INFERRED_TYPE,
|
|
227
|
+
return this.toDeclStmt(exports.INFERRED_TYPE, StmtModifier.Final);
|
|
246
228
|
}
|
|
247
229
|
}
|
|
248
230
|
exports.WriteVarExpr = WriteVarExpr;
|
|
@@ -288,41 +270,6 @@ class WritePropExpr extends Expression {
|
|
|
288
270
|
}
|
|
289
271
|
}
|
|
290
272
|
exports.WritePropExpr = WritePropExpr;
|
|
291
|
-
var BuiltinMethod;
|
|
292
|
-
(function (BuiltinMethod) {
|
|
293
|
-
BuiltinMethod[BuiltinMethod["ConcatArray"] = 0] = "ConcatArray";
|
|
294
|
-
BuiltinMethod[BuiltinMethod["SubscribeObservable"] = 1] = "SubscribeObservable";
|
|
295
|
-
BuiltinMethod[BuiltinMethod["Bind"] = 2] = "Bind";
|
|
296
|
-
})(BuiltinMethod = exports.BuiltinMethod || (exports.BuiltinMethod = {}));
|
|
297
|
-
class InvokeMethodExpr extends Expression {
|
|
298
|
-
constructor(receiver, method, args, type, sourceSpan) {
|
|
299
|
-
super(type, sourceSpan);
|
|
300
|
-
this.receiver = receiver;
|
|
301
|
-
this.args = args;
|
|
302
|
-
if (typeof method === 'string') {
|
|
303
|
-
this.name = method;
|
|
304
|
-
this.builtin = null;
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
this.name = null;
|
|
308
|
-
this.builtin = method;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
isEquivalent(e) {
|
|
312
|
-
return (e instanceof InvokeMethodExpr &&
|
|
313
|
-
this.receiver.isEquivalent(e.receiver) &&
|
|
314
|
-
this.name === e.name &&
|
|
315
|
-
this.builtin === e.builtin &&
|
|
316
|
-
areAllEquivalent(this.args, e.args));
|
|
317
|
-
}
|
|
318
|
-
isConstant() {
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
visitExpression(visitor, context) {
|
|
322
|
-
return visitor.visitInvokeMethodExpr(this, context);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
exports.InvokeMethodExpr = InvokeMethodExpr;
|
|
326
273
|
class InvokeFunctionExpr extends Expression {
|
|
327
274
|
constructor(fn, args, type, sourceSpan, pure = false) {
|
|
328
275
|
super(type, sourceSpan);
|
|
@@ -402,23 +349,47 @@ class TemplateLiteralElement {
|
|
|
402
349
|
}
|
|
403
350
|
}
|
|
404
351
|
exports.TemplateLiteralElement = TemplateLiteralElement;
|
|
405
|
-
class
|
|
352
|
+
class LiteralPiece {
|
|
406
353
|
constructor(text, sourceSpan) {
|
|
407
354
|
this.text = text;
|
|
408
355
|
this.sourceSpan = sourceSpan;
|
|
409
356
|
}
|
|
410
357
|
}
|
|
411
|
-
exports.MessagePiece = MessagePiece;
|
|
412
|
-
class LiteralPiece extends MessagePiece {
|
|
413
|
-
}
|
|
414
358
|
exports.LiteralPiece = LiteralPiece;
|
|
415
|
-
class PlaceholderPiece extends MessagePiece {
|
|
416
|
-
}
|
|
417
|
-
exports.PlaceholderPiece = PlaceholderPiece;
|
|
418
359
|
const escapeSlashes = (str) => str.replace(/\\/g, '\\\\');
|
|
419
360
|
const escapeStartingColon = (str) => str.replace(/^:/, '\\:');
|
|
420
361
|
const escapeColons = (str) => str.replace(/:/g, '\\:');
|
|
421
362
|
const escapeForTemplateLiteral = (str) => str.replace(/`/g, '\\`').replace(/\${/g, '$\\{');
|
|
363
|
+
/**
|
|
364
|
+
* Creates a `{cooked, raw}` object from the `metaBlock` and `messagePart`.
|
|
365
|
+
*
|
|
366
|
+
* The `raw` text must have various character sequences escaped:
|
|
367
|
+
* * "\" would otherwise indicate that the next character is a control character.
|
|
368
|
+
* * "`" and "${" are template string control sequences that would otherwise prematurely indicate
|
|
369
|
+
* the end of a message part.
|
|
370
|
+
* * ":" inside a metablock would prematurely indicate the end of the metablock.
|
|
371
|
+
* * ":" at the start of a messagePart with no metablock would erroneously indicate the start of a
|
|
372
|
+
* metablock.
|
|
373
|
+
*
|
|
374
|
+
* @param metaBlock Any metadata that should be prepended to the string
|
|
375
|
+
* @param messagePart The message part of the string
|
|
376
|
+
*/
|
|
377
|
+
function createCookedRawString(metaBlock, messagePart, range) {
|
|
378
|
+
if (metaBlock === '') {
|
|
379
|
+
return {
|
|
380
|
+
cooked: messagePart,
|
|
381
|
+
raw: escapeForTemplateLiteral(escapeStartingColon(escapeSlashes(messagePart))),
|
|
382
|
+
range,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
return {
|
|
387
|
+
cooked: `:${metaBlock}:${messagePart}`,
|
|
388
|
+
raw: escapeForTemplateLiteral(`:${escapeColons(escapeSlashes(metaBlock))}:${escapeSlashes(messagePart)}`),
|
|
389
|
+
range,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}
|
|
422
393
|
class ExternalExpr extends Expression {
|
|
423
394
|
constructor(value, type, typeParams = null, sourceSpan) {
|
|
424
395
|
super(type, sourceSpan);
|
|
@@ -484,38 +455,6 @@ class NotExpr extends Expression {
|
|
|
484
455
|
}
|
|
485
456
|
}
|
|
486
457
|
exports.NotExpr = NotExpr;
|
|
487
|
-
class AssertNotNull extends Expression {
|
|
488
|
-
constructor(condition, sourceSpan) {
|
|
489
|
-
super(condition.type, sourceSpan);
|
|
490
|
-
this.condition = condition;
|
|
491
|
-
}
|
|
492
|
-
isEquivalent(e) {
|
|
493
|
-
return (e instanceof AssertNotNull && this.condition.isEquivalent(e.condition));
|
|
494
|
-
}
|
|
495
|
-
isConstant() {
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
visitExpression(visitor, context) {
|
|
499
|
-
return visitor.visitAssertNotNullExpr(this, context);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
exports.AssertNotNull = AssertNotNull;
|
|
503
|
-
class CastExpr extends Expression {
|
|
504
|
-
constructor(value, type, sourceSpan) {
|
|
505
|
-
super(type, sourceSpan);
|
|
506
|
-
this.value = value;
|
|
507
|
-
}
|
|
508
|
-
isEquivalent(e) {
|
|
509
|
-
return e instanceof CastExpr && this.value.isEquivalent(e.value);
|
|
510
|
-
}
|
|
511
|
-
isConstant() {
|
|
512
|
-
return false;
|
|
513
|
-
}
|
|
514
|
-
visitExpression(visitor, context) {
|
|
515
|
-
return visitor.visitCastExpr(this, context);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
exports.CastExpr = CastExpr;
|
|
519
458
|
class FnParam {
|
|
520
459
|
constructor(name, type = null) {
|
|
521
460
|
this.name = name;
|
|
@@ -698,19 +637,16 @@ class CommaExpr extends Expression {
|
|
|
698
637
|
}
|
|
699
638
|
}
|
|
700
639
|
exports.CommaExpr = CommaExpr;
|
|
701
|
-
exports.THIS_EXPR = new ReadVarExpr(BuiltinVar.This, null, null);
|
|
702
|
-
exports.SUPER_EXPR = new ReadVarExpr(BuiltinVar.Super, null, null);
|
|
703
|
-
exports.CATCH_ERROR_VAR = new ReadVarExpr(BuiltinVar.CatchError, null, null);
|
|
704
|
-
exports.CATCH_STACK_VAR = new ReadVarExpr(BuiltinVar.CatchStack, null, null);
|
|
705
640
|
exports.NULL_EXPR = new LiteralExpr(null, null, null);
|
|
706
641
|
exports.TYPED_NULL_EXPR = new LiteralExpr(null, exports.INFERRED_TYPE, null);
|
|
707
642
|
//// Statements
|
|
708
643
|
var StmtModifier;
|
|
709
644
|
(function (StmtModifier) {
|
|
710
|
-
StmtModifier[StmtModifier["
|
|
711
|
-
StmtModifier[StmtModifier["
|
|
712
|
-
StmtModifier[StmtModifier["
|
|
713
|
-
StmtModifier[StmtModifier["
|
|
645
|
+
StmtModifier[StmtModifier["None"] = 0] = "None";
|
|
646
|
+
StmtModifier[StmtModifier["Final"] = 1] = "Final";
|
|
647
|
+
StmtModifier[StmtModifier["Private"] = 2] = "Private";
|
|
648
|
+
StmtModifier[StmtModifier["Exported"] = 4] = "Exported";
|
|
649
|
+
StmtModifier[StmtModifier["Static"] = 8] = "Static";
|
|
714
650
|
})(StmtModifier = exports.StmtModifier || (exports.StmtModifier = {}));
|
|
715
651
|
class LeadingComment {
|
|
716
652
|
constructor(text, multiline, trailingNewline) {
|
|
@@ -734,13 +670,13 @@ class JSDocComment extends LeadingComment {
|
|
|
734
670
|
}
|
|
735
671
|
exports.JSDocComment = JSDocComment;
|
|
736
672
|
class Statement {
|
|
737
|
-
constructor(modifiers =
|
|
673
|
+
constructor(modifiers = StmtModifier.None, sourceSpan = null, leadingComments) {
|
|
738
674
|
this.modifiers = modifiers;
|
|
739
675
|
this.sourceSpan = sourceSpan;
|
|
740
676
|
this.leadingComments = leadingComments;
|
|
741
677
|
}
|
|
742
678
|
hasModifier(modifier) {
|
|
743
|
-
return this.modifiers
|
|
679
|
+
return (this.modifiers & modifier) !== 0;
|
|
744
680
|
}
|
|
745
681
|
addLeadingComment(leadingComment) {
|
|
746
682
|
var _a;
|
|
@@ -788,7 +724,7 @@ class DeclareFunctionStmt extends Statement {
|
|
|
788
724
|
exports.DeclareFunctionStmt = DeclareFunctionStmt;
|
|
789
725
|
class ExpressionStatement extends Statement {
|
|
790
726
|
constructor(expr, sourceSpan, leadingComments) {
|
|
791
|
-
super(
|
|
727
|
+
super(StmtModifier.None, sourceSpan, leadingComments);
|
|
792
728
|
this.expr = expr;
|
|
793
729
|
}
|
|
794
730
|
isEquivalent(stmt) {
|
|
@@ -801,7 +737,7 @@ class ExpressionStatement extends Statement {
|
|
|
801
737
|
exports.ExpressionStatement = ExpressionStatement;
|
|
802
738
|
class ReturnStatement extends Statement {
|
|
803
739
|
constructor(value, sourceSpan = null, leadingComments) {
|
|
804
|
-
super(
|
|
740
|
+
super(StmtModifier.None, sourceSpan, leadingComments);
|
|
805
741
|
this.value = value;
|
|
806
742
|
}
|
|
807
743
|
isEquivalent(stmt) {
|
|
@@ -812,77 +748,9 @@ class ReturnStatement extends Statement {
|
|
|
812
748
|
}
|
|
813
749
|
}
|
|
814
750
|
exports.ReturnStatement = ReturnStatement;
|
|
815
|
-
class AbstractClassPart {
|
|
816
|
-
constructor(type = null, modifiers = []) {
|
|
817
|
-
this.type = type;
|
|
818
|
-
this.modifiers = modifiers;
|
|
819
|
-
}
|
|
820
|
-
hasModifier(modifier) {
|
|
821
|
-
return this.modifiers.indexOf(modifier) !== -1;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
exports.AbstractClassPart = AbstractClassPart;
|
|
825
|
-
class ClassField extends AbstractClassPart {
|
|
826
|
-
constructor(name, type, modifiers, initializer) {
|
|
827
|
-
super(type, modifiers);
|
|
828
|
-
this.name = name;
|
|
829
|
-
this.initializer = initializer;
|
|
830
|
-
}
|
|
831
|
-
isEquivalent(f) {
|
|
832
|
-
return this.name === f.name;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
exports.ClassField = ClassField;
|
|
836
|
-
class ClassMethod extends AbstractClassPart {
|
|
837
|
-
constructor(name, params, body, type, modifiers) {
|
|
838
|
-
super(type, modifiers);
|
|
839
|
-
this.name = name;
|
|
840
|
-
this.params = params;
|
|
841
|
-
this.body = body;
|
|
842
|
-
}
|
|
843
|
-
isEquivalent(m) {
|
|
844
|
-
return this.name === m.name && areAllEquivalent(this.body, m.body);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
exports.ClassMethod = ClassMethod;
|
|
848
|
-
class ClassGetter extends AbstractClassPart {
|
|
849
|
-
constructor(name, body, type, modifiers) {
|
|
850
|
-
super(type, modifiers);
|
|
851
|
-
this.name = name;
|
|
852
|
-
this.body = body;
|
|
853
|
-
}
|
|
854
|
-
isEquivalent(m) {
|
|
855
|
-
return this.name === m.name && areAllEquivalent(this.body, m.body);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
exports.ClassGetter = ClassGetter;
|
|
859
|
-
class ClassStmt extends Statement {
|
|
860
|
-
constructor(name, parent, fields, getters, constructorMethod, methods, modifiers, sourceSpan, leadingComments) {
|
|
861
|
-
super(modifiers, sourceSpan, leadingComments);
|
|
862
|
-
this.name = name;
|
|
863
|
-
this.parent = parent;
|
|
864
|
-
this.fields = fields;
|
|
865
|
-
this.getters = getters;
|
|
866
|
-
this.constructorMethod = constructorMethod;
|
|
867
|
-
this.methods = methods;
|
|
868
|
-
}
|
|
869
|
-
isEquivalent(stmt) {
|
|
870
|
-
return (stmt instanceof ClassStmt &&
|
|
871
|
-
this.name === stmt.name &&
|
|
872
|
-
nullSafeIsEquivalent(this.parent, stmt.parent) &&
|
|
873
|
-
areAllEquivalent(this.fields, stmt.fields) &&
|
|
874
|
-
areAllEquivalent(this.getters, stmt.getters) &&
|
|
875
|
-
this.constructorMethod.isEquivalent(stmt.constructorMethod) &&
|
|
876
|
-
areAllEquivalent(this.methods, stmt.methods));
|
|
877
|
-
}
|
|
878
|
-
visitStatement(visitor, context) {
|
|
879
|
-
return visitor.visitDeclareClassStmt(this, context);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
exports.ClassStmt = ClassStmt;
|
|
883
751
|
class IfStmt extends Statement {
|
|
884
752
|
constructor(condition, trueCase, falseCase = [], sourceSpan, leadingComments) {
|
|
885
|
-
super(
|
|
753
|
+
super(StmtModifier.None, sourceSpan, leadingComments);
|
|
886
754
|
this.condition = condition;
|
|
887
755
|
this.trueCase = trueCase;
|
|
888
756
|
this.falseCase = falseCase;
|
|
@@ -898,6 +766,14 @@ class IfStmt extends Statement {
|
|
|
898
766
|
}
|
|
899
767
|
}
|
|
900
768
|
exports.IfStmt = IfStmt;
|
|
769
|
+
function leadingComment(text, multiline = false, trailingNewline = true) {
|
|
770
|
+
return new LeadingComment(text, multiline, trailingNewline);
|
|
771
|
+
}
|
|
772
|
+
exports.leadingComment = leadingComment;
|
|
773
|
+
function jsDocComment(tags = []) {
|
|
774
|
+
return new JSDocComment(tags);
|
|
775
|
+
}
|
|
776
|
+
exports.jsDocComment = jsDocComment;
|
|
901
777
|
function variable(name, type, sourceSpan) {
|
|
902
778
|
return new ReadVarExpr(name, type, sourceSpan);
|
|
903
779
|
}
|
|
@@ -906,6 +782,12 @@ function importExpr(id, typeParams = null, sourceSpan) {
|
|
|
906
782
|
return new ExternalExpr(id, null, typeParams, sourceSpan);
|
|
907
783
|
}
|
|
908
784
|
exports.importExpr = importExpr;
|
|
785
|
+
function importType(id, typeParams, typeModifiers) {
|
|
786
|
+
return id != null
|
|
787
|
+
? expressionType(importExpr(id, typeParams, null), typeModifiers)
|
|
788
|
+
: null;
|
|
789
|
+
}
|
|
790
|
+
exports.importType = importType;
|
|
909
791
|
function expressionType(expr, typeModifiers, typeParams) {
|
|
910
792
|
return new ExpressionType(expr, typeModifiers, typeParams);
|
|
911
793
|
}
|
|
@@ -930,10 +812,6 @@ function not(expr, sourceSpan) {
|
|
|
930
812
|
return new NotExpr(expr, sourceSpan);
|
|
931
813
|
}
|
|
932
814
|
exports.not = not;
|
|
933
|
-
function assertNotNull(expr, sourceSpan) {
|
|
934
|
-
return new AssertNotNull(expr, sourceSpan);
|
|
935
|
-
}
|
|
936
|
-
exports.assertNotNull = assertNotNull;
|
|
937
815
|
function fn(params, body, type, sourceSpan, name) {
|
|
938
816
|
return new FunctionExpr(params, body, type, sourceSpan, name);
|
|
939
817
|
}
|
|
@@ -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];
|
|
@@ -137,7 +141,7 @@ function createFactoryType(meta) {
|
|
|
137
141
|
? createCtorDepsType(meta.deps)
|
|
138
142
|
: outputAst.NONE_TYPE;
|
|
139
143
|
return outputAst.expressionType(outputAst.importExpr(r3_identifiers_1.Identifiers.FactoryDeclaration, [
|
|
140
|
-
util_1.typeWithParameters(meta.type.type, meta.typeArgumentCount),
|
|
144
|
+
(0, util_1.typeWithParameters)(meta.type.type, meta.typeArgumentCount),
|
|
141
145
|
ctorDepsType,
|
|
142
146
|
]));
|
|
143
147
|
}
|
|
@@ -154,14 +158,14 @@ function compileInjectDependency(dep, target, index) {
|
|
|
154
158
|
}
|
|
155
159
|
else if (dep.attributeNameType === null) {
|
|
156
160
|
// 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
|
-
(dep.optional ? 8 /* Optional */ : 0);
|
|
161
|
+
const flags = 0 /* InjectFlags.Default */ |
|
|
162
|
+
(dep.self ? 2 /* InjectFlags.Self */ : 0) |
|
|
163
|
+
(dep.skipSelf ? 4 /* InjectFlags.SkipSelf */ : 0) |
|
|
164
|
+
(dep.optional ? 8 /* InjectFlags.Optional */ : 0);
|
|
161
165
|
// If this dependency is optional or otherwise has non-default flags, then additional
|
|
162
166
|
// parameters describing how to inject the dependency must be passed to the inject function
|
|
163
167
|
// that's being used.
|
|
164
|
-
let flagsParam = flags !== 0 /* Default */ || dep.optional
|
|
168
|
+
let flagsParam = flags !== 0 /* InjectFlags.Default */ || dep.optional
|
|
165
169
|
? outputAst.literal(flags)
|
|
166
170
|
: null;
|
|
167
171
|
// Build up the arguments to the injectFn call.
|
|
@@ -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;
|
|
@@ -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];
|
|
@@ -5,11 +5,11 @@
|
|
|
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, R3DependencyMetadata, R3Reference } from '
|
|
9
|
-
import { R3FactoryMetadata } from '
|
|
10
|
-
import { FactoryTarget } from '
|
|
8
|
+
import { Expression, R3DependencyMetadata, R3Reference } from '../../../../../../compiler';
|
|
9
|
+
import { R3FactoryMetadata } from '../../../../../../compiler';
|
|
10
|
+
import { FactoryTarget } from '../../../../../../compiler/src/render3/partial/api';
|
|
11
11
|
import * as ts from 'typescript';
|
|
12
|
-
import { ClassDeclaration, CtorParameter, Decorator, Import, ImportedTypeValueReference, LocalTypeValueReference, ReflectionHost, TypeValueReference, UnavailableValue } from '
|
|
12
|
+
import { ClassDeclaration, CtorParameter, Decorator, Import, ImportedTypeValueReference, LocalTypeValueReference, ReflectionHost, TypeValueReference, UnavailableValue } from '../../../reflection';
|
|
13
13
|
export declare type ConstructorDeps = {
|
|
14
14
|
deps: R3DependencyMetadata[];
|
|
15
15
|
} | {
|
|
@@ -89,3 +89,4 @@ export declare function wrapFunctionExpressionsInParens(expression: ts.Expressio
|
|
|
89
89
|
*/
|
|
90
90
|
export declare function wrapTypeReference(reflector: ReflectionHost, clazz: ClassDeclaration): R3Reference;
|
|
91
91
|
export declare function toFactoryMetadata(meta: Omit<R3FactoryMetadata, 'target'>, target: FactoryTarget): R3FactoryMetadata;
|
|
92
|
+
export declare function isAbstractClassDeclaration(clazz: ClassDeclaration): boolean;
|