-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@typedef: Improve error spans from declaration emit #42501
Merged
sandersn
merged 5 commits into
master
from
better-typedef-error-spans-in-declaration-emit
Jan 28, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e42c1d6
@typedef: Improve error spans from declaration emit
sandersn 3b6b0a4
track error node in isSymbolAccessible instead
sandersn 70343e4
Switch to using enclosingDeclaration
sandersn 8f60abb
add test of @callback and @enum
sandersn a215bd2
Better error + fix @enum error
sandersn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4183,7 +4183,8 @@ namespace ts { | |
return { | ||
accessibility: SymbolAccessibility.CannotBeNamed, | ||
errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), | ||
errorModuleName: symbolToString(symbolExternalModule) | ||
errorModuleName: symbolToString(symbolExternalModule), | ||
errorNode: isInJSFile(enclosingDeclaration) ? enclosingDeclaration : undefined, | ||
}; | ||
} | ||
} | ||
|
@@ -4699,7 +4700,7 @@ namespace ts { | |
|
||
function createMappedTypeNodeFromType(type: MappedType) { | ||
Debug.assert(!!(type.flags & TypeFlags.Object)); | ||
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined; | ||
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyKeyword | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined; | ||
const questionToken = type.declaration.questionToken ? <QuestionToken | PlusToken | MinusToken>factory.createToken(type.declaration.questionToken.kind) : undefined; | ||
let appropriateConstraintTypeNode: TypeNode; | ||
if (isMappedTypeWithKeyofConstraintDeclaration(type)) { | ||
|
@@ -6183,7 +6184,7 @@ namespace ts { | |
tracker: { | ||
...oldcontext.tracker, | ||
trackSymbol: (sym, decl, meaning) => { | ||
const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeALiases*/ false); | ||
const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeAliases*/ false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by case fix |
||
if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { | ||
// Lookup the root symbol of the chain of refs we'll use to access it and serialize it | ||
const chain = lookupSymbolChainWorker(sym, context, meaning); | ||
|
@@ -6625,16 +6626,17 @@ namespace ts { | |
function addResult(node: Statement, additionalModifierFlags: ModifierFlags) { | ||
if (canHaveModifiers(node)) { | ||
let newModifierFlags: ModifierFlags = ModifierFlags.None; | ||
const enclosingDeclaration = context.enclosingDeclaration && | ||
(isJSDocTypeAlias(context.enclosingDeclaration) ? getSourceFileOfNode(context.enclosingDeclaration) : context.enclosingDeclaration); | ||
if (additionalModifierFlags & ModifierFlags.Export && | ||
context.enclosingDeclaration && | ||
(isExportingScope(context.enclosingDeclaration) || isModuleDeclaration(context.enclosingDeclaration)) && | ||
enclosingDeclaration && (isExportingScope(enclosingDeclaration) || isModuleDeclaration(enclosingDeclaration)) && | ||
canHaveExportModifier(node) | ||
) { | ||
// Classes, namespaces, variables, functions, interfaces, and types should all be `export`ed in a module context if not private | ||
newModifierFlags |= ModifierFlags.Export; | ||
} | ||
if (addingDeclare && !(newModifierFlags & ModifierFlags.Export) && | ||
(!context.enclosingDeclaration || !(context.enclosingDeclaration.flags & NodeFlags.Ambient)) && | ||
(!enclosingDeclaration || !(enclosingDeclaration.flags & NodeFlags.Ambient)) && | ||
(isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || isModuleDeclaration(node))) { | ||
// Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope | ||
newModifierFlags |= ModifierFlags.Ambient; | ||
|
@@ -6657,6 +6659,8 @@ namespace ts { | |
const commentText = jsdocAliasDecl ? jsdocAliasDecl.comment || jsdocAliasDecl.parent.comment : undefined; | ||
const oldFlags = context.flags; | ||
context.flags |= NodeBuilderFlags.InTypeAlias; | ||
const oldEnclosingDecl = context.enclosingDeclaration; | ||
context.enclosingDeclaration = jsdocAliasDecl; | ||
const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression | ||
&& isJSDocTypeExpression(jsdocAliasDecl.typeExpression) | ||
&& serializeExistingTypeNode(context, jsdocAliasDecl.typeExpression.type, includePrivateSymbol, bundled) | ||
|
@@ -6666,6 +6670,7 @@ namespace ts { | |
!commentText ? [] : [{ kind: SyntaxKind.MultiLineCommentTrivia, text: "*\n * " + commentText.replace(/\n/g, "\n * ") + "\n ", pos: -1, end: -1, hasTrailingNewLine: true }] | ||
), modifierFlags); | ||
context.flags = oldFlags; | ||
context.enclosingDeclaration = oldEnclosingDecl; | ||
} | ||
|
||
function serializeInterface(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by deprecation fix