LivelyKernel / LivelyKernel/lively4-core

Support Circular Dependencies

Open
#93 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

comp: module system effort3: hard (weeks) P2: required type: feature
Dominant language
JavaScript
Stars
89
Forks
25
PR merge metrics
No merged PRs in 30d

Description

Our babel plugin for variable recordering is currently not capable of handling circular imports properly.

Circular dependencies are solved in SystemJS via their module rewriting.
To be specific, SystemJS uses local variables to represent import bindings.
These variables are set as specified in the `setters` functions.
```JavaScript
var html, pt;
return {
setters: [function (_htmlJs) {
html = _htmlJs.default;
}, function (_graphicsJs) {
pt = _graphicsJs.pt;
}],
execute: function () {
_recorder_._05580698383529998.html = html;
_recorder_._05580698383529998.pt = pt;

class ContextMenu {
[...]
```
`setters` are generated once for each import.

If we now have a circular dependency, that variable is initially set to `undefined`.
Then, the module's `execute` function runs, producing some exports.
These exports are then used to load the circular dependent module properly.
Afterwards the exports of the circular dependent module are set again with the `setters` functions.
However, the module's `execute` does not run again.
Thus, our variable recorder field are not assigned again.
They are only assigned in the module's first run with all values of imports being `undefined`.

---

We have to rewrite the module-scoped variables in a different way.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Babel plugin for variable reordering and compare its handling with the SystemJS module rewriting and setters described here. Done means circular imports no longer leave variable recorder fields assigned only from their initial undefined values, and the dependent module receives the later export values.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.