GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — importModuleSpecifierEnding changes .ts string completions to .js by jessetrinity · Pull Request #44602 · microsoft/TypeScript Conversation
Contributor
Fixes #44374
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Jesse Trinity (jessetrinity)
requested a review
from Andrew Branch (andrewbranch)
Andrew Branch (andrewbranch)
requested changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What we really need, and I’m not sure whether we have (but we might), is a function that maps input file extensions to emitted file extensions. So we would have
If we don’t have that function, we need to (a) figure out what the right thing for TSX is and implement it now, and (b) remember to update it for
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Emitter.ts has
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
| function getJSExtensionForFile(fileName: string, options: CompilerOptions): Extension { |
I would maybe just export that function so it doesn’t immediately cause merge conflicts with #44501.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actually, you might need to refactor it to return undefined instead of throwing on unsupported extensions, and move the debug assertions to its caller, or another wrapped version of it. But otherwise I think this function is exactly the thing we were looking for.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Andrew Branch <[email protected]>
8bc4f1f to
25555c3
Compare
| } | ||
|
|
||
| function getJSExtensionForFile(fileName: string, options: CompilerOptions): Extension { | ||
| function getJSExtensionForFileIfApplicable(fileName: string, options: CompilerOptions): Extension { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
To me this one sounds like the one that never throws. I would suggest naming the undefined-returning one tryGetJSExtensionForFile and the throwing one getJSExtensionForFile.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| export function getJSExtensionForFile(fileName: string, options: CompilerOptions): Extension | undefined { | ||
| const ext = extensionFromPath(fileName); |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I thought it was sketchy that this function didn’t have undefined in its return type, so I looked and found that it too has an undefined-returning counterpart, and this one throws! This may need to be swapped for tryGetExtensionFromPath for good measure. This also makes me realize we should have a test that actually returns completions for a non-source-file file extension, like index.css or something.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think we even read other extension types from disk, but I think you mean something like
//@filename: index.css body {} //@filename: index.html <!DOCTYPE html> //@filename: foo.ts import "./
And expect nothing at the uncompleted string?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hm, I looked at stringCompletions and saw tryReadDirectory, so I assumed we were offering everything we could find, with extension substitutions as appropriate. Not sure what’s going on then 🤔
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You could certainly be seeing an artifact of the fourslash client 😬. Have you checked the behavior against a Real Editor?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was pretty sure that tryReadDirectory only returned files that matched its extensions argument, if provided. I might be misreading though.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
either way, updated to not use the throwing variant :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed that parameter 🤦♂️
It might actually be nice to allow all extensions here in the future, since we can no longer seriously claim to believe we’re in a world where people only import things we know how to analyze. This doesn’t even account for declare module "*.css" pattern ambient module declarations. But that’s for another day. Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oh geez TIL. Is that a wildcard module declaration?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
importModuleSpecifierEnding = js doesn't apply for autocomplete within import paths
There was an error while loading. Please reload this page.