Skip to content

Set implied node format during source file creation #637

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

Merged
merged 35 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
66f4788
Set implied node format during source file creation
frodi-karlsson Mar 16, 2025
48873eb
Merge branch 'main' into implied-node-format-setting
frodi-karlsson Mar 16, 2025
fb0f304
Move into file loader
frodi-karlsson Mar 16, 2025
3e7b92c
Merge branch 'implied-node-format-setting' of github.com:frodi-karlss…
frodi-karlsson Mar 16, 2025
8bba782
Revert back to main to start from scratch with storing on Program per…
frodi-karlsson Mar 16, 2025
d1f5959
Try a v3 with parser-set fields, keep hacking at it
frodi-karlsson Mar 17, 2025
e5645d2
Merge branch 'main' into implied-node-format-setting
frodi-karlsson Mar 17, 2025
e825898
Resolve bad history linearly
frodi-karlsson Mar 17, 2025
1f3b470
Fix languageservice <-> project dependency muck up
frodi-karlsson Mar 17, 2025
1a66c19
Pass around package json type instead of cache entry
frodi-karlsson Mar 17, 2025
0112b00
Remove left-over !!!
frodi-karlsson Mar 17, 2025
8366e88
Remove GetImpliedNodeFormat
frodi-karlsson Mar 17, 2025
d33133b
Remove harnessUtil package json garbage
frodi-karlsson Mar 17, 2025
b81a9d1
Remove unnecessary newline
frodi-karlsson Mar 17, 2025
406918a
Move off of AST into a map in program
frodi-karlsson Mar 17, 2025
44d6aff
Move creation of metadata into fileloader
frodi-karlsson Mar 17, 2025
54fc786
Change arg to fileName and remove packageType argument in caching method
frodi-karlsson Mar 17, 2025
0644fd3
Appease linter and remove unnecessary convert
frodi-karlsson Mar 17, 2025
8d1f096
Use extension constants
frodi-karlsson Mar 18, 2025
344710a
Merge branch 'main' into implied-node-format-setting (-X theirs for
frodi-karlsson Mar 18, 2025
f6fcb49
Pass single sourceFileMetaData from program into emitContext
frodi-karlsson Mar 18, 2025
a1d63f5
Merge branch 'main' into implied-node-format-setting
frodi-karlsson Mar 18, 2025
3c902b8
Accept insane new diff wins
frodi-karlsson Mar 18, 2025
08333cf
Switch back to map
frodi-karlsson Mar 18, 2025
ba527ba
Use path as map key
frodi-karlsson Mar 18, 2025
4f740f1
Revert walking originals
frodi-karlsson Mar 18, 2025
d1e2b2e
Create MetaDataProvider
frodi-karlsson Mar 18, 2025
7da5ddc
Move commonjs metadata provider adding to struct declaration
frodi-karlsson Mar 18, 2025
e2c7a77
Use program as SourceFileMetaDataProvider and share fakeProgram in te…
frodi-karlsson Mar 18, 2025
3099425
Revert moving to util and create smaller fakeSourceFileMetaDataProvider
frodi-karlsson Mar 18, 2025
1697b75
Realign naming to provider
frodi-karlsson Mar 18, 2025
d86780d
Remove unnecessary struct
frodi-karlsson Mar 18, 2025
ac71490
Fix henceforth "load"SourceFileMetaData, spacings and leftover
frodi-karlsson Mar 18, 2025
286beed
Switch to RWMutex and include map creation in w lock
frodi-karlsson Mar 19, 2025
ed015b3
Fix deadlock
frodi-karlsson Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ linters-settings:
customlint:
type: module

wrapcheck:
ignorePackageGlobs:
- encoding/*
- github.com/go-json-experiment/*
# revive:
# enable-all-rules: true
# rules:
Expand Down
2 changes: 1 addition & 1 deletion Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const defaultGoBuildTags = [

/**
* @param {...string} extra
* @returns {string[]}
* @returns
*/
function goBuildTags(...extra) {
const tags = new Set(defaultGoBuildTags.concat(extra));
Expand Down
2 changes: 1 addition & 1 deletion _tools/customlint/emptycase.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var emptyCaseAnalyzer = &analysis.Analyzer{
},
}

func runEmptyCase(pass *analysis.Pass) (any, error) {
func runEmptyCase(pass *analysis.Pass) (interface{}, error) {
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)

nodeFilter := []ast.Node{
Expand Down
4 changes: 3 additions & 1 deletion internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"
"sync/atomic"

"github.com/microsoft/typescript-go/internal/compiler/packagejson"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/tspath"
)
Expand Down Expand Up @@ -8695,6 +8696,8 @@ type SourceFile struct {
ReferencedFiles []*FileReference
TypeReferenceDirectives []*FileReference
LibReferenceDirectives []*FileReference
PackageJsonScope *packagejson.InfoCacheEntry
ImpliedNodeFormat core.ModuleKind

// Fields set by binder

Expand Down Expand Up @@ -8723,7 +8726,6 @@ type SourceFile struct {

// !!!

ImpliedNodeFormat core.ModuleKind
CommonJsModuleIndicator *Node
ExternalModuleIndicator *Node
JsGlobalAugmentations SymbolTable
Expand Down
8 changes: 4 additions & 4 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2368,13 +2368,13 @@ func GetImpliedNodeFormatForEmitWorker(sourceFile *SourceFile, options *core.Com
return sourceFile.ImpliedNodeFormat
}
if sourceFile.ImpliedNodeFormat == core.ModuleKindCommonJS &&
( /*sourceFile.packageJsonScope.contents.packageJsonContent.type == "commonjs" ||*/ // !!!
tspath.FileExtensionIsOneOf(sourceFile.FileName(), []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
(sourceFile.PackageJsonScope != nil && sourceFile.PackageJsonScope.Contents.Type.Value != "module" || // !!!
tspath.FileExtensionIsOneOf(sourceFile.FileName(), []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
return core.ModuleKindCommonJS
}
if sourceFile.ImpliedNodeFormat == core.ModuleKindESNext &&
( /*sourceFile.packageJsonScope?.contents.packageJsonContent.type === "module" ||*/ // !!!
tspath.FileExtensionIsOneOf(sourceFile.fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
(sourceFile.PackageJsonScope != nil && sourceFile.PackageJsonScope.Contents.Type.Value == "module" ||
tspath.FileExtensionIsOneOf(sourceFile.fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
return core.ModuleKindESNext
}
return core.ModuleKindNone
Expand Down
4 changes: 2 additions & 2 deletions internal/astnav/tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestGetTokenAtPosition(t *testing.T) {
return 0;
}
`
file := parser.ParseSourceFile("/file.ts", "/file.ts", fileText, core.ScriptTargetLatest, scanner.JSDocParsingModeParseAll)
file := parser.ParseSourceFile("/file.ts", "/file.ts", fileText, core.ScriptTargetLatest, scanner.JSDocParsingModeParseAll, core.ResolutionModeESM, nil)
assert.Equal(t, astnav.GetTokenAtPosition(file, 0), astnav.GetTokenAtPosition(file, 0))
})
}
Expand Down Expand Up @@ -86,7 +86,7 @@ func baselineTokens(t *testing.T, testName string, getTSTokens func(fileText str
positions[i] = i
}
tsTokens := getTSTokens(string(fileText), positions)
file := parser.ParseSourceFile("/file.ts", "/file.ts", string(fileText), core.ScriptTargetLatest, scanner.JSDocParsingModeParseAll)
file := parser.ParseSourceFile("/file.ts", "/file.ts", string(fileText), core.ScriptTargetLatest, scanner.JSDocParsingModeParseAll, core.ResolutionModeESM, nil)

var output strings.Builder
currentRange := core.NewTextRange(0, 0)
Expand Down
1 change: 0 additions & 1 deletion internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func bindSourceFile(file *ast.SourceFile, options *core.CompilerOptions) {
b.file = file
b.options = options
b.languageVersion = options.GetEmitScriptTarget()
b.inStrictMode = options.AlwaysStrict.IsTrue()
b.unreachableFlow = b.newFlowNode(ast.FlowFlagsUnreachable)
b.reportedUnreachableFlow = b.newFlowNode(ast.FlowFlagsUnreachable)
b.bind(file.AsNode())
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func BenchmarkBind(b *testing.B) {

sourceFiles := make([]*ast.SourceFile, b.N)
for i := range b.N {
sourceFiles[i] = parser.ParseSourceFile(fileName, path, sourceText, core.ScriptTargetESNext, scanner.JSDocParsingModeParseAll)
sourceFiles[i] = parser.ParseSourceFile(fileName, path, sourceText, core.ScriptTargetESNext, scanner.JSDocParsingModeParseAll, core.ResolutionModeESM, nil)
}

compilerOptions := &core.CompilerOptions{Target: core.ScriptTargetESNext, ModuleKind: core.ModuleKindNodeNext}
Expand Down
Loading