Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Instantiation of HoistableDeclarations prior to Evaluation #42

Closed
bmeck opened this issue Aug 14, 2017 · 6 comments
Closed

Instantiation of HoistableDeclarations prior to Evaluation #42

bmeck opened this issue Aug 14, 2017 · 6 comments

Comments

@bmeck
Copy link

bmeck commented Aug 14, 2017

All HoistableDeclarations are instantiated and available at the time of hooking up bindings:

https://tc39.github.io/ecma262/#sec-moduledeclarationenvironmentsetup (towards the end you can see the list of things that gets hoisted prior to eval)

// a.mjs
// this file never evaluates to any meaningful effect

// it kicks off a circular dep on 'b'
import {b_fn} from './b';

// it exports a hoistable delcaration a_fn, this is setup while graph is instantiating
function a_fn() {return b_fn();};
export {a_fn};
// b.mjs
import assert from 'assert';

// grabs 'a'
import {a_fn} from './a';


// it exports a hoistable delcaration b_fn, this is setup while graph is instantiating
const v = {};
function b_fn() {
  return v;
}
export {b_fn};

// evaluation of this line happens before 'a' starts evaluating
// a_fn successfully is called since it was setup during instantiation
assert.strictEqual(a_fn(), v);

The hoistable declarations can also be part of a special form of export default.

@jdalton
Copy link
Member

jdalton commented Aug 14, 2017

Thanks @bmeck!

Can you explain what the current behavior is and what the expected result is?

@bmeck
Copy link
Author

bmeck commented Aug 14, 2017

the strictEqual should pass. v passes through a_fn even though a.mjs has not evaluated yet. all hoistable declarations are allocated prior to beginning evaluation of the ESM graph.

@jdalton
Copy link
Member

jdalton commented Aug 14, 2017

Just to clarify b.mjs should be exporting b_fn right?

Pulling in @benjamn on this since I believe it would be interesting for Reify too.

@bmeck
Copy link
Author

bmeck commented Aug 14, 2017

@jdalton yes, both are exporting prior to evaluating

@jdalton
Copy link
Member

jdalton commented Oct 4, 2017

Cleaning up the issue a bit to remove off topic non-@std/esm implementation bits.
I've got this working locally. The fix is to register setters before the module's compile function is called so that they're available when running the compiled module.

@standard-things standard-things deleted a comment from benjamn Oct 4, 2017
@standard-things standard-things deleted a comment from benjamn Oct 4, 2017
@standard-things standard-things deleted a comment from benjamn Oct 4, 2017
@standard-things standard-things deleted a comment from bmeck Oct 4, 2017
@standard-things standard-things deleted a comment from benjamn Oct 4, 2017
@standard-things standard-things deleted a comment from bmeck Oct 4, 2017
@standard-things standard-things deleted a comment from benjamn Oct 4, 2017
@standard-things standard-things deleted a comment from bmeck Oct 4, 2017
@standard-things standard-things deleted a comment from benjamn Oct 4, 2017
@standard-things standard-things deleted a comment from bmeck Oct 4, 2017
@standard-things standard-things deleted a comment from bmeck Oct 4, 2017
@jdalton
Copy link
Member

jdalton commented Oct 6, 2017

Fixed by ca9716b. Tests 44811ef.

@jdalton jdalton closed this as completed Oct 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants