diff --git a/CHANGES.md b/CHANGES.md index 22f84c3465..619b821b82 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,15 +6,14 @@ CHANGES.md lists intentional changes between the Strada (Typescript) and Corsa ( ## Parser -1. Source files do not contain an EndOfFile token as their last child. -2. Malformed `...T?` at the end of a tuple now fails with a parse error instead of a grammar error. -3. Malformed string ImportSpecifiers (`import x as "OOPS" from "y"`) now contain the string's text instead of an empty identifier. -4. Empty binding elements no longer have a separate kind for OmittedExpression. Instead they have Kind=BindingElement with a nil Initialiser, Name and DotDotDotToken. -5. ShorthandPropertyAssignment no longer includes an EqualsToken as a child when it has an ObjectAssignmentInitializer. -6. JSDoc nodes now include leading whitespace in their location. -7. The parser always parses a JSDocText node for comments in JSDoc. `string` is no longer part of the type of `comment`. -8. In cases where Strada did produce a JSDocText node, Corsa no longer (incorrectly) includes all leading and trailing whitespace/asterisks, as well as initial `/**`. -9. JSDocMemberName is now parsed as QualifiedName. These two nodes previously only differed by type, and now QualifiedName has a much less restrictive type for its left child. +1. Malformed `...T?` at the end of a tuple now fails with a parse error instead of a grammar error. +2. Malformed string ImportSpecifiers (`import x as "OOPS" from "y"`) now contain the string's text instead of an empty identifier. +3. Empty binding elements no longer have a separate kind for OmittedExpression. Instead they have Kind=BindingElement with a nil Initialiser, Name and DotDotDotToken. +4. ShorthandPropertyAssignment no longer includes an EqualsToken as a child when it has an ObjectAssignmentInitializer. +5. JSDoc nodes now include leading whitespace in their location. +6. The parser always parses a JSDocText node for comments in JSDoc. `string` is no longer part of the type of `comment`. +7. In cases where Strada did produce a JSDocText node, Corsa no longer (incorrectly) includes all leading and trailing whitespace/asterisks, as well as initial `/**`. +8. JSDocMemberName is now parsed as QualifiedName. These two nodes previously only differed by type, and now QualifiedName has a much less restrictive type for its left child. JSDoc types are parsed in normal type annotation position but show a grammar error. Corsa no longer parses the JSDoc types below, giving a parse error instead of a grammar error. diff --git a/_packages/api/src/node.ts b/_packages/api/src/node.ts index d906b3310b..9c757e9d9b 100644 --- a/_packages/api/src/node.ts +++ b/_packages/api/src/node.ts @@ -20,6 +20,7 @@ declare module "@typescript/ast" { const popcount8 = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8]; const childProperties: Readonly>> = { + [SyntaxKind.SourceFile]: ["statements", "endOfFileToken"], [SyntaxKind.QualifiedName]: ["left", "right"], [SyntaxKind.TypeParameter]: ["modifiers", "name", "constraint", "defaultType"], [SyntaxKind.IfStatement]: ["expression", "thenStatement", "elseStatement"], @@ -221,7 +222,7 @@ export class RemoteNodeBase { protected get childMask(): number { if (this.dataType !== NODE_DATA_TYPE_CHILDREN) { - return 0; + return -1; } return this.data & NODE_CHILD_MASK; } @@ -674,6 +675,9 @@ export class RemoteNode extends RemoteNodeBase implements Node { get elseStatement(): RemoteNode | undefined { return this.getNamedChild("elseStatement") as RemoteNode; } + get endOfFileToken(): RemoteNode | undefined { + return this.getNamedChild("endOfFileToken") as RemoteNode; + } get equalsGreaterThanToken(): RemoteNode | undefined { return this.getNamedChild("equalsGreaterThanToken") as RemoteNode; } diff --git a/_packages/api/test/api.test.ts b/_packages/api/test/api.test.ts index 846b44d604..a01b029fac 100644 --- a/_packages/api/test/api.test.ts +++ b/_packages/api/test/api.test.ts @@ -109,7 +109,7 @@ describe("SourceFile", () => { nodeCount++; node.forEachChild(visit); }); - assert.equal(nodeCount, 7); + assert.equal(nodeCount, 8); }); }); diff --git a/_packages/ast/src/nodes.ts b/_packages/ast/src/nodes.ts index a265f5545e..2798419285 100644 --- a/_packages/ast/src/nodes.ts +++ b/_packages/ast/src/nodes.ts @@ -14,6 +14,7 @@ export interface Node extends ReadonlyTextRange { export interface SourceFile extends Node { readonly kind: SyntaxKind.SourceFile; readonly statements: NodeArray; + readonly endOfFileToken: EndOfFile; readonly text: string; readonly fileName: string; } diff --git a/internal/ast/ast.go b/internal/ast/ast.go index ab2f247e68..bbaba269cf 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -10017,10 +10017,11 @@ type SourceFile struct { compositeNodeBase // Fields set by NewSourceFile - fileName string // For debugging convenience - parseOptions SourceFileParseOptions - text string - Statements *NodeList // NodeList[*Statement] + fileName string // For debugging convenience + parseOptions SourceFileParseOptions + text string + Statements *NodeList // NodeList[*Statement] + EndOfFileToken *TokenNode // TokenNode[*EndOfFileToken] // Fields set by parser diagnostics []*Diagnostic @@ -10070,7 +10071,7 @@ type SourceFile struct { declarationMap map[string][]*Node } -func (f *NodeFactory) NewSourceFile(opts SourceFileParseOptions, text string, statements *NodeList) *Node { +func (f *NodeFactory) NewSourceFile(opts SourceFileParseOptions, text string, statements *NodeList, endOfFileToken *TokenNode) *Node { if (tspath.GetEncodedRootLength(opts.FileName) == 0 && !strings.HasPrefix(opts.FileName, "^/")) || opts.FileName != tspath.NormalizePath(opts.FileName) { panic(fmt.Sprintf("fileName should be normalized and absolute: %q", opts.FileName)) } @@ -10079,6 +10080,7 @@ func (f *NodeFactory) NewSourceFile(opts SourceFileParseOptions, text string, st data.parseOptions = opts data.text = text data.Statements = statements + data.EndOfFileToken = endOfFileToken return f.newNode(KindSourceFile, data) } @@ -10139,11 +10141,11 @@ func (node *SourceFile) SetBindDiagnostics(diags []*Diagnostic) { } func (node *SourceFile) ForEachChild(v Visitor) bool { - return visitNodeList(v, node.Statements) + return visitNodeList(v, node.Statements) || visit(v, node.EndOfFileToken) } func (node *SourceFile) VisitEachChild(v *NodeVisitor) *Node { - return v.Factory.UpdateSourceFile(node, v.visitTopLevelStatements(node.Statements)) + return v.Factory.UpdateSourceFile(node, v.visitTopLevelStatements(node.Statements), v.visitToken(node.EndOfFileToken)) } func (node *SourceFile) IsJS() bool { @@ -10171,7 +10173,7 @@ func (node *SourceFile) copyFrom(other *SourceFile) { } func (node *SourceFile) Clone(f NodeFactoryCoercible) *Node { - updated := f.AsNodeFactory().NewSourceFile(node.parseOptions, node.text, node.Statements) + updated := f.AsNodeFactory().NewSourceFile(node.parseOptions, node.text, node.Statements, node.EndOfFileToken) newFile := updated.AsSourceFile() newFile.copyFrom(node) return cloneNode(updated, node.AsNode(), f.AsNodeFactory().hooks) @@ -10181,9 +10183,9 @@ func (node *SourceFile) computeSubtreeFacts() SubtreeFacts { return propagateNodeListSubtreeFacts(node.Statements, propagateSubtreeFacts) } -func (f *NodeFactory) UpdateSourceFile(node *SourceFile, statements *StatementList) *Node { - if statements != node.Statements { - updated := f.NewSourceFile(node.parseOptions, node.text, statements).AsSourceFile() +func (f *NodeFactory) UpdateSourceFile(node *SourceFile, statements *StatementList, endOfFileToken *TokenNode) *Node { + if statements != node.Statements || endOfFileToken != node.EndOfFileToken { + updated := f.NewSourceFile(node.parseOptions, node.text, statements, endOfFileToken).AsSourceFile() updated.copyFrom(node) return updateNode(updated.AsNode(), node.AsNode(), f.hooks) } diff --git a/internal/astnav/tokens.go b/internal/astnav/tokens.go index fe5f2dbf63..3eb50a522b 100644 --- a/internal/astnav/tokens.go +++ b/internal/astnav/tokens.go @@ -49,7 +49,7 @@ func getTokenAtPosition( left := 0 testNode := func(node *ast.Node) int { - if node.End() == position && includePrecedingTokenAtEndPosition != nil { + if node.Kind != ast.KindEndOfFile && node.End() == position && includePrecedingTokenAtEndPosition != nil { prevSubtree = node } @@ -247,7 +247,7 @@ func FindPrecedingToken(sourceFile *ast.SourceFile, position int) *ast.Node { func FindPrecedingTokenEx(sourceFile *ast.SourceFile, position int, startNode *ast.Node, excludeJSDoc bool) *ast.Node { var find func(node *ast.Node) *ast.Node find = func(n *ast.Node) *ast.Node { - if ast.IsNonWhitespaceToken(n) { + if ast.IsNonWhitespaceToken(n) && n.Kind != ast.KindEndOfFile { return n } diff --git a/internal/astnav/tokens_test.go b/internal/astnav/tokens_test.go index 9c237dafee..b2ea39491a 100644 --- a/internal/astnav/tokens_test.go +++ b/internal/astnav/tokens_test.go @@ -20,8 +20,6 @@ import ( ) var testFiles = []string{ - // !!! EOFToken JSDoc parsing is missing - // filepath.Join(repo.TestDataPath, "fixtures/astnav/eofJSDoc.ts"), filepath.Join(repo.TypeScriptSubmodulePath, "src/services/mapCode.ts"), } diff --git a/internal/binder/binder.go b/internal/binder/binder.go index f37f203fe3..05f8bc6382 100644 --- a/internal/binder/binder.go +++ b/internal/binder/binder.go @@ -1637,8 +1637,9 @@ func (b *Binder) bindChildren(node *ast.Node) { // case *JSDocImportTag: // b.bindJSDocImportTag(node) case ast.KindSourceFile: - b.bindEachStatementFunctionsFirst(node.AsSourceFile().Statements) - // b.bind(node.endOfFileToken) + sourceFile := node.AsSourceFile() + b.bindEachStatementFunctionsFirst(sourceFile.Statements) + b.bind(sourceFile.EndOfFileToken) case ast.KindBlock: b.bindEachStatementFunctionsFirst(node.AsBlock().Statements) case ast.KindModuleBlock: diff --git a/internal/fourslash/_scripts/failingTests.txt b/internal/fourslash/_scripts/failingTests.txt index 1871713615..dd25d2d92b 100644 --- a/internal/fourslash/_scripts/failingTests.txt +++ b/internal/fourslash/_scripts/failingTests.txt @@ -1,4 +1,3 @@ -TestAsOperatorCompletion TestAutoImportsWithRootDirsAndRootedPath01 TestClosedCommentsInConstructor TestCodeCompletionEscaping diff --git a/internal/fourslash/tests/gen/asOperatorCompletion_test.go b/internal/fourslash/tests/gen/asOperatorCompletion_test.go index 8a2a856d4d..1fe91cc907 100644 --- a/internal/fourslash/tests/gen/asOperatorCompletion_test.go +++ b/internal/fourslash/tests/gen/asOperatorCompletion_test.go @@ -9,7 +9,7 @@ import ( func TestAsOperatorCompletion(t *testing.T) { t.Parallel() - t.Skip() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") const content = `type T = number; var x; diff --git a/internal/ls/completions.go b/internal/ls/completions.go index 2bf90f3650..1e47beeaf2 100644 --- a/internal/ls/completions.go +++ b/internal/ls/completions.go @@ -2203,81 +2203,79 @@ func shouldIncludeSymbol( ) bool { allFlags := symbol.Flags location := data.location - if !ast.IsSourceFile(location) { - // export = /**/ here we want to get all meanings, so any symbol is ok - if ast.IsExportAssignment(location.Parent) { - return true - } + // export = /**/ here we want to get all meanings, so any symbol is ok + if location.Parent != nil && ast.IsExportAssignment(location.Parent) { + return true + } - // Filter out variables from their own initializers - // `const a = /* no 'a' here */` - if closestSymbolDeclaration != nil && - ast.IsVariableDeclaration(closestSymbolDeclaration) && - symbol.ValueDeclaration == closestSymbolDeclaration { - return false - } + // Filter out variables from their own initializers + // `const a = /* no 'a' here */` + if closestSymbolDeclaration != nil && + ast.IsVariableDeclaration(closestSymbolDeclaration) && + symbol.ValueDeclaration == closestSymbolDeclaration { + return false + } - // Filter out current and latter parameters from defaults - // `function f(a = /* no 'a' and 'b' here */, b) { }` or - // `function f(a: T, b: T2) { }` - var symbolDeclaration *ast.Declaration - if symbol.ValueDeclaration != nil { - symbolDeclaration = symbol.ValueDeclaration - } else if len(symbol.Declarations) > 0 { - symbolDeclaration = symbol.Declarations[0] - } + // Filter out current and latter parameters from defaults + // `function f(a = /* no 'a' and 'b' here */, b) { }` or + // `function f(a: T, b: T2) { }` + var symbolDeclaration *ast.Declaration + if symbol.ValueDeclaration != nil { + symbolDeclaration = symbol.ValueDeclaration + } else if len(symbol.Declarations) > 0 { + symbolDeclaration = symbol.Declarations[0] + } - if closestSymbolDeclaration != nil && symbolDeclaration != nil { - if ast.IsParameter(closestSymbolDeclaration) && ast.IsParameter(symbolDeclaration) { - parameters := closestSymbolDeclaration.Parent.ParameterList() - if symbolDeclaration.Pos() >= closestSymbolDeclaration.Pos() && - symbolDeclaration.Pos() < parameters.End() { - return false - } - } else if ast.IsTypeParameterDeclaration(closestSymbolDeclaration) && - ast.IsTypeParameterDeclaration(symbolDeclaration) { - if closestSymbolDeclaration == symbolDeclaration && data.contextToken != nil && data.contextToken.Kind == ast.KindExtendsKeyword { - // filter out the directly self-recursive type parameters - // `type A = K` + if closestSymbolDeclaration != nil && symbolDeclaration != nil { + if ast.IsParameter(closestSymbolDeclaration) && ast.IsParameter(symbolDeclaration) { + parameters := closestSymbolDeclaration.Parent.ParameterList() + if symbolDeclaration.Pos() >= closestSymbolDeclaration.Pos() && + symbolDeclaration.Pos() < parameters.End() { + return false + } + } else if ast.IsTypeParameterDeclaration(closestSymbolDeclaration) && + ast.IsTypeParameterDeclaration(symbolDeclaration) { + if closestSymbolDeclaration == symbolDeclaration && data.contextToken != nil && data.contextToken.Kind == ast.KindExtendsKeyword { + // filter out the directly self-recursive type parameters + // `type A = K` + return false + } + if isInTypeParameterDefault(data.contextToken) && !ast.IsInferTypeNode(closestSymbolDeclaration.Parent) { + typeParameters := closestSymbolDeclaration.Parent.TypeParameterList() + if typeParameters != nil && symbolDeclaration.Pos() >= closestSymbolDeclaration.Pos() && + symbolDeclaration.Pos() < typeParameters.End() { return false } - if isInTypeParameterDefault(data.contextToken) && !ast.IsInferTypeNode(closestSymbolDeclaration.Parent) { - typeParameters := closestSymbolDeclaration.Parent.TypeParameterList() - if typeParameters != nil && symbolDeclaration.Pos() >= closestSymbolDeclaration.Pos() && - symbolDeclaration.Pos() < typeParameters.End() { - return false - } - } } } + } - // External modules can have global export declarations that will be - // available as global keywords in all scopes. But if the external module - // already has an explicit export and user only wants to use explicit - // module imports then the global keywords will be filtered out so auto - // import suggestions will win in the completion. - symbolOrigin := checker.SkipAlias(symbol, typeChecker) - // We only want to filter out the global keywords. - // Auto Imports are not available for scripts so this conditional is always false. - if file.AsSourceFile().ExternalModuleIndicator != nil && - compilerOptions.AllowUmdGlobalAccess != core.TSTrue && - data.symbolToSortTextMap[ast.GetSymbolId(symbol)] == SortTextGlobalsOrKeywords && - (data.symbolToSortTextMap[ast.GetSymbolId(symbolOrigin)] == SortTextAutoImportSuggestions || - data.symbolToSortTextMap[ast.GetSymbolId(symbolOrigin)] == SortTextLocationPriority) { - return false - } + // External modules can have global export declarations that will be + // available as global keywords in all scopes. But if the external module + // already has an explicit export and user only wants to use explicit + // module imports then the global keywords will be filtered out so auto + // import suggestions will win in the completion. + symbolOrigin := checker.SkipAlias(symbol, typeChecker) + // We only want to filter out the global keywords. + // Auto Imports are not available for scripts so this conditional is always false. + if file.AsSourceFile().ExternalModuleIndicator != nil && + compilerOptions.AllowUmdGlobalAccess != core.TSTrue && + data.symbolToSortTextMap[ast.GetSymbolId(symbol)] == SortTextGlobalsOrKeywords && + (data.symbolToSortTextMap[ast.GetSymbolId(symbolOrigin)] == SortTextAutoImportSuggestions || + data.symbolToSortTextMap[ast.GetSymbolId(symbolOrigin)] == SortTextLocationPriority) { + return false + } - allFlags = allFlags | checker.GetCombinedLocalAndExportSymbolFlags(symbolOrigin) + allFlags = allFlags | checker.GetCombinedLocalAndExportSymbolFlags(symbolOrigin) - // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace) - if isInRightSideOfInternalImportEqualsDeclaration(data.location) { - return allFlags&ast.SymbolFlagsNamespace != 0 - } + // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace) + if isInRightSideOfInternalImportEqualsDeclaration(data.location) { + return allFlags&ast.SymbolFlagsNamespace != 0 + } - if data.isTypeOnlyLocation { - // It's a type, but you can reach it by namespace.type as well. - return symbolCanBeReferencedAtTypeLocation(symbol, typeChecker, collections.Set[ast.SymbolId]{}) - } + if data.isTypeOnlyLocation { + // It's a type, but you can reach it by namespace.type as well. + return symbolCanBeReferencedAtTypeLocation(symbol, typeChecker, collections.Set[ast.SymbolId]{}) } // expressions are value space (which includes the value namespaces) @@ -3677,7 +3675,6 @@ func tryGetObjectTypeDeclarationCompletionContainer( return location.Parent } return nil - // !!! we don't include EOF token anymore, verify what we should do in this case. case ast.KindEndOfFile: stmtList := location.Parent.AsSourceFile().Statements if stmtList != nil && len(stmtList.Nodes) > 0 && ast.IsObjectTypeDeclaration(stmtList.Nodes[len(stmtList.Nodes)-1]) { diff --git a/internal/ls/utilities.go b/internal/ls/utilities.go index d8e362ea75..716aea5eea 100644 --- a/internal/ls/utilities.go +++ b/internal/ls/utilities.go @@ -382,6 +382,9 @@ func isTypeReference(node *ast.Node) bool { } func isInRightSideOfInternalImportEqualsDeclaration(node *ast.Node) bool { + if node.Parent == nil { + return false + } for node.Parent.Kind == ast.KindQualifiedName { node = node.Parent } diff --git a/internal/parser/parser.go b/internal/parser/parser.go index f468ea9b7d..2307091d5f 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -127,10 +127,11 @@ func (p *Parser) initializeClosures() { func (p *Parser) parseJSONText() *ast.SourceFile { pos := p.nodePos() var statements *ast.NodeList + var eof *ast.TokenNode if p.token == ast.KindEndOfFile { statements = p.newNodeList(core.NewTextRange(pos, p.nodePos()), nil) - p.parseTokenNode() + eof = p.parseTokenNode() } else { var expressions any // []*ast.Expression | *ast.Expression @@ -183,9 +184,9 @@ func (p *Parser) parseJSONText() *ast.SourceFile { statement := p.factory.NewExpressionStatement(expression) p.finishNode(statement, pos) statements = p.newNodeList(core.NewTextRange(pos, p.nodePos()), []*ast.Node{statement}) - p.parseExpectedToken(ast.KindEndOfFile) + eof = p.parseExpectedToken(ast.KindEndOfFile) } - node := p.factory.NewSourceFile(p.opts, p.sourceText, statements) + node := p.factory.NewSourceFile(p.opts, p.sourceText, statements, eof) p.finishNode(node, pos) result := node.AsSourceFile() p.finishSourceFile(result, false) @@ -333,11 +334,19 @@ func (p *Parser) parseSourceFileWorker() *ast.SourceFile { } pos := p.nodePos() statements := p.parseListIndex(PCSourceElements, (*Parser).parseToplevelStatement) + end := p.nodePos() + endHasJSDoc := p.hasPrecedingJSDocComment() eof := p.parseTokenNode() + p.withJSDoc(eof, endHasJSDoc) if eof.Kind != ast.KindEndOfFile { panic("Expected end of file token from scanner.") } - node := p.factory.NewSourceFile(p.opts, p.sourceText, statements) + if len(p.reparseList) > 0 { + statements = append(statements, p.reparseList...) + p.reparseList = nil + end = p.nodePos() + } + node := p.factory.NewSourceFile(p.opts, p.sourceText, p.newNodeList(core.NewTextRange(pos, end), statements), eof) p.finishNode(node, pos) result := node.AsSourceFile() p.finishSourceFile(result, isDeclarationFile) @@ -475,15 +484,14 @@ func (p *Parser) reparseTopLevelAwait(sourceFile *ast.SourceFile) *ast.Node { } } - result := p.factory.NewSourceFile(sourceFile.ParseOptions(), p.sourceText, p.newNodeList(sourceFile.Statements.Loc, statements)) + result := p.factory.NewSourceFile(sourceFile.ParseOptions(), p.sourceText, p.newNodeList(sourceFile.Statements.Loc, statements), sourceFile.EndOfFileToken) for _, s := range statements { s.Parent = result.AsNode() // force (re)set parent to reparsed source file } return result } -func (p *Parser) parseListIndex(kind ParsingContext, parseElement func(p *Parser, index int) *ast.Node) *ast.NodeList { - pos := p.nodePos() +func (p *Parser) parseListIndex(kind ParsingContext, parseElement func(p *Parser, index int) *ast.Node) []*ast.Node { saveParsingContexts := p.parsingContexts p.parsingContexts |= 1 << kind list := make([]*ast.Node, 0, 16) @@ -504,11 +512,13 @@ func (p *Parser) parseListIndex(kind ParsingContext, parseElement func(p *Parser p.parsingContexts = saveParsingContexts slice := p.nodeSlicePool.NewSlice(len(list)) copy(slice, list) - return p.newNodeList(core.NewTextRange(pos, p.nodePos()), slice) + return slice } func (p *Parser) parseList(kind ParsingContext, parseElement func(p *Parser) *ast.Node) *ast.NodeList { - return p.parseListIndex(kind, func(p *Parser, _ int) *ast.Node { return parseElement(p) }) + pos := p.nodePos() + nodes := p.parseListIndex(kind, func(p *Parser, _ int) *ast.Node { return parseElement(p) }) + return p.newNodeList(core.NewTextRange(pos, p.nodePos()), nodes) } // Return a non-nil (but possibly empty) slice if parsing was successful, or nil if parseElement returned nil diff --git a/internal/parser/reparser.go b/internal/parser/reparser.go index 557d672bc2..6dd6cc5c02 100644 --- a/internal/parser/reparser.go +++ b/internal/parser/reparser.go @@ -110,6 +110,9 @@ func (p *Parser) reparseUnhosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Nod case ast.KindJSDocImportTag: importTag := tag.AsJSDocImportTag() importClause := importTag.ImportClause + if importClause == nil { + break + } importClause.Flags |= ast.NodeFlagsReparsed importClause.AsImportClause().IsTypeOnly = true p.finishReparsedNode(importClause) diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 6e40c86377..da14de4ea3 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -612,7 +612,7 @@ func TestParenthesizeDecorator(t *testing.T) { factory.NewNodeList([]*ast.Node{}), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "@(a + b)\nclass C {\n}") @@ -649,7 +649,7 @@ func TestParenthesizeComputedPropertyName(t *testing.T) { }), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "class C {\n [(a, b)];\n}") @@ -679,7 +679,7 @@ func TestParenthesizeArrayLiteral(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "[(a, b)];") @@ -707,7 +707,7 @@ func TestParenthesizePropertyAccess1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b).c;") @@ -734,7 +734,7 @@ func TestParenthesizePropertyAccess2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b).c;") @@ -760,7 +760,7 @@ func TestParenthesizePropertyAccess3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(new a).b;") @@ -788,7 +788,7 @@ func TestParenthesizeElementAccess1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b)[c];") @@ -815,7 +815,7 @@ func TestParenthesizeElementAccess2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b)[c];") @@ -841,7 +841,7 @@ func TestParenthesizeElementAccess3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(new a)[b];") @@ -870,7 +870,7 @@ func TestParenthesizeCall1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b)();") @@ -898,7 +898,7 @@ func TestParenthesizeCall2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b)();") @@ -925,7 +925,7 @@ func TestParenthesizeCall3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(new C)();") @@ -955,7 +955,7 @@ func TestParenthesizeCall4(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a((b, c));") @@ -982,7 +982,7 @@ func TestParenthesizeNew1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new (a, b)();") @@ -1009,7 +1009,7 @@ func TestParenthesizeNew2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new (C());") @@ -1037,7 +1037,7 @@ func TestParenthesizeNew3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new C((a, b));") @@ -1066,7 +1066,7 @@ func TestParenthesizeTaggedTemplate1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) ``;") @@ -1094,7 +1094,7 @@ func TestParenthesizeTaggedTemplate2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a?.b) ``;") @@ -1123,7 +1123,7 @@ func TestParenthesizeTypeAssertion1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a + b);") @@ -1150,7 +1150,7 @@ func TestParenthesizeArrowFunction1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "() => ({});") @@ -1182,7 +1182,7 @@ func TestParenthesizeArrowFunction2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "() => ({}.a);") @@ -1207,7 +1207,7 @@ func TestParenthesizeDelete(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "delete (a + b);") @@ -1232,7 +1232,7 @@ func TestParenthesizeVoid(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "void (a + b);") @@ -1257,7 +1257,7 @@ func TestParenthesizeTypeOf(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "typeof (a + b);") @@ -1282,7 +1282,7 @@ func TestParenthesizeAwait(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "await (a + b);") @@ -1405,7 +1405,7 @@ func TestParenthesizeBinary(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), rec.output+";") @@ -1436,7 +1436,7 @@ func TestParenthesizeConditional1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) ? c : d;") @@ -1465,7 +1465,7 @@ func TestParenthesizeConditional2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a = b) ? c : d;") @@ -1498,7 +1498,7 @@ func TestParenthesizeConditional3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(() => { }) ? a : b;") @@ -1521,7 +1521,7 @@ func TestParenthesizeConditional4(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(yield) ? a : b;") @@ -1550,7 +1550,7 @@ func TestParenthesizeConditional5(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a ? (b, c) : d;") @@ -1579,7 +1579,7 @@ func TestParenthesizeConditional6(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a ? b : (c, d);") @@ -1605,7 +1605,7 @@ func TestParenthesizeYield1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "yield (a, b);") @@ -1641,7 +1641,7 @@ func TestParenthesizeSpreadElement1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "[...(a, b)];") @@ -1676,7 +1676,7 @@ func TestParenthesizeSpreadElement2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "a(...(b, c));") @@ -1709,7 +1709,7 @@ func TestParenthesizeSpreadElement3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "new a(...(b, c));") @@ -1742,7 +1742,7 @@ func TestParenthesizeExpressionWithTypeArguments(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b);") @@ -1771,7 +1771,7 @@ func TestParenthesizeAsExpression(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) as c;") @@ -1800,7 +1800,7 @@ func TestParenthesizeSatisfiesExpression(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b) satisfies c;") @@ -1826,7 +1826,7 @@ func TestParenthesizeNonNullExpression(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(a, b)!;") @@ -1847,7 +1847,7 @@ func TestParenthesizeExpressionStatement1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "({});") @@ -1876,7 +1876,7 @@ func TestParenthesizeExpressionStatement2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(function () { });") @@ -1900,7 +1900,7 @@ func TestParenthesizeExpressionStatement3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "(class {\n});") @@ -1928,7 +1928,7 @@ func TestParenthesizeExpressionDefault1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "export default (class {\n});") @@ -1963,7 +1963,7 @@ func TestParenthesizeExpressionDefault2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "export default (function () { });") @@ -1989,7 +1989,7 @@ func TestParenthesizeExpressionDefault3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "export default (a, b);") @@ -2018,7 +2018,7 @@ func TestParenthesizeArrayType(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (a | b)[];") @@ -2053,7 +2053,7 @@ func TestParenthesizeOptionalType(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = [\n (a | b)?\n];") @@ -2086,7 +2086,7 @@ func TestParenthesizeUnionType1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a | (() => b);") @@ -2120,7 +2120,7 @@ func TestParenthesizeUnionType2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (infer a extends b) | c;") @@ -2154,7 +2154,7 @@ func TestParenthesizeIntersectionType(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a & (b | c);") @@ -2184,7 +2184,7 @@ func TestParenthesizeReadonlyTypeOperator1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = readonly (a | b);") @@ -2210,7 +2210,7 @@ func TestParenthesizeReadonlyTypeOperator2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = readonly (keyof a);") @@ -2240,7 +2240,7 @@ func TestParenthesizeKeyofTypeOperator(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = keyof (a | b);") @@ -2270,7 +2270,7 @@ func TestParenthesizeIndexedAccessType(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (a | b)[c];") @@ -2301,7 +2301,7 @@ func TestParenthesizeConditionalType1(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = (() => a) extends b ? c : d;") @@ -2331,7 +2331,7 @@ func TestParenthesizeConditionalType2(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a extends (b extends c ? d : e) ? f : g;") @@ -2369,7 +2369,7 @@ func TestParenthesizeConditionalType3(t *testing.T) { ), ), }, - )) + ), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a extends () => (infer b extends c) ? d : e;") @@ -2412,7 +2412,7 @@ func TestParenthesizeConditionalType4(t *testing.T) { factory.NewTypeReferenceNode(factory.NewIdentifier("f"), nil /*typeArguments*/), ), ), - })) + }), factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, nil, file.AsSourceFile(), "type _ = a extends () => (infer b extends c) | d ? e : f;") @@ -2444,7 +2444,7 @@ func TestNameGeneration(t *testing.T) { )), }), true), ), - })) + }), ec.Factory.NewToken(ast.KindEndOfFile)) parsetestutil.MarkSyntheticRecursive(file) emittestutil.CheckEmit(t, ec, file.AsSourceFile(), "var _a;\nfunction f() {\n var _a;\n}") diff --git a/internal/transformers/declarations/transform.go b/internal/transformers/declarations/transform.go index 8bc4b0181f..747c111e93 100644 --- a/internal/transformers/declarations/transform.go +++ b/internal/transformers/declarations/transform.go @@ -195,7 +195,7 @@ func (tx *DeclarationTransformer) transformSourceFile(node *ast.SourceFile) *ast combinedStatements = withMarker } outputFilePath := tspath.GetDirectoryPath(tspath.NormalizeSlashes(tx.declarationFilePath)) - result := tx.Factory().UpdateSourceFile(node, combinedStatements) + result := tx.Factory().UpdateSourceFile(node, combinedStatements, node.EndOfFileToken) result.AsSourceFile().LibReferenceDirectives = tx.getLibReferences() result.AsSourceFile().TypeReferenceDirectives = tx.getTypeReferences() result.AsSourceFile().IsDeclarationFile = true diff --git a/internal/transformers/estransforms/using.go b/internal/transformers/estransforms/using.go index 2fb810cfd9..101176221c 100644 --- a/internal/transformers/estransforms/using.go +++ b/internal/transformers/estransforms/using.go @@ -173,7 +173,7 @@ func (tx *usingDeclarationTransformer) visitSourceFile(node *ast.SourceFile) *as )) } - visited = tx.Factory().UpdateSourceFile(node, tx.Factory().NewNodeList(topLevelStatements)) + visited = tx.Factory().UpdateSourceFile(node, tx.Factory().NewNodeList(topLevelStatements), node.EndOfFileToken) } else { visited = tx.Visitor().VisitEachChild(node.AsNode()) } diff --git a/internal/transformers/jsxtransforms/jsx.go b/internal/transformers/jsxtransforms/jsx.go index 03fb5d8542..8cbd03ad35 100644 --- a/internal/transformers/jsxtransforms/jsx.go +++ b/internal/transformers/jsxtransforms/jsx.go @@ -273,7 +273,7 @@ func (tx *JSXTransformer) visitSourceFile(file *ast.SourceFile) *ast.Node { } if statementsUpdated { - visited = tx.Factory().UpdateSourceFile(file, tx.Factory().NewNodeList(statements)) + visited = tx.Factory().UpdateSourceFile(file, tx.Factory().NewNodeList(statements), file.EndOfFileToken) } tx.currentSourceFile = nil diff --git a/internal/transformers/moduletransforms/commonjsmodule.go b/internal/transformers/moduletransforms/commonjsmodule.go index 02e5458277..a078399c5b 100644 --- a/internal/transformers/moduletransforms/commonjsmodule.go +++ b/internal/transformers/moduletransforms/commonjsmodule.go @@ -363,7 +363,7 @@ func (tx *CommonJSModuleTransformer) transformCommonJSModule(node *ast.SourceFil statementList := tx.Factory().NewNodeList(statements) statementList.Loc = node.Statements.Loc - result := tx.Factory().UpdateSourceFile(node, statementList).AsSourceFile() + result := tx.Factory().UpdateSourceFile(node, statementList, node.EndOfFileToken).AsSourceFile() tx.EmitContext().AddEmitHelper(result.AsNode(), tx.EmitContext().ReadEmitHelpers()...) externalHelpersImportDeclaration := createExternalHelpersImportDeclarationIfNeeded(tx.EmitContext(), result, tx.compilerOptions, tx.getEmitModuleFormatOfFile(node), false /*hasExportStarsToExportValues*/, false /*hasImportStar*/, false /*hasImportDefault*/) @@ -376,7 +376,7 @@ func (tx *CommonJSModuleTransformer) transformCommonJSModule(node *ast.SourceFil statements = append(statements, rest...) statementList := tx.Factory().NewNodeList(statements) statementList.Loc = result.Statements.Loc - result = tx.Factory().UpdateSourceFile(result, statementList).AsSourceFile() + result = tx.Factory().UpdateSourceFile(result, statementList, node.EndOfFileToken).AsSourceFile() } return result.AsNode() diff --git a/internal/transformers/moduletransforms/esmodule.go b/internal/transformers/moduletransforms/esmodule.go index 3f1f90cdba..1ab1af2ee5 100644 --- a/internal/transformers/moduletransforms/esmodule.go +++ b/internal/transformers/moduletransforms/esmodule.go @@ -79,7 +79,7 @@ func (tx *ESModuleTransformer) visitSourceFile(node *ast.SourceFile) *ast.Node { statements = append(statements, rest...) statementList := tx.Factory().NewNodeList(statements) statementList.Loc = result.Statements.Loc - result = tx.Factory().UpdateSourceFile(result, statementList).AsSourceFile() + result = tx.Factory().UpdateSourceFile(result, statementList, node.EndOfFileToken).AsSourceFile() } if ast.IsExternalModule(result) && @@ -89,7 +89,7 @@ func (tx *ESModuleTransformer) visitSourceFile(node *ast.SourceFile) *ast.Node { statements = append(statements, createEmptyImports(tx.Factory())) statementList := tx.Factory().NewNodeList(statements) statementList.Loc = result.Statements.Loc - result = tx.Factory().UpdateSourceFile(result, statementList).AsSourceFile() + result = tx.Factory().UpdateSourceFile(result, statementList, node.EndOfFileToken).AsSourceFile() } tx.importRequireStatements = nil diff --git a/internal/tsoptions/tsconfigparsing.go b/internal/tsoptions/tsconfigparsing.go index b527558e24..5204f58e80 100644 --- a/internal/tsoptions/tsconfigparsing.go +++ b/internal/tsoptions/tsconfigparsing.go @@ -889,7 +889,7 @@ func readJsonConfigFile(fileName string, path tspath.Path, readFile func(fileNam }, diagnostic } else { file := &TsConfigSourceFile{ - SourceFile: (&ast.NodeFactory{}).NewSourceFile(ast.SourceFileParseOptions{FileName: fileName, Path: path}, "", nil).AsSourceFile(), + SourceFile: (&ast.NodeFactory{}).NewSourceFile(ast.SourceFileParseOptions{FileName: fileName, Path: path}, "", nil, (&ast.NodeFactory{}).NewToken(ast.KindEndOfFile)).AsSourceFile(), } file.SourceFile.SetDiagnostics(diagnostic) return file, diagnostic diff --git a/testdata/baselines/reference/api/encodeSourceFile.txt b/testdata/baselines/reference/api/encodeSourceFile.txt index 88eb7adb80..317827d625 100644 --- a/testdata/baselines/reference/api/encodeSourceFile.txt +++ b/testdata/baselines/reference/api/encodeSourceFile.txt @@ -1,5 +1,5 @@ KindSourceFile [0, 89), i=1, next=0 - NodeList [0, 89), i=2, next=0 + NodeList [0, 89), i=2, next=31 KindImportDeclaration [0, 26), i=3, next=10 KindImportClause [6, 14), i=4, next=9 KindNamedImports [6, 14), i=5, next=0 @@ -28,3 +28,4 @@ KindSourceFile [0, 89), i=1, next=0 KindExpressionStatement [82, 89), i=28, next=0 KindCallExpression [82, 88), i=29, next=0 KindIdentifier "foo" [82, 86), i=30, next=0 + KindEndOfFile [89, 89), i=31, next=0 diff --git a/testdata/baselines/reference/conformance/jsDeclarationsDefault2.js b/testdata/baselines/reference/conformance/jsDeclarationsDefault2.js new file mode 100644 index 0000000000..8ef559c295 --- /dev/null +++ b/testdata/baselines/reference/conformance/jsDeclarationsDefault2.js @@ -0,0 +1,61 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault2.ts] //// + +//// [index1.js] +export const _default = class {}; + +export default 12; +/** + * @typedef {string | number} default + */ + + +//// [index1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports._default = void 0; +const _default = class { +}; +exports._default = _default; +exports.default = 12; + + +//// [index1.d.ts] +export declare const _default: { + new (): {}; +}; +declare const _default_1: number; +export default _default_1; +export type default = string | number; + + +//// [DtsFileErrors] + + +out/index1.d.ts(6,1): error TS1128: Declaration or statement expected. +out/index1.d.ts(6,8): error TS2304: Cannot find name 'type'. +out/index1.d.ts(6,13): error TS2457: Type alias name cannot be 'default'. +out/index1.d.ts(6,21): error TS1128: Declaration or statement expected. +out/index1.d.ts(6,23): error TS2693: 'string' only refers to a type, but is being used as a value here. +out/index1.d.ts(6,32): error TS2693: 'number' only refers to a type, but is being used as a value here. + + +==== out/index1.d.ts (6 errors) ==== + export declare const _default: { + new (): {}; + }; + declare const _default_1: number; + export default _default_1; + export type default = string | number; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~ +!!! error TS2304: Cannot find name 'type'. + ~~~~~~~ +!!! error TS2457: Type alias name cannot be 'default'. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + ~~~~~~ +!!! error TS2693: 'number' only refers to a type, but is being used as a value here. + \ No newline at end of file diff --git a/testdata/baselines/reference/conformance/jsDeclarationsDefault2.symbols b/testdata/baselines/reference/conformance/jsDeclarationsDefault2.symbols new file mode 100644 index 0000000000..c87f2f59b3 --- /dev/null +++ b/testdata/baselines/reference/conformance/jsDeclarationsDefault2.symbols @@ -0,0 +1,11 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault2.ts] //// + +=== index1.js === +export const _default = class {}; +>_default : Symbol(_default, Decl(index1.js, 0, 12)) + +export default 12; +/** + * @typedef {string | number} default + */ + diff --git a/testdata/baselines/reference/conformance/jsDeclarationsDefault2.types b/testdata/baselines/reference/conformance/jsDeclarationsDefault2.types new file mode 100644 index 0000000000..a1df7e6f73 --- /dev/null +++ b/testdata/baselines/reference/conformance/jsDeclarationsDefault2.types @@ -0,0 +1,12 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault2.ts] //// + +=== index1.js === +export const _default = class {}; +>_default : typeof _default +>class {} : typeof _default + +export default 12; +/** + * @typedef {string | number} default + */ + diff --git a/testdata/baselines/reference/submodule/compiler/importTypeResolutionJSDocEOF.errors.txt b/testdata/baselines/reference/submodule/compiler/importTypeResolutionJSDocEOF.errors.txt deleted file mode 100644 index 3f5fe39172..0000000000 --- a/testdata/baselines/reference/submodule/compiler/importTypeResolutionJSDocEOF.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -usage.js(1,12): error TS2304: Cannot find name 'Bar'. - - -==== interfaces.d.ts (0 errors) ==== - export interface Bar { - prop: string - } - -==== usage.js (1 errors) ==== - /** @type {Bar} */ - ~~~ -!!! error TS2304: Cannot find name 'Bar'. - export let bar; - - /** @typedef {import('./interfaces').Bar} Bar */ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/importTypeResolutionJSDocEOF.types b/testdata/baselines/reference/submodule/compiler/importTypeResolutionJSDocEOF.types index fad53ca758..67e5e38a34 100644 --- a/testdata/baselines/reference/submodule/compiler/importTypeResolutionJSDocEOF.types +++ b/testdata/baselines/reference/submodule/compiler/importTypeResolutionJSDocEOF.types @@ -9,6 +9,6 @@ export interface Bar { === usage.js === /** @type {Bar} */ export let bar; ->bar : Bar +>bar : import("./interfaces").Bar /** @typedef {import('./interfaces').Bar} Bar */ diff --git a/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.errors.txt b/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.errors.txt index 6c3a675c1e..220be597bd 100644 --- a/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.errors.txt @@ -1,15 +1,15 @@ -/a.js(2,12): error TS2304: Cannot find name 'Ty'. +/a.js(7,14): error TS2304: Cannot find name 'CantResolveThis'. ==== /a.js (1 errors) ==== /** * @param {Ty} x - ~~ -!!! error TS2304: Cannot find name 'Ty'. */ function f(x) {} /** * @typedef {CantResolveThis} Ty + ~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'CantResolveThis'. */ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.types b/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.types index 475bea13be..dbb176d8b9 100644 --- a/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.types +++ b/testdata/baselines/reference/submodule/compiler/jsdocResolveNameFailureInTypedef.types @@ -5,8 +5,8 @@ * @param {Ty} x */ function f(x) {} ->f : (x: Ty) => void ->x : Ty +>f : (x: CantResolveThis) => void +>x : CantResolveThis /** * @typedef {CantResolveThis} Ty diff --git a/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt b/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt index 0af10fbba6..5e1769bc36 100644 --- a/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt @@ -1,21 +1,17 @@ -/contractHelper.d.ts(3,67): error TS2694: Namespace '"/types"' has no exported member 'ParamStateRecord'. -/exported.d.ts(2,10): error TS2305: Module '"./types.js"' has no exported member 'ParamStateRecord'. +/types.js(3,21): error TS2304: Cannot find name 'Keyword'. +/types.js(3,30): error TS2304: Cannot find name 'ParamValueTyped'. -==== /contractHelper.d.ts (1 errors) ==== +==== /contractHelper.d.ts (0 errors) ==== export function handleParamGovernance(zcf: any): { publicMixin: { getGovernedParams: () => globalThis.ERef; - ~~~~~~~~~~~~~~~~ -!!! error TS2694: Namespace '"/types"' has no exported member 'ParamStateRecord'. }; }; -==== /exported.d.ts (1 errors) ==== +==== /exported.d.ts (0 errors) ==== type _ERef = T | Promise; import { ParamStateRecord as _ParamStateRecord } from './types.js'; - ~~~~~~~~~~~~~~~~ -!!! error TS2305: Module '"./types.js"' has no exported member 'ParamStateRecord'. declare global { // @ts-ignore TS2666 export { @@ -24,10 +20,14 @@ }; } -==== /types.js (0 errors) ==== +==== /types.js (2 errors) ==== export {}; /** * @typedef {Record} ParamStateRecord a Record containing + ~~~~~~~ +!!! error TS2304: Cannot find name 'Keyword'. + ~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'ParamValueTyped'. * keyword pairs with descriptions of parameters under governance. */ diff --git a/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js b/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js index 2ae2909b75..7aea80f806 100644 --- a/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js +++ b/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js @@ -34,13 +34,10 @@ export const blah = handleParamGovernance({}); //// [types.d.ts] export {}; -/** - * @typedef {Record} ParamStateRecord a Record containing - * keyword pairs with descriptions of parameters under governance. - */ +export type ParamStateRecord = Record; //// [index.d.ts] export declare const blah: { publicMixin: { - getGovernedParams: () => any; + getGovernedParams: () => globalThis.ERef; }; }; diff --git a/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js.diff b/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js.diff index 5237df289e..f47efb7598 100644 --- a/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js.diff +++ b/testdata/baselines/reference/submodule/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js.diff @@ -4,18 +4,17 @@ //// [types.d.ts] -+export {}; - /** +-/** - * a Record containing -+ * @typedef {Record} ParamStateRecord a Record containing - * keyword pairs with descriptions of parameters under governance. - */ --export type ParamStateRecord = Record; +- * keyword pairs with descriptions of parameters under governance. +- */ ++export {}; + export type ParamStateRecord = Record; //// [index.d.ts] -export const blah: { +export declare const blah: { publicMixin: { - getGovernedParams: () => globalThis.ERef; -+ getGovernedParams: () => any; ++ getGovernedParams: () => globalThis.ERef; }; }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/uniqueSymbolJs.errors.txt b/testdata/baselines/reference/submodule/compiler/uniqueSymbolJs.errors.txt new file mode 100644 index 0000000000..162596d71b --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/uniqueSymbolJs.errors.txt @@ -0,0 +1,15 @@ +a.js(5,18): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. +a.js(5,23): error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'? + + +==== a.js (2 errors) ==== + /** @type {unique symbol} */ + const foo = Symbol(); + + /** @typedef {{ [foo]: boolean }} A */ + /** @typedef {{ [key: foo] boolean }} B */ + ~~~ +!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. + ~~~ +!!! error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'? + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/unmetTypeConstraintInJSDocImportCall.errors.txt b/testdata/baselines/reference/submodule/compiler/unmetTypeConstraintInJSDocImportCall.errors.txt new file mode 100644 index 0000000000..b3982713da --- /dev/null +++ b/testdata/baselines/reference/submodule/compiler/unmetTypeConstraintInJSDocImportCall.errors.txt @@ -0,0 +1,20 @@ +file2.js(3,36): error TS2344: Type 'T' does not satisfy the constraint 'string'. + + +==== file1.js (0 errors) ==== + /** + * @template {string} T + * @typedef {{ foo: T }} Foo + */ + + export default {}; + +==== file2.js (1 errors) ==== + /** + * @template T + * @typedef {import('./file1').Foo} Bar + ~ +!!! error TS2344: Type 'T' does not satisfy the constraint 'string'. +!!! related TS2208 file2.js:2:14: This type parameter might need an `extends string` constraint. + */ + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/callbackTag1.errors.txt b/testdata/baselines/reference/submodule/conformance/callbackTag1.errors.txt deleted file mode 100644 index 46a2b3efe8..0000000000 --- a/testdata/baselines/reference/submodule/conformance/callbackTag1.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -cb.js(11,12): error TS2304: Cannot find name 'NoReturn'. - - -==== cb.js (1 errors) ==== - /** @callback Sid - * @param {string} s - * @returns {string} What were you expecting - */ - var x = 1 - - /** @type {Sid} smallId */ - var sid = s => s + "!"; - - - /** @type {NoReturn} */ - ~~~~~~~~ -!!! error TS2304: Cannot find name 'NoReturn'. - var noreturn = obj => void obj.title - - /** - * @callback NoReturn - * @param {{ e: number, m: number, title: string }} s - Knee deep, shores, etc - */ - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/callbackTag1.symbols b/testdata/baselines/reference/submodule/conformance/callbackTag1.symbols index fa9e1caebe..26dba85654 100644 --- a/testdata/baselines/reference/submodule/conformance/callbackTag1.symbols +++ b/testdata/baselines/reference/submodule/conformance/callbackTag1.symbols @@ -19,7 +19,9 @@ var sid = s => s + "!"; var noreturn = obj => void obj.title >noreturn : Symbol(noreturn, Decl(cb.js, 11, 3)) >obj : Symbol(obj, Decl(cb.js, 11, 14)) +>obj.title : Symbol(title, Decl(cb.js, 15, 34)) >obj : Symbol(obj, Decl(cb.js, 11, 14)) +>title : Symbol(title, Decl(cb.js, 15, 34)) /** * @callback NoReturn diff --git a/testdata/baselines/reference/submodule/conformance/callbackTag1.symbols.diff b/testdata/baselines/reference/submodule/conformance/callbackTag1.symbols.diff deleted file mode 100644 index 16f9467d19..0000000000 --- a/testdata/baselines/reference/submodule/conformance/callbackTag1.symbols.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- old.callbackTag1.symbols -+++ new.callbackTag1.symbols -@@= skipped -18, +18 lines =@@ - var noreturn = obj => void obj.title - >noreturn : Symbol(noreturn, Decl(cb.js, 11, 3)) - >obj : Symbol(obj, Decl(cb.js, 11, 14)) -->obj.title : Symbol(title, Decl(cb.js, 15, 34)) - >obj : Symbol(obj, Decl(cb.js, 11, 14)) -->title : Symbol(title, Decl(cb.js, 15, 34)) - - /** - * @callback NoReturn \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/callbackTag1.types b/testdata/baselines/reference/submodule/conformance/callbackTag1.types index 70dac8bf06..460061c867 100644 --- a/testdata/baselines/reference/submodule/conformance/callbackTag1.types +++ b/testdata/baselines/reference/submodule/conformance/callbackTag1.types @@ -22,12 +22,12 @@ var sid = s => s + "!"; /** @type {NoReturn} */ var noreturn = obj => void obj.title >noreturn : NoReturn ->obj => void obj.title : (obj: any) => any ->obj : any +>obj => void obj.title : (obj: { e: number; m: number; title: string; }) => any +>obj : { e: number; m: number; title: string; } >void obj.title : undefined ->obj.title : any ->obj : any ->title : any +>obj.title : string +>obj : { e: number; m: number; title: string; } +>title : string /** * @callback NoReturn diff --git a/testdata/baselines/reference/submodule/conformance/callbackTag2.errors.txt b/testdata/baselines/reference/submodule/conformance/callbackTag2.errors.txt index f011f90e35..2dbccc172d 100644 --- a/testdata/baselines/reference/submodule/conformance/callbackTag2.errors.txt +++ b/testdata/baselines/reference/submodule/conformance/callbackTag2.errors.txt @@ -1,8 +1,7 @@ cb.js(19,14): error TS2339: Property 'id' does not exist on type 'SharedClass'. -cb.js(25,12): error TS2304: Cannot find name 'Final'. -==== cb.js (2 errors) ==== +==== cb.js (1 errors) ==== /** @template T * @callback Id * @param {T} t @@ -30,8 +29,6 @@ cb.js(25,12): error TS2304: Cannot find name 'Final'. var outside = n => n + 1; /** @type {Final<{ fantasy }, { heroes }>} */ - ~~~~~ -!!! error TS2304: Cannot find name 'Final'. var noreturn = (barts, tidus, noctis) => "cecil" /** diff --git a/testdata/baselines/reference/submodule/conformance/callbackTag2.types b/testdata/baselines/reference/submodule/conformance/callbackTag2.types index afdceb9570..c0bc6b9776 100644 --- a/testdata/baselines/reference/submodule/conformance/callbackTag2.types +++ b/testdata/baselines/reference/submodule/conformance/callbackTag2.types @@ -45,10 +45,10 @@ var outside = n => n + 1; /** @type {Final<{ fantasy }, { heroes }>} */ var noreturn = (barts, tidus, noctis) => "cecil" >noreturn : Final<{ fantasy: any; }, { heroes: any; }> ->(barts, tidus, noctis) => "cecil" : (barts: any, tidus: any, noctis: any) => string ->barts : any ->tidus : any ->noctis : any +>(barts, tidus, noctis) => "cecil" : (barts: { fantasy: any; }, tidus: { heroes: any; }, noctis: { heroes: any; } & { fantasy: any; }) => "cecil" +>barts : { fantasy: any; } +>tidus : { heroes: any; } +>noctis : { heroes: any; } & { fantasy: any; } >"cecil" : "cecil" /** diff --git a/testdata/baselines/reference/submodule/conformance/checkJsdocOnEndOfFile.errors.txt b/testdata/baselines/reference/submodule/conformance/checkJsdocOnEndOfFile.errors.txt new file mode 100644 index 0000000000..19e950b028 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/checkJsdocOnEndOfFile.errors.txt @@ -0,0 +1,10 @@ +eof.js(2,20): error TS2304: Cannot find name 'bad'. + + +==== eof.js (1 errors) ==== + /** + * @typedef {Array} Should have error here + ~~~ +!!! error TS2304: Cannot find name 'bad'. + */ + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importTag13.errors.txt b/testdata/baselines/reference/submodule/conformance/importTag13.errors.txt new file mode 100644 index 0000000000..958d6225ec --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importTag13.errors.txt @@ -0,0 +1,13 @@ +/foo.js(1,15): error TS1141: String literal expected. + + +==== /foo.js (1 errors) ==== + /** @import x = require("types") */ + ~~~~~~~~~~~~~~~~~~ +!!! error TS1141: String literal expected. + +==== /types.ts (0 errors) ==== + export interface Foo { + a: number; + } + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/importTag14.errors.txt b/testdata/baselines/reference/submodule/conformance/importTag14.errors.txt new file mode 100644 index 0000000000..b2aace2a64 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/importTag14.errors.txt @@ -0,0 +1,14 @@ +/foo.js(1,25): error TS2306: File '/foo.js' is not a module. +/foo.js(1,33): error TS1464: Type import attributes should have exactly one key - 'resolution-mode' - with value 'import' or 'require'. +/foo.js(1,33): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. + + +==== /foo.js (3 errors) ==== + /** @import * as f from "./foo" with */ + ~~~~~~~ +!!! error TS2306: File '/foo.js' is not a module. + ~~~~ +!!! error TS1464: Type import attributes should have exactly one key - 'resolution-mode' - with value 'import' or 'require'. + ~~~~ +!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.errors.txt b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.errors.txt deleted file mode 100644 index bdc889fdf9..0000000000 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.errors.txt +++ /dev/null @@ -1,29 +0,0 @@ -lib.js(3,17): error TS2552: Cannot find name 'IEncoder'. Did you mean 'Encoder'? - - -==== interface.ts (0 errors) ==== - export interface Encoder { - encode(value: T): Uint8Array - } -==== lib.js (1 errors) ==== - /** - * @template T - * @implements {IEncoder} - ~~~~~~~~ -!!! error TS2552: Cannot find name 'IEncoder'. Did you mean 'Encoder'? -!!! related TS2728 lib.js:5:14: 'Encoder' is declared here. - */ - export class Encoder { - /** - * @param {T} value - */ - encode(value) { - return new Uint8Array(0) - } - } - - - /** - * @template T - * @typedef {import('./interface').Encoder} IEncoder - */ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js index be704163a5..51ba9d09a5 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js @@ -44,10 +44,6 @@ class Encoder { } } exports.Encoder = Encoder; -/** - * @template T - * @typedef {import('./interface').Encoder} IEncoder - */ //// [interface.d.ts] @@ -65,7 +61,4 @@ export declare class Encoder implements IEncoder { */ encode(value: T): Uint8Array; } -/** - * @template T - * @typedef {import('./interface').Encoder} IEncoder - */ +export type IEncoder = import('./interface').Encoder; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js.diff index e0bb03baef..7e805bcf0d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassImplementsGenericsSerialization.js.diff @@ -1,6 +1,17 @@ --- old.jsDeclarationsClassImplementsGenericsSerialization.js +++ new.jsDeclarationsClassImplementsGenericsSerialization.js -@@= skipped -58, +58 lines =@@ +@@= skipped -43, +43 lines =@@ + } + } + exports.Encoder = Encoder; +-/** +- * @template T +- * @typedef {import('./interface').Encoder} IEncoder +- */ + + + //// [interface.d.ts] +@@= skipped -15, +11 lines =@@ * @template T * @implements {IEncoder} */ @@ -12,7 +23,4 @@ encode(value: T): Uint8Array; } -export type IEncoder = import("./interface").Encoder; -+/** -+ * @template T -+ * @typedef {import('./interface').Encoder} IEncoder -+ */ \ No newline at end of file ++export type IEncoder = import('./interface').Encoder; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js index 1aab631323..a0e2b92ee7 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js @@ -44,18 +44,11 @@ export = Handler; module.exports = Handler; export var Strings = Strings; module.exports.Strings = Strings; -/** - * @typedef {Object} HandlerOptions - * @property {String} name - * Should be able to export a type alias at the same time. - */ //// [source.d.ts] export = Handler; export var Strings = Strings; -/** - * @typedef {Object} HandlerOptions - * @property {String} name - * Should be able to export a type alias at the same time. - */ +export type HandlerOptions = { + name: String; +}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff index 40f0a73c85..f39f380c86 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic.js.diff @@ -17,9 +17,12 @@ module.exports = Handler; +export var Strings = Strings; module.exports.Strings = Strings; - /** - * @typedef {Object} HandlerOptions -@@= skipped -11, +13 lines =@@ +-/** +- * @typedef {Object} HandlerOptions +- * @property {String} name +- * Should be able to export a type alias at the same time. +- */ + //// [source.d.ts] export = Handler; @@ -40,10 +43,7 @@ - * Should be able to export a type alias at the same time. - */ - name: string; --}; +export var Strings = Strings; -+/** -+ * @typedef {Object} HandlerOptions -+ * @property {String} name -+ * Should be able to export a type alias at the same time. -+ */ \ No newline at end of file ++export type HandlerOptions = { ++ name: String; + }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js index 505f0d529a..fabe4f7586 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js @@ -77,9 +77,6 @@ exports.default = Bar; Object.defineProperty(exports, "__esModule", { value: true }); // merge type alias and const (OK) exports.default = 12; -/** - * @typedef {string | number} default - */ //// [index6.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); @@ -87,9 +84,6 @@ exports.default = func; // merge type alias and function (OK) function func() { } ; -/** - * @typedef {string | number} default - */ //// [index1.d.ts] @@ -114,12 +108,84 @@ export default Bar; //// [index5.d.ts] declare const _default: number; export default _default; -/** - * @typedef {string | number} default - */ +export type default = string | number; //// [index6.d.ts] // merge type alias and function (OK) export default function func(): void; -/** - * @typedef {string | number} default - */ +export type default = string | number; + + +//// [DtsFileErrors] + + +out/index5.d.ts(3,1): error TS1128: Declaration or statement expected. +out/index5.d.ts(3,8): error TS2304: Cannot find name 'type'. +out/index5.d.ts(3,13): error TS2457: Type alias name cannot be 'default'. +out/index5.d.ts(3,21): error TS1128: Declaration or statement expected. +out/index5.d.ts(3,23): error TS2693: 'string' only refers to a type, but is being used as a value here. +out/index5.d.ts(3,32): error TS2693: 'number' only refers to a type, but is being used as a value here. +out/index6.d.ts(3,1): error TS1128: Declaration or statement expected. +out/index6.d.ts(3,8): error TS2304: Cannot find name 'type'. +out/index6.d.ts(3,13): error TS2457: Type alias name cannot be 'default'. +out/index6.d.ts(3,21): error TS1128: Declaration or statement expected. +out/index6.d.ts(3,23): error TS2693: 'string' only refers to a type, but is being used as a value here. +out/index6.d.ts(3,32): error TS2693: 'number' only refers to a type, but is being used as a value here. + + +==== out/index1.d.ts (0 errors) ==== + declare const _default: number; + export default _default; + +==== out/index2.d.ts (0 errors) ==== + export default function foo(): typeof foo; + export declare const x: typeof foo; + export { foo as bar }; + +==== out/index3.d.ts (0 errors) ==== + export default class Foo { + a: Foo; + } + export declare const X: typeof Foo; + export { Foo as Bar }; + +==== out/index4.d.ts (0 errors) ==== + import Fab from "./index3"; + declare class Bar extends Fab { + x: Bar; + } + export default Bar; + +==== out/index5.d.ts (6 errors) ==== + declare const _default: number; + export default _default; + export type default = string | number; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~ +!!! error TS2304: Cannot find name 'type'. + ~~~~~~~ +!!! error TS2457: Type alias name cannot be 'default'. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + ~~~~~~ +!!! error TS2693: 'number' only refers to a type, but is being used as a value here. + +==== out/index6.d.ts (6 errors) ==== + // merge type alias and function (OK) + export default function func(): void; + export type default = string | number; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~ +!!! error TS2304: Cannot find name 'type'. + ~~~~~~~ +!!! error TS2457: Type alias name cannot be 'default'. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~ +!!! error TS2693: 'string' only refers to a type, but is being used as a value here. + ~~~~~~ +!!! error TS2693: 'number' only refers to a type, but is being used as a value here. + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff index 694467df49..913922e847 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.js.diff @@ -26,7 +26,23 @@ } exports.default = Bar; //// [index5.js] -@@= skipped -29, +26 lines =@@ +@@= skipped -13, +10 lines =@@ + Object.defineProperty(exports, "__esModule", { value: true }); + // merge type alias and const (OK) + exports.default = 12; +-/** +- * @typedef {string | number} default +- */ + //// [index6.js] + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +@@= skipped -10, +7 lines =@@ + // merge type alias and function (OK) + function func() { } + ; +-/** +- * @typedef {string | number} default +- */ //// [index1.d.ts] @@ -58,15 +74,87 @@ -declare const _default: 12; +declare const _default: number; export default _default; -+/** -+ * @typedef {string | number} default -+ */ ++export type default = string | number; //// [index6.d.ts] -declare function func(): void; -type func = string | number; -export default func; +// merge type alias and function (OK) +export default function func(): void; -+/** -+ * @typedef {string | number} default -+ */ \ No newline at end of file ++export type default = string | number; ++ ++ ++//// [DtsFileErrors] ++ ++ ++out/index5.d.ts(3,1): error TS1128: Declaration or statement expected. ++out/index5.d.ts(3,8): error TS2304: Cannot find name 'type'. ++out/index5.d.ts(3,13): error TS2457: Type alias name cannot be 'default'. ++out/index5.d.ts(3,21): error TS1128: Declaration or statement expected. ++out/index5.d.ts(3,23): error TS2693: 'string' only refers to a type, but is being used as a value here. ++out/index5.d.ts(3,32): error TS2693: 'number' only refers to a type, but is being used as a value here. ++out/index6.d.ts(3,1): error TS1128: Declaration or statement expected. ++out/index6.d.ts(3,8): error TS2304: Cannot find name 'type'. ++out/index6.d.ts(3,13): error TS2457: Type alias name cannot be 'default'. ++out/index6.d.ts(3,21): error TS1128: Declaration or statement expected. ++out/index6.d.ts(3,23): error TS2693: 'string' only refers to a type, but is being used as a value here. ++out/index6.d.ts(3,32): error TS2693: 'number' only refers to a type, but is being used as a value here. ++ ++ ++==== out/index1.d.ts (0 errors) ==== ++ declare const _default: number; ++ export default _default; ++ ++==== out/index2.d.ts (0 errors) ==== ++ export default function foo(): typeof foo; ++ export declare const x: typeof foo; ++ export { foo as bar }; ++ ++==== out/index3.d.ts (0 errors) ==== ++ export default class Foo { ++ a: Foo; ++ } ++ export declare const X: typeof Foo; ++ export { Foo as Bar }; ++ ++==== out/index4.d.ts (0 errors) ==== ++ import Fab from "./index3"; ++ declare class Bar extends Fab { ++ x: Bar; ++ } ++ export default Bar; ++ ++==== out/index5.d.ts (6 errors) ==== ++ declare const _default: number; ++ export default _default; ++ export type default = string | number; ++ ~~~~~~ ++!!! error TS1128: Declaration or statement expected. ++ ~~~~ ++!!! error TS2304: Cannot find name 'type'. ++ ~~~~~~~ ++!!! error TS2457: Type alias name cannot be 'default'. ++ ~ ++!!! error TS1128: Declaration or statement expected. ++ ~~~~~~ ++!!! error TS2693: 'string' only refers to a type, but is being used as a value here. ++ ~~~~~~ ++!!! error TS2693: 'number' only refers to a type, but is being used as a value here. ++ ++==== out/index6.d.ts (6 errors) ==== ++ // merge type alias and function (OK) ++ export default function func(): void; ++ export type default = string | number; ++ ~~~~~~ ++!!! error TS1128: Declaration or statement expected. ++ ~~~~ ++!!! error TS2304: Cannot find name 'type'. ++ ~~~~~~~ ++!!! error TS2457: Type alias name cannot be 'default'. ++ ~ ++!!! error TS1128: Declaration or statement expected. ++ ~~~~~~ ++!!! error TS2693: 'string' only refers to a type, but is being used as a value here. ++ ~~~~~~ ++!!! error TS2693: 'number' only refers to a type, but is being used as a value here. ++ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols index aea8216226..28591dbb31 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols @@ -60,7 +60,7 @@ export default 12; === index6.js === // merge type alias and function (OK) export default function func() {}; ->func : Symbol(func, Decl(index6.js, 0, 0)) +>func : Symbol(func, Decl(index6.js, 0, 0), Decl(index6.js, 3, 3)) /** * @typedef {string | number} default diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols.diff index 258e540ffd..b0d52a9d87 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefault.symbols.diff @@ -17,13 +17,4 @@ +>x : Symbol(x, Decl(index4.js, 1, 23)) } export default Bar; - >Bar : Symbol(Bar, Decl(index4.js, 0, 27)) -@@= skipped -16, +16 lines =@@ - === index6.js === - // merge type alias and function (OK) - export default function func() {}; -->func : Symbol(func, Decl(index6.js, 0, 0), Decl(index6.js, 3, 3)) -+>func : Symbol(func, Decl(index6.js, 0, 0)) - - /** - * @typedef {string | number} default \ No newline at end of file + >Bar : Symbol(Bar, Decl(index4.js, 0, 27)) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.errors.txt b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.errors.txt new file mode 100644 index 0000000000..72961c4893 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.errors.txt @@ -0,0 +1,34 @@ +index2.js(2,22): error TS2300: Duplicate identifier 'C'. +index2.js(4,31): error TS2300: Duplicate identifier 'default'. + + +==== index1.js (0 errors) ==== + // merge type alias and alias (should error, see #32367) + class Cls { + x = 12; + static y = "ok" + } + export default Cls; + /** + * @typedef {string | number} default + */ + +==== index2.js (2 errors) ==== + // merge type alias and class (error message improvement needed, see #32368) + export default class C {}; + ~ +!!! error TS2300: Duplicate identifier 'C'. + /** + * @typedef {string | number} default + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. + */ + +==== index3.js (0 errors) ==== + // merge type alias and variable (behavior is borked, see #32366) + const x = 12; + export {x as default}; + /** + * @typedef {string | number} default + */ + \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js index ec5a2262cc..29f6eb88e1 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js @@ -36,9 +36,6 @@ class Cls { static y = "ok"; } exports.default = Cls; -/** - * @typedef {string | number} default - */ //// [index2.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); @@ -47,9 +44,6 @@ class C { } exports.default = C; ; -/** - * @typedef {string | number} default - */ //// [index3.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); @@ -57,9 +51,6 @@ exports.default = void 0; // merge type alias and variable (behavior is borked, see #32366) const x = 12; exports.default = x; -/** - * @typedef {string | number} default - */ //// [index1.d.ts] @@ -69,20 +60,14 @@ declare class Cls { static y: string; } export default Cls; -/** - * @typedef {string | number} default - */ +export type default = string | number; //// [index2.d.ts] // merge type alias and class (error message improvement needed, see #32368) export default class C { } -/** - * @typedef {string | number} default - */ +export type default = string | number; //// [index3.d.ts] // merge type alias and variable (behavior is borked, see #32366) declare const x = 12; export { x as default }; -/** - * @typedef {string | number} default - */ +export type default = string | number; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js.diff index cb00d47a58..6cfad7b358 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.js.diff @@ -18,9 +18,29 @@ + static y = "ok"; +} exports.default = Cls; - /** - * @typedef {string | number} default -@@= skipped -37, +32 lines =@@ +-/** +- * @typedef {string | number} default +- */ + //// [index2.js] + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +@@= skipped -21, +13 lines =@@ + } + exports.default = C; + ; +-/** +- * @typedef {string | number} default +- */ + //// [index3.js] + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +@@= skipped -10, +7 lines =@@ + // merge type alias and variable (behavior is borked, see #32366) + const x = 12; + exports.default = x; +-/** +- * @typedef {string | number} default +- */ //// [index1.d.ts] @@ -33,22 +53,16 @@ + static y: string; } +export default Cls; -+/** -+ * @typedef {string | number} default -+ */ ++export type default = string | number; //// [index2.d.ts] +// merge type alias and class (error message improvement needed, see #32368) export default class C { } -+/** -+ * @typedef {string | number} default -+ */ ++export type default = string | number; //// [index3.d.ts] -export type _default = string | number; +// merge type alias and variable (behavior is borked, see #32366) +declare const x = 12; export { x as default }; -declare const x: 12; -+/** -+ * @typedef {string | number} default -+ */ \ No newline at end of file ++export type default = string | number; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols index ae3dec2cae..96ec67cbef 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols @@ -34,7 +34,7 @@ const x = 12; export {x as default}; >x : Symbol(x, Decl(index3.js, 1, 5)) ->default : Symbol(default, Decl(index3.js, 2, 8)) +>default : Symbol(default, Decl(index3.js, 2, 8), Decl(index3.js, 4, 3)) /** * @typedef {string | number} default diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols.diff index 4fc6eea966..60b302dec9 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsDefaultsErr.symbols.diff @@ -12,13 +12,4 @@ +>y : Symbol(y, Decl(index1.js, 2, 11)) } export default Cls; - >Cls : Symbol(Cls, Decl(index1.js, 0, 0)) -@@= skipped -28, +28 lines =@@ - - export {x as default}; - >x : Symbol(x, Decl(index3.js, 1, 5)) -->default : Symbol(default, Decl(index3.js, 2, 8), Decl(index3.js, 4, 3)) -+>default : Symbol(default, Decl(index3.js, 2, 8)) - - /** - * @typedef {string | number} default \ No newline at end of file + >Cls : Symbol(Cls, Decl(index1.js, 0, 0)) \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.errors.txt b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.errors.txt new file mode 100644 index 0000000000..0b7c06dc92 --- /dev/null +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.errors.txt @@ -0,0 +1,19 @@ +source.js(1,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== source.js (1 errors) ==== + module.exports = MyClass; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + + function MyClass() {} + MyClass.staticMethod = function() {} + MyClass.prototype.method = function() {} + MyClass.staticProperty = 123; + + /** + * Callback to be invoked when test execution is complete. + * + * @callback DoneCB + * @param {number} failures - Number of failures that occurred. + */ \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index b8f6a0ecb8..d637f33bc4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -16,44 +16,16 @@ MyClass.staticProperty = 123; */ //// [source.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); export = MyClass; module.exports = MyClass; function MyClass() { } MyClass.staticMethod = function () { }; MyClass.prototype.method = function () { }; MyClass.staticProperty = 123; -/** - * Callback to be invoked when test execution is complete. - * - * @callback DoneCB - * @param {number} failures - Number of failures that occurred. - */ //// [source.d.ts] export = MyClass; -/** - * Callback to be invoked when test execution is complete. - * - * @callback DoneCB - * @param {number} failures - Number of failures that occurred. - */ - - -//// [DtsFileErrors] - - -out/source.d.ts(1,10): error TS2304: Cannot find name 'MyClass'. - - -==== out/source.d.ts (1 errors) ==== - export = MyClass; - ~~~~~~~ -!!! error TS2304: Cannot find name 'MyClass'. - /** - * Callback to be invoked when test execution is complete. - * - * @callback DoneCB - * @param {number} failures - Number of failures that occurred. - */ - \ No newline at end of file +export type DoneCB = (failures: number) ; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index f6139cee0c..32b4e24364 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -4,11 +4,21 @@ */ //// [source.js] ++"use strict"; ++Object.defineProperty(exports, "__esModule", { value: true }); +export = MyClass; module.exports = MyClass; function MyClass() { } MyClass.staticMethod = function () { }; -@@= skipped -15, +16 lines =@@ + MyClass.prototype.method = function () { }; + MyClass.staticProperty = 123; +-/** +- * Callback to be invoked when test execution is complete. +- * +- * @callback DoneCB +- * @param {number} failures - Number of failures that occurred. +- */ + //// [source.d.ts] export = MyClass; @@ -21,30 +31,8 @@ -} -declare function staticMethod(): void; -declare var staticProperty: number; - /** - * Callback to be invoked when test execution is complete. +-/** +- * Callback to be invoked when test execution is complete. - */ -type DoneCB = (failures: number) => any; -+ * -+ * @callback DoneCB -+ * @param {number} failures - Number of failures that occurred. -+ */ -+ -+ -+//// [DtsFileErrors] -+ -+ -+out/source.d.ts(1,10): error TS2304: Cannot find name 'MyClass'. -+ -+ -+==== out/source.d.ts (1 errors) ==== -+ export = MyClass; -+ ~~~~~~~ -+!!! error TS2304: Cannot find name 'MyClass'. -+ /** -+ * Callback to be invoked when test execution is complete. -+ * -+ * @callback DoneCB -+ * @param {number} failures - Number of failures that occurred. -+ */ -+ \ No newline at end of file ++export type DoneCB = (failures: number) ; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js index e7534535c7..94f5f07cfe 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js @@ -54,28 +54,6 @@ class LocalThing { //// [index.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -/** - * @typedef {string | number | symbol} PropName - */ -/** - * Callback - * - * @callback NumberToStringCb - * @param {number} a - * @returns {string} - */ -/** - * @template T - * @typedef {T & {name: string}} MixinName - */ -/** - * Identity function - * - * @template T - * @callback Identity - * @param {T} x - * @returns {T} - */ //// [mixed.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); @@ -103,28 +81,12 @@ class LocalThing { //// [index.d.ts] export {}; // flag file as module -/** - * @typedef {string | number | symbol} PropName - */ -/** - * Callback - * - * @callback NumberToStringCb - * @param {number} a - * @returns {string} - */ -/** - * @template T - * @typedef {T & {name: string}} MixinName - */ -/** - * Identity function - * - * @template T - * @callback Identity - * @param {T} x - * @returns {T} - */ +export type PropName = string | number | symbol; +export type NumberToStringCb = (a: number) => string; +export type MixinName = T & { + name: string; +}; +export type Identity = (x: T) => T; //// [mixed.d.ts] export type SomeType = { x: string; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js.diff index 76e1142926..11e7931a07 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeAliases.js.diff @@ -1,15 +1,38 @@ --- old.jsDeclarationsTypeAliases.js +++ new.jsDeclarationsTypeAliases.js -@@= skipped -76, +76 lines =@@ - * @returns {T} - */ +@@= skipped -53, +53 lines =@@ + //// [index.js] + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); +-/** +- * @typedef {string | number | symbol} PropName +- */ +-/** +- * Callback +- * +- * @callback NumberToStringCb +- * @param {number} a +- * @returns {string} +- */ +-/** +- * @template T +- * @typedef {T & {name: string}} MixinName +- */ +-/** +- * Identity function +- * +- * @template T +- * @callback Identity +- * @param {T} x +- * @returns {T} +- */ //// [mixed.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); /** * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType */ -@@= skipped -11, +13 lines =@@ +@@= skipped -34, +14 lines =@@ return { x: "" + x }; } class ExportedThing { @@ -31,40 +54,22 @@ //// [index.d.ts] --export type PropName = string | number | symbol; +export {}; // flag file as module -+/** -+ * @typedef {string | number | symbol} PropName -+ */ - /** - * Callback + export type PropName = string | number | symbol; +-/** +- * Callback - */ --export type NumberToStringCb = (a: number) => string; --export type MixinName = T & { -- name: string; --}; -+ * -+ * @callback NumberToStringCb -+ * @param {number} a -+ * @returns {string} -+ */ -+/** -+ * @template T -+ * @typedef {T & {name: string}} MixinName -+ */ - /** - * Identity function -+ * -+ * @template T -+ * @callback Identity -+ * @param {T} x -+ * @returns {T} - */ --export type Identity = (x: T) => T; + export type NumberToStringCb = (a: number) => string; + export type MixinName = T & { + name: string; + }; +-/** +- * Identity function +- */ + export type Identity = (x: T) => T; //// [mixed.d.ts] export type SomeType = { - x: string; -@@= skipped -39, +46 lines =@@ +@@= skipped -39, +30 lines =@@ * @param {number} x * @returns {SomeType} */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js index 8758dc31c0..0b8647ca16 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js @@ -19,34 +19,16 @@ //// [index.js] -/** - * Options for Foo <------------ - * @typedef {Object} FooOptions - * @property {boolean} bar - Marvin K Mooney - * @property {string} baz - Sylvester McMonkey McBean - */ -/** - * Multiline - * Options - * for Foo <------------ - * @typedef {Object} BarOptions - * @property {boolean} bar - Marvin K Mooney - * @property {string} baz - Sylvester McMonkey McBean - */ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); //// [index.d.ts] -/** - * Options for Foo <------------ - * @typedef {Object} FooOptions - * @property {boolean} bar - Marvin K Mooney - * @property {string} baz - Sylvester McMonkey McBean - */ -/** - * Multiline - * Options - * for Foo <------------ - * @typedef {Object} BarOptions - * @property {boolean} bar - Marvin K Mooney - * @property {string} baz - Sylvester McMonkey McBean - */ +export type FooOptions = { + bar: boolean; + baz: string; +}; +export type BarOptions = { + bar: boolean; + baz: string; +}; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js.diff index 71c8b863ff..4b7c42f691 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefDescriptionsPreserved.js.diff @@ -1,38 +1,55 @@ --- old.jsDeclarationsTypedefDescriptionsPreserved.js +++ new.jsDeclarationsTypedefDescriptionsPreserved.js -@@= skipped -37, +37 lines =@@ +@@= skipped -18, +18 lines =@@ + + + //// [index.js] +-/** +- * Options for Foo <------------ +- * @typedef {Object} FooOptions +- * @property {boolean} bar - Marvin K Mooney +- * @property {string} baz - Sylvester McMonkey McBean +- */ +-/** +- * Multiline +- * Options +- * for Foo <------------ +- * @typedef {Object} BarOptions +- * @property {boolean} bar - Marvin K Mooney +- * @property {string} baz - Sylvester McMonkey McBean +- */ ++"use strict"; ++Object.defineProperty(exports, "__esModule", { value: true }); + + //// [index.d.ts] - /** - * Options for Foo <------------ -+ * @typedef {Object} FooOptions -+ * @property {boolean} bar - Marvin K Mooney -+ * @property {string} baz - Sylvester McMonkey McBean - */ +-/** +- * Options for Foo <------------ +- */ -type FooOptions = { - /** - * - Marvin K Mooney - */ -- bar: boolean; ++export type FooOptions = { + bar: boolean; - /** - * - Sylvester McMonkey McBean - */ -- baz: string; --}; - /** - * Multiline - * Options - * for Foo <------------ -+ * @typedef {Object} BarOptions -+ * @property {boolean} bar - Marvin K Mooney -+ * @property {string} baz - Sylvester McMonkey McBean - */ + baz: string; + }; +-/** +- * Multiline +- * Options +- * for Foo <------------ +- */ -type BarOptions = { - /** - * - Marvin K Mooney - */ -- bar: boolean; ++export type BarOptions = { + bar: boolean; - /** - * - Sylvester McMonkey McBean - */ -- baz: string; --}; \ No newline at end of file + baz: string; + }; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.errors.txt b/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.errors.txt deleted file mode 100644 index 4903c8be4b..0000000000 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -b.js(2,28): error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. -b.js(3,26): error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. - - -==== a.js (0 errors) ==== - export const kSymbol = Symbol("my-symbol"); - - /** - * @typedef {{[kSymbol]: true}} WithSymbol - */ -==== b.js (2 errors) ==== - /** - * @returns {import('./a').WithSymbol} - ~~~~~~~~~~ -!!! error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. - * @param {import('./a').WithSymbol} value - ~~~~~~~~~~ -!!! error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. - */ - export function b(value) { - return value; - } - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js index 5030d6b149..ed4545897d 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js @@ -20,9 +20,9 @@ export function b(value) { //// [a.d.ts] export declare const kSymbol: unique symbol; -/** - * @typedef {{[kSymbol]: true}} WithSymbol - */ +export type WithSymbol = { + [kSymbol]: true; +}; //// [b.d.ts] /** * @returns {import('./a').WithSymbol} diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js.diff index ef2dce4689..e8a3d224ab 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.js.diff @@ -5,15 +5,11 @@ //// [a.d.ts] -export const kSymbol: unique symbol; --export type WithSymbol = { -- [kSymbol]: true; --}; +export declare const kSymbol: unique symbol; -+/** -+ * @typedef {{[kSymbol]: true}} WithSymbol -+ */ - //// [b.d.ts] - /** + export type WithSymbol = { + [kSymbol]: true; + }; +@@= skipped -9, +9 lines =@@ * @returns {import('./a').WithSymbol} * @param {import('./a').WithSymbol} value */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.types b/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.types index f6bcf4794c..78d910083a 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.types +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsUniqueSymbolUsage.types @@ -16,10 +16,10 @@ export const kSymbol = Symbol("my-symbol"); * @param {import('./a').WithSymbol} value */ export function b(value) { ->b : (value: any) => any ->value : any +>b : (value: import("./a").WithSymbol) => import("./a").WithSymbol +>value : import("./a").WithSymbol return value; ->value : any +>value : import("./a").WithSymbol } diff --git a/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js b/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js index 696fd83743..547927b0be 100644 --- a/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js @@ -45,7 +45,6 @@ function computeCommonSourceDirectoryOfFilenames(integer) { } /** {@link https://hvad} */ var see3 = true; -/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/ //// [linkTagEmit1.d.ts] @@ -55,4 +54,4 @@ export type D1 = { m: 1; }; export type Z = number; -/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/ +export type Attempt = number; diff --git a/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js.diff b/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js.diff index 85033d0884..ae2862acc9 100644 --- a/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/linkTagEmit1.js.diff @@ -9,7 +9,11 @@ /** @typedef {number} N */ /** * @typedef {Object} D1 -@@= skipped -19, +21 lines =@@ +@@= skipped -15, +17 lines =@@ + } + /** {@link https://hvad} */ + var see3 = true; +-/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/ //// [linkTagEmit1.d.ts] @@ -45,4 +49,4 @@ - */ -type Attempt = number; +export type Z = number; -+/** @typedef {number} Attempt {@link https://wat} {@linkcode I think lingcod is better} {@linkplain or lutefisk}*/ \ No newline at end of file ++export type Attempt = number; \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/importTypeResolutionJSDocEOF.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/importTypeResolutionJSDocEOF.errors.txt.diff deleted file mode 100644 index 91273f1310..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/importTypeResolutionJSDocEOF.errors.txt.diff +++ /dev/null @@ -1,19 +0,0 @@ ---- old.importTypeResolutionJSDocEOF.errors.txt -+++ new.importTypeResolutionJSDocEOF.errors.txt -@@= skipped -0, +0 lines =@@ -- -+usage.js(1,12): error TS2304: Cannot find name 'Bar'. -+ -+ -+==== interfaces.d.ts (0 errors) ==== -+ export interface Bar { -+ prop: string -+ } -+ -+==== usage.js (1 errors) ==== -+ /** @type {Bar} */ -+ ~~~ -+!!! error TS2304: Cannot find name 'Bar'. -+ export let bar; -+ -+ /** @typedef {import('./interfaces').Bar} Bar */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/importTypeResolutionJSDocEOF.types.diff b/testdata/baselines/reference/submoduleAccepted/compiler/importTypeResolutionJSDocEOF.types.diff index 31965006ad..5f1bed320e 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/importTypeResolutionJSDocEOF.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/importTypeResolutionJSDocEOF.types.diff @@ -5,6 +5,6 @@ /** @type {Bar} */ export let bar; ->bar : import("interfaces").Bar -+>bar : Bar ++>bar : import("./interfaces").Bar /** @typedef {import('./interfaces').Bar} Bar */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocResolveNameFailureInTypedef.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/jsdocResolveNameFailureInTypedef.errors.txt.diff deleted file mode 100644 index 79a91a67d1..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocResolveNameFailureInTypedef.errors.txt.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- old.jsdocResolveNameFailureInTypedef.errors.txt -+++ new.jsdocResolveNameFailureInTypedef.errors.txt -@@= skipped -0, +0 lines =@@ --/a.js(7,14): error TS2304: Cannot find name 'CantResolveThis'. -+/a.js(2,12): error TS2304: Cannot find name 'Ty'. - - - ==== /a.js (1 errors) ==== - /** - * @param {Ty} x -+ ~~ -+!!! error TS2304: Cannot find name 'Ty'. - */ - function f(x) {} - - /** - * @typedef {CantResolveThis} Ty -- ~~~~~~~~~~~~~~~ --!!! error TS2304: Cannot find name 'CantResolveThis'. - */ - \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocResolveNameFailureInTypedef.types.diff b/testdata/baselines/reference/submoduleAccepted/compiler/jsdocResolveNameFailureInTypedef.types.diff index 62db915dfd..ff6182fe26 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/jsdocResolveNameFailureInTypedef.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/jsdocResolveNameFailureInTypedef.types.diff @@ -1,11 +1,11 @@ --- old.jsdocResolveNameFailureInTypedef.types +++ new.jsdocResolveNameFailureInTypedef.types -@@= skipped -5, +5 lines =@@ +@@= skipped -4, +4 lines =@@ + * @param {Ty} x */ function f(x) {} - >f : (x: Ty) => void -->x : CantResolveThis -+>x : Ty +->f : (x: Ty) => void ++>f : (x: CantResolveThis) => void + >x : CantResolveThis - /** - * @typedef {CantResolveThis} Ty \ No newline at end of file + /** \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt.diff deleted file mode 100644 index 01103a1613..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt.diff +++ /dev/null @@ -1,46 +0,0 @@ ---- old.reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt -+++ new.reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.errors.txt -@@= skipped -0, +0 lines =@@ --/types.js(3,21): error TS2304: Cannot find name 'Keyword'. --/types.js(3,30): error TS2304: Cannot find name 'ParamValueTyped'. -- -- --==== /contractHelper.d.ts (0 errors) ==== -+/contractHelper.d.ts(3,67): error TS2694: Namespace '"/types"' has no exported member 'ParamStateRecord'. -+/exported.d.ts(2,10): error TS2305: Module '"./types.js"' has no exported member 'ParamStateRecord'. -+ -+ -+==== /contractHelper.d.ts (1 errors) ==== - export function handleParamGovernance(zcf: any): { - publicMixin: { - getGovernedParams: () => globalThis.ERef; -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2694: Namespace '"/types"' has no exported member 'ParamStateRecord'. - }; - }; - --==== /exported.d.ts (0 errors) ==== -+==== /exported.d.ts (1 errors) ==== - type _ERef = T | Promise; - import { ParamStateRecord as _ParamStateRecord } from './types.js'; -+ ~~~~~~~~~~~~~~~~ -+!!! error TS2305: Module '"./types.js"' has no exported member 'ParamStateRecord'. - declare global { - // @ts-ignore TS2666 - export { -@@= skipped -19, +23 lines =@@ - }; - } - --==== /types.js (2 errors) ==== -+==== /types.js (0 errors) ==== - export {}; - /** - * @typedef {Record} ParamStateRecord a Record containing -- ~~~~~~~ --!!! error TS2304: Cannot find name 'Keyword'. -- ~~~~~~~~~~~~~~~ --!!! error TS2304: Cannot find name 'ParamValueTyped'. - * keyword pairs with descriptions of parameters under governance. - */ - \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/uniqueSymbolJs.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/uniqueSymbolJs.errors.txt.diff index 0e26cc67d6..e97c2ce80f 100644 --- a/testdata/baselines/reference/submoduleAccepted/compiler/uniqueSymbolJs.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/compiler/uniqueSymbolJs.errors.txt.diff @@ -3,17 +3,19 @@ @@= skipped -0, +0 lines =@@ -a.js(5,18): error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead. -a.js(5,28): error TS1005: ';' expected. -- -- --==== a.js (2 errors) ==== -- /** @type {unique symbol} */ -- const foo = Symbol(); -- -- /** @typedef {{ [foo]: boolean }} A */ -- /** @typedef {{ [key: foo] boolean }} B */ -- ~~~ ++a.js(5,18): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. ++a.js(5,23): error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'? + + + ==== a.js (2 errors) ==== +@@= skipped -8, +8 lines =@@ + /** @typedef {{ [foo]: boolean }} A */ + /** @typedef {{ [key: foo] boolean }} B */ + ~~~ -!!! error TS1337: An index signature parameter type cannot be a literal type or generic type. Consider using a mapped object type instead. - ~~~~~~~ -!!! error TS1005: ';' expected. -- -+ \ No newline at end of file ++!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type. ++ ~~~ ++!!! error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'? + \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/compiler/unmetTypeConstraintInJSDocImportCall.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/compiler/unmetTypeConstraintInJSDocImportCall.errors.txt.diff deleted file mode 100644 index c9d3ac59df..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/compiler/unmetTypeConstraintInJSDocImportCall.errors.txt.diff +++ /dev/null @@ -1,24 +0,0 @@ ---- old.unmetTypeConstraintInJSDocImportCall.errors.txt -+++ new.unmetTypeConstraintInJSDocImportCall.errors.txt -@@= skipped -0, +0 lines =@@ --file2.js(3,36): error TS2344: Type 'T' does not satisfy the constraint 'string'. -- -- --==== file1.js (0 errors) ==== -- /** -- * @template {string} T -- * @typedef {{ foo: T }} Foo -- */ -- -- export default {}; -- --==== file2.js (1 errors) ==== -- /** -- * @template T -- * @typedef {import('./file1').Foo} Bar -- ~ --!!! error TS2344: Type 'T' does not satisfy the constraint 'string'. --!!! related TS2208 file2.js:2:14: This type parameter might need an `extends string` constraint. -- */ -- -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag1.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag1.errors.txt.diff deleted file mode 100644 index 032097ac51..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag1.errors.txt.diff +++ /dev/null @@ -1,28 +0,0 @@ ---- old.callbackTag1.errors.txt -+++ new.callbackTag1.errors.txt -@@= skipped -0, +0 lines =@@ -- -+cb.js(11,12): error TS2304: Cannot find name 'NoReturn'. -+ -+ -+==== cb.js (1 errors) ==== -+ /** @callback Sid -+ * @param {string} s -+ * @returns {string} What were you expecting -+ */ -+ var x = 1 -+ -+ /** @type {Sid} smallId */ -+ var sid = s => s + "!"; -+ -+ -+ /** @type {NoReturn} */ -+ ~~~~~~~~ -+!!! error TS2304: Cannot find name 'NoReturn'. -+ var noreturn = obj => void obj.title -+ -+ /** -+ * @callback NoReturn -+ * @param {{ e: number, m: number, title: string }} s - Knee deep, shores, etc -+ */ -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag1.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag1.types.diff deleted file mode 100644 index 18401abc49..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag1.types.diff +++ /dev/null @@ -1,20 +0,0 @@ ---- old.callbackTag1.types -+++ new.callbackTag1.types -@@= skipped -21, +21 lines =@@ - /** @type {NoReturn} */ - var noreturn = obj => void obj.title - >noreturn : NoReturn -->obj => void obj.title : (obj: { e: number; m: number; title: string; }) => any -->obj : { e: number; m: number; title: string; } -+>obj => void obj.title : (obj: any) => any -+>obj : any - >void obj.title : undefined -->obj.title : string -->obj : { e: number; m: number; title: string; } -->title : string -+>obj.title : any -+>obj : any -+>title : any - - /** - * @callback NoReturn \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.errors.txt.diff index c8b92dbd79..9d44d496ef 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.errors.txt.diff @@ -2,18 +2,11 @@ +++ new.callbackTag2.errors.txt @@= skipped -0, +0 lines =@@ -cb.js(18,29): error TS2304: Cannot find name 'S'. -- -- --==== cb.js (1 errors) ==== +cb.js(19,14): error TS2339: Property 'id' does not exist on type 'SharedClass'. -+cb.js(25,12): error TS2304: Cannot find name 'Final'. -+ -+ -+==== cb.js (2 errors) ==== - /** @template T - * @callback Id - * @param {T} t -@@= skipped -19, +20 lines =@@ + + + ==== cb.js (1 errors) ==== +@@= skipped -19, +19 lines =@@ class SharedClass { constructor() { /** @type {SharedId} */ @@ -24,12 +17,4 @@ +!!! error TS2339: Property 'id' does not exist on type 'SharedClass'. } } - /** @type {SharedId} */ - var outside = n => n + 1; - - /** @type {Final<{ fantasy }, { heroes }>} */ -+ ~~~~~ -+!!! error TS2304: Cannot find name 'Final'. - var noreturn = (barts, tidus, noctis) => "cecil" - - /** \ No newline at end of file + /** @type {SharedId} */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.types.diff index c4d4ea8e20..dc6a3391be 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/callbackTag2.types.diff @@ -17,13 +17,7 @@ var noreturn = (barts, tidus, noctis) => "cecil" >noreturn : Final<{ fantasy: any; }, { heroes: any; }> ->(barts, tidus, noctis) => "cecil" : (barts: { fantasy: any; }, tidus: { heroes: any; }, noctis: { heroes: any; } & { fantasy: any; }) => "cecil" | "zidane" -->barts : { fantasy: any; } -->tidus : { heroes: any; } -->noctis : { heroes: any; } & { fantasy: any; } -+>(barts, tidus, noctis) => "cecil" : (barts: any, tidus: any, noctis: any) => string -+>barts : any -+>tidus : any -+>noctis : any - >"cecil" : "cecil" - - /** \ No newline at end of file ++>(barts, tidus, noctis) => "cecil" : (barts: { fantasy: any; }, tidus: { heroes: any; }, noctis: { heroes: any; } & { fantasy: any; }) => "cecil" + >barts : { fantasy: any; } + >tidus : { heroes: any; } + >noctis : { heroes: any; } & { fantasy: any; } \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocOnEndOfFile.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocOnEndOfFile.errors.txt.diff deleted file mode 100644 index 2d3a1daa55..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/checkJsdocOnEndOfFile.errors.txt.diff +++ /dev/null @@ -1,14 +0,0 @@ ---- old.checkJsdocOnEndOfFile.errors.txt -+++ new.checkJsdocOnEndOfFile.errors.txt -@@= skipped -0, +0 lines =@@ --eof.js(2,20): error TS2304: Cannot find name 'bad'. -- -- --==== eof.js (1 errors) ==== -- /** -- * @typedef {Array} Should have error here -- ~~~ --!!! error TS2304: Cannot find name 'bad'. -- */ -- -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/importTag13.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/importTag13.errors.txt.diff index 1a4e14121d..a55a49f933 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/importTag13.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/importTag13.errors.txt.diff @@ -2,16 +2,15 @@ +++ new.importTag13.errors.txt @@= skipped -0, +0 lines =@@ -/foo.js(1,15): error TS1005: 'from' expected. -- -- --==== /foo.js (1 errors) ==== -- /** @import x = require("types") */ ++/foo.js(1,15): error TS1141: String literal expected. + + + ==== /foo.js (1 errors) ==== + /** @import x = require("types") */ - ~ -!!! error TS1005: 'from' expected. -- --==== /types.ts (0 errors) ==== -- export interface Foo { -- a: number; -- } -- -+ \ No newline at end of file ++ ~~~~~~~~~~~~~~~~~~ ++!!! error TS1141: String literal expected. + + ==== /types.ts (0 errors) ==== + export interface Foo { \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/importTag14.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/importTag14.errors.txt.diff index 565a9e30df..689b431d29 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/importTag14.errors.txt.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/importTag14.errors.txt.diff @@ -1,18 +1,20 @@ --- old.importTag14.errors.txt +++ new.importTag14.errors.txt @@= skipped -0, +0 lines =@@ --/foo.js(1,33): error TS1464: Type import attributes should have exactly one key - 'resolution-mode' - with value 'import' or 'require'. --/foo.js(1,33): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. ++/foo.js(1,25): error TS2306: File '/foo.js' is not a module. + /foo.js(1,33): error TS1464: Type import attributes should have exactly one key - 'resolution-mode' - with value 'import' or 'require'. + /foo.js(1,33): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. -/foo.js(1,38): error TS1005: '{' expected. -- -- --==== /foo.js (3 errors) ==== -- /** @import * as f from "./foo" with */ -- ~~~~ --!!! error TS1464: Type import attributes should have exactly one key - 'resolution-mode' - with value 'import' or 'require'. -- ~~~~ --!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. + + + ==== /foo.js (3 errors) ==== + /** @import * as f from "./foo" with */ ++ ~~~~~~~ ++!!! error TS2306: File '/foo.js' is not a module. + ~~~~ + !!! error TS1464: Type import attributes should have exactly one key - 'resolution-mode' - with value 'import' or 'require'. + ~~~~ + !!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'nodenext', or 'preserve'. - -!!! error TS1005: '{' expected. -- -+ \ No newline at end of file + \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsClassImplementsGenericsSerialization.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsClassImplementsGenericsSerialization.errors.txt.diff deleted file mode 100644 index 2198dd5e69..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsClassImplementsGenericsSerialization.errors.txt.diff +++ /dev/null @@ -1,33 +0,0 @@ ---- old.jsDeclarationsClassImplementsGenericsSerialization.errors.txt -+++ new.jsDeclarationsClassImplementsGenericsSerialization.errors.txt -@@= skipped -0, +0 lines =@@ -- -+lib.js(3,17): error TS2552: Cannot find name 'IEncoder'. Did you mean 'Encoder'? -+ -+ -+==== interface.ts (0 errors) ==== -+ export interface Encoder { -+ encode(value: T): Uint8Array -+ } -+==== lib.js (1 errors) ==== -+ /** -+ * @template T -+ * @implements {IEncoder} -+ ~~~~~~~~ -+!!! error TS2552: Cannot find name 'IEncoder'. Did you mean 'Encoder'? -+!!! related TS2728 lib.js:5:14: 'Encoder' is declared here. -+ */ -+ export class Encoder { -+ /** -+ * @param {T} value -+ */ -+ encode(value) { -+ return new Uint8Array(0) -+ } -+ } -+ -+ -+ /** -+ * @template T -+ * @typedef {import('./interface').Encoder} IEncoder -+ */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsDefaultsErr.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsDefaultsErr.errors.txt.diff deleted file mode 100644 index fc767b347d..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsDefaultsErr.errors.txt.diff +++ /dev/null @@ -1,38 +0,0 @@ ---- old.jsDeclarationsDefaultsErr.errors.txt -+++ new.jsDeclarationsDefaultsErr.errors.txt -@@= skipped -0, +0 lines =@@ --index2.js(2,22): error TS2300: Duplicate identifier 'C'. --index2.js(4,31): error TS2300: Duplicate identifier 'default'. -- -- --==== index1.js (0 errors) ==== -- // merge type alias and alias (should error, see #32367) -- class Cls { -- x = 12; -- static y = "ok" -- } -- export default Cls; -- /** -- * @typedef {string | number} default -- */ -- --==== index2.js (2 errors) ==== -- // merge type alias and class (error message improvement needed, see #32368) -- export default class C {}; -- ~ --!!! error TS2300: Duplicate identifier 'C'. -- /** -- * @typedef {string | number} default -- ~~~~~~~ --!!! error TS2300: Duplicate identifier 'default'. -- */ -- --==== index3.js (0 errors) ==== -- // merge type alias and variable (behavior is borked, see #32366) -- const x = 12; -- export {x as default}; -- /** -- * @typedef {string | number} default -- */ -- -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsFunctionPrototypeStatic.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsFunctionPrototypeStatic.errors.txt.diff new file mode 100644 index 0000000000..bf29d0665d --- /dev/null +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsFunctionPrototypeStatic.errors.txt.diff @@ -0,0 +1,23 @@ +--- old.jsDeclarationsFunctionPrototypeStatic.errors.txt ++++ new.jsDeclarationsFunctionPrototypeStatic.errors.txt +@@= skipped -0, +0 lines =@@ +- ++source.js(1,1): error TS2309: An export assignment cannot be used in a module with other exported elements. ++ ++ ++==== source.js (1 errors) ==== ++ module.exports = MyClass; ++ ~~~~~~~~~~~~~~~~~~~~~~~~ ++!!! error TS2309: An export assignment cannot be used in a module with other exported elements. ++ ++ function MyClass() {} ++ MyClass.staticMethod = function() {} ++ MyClass.prototype.method = function() {} ++ MyClass.staticProperty = 123; ++ ++ /** ++ * Callback to be invoked when test execution is complete. ++ * ++ * @callback DoneCB ++ * @param {number} failures - Number of failures that occurred. ++ */ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsUniqueSymbolUsage.errors.txt.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsUniqueSymbolUsage.errors.txt.diff deleted file mode 100644 index f5560698f9..0000000000 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsUniqueSymbolUsage.errors.txt.diff +++ /dev/null @@ -1,27 +0,0 @@ ---- old.jsDeclarationsUniqueSymbolUsage.errors.txt -+++ new.jsDeclarationsUniqueSymbolUsage.errors.txt -@@= skipped -0, +0 lines =@@ -- -+b.js(2,28): error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. -+b.js(3,26): error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. -+ -+ -+==== a.js (0 errors) ==== -+ export const kSymbol = Symbol("my-symbol"); -+ -+ /** -+ * @typedef {{[kSymbol]: true}} WithSymbol -+ */ -+==== b.js (2 errors) ==== -+ /** -+ * @returns {import('./a').WithSymbol} -+ ~~~~~~~~~~ -+!!! error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. -+ * @param {import('./a').WithSymbol} value -+ ~~~~~~~~~~ -+!!! error TS2694: Namespace '"a"' has no exported member 'WithSymbol'. -+ */ -+ export function b(value) { -+ return value; -+ } -+ \ No newline at end of file diff --git a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsUniqueSymbolUsage.types.diff b/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsUniqueSymbolUsage.types.diff index 083003e697..af3617182f 100644 --- a/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsUniqueSymbolUsage.types.diff +++ b/testdata/baselines/reference/submoduleAccepted/conformance/jsDeclarationsUniqueSymbolUsage.types.diff @@ -1,15 +1,13 @@ --- old.jsDeclarationsUniqueSymbolUsage.types +++ new.jsDeclarationsUniqueSymbolUsage.types -@@= skipped -15, +15 lines =@@ - * @param {import('./a').WithSymbol} value +@@= skipped -16, +16 lines =@@ */ export function b(value) { -->b : (value: import("./a").WithSymbol) => import("./a").WithSymbol + >b : (value: import("./a").WithSymbol) => import("./a").WithSymbol ->value : import("a").WithSymbol -+>b : (value: any) => any -+>value : any ++>value : import("./a").WithSymbol return value; ->value : import("a").WithSymbol -+>value : any ++>value : import("./a").WithSymbol } diff --git a/testdata/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault2.ts b/testdata/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault2.ts new file mode 100644 index 0000000000..1707cdf0c2 --- /dev/null +++ b/testdata/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault2.ts @@ -0,0 +1,14 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true + +// @filename: index1.js + +export const _default = class {}; + +export default 12; +/** + * @typedef {string | number} default + */