Skip to content

v12 - Js.typeof or Type.typeof of a @val external function would produce SyntaxError in runtime #7641

@dsiu

Description

@dsiu

Calling Js.typeof or Type.typeof with a @val external function would result in SyntaxError: Unexpected token '=>'. Cannot parse base expression. in runtime. This is happening in rescript-v12.0.0-beta.1 (and any v12 versions generating arrow function) but not in v11.

Found this problem here when I was porting rescript-nodejs to v12.

Putting brackets around the arrow function manually in js like this console.log(typeof (prim => require(prim))) would make it run without SyntaxError.

ReScript Code (Playground) :

@val external require: string => {..} = "require"

// SyntaxError: Unexpected token '=>'. Cannot parse base expression.
Console.log(Js.typeof(require))
Console.log(Type.typeof(require))

// output: "function"
let add = (x,y) => x + y
Console.log(Js.typeof(add))
Console.log(Type.typeof(add))

v12 generated JS:

// Generated by ReScript, PLEASE EDIT WITH CARE

console.log(typeof prim => require(prim));
console.log(typeof prim => require(prim));

function add(x, y) {
  return x + y | 0;
}

console.log(typeof add);
console.log(typeof add);

export {
  add,
}
/*  Not a pure module */

v11 generated JS:

// Generated by ReScript, PLEASE EDIT WITH CARE

console.log(typeof (function (prim) {
        return require(prim);
      }));

console.log(typeof (function (prim) {
        return require(prim);
      }));

function add(x, y) {
  return x + y | 0;
}

console.log(typeof add);
console.log(typeof add);

export {
  add ,
}
/*  Not a pure module */

Thank you for filing! Check list:

  • Is it a bug? Usage questions should often be asked in the forum instead.
  • Concise, focused, friendly issue title & description.
  • A minimal, reproducible example.
  • OS and browser versions, if relevant.
  • Is it already fixed in master? Instructions

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions