mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
Split `module.link(linker)` into two synchronous step `sourceTextModule.linkRequests()` and `sourceTextModule.instantiate()`. This allows creating vm modules and resolving the dependencies in a complete synchronous procedure. This also makes `syntheticModule.link()` redundant. The link step for a SyntheticModule is no-op and is already taken care in the constructor by initializing the binding slots with the given export names. PR-URL: https://github.com/nodejs/node/pull/59000 Refs: https://github.com/nodejs/node/issues/37648 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
35 lines
815 B
JavaScript
35 lines
815 B
JavaScript
'use strict';
|
|
|
|
// Flags: --experimental-vm-modules --js-source-phase-imports
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { SourceTextModule } = require('vm');
|
|
const test = require('node:test');
|
|
|
|
test('deep linking', async function depth() {
|
|
const foo = new SourceTextModule('export default 5');
|
|
foo.linkRequests([]);
|
|
foo.instantiate();
|
|
|
|
function getProxy(parentName, parentModule) {
|
|
const mod = new SourceTextModule(`
|
|
import ${parentName} from '${parentName}';
|
|
export default ${parentName};
|
|
`);
|
|
mod.linkRequests([parentModule]);
|
|
mod.instantiate();
|
|
return mod;
|
|
}
|
|
|
|
const bar = getProxy('foo', foo);
|
|
const baz = getProxy('bar', bar);
|
|
const barz = getProxy('baz', baz);
|
|
|
|
await barz.evaluate();
|
|
|
|
assert.strictEqual(barz.namespace.default, 5);
|
|
});
|