Skip to content

Commit

Permalink
Adds a debug command to the scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Aug 8, 2019
1 parent b239c2a commit 71fa26a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ namespace ts {

setText(text, start, length);

return {
const scanner: Scanner = {
getStartPos: () => startPos,
getTextPos: () => pos,
getToken: () => token,
Expand Down Expand Up @@ -912,6 +912,17 @@ namespace ts {
scanRange,
};

if (Debug.isDebugging) {
Object.defineProperty(scanner, "__debugShowCurrentPositionInText", {
get: () => {
const text = scanner.getText();
return text.slice(0, scanner.getStartPos()) + "║" + text.slice(scanner.getStartPos());
},
});
}

return scanner;

function error(message: DiagnosticMessage): void;
function error(message: DiagnosticMessage, errPos: number, length: number): void;
function error(message: DiagnosticMessage, errPos: number = pos, length?: number): void {
Expand Down

0 comments on commit 71fa26a

Please sign in to comment.