Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuckleScript produces syntactically incorrect js code #1692

Closed
jmid opened this issue Jun 8, 2017 · 0 comments
Closed

BuckleScript produces syntactically incorrect js code #1692

jmid opened this issue Jun 8, 2017 · 0 comments

Comments

@jmid
Copy link

jmid commented Jun 8, 2017

Consider the following program:

$ cat issues-bs/syntax3.ml
(let _s = (let h = true in fun x -> let j = fun f -> true in fun f -> 0) "" "" in 0)

It is vanilla OCaml which can be compiled and run with the bytecode compiler:

$ ocamlc -o issues-bs/syntax3.byte issues-bs/syntax3.ml
File "issues-bs/syntax3.ml", line 1, characters 15-16:
Warning 26: unused variable h.
File "issues-bs/syntax3.ml", line 1, characters 40-41:
Warning 26: unused variable j.
$ ./issues-bs/syntax3.byte
$

However BuckleScript compiles it into what my node installation (and SpiderMonkey) considers syntactically incorrect JavaScript:

$ ./node_modules/bs-platform/bin/bsc.exe issues-bs/syntax3.ml
File "issues-bs/syntax3.ml", line 1, characters 15-16:
Warning 26: unused variable h.
File "issues-bs/syntax3.ml", line 1, characters 40-41:
Warning 26: unused variable j.
$ cat issues-bs/syntax3.js 
// Generated by BUCKLESCRIPT VERSION 1.7.4, PLEASE EDIT WITH CARE
'use strict';


function () {
      return function () {
        return 0;
      };
    }("")("");

/*  Not a pure module */
$ node issues-bs/syntax3.js 
/the/path/to/the/dir/issues-bs/syntax3.js:5
function () {
         ^
SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:390:7)
    at startup (bootstrap_node.js:150:9)
$ js17 issues-bs/syntax3.js 
issues-bs/syntax3.js:5:0 SyntaxError: function statement requires a name:
issues-bs/syntax3.js:5:0 function () {
issues-bs/syntax3.js:5:0 .........^

This is with BuckleScript 1.7.4 (Using OCaml4.02.3+BS ) and node v6.10.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants