Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit dbdcb1c

Browse files
TypeScript Teamalexeagle
authored andcommitted
Properly handle negative error codes in typescript diagnostic identifiers for tsc_wrapped diagnostics extensions
Since diagnostic identifier code's are of type `number`, both positive and negative numbers should be valid. PiperOrigin-RevId: 282587002
1 parent c91cf13 commit dbdcb1c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

internal/tsc_wrapped/diagnostics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function filterExpected(
2222
// 2. Required TS error: 'TS2000: message text.'
2323
// Need triple escapes because the expected diagnostics that we're matching
2424
// here are regexes, too.
25-
const ERROR_RE = /^(?:\\\((\d*),(\d*)\\\).*)?TS(\d+):(.*)/;
25+
const ERROR_RE = /^(?:\\\((\d*),(\d*)\\\).*)?TS(-?\d+):(.*)/;
2626
const incorrectErrors =
2727
bazelOpts.expectedDiagnostics.filter(e => !e.match(ERROR_RE));
2828
if (incorrectErrors.length) {
@@ -52,7 +52,7 @@ export function filterExpected(
5252

5353
const expectedDiags: ExpectedDiagnostics[] =
5454
bazelOpts.expectedDiagnostics.map(expected => {
55-
const m = expected.match(/^(?:\\\((\d*),(\d*)\\\).*)?TS(\d+):(.*)$/);
55+
const m = expected.match(/^(?:\\\((\d*),(\d*)\\\).*)?TS(-?\d+):(.*)$/);
5656
if (!m) {
5757
throw new Error(
5858
'Incorrect expected error, did you forget character escapes in ' +

internal/tsc_wrapped/diagnostics_test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,10 @@ describe('diagnostics', () => {
5858
'Incorrect expected error, did you forget character escapes in ' +
5959
'TS1234:unescaped \n newline');
6060
});
61+
62+
it('handle negative diagnostic codes', () => {
63+
expect(filter(['TS-999:custom error'], [diag(-999, 'custom error')]))
64+
.toEqual([]);
65+
});
6166
});
6267
});

0 commit comments

Comments
 (0)