@@ -111,17 +111,6 @@ export enum NodeKind {
111
111
COMMENT
112
112
}
113
113
114
- /** Checks if a node represents a constant value. */
115
- export function nodeIsConstantValue ( kind : NodeKind ) : bool {
116
- switch ( kind ) {
117
- case NodeKind . LITERAL :
118
- case NodeKind . NULL :
119
- case NodeKind . TRUE :
120
- case NodeKind . FALSE : return true ;
121
- }
122
- return false ;
123
- }
124
-
125
114
/** Base class of all nodes. */
126
115
export abstract class Node {
127
116
/** Node kind indicator. */
@@ -1141,6 +1130,41 @@ export abstract class Node {
1141
1130
node . statement = statement ;
1142
1131
return node ;
1143
1132
}
1133
+
1134
+ /** Tests if this node is a literal of the specified kind. */
1135
+ isLiteralKind ( literalKind : LiteralKind ) : bool {
1136
+ return this . kind == NodeKind . LITERAL
1137
+ && ( < LiteralExpression > changetype < Node > ( this ) ) . literalKind == literalKind ; // TS
1138
+ }
1139
+
1140
+ /** Tests if this node is a literal of a numeric kind (float or integer). */
1141
+ get isNumericLiteral ( ) : bool {
1142
+ if ( this . kind == NodeKind . LITERAL ) {
1143
+ switch ( ( < LiteralExpression > changetype < Node > ( this ) ) . literalKind ) { // TS
1144
+ case LiteralKind . FLOAT :
1145
+ case LiteralKind . INTEGER : return true ;
1146
+ }
1147
+ }
1148
+ return false ;
1149
+ }
1150
+
1151
+ /** Tests whether this node is guaranteed to compile to a constant value. */
1152
+ get compilesToConst ( ) : bool {
1153
+ switch ( this . kind ) {
1154
+ case NodeKind . LITERAL : {
1155
+ switch ( ( < LiteralExpression > changetype < Node > ( this ) ) . literalKind ) { // TS
1156
+ case LiteralKind . FLOAT :
1157
+ case LiteralKind . INTEGER :
1158
+ case LiteralKind . STRING : return true ;
1159
+ }
1160
+ break ;
1161
+ }
1162
+ case NodeKind . NULL :
1163
+ case NodeKind . TRUE :
1164
+ case NodeKind . FALSE : return true ;
1165
+ }
1166
+ return false ;
1167
+ }
1144
1168
}
1145
1169
1146
1170
// types
@@ -1153,28 +1177,29 @@ export abstract class TypeNode extends Node {
1153
1177
1154
1178
/** Tests if this type has a generic component matching one of the given type parameters. */
1155
1179
hasGenericComponent ( typeParameterNodes : TypeParameterNode [ ] ) : bool {
1156
- var self = < TypeNode > this ; // TS otherwise complains
1157
1180
if ( this . kind == NodeKind . NAMEDTYPE ) {
1158
- if ( ! ( < NamedTypeNode > self ) . name . next ) {
1159
- let typeArgumentNodes = ( < NamedTypeNode > self ) . typeArguments ;
1181
+ let namedTypeNode = < NamedTypeNode > changetype < TypeNode > ( this ) ; // TS
1182
+ if ( ! namedTypeNode . name . next ) {
1183
+ let typeArgumentNodes = namedTypeNode . typeArguments ;
1160
1184
if ( typeArgumentNodes !== null && typeArgumentNodes . length > 0 ) {
1161
1185
for ( let i = 0 , k = typeArgumentNodes . length ; i < k ; ++ i ) {
1162
1186
if ( typeArgumentNodes [ i ] . hasGenericComponent ( typeParameterNodes ) ) return true ;
1163
1187
}
1164
1188
} else {
1165
- let name = ( < NamedTypeNode > self ) . name . identifier . text ;
1189
+ let name = namedTypeNode . name . identifier . text ;
1166
1190
for ( let i = 0 , k = typeParameterNodes . length ; i < k ; ++ i ) {
1167
1191
if ( typeParameterNodes [ i ] . name . text == name ) return true ;
1168
1192
}
1169
1193
}
1170
1194
}
1171
1195
} else if ( this . kind == NodeKind . FUNCTIONTYPE ) {
1172
- let parameterNodes = ( < FunctionTypeNode > self ) . parameters ;
1196
+ let functionTypeNode = < FunctionTypeNode > changetype < TypeNode > ( this ) ; // TS
1197
+ let parameterNodes = functionTypeNode . parameters ;
1173
1198
for ( let i = 0 , k = parameterNodes . length ; i < k ; ++ i ) {
1174
1199
if ( parameterNodes [ i ] . type . hasGenericComponent ( typeParameterNodes ) ) return true ;
1175
1200
}
1176
- if ( ( < FunctionTypeNode > self ) . returnType . hasGenericComponent ( typeParameterNodes ) ) return true ;
1177
- let explicitThisType = ( < FunctionTypeNode > self ) . explicitThisType ;
1201
+ if ( functionTypeNode . returnType . hasGenericComponent ( typeParameterNodes ) ) return true ;
1202
+ let explicitThisType = functionTypeNode . explicitThisType ;
1178
1203
if ( explicitThisType !== null && explicitThisType . hasGenericComponent ( typeParameterNodes ) ) return true ;
1179
1204
} else {
1180
1205
assert ( false ) ;
@@ -1319,25 +1344,26 @@ export namespace DecoratorKind {
1319
1344
break ;
1320
1345
}
1321
1346
}
1322
- } else if (
1323
- nameNode . kind == NodeKind . PROPERTYACCESS &&
1324
- ( < PropertyAccessExpression > nameNode ) . expression . kind == NodeKind . IDENTIFIER
1325
- ) {
1326
- let nameStr = ( < IdentifierExpression > ( < PropertyAccessExpression > nameNode ) . expression ) . text ;
1327
- assert ( nameStr . length ) ;
1328
- let propStr = ( < PropertyAccessExpression > nameNode ) . property . text ;
1329
- assert ( propStr . length ) ;
1330
- // @operator .binary, @operator.prefix, @operator.postfix
1331
- if ( nameStr == "operator" ) {
1332
- switch ( propStr . charCodeAt ( 0 ) ) {
1333
- case CharCode . b : {
1334
- if ( propStr == "binary" ) return DecoratorKind . OPERATOR_BINARY ;
1335
- break ;
1336
- }
1337
- case CharCode . p : {
1338
- if ( propStr == "prefix" ) return DecoratorKind . OPERATOR_PREFIX ;
1339
- if ( propStr == "postfix" ) return DecoratorKind . OPERATOR_POSTFIX ;
1340
- break ;
1347
+ } else if ( nameNode . kind == NodeKind . PROPERTYACCESS ) {
1348
+ let propertyAccessNode = < PropertyAccessExpression > nameNode ;
1349
+ let expression = propertyAccessNode . expression ;
1350
+ if ( expression . kind == NodeKind . IDENTIFIER ) {
1351
+ let nameStr = ( < IdentifierExpression > expression ) . text ;
1352
+ assert ( nameStr . length ) ;
1353
+ let propStr = propertyAccessNode . property . text ;
1354
+ assert ( propStr . length ) ;
1355
+ // @operator .binary, @operator.prefix, @operator.postfix
1356
+ if ( nameStr == "operator" ) {
1357
+ switch ( propStr . charCodeAt ( 0 ) ) {
1358
+ case CharCode . b : {
1359
+ if ( propStr == "binary" ) return DecoratorKind . OPERATOR_BINARY ;
1360
+ break ;
1361
+ }
1362
+ case CharCode . p : {
1363
+ if ( propStr == "prefix" ) return DecoratorKind . OPERATOR_PREFIX ;
1364
+ if ( propStr == "postfix" ) return DecoratorKind . OPERATOR_POSTFIX ;
1365
+ break ;
1366
+ }
1341
1367
}
1342
1368
}
1343
1369
}
@@ -1397,17 +1423,6 @@ export enum LiteralKind {
1397
1423
OBJECT
1398
1424
}
1399
1425
1400
- /** Checks if the given node represents a numeric (float or integer) literal. */
1401
- export function isNumericLiteral ( node : Expression ) : bool {
1402
- if ( node . kind == NodeKind . LITERAL ) {
1403
- switch ( ( < LiteralExpression > node ) . literalKind ) {
1404
- case LiteralKind . FLOAT :
1405
- case LiteralKind . INTEGER : return true ;
1406
- }
1407
- }
1408
- return false ;
1409
- }
1410
-
1411
1426
/** Base class of all literal expressions. */
1412
1427
export abstract class LiteralExpression extends Expression {
1413
1428
/** Specific literal kind. */
0 commit comments