Skip to content

Commit 1098e80

Browse files
Remove one-based helper function.
1 parent 8ef4df8 commit 1098e80

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/compiler/emitter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,13 @@ module ts {
17331733
}
17341734
}
17351735

1736+
function getOneBasedLineAndCharacterOfPosition(sourceFile: SourceFile, pos: number) {
1737+
var result = getZeroBasedLineAndCharacterOfPosition(sourceFile, pos);
1738+
result.line++;
1739+
result.character++;
1740+
return result;
1741+
}
1742+
17361743
function recordSourceMapSpan(pos: number) {
17371744
var sourceLinePos = getOneBasedLineAndCharacterOfPosition(currentSourceFile, pos);
17381745
var emittedLine = writer.getLine();

src/compiler/scanner.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,6 @@ module ts {
319319
return computeZeroBasedLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
320320
}
321321

322-
export function getOneBasedLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter {
323-
return computeOneBasedLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
324-
}
325-
326322
var hasOwnProperty = Object.prototype.hasOwnProperty;
327323

328324
export function isWhiteSpace(ch: number): boolean {

src/compiler/tsc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module ts {
7272
function countLines(program: Program): number {
7373
var count = 0;
7474
forEach(program.getSourceFiles(), file => {
75-
count += getOneBasedLineAndCharacterOfPosition(file, file.end).line;
75+
count += getLineStarts(file).length;
7676
});
7777
return count;
7878
}
@@ -86,9 +86,9 @@ module ts {
8686
var output = "";
8787

8888
if (diagnostic.file) {
89-
var loc = getOneBasedLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
89+
var loc = getZeroBasedLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
9090

91-
output += diagnostic.file.fileName + "(" + loc.line + "," + loc.character + "): ";
91+
output += diagnostic.file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + "): ";
9292
}
9393

9494
var category = DiagnosticCategory[diagnostic.category].toLowerCase();

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ module ts {
118118
// This is a useful function for debugging purposes.
119119
export function nodePosToString(node: Node): string {
120120
var file = getSourceFileOfNode(node);
121-
var loc = getOneBasedLineAndCharacterOfPosition(file, node.pos);
122-
return file.fileName + "(" + loc.line + "," + loc.character + ")";
121+
var loc = getZeroBasedLineAndCharacterOfPosition(file, node.pos);
122+
return file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + ")";
123123
}
124124

125125
export function getStartPosOfNode(node: Node): number {

src/services/services.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,10 @@ module ts {
756756
}
757757

758758
public getOneBasedLineAndCharacterOfPosition(position: number): LineAndCharacter {
759-
return ts.getOneBasedLineAndCharacterOfPosition(this, position);
759+
var result = ts.getZeroBasedLineAndCharacterOfPosition(this, position);
760+
result.line++;
761+
result.character++;
762+
return result;
760763
}
761764

762765
public getLineStarts(): number[] {

0 commit comments

Comments
 (0)