Skip to content

Commit 81ebab4

Browse files
committed
Merge pull request #8080 from Microsoft/pathsValidation
added validation of paths option
2 parents 41c1a5b + 54862a2 commit 81ebab4

File tree

8 files changed

+66
-4
lines changed

8 files changed

+66
-4
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,14 @@
22922292
"category": "Error",
22932293
"code": 5062
22942294
},
2295-
2295+
"Substututions for pattern '{0}' should be an array.": {
2296+
"category": "Error",
2297+
"code": 5063
2298+
},
2299+
"Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'.": {
2300+
"category": "Error",
2301+
"code": 5064
2302+
},
22962303
"Concatenate and emit output to single file.": {
22972304
"category": "Message",
22982305
"code": 6001

src/compiler/program.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,11 +1985,22 @@ namespace ts {
19851985
if (!hasZeroOrOneAsteriskCharacter(key)) {
19861986
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, key));
19871987
}
1988-
for (const subst of options.paths[key]) {
1989-
if (!hasZeroOrOneAsteriskCharacter(subst)) {
1990-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key));
1988+
if (isArray(options.paths[key])) {
1989+
for (const subst of options.paths[key]) {
1990+
const typeOfSubst = typeof subst;
1991+
if (typeOfSubst === "string") {
1992+
if (!hasZeroOrOneAsteriskCharacter(subst)) {
1993+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key));
1994+
}
1995+
}
1996+
else {
1997+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2, subst, key, typeOfSubst));
1998+
}
19911999
}
19922000
}
2001+
else {
2002+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substututions_for_pattern_0_should_be_an_array, key));
2003+
}
19932004
}
19942005
}
19952006

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error TS5063: Substututions for pattern '*' should be an array.
2+
3+
4+
!!! error TS5063: Substututions for pattern '*' should be an 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error TS5064: Substitution '1' for pattern '*' has incorrect type, expected 'string', got 'number'.
2+
3+
4+
!!! error TS5064: Substitution '1' for pattern '*' has incorrect type, expected 'string', got 'number'.
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @filename: tsconfig.json
2+
{
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"*": "*"
7+
}
8+
}
9+
}
10+
// @filename: a.ts
11+
let x = 1;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @filename: tsconfig.json
2+
{
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"*": [1]
7+
}
8+
}
9+
}
10+
// @filename: a.ts
11+
let x = 1;

0 commit comments

Comments
 (0)