Conversation
a6c0e40 to
531b03a
Compare
| resolvedUsingTsExtension bool | ||
| } | ||
|
|
||
| func formatExtensions(extensions Extensions) string { |
There was a problem hiding this comment.
Eventually this would be nice to pull into a stringer like tool (https://cs.opensource.google/go/x/tools/+/refs/tags/v0.26.0:cmd/stringer/stringer.go), but that doesn't do bit ops.
| } | ||
|
|
||
| func formatExtensions(extensions Extensions) string { | ||
| result := []string{} |
There was a problem hiding this comment.
If this turns out to be hot, you may want to consider doing something like:
result := make([]string, 0, bits.OnesCount(extensions))To get the right number of entries, but I suspect this would be more efficient as a strings.Builder rather than a strings.Join anyway.
(This is premature optimization; profiling will tell us what to tweak)
There was a problem hiding this comment.
I’m not sure the hassle of adding the commas is worth using a strings.Builder—this is only for traceResolution which shouldn’t be used in production builds. Good idea about setting the capacity though.
| break | ||
| default: | ||
| panic(fmt.Sprintf("Unexpected moduleResolution: %s", moduleResolution)) | ||
| panic(fmt.Sprintf("Unexpected moduleResolution: %d", moduleResolution)) |
There was a problem hiding this comment.
Probably at some point we should just run stringer on this to generate enum stuff; I will put up a PR with an example of this since we already have enums which would benefit.
jakebailey
left a comment
There was a problem hiding this comment.
Just from a Go code perspective, this all seems good to me; we'll have to see how the Host interface stuff plays out as that will get more complicated as we introduce more of them and want to cross-assign them. Thankfully it's not that bad to "cast" (type convert) between them as they will actually be statically checked so we can "add" more methods onto a narrower type if the underlying implementation has it.
|
|
||
| func (c *Checker) resolveExternalModuleName(location *Node, moduleReferenceExpression *Node, ignoreErrors bool) *Symbol { | ||
| isClassic := getEmitModuleResolutionKind(c.compilerOptions) == ModuleResolutionKindClassic | ||
| errorMessage := ifElse(isClassic, |
There was a problem hiding this comment.
At some level I wonder if we're really saving much code by omitting classic, but I guess we want it to go away anyway.
| }) | ||
| } | ||
|
|
||
| func formatMessage(message *diagnostics.Message, args ...any) string { |
There was a problem hiding this comment.
At some level, I wonder if this should just be a method on Message. Surely the logic for formatting args is not compiler specific.
There was a problem hiding this comment.
I’m not going to do that right now because this uses multiple other utilities from the compiler package, and I don’t know the best way to move them to or access them in the diagnostics package.
* add import attribute type to resolved file cache key * fmt
This adds many of the types and utilities used by module resolution, but doesn’t yet implement the core resolution algorithms. I wanted to get a PR up as soon as possible to prevent clashes with others who might need the same types and utilities as they’re getting started.
(Note: fixed my local clone to push to my fork after opening this PR)