@@ -111,17 +111,6 @@ export enum NodeKind {
111111 COMMENT
112112}
113113
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-
125114/** Base class of all nodes. */
126115export abstract class Node {
127116 /** Node kind indicator. */
@@ -1141,6 +1130,41 @@ export abstract class Node {
11411130 node . statement = statement ;
11421131 return node ;
11431132 }
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+ }
11441168}
11451169
11461170// types
@@ -1153,28 +1177,29 @@ export abstract class TypeNode extends Node {
11531177
11541178 /** Tests if this type has a generic component matching one of the given type parameters. */
11551179 hasGenericComponent ( typeParameterNodes : TypeParameterNode [ ] ) : bool {
1156- var self = < TypeNode > this ; // TS otherwise complains
11571180 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 ;
11601184 if ( typeArgumentNodes !== null && typeArgumentNodes . length > 0 ) {
11611185 for ( let i = 0 , k = typeArgumentNodes . length ; i < k ; ++ i ) {
11621186 if ( typeArgumentNodes [ i ] . hasGenericComponent ( typeParameterNodes ) ) return true ;
11631187 }
11641188 } else {
1165- let name = ( < NamedTypeNode > self ) . name . identifier . text ;
1189+ let name = namedTypeNode . name . identifier . text ;
11661190 for ( let i = 0 , k = typeParameterNodes . length ; i < k ; ++ i ) {
11671191 if ( typeParameterNodes [ i ] . name . text == name ) return true ;
11681192 }
11691193 }
11701194 }
11711195 } 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 ;
11731198 for ( let i = 0 , k = parameterNodes . length ; i < k ; ++ i ) {
11741199 if ( parameterNodes [ i ] . type . hasGenericComponent ( typeParameterNodes ) ) return true ;
11751200 }
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 ;
11781203 if ( explicitThisType !== null && explicitThisType . hasGenericComponent ( typeParameterNodes ) ) return true ;
11791204 } else {
11801205 assert ( false ) ;
@@ -1319,25 +1344,26 @@ export namespace DecoratorKind {
13191344 break ;
13201345 }
13211346 }
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+ }
13411367 }
13421368 }
13431369 }
@@ -1397,17 +1423,6 @@ export enum LiteralKind {
13971423 OBJECT
13981424}
13991425
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-
14111426/** Base class of all literal expressions. */
14121427export abstract class LiteralExpression extends Expression {
14131428 /** Specific literal kind. */
0 commit comments