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

Use correct ResolutionMode for files when resolving/loading files #267

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

EricCornelson
Copy link
Contributor

Pass the correct ResolutionMode to the resolver when resolving imports/type directives, and for resolvedModules on the file.

@@ -7491,6 +7543,71 @@ func (node *SourceFile) LineMap() []core.TextPos {
return lineMap
}

func (file *SourceFile) CollectDynamicImportOrRequireOrJsDocImportCalls() {
Copy link
Member

Choose a reason for hiding this comment

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

This method modifies the source file; I suspect we'll need some additional protection later if we start sharing these ASTs between programs so that two programs can't possibly race to be the first to update this info (note lineMap above). But I assume it doesn't matter at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

Though, I do wonder if we can come up with some method by which we don't do this here, but instead as a part of parsing or binding themselves...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks to me like this could be done at parse time, but we are specifically just setting the NodeFlagsPossiblyContainsDynamicImport flag in parseImportType(), so I guess I'd presume there's some important reason to defer it. Maybe to do with incremental parsing (which might not be valid anymore)?

Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is already being handled in Parser.

Comment on lines 469 to 470
```ts
// tsc foo.mts --module nodenext
Copy link
Member

Choose a reason for hiding this comment

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

I don't know how much of this comment is relevant now, but this format isn't going to show correctly in gopls. I think 4-space indentation works for code snippets. JSDoc-style @param tags also don't do anything.

}

func getDefaultResolutionModeForFile(item *sourceFileMetadata, options *core.CompilerOptions) core.ResolutionMode {
if importSyntaxAffectsModuleResolution(options) {
Copy link
Member

Choose a reason for hiding this comment

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

Do these functions belong in fileloader.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'm not sure. I thought about making all of these methods on core.CompilerOptions but I'm not sure if that's the right place either

Copy link
Member

Choose a reason for hiding this comment

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

If they accept sourceFileMetadata, that doesn't sounds like it'd be a method on the compiler options; I feel like this is definitely a feature of the Program and not CompilerOptions.

@RyanCavanaugh RyanCavanaugh requested a review from Copilot February 6, 2025 00:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • internal/ast/ast.go: Evaluated as low risk
Comments suppressed due to low confidence (4)

internal/compiler/fileloader.go:360

  • The function resolveTripleslashPathReference was changed to remove the receiver *fileLoader, but the function name is still used with the receiver in the code. This might cause confusion or errors if the function is called with the receiver elsewhere in the code.
func resolveTripleslashPathReference(moduleName string, containingFile string) string {

internal/compiler/fileloader.go:390

  • The getModeForUsageLocation function might not always return the correct mode if the usage node is not correctly identified. Ensure that the usage node is correctly identified before calling this function.
mode := getModeForUsageLocation(item, resolution.node, optionsForFile)

internal/ast/utilities.go:1150

  • The new behavior introduced by IsRequireCall should be covered by tests. Please add relevant test cases to ensure the function works as expected.
func IsRequireCall(node *Node, requireStringLiteralLikeArgument bool) bool {

internal/ast/utilities.go:1211

  • The new behavior introduced by IsExclusivelyTypeOnlyImportOrExport should be covered by tests. Please add relevant test cases to ensure the function works as expected.
func IsExclusivelyTypeOnlyImportOrExport(decl *Node) bool {

@@ -1196,6 +1208,20 @@ func IsImportOrExportSpecifier(node *Node) bool {
return IsImportSpecifier(node) || IsExportSpecifier(node)
}

func IsExclusivelyTypeOnlyImportOrExport(decl *Node) bool {
Copy link
Preview

Copilot AI Feb 6, 2025

Choose a reason for hiding this comment

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

The function IsExclusivelyTypeOnlyImportOrExport is missing a case for KindImportEqualsDeclaration. Please add this case to ensure all relevant node kinds are covered.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -176,19 +183,21 @@ type parseTask struct {
func (t *parseTask) start(loader *fileLoader) {
loader.wg.Run(func() {
file := loader.parseSourceFile(t.normalizedFilePath)
metadata := loader.buildFileMetadata(file)
Copy link
Member

Choose a reason for hiding this comment

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

The emitter needs to know the implied node format to emit the correct output for .ts files. In Strada, this was available via SourceFile.impliedNodeFormat and was passed as an option to createSourceFile. Is there any way to access this information from the emitter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants