Skip to content

Commit c777d5c

Browse files
Report error on unclosed multiline comment.
Fixes #22
1 parent 455364c commit c777d5c

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

src/compiler/scanner.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,14 @@ module ts {
662662
if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
663663
pos += 2;
664664

665-
while (pos < len) {
665+
var safeLength = len - 1; // For lookahead.
666+
var commentClosed = false;
667+
while (pos < safeLength) {
666668
var ch = text.charCodeAt(pos);
667669

668670
if (ch === CharacterCodes.asterisk && text.charCodeAt(pos + 1) === CharacterCodes.slash) {
669671
pos += 2;
672+
commentClosed = true;
670673
break;
671674
}
672675

@@ -676,6 +679,11 @@ module ts {
676679
pos++;
677680
}
678681

682+
if (!commentClosed) {
683+
pos++;
684+
onError(Diagnostics.Asterisk_Slash_expected);
685+
}
686+
679687
if (onComment) {
680688
onComment(tokenPos, pos);
681689
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
==== tests/cases/conformance/parser/ecmascript5/parserKeywordsAsIdentifierName2.ts (2 errors) ====
2+
// 'public' should be marked unusable, should complain on trailing /*
3+
a.public /*
4+
5+
!!! '*/' expected.
6+
~
7+
!!! Cannot find name 'a'.

tests/baselines/reference/parserKeywordsAsIdentifierName2.js

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
==== tests/cases/conformance/scanner/ecmascript5/scannerS7.4_A2_T2.ts (1 errors) ====
2+
// Copyright 2009 the Sputnik authors. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
5+
/**
6+
* Correct interpretation of multi line comments
7+
*
8+
* @path ch07/7.4/S7.4_A2_T2.js
9+
* @description Try use /*CHECK#1/. This is not closed multi line comment
10+
* @negative
11+
*/
12+
13+
/*CHECK#1/
14+
15+
16+
17+
!!! '*/' expected.

tests/baselines/reference/scannerS7.4_A2_T2.js

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// 'public' shoudl be marked unusable because it has a trailing /*
2-
//a.public /*
1+
// 'public' should be marked unusable, should complain on trailing /*
2+
a.public /*

0 commit comments

Comments
 (0)