Skip to content

Commit

Permalink
Cherry-pick PR microsoft#35209 into release-3.7 (microsoft#35213)
Browse files Browse the repository at this point in the history
Component commits:
74a6343 Fix the usage of pattern matching for check of hasZeroOrOneAsteriskCharacter Fixes microsoft#35171

ffe82c6 Fix error message
  • Loading branch information
TypeScript Bot authored and sheetalkamat committed Nov 20, 2019
1 parent b37cc6e commit c18d72f
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3233,7 +3233,7 @@
"category": "Error",
"code": 5061
},
"Substitution '{0}' in pattern '{1}' in can have at most one '*' character.": {
"Substitution '{0}' in pattern '{1}' can have at most one '*' character.": {
"category": "Error",
"code": 5062
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,7 @@ namespace ts {
const typeOfSubst = typeof subst;
if (typeOfSubst === "string") {
if (!hasZeroOrOneAsteriskCharacter(subst)) {
createDiagnosticForOptionPathKeyValue(key, i, Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key);
createDiagnosticForOptionPathKeyValue(key, i, Diagnostics.Substitution_0_in_pattern_1_can_have_at_most_one_Asterisk_character, subst, key);
}
}
else {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8256,6 +8256,7 @@ namespace ts {
export function matchPatternOrExact(patternStrings: readonly string[], candidate: string): string | Pattern | undefined {
const patterns: Pattern[] = [];
for (const patternString of patternStrings) {
if (!hasZeroOrOneAsteriskCharacter(patternString)) continue;
const pattern = tryParsePattern(patternString);
if (pattern) {
patterns.push(pattern);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/compiler/root/tsconfig.json(8,13): error TS5061: Pattern '*1*' can have at most one '*' character.
tests/cases/compiler/root/tsconfig.json(8,22): error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character.
tests/cases/compiler/root/tsconfig.json(8,22): error TS5062: Substitution '*2*' in pattern '*1*' can have at most one '*' character.


==== tests/cases/compiler/root/tsconfig.json (2 errors) ====
Expand All @@ -14,7 +14,7 @@ tests/cases/compiler/root/tsconfig.json(8,22): error TS5062: Substitution '*2*'
~~~~~
!!! error TS5061: Pattern '*1*' can have at most one '*' character.
~~~~~
!!! error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character.
!!! error TS5062: Substitution '*2*' in pattern '*1*' can have at most one '*' character.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/compiler/root/tsconfig.json(8,13): error TS5061: Pattern '*1*' can have at most one '*' character.
tests/cases/compiler/root/tsconfig.json(8,22): error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character.
tests/cases/compiler/root/tsconfig.json(8,22): error TS5062: Substitution '*2*' in pattern '*1*' can have at most one '*' character.


==== tests/cases/compiler/root/tsconfig.json (2 errors) ====
Expand All @@ -14,7 +14,7 @@ tests/cases/compiler/root/tsconfig.json(8,22): error TS5062: Substitution '*2*'
~~~~~
!!! error TS5061: Pattern '*1*' can have at most one '*' character.
~~~~~
!!! error TS5062: Substitution '*2*' in pattern '*1*' in can have at most one '*' character.
!!! error TS5062: Substitution '*2*' in pattern '*1*' can have at most one '*' character.
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/baselines/reference/pathsValidation4.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
tests/cases/compiler/tsconfig.json(6,11): error TS5061: Pattern '@interface/**/*' can have at most one '*' character.
tests/cases/compiler/tsconfig.json(7,11): error TS5061: Pattern '@service/**/*' can have at most one '*' character.
tests/cases/compiler/tsconfig.json(7,29): error TS5062: Substitution './src/service/**/*' in pattern '@service/**/*' can have at most one '*' character.


==== tests/cases/compiler/tsconfig.json (3 errors) ====
{
"compilerOptions": {
"traceResolution": true,
"baseUrl": "./src",
"paths": {
"@interface/**/*" : ["./src/interface/*"],
~~~~~~~~~~~~~~~~~
!!! error TS5061: Pattern '@interface/**/*' can have at most one '*' character.
"@service/**/*": ["./src/service/**/*"],
~~~~~~~~~~~~~~~
!!! error TS5061: Pattern '@service/**/*' can have at most one '*' character.
~~~~~~~~~~~~~~~~~~~~
!!! error TS5062: Substitution './src/service/**/*' in pattern '@service/**/*' can have at most one '*' character.
"@controller/*": ["controller/*"],
}
}
}

==== tests/cases/compiler/src/main.ts (0 errors) ====
import 'someModule';
7 changes: 7 additions & 0 deletions tests/baselines/reference/pathsValidation4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [main.ts]
import 'someModule';

//// [main.js]
"use strict";
exports.__esModule = true;
require("someModule");
36 changes: 36 additions & 0 deletions tests/baselines/reference/pathsValidation4.trace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
"======== Resolving module 'someModule' from 'tests/cases/compiler/src/main.ts'. ========",
"Module resolution kind is not specified, using 'NodeJs'.",
"'baseUrl' option is set to 'tests/cases/compiler/src', using this value to resolve non-relative module name 'someModule'.",
"'paths' option is specified, looking for a pattern to match module name 'someModule'.",
"'baseUrl' option is set to 'tests/cases/compiler/src', using this value to resolve non-relative module name 'someModule'.",
"Resolving module name 'someModule' relative to base url 'tests/cases/compiler/src' - 'tests/cases/compiler/src/someModule'.",
"Loading module as file / folder, candidate module location 'tests/cases/compiler/src/someModule', target file type 'TypeScript'.",
"File 'tests/cases/compiler/src/someModule.ts' does not exist.",
"File 'tests/cases/compiler/src/someModule.tsx' does not exist.",
"File 'tests/cases/compiler/src/someModule.d.ts' does not exist.",
"Directory 'tests/cases/compiler/src/someModule' does not exist, skipping all lookups in it.",
"Loading module 'someModule' from 'node_modules' folder, target file type 'TypeScript'.",
"Directory 'tests/cases/compiler/src/node_modules' does not exist, skipping all lookups in it.",
"Directory 'tests/cases/compiler/node_modules' does not exist, skipping all lookups in it.",
"Directory 'tests/cases/node_modules' does not exist, skipping all lookups in it.",
"Directory 'tests/node_modules' does not exist, skipping all lookups in it.",
"Directory 'node_modules' does not exist, skipping all lookups in it.",
"Directory '/node_modules' does not exist, skipping all lookups in it.",
"'baseUrl' option is set to 'tests/cases/compiler/src', using this value to resolve non-relative module name 'someModule'.",
"'paths' option is specified, looking for a pattern to match module name 'someModule'.",
"'baseUrl' option is set to 'tests/cases/compiler/src', using this value to resolve non-relative module name 'someModule'.",
"Resolving module name 'someModule' relative to base url 'tests/cases/compiler/src' - 'tests/cases/compiler/src/someModule'.",
"Loading module as file / folder, candidate module location 'tests/cases/compiler/src/someModule', target file type 'JavaScript'.",
"File 'tests/cases/compiler/src/someModule.js' does not exist.",
"File 'tests/cases/compiler/src/someModule.jsx' does not exist.",
"Directory 'tests/cases/compiler/src/someModule' does not exist, skipping all lookups in it.",
"Loading module 'someModule' from 'node_modules' folder, target file type 'JavaScript'.",
"Directory 'tests/cases/compiler/src/node_modules' does not exist, skipping all lookups in it.",
"Directory 'tests/cases/compiler/node_modules' does not exist, skipping all lookups in it.",
"Directory 'tests/cases/node_modules' does not exist, skipping all lookups in it.",
"Directory 'tests/node_modules' does not exist, skipping all lookups in it.",
"Directory 'node_modules' does not exist, skipping all lookups in it.",
"Directory '/node_modules' does not exist, skipping all lookups in it.",
"======== Module name 'someModule' was not resolved. ========"
]
16 changes: 16 additions & 0 deletions tests/cases/compiler/pathsValidation4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @noTypesAndSymbols: true
// @filename: tsconfig.json
{
"compilerOptions": {
"traceResolution": true,
"baseUrl": "./src",
"paths": {
"@interface/**/*" : ["./src/interface/*"],
"@service/**/*": ["./src/service/**/*"],
"@controller/*": ["controller/*"],
}
}
}

// @filename: src/main.ts
import 'someModule';

0 comments on commit c18d72f

Please sign in to comment.