Fable
Fable copied to clipboard
error when aliasing a Global value
Description
Creating a top-level binding to a Global
value with the same name causes a reference error
Uncaught ReferenceError: Cannot access 'self' before initialization
Repro code
open Fable.Core
type Exports =
[<Global>]
static member self: obj = nativeOnly
static member x: int = 1
// this line generates: export const self = self;
let self = Exports.self
// this line generates: const self = self;
// let private self = Exports.self
https://fable.io/repl/#?code=PYBwpgdgBAYghgIwDZgHQGFgCcwChcAuAnuFAKIAeI2BAzlALy5QtQDaAPAOJLAJxIAfAF1mrWgTgEAlgGMoAWzAKEYLFFpgkAMwBcUPgCtGUCFOkA3MAHkISImJYTz8pSrVQK+6RAImAjPgofpo6JpTUWHSoodq4wVAA+rHhVDS0MVraQA&html=Q&css=Q
Expected and actual results
Ideally, this situation would either be a compiler error or create an shadowed aliased value. In local scopes, a similar reference is aliased locally:
let y () =
let self = Exports.self
self
export function y() {
const self_1 = self;
return self_1;
}
For public toplevel fields, which are automatically exported, I'm not sure how it should behave.
Related information
- Fable version:
4.22.0
- Operating system OSX