Giter Club home page Giter Club logo

interface's Introduction

Interface

interface's People

Contributors

bpstrngr avatar

Watchers

 avatar

Forkers

okpalandev

interface's Issues

Standardize synchronous circular requires

Synchronous circular requires (commonjs equivalent of static default imports)
are individually edited in some sources (CSSOM, JSDOM),
but a generic pattern can be recognized.

The edits are always a delayed reassignment from dynamic import
(const a=require("a") -> let a;setTimeout(async function expect_hoisted_a()
{import("a").then(({default:module})=>a=module)},3000)
- note that dynamic import is only supported for requires in already async scopes; see issue #9 ),
supported by an equal timeout before the default export of module.exports in the
entry module since the dynamic imports become promise resolutions of hoisted variables
of co-dependent modules stacked lower in the module scope when bundled:

// entry module: 
await new Promise(resolve=>setTimeout(resolve,3000));
export default module.exports;

// dependent module: 
var codependent;
setTimeout(async function expect_hoisted_dependency()
{import("codependent").then(({default:module})=>codependent=module)
},3000);
export default module.exports;

// codependent module: 
import dependent from "dependent";
module.exports={dependent}
export default module.exports;

// bundle: 
var codependent;
setTimeout(async function expect_hoisted_a()
{Promise.resolve(dependency).then(({default:module})=>codependent=module)
},3000);
var dependent={default};
var dependency={default:dependent};
await new Promise(resolve=>setTimeout(resolve,3000));
export default module.exports;

Collecting and awaiting the dynamic import reassignments instead of the arbitrary delay at the end of bundle,
as well as gaining access to rollup's hoisted variable name to recursively ascertain the local reassignments,
or potential modifications to the module hierarchy could be further improvements to this generalization.

An illustrative subject circular dependency graph (CSSOM):
image

Keep dynamic requires synchronous in module

meta/sanitize currently converts dynamic requires to awaited dynamic imports,
along with making their corresponding enclosing functions async.
This was a tradeoff to support conditional dependency (if(true)require()) instead of all being hoisted as a static import to keep them synchronous.

Synchronous internal or peer dependant calls to the resulting asynchronized functions can be edited to be async as well, but this can get complex beyond simple library initializations, in eg. opaque object hierarchies.

Such peers, relying extensively on commonjs's synchronous loading of what are supposed to be modules, may deserve to be deprecated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.