Skip to content

Inconsistency with mangling of reserved keywords #1152

Closed
@glennsl

Description

@glennsl

This came up when trying to import an es6 module, where the natural way of doing it breaks due to mangling of the reserved keyword default:

external foo': t = "default" [@@bs.module "some-es6-mod"];
let foo = foo';

is compiled into:

var SomeEs6Mod = require("some-es6-mod");
var foo = SomeEs6Mod.$$default;
exports.foo = foo;

This, on the other hand, works:

external foo': Js.t {. default: t } = "some-es6-mod" [@@bs.module];
let foo = foo'##default;

which compiles into:

var Foo$prime = require("some-es6-mod");
var foo = Foo$prime.default;
exports.foo = foo;

As I've been told, the latter case works because in Js.t, anything goes. But these two cases are functionally equivalent, and in the former case the reserved keyword is quoted, not even able to be used as an identifier. This makes the (non-)mangling rules rather counter-intuitive as well as inconsistent.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions