module: fix builtin reexport tracing

PR-URL: https://github.com/nodejs/node/pull/35500
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Guy Bedford 2020-10-04 07:34:15 -07:00
parent db4e70141d
commit 5e605c0dd9
5 changed files with 31 additions and 2 deletions

View File

@ -24,7 +24,7 @@ function lazyTypes() {
}
const { readFileSync } = require('fs');
const { extname } = require('path');
const { extname, isAbsolute } = require('path');
const {
stripBOM,
loadNativeModule
@ -244,7 +244,8 @@ function cjsPreparseModuleExports(filename) {
continue;
}
const ext = extname(resolved);
if (ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) {
if ((ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) &&
isAbsolute(resolved)) {
const { exportNames: reexportNames } = cjsPreparseModuleExports(resolved);
for (const name of reexportNames)
exportNames.add(name);

View File

@ -0,0 +1,21 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const { spawn } = require('child_process');
const assert = require('assert');
const entry = fixtures.path('/es-modules/builtin-imports-case.mjs');
const child = spawn(process.execPath, [entry]);
child.stderr.setEncoding('utf8');
let stdout = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
stdout += data;
});
child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(stdout, 'ok\n');
}));

View File

@ -0,0 +1,5 @@
import { strictEqual } from 'assert';
import './dep1.js';
import { assert as depAssert } from './dep2.js';
strictEqual(depAssert.strictEqual, strictEqual);
console.log('ok');

1
test/fixtures/es-modules/dep1.js vendored Normal file
View File

@ -0,0 +1 @@
module.exports = require('assert');

1
test/fixtures/es-modules/dep2.js vendored Normal file
View File

@ -0,0 +1 @@
exports.assert = require('assert');