mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
This change implements the `Symbol.dispose` key in the `ModuleHooks` class as an alias for deregister. This makes `registerHooks` work with the `using` keyword. Fixes: https://github.com/nodejs/node/issues/63846 Signed-off-by: Remco Haszing <remcohaszing@gmail.com> PR-URL: https://github.com/nodejs/node/pull/63928 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Jacob Smith <jacob@frende.me>
27 lines
709 B
JavaScript
27 lines
709 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { registerHooks } = require('module');
|
|
|
|
// Test that using syntax works.
|
|
{
|
|
// eslint-disable-next-line no-unused-vars
|
|
using hook = registerHooks({
|
|
load: common.mustCall((url, context, nextLoad) => {
|
|
const result = nextLoad(url, context);
|
|
assert.strictEqual(result.source, '');
|
|
return {
|
|
source: 'export const hello = "world"',
|
|
};
|
|
}),
|
|
});
|
|
|
|
const mod = require('../fixtures/empty.js');
|
|
assert.strictEqual(mod.hello, 'world');
|
|
}
|
|
|
|
delete require.cache[require.resolve('../fixtures/empty.js')];
|
|
const mod = require('../fixtures/empty.js');
|
|
assert.deepStrictEqual(mod, {});
|