Skip to content

Commit 659362b

Browse files
committed
Merge branch 'main' into jabaile/gofumpt-go-tool
2 parents ff4c107 + 7a99cd9 commit 659362b

File tree

24,024 files changed

+975324
-28923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

24,024 files changed

+975324
-28923
lines changed

.github/workflows/ci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
steps:
2424
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25-
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
25+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
2626
- uses: ./.github/actions/setup-go
2727
with:
2828
cache-name: build
@@ -63,7 +63,7 @@ jobs:
6363
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6464
with:
6565
submodules: ${{ !matrix.no-submodules }}
66-
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
66+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
6767
with:
6868
node-version: 'lts/*'
6969
- uses: ./.github/actions/setup-go
@@ -118,7 +118,7 @@ jobs:
118118

119119
steps:
120120
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
121-
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
121+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
122122
- uses: ./.github/actions/setup-go
123123
with:
124124
cache-name: lint${{ (matrix.noembed && '-noembed') || ''}}
@@ -134,7 +134,7 @@ jobs:
134134
runs-on: ubuntu-latest
135135
steps:
136136
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
137-
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
137+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
138138
- uses: ./.github/actions/setup-go
139139
with:
140140
cache-name: format
@@ -150,7 +150,7 @@ jobs:
150150
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
151151
with:
152152
submodules: true
153-
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
153+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
154154
- uses: ./.github/actions/setup-go
155155
with:
156156
cache-name: generate
@@ -179,7 +179,7 @@ jobs:
179179
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
180180
with:
181181
submodules: true
182-
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
182+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
183183
- uses: ./.github/actions/setup-go
184184
with:
185185
cache-name: smoke

.github/workflows/merge-queue.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2020
with:
2121
submodules: true
22-
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
22+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
2323
with:
2424
node-version: 'lts/*'
2525
- uses: ./.github/actions/setup-go

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,5 @@ custom-gcl.hash
192192
.DS_Store
193193

194194
.idea
195+
196+
!testdata/submoduleAccepted.txt

.golangci.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ linters:
3030
- intrange
3131
- makezero
3232
- mirror
33+
- misspell
3334
- musttag
3435
- nolintlint
3536
- paralleltest
3637
- perfsprint
3738
- predeclared
3839
- reassign
39-
- tenv
4040
- testableexamples
4141
- tparallel
4242
- unconvert
4343
- usestdlibvars
44+
- usetesting
4445
- whitespace
4546

4647
- customlint
@@ -64,10 +65,6 @@ linters-settings:
6465
customlint:
6566
type: module
6667

