-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add section - Find identifiers with same symbol #3
Merged
itsdouges
merged 4 commits into
itsdouges:master
from
bendtherules:match-identifier-by-symbol
Jan 3, 2020
Merged
Add section - Find identifiers with same symbol #3
itsdouges
merged 4 commits into
itsdouges:master
from
bendtherules:match-identifier-by-symbol
Jan 3, 2020
Conversation
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
bendtherules
changed the title
Add section - Check identifiers with same symbol
Add section - Find identifiers with same symbol
Jan 2, 2020
itsdouges
reviewed
Jan 2, 2020
|
||
Then, the linker runs through these identifiers and connects the identifiers referring to the same variable with a common symbol (while considering scope and shadowing). Think of symbols as what we intuitively think as variables. | ||
|
||
So, to check if two identifiers refer to the same symbol - just get the symbols related to the identifier and check if they are the same (by reference). |
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.
if an identifier is not referenced typeChecker.getSymbolAtLocation(node)
would return undefined
yeah? should we mention that? 😄
No, so think like this - whenever ts finds a identifier, it looks up if a
symbol already exists for it and returns that. If not, then it creates a
new symbol for it.
So, every identifier has a corresponding symbol - it doesn't matter if it
appears again in the ast or not.
For ex, in our source.ts, inner foo identifier appears only once - but we
handle it in just the same way (getsymbol) and can log it. It will give a
proper symbol, no undefined.
…On Fri, 3 Jan, 2020, 4:37 am DOUGES DOES DXMAS, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In translations/en/transformer-handbook.md
<#3 (comment)>
:
>
-> **TODO** - Is this possible?
+Identifiers are created by the parser and are always unique.
+Say, if you create a variable `foo` and use it in another line, it will create 2 separate identifiers with the same text `foo`.
+
+Then, the linker runs through these identifiers and connects the identifiers referring to the same variable with a common symbol (while considering scope and shadowing). Think of symbols as what we intuitively think as variables.
+
+So, to check if two identifiers refer to the same symbol - just get the symbols related to the identifier and check if they are the same (by reference).
if an identifier is *not* referenced typeChecker.getSymbolAtLocation(node)
would return undefined yeah? should we mention that? 😄
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAXVDXSDUQHKZUYIUSR2NYDQ3ZXSFANCNFSM4KCGAGHQ>
.
|
cool thanks for the explanation :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related to #2 .