Skip to content

Commit 12749c9

Browse files
Added tests, and perhaps fixed a test runner bug?
1 parent 956ac21 commit 12749c9

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/compiler/scanner.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,12 @@ namespace ts {
17401740
pos++;
17411741
}
17421742

1743-
commentDirectives = appendIfCommentDirective(commentDirectives, text.slice(tokenPos, pos), commentDirectiveRegExSingleLine);
1743+
commentDirectives = appendIfCommentDirective(
1744+
commentDirectives,
1745+
text.slice(tokenPos, pos),
1746+
commentDirectiveRegExSingleLine,
1747+
tokenPos,
1748+
);
17441749

17451750
if (skipTrivia) {
17461751
continue;
@@ -2119,7 +2124,12 @@ namespace ts {
21192124
return token;
21202125
}
21212126

2122-
function appendIfCommentDirective(commentDirectives: CommentDirective[] | undefined, text: string, commentDirectiveRegEx: RegExp, lineStart = tokenPos) {
2127+
function appendIfCommentDirective(
2128+
commentDirectives: CommentDirective[] | undefined,
2129+
text: string,
2130+
commentDirectiveRegEx: RegExp,
2131+
lineStart: number,
2132+
) {
21232133
const type = getDirectiveFromComment(text, commentDirectiveRegEx);
21242134
if (type === undefined) {
21252135
return commentDirectives;

src/testRunner/unittests/incrementalParser.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ module m3 { }\
833833
});
834834

835835
describe("comment directives", () => {
836-
const tsIgnoreComment = "// @ts-ignore";
836+
const tsIgnoreComment = "@ts-ignore";
837837
const textWithIgnoreComment = `const x = 10;
838838
function foo() {
839839
// @ts-ignore
@@ -845,14 +845,27 @@ function bar() {
845845
let z : string = x;
846846
return z;
847847
}
848-
function bar3() {
848+
function bar2() {
849849
// @ts-ignore
850850
let z : string = x;
851851
return z;
852852
}
853+
function bar3() {
854+
/* @ts-ignore */
855+
let z : string = x;
856+
return z;
857+
}
858+
function bar4() {
859+
/*
860+
@ts-ignore */
861+
let z : string = x;
862+
return z;
863+
}
853864
foo();
854865
bar();
855-
bar3();`;
866+
bar3();
867+
bar4();
868+
bar5()`;
856869
verifyScenario("when deleting ts-ignore comment", verifyDelete);
857870
verifyScenario("when inserting ts-ignore comment", verifyInsert);
858871
verifyScenario("when changing ts-ignore comment to blah", verifyChangeToBlah);
@@ -876,17 +889,23 @@ bar3();`;
876889
it(`${scenario} - 2`, () => {
877890
verifyChange(2);
878891
});
892+
it(`${scenario} - 3`, () => {
893+
verifyChange(3);
894+
});
895+
it(`${scenario} - 4`, () => {
896+
verifyChange(4);
897+
});
879898
it(`${scenario} - with single ts-ignore`, () => {
880899
verifyChange(0, /*singleIgnore*/ true);
881900
});
882901
}
883902

884903
function getIndexOfTsIgnoreComment(atIndex: number) {
885-
let index: number;
904+
let index = 0;
886905
for (let i = 0; i <= atIndex; i++) {
887-
index = textWithIgnoreComment.indexOf(tsIgnoreComment);
906+
index = textWithIgnoreComment.indexOf(tsIgnoreComment, index);
888907
}
889-
return index!;
908+
return index;
890909
}
891910

892911
function textWithIgnoreCommentFrom(text: string, singleIgnore: true | undefined) {

0 commit comments

Comments
 (0)