Skip to content

Commit 6a6f5db

Browse files
authored
Merge pull request #9909 from YuichiNukiyama/fix9772
throw error when paths option mapping empty array
2 parents a0406c7 + bf2783f commit 6a6f5db

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,6 +2336,10 @@
23362336
"category": "Error",
23372337
"code": 5065
23382338
},
2339+
"Substitutions for pattern '{0}' shouldn't be an empty array.": {
2340+
"category": "Error",
2341+
"code": 5066
2342+
},
23392343
"Concatenate and emit output to single file.": {
23402344
"category": "Message",
23412345
"code": 6001
@@ -2800,11 +2804,11 @@
28002804
"category": "Error",
28012805
"code": 6133
28022806
},
2803-
"Report errors on unused locals.": {
2807+
"Report errors on unused locals.": {
28042808
"category": "Message",
28052809
"code": 6134
28062810
},
2807-
"Report errors on unused parameters.": {
2811+
"Report errors on unused parameters.": {
28082812
"category": "Message",
28092813
"code": 6135
28102814
},

src/compiler/program.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,9 @@ namespace ts {
22002200
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, key));
22012201
}
22022202
if (isArray(options.paths[key])) {
2203+
if (options.paths[key].length === 0) {
2204+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitutions_for_pattern_0_shouldn_t_be_an_empty_array, key));
2205+
}
22032206
for (const subst of options.paths[key]) {
22042207
const typeOfSubst = typeof subst;
22052208
if (typeOfSubst === "string") {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error TS5066: Substitutions for pattern 'foo' shouldn't be an empty array.
2+
3+
4+
!!! error TS5066: Substitutions for pattern 'foo' shouldn't be an empty array.
5+
==== tests/cases/compiler/a.ts (0 errors) ====
6+
let x = 1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//// [a.ts]
2+
let x = 1;
3+
4+
//// [a.js]
5+
var x = 1;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @filename: tsconfig.json
2+
{
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"foo": []
7+
}
8+
}
9+
}
10+
11+
// @filename: a.ts
12+
let x = 1;

0 commit comments

Comments
 (0)