Skip to content

Typeof can refer to block-scoped values before declaration#15239

Merged
sandersn merged 5 commits into
masterfrom
typeof-can-refer-class-before-declaration
Apr 18, 2017
Merged

Typeof can refer to block-scoped values before declaration#15239
sandersn merged 5 commits into
masterfrom
typeof-can-refer-class-before-declaration

Conversation

@sandersn
Copy link
Copy Markdown
Member

Fixes #15102 by allowing references to block-scoped values before declaration inside of a type query.

Also adds findAncestor, which iterates up a parent pointer chain. I updated the parent pointer walks in checker to use findAncestor.

Copy link
Copy Markdown
Contributor

@mhegazy mhegazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Can you run the perf tests to make sure the new polymorphic function does not impact performance adversely.

Comment thread src/compiler/core.ts Outdated
* At that point findAncestor returns undefined.
*/
export function findAncestor<T>(node: Node, callback: (element: Node) => T | undefined, done?: (element: Node) => boolean): Node {
if (node) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this condition, because it's being checked in the while loop again

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@sandersn
Copy link
Copy Markdown
Member Author

With the PR as it stands now, total time of Monaco was 0.01 seconds faster and TFS was 0.37 seconds faster. Neither of those are significant, if I'm reading the output correctly.

I'm going to update the PR suggestions from @alfaproject and @Andy-MS and then re-run the perf test. I'll also try to get Angular correctly added to the perf test.

Previously there was a 'found' callback and a 'quit' callback.
@sandersn
Copy link
Copy Markdown
Member Author

Perf tests are about the same with the changes suggested by @Andy-MS. There's some variance but the average is right around 0.

@sandersn sandersn merged commit e36d8d5 into master Apr 18, 2017
@sandersn sandersn deleted the typeof-can-refer-class-before-declaration branch April 18, 2017 20:12
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants