| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 04eaa5c commit aa2be4b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -289,6 +289,8 @@ function createCJSModuleWrap(url, source, isMain, loadCJS = loadCJSModule) { | |||
| 289 | 289 | // In case the source was not provided by the `load` step, we need fetch it now. | |
| 290 | 290 | source = stringify(source ?? getSource(new URL(url)).source); | |
| 291 | 291 | ||
| 292 | + maybeCacheSourceMap(url, source); | ||
| 293 | + | ||
| 292 | 294 | const { exportNames, module } = cjsPreparseModuleExports(filename, source); | |
| 293 | 295 | cjsCache.set(url, module); | |
| 294 | 296 | const namesWithDefault = exportNames.has('default') ? | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -747,6 +747,39 @@ describe('Loader hooks', { concurrency: true }, () => { | |||
| 747 | 747 | assert.strictEqual(signal, null); | |
| 748 | 748 | }); | |
| 749 | 749 | ||
| 750 | + it('should support source maps in commonjs translator', async () => { | ||
| 751 | + const readFile = async () => {}; | ||
| 752 | + const hook = ` | ||
| 753 | + import { readFile } from 'node:fs/promises'; | ||
| 754 | + export ${ | ||
| 755 | + async function load(url, context, nextLoad) { | ||
| 756 | + const resolved = await nextLoad(url, context); | ||
| 757 | + if (context.format === 'commonjs') { | ||
| 758 | + resolved.source = await readFile(new URL(url)); | ||
| 759 | + } | ||
| 760 | + return resolved; | ||
| 761 | + } | ||
| 762 | + }`; | ||
| 763 | + | ||
| 764 | + const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | ||
| 765 | + '--no-warnings', | ||
| 766 | + '--enable-source-maps', | ||
| 767 | + '--import', | ||
| 768 | + `data:text/javascript,${encodeURIComponent(` | ||
| 769 | + import{ register } from "node:module"; | ||
| 770 | + register(${ | ||
| 771 | + JSON.stringify('data:text/javascript,' + encodeURIComponent(hook)) | ||
| 772 | + }); | ||
| 773 | + `)}`, | ||
| 774 | + fixtures.path('source-map/throw-on-require.js'), | ||
| 775 | + ]); | ||
| 776 | + | ||
| 777 | + assert.strictEqual(stdout, ''); | ||
| 778 | + assert.match(stderr, /throw-on-require\.ts:9:9/); | ||
| 779 | + assert.strictEqual(code, 1); | ||
| 780 | + assert.strictEqual(signal, null); | ||
| 781 | + }); | ||
| 782 | + | ||
| 750 | 783 | it('should handle mixed of opt-in modules and non-opt-in ones', async () => { | |
| 751 | 784 | const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ | |
| 752 | 785 | '--no-warnings', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments