static-injector 4.0.1 → 5.0.0-alpha.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.
Files changed (179) hide show
  1. package/{import/commonjs → commonjs}/index.js +29 -197
  2. package/{import/es2022 → es2022}/di/interface/defs.js +5 -1
  3. package/{import/es2022 → es2022}/index.js +0 -1
  4. package/{transform/compiler/index.d.ts → es2022/interface/lifecycle_hooks.js} +1 -1
  5. package/{transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.js → es2022/render3/definition_factory.js} +3 -2
  6. package/es2022/util/decorators.js +31 -0
  7. package/{import/fesm2022 → fesm2022}/index.js +30 -196
  8. package/package.json +17 -14
  9. package/readme.md +33 -13
  10. package/{import/typings → typings}/di/injectable.d.ts +0 -7
  11. package/{import/typings → typings}/index.d.ts +0 -1
  12. package/import/es2022/di/injectable.js +0 -14
  13. package/import/es2022/error_details_base_url.js +0 -19
  14. package/import/es2022/render3/definition_factory.js +0 -14
  15. package/import/es2022/render3/di.js +0 -49
  16. package/import/es2022/render3/error_code.js +0 -30
  17. package/import/es2022/util/array_utils.js +0 -17
  18. package/import/es2022/util/decorators.js +0 -53
  19. package/import/typings/error_details_base_url.d.ts +0 -19
  20. package/import/typings/render3/di.d.ts +0 -12
  21. package/import/typings/render3/error_code.d.ts +0 -24
  22. package/import/typings/util/array_utils.d.ts +0 -25
  23. package/transform/compiler/compiler.d.ts +0 -8
  24. package/transform/compiler/compiler.js +0 -28
  25. package/transform/compiler/index.js +0 -28
  26. package/transform/compiler/public_api.d.ts +0 -13
  27. package/transform/compiler/public_api.js +0 -30
  28. package/transform/compiler/src/compiler.d.ts +0 -5
  29. package/transform/compiler/src/compiler.js +0 -21
  30. package/transform/compiler/src/core.d.ts +0 -25
  31. package/transform/compiler/src/core.js +0 -22
  32. package/transform/compiler/src/injectable_compiler_2.d.ts +0 -23
  33. package/transform/compiler/src/injectable_compiler_2.js +0 -171
  34. package/transform/compiler/src/output/output_ast.d.ts +0 -512
  35. package/transform/compiler/src/output/output_ast.js +0 -1109
  36. package/transform/compiler/src/parse_util.d.ts +0 -50
  37. package/transform/compiler/src/parse_util.js +0 -71
  38. package/transform/compiler/src/render3/partial/api.d.ts +0 -171
  39. package/transform/compiler/src/render3/partial/api.js +0 -18
  40. package/transform/compiler/src/render3/r3_factory.d.ts +0 -82
  41. package/transform/compiler/src/render3/r3_factory.js +0 -225
  42. package/transform/compiler/src/render3/r3_identifiers.d.ts +0 -20
  43. package/transform/compiler/src/render3/r3_identifiers.js +0 -55
  44. package/transform/compiler/src/render3/util.d.ts +0 -85
  45. package/transform/compiler/src/render3/util.js +0 -82
  46. package/transform/compiler/src/render3/view/util.d.ts +0 -24
  47. package/transform/compiler/src/render3/view/util.js +0 -59
  48. package/transform/compiler-cli/src/ngtsc/annotations/common/index.d.ts +0 -3
  49. package/transform/compiler-cli/src/ngtsc/annotations/common/index.js +0 -19
  50. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.d.ts +0 -37
  51. package/transform/compiler-cli/src/ngtsc/annotations/common/src/di.js +0 -195
  52. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.d.ts +0 -11
  53. package/transform/compiler-cli/src/ngtsc/annotations/common/src/factory.js +0 -22
  54. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.d.ts +0 -64
  55. package/transform/compiler-cli/src/ngtsc/annotations/common/src/util.js +0 -189
  56. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.d.ts +0 -43
  57. package/transform/compiler-cli/src/ngtsc/annotations/src/injectable.js +0 -277
  58. package/transform/compiler-cli/src/ngtsc/diagnostics/error.d.ts +0 -24
  59. package/transform/compiler-cli/src/ngtsc/diagnostics/error.js +0 -84
  60. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.d.ts +0 -188
  61. package/transform/compiler-cli/src/ngtsc/diagnostics/error_code.js +0 -206
  62. package/transform/compiler-cli/src/ngtsc/diagnostics/index.d.ts +0 -2
  63. package/transform/compiler-cli/src/ngtsc/diagnostics/index.js +0 -18
  64. package/transform/compiler-cli/src/ngtsc/imports/index.d.ts +0 -1
  65. package/transform/compiler-cli/src/ngtsc/imports/index.js +0 -17
  66. package/transform/compiler-cli/src/ngtsc/imports/src/core.d.ts +0 -36
  67. package/transform/compiler-cli/src/ngtsc/imports/src/core.js +0 -25
  68. package/transform/compiler-cli/src/ngtsc/imports/src/default.d.ts +0 -19
  69. package/transform/compiler-cli/src/ngtsc/imports/src/default.js +0 -27
  70. package/transform/compiler-cli/src/ngtsc/reflection/index.d.ts +0 -3
  71. package/transform/compiler-cli/src/ngtsc/reflection/index.js +0 -19
  72. package/transform/compiler-cli/src/ngtsc/reflection/src/host.d.ts +0 -522
  73. package/transform/compiler-cli/src/ngtsc/reflection/src/host.js +0 -34
  74. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.d.ts +0 -25
  75. package/transform/compiler-cli/src/ngtsc/reflection/src/type_to_value.js +0 -271
  76. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.d.ts +0 -53
  77. package/transform/compiler-cli/src/ngtsc/reflection/src/typescript.js +0 -393
  78. package/transform/compiler-cli/src/ngtsc/reflection/src/util.d.ts +0 -12
  79. package/transform/compiler-cli/src/ngtsc/reflection/src/util.js +0 -29
  80. package/transform/compiler-cli/src/ngtsc/transform/index.d.ts +0 -2
  81. package/transform/compiler-cli/src/ngtsc/transform/index.js +0 -18
  82. package/transform/compiler-cli/src/ngtsc/transform/src/api.d.ts +0 -115
  83. package/transform/compiler-cli/src/ngtsc/transform/src/api.js +0 -29
  84. package/transform/compiler-cli/src/ngtsc/transform/src/utils.d.ts +0 -15
  85. package/transform/compiler-cli/src/ngtsc/transform/src/utils.js +0 -79
  86. package/transform/compiler-cli/src/ngtsc/translator/index.d.ts +0 -5
  87. package/transform/compiler-cli/src/ngtsc/translator/index.js +0 -21
  88. package/transform/compiler-cli/src/ngtsc/translator/src/api/ast_factory.d.ts +0 -289
  89. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.d.ts +0 -27
  90. package/transform/compiler-cli/src/ngtsc/translator/src/api/import_generator.js +0 -9
  91. package/transform/compiler-cli/src/ngtsc/translator/src/context.d.ts +0 -18
  92. package/transform/compiler-cli/src/ngtsc/translator/src/context.js +0 -28
  93. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.d.ts +0 -47
  94. package/transform/compiler-cli/src/ngtsc/translator/src/import_manager.js +0 -66
  95. package/transform/compiler-cli/src/ngtsc/translator/src/translator.d.ts +0 -56
  96. package/transform/compiler-cli/src/ngtsc/translator/src/translator.js +0 -270
  97. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.d.ts +0 -12
  98. package/transform/compiler-cli/src/ngtsc/translator/src/ts_util.js +0 -27
  99. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.d.ts +0 -53
  100. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.js +0 -250
  101. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.d.ts +0 -13
  102. package/transform/compiler-cli/src/ngtsc/translator/src/typescript_translator.js +0 -21
  103. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.d.ts +0 -8
  104. package/transform/compiler-cli/src/ngtsc/ts_compatibility/index.js +0 -24
  105. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.d.ts +0 -45
  106. package/transform/compiler-cli/src/ngtsc/ts_compatibility/src/ts_cross_version_utils.js +0 -86
  107. package/transform/compiler-cli/src/ngtsc/util/src/typescript.d.ts +0 -4
  108. package/transform/compiler-cli/src/ngtsc/util/src/typescript.js +0 -16
  109. package/transform/index.d.ts +0 -1
  110. package/transform/index.js +0 -17
  111. package/transform/injectable-transform.d.ts +0 -41
  112. package/transform/injectable-transform.js +0 -245
  113. package/transform/node-Iteration.d.ts +0 -2
  114. package/transform/node-Iteration.js +0 -12
  115. /package/{import/es2022 → es2022}/di/create_injector.js +0 -0
  116. /package/{import/es2022 → es2022}/di/forward_ref.js +0 -0
  117. /package/{import/es2022 → es2022}/di/index.js +0 -0
  118. /package/{import/es2022 → es2022}/di/initializer_token.js +0 -0
  119. /package/{import/es2022 → es2022}/di/inject_switch.js +0 -0
  120. /package/{import/es2022/di/injector_marker.js → es2022/di/injectable.js} +0 -0
  121. /package/{import/es2022 → es2022}/di/injection_token.js +0 -0
  122. /package/{import/es2022 → es2022}/di/injector.js +0 -0
  123. /package/{import/es2022 → es2022}/di/injector_compatibility.js +0 -0
  124. /package/{import/es2022/di/provider_token.js → es2022/di/injector_marker.js} +0 -0
  125. /package/{import/es2022 → es2022}/di/injector_token.js +0 -0
  126. /package/{import/es2022 → es2022}/di/interface/injector.js +0 -0
  127. /package/{import/es2022 → es2022}/di/interface/provider.js +0 -0
  128. /package/{import/es2022 → es2022}/di/internal_tokens.js +0 -0
  129. /package/{import/es2022 → es2022}/di/metadata.js +0 -0
  130. /package/{import/es2022 → es2022}/di/null_injector.js +0 -0
  131. /package/{import/es2022 → es2022}/di/provider_collection.js +0 -0
  132. /package/{import/es2022/interface/lifecycle_hooks.js → es2022/di/provider_token.js} +0 -0
  133. /package/{import/es2022 → es2022}/di/r3_injector.js +0 -0
  134. /package/{import/es2022 → es2022}/di/scope.js +0 -0
  135. /package/{import/es2022 → es2022}/di.js +0 -0
  136. /package/{import/es2022 → es2022}/errors.js +0 -0
  137. /package/{import/es2022 → es2022}/interface/type.js +0 -0
  138. /package/{import/es2022 → es2022}/render3/errors_di.js +0 -0
  139. /package/{import/es2022 → es2022}/render3/fields.js +0 -0
  140. /package/{import/es2022 → es2022}/render3/instructions/di.js +0 -0
  141. /package/{import/es2022 → es2022}/render3/util/stringify_utils.js +0 -0
  142. /package/{import/es2022 → es2022}/util/closure.js +0 -0
  143. /package/{import/es2022 → es2022}/util/empty.js +0 -0
  144. /package/{import/es2022 → es2022}/util/property.js +0 -0
  145. /package/{import/es2022 → es2022}/util/stringify.js +0 -0
  146. /package/{import/typings → typings}/di/create_injector.d.ts +0 -0
  147. /package/{import/typings → typings}/di/forward_ref.d.ts +0 -0
  148. /package/{import/typings → typings}/di/index.d.ts +0 -0
  149. /package/{import/typings → typings}/di/initializer_token.d.ts +0 -0
  150. /package/{import/typings → typings}/di/inject_switch.d.ts +0 -0
  151. /package/{import/typings → typings}/di/injection_token.d.ts +0 -0
  152. /package/{import/typings → typings}/di/injector.d.ts +0 -0
  153. /package/{import/typings → typings}/di/injector_compatibility.d.ts +0 -0
  154. /package/{import/typings → typings}/di/injector_marker.d.ts +0 -0
  155. /package/{import/typings → typings}/di/injector_token.d.ts +0 -0
  156. /package/{import/typings → typings}/di/interface/defs.d.ts +0 -0
  157. /package/{import/typings → typings}/di/interface/injector.d.ts +0 -0
  158. /package/{import/typings → typings}/di/interface/provider.d.ts +0 -0
  159. /package/{import/typings → typings}/di/internal_tokens.d.ts +0 -0
  160. /package/{import/typings → typings}/di/metadata.d.ts +0 -0
  161. /package/{import/typings → typings}/di/null_injector.d.ts +0 -0
  162. /package/{import/typings → typings}/di/provider_collection.d.ts +0 -0
  163. /package/{import/typings → typings}/di/provider_token.d.ts +0 -0
  164. /package/{import/typings → typings}/di/r3_injector.d.ts +0 -0
  165. /package/{import/typings → typings}/di/scope.d.ts +0 -0
  166. /package/{import/typings → typings}/di.d.ts +0 -0
  167. /package/{import/typings → typings}/errors.d.ts +0 -0
  168. /package/{import/typings → typings}/interface/lifecycle_hooks.d.ts +0 -0
  169. /package/{import/typings → typings}/interface/type.d.ts +0 -0
  170. /package/{import/typings → typings}/render3/definition_factory.d.ts +0 -0
  171. /package/{import/typings → typings}/render3/errors_di.d.ts +0 -0
  172. /package/{import/typings → typings}/render3/fields.d.ts +0 -0
  173. /package/{import/typings → typings}/render3/instructions/di.d.ts +0 -0
  174. /package/{import/typings → typings}/render3/util/stringify_utils.d.ts +0 -0
  175. /package/{import/typings → typings}/util/closure.d.ts +0 -0
  176. /package/{import/typings → typings}/util/decorators.d.ts +0 -0
  177. /package/{import/typings → typings}/util/empty.d.ts +0 -0
  178. /package/{import/typings → typings}/util/property.d.ts +0 -0
  179. /package/{import/typings → typings}/util/stringify.d.ts +0 -0
@@ -1,1109 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.NULL_EXPR = exports.CommaExpr = exports.LiteralMapExpr = exports.LiteralMapEntry = exports.LiteralArrayExpr = exports.ReadKeyExpr = exports.ReadPropExpr = exports.BinaryOperatorExpr = exports.UnaryOperatorExpr = exports.ArrowFunctionExpr = exports.FunctionExpr = exports.FnParam = exports.NotExpr = exports.DynamicImportExpr = 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.TransplantedType = exports.MapType = exports.ArrayType = exports.ExpressionType = exports.BuiltinType = exports.BuiltinTypeName = exports.Type = exports.TypeModifier = void 0;
11
- exports.isNull = exports.literal = exports.ifStmt = exports.arrowFn = exports.fn = exports.not = exports.unary = exports.literalMap = exports.literalArr = exports.typeofExpr = exports.transplantedType = 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 = exports.LeadingComment = exports.StmtModifier = exports.TYPED_NULL_EXPR = void 0;
12
- //// Types
13
- var TypeModifier;
14
- (function (TypeModifier) {
15
- TypeModifier[TypeModifier["None"] = 0] = "None";
16
- TypeModifier[TypeModifier["Const"] = 1] = "Const";
17
- })(TypeModifier || (exports.TypeModifier = TypeModifier = {}));
18
- class Type {
19
- modifiers;
20
- constructor(modifiers = TypeModifier.None) {
21
- this.modifiers = modifiers;
22
- }
23
- hasModifier(modifier) {
24
- return (this.modifiers & modifier) !== 0;
25
- }
26
- }
27
- exports.Type = Type;
28
- var BuiltinTypeName;
29
- (function (BuiltinTypeName) {
30
- BuiltinTypeName[BuiltinTypeName["Dynamic"] = 0] = "Dynamic";
31
- BuiltinTypeName[BuiltinTypeName["Bool"] = 1] = "Bool";
32
- BuiltinTypeName[BuiltinTypeName["String"] = 2] = "String";
33
- BuiltinTypeName[BuiltinTypeName["Int"] = 3] = "Int";
34
- BuiltinTypeName[BuiltinTypeName["Number"] = 4] = "Number";
35
- BuiltinTypeName[BuiltinTypeName["Function"] = 5] = "Function";
36
- BuiltinTypeName[BuiltinTypeName["Inferred"] = 6] = "Inferred";
37
- BuiltinTypeName[BuiltinTypeName["None"] = 7] = "None";
38
- })(BuiltinTypeName || (exports.BuiltinTypeName = BuiltinTypeName = {}));
39
- class BuiltinType extends Type {
40
- name;
41
- constructor(name, modifiers) {
42
- super(modifiers);
43
- this.name = name;
44
- }
45
- visitType(visitor, context) {
46
- return visitor.visitBuiltinType(this, context);
47
- }
48
- }
49
- exports.BuiltinType = BuiltinType;
50
- class ExpressionType extends Type {
51
- value;
52
- typeParams;
53
- constructor(value, modifiers, typeParams = null) {
54
- super(modifiers);
55
- this.value = value;
56
- this.typeParams = typeParams;
57
- }
58
- visitType(visitor, context) {
59
- return visitor.visitExpressionType(this, context);
60
- }
61
- }
62
- exports.ExpressionType = ExpressionType;
63
- class ArrayType extends Type {
64
- of;
65
- constructor(of, modifiers) {
66
- super(modifiers);
67
- this.of = of;
68
- }
69
- visitType(visitor, context) {
70
- return visitor.visitArrayType(this, context);
71
- }
72
- }
73
- exports.ArrayType = ArrayType;
74
- class MapType extends Type {
75
- valueType;
76
- constructor(valueType, modifiers) {
77
- super(modifiers);
78
- this.valueType = valueType || null;
79
- }
80
- visitType(visitor, context) {
81
- return visitor.visitMapType(this, context);
82
- }
83
- }
84
- exports.MapType = MapType;
85
- class TransplantedType extends Type {
86
- type;
87
- constructor(type, modifiers) {
88
- super(modifiers);
89
- this.type = type;
90
- }
91
- visitType(visitor, context) {
92
- return visitor.visitTransplantedType(this, context);
93
- }
94
- }
95
- exports.TransplantedType = TransplantedType;
96
- exports.DYNAMIC_TYPE = new BuiltinType(BuiltinTypeName.Dynamic);
97
- exports.INFERRED_TYPE = new BuiltinType(BuiltinTypeName.Inferred);
98
- exports.BOOL_TYPE = new BuiltinType(BuiltinTypeName.Bool);
99
- exports.INT_TYPE = new BuiltinType(BuiltinTypeName.Int);
100
- exports.NUMBER_TYPE = new BuiltinType(BuiltinTypeName.Number);
101
- exports.STRING_TYPE = new BuiltinType(BuiltinTypeName.String);
102
- exports.FUNCTION_TYPE = new BuiltinType(BuiltinTypeName.Function);
103
- exports.NONE_TYPE = new BuiltinType(BuiltinTypeName.None);
104
- ///// Expressions
105
- var UnaryOperator;
106
- (function (UnaryOperator) {
107
- UnaryOperator[UnaryOperator["Minus"] = 0] = "Minus";
108
- UnaryOperator[UnaryOperator["Plus"] = 1] = "Plus";
109
- })(UnaryOperator || (exports.UnaryOperator = UnaryOperator = {}));
110
- var BinaryOperator;
111
- (function (BinaryOperator) {
112
- BinaryOperator[BinaryOperator["Equals"] = 0] = "Equals";
113
- BinaryOperator[BinaryOperator["NotEquals"] = 1] = "NotEquals";
114
- BinaryOperator[BinaryOperator["Identical"] = 2] = "Identical";
115
- BinaryOperator[BinaryOperator["NotIdentical"] = 3] = "NotIdentical";
116
- BinaryOperator[BinaryOperator["Minus"] = 4] = "Minus";
117
- BinaryOperator[BinaryOperator["Plus"] = 5] = "Plus";
118
- BinaryOperator[BinaryOperator["Divide"] = 6] = "Divide";
119
- BinaryOperator[BinaryOperator["Multiply"] = 7] = "Multiply";
120
- BinaryOperator[BinaryOperator["Modulo"] = 8] = "Modulo";
121
- BinaryOperator[BinaryOperator["And"] = 9] = "And";
122
- BinaryOperator[BinaryOperator["Or"] = 10] = "Or";
123
- BinaryOperator[BinaryOperator["BitwiseOr"] = 11] = "BitwiseOr";
124
- BinaryOperator[BinaryOperator["BitwiseAnd"] = 12] = "BitwiseAnd";
125
- BinaryOperator[BinaryOperator["Lower"] = 13] = "Lower";
126
- BinaryOperator[BinaryOperator["LowerEquals"] = 14] = "LowerEquals";
127
- BinaryOperator[BinaryOperator["Bigger"] = 15] = "Bigger";
128
- BinaryOperator[BinaryOperator["BiggerEquals"] = 16] = "BiggerEquals";
129
- BinaryOperator[BinaryOperator["NullishCoalesce"] = 17] = "NullishCoalesce";
130
- })(BinaryOperator || (exports.BinaryOperator = BinaryOperator = {}));
131
- function nullSafeIsEquivalent(base, other) {
132
- if (base == null || other == null) {
133
- return base == other;
134
- }
135
- return base.isEquivalent(other);
136
- }
137
- exports.nullSafeIsEquivalent = nullSafeIsEquivalent;
138
- function areAllEquivalentPredicate(base, other, equivalentPredicate) {
139
- const len = base.length;
140
- if (len !== other.length) {
141
- return false;
142
- }
143
- for (let i = 0; i < len; i++) {
144
- if (!equivalentPredicate(base[i], other[i])) {
145
- return false;
146
- }
147
- }
148
- return true;
149
- }
150
- function areAllEquivalent(base, other) {
151
- return areAllEquivalentPredicate(base, other, (baseElement, otherElement) => baseElement.isEquivalent(otherElement));
152
- }
153
- exports.areAllEquivalent = areAllEquivalent;
154
- class Expression {
155
- type;
156
- sourceSpan;
157
- constructor(type, sourceSpan) {
158
- this.type = type || null;
159
- this.sourceSpan = sourceSpan || null;
160
- }
161
- prop(name, sourceSpan) {
162
- return new ReadPropExpr(this, name, null, sourceSpan);
163
- }
164
- key(index, type, sourceSpan) {
165
- return new ReadKeyExpr(this, index, type, sourceSpan);
166
- }
167
- callFn(params, sourceSpan, pure) {
168
- return new InvokeFunctionExpr(this, params, null, sourceSpan, pure);
169
- }
170
- bitwiseOr(rhs, sourceSpan, parens = true) {
171
- return new BinaryOperatorExpr(BinaryOperator.BitwiseOr, this, rhs, null, sourceSpan, parens);
172
- }
173
- toStmt() {
174
- return new ExpressionStatement(this, null);
175
- }
176
- }
177
- exports.Expression = Expression;
178
- class ReadVarExpr extends Expression {
179
- name;
180
- constructor(name, type, sourceSpan) {
181
- super(type, sourceSpan);
182
- this.name = name;
183
- }
184
- isEquivalent(e) {
185
- return e instanceof ReadVarExpr && this.name === e.name;
186
- }
187
- isConstant() {
188
- return false;
189
- }
190
- visitExpression(visitor, context) {
191
- return visitor.visitReadVarExpr(this, context);
192
- }
193
- clone() {
194
- return new ReadVarExpr(this.name, this.type, this.sourceSpan);
195
- }
196
- set(value) {
197
- return new WriteVarExpr(this.name, value, null, this.sourceSpan);
198
- }
199
- }
200
- exports.ReadVarExpr = ReadVarExpr;
201
- class TypeofExpr extends Expression {
202
- expr;
203
- constructor(expr, type, sourceSpan) {
204
- super(type, sourceSpan);
205
- this.expr = expr;
206
- }
207
- visitExpression(visitor, context) {
208
- return visitor.visitTypeofExpr(this, context);
209
- }
210
- isEquivalent(e) {
211
- return e instanceof TypeofExpr && e.expr.isEquivalent(this.expr);
212
- }
213
- isConstant() {
214
- return this.expr.isConstant();
215
- }
216
- clone() {
217
- return new TypeofExpr(this.expr.clone());
218
- }
219
- }
220
- exports.TypeofExpr = TypeofExpr;
221
- class WrappedNodeExpr extends Expression {
222
- node;
223
- constructor(node, type, sourceSpan) {
224
- super(type, sourceSpan);
225
- this.node = node;
226
- }
227
- isEquivalent(e) {
228
- return e instanceof WrappedNodeExpr && this.node === e.node;
229
- }
230
- isConstant() {
231
- return false;
232
- }
233
- visitExpression(visitor, context) {
234
- return visitor.visitWrappedNodeExpr(this, context);
235
- }
236
- clone() {
237
- return new WrappedNodeExpr(this.node, this.type, this.sourceSpan);
238
- }
239
- }
240
- exports.WrappedNodeExpr = WrappedNodeExpr;
241
- class WriteVarExpr extends Expression {
242
- name;
243
- value;
244
- constructor(name, value, type, sourceSpan) {
245
- super(type || value.type, sourceSpan);
246
- this.name = name;
247
- this.value = value;
248
- }
249
- isEquivalent(e) {
250
- return (e instanceof WriteVarExpr &&
251
- this.name === e.name &&
252
- this.value.isEquivalent(e.value));
253
- }
254
- isConstant() {
255
- return false;
256
- }
257
- visitExpression(visitor, context) {
258
- return visitor.visitWriteVarExpr(this, context);
259
- }
260
- clone() {
261
- return new WriteVarExpr(this.name, this.value.clone(), this.type, this.sourceSpan);
262
- }
263
- toDeclStmt(type, modifiers) {
264
- return new DeclareVarStmt(this.name, this.value, type, modifiers, this.sourceSpan);
265
- }
266
- toConstDecl() {
267
- return this.toDeclStmt(exports.INFERRED_TYPE, StmtModifier.Final);
268
- }
269
- }
270
- exports.WriteVarExpr = WriteVarExpr;
271
- class WriteKeyExpr extends Expression {
272
- receiver;
273
- index;
274
- value;
275
- constructor(receiver, index, value, type, sourceSpan) {
276
- super(type || value.type, sourceSpan);
277
- this.receiver = receiver;
278
- this.index = index;
279
- this.value = value;
280
- }
281
- isEquivalent(e) {
282
- return (e instanceof WriteKeyExpr &&
283
- this.receiver.isEquivalent(e.receiver) &&
284
- this.index.isEquivalent(e.index) &&
285
- this.value.isEquivalent(e.value));
286
- }
287
- isConstant() {
288
- return false;
289
- }
290
- visitExpression(visitor, context) {
291
- return visitor.visitWriteKeyExpr(this, context);
292
- }
293
- clone() {
294
- return new WriteKeyExpr(this.receiver.clone(), this.index.clone(), this.value.clone(), this.type, this.sourceSpan);
295
- }
296
- }
297
- exports.WriteKeyExpr = WriteKeyExpr;
298
- class WritePropExpr extends Expression {
299
- receiver;
300
- name;
301
- value;
302
- constructor(receiver, name, value, type, sourceSpan) {
303
- super(type || value.type, sourceSpan);
304
- this.receiver = receiver;
305
- this.name = name;
306
- this.value = value;
307
- }
308
- isEquivalent(e) {
309
- return (e instanceof WritePropExpr &&
310
- this.receiver.isEquivalent(e.receiver) &&
311
- this.name === e.name &&
312
- this.value.isEquivalent(e.value));
313
- }
314
- isConstant() {
315
- return false;
316
- }
317
- visitExpression(visitor, context) {
318
- return visitor.visitWritePropExpr(this, context);
319
- }
320
- clone() {
321
- return new WritePropExpr(this.receiver.clone(), this.name, this.value.clone(), this.type, this.sourceSpan);
322
- }
323
- }
324
- exports.WritePropExpr = WritePropExpr;
325
- class InvokeFunctionExpr extends Expression {
326
- fn;
327
- args;
328
- pure;
329
- constructor(fn, args, type, sourceSpan, pure = false) {
330
- super(type, sourceSpan);
331
- this.fn = fn;
332
- this.args = args;
333
- this.pure = pure;
334
- }
335
- // An alias for fn, which allows other logic to handle calls and property reads together.
336
- get receiver() {
337
- return this.fn;
338
- }
339
- isEquivalent(e) {
340
- return (e instanceof InvokeFunctionExpr &&
341
- this.fn.isEquivalent(e.fn) &&
342
- areAllEquivalent(this.args, e.args) &&
343
- this.pure === e.pure);
344
- }
345
- isConstant() {
346
- return false;
347
- }
348
- visitExpression(visitor, context) {
349
- return visitor.visitInvokeFunctionExpr(this, context);
350
- }
351
- clone() {
352
- return new InvokeFunctionExpr(this.fn.clone(), this.args.map((arg) => arg.clone()), this.type, this.sourceSpan, this.pure);
353
- }
354
- }
355
- exports.InvokeFunctionExpr = InvokeFunctionExpr;
356
- class InstantiateExpr extends Expression {
357
- classExpr;
358
- args;
359
- constructor(classExpr, args, type, sourceSpan) {
360
- super(type, sourceSpan);
361
- this.classExpr = classExpr;
362
- this.args = args;
363
- }
364
- isEquivalent(e) {
365
- return (e instanceof InstantiateExpr &&
366
- this.classExpr.isEquivalent(e.classExpr) &&
367
- areAllEquivalent(this.args, e.args));
368
- }
369
- isConstant() {
370
- return false;
371
- }
372
- visitExpression(visitor, context) {
373
- return visitor.visitInstantiateExpr(this, context);
374
- }
375
- clone() {
376
- return new InstantiateExpr(this.classExpr.clone(), this.args.map((arg) => arg.clone()), this.type, this.sourceSpan);
377
- }
378
- }
379
- exports.InstantiateExpr = InstantiateExpr;
380
- class LiteralExpr extends Expression {
381
- value;
382
- constructor(value, type, sourceSpan) {
383
- super(type, sourceSpan);
384
- this.value = value;
385
- }
386
- isEquivalent(e) {
387
- return e instanceof LiteralExpr && this.value === e.value;
388
- }
389
- isConstant() {
390
- return true;
391
- }
392
- visitExpression(visitor, context) {
393
- return visitor.visitLiteralExpr(this, context);
394
- }
395
- clone() {
396
- return new LiteralExpr(this.value, this.type, this.sourceSpan);
397
- }
398
- }
399
- exports.LiteralExpr = LiteralExpr;
400
- class TemplateLiteral {
401
- elements;
402
- expressions;
403
- constructor(elements, expressions) {
404
- this.elements = elements;
405
- this.expressions = expressions;
406
- }
407
- clone() {
408
- return new TemplateLiteral(this.elements.map((el) => el.clone()), this.expressions.map((expr) => expr.clone()));
409
- }
410
- }
411
- exports.TemplateLiteral = TemplateLiteral;
412
- class TemplateLiteralElement {
413
- text;
414
- sourceSpan;
415
- rawText;
416
- constructor(text, sourceSpan, rawText) {
417
- this.text = text;
418
- this.sourceSpan = sourceSpan;
419
- // If `rawText` is not provided, try to extract the raw string from its
420
- // associated `sourceSpan`. If that is also not available, "fake" the raw
421
- // string instead by escaping the following control sequences:
422
- // - "\" would otherwise indicate that the next character is a control character.
423
- // - "`" and "${" are template string control sequences that would otherwise prematurely
424
- // indicate the end of the template literal element.
425
- this.rawText =
426
- rawText ??
427
- sourceSpan?.toString() ??
428
- escapeForTemplateLiteral(escapeSlashes(text));
429
- }
430
- clone() {
431
- return new TemplateLiteralElement(this.text, this.sourceSpan, this.rawText);
432
- }
433
- }
434
- exports.TemplateLiteralElement = TemplateLiteralElement;
435
- class LiteralPiece {
436
- text;
437
- sourceSpan;
438
- constructor(text, sourceSpan) {
439
- this.text = text;
440
- this.sourceSpan = sourceSpan;
441
- }
442
- }
443
- exports.LiteralPiece = LiteralPiece;
444
- const escapeSlashes = (str) => str.replace(/\\/g, '\\\\');
445
- const escapeStartingColon = (str) => str.replace(/^:/, '\\:');
446
- const escapeColons = (str) => str.replace(/:/g, '\\:');
447
- const escapeForTemplateLiteral = (str) => str.replace(/`/g, '\\`').replace(/\${/g, '$\\{');
448
- /**
449
- * Creates a `{cooked, raw}` object from the `metaBlock` and `messagePart`.
450
- *
451
- * The `raw` text must have various character sequences escaped:
452
- * * "\" would otherwise indicate that the next character is a control character.
453
- * * "`" and "${" are template string control sequences that would otherwise prematurely indicate
454
- * the end of a message part.
455
- * * ":" inside a metablock would prematurely indicate the end of the metablock.
456
- * * ":" at the start of a messagePart with no metablock would erroneously indicate the start of a
457
- * metablock.
458
- *
459
- * @param metaBlock Any metadata that should be prepended to the string
460
- * @param messagePart The message part of the string
461
- */
462
- function createCookedRawString(metaBlock, messagePart, range) {
463
- if (metaBlock === '') {
464
- return {
465
- cooked: messagePart,
466
- raw: escapeForTemplateLiteral(escapeStartingColon(escapeSlashes(messagePart))),
467
- range,
468
- };
469
- }
470
- else {
471
- return {
472
- cooked: `:${metaBlock}:${messagePart}`,
473
- raw: escapeForTemplateLiteral(`:${escapeColons(escapeSlashes(metaBlock))}:${escapeSlashes(messagePart)}`),
474
- range,
475
- };
476
- }
477
- }
478
- class ExternalExpr extends Expression {
479
- value;
480
- typeParams;
481
- constructor(value, type, typeParams = null, sourceSpan) {
482
- super(type, sourceSpan);
483
- this.value = value;
484
- this.typeParams = typeParams;
485
- }
486
- isEquivalent(e) {
487
- return (e instanceof ExternalExpr &&
488
- this.value.name === e.value.name &&
489
- this.value.moduleName === e.value.moduleName &&
490
- this.value.runtime === e.value.runtime);
491
- }
492
- isConstant() {
493
- return false;
494
- }
495
- visitExpression(visitor, context) {
496
- return visitor.visitExternalExpr(this, context);
497
- }
498
- clone() {
499
- return new ExternalExpr(this.value, this.type, this.typeParams, this.sourceSpan);
500
- }
501
- }
502
- exports.ExternalExpr = ExternalExpr;
503
- class ExternalReference {
504
- moduleName;
505
- name;
506
- runtime;
507
- constructor(moduleName, name, runtime) {
508
- this.moduleName = moduleName;
509
- this.name = name;
510
- this.runtime = runtime;
511
- }
512
- }
513
- exports.ExternalReference = ExternalReference;
514
- class ConditionalExpr extends Expression {
515
- condition;
516
- falseCase;
517
- trueCase;
518
- constructor(condition, trueCase, falseCase = null, type, sourceSpan) {
519
- super(type || trueCase.type, sourceSpan);
520
- this.condition = condition;
521
- this.falseCase = falseCase;
522
- this.trueCase = trueCase;
523
- }
524
- isEquivalent(e) {
525
- return (e instanceof ConditionalExpr &&
526
- this.condition.isEquivalent(e.condition) &&
527
- this.trueCase.isEquivalent(e.trueCase) &&
528
- nullSafeIsEquivalent(this.falseCase, e.falseCase));
529
- }
530
- isConstant() {
531
- return false;
532
- }
533
- visitExpression(visitor, context) {
534
- return visitor.visitConditionalExpr(this, context);
535
- }
536
- clone() {
537
- return new ConditionalExpr(this.condition.clone(), this.trueCase.clone(), this.falseCase?.clone(), this.type, this.sourceSpan);
538
- }
539
- }
540
- exports.ConditionalExpr = ConditionalExpr;
541
- class DynamicImportExpr extends Expression {
542
- url;
543
- constructor(url, sourceSpan) {
544
- super(null, sourceSpan);
545
- this.url = url;
546
- }
547
- isEquivalent(e) {
548
- return e instanceof DynamicImportExpr && this.url === e.url;
549
- }
550
- isConstant() {
551
- return false;
552
- }
553
- visitExpression(visitor, context) {
554
- return visitor.visitDynamicImportExpr(this, context);
555
- }
556
- clone() {
557
- return new DynamicImportExpr(this.url, this.sourceSpan);
558
- }
559
- }
560
- exports.DynamicImportExpr = DynamicImportExpr;
561
- class NotExpr extends Expression {
562
- condition;
563
- constructor(condition, sourceSpan) {
564
- super(exports.BOOL_TYPE, sourceSpan);
565
- this.condition = condition;
566
- }
567
- isEquivalent(e) {
568
- return e instanceof NotExpr && this.condition.isEquivalent(e.condition);
569
- }
570
- isConstant() {
571
- return false;
572
- }
573
- visitExpression(visitor, context) {
574
- return visitor.visitNotExpr(this, context);
575
- }
576
- clone() {
577
- return new NotExpr(this.condition.clone(), this.sourceSpan);
578
- }
579
- }
580
- exports.NotExpr = NotExpr;
581
- class FnParam {
582
- name;
583
- type;
584
- constructor(name, type = null) {
585
- this.name = name;
586
- this.type = type;
587
- }
588
- isEquivalent(param) {
589
- return this.name === param.name;
590
- }
591
- clone() {
592
- return new FnParam(this.name, this.type);
593
- }
594
- }
595
- exports.FnParam = FnParam;
596
- class FunctionExpr extends Expression {
597
- params;
598
- statements;
599
- name;
600
- constructor(params, statements, type, sourceSpan, name) {
601
- super(type, sourceSpan);
602
- this.params = params;
603
- this.statements = statements;
604
- this.name = name;
605
- }
606
- isEquivalent(e) {
607
- return ((e instanceof FunctionExpr || e instanceof DeclareFunctionStmt) &&
608
- areAllEquivalent(this.params, e.params) &&
609
- areAllEquivalent(this.statements, e.statements));
610
- }
611
- isConstant() {
612
- return false;
613
- }
614
- visitExpression(visitor, context) {
615
- return visitor.visitFunctionExpr(this, context);
616
- }
617
- toDeclStmt(name, modifiers) {
618
- return new DeclareFunctionStmt(name, this.params, this.statements, this.type, modifiers, this.sourceSpan);
619
- }
620
- clone() {
621
- // TODO: Should we deep clone statements?
622
- return new FunctionExpr(this.params.map((p) => p.clone()), this.statements, this.type, this.sourceSpan, this.name);
623
- }
624
- }
625
- exports.FunctionExpr = FunctionExpr;
626
- class ArrowFunctionExpr extends Expression {
627
- params;
628
- body;
629
- // Note that `body: Expression` represents `() => expr` whereas
630
- // `body: Statement[]` represents `() => { expr }`.
631
- constructor(params, body, type, sourceSpan) {
632
- super(type, sourceSpan);
633
- this.params = params;
634
- this.body = body;
635
- }
636
- isEquivalent(e) {
637
- if (!(e instanceof ArrowFunctionExpr) ||
638
- !areAllEquivalent(this.params, e.params)) {
639
- return false;
640
- }
641
- if (this.body instanceof Expression && e.body instanceof Expression) {
642
- return this.body.isEquivalent(e.body);
643
- }
644
- if (Array.isArray(this.body) && Array.isArray(e.body)) {
645
- return areAllEquivalent(this.body, e.body);
646
- }
647
- return false;
648
- }
649
- isConstant() {
650
- return false;
651
- }
652
- visitExpression(visitor, context) {
653
- return visitor.visitArrowFunctionExpr(this, context);
654
- }
655
- clone() {
656
- // TODO: Should we deep clone statements?
657
- return new ArrowFunctionExpr(this.params.map((p) => p.clone()), Array.isArray(this.body) ? this.body : this.body.clone(), this.type, this.sourceSpan);
658
- }
659
- toDeclStmt(name, modifiers) {
660
- return new DeclareVarStmt(name, this, exports.INFERRED_TYPE, modifiers, this.sourceSpan);
661
- }
662
- }
663
- exports.ArrowFunctionExpr = ArrowFunctionExpr;
664
- class UnaryOperatorExpr extends Expression {
665
- operator;
666
- expr;
667
- parens;
668
- constructor(operator, expr, type, sourceSpan, parens = true) {
669
- super(type || exports.NUMBER_TYPE, sourceSpan);
670
- this.operator = operator;
671
- this.expr = expr;
672
- this.parens = parens;
673
- }
674
- isEquivalent(e) {
675
- return (e instanceof UnaryOperatorExpr &&
676
- this.operator === e.operator &&
677
- this.expr.isEquivalent(e.expr));
678
- }
679
- isConstant() {
680
- return false;
681
- }
682
- visitExpression(visitor, context) {
683
- return visitor.visitUnaryOperatorExpr(this, context);
684
- }
685
- clone() {
686
- return new UnaryOperatorExpr(this.operator, this.expr.clone(), this.type, this.sourceSpan, this.parens);
687
- }
688
- }
689
- exports.UnaryOperatorExpr = UnaryOperatorExpr;
690
- class BinaryOperatorExpr extends Expression {
691
- operator;
692
- rhs;
693
- parens;
694
- lhs;
695
- constructor(operator, lhs, rhs, type, sourceSpan, parens = true) {
696
- super(type || lhs.type, sourceSpan);
697
- this.operator = operator;
698
- this.rhs = rhs;
699
- this.parens = parens;
700
- this.lhs = lhs;
701
- }
702
- isEquivalent(e) {
703
- return (e instanceof BinaryOperatorExpr &&
704
- this.operator === e.operator &&
705
- this.lhs.isEquivalent(e.lhs) &&
706
- this.rhs.isEquivalent(e.rhs));
707
- }
708
- isConstant() {
709
- return false;
710
- }
711
- visitExpression(visitor, context) {
712
- return visitor.visitBinaryOperatorExpr(this, context);
713
- }
714
- clone() {
715
- return new BinaryOperatorExpr(this.operator, this.lhs.clone(), this.rhs.clone(), this.type, this.sourceSpan, this.parens);
716
- }
717
- }
718
- exports.BinaryOperatorExpr = BinaryOperatorExpr;
719
- class ReadPropExpr extends Expression {
720
- receiver;
721
- name;
722
- constructor(receiver, name, type, sourceSpan) {
723
- super(type, sourceSpan);
724
- this.receiver = receiver;
725
- this.name = name;
726
- }
727
- // An alias for name, which allows other logic to handle property reads and keyed reads together.
728
- get index() {
729
- return this.name;
730
- }
731
- isEquivalent(e) {
732
- return (e instanceof ReadPropExpr &&
733
- this.receiver.isEquivalent(e.receiver) &&
734
- this.name === e.name);
735
- }
736
- isConstant() {
737
- return false;
738
- }
739
- visitExpression(visitor, context) {
740
- return visitor.visitReadPropExpr(this, context);
741
- }
742
- set(value) {
743
- return new WritePropExpr(this.receiver, this.name, value, null, this.sourceSpan);
744
- }
745
- clone() {
746
- return new ReadPropExpr(this.receiver.clone(), this.name, this.type, this.sourceSpan);
747
- }
748
- }
749
- exports.ReadPropExpr = ReadPropExpr;
750
- class ReadKeyExpr extends Expression {
751
- receiver;
752
- index;
753
- constructor(receiver, index, type, sourceSpan) {
754
- super(type, sourceSpan);
755
- this.receiver = receiver;
756
- this.index = index;
757
- }
758
- isEquivalent(e) {
759
- return (e instanceof ReadKeyExpr &&
760
- this.receiver.isEquivalent(e.receiver) &&
761
- this.index.isEquivalent(e.index));
762
- }
763
- isConstant() {
764
- return false;
765
- }
766
- visitExpression(visitor, context) {
767
- return visitor.visitReadKeyExpr(this, context);
768
- }
769
- set(value) {
770
- return new WriteKeyExpr(this.receiver, this.index, value, null, this.sourceSpan);
771
- }
772
- clone() {
773
- return new ReadKeyExpr(this.receiver.clone(), this.index.clone(), this.type, this.sourceSpan);
774
- }
775
- }
776
- exports.ReadKeyExpr = ReadKeyExpr;
777
- class LiteralArrayExpr extends Expression {
778
- entries;
779
- constructor(entries, type, sourceSpan) {
780
- super(type, sourceSpan);
781
- this.entries = entries;
782
- }
783
- isConstant() {
784
- return this.entries.every((e) => e.isConstant());
785
- }
786
- isEquivalent(e) {
787
- return (e instanceof LiteralArrayExpr && areAllEquivalent(this.entries, e.entries));
788
- }
789
- visitExpression(visitor, context) {
790
- return visitor.visitLiteralArrayExpr(this, context);
791
- }
792
- clone() {
793
- return new LiteralArrayExpr(this.entries.map((e) => e.clone()), this.type, this.sourceSpan);
794
- }
795
- }
796
- exports.LiteralArrayExpr = LiteralArrayExpr;
797
- class LiteralMapEntry {
798
- key;
799
- value;
800
- quoted;
801
- constructor(key, value, quoted) {
802
- this.key = key;
803
- this.value = value;
804
- this.quoted = quoted;
805
- }
806
- isEquivalent(e) {
807
- return this.key === e.key && this.value.isEquivalent(e.value);
808
- }
809
- clone() {
810
- return new LiteralMapEntry(this.key, this.value.clone(), this.quoted);
811
- }
812
- }
813
- exports.LiteralMapEntry = LiteralMapEntry;
814
- class LiteralMapExpr extends Expression {
815
- entries;
816
- valueType = null;
817
- constructor(entries, type, sourceSpan) {
818
- super(type, sourceSpan);
819
- this.entries = entries;
820
- if (type) {
821
- this.valueType = type.valueType;
822
- }
823
- }
824
- isEquivalent(e) {
825
- return (e instanceof LiteralMapExpr && areAllEquivalent(this.entries, e.entries));
826
- }
827
- isConstant() {
828
- return this.entries.every((e) => e.value.isConstant());
829
- }
830
- visitExpression(visitor, context) {
831
- return visitor.visitLiteralMapExpr(this, context);
832
- }
833
- clone() {
834
- const entriesClone = this.entries.map((entry) => entry.clone());
835
- return new LiteralMapExpr(entriesClone, this.type, this.sourceSpan);
836
- }
837
- }
838
- exports.LiteralMapExpr = LiteralMapExpr;
839
- class CommaExpr extends Expression {
840
- parts;
841
- constructor(parts, sourceSpan) {
842
- super(parts[parts.length - 1].type, sourceSpan);
843
- this.parts = parts;
844
- }
845
- isEquivalent(e) {
846
- return e instanceof CommaExpr && areAllEquivalent(this.parts, e.parts);
847
- }
848
- isConstant() {
849
- return false;
850
- }
851
- visitExpression(visitor, context) {
852
- return visitor.visitCommaExpr(this, context);
853
- }
854
- clone() {
855
- return new CommaExpr(this.parts.map((p) => p.clone()));
856
- }
857
- }
858
- exports.CommaExpr = CommaExpr;
859
- exports.NULL_EXPR = new LiteralExpr(null, null, null);
860
- exports.TYPED_NULL_EXPR = new LiteralExpr(null, exports.INFERRED_TYPE, null);
861
- //// Statements
862
- var StmtModifier;
863
- (function (StmtModifier) {
864
- StmtModifier[StmtModifier["None"] = 0] = "None";
865
- StmtModifier[StmtModifier["Final"] = 1] = "Final";
866
- StmtModifier[StmtModifier["Private"] = 2] = "Private";
867
- StmtModifier[StmtModifier["Exported"] = 4] = "Exported";
868
- StmtModifier[StmtModifier["Static"] = 8] = "Static";
869
- })(StmtModifier || (exports.StmtModifier = StmtModifier = {}));
870
- class LeadingComment {
871
- text;
872
- multiline;
873
- trailingNewline;
874
- constructor(text, multiline, trailingNewline) {
875
- this.text = text;
876
- this.multiline = multiline;
877
- this.trailingNewline = trailingNewline;
878
- }
879
- toString() {
880
- return this.multiline ? ` ${this.text} ` : this.text;
881
- }
882
- }
883
- exports.LeadingComment = LeadingComment;
884
- class JSDocComment extends LeadingComment {
885
- tags;
886
- constructor(tags) {
887
- super('', /* multiline */ true, /* trailingNewline */ true);
888
- this.tags = tags;
889
- }
890
- toString() {
891
- return serializeTags(this.tags);
892
- }
893
- }
894
- exports.JSDocComment = JSDocComment;
895
- class Statement {
896
- modifiers;
897
- sourceSpan;
898
- leadingComments;
899
- constructor(modifiers = StmtModifier.None, sourceSpan = null, leadingComments) {
900
- this.modifiers = modifiers;
901
- this.sourceSpan = sourceSpan;
902
- this.leadingComments = leadingComments;
903
- }
904
- hasModifier(modifier) {
905
- return (this.modifiers & modifier) !== 0;
906
- }
907
- addLeadingComment(leadingComment) {
908
- this.leadingComments = this.leadingComments ?? [];
909
- this.leadingComments.push(leadingComment);
910
- }
911
- }
912
- exports.Statement = Statement;
913
- class DeclareVarStmt extends Statement {
914
- name;
915
- value;
916
- type;
917
- constructor(name, value, type, modifiers, sourceSpan, leadingComments) {
918
- super(modifiers, sourceSpan, leadingComments);
919
- this.name = name;
920
- this.value = value;
921
- this.type = type || (value && value.type) || null;
922
- }
923
- isEquivalent(stmt) {
924
- return (stmt instanceof DeclareVarStmt &&
925
- this.name === stmt.name &&
926
- (this.value
927
- ? !!stmt.value && this.value.isEquivalent(stmt.value)
928
- : !stmt.value));
929
- }
930
- visitStatement(visitor, context) {
931
- return visitor.visitDeclareVarStmt(this, context);
932
- }
933
- }
934
- exports.DeclareVarStmt = DeclareVarStmt;
935
- class DeclareFunctionStmt extends Statement {
936
- name;
937
- params;
938
- statements;
939
- type;
940
- constructor(name, params, statements, type, modifiers, sourceSpan, leadingComments) {
941
- super(modifiers, sourceSpan, leadingComments);
942
- this.name = name;
943
- this.params = params;
944
- this.statements = statements;
945
- this.type = type || null;
946
- }
947
- isEquivalent(stmt) {
948
- return (stmt instanceof DeclareFunctionStmt &&
949
- areAllEquivalent(this.params, stmt.params) &&
950
- areAllEquivalent(this.statements, stmt.statements));
951
- }
952
- visitStatement(visitor, context) {
953
- return visitor.visitDeclareFunctionStmt(this, context);
954
- }
955
- }
956
- exports.DeclareFunctionStmt = DeclareFunctionStmt;
957
- class ExpressionStatement extends Statement {
958
- expr;
959
- constructor(expr, sourceSpan, leadingComments) {
960
- super(StmtModifier.None, sourceSpan, leadingComments);
961
- this.expr = expr;
962
- }
963
- isEquivalent(stmt) {
964
- return (stmt instanceof ExpressionStatement && this.expr.isEquivalent(stmt.expr));
965
- }
966
- visitStatement(visitor, context) {
967
- return visitor.visitExpressionStmt(this, context);
968
- }
969
- }
970
- exports.ExpressionStatement = ExpressionStatement;
971
- class ReturnStatement extends Statement {
972
- value;
973
- constructor(value, sourceSpan = null, leadingComments) {
974
- super(StmtModifier.None, sourceSpan, leadingComments);
975
- this.value = value;
976
- }
977
- isEquivalent(stmt) {
978
- return (stmt instanceof ReturnStatement && this.value.isEquivalent(stmt.value));
979
- }
980
- visitStatement(visitor, context) {
981
- return visitor.visitReturnStmt(this, context);
982
- }
983
- }
984
- exports.ReturnStatement = ReturnStatement;
985
- class IfStmt extends Statement {
986
- condition;
987
- trueCase;
988
- falseCase;
989
- constructor(condition, trueCase, falseCase = [], sourceSpan, leadingComments) {
990
- super(StmtModifier.None, sourceSpan, leadingComments);
991
- this.condition = condition;
992
- this.trueCase = trueCase;
993
- this.falseCase = falseCase;
994
- }
995
- isEquivalent(stmt) {
996
- return (stmt instanceof IfStmt &&
997
- this.condition.isEquivalent(stmt.condition) &&
998
- areAllEquivalent(this.trueCase, stmt.trueCase) &&
999
- areAllEquivalent(this.falseCase, stmt.falseCase));
1000
- }
1001
- visitStatement(visitor, context) {
1002
- return visitor.visitIfStmt(this, context);
1003
- }
1004
- }
1005
- exports.IfStmt = IfStmt;
1006
- function leadingComment(text, multiline = false, trailingNewline = true) {
1007
- return new LeadingComment(text, multiline, trailingNewline);
1008
- }
1009
- exports.leadingComment = leadingComment;
1010
- function jsDocComment(tags = []) {
1011
- return new JSDocComment(tags);
1012
- }
1013
- exports.jsDocComment = jsDocComment;
1014
- function variable(name, type, sourceSpan) {
1015
- return new ReadVarExpr(name, type, sourceSpan);
1016
- }
1017
- exports.variable = variable;
1018
- function importExpr(id, typeParams = null, sourceSpan) {
1019
- return new ExternalExpr(id, null, typeParams, sourceSpan);
1020
- }
1021
- exports.importExpr = importExpr;
1022
- function importType(id, typeParams, typeModifiers) {
1023
- return id != null
1024
- ? expressionType(importExpr(id, typeParams, null), typeModifiers)
1025
- : null;
1026
- }
1027
- exports.importType = importType;
1028
- function expressionType(expr, typeModifiers, typeParams) {
1029
- return new ExpressionType(expr, typeModifiers, typeParams);
1030
- }
1031
- exports.expressionType = expressionType;
1032
- function transplantedType(type, typeModifiers) {
1033
- return new TransplantedType(type, typeModifiers);
1034
- }
1035
- exports.transplantedType = transplantedType;
1036
- function typeofExpr(expr) {
1037
- return new TypeofExpr(expr);
1038
- }
1039
- exports.typeofExpr = typeofExpr;
1040
- function literalArr(values, type, sourceSpan) {
1041
- return new LiteralArrayExpr(values, type, sourceSpan);
1042
- }
1043
- exports.literalArr = literalArr;
1044
- function literalMap(values, type = null) {
1045
- return new LiteralMapExpr(values.map((e) => new LiteralMapEntry(e.key, e.value, e.quoted)), type, null);
1046
- }
1047
- exports.literalMap = literalMap;
1048
- function unary(operator, expr, type, sourceSpan) {
1049
- return new UnaryOperatorExpr(operator, expr, type, sourceSpan);
1050
- }
1051
- exports.unary = unary;
1052
- function not(expr, sourceSpan) {
1053
- return new NotExpr(expr, sourceSpan);
1054
- }
1055
- exports.not = not;
1056
- function fn(params, body, type, sourceSpan, name) {
1057
- return new FunctionExpr(params, body, type, sourceSpan, name);
1058
- }
1059
- exports.fn = fn;
1060
- function arrowFn(params, body, type, sourceSpan) {
1061
- return new ArrowFunctionExpr(params, body, type, sourceSpan);
1062
- }
1063
- exports.arrowFn = arrowFn;
1064
- function ifStmt(condition, thenClause, elseClause, sourceSpan, leadingComments) {
1065
- return new IfStmt(condition, thenClause, elseClause, sourceSpan, leadingComments);
1066
- }
1067
- exports.ifStmt = ifStmt;
1068
- function literal(value, type, sourceSpan) {
1069
- return new LiteralExpr(value, type, sourceSpan);
1070
- }
1071
- exports.literal = literal;
1072
- function isNull(exp) {
1073
- return exp instanceof LiteralExpr && exp.value === null;
1074
- }
1075
- exports.isNull = isNull;
1076
- /*
1077
- * Serializes a `Tag` into a string.
1078
- * Returns a string like " @foo {bar} baz" (note the leading whitespace before `@foo`).
1079
- */
1080
- function tagToString(tag) {
1081
- let out = '';
1082
- if (tag.tagName) {
1083
- out += ` @${tag.tagName}`;
1084
- }
1085
- if (tag.text) {
1086
- if (tag.text.match(/\/\*|\*\//)) {
1087
- throw new Error('JSDoc text cannot contain "/*" and "*/"');
1088
- }
1089
- out += ' ' + tag.text.replace(/@/g, '\\@');
1090
- }
1091
- return out;
1092
- }
1093
- function serializeTags(tags) {
1094
- if (tags.length === 0)
1095
- return '';
1096
- if (tags.length === 1 && tags[0].tagName && !tags[0].text) {
1097
- // The JSDOC comment is a single simple tag: e.g `/** @tagname */`.
1098
- return `*${tagToString(tags[0])} `;
1099
- }
1100
- let out = '*\n';
1101
- for (const tag of tags) {
1102
- out += ' *';
1103
- // If the tagToString is multi-line, insert " * " prefixes on lines.
1104
- out += tagToString(tag).replace(/\n/g, '\n * ');
1105
- out += '\n';
1106
- }
1107
- out += ' ';
1108
- return out;
1109
- }