diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8ffb02a89743e..23018f3ef1171 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2336,6 +2336,10 @@ "category": "Error", "code": 5065 }, + "Substitutions for pattern '{0}' shouldn't be an empty array.": { + "category": "Error", + "code": 5066 + }, "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 @@ -2800,11 +2804,11 @@ "category": "Error", "code": 6133 }, - "Report errors on unused locals.": { + "Report errors on unused locals.": { "category": "Message", "code": 6134 }, - "Report errors on unused parameters.": { + "Report errors on unused parameters.": { "category": "Message", "code": 6135 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8d59c2d46fe2e..4b9948c3ba0b4 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2200,6 +2200,9 @@ namespace ts { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, key)); } if (isArray(options.paths[key])) { + if (options.paths[key].length === 0) { + programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitutions_for_pattern_0_shouldn_t_be_an_empty_array, key)); + } for (const subst of options.paths[key]) { const typeOfSubst = typeof subst; if (typeOfSubst === "string") { diff --git a/tests/baselines/reference/pathsValidation3.errors.txt b/tests/baselines/reference/pathsValidation3.errors.txt new file mode 100644 index 0000000000000..3bb85203e6e38 --- /dev/null +++ b/tests/baselines/reference/pathsValidation3.errors.txt @@ -0,0 +1,6 @@ +error TS5066: Substitutions for pattern 'foo' shouldn't be an empty array. + + +!!! error TS5066: Substitutions for pattern 'foo' shouldn't be an empty array. +==== tests/cases/compiler/a.ts (0 errors) ==== + let x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/pathsValidation3.js b/tests/baselines/reference/pathsValidation3.js new file mode 100644 index 0000000000000..bfffc647f632c --- /dev/null +++ b/tests/baselines/reference/pathsValidation3.js @@ -0,0 +1,5 @@ +//// [a.ts] +let x = 1; + +//// [a.js] +var x = 1; diff --git a/tests/cases/compiler/pathsValidation3.ts b/tests/cases/compiler/pathsValidation3.ts new file mode 100644 index 0000000000000..28db959a881db --- /dev/null +++ b/tests/cases/compiler/pathsValidation3.ts @@ -0,0 +1,12 @@ +// @filename: tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "foo": [] + } + } +} + +// @filename: a.ts +let x = 1; \ No newline at end of file