-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[ID-Prep] PR5 - Preserve type nodes from function like expression in declaration emit #57678
Closed
dragomirtitian
wants to merge
9
commits into
microsoft:main
from
bloomberg:ts-verbatim-declrations-from-function-expressions
Closed
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
297ba1b
Added tests for using type from assertion in declarations.
dragomirtitian 9399b32
Allow extraction of type from type assertions for declaration emit
dragomirtitian 4f63418
Accessor declared type was not visited
dragomirtitian c84eeb0
Merge remote-tracking branch 'remotes/origin/main' into ts-verbatim-d…
dragomirtitian 3833bf5
Incorporated feedback
dragomirtitian 5506934
Infer type from assertion for export assignment.
dragomirtitian 83c3715
Added test for JS assertions (not affected)
dragomirtitian 85ee2c0
Added test for function expression types in declarations.
dragomirtitian cd7636d
Preserve types from initializers that contain function expressions an…
dragomirtitian 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 |
---|---|---|
|
@@ -6329,8 +6329,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
|
||
const firstIdentifier = getFirstIdentifier(entityName); | ||
const symbol = resolveName(enclosingDeclaration, firstIdentifier.escapedText, meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false); | ||
if (symbol && symbol.flags & SymbolFlags.TypeParameter && meaning & SymbolFlags.Type) { | ||
return { accessibility: SymbolAccessibility.Accessible }; | ||
if (symbol) { | ||
if (symbol.flags & SymbolFlags.TypeParameter && meaning & SymbolFlags.Type) { | ||
return { accessibility: SymbolAccessibility.Accessible }; | ||
} | ||
|
||
// Parameters or binding elements from parameters are always visible in their enclosing function declarations | ||
if (symbol.flags & SymbolFlags.FunctionScopedVariable && meaning & SymbolFlags.Value) { | ||
let declaration: Node | undefined = symbol.valueDeclaration; | ||
while (declaration) { | ||
if (declaration.kind === SyntaxKind.Parameter) break; | ||
if (declaration.kind === SyntaxKind.BindingElement) { | ||
declaration = declaration.parent.parent; | ||
} | ||
break; | ||
} | ||
if (declaration?.kind === SyntaxKind.Parameter) { | ||
return { accessibility: SymbolAccessibility.Accessible }; | ||
} | ||
} | ||
} | ||
if (!symbol && isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfDeclaration(getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false, /*includeClassComputedPropertyName*/ false)), firstIdentifier, meaning, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) { | ||
return { accessibility: SymbolAccessibility.Accessible }; | ||
|
@@ -48160,13 +48177,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
hasSyntacticModifier(parameter, ModifierFlags.ParameterPropertyModifier); | ||
} | ||
|
||
function isExpandoFunctionDeclaration(node: Declaration): boolean { | ||
const declaration = getParseTreeNode(node, isFunctionDeclaration); | ||
function isExpandoFunctionDeclaration(node: FunctionDeclaration | VariableDeclaration): boolean { | ||
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. Both function and variable declarations will now be tested. We can't reliably determine the type for an expando functions variable from just it's declaration so we fall back on the type checker. |
||
const declaration = getParseTreeNode(node, isDeclaration); | ||
if (!declaration) { | ||
return false; | ||
} | ||
const symbol = getSymbolOfDeclaration(declaration); | ||
if (!symbol || !(symbol.flags & SymbolFlags.Function)) { | ||
let symbol: Symbol; | ||
if (isVariableDeclaration(declaration)) { | ||
if (declaration.type || !isVarConstLike(declaration)) { | ||
return false; | ||
} | ||
if (!(declaration.initializer && isFunctionExpressionOrArrowFunction(declaration.initializer))) { | ||
return false; | ||
} | ||
symbol = getSymbolOfDeclaration(declaration.initializer); | ||
} | ||
else { | ||
symbol = getSymbolOfDeclaration(declaration); | ||
} | ||
if (!symbol || !(symbol.flags & SymbolFlags.Function | SymbolFlags.Variable)) { | ||
return false; | ||
} | ||
return !!forEachEntry(getExportsOfSymbol(symbol), p => p.flags & SymbolFlags.Value && isExpandoPropertyDeclaration(p.valueDeclaration)); | ||
|
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
The checker complained about the parameter name not being accessible (since arrow functions are not themselves marked as visible by
determineIfDeclarationIsVisible
.