Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

esm: refactor dynamic modules #9

Merged
merged 1 commit into from
Nov 21, 2018
Merged

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Oct 8, 2018

Use one module wrap instead of two for the dynamic modules implementation.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@jdalton
Copy link
Member

jdalton commented Oct 8, 2018

What's the gist of the refactor? A sentence or two as a description would do.

const debug = require('util').debuglog('esm');
const ArrayJoin = Function.call.bind(Array.prototype.join);
const ArrayMap = Function.call.bind(Array.prototype.map);

const defaultName = '\u5343\u4e07\u4e0d\u8981\u7528\u8fd9\u4e2a\u53d8\u91cf' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is up with the default name here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A local name has to be bound to the default export, and "do not use this variable or you will be fired" in chinese was suggested to me by @TimothyGu.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devsnek

A local name has to be bound to the default export, and "do not use this variable or you will be fired" in chinese was suggested to me by @TimothyGu.

Would you please add code comments about it and why it's needed. This seems kind of hacky. Are there any other possible ways to tackle this (or APIs we could introduce to better address this)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment. the API we can introduce is what @guybedford is already working on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we could just prefix all names with $ like the old code instead, which I would prefer rather than treating some names differently from others.

@bmeck
Copy link
Member

bmeck commented Oct 8, 2018

@jdalton the original esm loader was using 2 module records for any dynamic module due to a lack of import.meta being available when it was originally written. This moves the dynamic module facade to a single module record by exposing the reflection API off import.meta instead of a completion with a 2nd module record.

Copy link
Member

@bmeck bmeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use special variable names.

const debug = require('util').debuglog('esm');
const ArrayJoin = Function.call.bind(Array.prototype.join);
const ArrayMap = Function.call.bind(Array.prototype.map);

const defaultName = '\u5343\u4e07\u4e0d\u8981\u7528\u8fd9\u4e2a\u53d8\u91cf' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we could just prefix all names with $ like the old code instead, which I would prefer rather than treating some names differently from others.

lib/internal/modules/esm/create_dynamic_module.js Outdated Show resolved Hide resolved
@devsnek devsnek force-pushed the refactor/dynamic-modules branch 2 times, most recently from c84a41b to 7bd1e1c Compare October 10, 2018 15:06
Copy link
Contributor

@MylesBorins MylesBorins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I would also like to see this upstreamed

@devsnek devsnek removed the blocked label Nov 7, 2018
@guybedford
Copy link
Contributor

@devsnek were you planning to merge this after sorting out the rebase approach then? There don't seem to be any conflicts though so could be worth merging already too.

@devsnek
Copy link
Member Author

devsnek commented Nov 8, 2018

@guybedford we shouldn't land anything when our HEAD is this far behind nodejs/node~HEAD. once we're more up to date it should be safe to start landing things again.

@MylesBorins
Copy link
Contributor

MylesBorins commented Nov 8, 2018

@devsnek didn't we have consensus to do a manual rebase?

edit: also since we had consensus to upstream, would it make more sense to simply open this PR on the main repo?

@devsnek
Copy link
Member Author

devsnek commented Nov 8, 2018

@MylesBorins oh i wasn't aware we had agreed to do that. i guess i can try to do the rebase this weekend then unless someone else is feeling more masochistic...

@MylesBorins
Copy link
Contributor

rebase opened in #13

I think this could potentially just be moved to nodejs/node and picked up in a future rebase... thoughts?

@devsnek
Copy link
Member Author

devsnek commented Nov 8, 2018

I don't quite understand why we're maintaining the upstream if we're just going to replace it

@guybedford
Copy link
Contributor

It may indeed make merging easier if we don't upstream.

@MylesBorins
Copy link
Contributor

@devsnek because people are still using it. Unless we plan to completely remove it anything we can do to keep the delta smaller will make a future merge easier imho

@ljharb

This comment has been minimized.

@MylesBorins MylesBorins changed the base branch from master to modules-lkgr November 9, 2018 04:18
@MylesBorins
Copy link
Contributor

MylesBorins commented Nov 9, 2018

@ljharb I was suggesting that this specific PR could land directly on master.

I've retargeting this against modules-lkgr and rebased. Will land if CI is green

CI: https://ci.nodejs.org/job/node-test-pull-request/18433/

@MylesBorins
Copy link
Contributor

Failure on arm

06:05:25 not ok 311 known_issues/test-vm-timeout-escape-nexttick
06:05:25   ---
06:05:25   duration_ms: 1.235
06:05:25   severity: fail
06:05:25   stack: |-

Rerunning https://ci.nodejs.org/job/node-test-commit-arm-fanned/4210/

@MylesBorins
Copy link
Contributor

rebased against modules-lkgr

ci: https://ci.nodejs.org/job/node-test-pull-request/18832/

@MylesBorins MylesBorins merged commit cf533af into modules-lkgr Nov 21, 2018
@MylesBorins
Copy link
Contributor

CI is green 🎉

landed in cf533af

@devsnek do you object to me opening this upstream? I think it is worth minimizing the delta if it doesn't change any behavior

MylesBorins added a commit that referenced this pull request Nov 30, 2018
This is a change from the ecmascript-modules fork.
There is no change to behavior and we would like to
upstream to reduce the delta between our repos.

Refs: https://github.com/nodejs/ecmascript-modules#9

PR-URL: nodejs/node#24560
Refs: #9
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
@MylesBorins
Copy link
Contributor

This landed upstream in 2931c50

@devsnek devsnek deleted the refactor/dynamic-modules branch November 30, 2018 21:45
BridgeAR pushed a commit to nodejs/node that referenced this pull request Dec 5, 2018
This is a change from the ecmascript-modules fork.
There is no change to behavior and we would like to
upstream to reduce the delta between our repos.

Refs: https://github.com/nodejs/ecmascript-modules#9

PR-URL: #24560
Refs: nodejs/ecmascript-modules#9
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
refack pushed a commit to refack/node that referenced this pull request Jan 14, 2019
This is a change from the ecmascript-modules fork.
There is no change to behavior and we would like to
upstream to reduce the delta between our repos.

Refs: https://github.com/nodejs/ecmascript-modules#9

PR-URL: nodejs#24560
Refs: nodejs/ecmascript-modules#9
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
BethGriggs pushed a commit to nodejs/node that referenced this pull request Feb 12, 2019
This is a change from the ecmascript-modules fork.
There is no change to behavior and we would like to
upstream to reduce the delta between our repos.

Refs: https://github.com/nodejs/ecmascript-modules#9

PR-URL: #24560
Refs: nodejs/ecmascript-modules#9
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Feb 28, 2019
This is a change from the ecmascript-modules fork.
There is no change to behavior and we would like to
upstream to reduce the delta between our repos.

Refs: https://github.com/nodejs/ecmascript-modules#9

PR-URL: #24560
Refs: nodejs/ecmascript-modules#9
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants