Skip to content

Commit

Permalink
JS: fix JS() output with Integer.Identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jan 12, 2024
1 parent 4b768d6 commit 94b6e86
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions js/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ func (n LiteralExpr) JS(w io.Writer) {

// JSON writes JSON to writer.
func (n LiteralExpr) JSON(w io.Writer) error {
if n.TokenType == TrueToken || n.TokenType == FalseToken || n.TokenType == NullToken || n.TokenType == DecimalToken {
if n.TokenType == TrueToken || n.TokenType == FalseToken || n.TokenType == NullToken || n.TokenType == DecimalToken || n.TokenType == IntegerToken {
w.Write(n.Data)
return nil
} else if n.TokenType == StringToken {
Expand Down Expand Up @@ -1996,7 +1996,7 @@ func (n DotExpr) String() string {
// JS writes JavaScript to writer.
func (n DotExpr) JS(w io.Writer) {
lit, ok := n.X.(*LiteralExpr)
group := ok && !n.Optional && lit.TokenType == DecimalToken
group := ok && !n.Optional && (lit.TokenType == DecimalToken || lit.TokenType == IntegerToken)
if group {
w.Write([]byte("("))
}
Expand Down Expand Up @@ -2168,7 +2168,7 @@ func (n UnaryExpr) JS(w io.Writer) {

// JSON writes JSON to writer.
func (n UnaryExpr) JSON(w io.Writer) error {
if lit, ok := n.X.(*LiteralExpr); ok && n.Op == NegToken && lit.TokenType == DecimalToken {
if lit, ok := n.X.(*LiteralExpr); ok && n.Op == NegToken && (lit.TokenType == DecimalToken || lit.TokenType == IntegerToken) {
w.Write([]byte("-"))
w.Write(lit.Data)
return nil
Expand Down
1 change: 1 addition & 0 deletions js/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestJS(t *testing.T) {
{"([,,])=>P", "([,,]) => { return P; };"},
{"(t)=>{//!\n}", "(t) => { //! };"},
{"import();", "import();"},
{"0\n.k", "(0).k;"},
}

re := regexp.MustCompile("\n *")
Expand Down

0 comments on commit 94b6e86

Please sign in to comment.