From df57160b6c2330e4dc8cc29d18d8b315d3908655 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 14 Jul 2014 17:39:20 -0700 Subject: [PATCH] Report error on unclosed multiline comment. Fixes #22 --- src/compiler/scanner.ts | 10 +++++++++- .../parserKeywordsAsIdentifierName2.errors.txt | 7 +++++++ .../parserKeywordsAsIdentifierName2.js | 5 ----- .../reference/scannerS7.4_A2_T2.errors.txt | 17 +++++++++++++++++ tests/baselines/reference/scannerS7.4_A2_T2.js | 17 ----------------- .../parserKeywordsAsIdentifierName2.ts | 4 ++-- 6 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 tests/baselines/reference/parserKeywordsAsIdentifierName2.errors.txt delete mode 100644 tests/baselines/reference/parserKeywordsAsIdentifierName2.js create mode 100644 tests/baselines/reference/scannerS7.4_A2_T2.errors.txt delete mode 100644 tests/baselines/reference/scannerS7.4_A2_T2.js diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 4b4d3f3d723b5..b109ba8bfbdec 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -662,11 +662,14 @@ module ts { if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) { pos += 2; - while (pos < len) { + var safeLength = len - 1; // For lookahead. + var commentClosed = false; + while (pos < safeLength) { var ch = text.charCodeAt(pos); if (ch === CharacterCodes.asterisk && text.charCodeAt(pos + 1) === CharacterCodes.slash) { pos += 2; + commentClosed = true; break; } @@ -676,6 +679,11 @@ module ts { pos++; } + if (!commentClosed) { + pos++; + onError(Diagnostics.Asterisk_Slash_expected); + } + if (onComment) { onComment(tokenPos, pos); } diff --git a/tests/baselines/reference/parserKeywordsAsIdentifierName2.errors.txt b/tests/baselines/reference/parserKeywordsAsIdentifierName2.errors.txt new file mode 100644 index 0000000000000..41b5ab32f8945 --- /dev/null +++ b/tests/baselines/reference/parserKeywordsAsIdentifierName2.errors.txt @@ -0,0 +1,7 @@ +==== tests/cases/conformance/parser/ecmascript5/parserKeywordsAsIdentifierName2.ts (2 errors) ==== + // 'public' should be marked unusable, should complain on trailing /* + a.public /* + +!!! '*/' expected. + ~ +!!! Cannot find name 'a'. \ No newline at end of file diff --git a/tests/baselines/reference/parserKeywordsAsIdentifierName2.js b/tests/baselines/reference/parserKeywordsAsIdentifierName2.js deleted file mode 100644 index 8038ddd5f37aa..0000000000000 --- a/tests/baselines/reference/parserKeywordsAsIdentifierName2.js +++ /dev/null @@ -1,5 +0,0 @@ -//// [parserKeywordsAsIdentifierName2.ts] -// 'public' shoudl be marked unusable because it has a trailing /* -//a.public /* - -//// [parserKeywordsAsIdentifierName2.js] diff --git a/tests/baselines/reference/scannerS7.4_A2_T2.errors.txt b/tests/baselines/reference/scannerS7.4_A2_T2.errors.txt new file mode 100644 index 0000000000000..4d3d2500e08d0 --- /dev/null +++ b/tests/baselines/reference/scannerS7.4_A2_T2.errors.txt @@ -0,0 +1,17 @@ +==== tests/cases/conformance/scanner/ecmascript5/scannerS7.4_A2_T2.ts (1 errors) ==== + // Copyright 2009 the Sputnik authors. All rights reserved. + // This code is governed by the BSD license found in the LICENSE file. + + /** + * Correct interpretation of multi line comments + * + * @path ch07/7.4/S7.4_A2_T2.js + * @description Try use /*CHECK#1/. This is not closed multi line comment + * @negative + */ + + /*CHECK#1/ + + + +!!! '*/' expected. \ No newline at end of file diff --git a/tests/baselines/reference/scannerS7.4_A2_T2.js b/tests/baselines/reference/scannerS7.4_A2_T2.js deleted file mode 100644 index ae5acbaece4a1..0000000000000 --- a/tests/baselines/reference/scannerS7.4_A2_T2.js +++ /dev/null @@ -1,17 +0,0 @@ -//// [scannerS7.4_A2_T2.ts] -// Copyright 2009 the Sputnik authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/** - * Correct interpretation of multi line comments - * - * @path ch07/7.4/S7.4_A2_T2.js - * @description Try use /*CHECK#1/. This is not closed multi line comment - * @negative - */ - -/*CHECK#1/ - - - -//// [scannerS7.4_A2_T2.js] diff --git a/tests/cases/conformance/parser/ecmascript5/parserKeywordsAsIdentifierName2.ts b/tests/cases/conformance/parser/ecmascript5/parserKeywordsAsIdentifierName2.ts index cac3a668cbf6b..d197f85905c38 100644 --- a/tests/cases/conformance/parser/ecmascript5/parserKeywordsAsIdentifierName2.ts +++ b/tests/cases/conformance/parser/ecmascript5/parserKeywordsAsIdentifierName2.ts @@ -1,2 +1,2 @@ -// 'public' shoudl be marked unusable because it has a trailing /* -//a.public /* \ No newline at end of file +// 'public' should be marked unusable, should complain on trailing /* +a.public /* \ No newline at end of file