Skip to content

Bindings where @scope has same name as module can result in runtime errors #7478

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

Open
mediremi opened this issue May 16, 2025 · 7 comments
Open

Comments

@mediremi
Copy link
Contributor

mediremi commented May 16, 2025

When a binding's @scope has the same name as a module, the binding's scope is shadowed by the module:

module URL = {  
  @val @scope("URL")
  external revokeObjectURL: string => unit = "revokeObjectURL"
}

URL.revokeObjectURL("some url")
let URL = {};

URL.revokeObjectURL("some url");
@cknitt
Copy link
Member

cknitt commented May 17, 2025

I think this is not a v12 issue per se, it's just that v12 doesn't escape URL with $$ anymore.

If the module name is different, the same problem exists in v11:

module URRL = {  
  @val @scope("URRL")
  external revokeObjectURL: string => unit = "revokeObjectURL"
}

URRL.revokeObjectURL("some url")

https://rescript-lang.org/try?version=v11.1.4&module=esmodule&code=LYewJgrgNgpgBAVQEpIDJwLxwN5zgKDwAEA3AQyjiIGcBjEABxgAoAiZNVgSkLhgA8ALjABOAOwpwRMEiADWMAPIAjAFYxag5KgBccaoJEBLMQHNMAPjgQxRwZjitpshSvWbtrfAF98+DqgAdM7ySmoaWmhs1CDA8BAiUNz4QA

@mediremi
Copy link
Contributor Author

Ah I didn't read the breaking changes section of v12.0.0-alpha.1 carefully enough - I see now that since #6831 we're not escaping browser globals anymore.

I'll update this issue title and description to not be v12 specific 👍

@mediremi mediremi changed the title v12 breaks bindings where @scope has same name as module Bindings where @scope has same name as module can result in runtime errors May 17, 2025
@cometkim

This comment has been minimized.

@cometkim
Copy link
Member

cometkim commented May 18, 2025

I see. It should be something like:

let URL$1 = {};

URL.revokeObjectURL("some url");

export {
  URL$1 as URL,
}

@cometkim
Copy link
Member

Workaround (IMO the correct resolution):

module URL = {  
  @val @scope("globalThis.URL")
  external revokeObjectURL: string => unit = "revokeObjectURL"
}

URL.revokeObjectURL("some url")

@cknitt
Copy link
Member

cknitt commented May 19, 2025

Although this can be broken in basically the same way:

module URL = {  
  @val @scope("globalThis.URL")
  external revokeObjectURL: string => unit = "revokeObjectURL"
}

let globalThis = 0

URL.revokeObjectURL("some url")

@cometkim
Copy link
Member

globalThis should be mangled by default.

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

No branches or pull requests

3 participants