This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
UASTv2 has no tokens for JSX Nodes #58
Copy link
Copy link
Closed
Labels
Description
JSX is a syntax extension to JavaScript. It can be converted to a proper JS with babel tool.
The bug I found is that UASTv1 provides a lot of tokens while UASTv2 don't
Here is the data to reproduce:
The JSX code
class TestIdTestApp extends React.Component {
render() {
return (
<View>
<Text testID="Text">text</Text>
</View>
);
}
}UASTv1
Start Position Token Internal Role Roles Tree
(0, 1, 1) |''| File FILE
(0, 1, 1) |''| Program ┣ MODULE
(0, 1, 1) |''| ClassDeclaration ┃ ┣ DECLARATION, TYPE, STATEMENT
(6, 1, 7) |'TestIdTestApp'| Identifier ┃ ┃ ┣ EXPRESSION, IDENTIFIER, TYPE, NAME
(28, 1, 29) |''| MemberExpression ┃ ┃ ┣ QUALIFIED, EXPRESSION, IDENTIFIER, TYPE, BASE
(28, 1, 29) |'React'| Identifier ┃ ┃ ┃ ┣ EXPRESSION, IDENTIFIER
(34, 1, 35) |'Component'| Identifier ┃ ┃ ┃ ┗ EXPRESSION, IDENTIFIER
(44, 1, 45) |''| ClassBody ┃ ┃ ┣ TYPE, BODY
(48, 2, 3) |''| ClassMethod ┃ ┃ ┃ ┣ DECLARATION, FUNCTION, STATEMENT
(48, 2, 3) |'render'| Identifier ┃ ┃ ┃ ┃ ┣ EXPRESSION, IDENTIFIER, KEY, NAME
(57, 2, 12) |''| BlockStatement ┃ ┃ ┃ ┃ ┣ FUNCTION, BODY, STATEMENT, BLOCK, SCOPE, VALUE
(63, 3, 5) |''| ReturnStatement ┃ ┃ ┃ ┃ ┃ ┣ STATEMENT, RETURN
(78, 4, 7) |''| JSXElement ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(78, 4, 7) |''| JSXOpeningElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(79, 4, 8) |'View'| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ UNANNOTATED
(84, 4, 13) |'\n '| JSXText ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(93, 5, 9) |''| JSXElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(93, 5, 9) |''| JSXOpeningElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(94, 5, 10) |'Text'| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(99, 5, 15) |''| JSXAttribute ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(99, 5, 15) |'testID'| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(106, 5, 22) |'Text'| StringLiteral ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ ┗ EXPRESSION, LITERAL, STRING
(113, 5, 29) |'text'| JSXText ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(117, 5, 33) |''| JSXClosingElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(119, 5, 35) |'Text'| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ ┗ UNANNOTATED
(124, 5, 40) |'\n '| JSXText ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(131, 6, 7) |''| JSXClosingElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(133, 6, 9) |'View'| JSXIdentifier ┗ ┗ ┗ ┗ ┗ ┗ ┗ ┗ ┗ UNANNOTATED
UASTv2
(0, 1, 1) |''| File FILE
(0, 1, 1) |''| Program ┣ MODULE
(0, 1, 1) |''| ClassDeclaration ┃ ┣ DECLARATION, TYPE, STATEMENT
(6, 1, 7) |'TestIdTestApp'| Identifier ┃ ┃ ┣ EXPRESSION, IDENTIFIER, TYPE, NAME
(28, 1, 29) |''| MemberExpression ┃ ┃ ┣ QUALIFIED, EXPRESSION, IDENTIFIER, TYPE, BASE
(28, 1, 29) |'React'| Identifier ┃ ┃ ┃ ┣ EXPRESSION, IDENTIFIER
(34, 1, 35) |'Component'| Identifier ┃ ┃ ┃ ┗ EXPRESSION, IDENTIFIER
(44, 1, 45) |''| ClassBody ┃ ┃ ┣ TYPE, BODY
(48, 2, 3) |''| ClassMethod ┃ ┃ ┃ ┣ DECLARATION, FUNCTION, STATEMENT
(48, 2, 3) |'render'| Identifier ┃ ┃ ┃ ┃ ┣ EXPRESSION, IDENTIFIER, KEY, NAME
(57, 2, 12) |''| BlockStatement ┃ ┃ ┃ ┃ ┣ STATEMENT, BLOCK, SCOPE, FUNCTION, BODY, VALUE
(63, 3, 5) |''| ReturnStatement ┃ ┃ ┃ ┃ ┃ ┣ STATEMENT, RETURN
(78, 4, 7) |''| JSXElement ┃ ┃ ┃ ┃ ┃ ┃ ┣ INCOMPLETE
(78, 4, 7) |''| JSXOpeningElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ BLOCK, INCOMPLETE
(79, 4, 8) |''| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ IDENTIFIER, INCOMPLETE
(84, 4, 13) |''| JSXText ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(93, 5, 9) |''| JSXElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ INCOMPLETE
(93, 5, 9) |''| JSXOpeningElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ BLOCK, INCOMPLETE
(94, 5, 10) |''| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ IDENTIFIER, INCOMPLETE
(99, 5, 15) |''| JSXAttribute ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ INCOMPLETE
(99, 5, 15) |''| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ IDENTIFIER, INCOMPLETE
(106, 5, 22) |'"Text"'| StringLiteral ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ ┗ EXPRESSION, LITERAL, STRING
(113, 5, 29) |''| JSXText ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(117, 5, 33) |''| JSXClosingElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(119, 5, 35) |''| JSXIdentifier ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ ┗ IDENTIFIER, INCOMPLETE
(124, 5, 40) |''| JSXText ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(131, 6, 7) |''| JSXClosingElement ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ UNANNOTATED
(133, 6, 9) |''| JSXIdentifier ┗ ┗ ┗ ┗ ┗ ┗ ┗ ┗ ┗ IDENTIFIER, INCOMPLETE
Should be easy to fix because all positional information is saved.
drivers are v1.2.0 and v.2.6.0
Activity
zurk commentedon Feb 13, 2019
Also, I am not sure if we can count JSX as the same language like JS. Can I kindly ask you do give some understanding why is it so?
zurk commentedon Feb 19, 2019
If you want to reproduce this trees:
Python Code
bzz commentedon Feb 22, 2019
I will get back to this, as soon as driver is migrated to the latest SDK version and all the missing annotations are added (#59 #56)
bzz commentedon Mar 3, 2019
@zurk the second example you gave uses bblfsh protocol.v2 but it is in "annotated" mode, or equivalent of
bblfsh-cli -m annotated.Full UASTv2, which is a "semantic" mode, is only supported by bblfsh/python-client#128
So here is an output of your script with 1 line modified to play better in this mode:
The only change is
and, as you can see, now it includes the text of all
JSXIdentifiers which are all haveIdentifierrole.From my experience,
bblfsh-cliis the best way to check the UAST structure, so you could see how Semantic USATv2 schema looks like and adapt your client code for it (hint: there is not going to betokenfield anywhere in it, Identifiers have only names)bzz commentedon Mar 3, 2019
To your second question
Long story short: it depends on the convention :)
In
enryusing a CLI you can quickly verify that JSX is a different language from the JavaScriptlanguage: JSXbut in bblfsh - there is no driver for this language and so the parsing will fail, until the client manually overrides it to be parsed by javascript driver. In CLI that can be done withbblfsh-sdk -l javascript <your-file>.jsx.So that way, on bblfsh side a single driver now does support multiple languages which makes sense (e.g as there is no such language as JavaScript - there are many ECMAScript language standards that all are parsed by the same tool that you mention
babel, including JSX though the plugin) - this fact is not well documented right now BUT we are looking to change that in the Q2.If you are interested in sneak-peeking into the future - there is a proposal in RFC stage on project's mailing list for language aliases support that covers exactly this problem.
Let me know if that answers your questions!
zurk commentedon Mar 4, 2019
Answering to #58 (comment)
Well, I still do not see tokens for
JSXTextwhich are present in UASTv1 example. Is it a bug or it was removed on purpose?If you are worried about style-analyzer I think we will not use the annotated layer. We have an implementation for code tokenizer based on UAST tokens. So, we actually don't need just identifiers but all tokens that UAST have.
But for sourced-ml package adaptation, it is a good feature for sure 👍
About JSX #58 (comment)
Thanks for the clarification, now I wonder how lookout deals with it... Going to ask in https://github.com/src-d/lookout.
bzz commentedon Mar 5, 2019
Would you be so kind to also check that it in the CLI following the instructions that I posted above and let me know if you think something is missing in there?
I belive lookout does not add anything to that and is just using
enryto detect language ifIncludeLanguageswas set.Right now
bblfshdis adapted to accept enry names so difference likeC#(enry) vscsharp(bblfsh driver) is mitigated but e.g in case of.jsxI'm almost sure it will not get UAST as it must havejavascriptset as language in the request.zurk commentedon Mar 5, 2019
bblfsh-cliworks as expected.Ok, I think that some tokens were missing because I use old and possibly incompatible python client.
For me this issue is solved, thanks @bzz! Feel free to close it.