67-
wrapcheck:
68-
ignorePackageGlobs:
69-
- encoding/*
70-
- github.com/go-json-experiment/*
7168
# revive:
7269
# enable-all-rules: true
7370
# rules:

Herebyfile.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const { values: options } = parseArgs({
2525
args: process.argv.slice(2),
2626
options: {
2727
race: { type: "boolean" },
28+
tests: { type: "string", short: "t" },
2829
fix: { type: "boolean" },
2930
noembed: { type: "boolean" },
3031
debug: { type: "boolean" },
@@ -44,7 +45,7 @@ const defaultGoBuildTags = [
4445

4546
/**
4647
* @param {...string} extra
47-
* @returns
48+
* @returns {string[]}
4849
*/
4950
function goBuildTags(...extra) {
5051
const tags = new Set(defaultGoBuildTags.concat(extra));
@@ -202,6 +203,7 @@ export const generate = task({
202203
const goTestFlags = [
203204
...goBuildFlags,
204205
...goBuildTags(),
206+
...(options.tests ? [`-run=${options.tests}`] : []),
205207
];
206208

207209
const goTestEnv = {

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ This repo uses [Go 1.24 or higher](https://go.dev/dl/), [Node.js with npm](https
1212
For tests and code generation, this repo contains a git submodule to the main TypeScript repo pointing to the commit being ported.
1313
When cloning, you'll want to clone with submodules:
1414

15-
```console
16-
$ git clone --recurse-submodules https://github.com/microsoft/typescript-go.git
15+
```sh
16+
git clone --recurse-submodules https://github.com/microsoft/typescript-go.git
1717
```
1818

1919
If you have already cloned the repo, you can initialize the submodule with:
2020

21-
```console
22-
$ git submodule update --init --recursive
21+
```sh
22+
git submodule update --init --recursive
2323
```
2424

2525
With the submodule in place and `npm ci`, you can run tasks via `hereby`, similar to the TypeScript repo:
2626

27-
```console
28-
$ hereby build # Verify that the project builds
29-
$ hereby test # Run all tests
30-
$ hereby install-tools # Install additional tools such as linters
31-
$ hereby lint # Run all linters
32-
$ hereby format # Format all code
33-
$ hereby generate # Generate all Go code (e.g. diagnostics, committed to repo)
27+
```sh
28+
hereby build # Verify that the project builds
29+
hereby test # Run all tests
30+
hereby install-tools # Install additional tools such as linters
31+
hereby lint # Run all linters
32+
hereby format # Format all code
33+
hereby generate # Generate all Go code (e.g. diagnostics, committed to repo)
3434
```
3535

3636
Additional tasks are a work in progress.

_extension/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
],
3131
"default": "verbose",
3232
"description": "Trace TypeScript Go server communication."
33+
},
34+
"typescript-go.pprofDir": {
35+
"type": "string",
36+
"description": "Directory to write pprof profiles to."
3337
}
3438
}
3539
}

_extension/src/extension.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,21 @@ export function activate(context: vscode.ExtensionContext) {
2626

2727
output.appendLine(`Resolved to ${exe}`);
2828

29+
const config = vscode.workspace.getConfiguration("typescript-go");
30+
31+
// Get pprofDir
32+
const pprofDir = config.get<string>("pprofDir");
33+
const pprofArgs = pprofDir ? ["-pprofDir", pprofDir] : [];
34+
2935
const serverOptions: ServerOptions = {
3036
run: {
3137
command: exe,
32-
args: ["lsp"],
38+
args: ["lsp", ...pprofArgs],
3339
transport: TransportKind.stdio,
3440
},
3541
debug: {
3642
command: exe,
37-
args: ["lsp"],
43+
args: ["lsp", ...pprofArgs],
3844
transport: TransportKind.stdio,
3945
},
4046
};

_tools/customlint/emptycase.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var emptyCaseAnalyzer = &analysis.Analyzer{
1919
},
2020
}
2121

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

2525
nodeFilter := []ast.Node{

cmd/tsgo/lsp.go

+8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import (
1010
"github.com/microsoft/typescript-go/internal/bundled"
1111
"github.com/microsoft/typescript-go/internal/core"
1212
"github.com/microsoft/typescript-go/internal/lsp"
13+
"github.com/microsoft/typescript-go/internal/pprof"
1314
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
1415
)
1516

1617
func runLSP(args []string) int {
1718
flag := flag.NewFlagSet("lsp", flag.ContinueOnError)
1819
stdio := flag.Bool("stdio", false, "use stdio for communication")
20+
pprofDir := flag.String("pprofDir", "", "Generate pprof CPU/memory profiles to the given directory.")
1921
pipe := flag.String("pipe", "", "use named pipe for communication")
2022
_ = pipe
2123
socket := flag.String("socket", "", "use socket for communication")
@@ -29,6 +31,12 @@ func runLSP(args []string) int {
2931
return 1
3032
}
3133

34+
if *pprofDir != "" {
35+
fmt.Fprintf(os.Stderr, "pprof profiles will be written to: %v\n", *pprofDir)
36+
profileSession := pprof.BeginProfiling(*pprofDir, os.Stderr)
37+
defer profileSession.Stop()
38+
}
39+
3240
fs := bundled.WrapFS(osvfs.FS())
3341
defaultLibraryPath := bundled.LibPath()
3442

cmd/tsgo/main.go

+6-65
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"flag"
77
"fmt"
88
"os"
9-
"path/filepath"
109
"runtime"
11-
"runtime/pprof"
1210
"slices"
1311
"strconv"
1412
"strings"
@@ -21,6 +19,7 @@ import (
2119
"github.com/microsoft/typescript-go/internal/core"
2220
"github.com/microsoft/typescript-go/internal/diagnosticwriter"
2321
"github.com/microsoft/typescript-go/internal/execute"
22+
"github.com/microsoft/typescript-go/internal/pprof"
2423
"github.com/microsoft/typescript-go/internal/scanner"
2524
"github.com/microsoft/typescript-go/internal/tspath"
2625
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
@@ -135,8 +134,8 @@ func main() {
135134
opts := parseArgs()
136135

137136
if opts.devel.pprofDir != "" {
138-
profileSession := beginProfiling(opts.devel.pprofDir)
139-
defer profileSession.stop()
137+
profileSession := pprof.BeginProfiling(opts.devel.pprofDir, os.Stdout)
138+
defer profileSession.Stop()
140139
}
141140

142141
startTime := time.Now()
@@ -221,7 +220,7 @@ func main() {
221220
var emitTime time.Duration
222221
if compilerOptions.NoEmit.IsFalseOrUnknown() {
223222
emitStart := time.Now()
224-
result := program.Emit(&ts.EmitOptions{})
223+
result := program.Emit(ts.EmitOptions{})
225224
diagnostics = append(diagnostics, result.Diagnostics...)
226225
emitTime = time.Since(emitStart)
227226
}
@@ -238,15 +237,8 @@ func main() {
238237
printDiagnostics(ts.SortAndDeduplicateDiagnostics(diagnostics), host, compilerOptions)
239238
}
240239

241-
var unsupportedExtensions []string
242-
for _, file := range program.SourceFiles() {
243-
extension := tspath.TryGetExtensionFromPath(file.FileName())
244-
if extension == tspath.ExtensionTsx || slices.Contains(tspath.SupportedJSExtensionsFlat, extension) {
245-
unsupportedExtensions = core.AppendIfUnique(unsupportedExtensions, extension)
246-
}
247-
}
248-
if len(unsupportedExtensions) != 0 {
249-
fmt.Fprintf(os.Stderr, "Warning: The project contains unsupported file types (%s), which are currently not fully type-checked.\n", strings.Join(unsupportedExtensions, ", "))
240+
if exts := program.UnsupportedExtensions(); len(exts) != 0 {
241+
fmt.Fprintf(os.Stderr, "Warning: The project contains unsupported file types (%s), which are currently not fully type-checked.\n", strings.Join(exts, ", "))
250242
}
251243

252244
if compilerOptions.ListFiles.IsTrue() {
@@ -335,54 +327,3 @@ func printDiagnostics(diagnostics []*ast.Diagnostic, host ts.CompilerHost, compi
335327
}
336328
}
337329
}
338-
339-
type profileSession struct {
340-
cpuFilePath string
341-
memFilePath string
342-
cpuFile *os.File
343-
memFile *os.File
344-
}
345-
346-
func beginProfiling(profileDir string) *profileSession {
347-
if err := os.MkdirAll(profileDir, 0o755); err != nil {
348-
panic(err)
349-
}
350-
351-
pid := os.Getpid()
352-
353-
cpuProfilePath := filepath.Join(profileDir, fmt.Sprintf("%d-cpuprofile.pb.gz", pid))
354-
memProfilePath := filepath.Join(profileDir, fmt.Sprintf("%d-memprofile.pb.gz", pid))
355-
cpuFile, err := os.Create(cpuProfilePath)
356-
if err != nil {
357-
panic(err)
358-
}
359-
memFile, err := os.Create(memProfilePath)
360-
if err != nil {
361-
panic(err)
362-
}
363-
364-
if err := pprof.StartCPUProfile(cpuFile); err != nil {
365-
panic(err)
366-
}
367-
368-
return &profileSession{
369-
cpuFilePath: cpuProfilePath,
370-
memFilePath: memProfilePath,
371-
cpuFile: cpuFile,
372-
memFile: memFile,
373-
}
374-
}
375-
376-
func (p *profileSession) stop() {
377-
pprof.StopCPUProfile()
378-
err := pprof.Lookup("allocs").WriteTo(p.memFile, 0)
379-
if err != nil {
380-
panic(err)
381-
}
382-
383-
p.cpuFile.Close()
384-
p.memFile.Close()
385-
386-
fmt.Printf("CPU profile: %v\n", p.cpuFilePath)
387-
fmt.Printf("Memory profile: %v\n", p.memFilePath)
388-
}

internal/ast/ast.go

+3
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ func (n *Node) ModifierFlags() ModifierFlags {
442442
if modifiers != nil {
443443
return modifiers.ModifierFlags
444444
}
445+
if n.Flags&NodeFlagsNestedNamespace != 0 {
446+
return ModifierFlagsExport
447+
}
445448
return ModifierFlagsNone
446449
}
447450

internal/ast/utilities.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ func GetExternalModuleName(node *Node) *Expression {
16751675
case KindImportType:
16761676
return getImportTypeNodeLiteral(node)
16771677
case KindCallExpression:
1678-
return node.AsCallExpression().Arguments.Nodes[0]
1678+
return core.FirstOrNil(node.AsCallExpression().Arguments.Nodes)
16791679
case KindModuleDeclaration:
16801680
if IsStringLiteral(node.AsModuleDeclaration().Name()) {
16811681
return node.AsModuleDeclaration().Name()

internal/ast/visitor.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,21 @@ func (v *NodeVisitor) visitTopLevelStatements(nodes *StatementList) *StatementLi
258258
}
259259

260260
func (v *NodeVisitor) liftToBlock(node *Statement) *Statement {
261-
if node != nil && node.Kind == KindSyntaxList {
262-
nodes := node.AsSyntaxList().Children
263-
if len(nodes) == 0 {
264-
node = nil
265-
} else if len(nodes) == 1 {
266-
node = nodes[0]
261+
var nodes []*Node
262+
if node != nil {
263+
if node.Kind == KindSyntaxList {
264+
nodes = node.AsSyntaxList().Children
267265
} else {
268-
node = v.Factory.NewBlock(v.Factory.NewNodeList(nodes), true /*multiLine*/)
269-
}
270-
if node != nil && node.Kind == KindSyntaxList {
271-
panic("The result of visiting and lifting a Node may not be SyntaxList")
266+
nodes = []*Node{node}
272267
}
273268
}
269+
if len(nodes) == 1 {
270+
node = nodes[0]
271+
} else {
272+
node = v.Factory.NewBlock(v.Factory.NewNodeList(nodes), true /*multiLine*/)
273+
}
274+
if node.Kind == KindSyntaxList {
275+
panic("The result of visiting and lifting a Node may not be SyntaxList")
276+
}
274277
return node
275278
}

0 commit comments

Comments
 (0)