| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8d33f78 commit fdf5028
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1360,7 +1360,10 @@ function loadESMFromCJS(mod, filename) { | |||
| 1360 | 1360 | messagePrefix = `${from} is loading ES Module ${to} using require().\n`; | |
| 1361 | 1361 | } | |
| 1362 | 1362 | } | |
| 1363 | - emitExperimentalWarning('Support for loading ES Module in require()', messagePrefix); | ||
| 1363 | + emitExperimentalWarning('Support for loading ES Module in require()', | ||
| 1364 | + messagePrefix, | ||
| 1365 | + undefined, | ||
| 1366 | + parent?.require); | ||
| 1364 | 1367 | const { | |
| 1365 | 1368 | wrap, | |
| 1366 | 1369 | namespace, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -255,14 +255,20 @@ function slowCases(enc) { | |||
| 255 | 255 | } | |
| 256 | 256 | } | |
| 257 | 257 | ||
| 258 | - function emitExperimentalWarning(feature, messagePrefix) { | ||
| 258 | + /** | ||
| 259 | + * @param {string} feature Feature name used in the warning message | ||
| 260 | + * @param {string} messagePrefix Prefix of the warning message | ||
| 261 | + * @param {string} code See documentation of process.emitWarning | ||
| 262 | + * @param {string} ctor See documentation of process.emitWarning | ||
| 263 | + */ | ||
| 264 | + function emitExperimentalWarning(feature, messagePrefix, code, ctor) { | ||
| 259 | 265 | if (experimentalWarnings.has(feature)) return; | |
| 260 | 266 | experimentalWarnings.add(feature); | |
| 261 | 267 | let msg = `${feature} is an experimental feature and might change at any time`; | |
| 262 | 268 | if (messagePrefix) { | |
| 263 | 269 | msg = messagePrefix + msg; | |
| 264 | 270 | } | |
| 265 | - process.emitWarning(msg, 'ExperimentalWarning'); | ||
| 271 | + process.emitWarning(msg, 'ExperimentalWarning', code, ctor); | ||
| 266 | 272 | } | |
| 267 | 273 | ||
| 268 | 274 | function filterDuplicateStrings(items, low) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,35 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This checks the warning and the stack trace emitted by the require(esm) | ||
| 4 | + // experimental warning. It can get removed when `require(esm)` becomes stable. | ||
| 5 | + | ||
| 6 | + require('../common'); | ||
| 7 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 8 | + const fixtures = require('../common/fixtures'); | ||
| 9 | + const assert = require('assert'); | ||
| 10 | + | ||
| 11 | + spawnSyncAndAssert(process.execPath, [ | ||
| 12 | + '--trace-warnings', | ||
| 13 | + fixtures.path('es-modules', 'require-module.js'), | ||
| 14 | + ], { | ||
| 15 | + trim: true, | ||
| 16 | + stderr(output) { | ||
| 17 | + const lines = output.split('\n'); | ||
| 18 | + assert.match( | ||
| 19 | + lines[0], | ||
| 20 | + /ExperimentalWarning: CommonJS module .*require-module\.js is loading ES Module .*message\.mjs/ | ||
| 21 | + ); | ||
| 22 | + assert.strictEqual( | ||
| 23 | + lines[1], | ||
| 24 | + 'Support for loading ES Module in require() is an experimental feature and might change at any time' | ||
| 25 | + ); | ||
| 26 | + assert.match( | ||
| 27 | + lines[2], | ||
| 28 | + /at require \(.*modules\/helpers:\d+:\d+\)/ | ||
| 29 | + ); | ||
| 30 | + assert.match( | ||
| 31 | + lines[3], | ||
| 32 | + /at Object\.<anonymous> \(.*require-module\.js:1:1\)/ | ||
| 33 | + ); | ||
| 34 | + } | ||
| 35 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + require('./message.mjs'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments