Skip to content

Commit

Permalink
module: fix builtin reexport tracing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
guybedford authored and MylesBorins committed Nov 16, 2020
1 parent 370f8e3 commit 76f7601
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function lazyTypes() {
}

const { readFileSync } = require('fs');
const { extname } = require('path');
const { extname, isAbsolute } = require('path');
const {
stripBOM,
loadNativeModule
Expand Down Expand Up @@ -247,7 +247,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);
Expand Down
21 changes: 21 additions & 0 deletions test/es-module/test-esm-cjs-builtins.js
Original file line number Diff line number Diff line change
@@ -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');
}));
5 changes: 5 additions & 0 deletions test/fixtures/es-modules/builtin-imports-case.mjs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions test/fixtures/es-modules/dep1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('assert');
1 change: 1 addition & 0 deletions test/fixtures/es-modules/dep2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.assert = require('assert');

0 comments on commit 76f7601

Please sign in to comment.