Skip to content

Implicitly consider an extensionless file in "includes" to be a recursive directory glob#11495

Merged
5 commits merged into
masterfrom
includes_glob
Oct 31, 2016
Merged

Implicitly consider an extensionless file in "includes" to be a recursive directory glob#11495
5 commits merged into
masterfrom
includes_glob

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Oct 10, 2016

Fixes #10578

There is a lot of refactoring in this PR but the actual changes just have to do with uses of the isImpicitGlob function. If this always returns false then behavior will be the same as before. If wanted I could break this into 2 PRs, one which refactors and one which adds isImplicitGlob.

It would also be a good idea to someday rewrite this functionality into a) parsing globs, then b) doing things with parsed globs. Then we would pass around strings less often.

@ghost ghost force-pushed the includes_glob branch from 08791b7 to 2f77a54 Compare October 10, 2016 18:14
@ghost
Copy link
Copy Markdown
Author

ghost commented Oct 10, 2016

I tested this on the command-line with a real project and it worked. I'd still like to get @rbuckton's review before merging. Are there some additional tests that should be added?

Comment thread src/compiler/commandLineParser.ts Outdated

function getWildcardDirectoryFromSpec(spec: string, useCaseSensitiveFileNames: boolean): { key: string, flags: WatchDirectoryFlags } | undefined {
const match = wildcardDirectoryPattern.exec(spec);
return match
Copy link
Copy Markdown
Member

@DanielRosenwasser DanielRosenwasser Oct 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you turn this into a series of ifs? this is pretty unreadable to me.

Comment thread src/compiler/core.ts Outdated
}
}
/**
* An "includes" path "foo" is implicitly a glob "foo\**\*" (replace \ with /) if its last component has no extension,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by "replace \ with /"?

Comment thread src/compiler/core.ts Outdated

function getBasename(path: Path): Path;
function getBasename(path: string): string;
function getBasename(path: string): any {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to use any - our overload compatibility rules are bidirectional for return types.

@ghost ghost force-pushed the includes_glob branch from b7496d1 to 9b2e6a3 Compare October 12, 2016 17:13
Comment thread src/compiler/commandLineParser.ts Outdated
else if (isImplicitGlob(spec)) {
return { key: spec, flags: WatchDirectoryFlags.Recursive };
}
else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: when each branch of an if finishes in a return, we don't structure these as if-elses, since the logic is automatically exclusive.

Comment thread src/compiler/core.ts Outdated
if (hasWrittenComponent) {
subpattern += directorySeparator;
}
return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate the last part into a variable and comment what the purpose is.

Comment thread src/compiler/core.ts Outdated
}
else {
return absolute.substring(0, absolute.lastIndexOf(directorySeparator, wildcardOffset));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit as above about if-elses

Comment thread src/compiler/core.ts Outdated
function getIncludeBasePath(absolute: string): string {
const wildcardOffset = indexOfAnyCharCode(absolute, wildcardCharCodes);
if (wildcardOffset < 0) {
// No "*" in the path
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't isImplicitGlob redoing the work of the call to indexOfAnyCharCode above? We have already eliminated * and ? as possible characters, so the only character you really need to test for is ..

Also the comment should probably read // No "*" or "?" in the path

@ghost ghost merged commit e6f6a5e into master Oct 31, 2016
@ghost ghost deleted the includes_glob branch October 31, 2016 20:56
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants