Skip to content
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

Failed to fix formating in JSX #605

Open
zurk opened this issue Feb 13, 2019 · 0 comments
Open

Failed to fix formating in JSX #605

zurk opened this issue Feb 13, 2019 · 0 comments
Labels
format Issues related to format analyzer

Comments

@zurk
Copy link
Contributor

zurk commented Feb 13, 2019

JSX is a syntax extension to JavaScript. It can be converted to a proper JS with babel tool

The JSX code looks like:
class TestIdTestApp extends React.Component {
  render() {
    return (
      <View>
        <Text testID="Text">text</Text>
      </View>
    );
  }
}
UASTv1 for this code looks like
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           

You can see that formatting sequences line \n in position (84, 4, 13) have a UAST node. I think this node originally present in AST. So we do not label corresponding virtual nodes.

That means that we do not fix any format mistake in the JSX.

P.S.:

UASTv2 looks like
(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   

No idea why but we are missing all tokens from JSX. I create an issue about it bblfsh/javascript-driver#58
Also, ask why we count JSX as JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
format Issues related to format analyzer
Projects
None yet
Development

No branches or pull requests

1 participant