-
Notifications
You must be signed in to change notification settings - Fork 12.9k
importModuleSpecifierEnding changes .ts string completions to .js #44602
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
Changes from 4 commits
bc80712
76509c3
25555c3
ab950c0
5adaabc
15a4735
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -687,13 +687,17 @@ namespace ts.moduleSpecifiers { | |
case Ending.Index: | ||
return noExtension; | ||
case Ending.JsExtension: | ||
return noExtension + getJSExtensionForFile(fileName, options); | ||
return noExtension + getJSExtensionForFileIfApplicable(fileName, options); | ||
default: | ||
return Debug.assertNever(ending); | ||
} | ||
} | ||
|
||
function getJSExtensionForFile(fileName: string, options: CompilerOptions): Extension { | ||
function getJSExtensionForFileIfApplicable(fileName: string, options: CompilerOptions): Extension { | ||
return getJSExtensionForFile(fileName, options) ?? Debug.fail(`Extension ${extensionFromPath(fileName)} is unsupported:: FileName:: ${fileName}`); | ||
} | ||
|
||
export function getJSExtensionForFile(fileName: string, options: CompilerOptions): Extension | undefined { | ||
const ext = extensionFromPath(fileName); | ||
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. I thought it was sketchy that this function didn’t have 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. 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? 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. Hm, I looked at stringCompletions and saw 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. You could certainly be seeing an artifact of the fourslash client 😬. Have you checked the behavior against a Real Editor? 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. I was pretty sure that 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. either way, updated to not use the throwing variant :) 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. 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 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. Oh geez TIL. Is that a wildcard module declaration? |
||
switch (ext) { | ||
case Extension.Ts: | ||
|
@@ -705,10 +709,8 @@ namespace ts.moduleSpecifiers { | |
case Extension.Jsx: | ||
case Extension.Json: | ||
return ext; | ||
case Extension.TsBuildInfo: | ||
return Debug.fail(`Extension ${Extension.TsBuildInfo} is unsupported:: FileName:: ${fileName}`); | ||
default: | ||
return Debug.assertNever(ext); | ||
return undefined; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/// <reference path='fourslash.ts'/> | ||
//@Filename:test.d.ts | ||
//// export declare class Test {} | ||
|
||
//@Filename:module.ts | ||
////import { Test } from ".//**/" | ||
|
||
verify.completions({ marker: "", includes:{name:"test.js"}, preferences: {importModuleSpecifierEnding: "js" }, isNewIdentifierLocation: true}); | ||
verify.completions({ marker: "", includes:{name:"test"}, preferences: {importModuleSpecifierEnding: "index" }, isNewIdentifierLocation: true}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path='fourslash.ts'/> | ||
//@allowJs: true | ||
//@jsx:preserve | ||
//@Filename:test.jsx | ||
//// export class Test { } | ||
|
||
//@Filename:module.jsx | ||
////import { Test } from ".//**/" | ||
|
||
verify.completions({ marker: "", includes:{name:"test.jsx"}, preferences: {importModuleSpecifierEnding: "js"}, isNewIdentifierLocation: true}); | ||
verify.completions({ marker: "", includes:{name:"test"}, preferences: {importModuleSpecifierEnding: "index" }, isNewIdentifierLocation: true}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path='fourslash.ts'/> | ||
//@Filename:test.ts | ||
////export function f(){ | ||
//// return 1 | ||
////} | ||
|
||
//@Filename:module.ts | ||
////import { f } from ".//**/" | ||
|
||
verify.completions({ marker: "", includes:{name:"test.js"}, preferences: {importModuleSpecifierEnding: "js" }, isNewIdentifierLocation: true}); | ||
verify.completions({ marker: "", includes:{name:"test"}, preferences: {importModuleSpecifierEnding: "index" }, isNewIdentifierLocation: true}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference path='fourslash.ts'/> | ||
//@jsx:preserve | ||
//@Filename:test.tsx | ||
//// export class Test { } | ||
|
||
//@Filename:module.tsx | ||
////import { Test } from ".//**/" | ||
|
||
verify.completions({ marker: "", includes:{name:"test.jsx"}, preferences: {importModuleSpecifierEnding: "js"}, isNewIdentifierLocation: true}); | ||
verify.completions({ marker: "", includes:{name:"test"}, preferences: {importModuleSpecifierEnding: "index" }, isNewIdentifierLocation: true}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference path='fourslash.ts'/> | ||
//@jsx:react | ||
//@Filename:test.tsx | ||
//// export class Test { } | ||
|
||
//@Filename:module.tsx | ||
////import { Test } from ".//**/" | ||
|
||
verify.completions({ marker: "", includes:{name:"test.js"}, preferences: {importModuleSpecifierEnding: "js"}, isNewIdentifierLocation: true}); | ||
verify.completions({ marker: "", includes:{name:"test"}, preferences: {importModuleSpecifierEnding: "index" }, isNewIdentifierLocation: true}); |
There was a problem hiding this comment.
Choose a reason for 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 onegetJSExtensionForFile
.