Repository: microsoft/typescript-go (go)

Issue:
Panic in checkGrammarClassLikeDeclaration on vscode
Testing on vscode at `60e1bdd0b6d6085283ac78879c38dc5b09cb5ab2`:

```
 ./built/local/tsgo -p ~/work/vscode/src --diagnostics
```

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x8035ca]

goroutine 5113 [running]:
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkGrammarClassDeclarationHeritageClauses(0xc0533ab008, 0xc00d343170, 0xc00e4d0f08)
        /home/jabaile/work/TypeScript-go/internal/checker/grammarchecks.go:934 +0x3ca
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkGrammarClassLikeDeclaration(0xc0533ab008, 0x40abc2?)
        /home/jabaile/work/TypeScript-go/internal/checker/grammarchecks.go:782 +0x5f
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkClassLikeDeclaration(0xc0533ab008, 0xc00d343170)
        /home/jabaile/work/TypeScript-go/internal/checker/checker.go:4069 +0x32
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkClassDeclaration(0xc0533ab008, 0xc00d343170)
        /home/jabaile/work/TypeScript-go/internal/checker/checker.go:4063 +0xfc
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElementWorker(0xc0533ab008, 0xc00d343170)
        /home/jabaile/work/TypeScript-go/internal/checker/checker.go:2253 +0x347
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElement(0xc0533ab008, 0xc0539b70b0?)
        /home/jabaile/work/TypeScript-go/internal/checker/checker.go:2147 +0x4a
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceElements(0xc0533ab008, {0xc00eef7b08, 0x34, 0xc0002cfa80?})
        /home/jabaile/work/TypeScript-go/internal/checker/checker.go:2138 +0x2d
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkSourceFile(0xc0533ab008, {0xd04178, 0x12633e0}, 0xc00e4d0f08)
        /home/jabaile/work/TypeScript-go/internal/checker/checker.go:2110 +0x119
github.com/microsoft/typescript-go/internal/checker.(*Checker).CheckSourceFile(0xc0533ab008, {0xd04178, 0x12633e0}, 0xc00e4d0f08)
        /home/jabaile/work/TypeScript-go/internal/checker/checker.go:2099 +0x5c
github.com/microsoft/typescript-go/internal/compiler.(*Program).CheckSourceFiles.func1-range1(0x74203e3d20292801?)
        /home/jabaile/work/TypeScript-go/internal/compiler/program.go:336 +0x3e
github.com/microsoft/typescript-go/internal/compiler.(*checkerPool).Files.func1(0xc0539b7080)
        /home/jabaile/work/TypeScript-go/internal/compiler/checkerpool.go:82 +0x88
github.com/microsoft/typescript-go/internal/compiler.(*Program).CheckSourceFiles.func1()
        /home/jabaile/work/TypeScript-go/internal/compiler/program.go:335 +0xe2
github.com/microsoft/typescript-go/internal/core.(*parallelWorkGroup).Queue.func1()
        /home/jabaile/work/TypeScript-go/internal/core/workgroup.go:39 +0x50
created by github.com/microsoft/typescript-go/internal/core.(*parallelWorkGroup).Queue in goroutine 1
        /home/jabaile/work/TypeScript-go/internal/core/workgroup.go:37 +0x85
```

Pull request description:
Fix nil panic on heritage clause in grammar checks
Iterating JSDoc.Tags.Nodes panics if there are no tags. You can iterate nil but not a slice on something that is nil. Expect to see more panics like this on any new code, because we're not tracking nil in the type system anymore.

Fixes #1171 

Patch:
diff --git a/internal/checker/grammarchecks.go b/internal/checker/grammarchecks.go
index d7deeef5e..acd23758e 100644
--- a/internal/checker/grammarchecks.go
+++ b/internal/checker/grammarchecks.go
@@ -931,6 +931,9 @@ func (c *Checker) checkGrammarClassDeclarationHeritageClauses(node *ast.ClassLik
 				}
 
 				for _, j := range node.JSDoc(file) {
+					if j.AsJSDoc().Tags == nil {
+						continue
+					}
 					for _, tag := range j.AsJSDoc().Tags.Nodes {
 						if tag.Kind == ast.KindJSDocAugmentsTag {
 							target := typeNodes[0].AsExpressionWithTypeArguments()


Test patch:
diff --git a/testdata/baselines/reference/conformance/jsdocClassNoTags.js b/testdata/baselines/reference/conformance/jsdocClassNoTags.js
new file mode 100644
index 000000000..89877fae4
--- /dev/null
+++ b/testdata/baselines/reference/conformance/jsdocClassNoTags.js
@@ -0,0 +1,17 @@
+//// [tests/cases/conformance/jsdoc/jsdocClassNoTags.ts] ////
+
+//// [jsdocClassNoTags.ts]
+class B {
+}
+/** this is a test */
+class C extends B {
+}
+
+
+
+//// [jsdocClassNoTags.js]
+class B {
+}
+/** this is a test */
+class C extends B {
+}
diff --git a/testdata/baselines/reference/conformance/jsdocClassNoTags.symbols b/testdata/baselines/reference/conformance/jsdocClassNoTags.symbols
new file mode 100644
index 000000000..13fb4617e
--- /dev/null
+++ b/testdata/baselines/reference/conformance/jsdocClassNoTags.symbols
@@ -0,0 +1,13 @@
+//// [tests/cases/conformance/jsdoc/jsdocClassNoTags.ts] ////
+
+=== jsdocClassNoTags.ts ===
+class B {
+>B : Symbol(B, Decl(jsdocClassNoTags.ts, 0, 0))
+}
+/** this is a test */
+class C extends B {
+>C : Symbol(C, Decl(jsdocClassNoTags.ts, 1, 1))
+>B : Symbol(B, Decl(jsdocClassNoTags.ts, 0, 0))
+}
+
+
diff --git a/testdata/baselines/reference/conformance/jsdocClassNoTags.types b/testdata/baselines/reference/conformance/jsdocClassNoTags.types
new file mode 100644
index 000000000..6765cd482
--- /dev/null
+++ b/testdata/baselines/reference/conformance/jsdocClassNoTags.types
@@ -0,0 +1,13 @@
+//// [tests/cases/conformance/jsdoc/jsdocClassNoTags.ts] ////
+
+=== jsdocClassNoTags.ts ===
+class B {
+>B : B
+}
+/** this is a test */
+class C extends B {
+>C : C
+>B : B
+}
+
+
diff --git a/testdata/tests/cases/conformance/jsdoc/jsdocClassNoTags.ts b/testdata/tests/cases/conformance/jsdoc/jsdocClassNoTags.ts
new file mode 100644
index 000000000..0274a308e
--- /dev/null
+++ b/testdata/tests/cases/conformance/jsdoc/jsdocClassNoTags.ts
@@ -0,0 +1,6 @@
+class B {
+}
+/** this is a test */
+class C extends B {
+}
+