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
diff --git a/internal/tsc_wrapped/diagnostics.ts b/internal/tsc_wrapped/diagnostics.ts
index 89c2680..32fbfe0 100644
--- a/internal/tsc_wrapped/diagnostics.ts
+++ b/internal/tsc_wrapped/diagnostics.ts
@@ -22,7 +22,7 @@
// 2. Required TS error: 'TS2000: message text.'
// Need triple escapes because the expected diagnostics that we're matching
// here are regexes, too.
- const ERROR_RE = /^(?:\\\((\d*),(\d*)\\\).*)?TS(\d+):(.*)/;
+ const ERROR_RE = /^(?:\\\((\d*),(\d*)\\\).*)?TS(-?\d+):(.*)/;
const incorrectErrors =
bazelOpts.expectedDiagnostics.filter(e => !e.match(ERROR_RE));
if (incorrectErrors.length) {
@@ -52,7 +52,7 @@
const expectedDiags: ExpectedDiagnostics[] =
bazelOpts.expectedDiagnostics.map(expected => {
- const m = expected.match(/^(?:\\\((\d*),(\d*)\\\).*)?TS(\d+):(.*)$/);
+ const m = expected.match(/^(?:\\\((\d*),(\d*)\\\).*)?TS(-?\d+):(.*)$/);
if (!m) {
throw new Error(
'Incorrect expected error, did you forget character escapes in ' +
diff --git a/internal/tsc_wrapped/diagnostics_test.ts b/internal/tsc_wrapped/diagnostics_test.ts
index fceece4..8acf212 100644
--- a/internal/tsc_wrapped/diagnostics_test.ts
+++ b/internal/tsc_wrapped/diagnostics_test.ts
@@ -58,5 +58,10 @@
'Incorrect expected error, did you forget character escapes in ' +
'TS1234:unescaped \n newline');
});
+
+ it('handle negative diagnostic codes', () => {
+ expect(filter(['TS-999:custom error'], [diag(-999, 'custom error')]))
+ .toEqual([]);
+ });
});
});