Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

defvar within function generates two semicolons #48

Closed
mfrawley opened this Issue · 4 comments

4 participants

@mfrawley

From your REPL demo:

(defun alert-hello (planet-name)
(defvar message (concat "hello " planet-name))
(alert message)
message)

generates:
var alertHello = (function(planetName) {
// planetName:required
var message = ("hello " + planetName);;
alert(message);
return message;
});

@mfrawley

btw I love the project, was working on something v. similar (forked from lava-script by Evan Murphy) till I found this. If I can help out I will.

@matthewp matthewp referenced this issue from a commit in matthewp/sibilant
@matthewp matthewp Fixes issue #48, double semi-colons when defvar used within defun
The problem is that defun calls macros.lamba which automatically inserts the semicolon on the end of lines. Since defvar also inserts the semicolon you wind up with 2 semicolons. This isn't a problem in JavaScript, just a prettiness problem.

The fix is to check to see if the last character in the statement is a semicolon, and if it is to not do the insertion.
47f69e4
@matthewp matthewp referenced this issue from a commit in matthewp/sibilant
@matthewp matthewp Related to #48, don't want to run translate(stmt) twice. 2a583b4
@matthewp

That pull request fixes the issue.

@dubiousdavid

http://sibilantjs.info still produces this error.

(defun test ()
 (defvar x [])
 x)

produces:

var test = (function() {
  var x = [  ];;
  return x;
});
@jbr
Owner

website updated

@jbr jbr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.