From 0e478d7a911582ad7f3624a5eee50cac2ab8edc1 Mon Sep 17 00:00:00 2001 From: bun-unsafe Date: Tue, 25 Aug 2026 22:10:44 +0800 Subject: [PATCH] Fix JSDoc @enum so the tagged name is a type as well as a value @enum was parsed as an unknown tag, so names like E were value-only. That made @param {E} and .d.ts consumers report TS2749. Parse the tag, reparse a type alias from the host name, and parse JSDoc function(...) types so @enum {function(number): number} emits a valid signature. --- tools/scripts/tsc/ast.json | 24 ++++++- tsc/internal/api/encoder/decoder_generated.go | 6 ++ tsc/internal/api/encoder/encoder_generated.go | 3 + tsc/internal/ast/ast.go | 7 ++ tsc/internal/ast/ast_generated.go | 47 +++++++++++++ tsc/internal/ast/kind_generated.go | 7 +- tsc/internal/ast/kind_stringer_generated.go | 21 +++--- tsc/internal/ast/utilities.go | 2 +- tsc/internal/checker/checker.go | 2 +- tsc/internal/checker/emitresolver.go | 2 +- tsc/internal/parser/jsdoc.go | 56 +++++++++++++++ tsc/internal/parser/parser.go | 5 ++ tsc/internal/parser/reparser.go | 70 +++++++++++++++++++ .../jsFileESModuleWithEnumTag.symbols | 14 ++-- .../reference/conformance/enumTag.errors.txt | 68 ------------------ .../reference/conformance/enumTag.symbols | 16 ++--- .../reference/conformance/enumTag.types | 16 ++--- .../enumTagCircularReference.errors.txt | 9 +++ .../enumTagCircularReference.symbols | 2 +- .../conformance/enumTagImported.errors.txt | 31 -------- .../conformance/enumTagImported.symbols | 2 +- .../conformance/enumTagImported.types | 6 +- .../conformance/enumTagOnExports.symbols | 8 +-- .../enumTagUseBeforeDefCrash.errors.txt | 16 ----- .../enumTagUseBeforeDefCrash.symbols | 2 +- .../enumTagUseBeforeDefCrash.types | 2 +- ...larationsEnumTag(target=es2015).errors.txt | 63 ----------------- .../jsDeclarationsEnumTag(target=es2015).js | 3 + ...DeclarationsEnumTag(target=es2015).symbols | 12 ++-- ...jsDeclarationsEnumTag(target=es2015).types | 12 ++-- .../conformance/typedefTagWrapping.errors.txt | 46 +----------- .../conformance/typedefTagWrapping.types | 6 +- .../smartSelection_JSDocTags9.baseline | 2 +- 33 files changed, 299 insertions(+), 289 deletions(-) delete mode 100644 tsc/testdata/baselines/reference/conformance/enumTag.errors.txt create mode 100644 tsc/testdata/baselines/reference/conformance/enumTagCircularReference.errors.txt delete mode 100644 tsc/testdata/baselines/reference/conformance/enumTagImported.errors.txt delete mode 100644 tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.errors.txt delete mode 100644 tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).errors.txt diff --git a/tools/scripts/tsc/ast.json b/tools/scripts/tsc/ast.json index 3c85511b463db..ea585efea25c6 100644 --- a/tools/scripts/tsc/ast.json +++ b/tools/scripts/tsc/ast.json @@ -430,6 +430,7 @@ "JSDocThrowsTag", "JSDocSatisfiesTag", "JSDocImportTag", + "JSDocEnumTag", { "comment": "Synthesized list" }, @@ -554,7 +555,7 @@ }, { "name": "LastJSDocNode", - "value": "JSDocImportTag" + "value": "JSDocEnumTag" }, { "name": "FirstJSDocTagNode", @@ -562,7 +563,7 @@ }, { "name": "LastJSDocTagNode", - "value": "JSDocImportTag" + "value": "JSDocEnumTag" }, { "name": "FirstContextualKeyword", @@ -4726,6 +4727,25 @@ } ] }, + "JSDocEnumTag": { + "extends": [ + "JSDocTagBase" + ], + "members": [ + { + "name": "TagName", + "inherited": true + }, + { + "name": "TypeExpression", + "type": "TypeNode" + }, + { + "name": "Comment", + "inherited": true + } + ] + }, "JSDocSignature": { "extends": [ "JSDocTypeBase", diff --git a/tsc/internal/api/encoder/decoder_generated.go b/tsc/internal/api/encoder/decoder_generated.go index 6532a5a36ee05..e37ac6a2762ef 100644 --- a/tsc/internal/api/encoder/decoder_generated.go +++ b/tsc/internal/api/encoder/decoder_generated.go @@ -1026,6 +1026,12 @@ func (d *astDecoder) createChildrenNode(kind ast.Kind, data uint32, childIndices attributes := d.nodeAt(it.nextIf(mask, 3)) comment := d.nodeListAt(it.nextIf(mask, 4)) return d.factory.NewJSDocImportTag(tagName, importClause, moduleSpecifier, attributes, comment), nil + case ast.KindJSDocEnumTag: + it := newChildIter(childIndices) + tagName := d.nodeAt(it.nextIf(mask, 0)) + typeExpression := d.nodeAt(it.nextIf(mask, 1)) + comment := d.nodeListAt(it.nextIf(mask, 2)) + return d.factory.NewJSDocEnumTag(tagName, typeExpression, comment), nil case ast.KindJSDocCallbackTag: it := newChildIter(childIndices) tagName := d.nodeAt(it.nextIf(mask, 0)) diff --git a/tsc/internal/api/encoder/encoder_generated.go b/tsc/internal/api/encoder/encoder_generated.go index d3e7599e326c7..3ef9dcc0932b4 100644 --- a/tsc/internal/api/encoder/encoder_generated.go +++ b/tsc/internal/api/encoder/encoder_generated.go @@ -479,6 +479,9 @@ func getChildrenPropertyMask(node *ast.Node) uint8 { case ast.KindJSDocImportTag: n := node.AsJSDocImportTag() return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.ImportClause != nil) << 1) | (boolToByte(n.ModuleSpecifier != nil) << 2) | (boolToByte(n.Attributes != nil) << 3) | (boolToByte(n.Comment != nil) << 4) + case ast.KindJSDocEnumTag: + n := node.AsJSDocEnumTag() + return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.TypeExpression != nil) << 1) | (boolToByte(n.Comment != nil) << 2) case ast.KindJSDocCallbackTag: n := node.AsJSDocCallbackTag() return (boolToByte(n.TagName != nil) << 0) | (boolToByte(n.TypeExpression != nil) << 1) | (boolToByte(n.Name() != nil) << 2) | (boolToByte(n.Comment != nil) << 3) diff --git a/tsc/internal/ast/ast.go b/tsc/internal/ast/ast.go index 07b0fdc62c644..d2d4f05b884d2 100644 --- a/tsc/internal/ast/ast.go +++ b/tsc/internal/ast/ast.go @@ -851,6 +851,8 @@ func (n *Node) TagName() *Node { return n.AsJSDocThrowsTag().TagName case KindJSDocImportTag: return n.AsJSDocImportTag().TagName + case KindJSDocEnumTag: + return n.AsJSDocEnumTag().TagName } panic("Unhandled case in Node.TagName: " + n.Kind.String()) } @@ -938,6 +940,8 @@ func (n *Node) CommentList() *NodeList { return n.AsJSDocThrowsTag().Comment case KindJSDocImportTag: return n.AsJSDocImportTag().Comment + case KindJSDocEnumTag: + return n.AsJSDocEnumTag().Comment } panic("Unhandled case in Node.CommentList: " + n.Kind.String()) } @@ -1136,6 +1140,8 @@ func (n *Node) TypeExpression() *Node { return n.AsJSDocSatisfiesTag().TypeExpression case KindJSDocThrowsTag: return n.AsJSDocThrowsTag().TypeExpression + case KindJSDocEnumTag: + return n.AsJSDocEnumTag().TypeExpression } panic("Unhandled case in Node.TypeExpression: " + n.Kind.String()) } @@ -1345,6 +1351,7 @@ func declarationIsWriteAccess(decl *Node) bool { KindInterfaceDeclaration, KindJSDocCallbackTag, KindJSDocTypedefTag, + KindJSDocEnumTag, KindJsxAttribute, KindModuleDeclaration, KindNamespaceExportDeclaration, diff --git a/tsc/internal/ast/ast_generated.go b/tsc/internal/ast/ast_generated.go index 87c1e59f8653e..c90a1810eafec 100644 --- a/tsc/internal/ast/ast_generated.go +++ b/tsc/internal/ast/ast_generated.go @@ -421,6 +421,7 @@ type ( JSDocThrowsTagNode = Node JSDocThisTagNode = Node JSDocImportTagNode = Node + JSDocEnumTagNode = Node JSDocCallbackTagNode = Node JSDocOverloadTagNode = Node JSDocTypedefTagNode = Node @@ -7797,6 +7798,46 @@ func IsJSDocImportTag(node *Node) bool { return node.Kind == KindJSDocImportTag } +// ────────────────────────────────────────────────────────────────────── +// JSDocEnumTag +// ────────────────────────────────────────────────────────────────────── + +type JSDocEnumTag struct { + JSDocTagBase + TypeExpression *TypeNode +} + +func (f *NodeFactory) NewJSDocEnumTag(tagName *IdentifierNode, typeExpression *TypeNode, comment *NodeList) *Node { + data := &JSDocEnumTag{} + data.TagName = tagName + data.TypeExpression = typeExpression + data.Comment = comment + return f.newNode(KindJSDocEnumTag, data) +} + +func (f *NodeFactory) UpdateJSDocEnumTag(node *JSDocEnumTag, tagName *IdentifierNode, typeExpression *TypeNode, comment *NodeList) *Node { + if tagName != node.TagName || typeExpression != node.TypeExpression || comment != node.Comment { + return updateNode(f.NewJSDocEnumTag(tagName, typeExpression, comment), node.AsNode(), f.hooks) + } + return node.AsNode() +} + +func (node *JSDocEnumTag) ForEachChild(v Visitor) bool { + return visit(v, node.TagName) || visit(v, node.TypeExpression) || visitNodeList(v, node.Comment) +} + +func (node *JSDocEnumTag) VisitEachChild(v *NodeVisitor) *Node { + return v.Factory.UpdateJSDocEnumTag(node, v.visitNode(node.TagName), v.visitNode(node.TypeExpression), v.visitNodes(node.Comment)) +} + +func (node *JSDocEnumTag) Clone(f NodeFactoryCoercible) *Node { + return cloneNode(f.AsNodeFactory().NewJSDocEnumTag(node.TagName, node.TypeExpression, node.Comment), node.AsNode(), f.AsNodeFactory().hooks) +} + +func IsJSDocEnumTag(node *Node) bool { + return node.Kind == KindJSDocEnumTag +} + // ────────────────────────────────────────────────────────────────────── // JSDocCallbackTag // ────────────────────────────────────────────────────────────────────── @@ -8981,6 +9022,8 @@ func (n *Node) ForEachChild(v Visitor) bool { return n.data.(*JSDocThisTag).ForEachChild(v) case KindJSDocImportTag: return n.data.(*JSDocImportTag).ForEachChild(v) + case KindJSDocEnumTag: + return n.data.(*JSDocEnumTag).ForEachChild(v) case KindJSDocCallbackTag: return n.data.(*JSDocCallbackTag).ForEachChild(v) case KindJSDocOverloadTag: @@ -9716,6 +9759,10 @@ func (n *Node) AsJSDocImportTag() *JSDocImportTag { return n.data.(*JSDocImportTag) } +func (n *Node) AsJSDocEnumTag() *JSDocEnumTag { + return n.data.(*JSDocEnumTag) +} + func (n *Node) AsJSDocCallbackTag() *JSDocCallbackTag { return n.data.(*JSDocCallbackTag) } diff --git a/tsc/internal/ast/kind_generated.go b/tsc/internal/ast/kind_generated.go index 8c67e7947572f..f5590b437e89a 100644 --- a/tsc/internal/ast/kind_generated.go +++ b/tsc/internal/ast/kind_generated.go @@ -378,6 +378,7 @@ const ( KindJSDocThrowsTag KindJSDocSatisfiesTag KindJSDocImportTag + KindJSDocEnumTag // Synthesized list KindSyntaxList // Reparsed JS nodes @@ -415,9 +416,9 @@ const ( KindLastStatement = KindDebuggerStatement KindFirstNode = KindQualifiedName KindFirstJSDocNode = KindJSDocTypeExpression - KindLastJSDocNode = KindJSDocImportTag + KindLastJSDocNode = KindJSDocEnumTag KindFirstJSDocTagNode = KindJSDocUnknownTag - KindLastJSDocTagNode = KindJSDocImportTag + KindLastJSDocTagNode = KindJSDocEnumTag KindFirstContextualKeyword = KindAbstractKeyword KindLastContextualKeyword = KindDeferKeyword KindLastUnaryOperator = KindTildeToken @@ -436,7 +437,7 @@ type ( KeywordExpressionSyntaxKind = Kind // KindNullKeyword | KindTrueKeyword | KindFalseKeyword | KindThisKeyword | KindSuperKeyword | KindImportKeyword TokenSyntaxKind = Kind // KindUnknown | KindEndOfFile | KindSingleLineCommentTrivia | KindMultiLineCommentTrivia | KindNewLineTrivia | KindWhitespaceTrivia | KindConflictMarkerTrivia | KindNonTextFileMarkerTrivia | KindNumericLiteral | KindBigIntLiteral | KindStringLiteral | KindJsxText | KindJsxTextAllWhiteSpaces | KindRegularExpressionLiteral | KindNoSubstitutionTemplateLiteral | KindTemplateHead | KindTemplateMiddle | KindTemplateTail | KindOpenBraceToken | KindCloseBraceToken | KindOpenParenToken | KindCloseParenToken | KindOpenBracketToken | KindCloseBracketToken | KindDotToken | KindDotDotDotToken | KindSemicolonToken | KindCommaToken | KindQuestionDotToken | KindLessThanToken | KindLessThanSlashToken | KindGreaterThanToken | KindLessThanEqualsToken | KindGreaterThanEqualsToken | KindEqualsEqualsToken | KindExclamationEqualsToken | KindEqualsEqualsEqualsToken | KindExclamationEqualsEqualsToken | KindEqualsGreaterThanToken | KindPlusToken | KindMinusToken | KindAsteriskToken | KindAsteriskAsteriskToken | KindSlashToken | KindPercentToken | KindPlusPlusToken | KindMinusMinusToken | KindLessThanLessThanToken | KindGreaterThanGreaterThanToken | KindGreaterThanGreaterThanGreaterThanToken | KindAmpersandToken | KindBarToken | KindCaretToken | KindExclamationToken | KindTildeToken | KindAmpersandAmpersandToken | KindBarBarToken | KindQuestionToken | KindColonToken | KindAtToken | KindQuestionQuestionToken | KindBacktickToken | KindHashToken | KindEqualsToken | KindPlusEqualsToken | KindMinusEqualsToken | KindAsteriskEqualsToken | KindAsteriskAsteriskEqualsToken | KindSlashEqualsToken | KindPercentEqualsToken | KindLessThanLessThanEqualsToken | KindGreaterThanGreaterThanEqualsToken | KindGreaterThanGreaterThanGreaterThanEqualsToken | KindAmpersandEqualsToken | KindBarEqualsToken | KindBarBarEqualsToken | KindAmpersandAmpersandEqualsToken | KindQuestionQuestionEqualsToken | KindCaretEqualsToken | KindIdentifier | KindPrivateIdentifier | KindJSDocCommentTextToken | KindBreakKeyword | KindCaseKeyword | KindCatchKeyword | KindClassKeyword | KindConstKeyword | KindContinueKeyword | KindDebuggerKeyword | KindDefaultKeyword | KindDeleteKeyword | KindDoKeyword | KindElseKeyword | KindEnumKeyword | KindExportKeyword | KindExtendsKeyword | KindFalseKeyword | KindFinallyKeyword | KindForKeyword | KindFunctionKeyword | KindIfKeyword | KindImportKeyword | KindInKeyword | KindInstanceOfKeyword | KindNewKeyword | KindNullKeyword | KindReturnKeyword | KindSuperKeyword | KindSwitchKeyword | KindThisKeyword | KindThrowKeyword | KindTrueKeyword | KindTryKeyword | KindTypeOfKeyword | KindVarKeyword | KindVoidKeyword | KindWhileKeyword | KindWithKeyword | KindImplementsKeyword | KindInterfaceKeyword | KindLetKeyword | KindPackageKeyword | KindPrivateKeyword | KindProtectedKeyword | KindPublicKeyword | KindStaticKeyword | KindYieldKeyword | KindAbstractKeyword | KindAccessorKeyword | KindAsKeyword | KindAssertsKeyword | KindAssertKeyword | KindAnyKeyword | KindAsyncKeyword | KindAwaitKeyword | KindBooleanKeyword | KindConstructorKeyword | KindDeclareKeyword | KindGetKeyword | KindImmediateKeyword | KindInferKeyword | KindIntrinsicKeyword | KindIsKeyword | KindKeyOfKeyword | KindModuleKeyword | KindNamespaceKeyword | KindNeverKeyword | KindOutKeyword | KindReadonlyKeyword | KindRequireKeyword | KindNumberKeyword | KindObjectKeyword | KindSatisfiesKeyword | KindSetKeyword | KindStringKeyword | KindSymbolKeyword | KindTypeKeyword | KindUndefinedKeyword | KindUniqueKeyword | KindUnknownKeyword | KindUsingKeyword | KindFromKeyword | KindGlobalKeyword | KindBigIntKeyword | KindOverrideKeyword | KindOfKeyword | KindDeferKeyword JsxTokenSyntaxKind = Kind // KindLessThanSlashToken | KindEndOfFile | KindConflictMarkerTrivia | KindJsxText | KindJsxTextAllWhiteSpaces | KindOpenBraceToken | KindLessThanToken - JSDocNodeSyntaxKind = Kind // KindJSDocTypeExpression | KindJSDocNameReference | KindJSDocAllType | KindJSDocNullableType | KindJSDocNonNullableType | KindJSDocOptionalType | KindJSDocVariadicType | KindJSDoc | KindJSDocText | KindJSDocTypeLiteral | KindJSDocSignature | KindJSDocLink | KindJSDocLinkCode | KindJSDocLinkPlain | KindJSDocUnknownTag | KindJSDocAugmentsTag | KindJSDocImplementsTag | KindJSDocDeprecatedTag | KindJSDocPublicTag | KindJSDocPrivateTag | KindJSDocProtectedTag | KindJSDocReadonlyTag | KindJSDocOverrideTag | KindJSDocCallbackTag | KindJSDocOverloadTag | KindJSDocParameterTag | KindJSDocReturnTag | KindJSDocThisTag | KindJSDocTypeTag | KindJSDocTemplateTag | KindJSDocTypedefTag | KindJSDocSeeTag | KindJSDocPropertyTag | KindJSDocThrowsTag | KindJSDocSatisfiesTag | KindJSDocImportTag + JSDocNodeSyntaxKind = Kind // KindJSDocTypeExpression | KindJSDocNameReference | KindJSDocAllType | KindJSDocNullableType | KindJSDocNonNullableType | KindJSDocOptionalType | KindJSDocVariadicType | KindJSDoc | KindJSDocText | KindJSDocTypeLiteral | KindJSDocSignature | KindJSDocLink | KindJSDocLinkCode | KindJSDocLinkPlain | KindJSDocUnknownTag | KindJSDocAugmentsTag | KindJSDocImplementsTag | KindJSDocDeprecatedTag | KindJSDocPublicTag | KindJSDocPrivateTag | KindJSDocProtectedTag | KindJSDocReadonlyTag | KindJSDocOverrideTag | KindJSDocCallbackTag | KindJSDocOverloadTag | KindJSDocParameterTag | KindJSDocReturnTag | KindJSDocThisTag | KindJSDocTypeTag | KindJSDocTemplateTag | KindJSDocTypedefTag | KindJSDocSeeTag | KindJSDocPropertyTag | KindJSDocThrowsTag | KindJSDocSatisfiesTag | KindJSDocImportTag | KindJSDocEnumTag ImportPhaseModifierSyntaxKind = Kind // KindTypeKeyword | KindDeferKeyword PostfixUnaryOperator = Kind // KindPlusPlusToken | KindMinusMinusToken PrefixUnaryOperator = Kind // KindPlusToken | KindMinusToken | KindTildeToken | KindExclamationToken | KindPlusPlusToken | KindMinusMinusToken diff --git a/tsc/internal/ast/kind_stringer_generated.go b/tsc/internal/ast/kind_stringer_generated.go index b80f1ba531982..265a3febc6eec 100644 --- a/tsc/internal/ast/kind_stringer_generated.go +++ b/tsc/internal/ast/kind_stringer_generated.go @@ -352,19 +352,20 @@ func _() { _ = x[KindJSDocThrowsTag-341] _ = x[KindJSDocSatisfiesTag-342] _ = x[KindJSDocImportTag-343] - _ = x[KindSyntaxList-344] - _ = x[KindJSTypeAliasDeclaration-345] - _ = x[KindJSImportDeclaration-346] - _ = x[KindNotEmittedStatement-347] - _ = x[KindPartiallyEmittedExpression-348] - _ = x[KindSyntheticReferenceExpression-349] - _ = x[KindNotEmittedTypeElement-350] - _ = x[KindCount-351] + _ = x[KindJSDocEnumTag-344] + _ = x[KindSyntaxList-345] + _ = x[KindJSTypeAliasDeclaration-346] + _ = x[KindJSImportDeclaration-347] + _ = x[KindNotEmittedStatement-348] + _ = x[KindPartiallyEmittedExpression-349] + _ = x[KindSyntheticReferenceExpression-350] + _ = x[KindNotEmittedTypeElement-351] + _ = x[KindCount-352] } -const _Kind_name = "KindUnknownKindEndOfFileKindSingleLineCommentTriviaKindMultiLineCommentTriviaKindNewLineTriviaKindWhitespaceTriviaKindConflictMarkerTriviaKindNonTextFileMarkerTriviaKindNumericLiteralKindBigIntLiteralKindStringLiteralKindJsxTextKindJsxTextAllWhiteSpacesKindRegularExpressionLiteralKindNoSubstitutionTemplateLiteralKindTemplateHeadKindTemplateMiddleKindTemplateTailKindOpenBraceTokenKindCloseBraceTokenKindOpenParenTokenKindCloseParenTokenKindOpenBracketTokenKindCloseBracketTokenKindDotTokenKindDotDotDotTokenKindSemicolonTokenKindCommaTokenKindQuestionDotTokenKindLessThanTokenKindLessThanSlashTokenKindGreaterThanTokenKindLessThanEqualsTokenKindGreaterThanEqualsTokenKindEqualsEqualsTokenKindExclamationEqualsTokenKindEqualsEqualsEqualsTokenKindExclamationEqualsEqualsTokenKindEqualsGreaterThanTokenKindPlusTokenKindMinusTokenKindAsteriskTokenKindAsteriskAsteriskTokenKindSlashTokenKindPercentTokenKindPlusPlusTokenKindMinusMinusTokenKindLessThanLessThanTokenKindGreaterThanGreaterThanTokenKindGreaterThanGreaterThanGreaterThanTokenKindAmpersandTokenKindBarTokenKindCaretTokenKindExclamationTokenKindTildeTokenKindAmpersandAmpersandTokenKindBarBarTokenKindQuestionTokenKindColonTokenKindAtTokenKindQuestionQuestionTokenKindBacktickTokenKindHashTokenKindEqualsTokenKindPlusEqualsTokenKindMinusEqualsTokenKindAsteriskEqualsTokenKindAsteriskAsteriskEqualsTokenKindSlashEqualsTokenKindPercentEqualsTokenKindLessThanLessThanEqualsTokenKindGreaterThanGreaterThanEqualsTokenKindGreaterThanGreaterThanGreaterThanEqualsTokenKindAmpersandEqualsTokenKindBarEqualsTokenKindBarBarEqualsTokenKindAmpersandAmpersandEqualsTokenKindQuestionQuestionEqualsTokenKindCaretEqualsTokenKindIdentifierKindPrivateIdentifierKindJSDocCommentTextTokenKindBreakKeywordKindCaseKeywordKindCatchKeywordKindClassKeywordKindConstKeywordKindContinueKeywordKindDebuggerKeywordKindDefaultKeywordKindDeleteKeywordKindDoKeywordKindElseKeywordKindEnumKeywordKindExportKeywordKindExtendsKeywordKindFalseKeywordKindFinallyKeywordKindForKeywordKindFunctionKeywordKindIfKeywordKindImportKeywordKindInKeywordKindInstanceOfKeywordKindNewKeywordKindNullKeywordKindReturnKeywordKindSuperKeywordKindSwitchKeywordKindThisKeywordKindThrowKeywordKindTrueKeywordKindTryKeywordKindTypeOfKeywordKindVarKeywordKindVoidKeywordKindWhileKeywordKindWithKeywordKindImplementsKeywordKindInterfaceKeywordKindLetKeywordKindPackageKeywordKindPrivateKeywordKindProtectedKeywordKindPublicKeywordKindStaticKeywordKindYieldKeywordKindAbstractKeywordKindAccessorKeywordKindAsKeywordKindAssertsKeywordKindAssertKeywordKindAnyKeywordKindAsyncKeywordKindAwaitKeywordKindBooleanKeywordKindConstructorKeywordKindDeclareKeywordKindGetKeywordKindImmediateKeywordKindInferKeywordKindIntrinsicKeywordKindIsKeywordKindKeyOfKeywordKindModuleKeywordKindNamespaceKeywordKindNeverKeywordKindOutKeywordKindReadonlyKeywordKindRequireKeywordKindNumberKeywordKindObjectKeywordKindSatisfiesKeywordKindSetKeywordKindStringKeywordKindSymbolKeywordKindTypeKeywordKindUndefinedKeywordKindUniqueKeywordKindUnknownKeywordKindUsingKeywordKindFromKeywordKindGlobalKeywordKindBigIntKeywordKindOverrideKeywordKindOfKeywordKindDeferKeywordKindQualifiedNameKindComputedPropertyNameKindTypeParameterKindParameterKindDecoratorKindPropertySignatureKindPropertyDeclarationKindMethodSignatureKindMethodDeclarationKindClassStaticBlockDeclarationKindConstructorKindGetAccessorKindSetAccessorKindCallSignatureKindConstructSignatureKindIndexSignatureKindTypePredicateKindTypeReferenceKindFunctionTypeKindConstructorTypeKindTypeQueryKindTypeLiteralKindArrayTypeKindTupleTypeKindOptionalTypeKindRestTypeKindUnionTypeKindIntersectionTypeKindConditionalTypeKindInferTypeKindParenthesizedTypeKindThisTypeKindTypeOperatorKindIndexedAccessTypeKindMappedTypeKindLiteralTypeKindNamedTupleMemberKindTemplateLiteralTypeKindTemplateLiteralTypeSpanKindImportTypeKindObjectBindingPatternKindArrayBindingPatternKindBindingElementKindArrayLiteralExpressionKindObjectLiteralExpressionKindPropertyAccessExpressionKindElementAccessExpressionKindCallExpressionKindNewExpressionKindTaggedTemplateExpressionKindTypeAssertionExpressionKindParenthesizedExpressionKindFunctionExpressionKindArrowFunctionKindDeleteExpressionKindTypeOfExpressionKindVoidExpressionKindAwaitExpressionKindPrefixUnaryExpressionKindPostfixUnaryExpressionKindBinaryExpressionKindConditionalExpressionKindTemplateExpressionKindYieldExpressionKindSpreadElementKindClassExpressionKindOmittedExpressionKindExpressionWithTypeArgumentsKindAsExpressionKindNonNullExpressionKindMetaPropertyKindSyntheticExpressionKindSatisfiesExpressionKindTemplateSpanKindSemicolonClassElementKindBlockKindEmptyStatementKindVariableStatementKindExpressionStatementKindIfStatementKindDoStatementKindWhileStatementKindForStatementKindForInStatementKindForOfStatementKindContinueStatementKindBreakStatementKindReturnStatementKindWithStatementKindSwitchStatementKindLabeledStatementKindThrowStatementKindTryStatementKindDebuggerStatementKindVariableDeclarationKindVariableDeclarationListKindFunctionDeclarationKindClassDeclarationKindInterfaceDeclarationKindTypeAliasDeclarationKindEnumDeclarationKindModuleDeclarationKindModuleBlockKindCaseBlockKindNamespaceExportDeclarationKindImportEqualsDeclarationKindImportDeclarationKindImportClauseKindNamespaceImportKindNamedImportsKindImportSpecifierKindExportAssignmentKindExportDeclarationKindNamedExportsKindNamespaceExportKindExportSpecifierKindMissingDeclarationKindExternalModuleReferenceKindJsxElementKindJsxSelfClosingElementKindJsxOpeningElementKindJsxClosingElementKindJsxFragmentKindJsxOpeningFragmentKindJsxClosingFragmentKindJsxAttributeKindJsxAttributesKindJsxSpreadAttributeKindJsxExpressionKindJsxNamespacedNameKindCaseClauseKindDefaultClauseKindHeritageClauseKindCatchClauseKindImportAttributesKindImportAttributeKindPropertyAssignmentKindShorthandPropertyAssignmentKindSpreadAssignmentKindEnumMemberKindSourceFileKindJSDocTypeExpressionKindJSDocNameReferenceKindJSDocAllTypeKindJSDocNullableTypeKindJSDocNonNullableTypeKindJSDocOptionalTypeKindJSDocVariadicTypeKindJSDocKindJSDocTextKindJSDocTypeLiteralKindJSDocSignatureKindJSDocLinkKindJSDocLinkCodeKindJSDocLinkPlainKindJSDocUnknownTagKindJSDocAugmentsTagKindJSDocImplementsTagKindJSDocDeprecatedTagKindJSDocPublicTagKindJSDocPrivateTagKindJSDocProtectedTagKindJSDocReadonlyTagKindJSDocOverrideTagKindJSDocCallbackTagKindJSDocOverloadTagKindJSDocParameterTagKindJSDocReturnTagKindJSDocThisTagKindJSDocTypeTagKindJSDocTemplateTagKindJSDocTypedefTagKindJSDocSeeTagKindJSDocPropertyTagKindJSDocThrowsTagKindJSDocSatisfiesTagKindJSDocImportTagKindSyntaxListKindJSTypeAliasDeclarationKindJSImportDeclarationKindNotEmittedStatementKindPartiallyEmittedExpressionKindSyntheticReferenceExpressionKindNotEmittedTypeElementKindCount" +const _Kind_name = "KindUnknownKindEndOfFileKindSingleLineCommentTriviaKindMultiLineCommentTriviaKindNewLineTriviaKindWhitespaceTriviaKindConflictMarkerTriviaKindNonTextFileMarkerTriviaKindNumericLiteralKindBigIntLiteralKindStringLiteralKindJsxTextKindJsxTextAllWhiteSpacesKindRegularExpressionLiteralKindNoSubstitutionTemplateLiteralKindTemplateHeadKindTemplateMiddleKindTemplateTailKindOpenBraceTokenKindCloseBraceTokenKindOpenParenTokenKindCloseParenTokenKindOpenBracketTokenKindCloseBracketTokenKindDotTokenKindDotDotDotTokenKindSemicolonTokenKindCommaTokenKindQuestionDotTokenKindLessThanTokenKindLessThanSlashTokenKindGreaterThanTokenKindLessThanEqualsTokenKindGreaterThanEqualsTokenKindEqualsEqualsTokenKindExclamationEqualsTokenKindEqualsEqualsEqualsTokenKindExclamationEqualsEqualsTokenKindEqualsGreaterThanTokenKindPlusTokenKindMinusTokenKindAsteriskTokenKindAsteriskAsteriskTokenKindSlashTokenKindPercentTokenKindPlusPlusTokenKindMinusMinusTokenKindLessThanLessThanTokenKindGreaterThanGreaterThanTokenKindGreaterThanGreaterThanGreaterThanTokenKindAmpersandTokenKindBarTokenKindCaretTokenKindExclamationTokenKindTildeTokenKindAmpersandAmpersandTokenKindBarBarTokenKindQuestionTokenKindColonTokenKindAtTokenKindQuestionQuestionTokenKindBacktickTokenKindHashTokenKindEqualsTokenKindPlusEqualsTokenKindMinusEqualsTokenKindAsteriskEqualsTokenKindAsteriskAsteriskEqualsTokenKindSlashEqualsTokenKindPercentEqualsTokenKindLessThanLessThanEqualsTokenKindGreaterThanGreaterThanEqualsTokenKindGreaterThanGreaterThanGreaterThanEqualsTokenKindAmpersandEqualsTokenKindBarEqualsTokenKindBarBarEqualsTokenKindAmpersandAmpersandEqualsTokenKindQuestionQuestionEqualsTokenKindCaretEqualsTokenKindIdentifierKindPrivateIdentifierKindJSDocCommentTextTokenKindBreakKeywordKindCaseKeywordKindCatchKeywordKindClassKeywordKindConstKeywordKindContinueKeywordKindDebuggerKeywordKindDefaultKeywordKindDeleteKeywordKindDoKeywordKindElseKeywordKindEnumKeywordKindExportKeywordKindExtendsKeywordKindFalseKeywordKindFinallyKeywordKindForKeywordKindFunctionKeywordKindIfKeywordKindImportKeywordKindInKeywordKindInstanceOfKeywordKindNewKeywordKindNullKeywordKindReturnKeywordKindSuperKeywordKindSwitchKeywordKindThisKeywordKindThrowKeywordKindTrueKeywordKindTryKeywordKindTypeOfKeywordKindVarKeywordKindVoidKeywordKindWhileKeywordKindWithKeywordKindImplementsKeywordKindInterfaceKeywordKindLetKeywordKindPackageKeywordKindPrivateKeywordKindProtectedKeywordKindPublicKeywordKindStaticKeywordKindYieldKeywordKindAbstractKeywordKindAccessorKeywordKindAsKeywordKindAssertsKeywordKindAssertKeywordKindAnyKeywordKindAsyncKeywordKindAwaitKeywordKindBooleanKeywordKindConstructorKeywordKindDeclareKeywordKindGetKeywordKindImmediateKeywordKindInferKeywordKindIntrinsicKeywordKindIsKeywordKindKeyOfKeywordKindModuleKeywordKindNamespaceKeywordKindNeverKeywordKindOutKeywordKindReadonlyKeywordKindRequireKeywordKindNumberKeywordKindObjectKeywordKindSatisfiesKeywordKindSetKeywordKindStringKeywordKindSymbolKeywordKindTypeKeywordKindUndefinedKeywordKindUniqueKeywordKindUnknownKeywordKindUsingKeywordKindFromKeywordKindGlobalKeywordKindBigIntKeywordKindOverrideKeywordKindOfKeywordKindDeferKeywordKindQualifiedNameKindComputedPropertyNameKindTypeParameterKindParameterKindDecoratorKindPropertySignatureKindPropertyDeclarationKindMethodSignatureKindMethodDeclarationKindClassStaticBlockDeclarationKindConstructorKindGetAccessorKindSetAccessorKindCallSignatureKindConstructSignatureKindIndexSignatureKindTypePredicateKindTypeReferenceKindFunctionTypeKindConstructorTypeKindTypeQueryKindTypeLiteralKindArrayTypeKindTupleTypeKindOptionalTypeKindRestTypeKindUnionTypeKindIntersectionTypeKindConditionalTypeKindInferTypeKindParenthesizedTypeKindThisTypeKindTypeOperatorKindIndexedAccessTypeKindMappedTypeKindLiteralTypeKindNamedTupleMemberKindTemplateLiteralTypeKindTemplateLiteralTypeSpanKindImportTypeKindObjectBindingPatternKindArrayBindingPatternKindBindingElementKindArrayLiteralExpressionKindObjectLiteralExpressionKindPropertyAccessExpressionKindElementAccessExpressionKindCallExpressionKindNewExpressionKindTaggedTemplateExpressionKindTypeAssertionExpressionKindParenthesizedExpressionKindFunctionExpressionKindArrowFunctionKindDeleteExpressionKindTypeOfExpressionKindVoidExpressionKindAwaitExpressionKindPrefixUnaryExpressionKindPostfixUnaryExpressionKindBinaryExpressionKindConditionalExpressionKindTemplateExpressionKindYieldExpressionKindSpreadElementKindClassExpressionKindOmittedExpressionKindExpressionWithTypeArgumentsKindAsExpressionKindNonNullExpressionKindMetaPropertyKindSyntheticExpressionKindSatisfiesExpressionKindTemplateSpanKindSemicolonClassElementKindBlockKindEmptyStatementKindVariableStatementKindExpressionStatementKindIfStatementKindDoStatementKindWhileStatementKindForStatementKindForInStatementKindForOfStatementKindContinueStatementKindBreakStatementKindReturnStatementKindWithStatementKindSwitchStatementKindLabeledStatementKindThrowStatementKindTryStatementKindDebuggerStatementKindVariableDeclarationKindVariableDeclarationListKindFunctionDeclarationKindClassDeclarationKindInterfaceDeclarationKindTypeAliasDeclarationKindEnumDeclarationKindModuleDeclarationKindModuleBlockKindCaseBlockKindNamespaceExportDeclarationKindImportEqualsDeclarationKindImportDeclarationKindImportClauseKindNamespaceImportKindNamedImportsKindImportSpecifierKindExportAssignmentKindExportDeclarationKindNamedExportsKindNamespaceExportKindExportSpecifierKindMissingDeclarationKindExternalModuleReferenceKindJsxElementKindJsxSelfClosingElementKindJsxOpeningElementKindJsxClosingElementKindJsxFragmentKindJsxOpeningFragmentKindJsxClosingFragmentKindJsxAttributeKindJsxAttributesKindJsxSpreadAttributeKindJsxExpressionKindJsxNamespacedNameKindCaseClauseKindDefaultClauseKindHeritageClauseKindCatchClauseKindImportAttributesKindImportAttributeKindPropertyAssignmentKindShorthandPropertyAssignmentKindSpreadAssignmentKindEnumMemberKindSourceFileKindJSDocTypeExpressionKindJSDocNameReferenceKindJSDocAllTypeKindJSDocNullableTypeKindJSDocNonNullableTypeKindJSDocOptionalTypeKindJSDocVariadicTypeKindJSDocKindJSDocTextKindJSDocTypeLiteralKindJSDocSignatureKindJSDocLinkKindJSDocLinkCodeKindJSDocLinkPlainKindJSDocUnknownTagKindJSDocAugmentsTagKindJSDocImplementsTagKindJSDocDeprecatedTagKindJSDocPublicTagKindJSDocPrivateTagKindJSDocProtectedTagKindJSDocReadonlyTagKindJSDocOverrideTagKindJSDocCallbackTagKindJSDocOverloadTagKindJSDocParameterTagKindJSDocReturnTagKindJSDocThisTagKindJSDocTypeTagKindJSDocTemplateTagKindJSDocTypedefTagKindJSDocSeeTagKindJSDocPropertyTagKindJSDocThrowsTagKindJSDocSatisfiesTagKindJSDocImportTagKindJSDocEnumTagKindSyntaxListKindJSTypeAliasDeclarationKindJSImportDeclarationKindNotEmittedStatementKindPartiallyEmittedExpressionKindSyntheticReferenceExpressionKindNotEmittedTypeElementKindCount" -var _Kind_index = [...]uint16{0, 11, 24, 51, 77, 94, 114, 138, 165, 183, 200, 217, 228, 253, 281, 314, 330, 348, 364, 382, 401, 419, 438, 458, 479, 491, 509, 527, 541, 561, 578, 600, 620, 643, 669, 690, 716, 743, 775, 801, 814, 828, 845, 870, 884, 900, 917, 936, 961, 992, 1034, 1052, 1064, 1078, 1098, 1112, 1139, 1154, 1171, 1185, 1196, 1221, 1238, 1251, 1266, 1285, 1305, 1328, 1359, 1379, 1401, 1432, 1469, 1517, 1541, 1559, 1580, 1613, 1644, 1664, 1678, 1699, 1724, 1740, 1755, 1771, 1787, 1803, 1822, 1841, 1859, 1876, 1889, 1904, 1919, 1936, 1954, 1970, 1988, 2002, 2021, 2034, 2051, 2064, 2085, 2099, 2114, 2131, 2147, 2164, 2179, 2195, 2210, 2224, 2241, 2255, 2270, 2286, 2301, 2322, 2342, 2356, 2374, 2392, 2412, 2429, 2446, 2462, 2481, 2500, 2513, 2531, 2548, 2562, 2578, 2594, 2612, 2634, 2652, 2666, 2686, 2702, 2722, 2735, 2751, 2768, 2788, 2804, 2818, 2837, 2855, 2872, 2889, 2909, 2923, 2940, 2957, 2972, 2992, 3009, 3027, 3043, 3058, 3075, 3092, 3111, 3124, 3140, 3157, 3181, 3198, 3211, 3224, 3245, 3268, 3287, 3308, 3339, 3354, 3369, 3384, 3401, 3423, 3441, 3458, 3475, 3491, 3510, 3523, 3538, 3551, 3564, 3580, 3592, 3605, 3625, 3644, 3657, 3678, 3690, 3706, 3727, 3741, 3756, 3776, 3799, 3826, 3840, 3864, 3887, 3905, 3931, 3958, 3986, 4013, 4031, 4048, 4076, 4103, 4130, 4152, 4169, 4189, 4209, 4227, 4246, 4271, 4297, 4317, 4342, 4364, 4383, 4400, 4419, 4440, 4471, 4487, 4508, 4524, 4547, 4570, 4586, 4611, 4620, 4638, 4659, 4682, 4697, 4712, 4730, 4746, 4764, 4782, 4803, 4821, 4840, 4857, 4876, 4896, 4914, 4930, 4951, 4974, 5001, 5024, 5044, 5068, 5092, 5111, 5132, 5147, 5160, 5190, 5217, 5238, 5254, 5273, 5289, 5308, 5328, 5349, 5365, 5384, 5403, 5425, 5452, 5466, 5491, 5512, 5533, 5548, 5570, 5592, 5608, 5625, 5647, 5664, 5685, 5699, 5716, 5734, 5749, 5769, 5788, 5810, 5841, 5861, 5875, 5889, 5912, 5934, 5950, 5971, 5995, 6016, 6037, 6046, 6059, 6079, 6097, 6110, 6127, 6145, 6164, 6184, 6206, 6228, 6246, 6265, 6286, 6306, 6326, 6346, 6366, 6387, 6405, 6421, 6437, 6457, 6476, 6491, 6511, 6529, 6550, 6568, 6582, 6608, 6631, 6654, 6684, 6716, 6741, 6750} +var _Kind_index = [...]uint16{0, 11, 24, 51, 77, 94, 114, 138, 165, 183, 200, 217, 228, 253, 281, 314, 330, 348, 364, 382, 401, 419, 438, 458, 479, 491, 509, 527, 541, 561, 578, 600, 620, 643, 669, 690, 716, 743, 775, 801, 814, 828, 845, 870, 884, 900, 917, 936, 961, 992, 1034, 1052, 1064, 1078, 1098, 1112, 1139, 1154, 1171, 1185, 1196, 1221, 1238, 1251, 1266, 1285, 1305, 1328, 1359, 1379, 1401, 1432, 1469, 1517, 1541, 1559, 1580, 1613, 1644, 1664, 1678, 1699, 1724, 1740, 1755, 1771, 1787, 1803, 1822, 1841, 1859, 1876, 1889, 1904, 1919, 1936, 1954, 1970, 1988, 2002, 2021, 2034, 2051, 2064, 2085, 2099, 2114, 2131, 2147, 2164, 2179, 2195, 2210, 2224, 2241, 2255, 2270, 2286, 2301, 2322, 2342, 2356, 2374, 2392, 2412, 2429, 2446, 2462, 2481, 2500, 2513, 2531, 2548, 2562, 2578, 2594, 2612, 2634, 2652, 2666, 2686, 2702, 2722, 2735, 2751, 2768, 2788, 2804, 2818, 2837, 2855, 2872, 2889, 2909, 2923, 2940, 2957, 2972, 2992, 3009, 3027, 3043, 3058, 3075, 3092, 3111, 3124, 3140, 3157, 3181, 3198, 3211, 3224, 3245, 3268, 3287, 3308, 3339, 3354, 3369, 3384, 3401, 3423, 3441, 3458, 3475, 3491, 3510, 3523, 3538, 3551, 3564, 3580, 3592, 3605, 3625, 3644, 3657, 3678, 3690, 3706, 3727, 3741, 3756, 3776, 3799, 3826, 3840, 3864, 3887, 3905, 3931, 3958, 3986, 4013, 4031, 4048, 4076, 4103, 4130, 4152, 4169, 4189, 4209, 4227, 4246, 4271, 4297, 4317, 4342, 4364, 4383, 4400, 4419, 4440, 4471, 4487, 4508, 4524, 4547, 4570, 4586, 4611, 4620, 4638, 4659, 4682, 4697, 4712, 4730, 4746, 4764, 4782, 4803, 4821, 4840, 4857, 4876, 4896, 4914, 4930, 4951, 4974, 5001, 5024, 5044, 5068, 5092, 5111, 5132, 5147, 5160, 5190, 5217, 5238, 5254, 5273, 5289, 5308, 5328, 5349, 5365, 5384, 5403, 5425, 5452, 5466, 5491, 5512, 5533, 5548, 5570, 5592, 5608, 5625, 5647, 5664, 5685, 5699, 5716, 5734, 5749, 5769, 5788, 5810, 5841, 5861, 5875, 5889, 5912, 5934, 5950, 5971, 5995, 6016, 6037, 6046, 6059, 6079, 6097, 6110, 6127, 6145, 6164, 6184, 6206, 6228, 6246, 6265, 6286, 6306, 6326, 6346, 6366, 6387, 6405, 6421, 6437, 6457, 6476, 6491, 6511, 6529, 6550, 6568, 6584, 6598, 6624, 6647, 6670, 6700, 6732, 6757, 6766} func (i Kind) String() string { idx := int(i) - 0 diff --git a/tsc/internal/ast/utilities.go b/tsc/internal/ast/utilities.go index 42058ea2c399f..18d5cce0d572c 100644 --- a/tsc/internal/ast/utilities.go +++ b/tsc/internal/ast/utilities.go @@ -3825,7 +3825,7 @@ func hasComment(kind Kind) bool { KindJSDocReadonlyTag, KindJSDocOverrideTag, KindJSDocCallbackTag, KindJSDocOverloadTag, KindJSDocParameterTag, KindJSDocPropertyTag, KindJSDocReturnTag, KindJSDocThisTag, KindJSDocTypeTag, KindJSDocTemplateTag, KindJSDocTypedefTag, KindJSDocSeeTag, - KindJSDocThrowsTag, KindJSDocSatisfiesTag, KindJSDocImportTag: + KindJSDocThrowsTag, KindJSDocSatisfiesTag, KindJSDocImportTag, KindJSDocEnumTag: return true default: return false diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index ba4c3fa2718b6..61df284c87271 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -7050,7 +7050,7 @@ func (c *Checker) checkExportsOnMergedDeclarations(node *ast.Node) { func (c *Checker) getDeclarationSpaces(node *ast.Declaration) DeclarationSpaces { switch node.Kind { - case ast.KindInterfaceDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindJSDocTypedefTag, ast.KindJSDocCallbackTag: + case ast.KindInterfaceDeclaration, ast.KindTypeAliasDeclaration, ast.KindJSTypeAliasDeclaration, ast.KindJSDocTypedefTag, ast.KindJSDocCallbackTag, ast.KindJSDocEnumTag: return DeclarationSpacesExportType case ast.KindModuleDeclaration: if ast.IsAmbientModule(node) || ast.GetModuleInstanceState(node) != ast.ModuleInstanceStateNonInstantiated { diff --git a/tsc/internal/checker/emitresolver.go b/tsc/internal/checker/emitresolver.go index 1a4f86696fd2a..6fd60c1c84bd4 100644 --- a/tsc/internal/checker/emitresolver.go +++ b/tsc/internal/checker/emitresolver.go @@ -131,7 +131,7 @@ func (r *EmitResolver) isDeclarationVisible(node *ast.Node) bool { func (r *EmitResolver) determineIfDeclarationIsVisible(node *ast.Node) bool { switch node.Kind { case ast.KindJSDocCallbackTag, - // ast.KindJSDocEnumTag, // !!! TODO: JSDoc @enum support? + ast.KindJSDocEnumTag, ast.KindJSDocTypedefTag: // Top-level jsdoc type aliases are considered exported // First parent is comment node, second is hosting declaration or token; we only care about those tokens or declarations whose parent is a source file diff --git a/tsc/internal/parser/jsdoc.go b/tsc/internal/parser/jsdoc.go index bd55bd03a2d8e..4d1382392aee1 100644 --- a/tsc/internal/parser/jsdoc.go +++ b/tsc/internal/parser/jsdoc.go @@ -1,6 +1,7 @@ package parser import ( + "strconv" "strings" "unicode" @@ -123,6 +124,53 @@ func (p *Parser) parseJSDocTypeExpression(mayOmitBraces bool) *ast.Node { return p.finishNode(p.factory.NewJSDocTypeExpression(t), pos) } +func (p *Parser) parseJSDocFunctionType() *ast.Node { + pos := p.nodePos() + if !p.lookAhead((*Parser).nextTokenIsOpenParen) { + return p.parseTypeReference() + } + p.nextToken() // consume `function`; current token is `(` + p.parseExpected(ast.KindOpenParenToken) + params := p.nodeSliceArena.NewSlice(0) + if p.token != ast.KindCloseParenToken && p.token != ast.KindEndOfFile { + for i := 0; ; i++ { + params = append(params, p.parseJSDocFunctionParameter(i)) + if !p.parseOptional(ast.KindCommaToken) { + break + } + if p.token == ast.KindCloseParenToken { + break + } + } + } + closePos := p.nodePos() + p.parseExpected(ast.KindCloseParenToken) + returnType := p.parseReturnType(ast.KindColonToken, false /*isType*/) + if returnType == nil { + returnType = p.finishNode(p.factory.NewKeywordTypeNode(ast.KindAnyKeyword), closePos) + } + var loc core.TextRange + if len(params) > 0 { + loc = core.NewTextRange(params[0].Pos(), params[len(params)-1].End()) + } else { + loc = core.NewTextRange(pos, closePos) + } + return p.finishNode(p.factory.NewFunctionTypeNode(nil, p.newNodeList(loc, params), returnType), pos) +} + +func (p *Parser) parseJSDocFunctionParameter(index int) *ast.Node { + pos := p.nodePos() + var name *ast.Node + if p.token == ast.KindThisKeyword || p.token == ast.KindNewKeyword { + name = p.parseIdentifierName() + p.parseExpected(ast.KindColonToken) + } else { + name = p.factory.NewIdentifier("p" + strconv.Itoa(index)) + } + typ := p.parseJSDocType() + return p.finishNode(p.factory.NewParameterDeclaration(nil, nil, name, nil, typ, nil), pos) +} + func (p *Parser) parseJSDocNameReference() *ast.Node { pos := p.nodePos() hasBrace := p.parseOptional(ast.KindOpenBraceToken) @@ -522,6 +570,8 @@ func (p *Parser) parseTag(tags []*ast.Node, margin int) *ast.Node { tag = p.parseThrowsTag(start, tagName, margin, indentText) case "import": tag = p.parseImportTag(start, tagName, margin, indentText) + case "enum": + tag = p.parseEnumTag(start, tagName, margin, indentText) default: tag = p.parseUnknownTag(start, tagName, margin, indentText) } @@ -989,6 +1039,12 @@ func (p *Parser) parseThisTag(start int, tagName *ast.IdentifierNode, margin int return p.finishNode(result, start) } +func (p *Parser) parseEnumTag(start int, tagName *ast.IdentifierNode, margin int, indentText string) *ast.Node { + typeExpression := p.parseJSDocTypeExpression(true) + p.skipWhitespace() + return p.finishNode(p.factory.NewJSDocEnumTag(tagName, typeExpression, p.parseTrailingTagComments(start, p.nodePos(), margin, indentText)), start) +} + func (p *Parser) parseJSDocTypeNameWithNamespace(nested bool) *ast.Node { start := p.scanner.TokenStart() if !tokenIsIdentifierOrKeyword(p.token) { diff --git a/tsc/internal/parser/parser.go b/tsc/internal/parser/parser.go index 8b53a39b0cda3..6b1bf8609cf1b 100644 --- a/tsc/internal/parser/parser.go +++ b/tsc/internal/parser/parser.go @@ -2862,6 +2862,11 @@ func (p *Parser) parseNonArrayType() *ast.Node { return p.parseTypeReference() case ast.KindTemplateHead: return p.parseTemplateType() + case ast.KindFunctionKeyword: + if p.contextFlags&ast.NodeFlagsJSDoc != 0 { + return p.parseJSDocFunctionType() + } + return p.parseTypeReference() default: return p.parseTypeReference() } diff --git a/tsc/internal/parser/reparser.go b/tsc/internal/parser/reparser.go index fce97c480286c..0d4723385a99c 100644 --- a/tsc/internal/parser/reparser.go +++ b/tsc/internal/parser/reparser.go @@ -97,6 +97,8 @@ func (p *Parser) reparseUnhosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Nod typeAlias.Flags |= ast.NodeFlagsHasJSDoc result := p.wrapInJSDocNamespace(fullName, typeAlias, false /*nested*/) p.reparseList = append(p.reparseList, result) + case ast.KindJSDocEnumTag: + p.reparseJSDocEnumTag(tag, parent, jsDoc) case ast.KindJSDocCallbackTag: typeExpression := tag.TypeExpression() if typeExpression == nil { @@ -693,6 +695,74 @@ func getClassLikeData(parent *ast.Node) *ast.ClassLikeBase { return class } +func (p *Parser) reparseJSDocEnumTag(tag *ast.Node, parent *ast.Node, _ *ast.Node) { + typeExpression := tag.TypeExpression() + if typeExpression == nil { + return + } + name := p.nameForNamelessJSDocEnum(parent) + if name == nil { + return + } + var t *ast.Node + if typeExpression.Kind == ast.KindJSDocTypeExpression { + inner := typeExpression.Type() + if inner == nil { + return + } + t = p.addDeepCloneReparse(inner) + } else { + t = p.addDeepCloneReparse(typeExpression) + } + typeAlias := p.factory.NewJSTypeAliasDeclaration(nil, p.addDeepCloneReparse(p.checkNonIdentifierName(name)), nil, t) + p.finishReparsedNode(typeAlias, tag) + p.reparseList = append(p.reparseList, typeAlias) +} + +// nameForNamelessJSDocEnum mirrors Strada nameForNamelessJSDocTypedef: @enum takes +// its name from the host declaration (export const E / exports.E = ...). +func (p *Parser) nameForNamelessJSDocEnum(host *ast.Node) *ast.Node { + if host == nil { + return nil + } + if ast.IsDeclaration(host) { + if name := ast.GetNameOfDeclaration(host); name != nil && ast.IsIdentifier(name) { + return name + } + } + switch host.Kind { + case ast.KindVariableStatement: + list := host.AsVariableStatement().DeclarationList + if list == nil { + return nil + } + decls := list.AsVariableDeclarationList().Declarations.Nodes + if len(decls) == 0 { + return nil + } + return p.nameForNamelessJSDocEnum(decls[0]) + case ast.KindExpressionStatement: + expr := host.Expression() + if ast.IsBinaryExpression(expr) && expr.AsBinaryExpression().OperatorToken.Kind == ast.KindEqualsToken { + expr = expr.AsBinaryExpression().Left + } + switch expr.Kind { + case ast.KindPropertyAccessExpression: + return expr.AsPropertyAccessExpression().Name() + case ast.KindElementAccessExpression: + arg := expr.AsElementAccessExpression().ArgumentExpression + if ast.IsIdentifier(arg) { + return arg + } + case ast.KindIdentifier: + return expr + } + case ast.KindParenthesizedExpression: + return p.nameForNamelessJSDocEnum(host.Expression()) + } + return nil +} + func (p *Parser) createExportModifier(locationNode *ast.Node) *ast.ModifierList { exportModifier := p.factory.NewModifier(ast.KindExportKeyword) exportModifier.Loc = locationNode.Loc diff --git a/tsc/testdata/baselines/reference/compiler/jsFileESModuleWithEnumTag.symbols b/tsc/testdata/baselines/reference/compiler/jsFileESModuleWithEnumTag.symbols index 6c4614c022c60..bd5917579bee4 100644 --- a/tsc/testdata/baselines/reference/compiler/jsFileESModuleWithEnumTag.symbols +++ b/tsc/testdata/baselines/reference/compiler/jsFileESModuleWithEnumTag.symbols @@ -4,7 +4,7 @@ export {}; // mark as module /** @enum {number} */ const ChangeDetectionStrategy = { ->ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5)) +>ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5), Decl(jsFileESModuleWithEnumTag.js, 1, 4)) OnPush: 0, >OnPush : Symbol(OnPush, Decl(jsFileESModuleWithEnumTag.js, 2, 33)) @@ -14,26 +14,26 @@ const ChangeDetectionStrategy = { }; ChangeDetectionStrategy[ChangeDetectionStrategy.OnPush] = 'OnPush'; ->ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5)) +>ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5), Decl(jsFileESModuleWithEnumTag.js, 1, 4)) >ChangeDetectionStrategy.OnPush : Symbol(OnPush, Decl(jsFileESModuleWithEnumTag.js, 2, 33)) ->ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5)) +>ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5), Decl(jsFileESModuleWithEnumTag.js, 1, 4)) >OnPush : Symbol(OnPush, Decl(jsFileESModuleWithEnumTag.js, 2, 33)) ChangeDetectionStrategy[ChangeDetectionStrategy.Default] = 'Default'; ->ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5)) +>ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5), Decl(jsFileESModuleWithEnumTag.js, 1, 4)) >ChangeDetectionStrategy.Default : Symbol(Default, Decl(jsFileESModuleWithEnumTag.js, 3, 12)) ->ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5)) +>ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5), Decl(jsFileESModuleWithEnumTag.js, 1, 4)) >Default : Symbol(Default, Decl(jsFileESModuleWithEnumTag.js, 3, 12)) Object.defineProperty(ChangeDetectionStrategy, "aField", {value: 42}); >Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) ->ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5)) +>ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5), Decl(jsFileESModuleWithEnumTag.js, 1, 4)) >value : Symbol(value, Decl(jsFileESModuleWithEnumTag.js, 8, 58)) /** @type {number} */ ChangeDetectionStrategy["bField"]; ->ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5)) +>ChangeDetectionStrategy : Symbol(ChangeDetectionStrategy, Decl(jsFileESModuleWithEnumTag.js, 2, 5), Decl(jsFileESModuleWithEnumTag.js, 1, 4)) diff --git a/tsc/testdata/baselines/reference/conformance/enumTag.errors.txt b/tsc/testdata/baselines/reference/conformance/enumTag.errors.txt deleted file mode 100644 index 1d4701cfc5a79..0000000000000 --- a/tsc/testdata/baselines/reference/conformance/enumTag.errors.txt +++ /dev/null @@ -1,68 +0,0 @@ -a.js(24,13): error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? -a.js(25,12): error TS2749: 'Second' refers to a value, but is being used as a type here. Did you mean 'typeof Second'? -a.js(26,12): error TS2749: 'Fs' refers to a value, but is being used as a type here. Did you mean 'typeof Fs'? -a.js(35,16): error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? - - -==== a.js (4 errors) ==== - /** @enum {string} */ - const Target = { - START: "start", - MIDDLE: "middle", - END: "end", - MISTAKE: 1, - /** @type {number} */ - OK_I_GUESS: 2 - } - /** @enum number */ - const Second = { - MISTAKE: "end", - OK: 1, - /** @type {number} */ - FINE: 2, - } - /** @enum {function(number): number} */ - const Fs = { - ADD1: n => n + 1, - ID: n => n, - SUB1: n => n - 1 - } - - /** @param {Target} t - ~~~~~~ -!!! error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? - * @param {Second} s - ~~~~~~ -!!! error TS2749: 'Second' refers to a value, but is being used as a type here. Did you mean 'typeof Second'? - * @param {Fs} f - ~~ -!!! error TS2749: 'Fs' refers to a value, but is being used as a type here. Did you mean 'typeof Fs'? - */ - function consume(t,s,f) { - /** @type {string} */ - var str = t - /** @type {number} */ - var num = s - /** @type {(n: number) => number} */ - var fun = f - /** @type {Target} */ - ~~~~~~ -!!! error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? - var v = Target.START - v = Target.UNKNOWN // error, can't find 'UNKNOWN' - v = Second.MISTAKE // meh..ok, I guess? - v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums - } - /** @param {string} s */ - function ff(s) { - // element access with arbitrary string is an error only with noImplicitAny - if (!Target[s]) { - return null - } - else { - return Target[s] - } - } - - - \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/enumTag.symbols b/tsc/testdata/baselines/reference/conformance/enumTag.symbols index 207534853571d..3963ede5a1acb 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTag.symbols +++ b/tsc/testdata/baselines/reference/conformance/enumTag.symbols @@ -3,7 +3,7 @@ === a.js === /** @enum {string} */ const Target = { ->Target : Symbol(Target, Decl(a.js, 1, 5)) +>Target : Symbol(Target, Decl(a.js, 1, 5), Decl(a.js, 0, 4)) START: "start", >START : Symbol(START, Decl(a.js, 1, 16)) @@ -23,7 +23,7 @@ const Target = { } /** @enum number */ const Second = { ->Second : Symbol(Second, Decl(a.js, 10, 5)) +>Second : Symbol(Second, Decl(a.js, 10, 5), Decl(a.js, 9, 4)) MISTAKE: "end", >MISTAKE : Symbol(MISTAKE, Decl(a.js, 10, 16)) @@ -37,7 +37,7 @@ const Second = { } /** @enum {function(number): number} */ const Fs = { ->Fs : Symbol(Fs, Decl(a.js, 17, 5)) +>Fs : Symbol(Fs, Decl(a.js, 17, 5), Decl(a.js, 16, 4)) ADD1: n => n + 1, >ADD1 : Symbol(ADD1, Decl(a.js, 17, 12)) @@ -84,17 +84,17 @@ function consume(t,s,f) { var v = Target.START >v : Symbol(v, Decl(a.js, 35, 7)) >Target.START : Symbol(START, Decl(a.js, 1, 16)) ->Target : Symbol(Target, Decl(a.js, 1, 5)) +>Target : Symbol(Target, Decl(a.js, 1, 5), Decl(a.js, 0, 4)) >START : Symbol(START, Decl(a.js, 1, 16)) v = Target.UNKNOWN // error, can't find 'UNKNOWN' >v : Symbol(v, Decl(a.js, 35, 7)) ->Target : Symbol(Target, Decl(a.js, 1, 5)) +>Target : Symbol(Target, Decl(a.js, 1, 5), Decl(a.js, 0, 4)) v = Second.MISTAKE // meh..ok, I guess? >v : Symbol(v, Decl(a.js, 35, 7)) >Second.MISTAKE : Symbol(MISTAKE, Decl(a.js, 10, 16)) ->Second : Symbol(Second, Decl(a.js, 10, 5)) +>Second : Symbol(Second, Decl(a.js, 10, 5), Decl(a.js, 9, 4)) >MISTAKE : Symbol(MISTAKE, Decl(a.js, 10, 16)) v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums @@ -107,14 +107,14 @@ function ff(s) { // element access with arbitrary string is an error only with noImplicitAny if (!Target[s]) { ->Target : Symbol(Target, Decl(a.js, 1, 5)) +>Target : Symbol(Target, Decl(a.js, 1, 5), Decl(a.js, 0, 4)) >s : Symbol(s, Decl(a.js, 41, 12)) return null } else { return Target[s] ->Target : Symbol(Target, Decl(a.js, 1, 5)) +>Target : Symbol(Target, Decl(a.js, 1, 5), Decl(a.js, 0, 4)) >s : Symbol(s, Decl(a.js, 41, 12)) } } diff --git a/tsc/testdata/baselines/reference/conformance/enumTag.types b/tsc/testdata/baselines/reference/conformance/enumTag.types index 03c5f941bdd01..6360ffca136c1 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTag.types +++ b/tsc/testdata/baselines/reference/conformance/enumTag.types @@ -79,19 +79,19 @@ const Fs = { */ function consume(t,s,f) { >consume : (t: Target, s: Second, f: Fs) => void ->t : Target ->s : Second +>t : string +>s : number >f : Fs /** @type {string} */ var str = t >str : string ->t : Target +>t : string /** @type {number} */ var num = s >num : number ->s : Second +>s : number /** @type {(n: number) => number} */ var fun = f @@ -100,28 +100,28 @@ function consume(t,s,f) { /** @type {Target} */ var v = Target.START ->v : Target +>v : string >Target.START : string >Target : { START: string; MIDDLE: string; END: string; MISTAKE: number; OK_I_GUESS: number; } >START : string v = Target.UNKNOWN // error, can't find 'UNKNOWN' >v = Target.UNKNOWN : any ->v : Target +>v : string >Target.UNKNOWN : any >Target : { START: string; MIDDLE: string; END: string; MISTAKE: number; OK_I_GUESS: number; } >UNKNOWN : any v = Second.MISTAKE // meh..ok, I guess? >v = Second.MISTAKE : string ->v : Target +>v : string >Second.MISTAKE : string >Second : { MISTAKE: string; OK: number; FINE: number; } >MISTAKE : string v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums >v = 'something else' : "something else" ->v : Target +>v : string >'something else' : "something else" } /** @param {string} s */ diff --git a/tsc/testdata/baselines/reference/conformance/enumTagCircularReference.errors.txt b/tsc/testdata/baselines/reference/conformance/enumTagCircularReference.errors.txt new file mode 100644 index 0000000000000..9f965b228f71d --- /dev/null +++ b/tsc/testdata/baselines/reference/conformance/enumTagCircularReference.errors.txt @@ -0,0 +1,9 @@ +bug27142.js(2,7): error TS2456: Type alias 'E' circularly references itself. + + +==== bug27142.js (1 errors) ==== + /** @enum {E} */ + const E = { x: 0 }; + ~ +!!! error TS2456: Type alias 'E' circularly references itself. + \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/enumTagCircularReference.symbols b/tsc/testdata/baselines/reference/conformance/enumTagCircularReference.symbols index 840a5c2f004f4..3ca102c43c0e8 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTagCircularReference.symbols +++ b/tsc/testdata/baselines/reference/conformance/enumTagCircularReference.symbols @@ -3,6 +3,6 @@ === bug27142.js === /** @enum {E} */ const E = { x: 0 }; ->E : Symbol(E, Decl(bug27142.js, 1, 5)) +>E : Symbol(E, Decl(bug27142.js, 1, 5), Decl(bug27142.js, 0, 4)) >x : Symbol(x, Decl(bug27142.js, 1, 11)) diff --git a/tsc/testdata/baselines/reference/conformance/enumTagImported.errors.txt b/tsc/testdata/baselines/reference/conformance/enumTagImported.errors.txt deleted file mode 100644 index 5180e905958ce..0000000000000 --- a/tsc/testdata/baselines/reference/conformance/enumTagImported.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -type.js(1,32): error TS2694: Namespace '"mod1"' has no exported member 'TestEnum'. -type.js(4,29): error TS2694: Namespace '"mod1"' has no exported member 'TestEnum'. -value.js(2,12): error TS2749: 'TestEnum' refers to a value, but is being used as a type here. Did you mean 'typeof TestEnum'? - - -==== type.js (2 errors) ==== - /** @typedef {import("./mod1").TestEnum} TE */ - ~~~~~~~~ -!!! error TS2694: Namespace '"mod1"' has no exported member 'TestEnum'. - /** @type {TE} */ - const test = 'add' - /** @type {import("./mod1").TestEnum} */ - ~~~~~~~~ -!!! error TS2694: Namespace '"mod1"' has no exported member 'TestEnum'. - const tost = 'remove' - -==== value.js (1 errors) ==== - import { TestEnum } from "./mod1" - /** @type {TestEnum} */ - ~~~~~~~~ -!!! error TS2749: 'TestEnum' refers to a value, but is being used as a type here. Did you mean 'typeof TestEnum'? - const tist = TestEnum.ADD - - -==== mod1.js (0 errors) ==== - /** @enum {string} */ - export const TestEnum = { - ADD: 'add', - REMOVE: 'remove' - } - \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/enumTagImported.symbols b/tsc/testdata/baselines/reference/conformance/enumTagImported.symbols index 93e5cd1a66065..6486d1b8df1d0 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTagImported.symbols +++ b/tsc/testdata/baselines/reference/conformance/enumTagImported.symbols @@ -25,7 +25,7 @@ const tist = TestEnum.ADD === mod1.js === /** @enum {string} */ export const TestEnum = { ->TestEnum : Symbol(TestEnum, Decl(mod1.js, 1, 12)) +>TestEnum : Symbol(TestEnum, Decl(mod1.js, 1, 12), Decl(mod1.js, 0, 4)) ADD: 'add', >ADD : Symbol(ADD, Decl(mod1.js, 1, 25)) diff --git a/tsc/testdata/baselines/reference/conformance/enumTagImported.types b/tsc/testdata/baselines/reference/conformance/enumTagImported.types index a7e576e4d91c4..f063996dcb4a4 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTagImported.types +++ b/tsc/testdata/baselines/reference/conformance/enumTagImported.types @@ -4,12 +4,12 @@ /** @typedef {import("./mod1").TestEnum} TE */ /** @type {TE} */ const test = 'add' ->test : any +>test : string >'add' : "add" /** @type {import("./mod1").TestEnum} */ const tost = 'remove' ->tost : any +>tost : string >'remove' : "remove" === value.js === @@ -18,7 +18,7 @@ import { TestEnum } from "./mod1" /** @type {TestEnum} */ const tist = TestEnum.ADD ->tist : TestEnum +>tist : string >TestEnum.ADD : string >TestEnum : { ADD: string; REMOVE: string; } >ADD : string diff --git a/tsc/testdata/baselines/reference/conformance/enumTagOnExports.symbols b/tsc/testdata/baselines/reference/conformance/enumTagOnExports.symbols index c795bebd90617..e2167b3fcb2d5 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTagOnExports.symbols +++ b/tsc/testdata/baselines/reference/conformance/enumTagOnExports.symbols @@ -3,15 +3,15 @@ === enumTagOnExports.js === /** @enum {number} */ exports.a = {}; ->exports.a : Symbol(a, Decl(enumTagOnExports.js, 0, 0)) +>exports.a : Symbol(a, Decl(enumTagOnExports.js, 0, 0), Decl(enumTagOnExports.js, 0, 4)) >exports : Symbol(exports, Decl(enumTagOnExports.js, 0, 0)) ->a : Symbol(a, Decl(enumTagOnExports.js, 0, 0)) +>a : Symbol(a, Decl(enumTagOnExports.js, 0, 0), Decl(enumTagOnExports.js, 0, 4)) /** @enum {string} */ module.exports.b = {}; ->module.exports.b : Symbol(b, Decl(enumTagOnExports.js, 1, 15)) +>module.exports.b : Symbol(b, Decl(enumTagOnExports.js, 1, 15), Decl(enumTagOnExports.js, 3, 4)) >module.exports : Symbol(exports, Decl(enumTagOnExports.js, 0, 0)) >module : Symbol(module, Decl(enumTagOnExports.js, 0, 0)) >exports : Symbol(exports, Decl(enumTagOnExports.js, 0, 0)) ->b : Symbol(b, Decl(enumTagOnExports.js, 1, 15)) +>b : Symbol(b, Decl(enumTagOnExports.js, 1, 15), Decl(enumTagOnExports.js, 3, 4)) diff --git a/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.errors.txt b/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.errors.txt deleted file mode 100644 index 5aebbf567d58f..0000000000000 --- a/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -bug27134.js(7,11): error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'? - - -==== bug27134.js (1 errors) ==== - /** - * @enum {number} - */ - var foo = { }; - - /** - * @type {foo} - ~~~ -!!! error TS2749: 'foo' refers to a value, but is being used as a type here. Did you mean 'typeof foo'? - */ - var s; - \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.symbols b/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.symbols index 1d281375d3da1..4cfc6a71f06f0 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.symbols +++ b/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.symbols @@ -5,7 +5,7 @@ * @enum {number} */ var foo = { }; ->foo : Symbol(foo, Decl(bug27134.js, 3, 3)) +>foo : Symbol(foo, Decl(bug27134.js, 3, 3), Decl(bug27134.js, 1, 3)) /** * @type {foo} diff --git a/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.types b/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.types index 09e308a994b38..a45251ae78598 100644 --- a/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.types +++ b/tsc/testdata/baselines/reference/conformance/enumTagUseBeforeDefCrash.types @@ -12,5 +12,5 @@ var foo = { }; * @type {foo} */ var s; ->s : foo +>s : number diff --git a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).errors.txt b/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).errors.txt deleted file mode 100644 index 7312ed2c6638f..0000000000000 --- a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).errors.txt +++ /dev/null @@ -1,63 +0,0 @@ -index.js(23,12): error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? -index.js(24,12): error TS2749: 'Second' refers to a value, but is being used as a type here. Did you mean 'typeof Second'? -index.js(25,12): error TS2749: 'Fs' refers to a value, but is being used as a type here. Did you mean 'typeof Fs'? -index.js(34,16): error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? - - -==== index.js (4 errors) ==== - /** @enum {string} */ - export const Target = { - START: "start", - MIDDLE: "middle", - END: "end", - /** @type {number} */ - OK_I_GUESS: 2 - } - /** @enum number */ - export const Second = { - OK: 1, - /** @type {number} */ - FINE: 2, - } - /** @enum {function(number): number} */ - export const Fs = { - ADD1: n => n + 1, - ID: n => n, - SUB1: n => n - 1 - } - - /** - * @param {Target} t - ~~~~~~ -!!! error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? - * @param {Second} s - ~~~~~~ -!!! error TS2749: 'Second' refers to a value, but is being used as a type here. Did you mean 'typeof Second'? - * @param {Fs} f - ~~ -!!! error TS2749: 'Fs' refers to a value, but is being used as a type here. Did you mean 'typeof Fs'? - */ - export function consume(t,s,f) { - /** @type {string} */ - var str = t - /** @type {number} */ - var num = s - /** @type {(n: number) => number} */ - var fun = f - /** @type {Target} */ - ~~~~~~ -!!! error TS2749: 'Target' refers to a value, but is being used as a type here. Did you mean 'typeof Target'? - var v = Target.START - v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums - } - /** @param {string} s */ - export function ff(s) { - // element access with arbitrary string is an error only with noImplicitAny - if (!Target[s]) { - return null - } - else { - return Target[s] - } - } - \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).js b/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).js index fb5a994b834e5..c67d5856eb4ab 100644 --- a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).js +++ b/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).js @@ -105,6 +105,7 @@ function ff(s) { //// [index.d.ts] +export type Target = string; /** @enum {string} */ export declare const Target: { START: string; @@ -113,12 +114,14 @@ export declare const Target: { /** @type {number} */ OK_I_GUESS: number; }; +export type Second = number; /** @enum number */ export declare const Second: { OK: number; /** @type {number} */ FINE: number; }; +export type Fs = (p0: number) => number; /** @enum {function(number): number} */ export declare const Fs: { ADD1: (n: any) => any; diff --git a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).symbols b/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).symbols index 7f34a0fbd38bc..10b6657a2d034 100644 --- a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).symbols +++ b/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).symbols @@ -3,7 +3,7 @@ === index.js === /** @enum {string} */ export const Target = { ->Target : Symbol(Target, Decl(index.js, 1, 12)) +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) START: "start", >START : Symbol(START, Decl(index.js, 1, 23)) @@ -20,7 +20,7 @@ export const Target = { } /** @enum number */ export const Second = { ->Second : Symbol(Second, Decl(index.js, 9, 12)) +>Second : Symbol(Second, Decl(index.js, 9, 12), Decl(index.js, 8, 4)) OK: 1, >OK : Symbol(OK, Decl(index.js, 9, 23)) @@ -31,7 +31,7 @@ export const Second = { } /** @enum {function(number): number} */ export const Fs = { ->Fs : Symbol(Fs, Decl(index.js, 15, 12)) +>Fs : Symbol(Fs, Decl(index.js, 15, 12), Decl(index.js, 14, 4)) ADD1: n => n + 1, >ADD1 : Symbol(ADD1, Decl(index.js, 15, 19)) @@ -79,7 +79,7 @@ export function consume(t,s,f) { var v = Target.START >v : Symbol(v, Decl(index.js, 34, 7)) >Target.START : Symbol(START, Decl(index.js, 1, 23)) ->Target : Symbol(Target, Decl(index.js, 1, 12)) +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) >START : Symbol(START, Decl(index.js, 1, 23)) v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums @@ -92,14 +92,14 @@ export function ff(s) { // element access with arbitrary string is an error only with noImplicitAny if (!Target[s]) { ->Target : Symbol(Target, Decl(index.js, 1, 12)) +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) >s : Symbol(s, Decl(index.js, 38, 19)) return null } else { return Target[s] ->Target : Symbol(Target, Decl(index.js, 1, 12)) +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) >s : Symbol(s, Decl(index.js, 38, 19)) } } diff --git a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).types b/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).types index 440509b700be4..c86e23efe8832 100644 --- a/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).types +++ b/tsc/testdata/baselines/reference/conformance/jsDeclarationsEnumTag(target=es2015).types @@ -72,19 +72,19 @@ export const Fs = { */ export function consume(t,s,f) { >consume : (t: Target, s: Second, f: Fs) => void ->t : Target ->s : Second +>t : string +>s : number >f : Fs /** @type {string} */ var str = t >str : string ->t : Target +>t : string /** @type {number} */ var num = s >num : number ->s : Second +>s : number /** @type {(n: number) => number} */ var fun = f @@ -93,14 +93,14 @@ export function consume(t,s,f) { /** @type {Target} */ var v = Target.START ->v : Target +>v : string >Target.START : string >Target : { START: string; MIDDLE: string; END: string; OK_I_GUESS: number; } >START : string v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums >v = 'something else' : "something else" ->v : Target +>v : string >'something else' : "something else" } /** @param {string} s */ diff --git a/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.errors.txt b/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.errors.txt index 7501b5fd05b30..136fdcd2c1dbf 100644 --- a/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.errors.txt +++ b/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.errors.txt @@ -1,30 +1,10 @@ -mod1.js(2,21): error TS1003: Identifier expected. -mod1.js(2,22): error TS2300: Duplicate identifier '(Missing)'. -mod1.js(2,22): error TS1005: '}' expected. -mod1.js(9,12): error TS2552: Cannot find name 'Type1'. Did you mean 'Type2'? -mod3.js(4,21): error TS1003: Identifier expected. -mod3.js(4,22): error TS2300: Duplicate identifier '(Missing)'. -mod3.js(4,22): error TS1005: '}' expected. -mod3.js(10,12): error TS2304: Cannot find name 'StringOrNumber1'. -mod4.js(4,21): error TS1003: Identifier expected. -mod4.js(4,22): error TS2300: Duplicate identifier '(Missing)'. -mod4.js(4,22): error TS1005: '}' expected. -mod4.js(11,12): error TS2304: Cannot find name 'StringOrNumber2'. mod7.js(5,7): error TS1110: Type expected. mod7.js(8,4): error TS1110: Type expected. -==== mod1.js (4 errors) ==== +==== mod1.js (0 errors) ==== /** * @typedef {function(string): boolean} - ~ -!!! error TS1003: Identifier expected. - -!!! error TS2300: Duplicate identifier '(Missing)'. -!!! related TS6203 mod3.js:4:22: '(Missing)' was also declared here. -!!! related TS6203 mod4.js:4:22: '(Missing)' was also declared here. - ~ -!!! error TS1005: '}' expected. * Type1 */ @@ -32,8 +12,6 @@ mod7.js(8,4): error TS1110: Type expected. * Tries to use a type whose name is on a different * line than the typedef tag. * @param {Type1} func The function to call. - ~~~~~ -!!! error TS2552: Cannot find name 'Type1'. Did you mean 'Type2'? * @param {string} arg The argument to call it with. * @returns {boolean} The return. */ @@ -59,26 +37,17 @@ mod7.js(8,4): error TS1110: Type expected. return obj.boo ? obj.num : obj.str; } -==== mod3.js (4 errors) ==== +==== mod3.js (0 errors) ==== /** * A function whose signature is very long. * * @typedef {function(boolean, string, number): - ~ -!!! error TS1003: Identifier expected. - -!!! error TS2300: Duplicate identifier '(Missing)'. -!!! related TS6203 mod1.js:2:22: '(Missing)' was also declared here. - ~ -!!! error TS1005: '}' expected. * (string|number)} StringOrNumber1 */ /** * Makes use of a function type with a long signature. * @param {StringOrNumber1} func The function. - ~~~~~~~~~~~~~~~ -!!! error TS2304: Cannot find name 'StringOrNumber1'. * @param {boolean} bool The condition. * @param {string} str The string. * @param {number} num The number. @@ -88,18 +57,11 @@ mod7.js(8,4): error TS1110: Type expected. return func(bool, str, num) } -==== mod4.js (4 errors) ==== +==== mod4.js (0 errors) ==== /** * A function whose signature is very long. * * @typedef {function(boolean, string, - ~ -!!! error TS1003: Identifier expected. - -!!! error TS2300: Duplicate identifier '(Missing)'. -!!! related TS6203 mod1.js:2:22: '(Missing)' was also declared here. - ~ -!!! error TS1005: '}' expected. * number): * (string|number)} StringOrNumber2 */ @@ -107,8 +69,6 @@ mod7.js(8,4): error TS1110: Type expected. /** * Makes use of a function type with a long signature. * @param {StringOrNumber2} func The function. - ~~~~~~~~~~~~~~~ -!!! error TS2304: Cannot find name 'StringOrNumber2'. * @param {boolean} bool The condition. * @param {string} str The string. * @param {number} num The number. diff --git a/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.types b/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.types index ebd2541cad7ea..90fff1b7df9b2 100644 --- a/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.types +++ b/tsc/testdata/baselines/reference/conformance/typedefTagWrapping.types @@ -19,7 +19,7 @@ function callIt(func, arg) { >arg : string return func(arg); ->func(arg) : any +>func(arg) : boolean >func : Type1 >arg : string } @@ -79,7 +79,7 @@ function use1(func, bool, str, num) { >num : number return func(bool, str, num) ->func(bool, str, num) : any +>func(bool, str, num) : string | number >func : StringOrNumber1 >bool : boolean >str : string @@ -111,7 +111,7 @@ function use2(func, bool, str, num) { >num : number return func(bool, str, num) ->func(bool, str, num) : any +>func(bool, str, num) : string | number >func : StringOrNumber2 >bool : boolean >str : string diff --git a/tsc/testdata/baselines/reference/fourslash/smartSelection/smartSelection_JSDocTags9.baseline b/tsc/testdata/baselines/reference/fourslash/smartSelection/smartSelection_JSDocTags9.baseline index 02e046a1ae333..fde518b314f01 100644 --- a/tsc/testdata/baselines/reference/fourslash/smartSelection/smartSelection_JSDocTags9.baseline +++ b/tsc/testdata/baselines/reference/fourslash/smartSelection/smartSelection_JSDocTags9.baseline @@ -5,7 +5,7 @@ const Foo = { y: 1, }; - {number}• ↲ + number ↲ @enum {number}• ↲ /** @enum {number} */↲