Closed nidorx closed 2 years ago
When converting AST to Javascript, when finding an EmptyStmt, a semicolon is being added.
EmptyStmt
The problem with this is that a new AST generated from this original conversion will result in different output than the previous one.
The test below, in the current version, results in an error.
a; ; after 2 .JS() will be a; ;; ;;
a; ;
.JS()
a; ;; ;;
function x() { let a = 33; ; } after 2 .JS() will be function x() { let a = 33; ;; ;; }
function x() { let a = 33; ; }
function x() { let a = 33; ;; ;; }
The fix just ignores when an item from a BlockStmt is an EmptyStmt
BlockStmt
func TestEmptyStmtToJs(t *testing.T) { var tests = []struct { input string output string }{ {"a; ;", "a; "}, {"function x() { let a = 33; ; }", "function x () { let a = 33; }; "}, } for _, tt := range tests { t.Run(tt.input, func(t *testing.T) { ast, err := Parse(parse.NewInputString(tt.input), Options{}) if err != io.EOF { test.Error(t, err) } ast2, err := Parse(parse.NewInputString(ast.JS()), Options{}) if err != io.EOF { test.Error(t, err) } test.String(t, ast2.JS(), tt.output) }) } }
Thanks!
When converting AST to Javascript, when finding an
EmptyStmt
, a semicolon is being added.The problem with this is that a new AST generated from this original conversion will result in different output than the previous one.
The test below, in the current version, results in an error.
a; ;
after 2.JS()
will bea; ;; ;;
function x() { let a = 33; ; }
after 2.JS()
will befunction x() { let a = 33; ;; ;; }
The fix just ignores when an item from a
BlockStmt
is anEmptyStmt