Skip to content

Commit 76f7601

Browse files
guybedfordMylesBorins
authored andcommittedNov 16, 2020
module: fix builtin reexport tracing
PR-URL: #35500 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 370f8e3 commit 76f7601

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed
 

‎lib/internal/modules/esm/translators.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function lazyTypes() {
2424
}
2525

2626
const { readFileSync } = require('fs');
27-
const { extname } = require('path');
27+
const { extname, isAbsolute } = require('path');
2828
const {
2929
stripBOM,
3030
loadNativeModule
@@ -247,7 +247,8 @@ function cjsPreparseModuleExports(filename) {
247247
continue;
248248
}
249249
const ext = extname(resolved);
250-
if (ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) {
250+
if ((ext === '.js' || ext === '.cjs' || !CJSModule._extensions[ext]) &&
251+
isAbsolute(resolved)) {
251252
const { exportNames: reexportNames } = cjsPreparseModuleExports(resolved);
252253
for (const name of reexportNames)
253254
exportNames.add(name);
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fixtures = require('../common/fixtures');
5+
const { spawn } = require('child_process');
6+
const assert = require('assert');
7+
8+
const entry = fixtures.path('/es-modules/builtin-imports-case.mjs');
9+
10+
const child = spawn(process.execPath, [entry]);
11+
child.stderr.setEncoding('utf8');
12+
let stdout = '';
13+
child.stdout.setEncoding('utf8');
14+
child.stdout.on('data', (data) => {
15+
stdout += data;
16+
});
17+
child.on('close', common.mustCall((code, signal) => {
18+
assert.strictEqual(code, 0);
19+
assert.strictEqual(signal, null);
20+
assert.strictEqual(stdout, 'ok\n');
21+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { strictEqual } from 'assert';
2+
import './dep1.js';
3+
import { assert as depAssert } from './dep2.js';
4+
strictEqual(depAssert.strictEqual, strictEqual);
5+
console.log('ok');

‎test/fixtures/es-modules/dep1.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('assert');

‎test/fixtures/es-modules/dep2.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.assert = require('assert');

0 commit comments

Comments
 (0)
Please sign in to comment.