diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8ffae3b8680..6105ae32ba5 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1295,12 +1295,10 @@ namespace ts { flags: watchRecursivePattern.test(spec) ? WatchDirectoryFlags.Recursive : WatchDirectoryFlags.None }; } - else if (isImplicitGlob(spec)) { + if (isImplicitGlob(spec)) { return { key: spec, flags: WatchDirectoryFlags.Recursive }; } - else { - return undefined; - } + return undefined; } /** diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 0164d0f4333..1eb0614a8a3 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1515,7 +1515,9 @@ namespace ts { return undefined; } - return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$"); + // If excluding, match "foo/bar/baz...", but if including, only allow "foo". + const terminator = usage === "exclude" ? "($|/)" : "$"; + return `^(${pattern})${terminator}`; } /** @@ -1711,9 +1713,7 @@ namespace ts { ? absolute : removeTrailingDirectorySeparator(getDirectoryPath(absolute)); } - else { - return absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset)); - } + return absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset)); } export function ensureScriptKind(fileName: string, scriptKind?: ScriptKind): ScriptKind {