Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow an import of "foo.js" to be matched by a file "foo.ts" #8895

Merged
8 commits merged into from
Jun 9, 2016

Conversation

ghost
Copy link

@ghost ghost commented May 31, 2016

Fixes #4595

@msftclas
Copy link

Hi @andy-ms, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (Andy Hanson). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

if (ext === ".tsx" && state.skipTsx) {
return undefined;
if (state.skipTsx)
extensions = filter(extensions, ext => ext !== "tsx");
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this still have a dot in it?

Copy link
Author

Choose a reason for hiding this comment

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

Yes it should! I'll add tests so this error is detected.

Copy link
Author

Choose a reason for hiding this comment

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

Also, noticed that I forgot the curly braces on this. Maybe we should add a lint rule?

Copy link
Contributor

Choose a reason for hiding this comment

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

i would rather we checked this tryLoad to avoid the array allocation for every module lookup.

@ghost ghost force-pushed the strip_extension branch from 3cd506a to a0546a9 Compare May 31, 2016 17:41
}
return tryLoad(fileExtensionIs(candidate, ext) ? candidate : candidate + ext);
});
if (keepOrAddExtension) {
Copy link
Member

Choose a reason for hiding this comment

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

Newline above

return fileExtensionIs(path, extension) ? path.substring(0, path.length - extension.length) : undefined;
}

export function getFileExtension(path: string): string {
Copy link
Member

@DanielRosenwasser DanielRosenwasser May 31, 2016

Choose a reason for hiding this comment

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

Consider making the return type annotation string | undefined

}

export function getFileExtension(path: string): string {
const dot = path.lastIndexOf(".");
Copy link
Member

Choose a reason for hiding this comment

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

What if the dot is somewhere else in the path, e.g. /foo/some.dir/filename ?

Copy link
Author

Choose a reason for hiding this comment

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

Turns out we don't need this function, so removing it.

@billti
Copy link
Member

billti commented Jun 1, 2016

That's a bigger change than I would have expected. What doesn't work if you just remove a .js ending if present at the start of loadModuleFromFile? It'll still add all the supported extensions in order (e.g. .ts, .d.ts, .js if allowJs is set, etc...) and try to locate that file.

@ghost
Copy link
Author

ghost commented Jun 1, 2016

If a file is named "foo.js.ts", currently imports of "foo.js" will work. If we eagerly strip the ".js" extension from the import it will stop working. This might be an acceptable breaking change, though.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 8, 2016

👍

@ghost ghost merged commit 512c671 into master Jun 9, 2016
@ghost ghost deleted the strip_extension branch June 9, 2016 18:38
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