Skip to content

Js.Unsafe.get compiles to dot notation even when that's invalid #330

@wiml

Description

@wiml

I'm interfacing with other code which hands me JS objects used as general purpose (string -> x) maps, and I've found that looking up entries using get can compile to invalid Javascript. In this example:

let foo s =
  Js.Unsafe.get s "{foo bar}"
let bar s =
  Js.Unsafe.get s (Js.string ("{foo "^"bar}"))
;;

Js.Unsafe.global##foo <- Js.wrap_callback(foo);;
Js.Unsafe.global##bar <- Js.wrap_callback(bar);;

the function foo compiles to code like {return _a_.{foo bar}}, which obviously doesn't work. The function bar results in code which constructs an ocaml string object at runtime and then calls return _a_[_c_.toString()].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions