Skip to content

Treat "." and ".." as relative module names#9676

Merged
5 commits merged into
masterfrom
relative_module
Jul 13, 2016
Merged

Treat "." and ".." as relative module names#9676
5 commits merged into
masterfrom
relative_module

Conversation

@ghost

@ghost ghost commented Jul 13, 2016

Copy link
Copy Markdown

Fixes #9651

Comment thread src/compiler/utilities.ts
export function isExternalModuleNameRelative(moduleName: string): boolean {
// TypeScript 1.0 spec (April 2014): 11.2.1
// An external module name is "relative" if the first term is "." or "..".
return moduleName.substr(0, 2) === "./" || moduleName.substr(0, 3) === "../" || moduleName.substr(0, 2) === ".\\" || moduleName.substr(0, 3) === "..\\";

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.

why not use /^\.\.?($|[\\/])/.test(moduleName)? It's a regex, but I think it's still easier to read than 16 lines of imperative code.

@sandersn

Copy link
Copy Markdown
Member

👍

@ghost ghost force-pushed the relative_module branch from b851242 to 8e679b7 Compare July 13, 2016 17:04
@ghost

ghost commented Jul 13, 2016

Copy link
Copy Markdown
Author

One more 8e679b7

Comment thread src/compiler/core.ts Outdated
}

// Should act like String.prototype.startsWith
export function stringStartsWith(s: string, start: string): boolean {

@vladima vladima Jul 13, 2016

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.

we already have startsWith and endsWith in utilities.ts. BTW. this function seems to be unused

@ghost ghost merged commit 1546974 into master Jul 13, 2016
@ghost ghost deleted the relative_module branch July 13, 2016 19:18
@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.

3 participants