Skip to content

Commit

Permalink
Fix lexer crash when given undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Jul 9, 2024
1 parent 4a6b4a7 commit db46e59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export class LanguageServer {
timestamp: Date.now(),
index: this.busyStatusIndex,
activeRuns: [...this.projectManager.busyStatusTracker.activeRuns]
}).catch(logAndIgnoreError);
})?.catch(logAndIgnoreError);
}
private busyStatusIndex = -1;

Expand Down
9 changes: 9 additions & 0 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ describe('BrsFile', () => {
program.dispose();
});

describe('dispose', () => {
it('does not crash the program after it has been disposed', () => {
const file = program.setFile('source/main.bs', `sub main(): end sub`);
file.dispose();
program.validate();
expectZeroDiagnostics(program);
});
});

describe('allowBrighterScriptInBrightScript', () => {
it('is false by default', () => {
program.setFile('source/main.brs', `
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class Lexer {
* @returns `true` if the lexer has read to (or past) the end of its input, otherwise `false`.
*/
private isAtEnd() {
return this.current >= this.source.length;
return !this.source || this.current >= this.source.length;
}

/**
Expand Down

0 comments on commit db46e59

Please sign in to comment.