@@ -30,10 +30,10 @@ let buffer: BufferWithArrays | null = null;
3030let hasBOM = false ;
3131
3232// Lazily populated when `SOURCE_CODE.text` or `SOURCE_CODE.ast` is accessed,
33- // or `getAst ()` is called before the AST is walked.
33+ // or `initAst ()` is called before the AST is walked.
3434let sourceText : string | null = null ;
3535let sourceByteLen : number = 0 ;
36- let ast : Program | null = null ;
36+ export let ast : Program | null = null ;
3737
3838// Lazily populated when `SOURCE_CODE.lines` is accessed.
3939// `lineStartOffsets` starts as `[0]`, and `resetSource` doesn't remove that initial element, so it's never empty.
@@ -66,21 +66,11 @@ function initSourceText(): void {
6666/**
6767 * Deserialize AST from buffer.
6868 */
69- function initAst ( ) : void {
69+ export function initAst ( ) : void {
7070 if ( sourceText === null ) initSourceText ( ) ;
7171 ast = deserializeProgramOnly ( buffer , sourceText , sourceByteLen ) ;
7272}
7373
74- /**
75- * Get AST of the file being linted.
76- * If AST has not already been deserialized, do it now.
77- * @returns AST of the file being linted.
78- */
79- export function getAst ( ) : Program {
80- if ( ast === null ) initAst ( ) ;
81- return ast ;
82- }
83-
8474/**
8575 * Split source text into lines.
8676 */
@@ -151,7 +141,8 @@ export const SOURCE_CODE = Object.freeze({
151141
152142 // Get AST of the file.
153143 get ast ( ) : Program {
154- return getAst ( ) ;
144+ if ( ast === null ) initAst ( ) ;
145+ return ast ;
155146 } ,
156147
157148 // Get `ScopeManager` for the file.
0 commit comments