@@ -1176,12 +1176,20 @@ export enum ModifierKind {
11761176/** Base class of all statement nodes. */
11771177export abstract class Statement extends Node { }
11781178
1179+ export enum SourceKind {
1180+ DEFAULT ,
1181+ ENTRY ,
1182+ STDLIB
1183+ }
1184+
11791185/** A top-level source node. */
11801186export class Source extends Node {
11811187
11821188 kind = NodeKind . SOURCE ;
11831189 parent = null ;
11841190
1191+ /** Source kind. */
1192+ sourceKind : SourceKind ;
11851193 /** Path as provided to the parser. */
11861194 path : string ;
11871195 /** Normalized path. */
@@ -1194,21 +1202,24 @@ export class Source extends Node {
11941202 text : string ;
11951203 /** Tokenizer reference. */
11961204 tokenizer : Tokenizer | null = null ;
1197- /** Whether an entry file or not. */
1198- isEntry : bool ;
11991205
12001206 /** Constructs a new source node. */
1201- constructor ( path : string , text : string , isEntry : bool = false ) {
1207+ constructor ( path : string , text : string , kind : SourceKind = SourceKind . DEFAULT ) {
12021208 super ( ) ;
1209+ this . sourceKind = kind ;
12031210 this . path = path ;
12041211 this . normalizedPath = normalizePath ( path , true ) ;
12051212 this . internalPath = mangleInternalPath ( this . normalizedPath ) ;
12061213 this . statements = new Array ( ) ;
12071214 this . range = new Range ( this , 0 , text . length ) ;
12081215 this . text = text ;
1209- this . isEntry = isEntry ;
12101216 }
12111217
1218+ /** Tests if this source is an entry file. */
1219+ get isEntry ( ) : bool { return this . sourceKind == SourceKind . ENTRY ; }
1220+ /** Tests if this source is a stdlib file. */
1221+ get isStdlib ( ) : bool { return this . sourceKind == SourceKind . STDLIB ; }
1222+
12121223 serialize ( sb : string [ ] ) : void {
12131224 for ( var i : i32 = 0 , k : i32 = this . statements . length ; i < k ; ++ i ) {
12141225 this . statements [ i ] . serialize ( sb ) ;
@@ -1236,6 +1247,8 @@ export abstract class DeclarationStatement extends Statement {
12361247
12371248 /** Gets the mangled internal name of this declaration. */
12381249 get internalName ( ) : string { return this . _cachedInternalName === null ? this . _cachedInternalName = mangleInternalName ( this ) : this . _cachedInternalName ; }
1250+ /** Tests if this is a top-level declaration. */
1251+ get isTopLevel ( ) : bool { return this . parent != null && this . parent . kind == NodeKind . SOURCE ; }
12391252}
12401253
12411254/** Base class of all variable-like declaration statements with a type and initializer. */
0 commit comments