For declarative modules, where does declare get set?

22 views
Skip to first unread message

s...@samuelberney.com

unread,
Jan 19, 2016, 7:39:15 PM1/19/16
to SystemJS
For declarative modules, where does declare get set? I see one source which changes that value at https://github.com/systemjs/systemjs/blob/master/lib/register.js#L111 , but I don't see anything that calls System.register anywhere.

I see an explicit setting of declare for aliased modules here https://github.com/systemjs/systemjs/blob/master/lib/alias.js#L21 , but that's not the general place it happens.

Do transpilers produce code that maps to System.register(, , becomesDeclare) ? How does that work? Is whatever that format is the 'register' format I see in a number of places in the SystemJS source?

I see how dynamic modules work, but I can't see where this line is getting its function from: https://github.com/systemjs/systemjs/blob/8a688f7d21618967f382884caed8badd4d2012b2/lib/register.js#L273

tita...@gmail.com

unread,
Jan 20, 2016, 12:29:49 PM1/20/16
to SystemJS, s...@samuelberney.com
For anyone wondering this, they will find the answer here: https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained

s...@samuelberney.com

unread,
Jan 21, 2016, 3:38:06 PM1/21/16
to SystemJS, s...@samuelberney.com, tita...@gmail.com
That's my other google account, forgot to switch accounts.

Anyway, I actually am confused again. Since transpiled code gets evaluated with System.register overridden ( https://github.com/systemjs/systemjs/blob/master/dist/system.src.js#L361 ) to ignore the usual chain of things happening, I don't see how any transpiled code works ever. Where does the overridden System.register kick things into `defined`?

And furthermore, where on earth does anything ever get put into the module table, ever? finishLoad shouldn't put things in the module table except with the debug mode (execute: false). Yet, all the modules go into the module table eventually ...

I could imagine that .declare() involves some kind of System.set, or perhaps during the transpilation process System.set gets called, but I don't know how dynamic modules work, it turns out.

Here's how I would describe the loading process:

User calls 'import', which kicks in the ES6-module-loader Locate-Fetch-Translate-Instantiate cycle. Each part of the cycle calls the SystemJS chains named for the step. This does a bunch of logic, and ultimately more or less sets some loads, entries, and dependencies. LinkSets get built. Dependencies begin their resolution process at the top level, where the es6-module-loader enters a `requestLoad` cycle that kicks into the Locate-Fetch-Translate-Instantiate cycle. .execute() and .declare() functions get defined for dynamic and declarative modules, respectively (although how declarative modules can go through this process with register overridden, I don't know). The es6-module-loader has a module.execute() created by instantiate which invokes the linker. The linker needs everything `defined`, and, working on a linkSet, turns dependencies into a tree of alternating dynamic-declarative modules (I'm not 100% sure why that is necessary). The dependencies are evaluated. The module is evaluated. The linkSet is resolved. LinkSets are updated. `defined` is cleaned. And, somehow, the module gets put into the module table. ???
Reply all
Reply to author
Forward
0 new messages