X Tutup
Skip to content

Move parentheses usage logic from AST to printer #665

@ark120202

Description

@ark120202
  • Having specific nodes for parentheses doesn't make much sense for me. Parentheses are supposed to be a tip to parser, in AST we don't have any ambiguities where parentheses matter:
     (1 + 2) + 3
    
     BinaryExpression:
     	left:
     		BinaryExpression:
     			left: 1
     			right: 2
     	right: 3
    
     1 + (2 + 3)
    
     BinaryExpression:
     	left: 1
     	right:
     		BinaryExpression:
     			left: 2
     			right: 3
    
  • It would make code cleaner and easier to maintain, since to fix issues like Fix for property access on string and array literals #650 we won't have to duplicate logic everywhere
  • It would make code less bug-prone, since we'll have less invalid states in AST
  • Most of JS parsers (babel, acorn, esprima) do it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup