added validation of paths option

This commit is contained in:
Vladimir Matveev 2016-04-13 21:16:39 -07:00
parent 41c1a5b497
commit e7a4dd4cf5
8 changed files with 66 additions and 4 deletions

View File

@ -2292,7 +2292,14 @@
"category": "Error",
"code": 5062
},
"Substututions for patterns '{0}' should be an array.": {
"category": "Error",
"code": 5063
},
"Substitution '{0}' for pattern '{1}' has incorrect type, expected 'string', got '{2}'.": {
"category": "Error",
"code": 5064
},
"Concatenate and emit output to single file.": {
"category": "Message",
"code": 6001

View File

@ -1985,11 +1985,22 @@ namespace ts {
if (!hasZeroOrOneAsteriskCharacter(key)) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Pattern_0_can_have_at_most_one_Asterisk_character, key));
}
for (const subst of options.paths[key]) {
if (!hasZeroOrOneAsteriskCharacter(subst)) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key));
if (isArray(options.paths[key])) {
for (const subst of options.paths[key]) {
const typeOfSubst = typeof subst;
if (typeOfSubst === "string") {
if (!hasZeroOrOneAsteriskCharacter(subst)) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key));
}
}
else {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substitution_0_for_pattern_1_has_incorrect_type_expected_string_got_2, subst, key, typeOfSubst));
}
}
}
else {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Substututions_for_patterns_0_should_be_an_array, key));
}
}
}

View File

@ -0,0 +1,6 @@
error TS5063: Substututions for patterns '*' should be an array.
!!! error TS5063: Substututions for patterns '*' should be an array.
==== tests/cases/compiler/a.ts (0 errors) ====
let x = 1;

View File

@ -0,0 +1,5 @@
//// [a.ts]
let x = 1;
//// [a.js]
var x = 1;

View File

@ -0,0 +1,6 @@
error TS5064: Substitution '1' for pattern '*' has incorrect type, expected 'string', got 'number'.
!!! error TS5064: Substitution '1' for pattern '*' has incorrect type, expected 'string', got 'number'.
==== tests/cases/compiler/a.ts (0 errors) ====
let x = 1;

View File

@ -0,0 +1,5 @@
//// [a.ts]
let x = 1;
//// [a.js]
var x = 1;

View File

@ -0,0 +1,11 @@
// @filename: tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": "*"
}
}
}
// @filename: a.ts
let x = 1;

View File

@ -0,0 +1,11 @@
// @filename: tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": [1]
}
}
}
// @filename: a.ts
let x = 1;