Ticket #8 (closed defect)

Opened 16 years ago

Last modified 16 years ago

bad parenthesization in pretty-printing

Reported by: dherman Owned by: dherman
Priority: major Milestone:
Component: dherman/javascript.plt Keywords:
Cc: Version:
Racket Version: 4.0


Dave Gurnell wrote:

The following code:

   #lang scheme/base

   (require (planet "syntax/sexp.ss" ("dherman" "javascript.plt" 5))
            (planet "syntax/pretty-print.ss" ("dherman" "javascript.plt" 5)))

   (pretty-print (sexp->SourceElement '((function (a b) (return (+ a b))) 1 2)))

prints out:

   function(a, b) {
       return a + b;
   }(1, 2);

when I think the correct JS should contain a parenthesised function block:

   (function(a, b) {
       return a + b;
   })(1, 2);

I got this working by making the method-call clause of sexp->Expression wrap a ParenExpression? around the method when the method is a FunctionExpression?:

      ; ...
      [(method args ...)
       (let ([method-expr (sexp->Expression method)])
         (if (FunctionExpression? method-expr)
             (make-CallExpression #f (make-ParenExpression #f method-expr) (map sexp->Expression args))
             (make-CallExpression #f method-expr (map sexp->Expression args))))]
      ; ...

Does that seem right to you?

Change History

Changed 16 years ago by dherman

  • status changed from new to closed
  • pltversion set to 4.0

Fixed in 6:6.

Note: See TracTickets for help on using tickets.