From 7224f22975c1615ee2e29cdd03b14559b42a94c6 Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Sat, 23 Jul 2016 15:05:36 +0900 Subject: [PATCH 1/2] throw error when paths option mapping empty array fix --- src/compiler/diagnosticMessages.json | 8 ++++++-- src/compiler/program.ts | 3 +++ tests/baselines/reference/pathsValidation3.errors.txt | 6 ++++++ tests/baselines/reference/pathsValidation3.js | 5 +++++ tests/cases/compiler/pathsValidation3.ts | 11 +++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/pathsValidation3.errors.txt create mode 100644 tests/baselines/reference/pathsValidation3.js create mode 100644 tests/cases/compiler/pathsValidation3.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8ffb02a8974..23018f3ef11 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 8d59c2d46fe..4b9948c3ba0 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 00000000000..3bb85203e6e --- /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 00000000000..bfffc647f63 --- /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 00000000000..8d677ed15b4 --- /dev/null +++ b/tests/cases/compiler/pathsValidation3.ts @@ -0,0 +1,11 @@ +// @filename: tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "foo": [] + } + } +} +// @filename: a.ts +let x = 1; \ No newline at end of file From bf2783f0c55e840a31642e087c9e6cb3d2ab41f1 Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Sat, 23 Jul 2016 15:50:21 +0900 Subject: [PATCH 2/2] to run CI --- tests/cases/compiler/pathsValidation3.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cases/compiler/pathsValidation3.ts b/tests/cases/compiler/pathsValidation3.ts index 8d677ed15b4..28db959a881 100644 --- a/tests/cases/compiler/pathsValidation3.ts +++ b/tests/cases/compiler/pathsValidation3.ts @@ -7,5 +7,6 @@ } } } + // @filename: a.ts let x = 1; \ No newline at end of file