-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4354a1d
commit fe8f181
Showing
10 changed files
with
193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { spawnPromisified } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { strictEqual, match, throws, deepStrictEqual } from 'node:assert'; | ||
import { test } from 'node:test'; | ||
import { mapCallSite } from 'node:module'; | ||
import { getCallSite } from 'node:util'; | ||
|
||
test('module.mapCallSite', async () => { | ||
throws(() => mapCallSite('not an object'), { code: 'ERR_INVALID_ARG_TYPE' }); | ||
deepStrictEqual(mapCallSite([]), []); | ||
throws(() => mapCallSite({}), { code: 'ERR_INVALID_ARG_TYPE' }); | ||
|
||
const callSite = getCallSite(); | ||
deepStrictEqual(callSite, mapCallSite(callSite)); | ||
deepStrictEqual(callSite[0], mapCallSite(callSite[0])); | ||
}); | ||
|
||
|
||
test('module.mapCallSite should reconstruct ts callsite', async () => { | ||
const result = await spawnPromisified(process.execPath, [ | ||
'--no-warnings', | ||
'--experimental-transform-types', | ||
fixtures.path('typescript/ts/test-callsite.ts'), | ||
]); | ||
const output = result.stdout.toString().trim(); | ||
strictEqual(result.stderr, ''); | ||
match(output, /lineNumber: 9/); | ||
match(output, /column: 18/); | ||
match(output, /typescript\/ts\/test-callsite\.ts/); | ||
strictEqual(result.code, 0); | ||
}); | ||
|
||
test('module.mapCallSite should reconstruct ts callsite', async () => { | ||
const result = await spawnPromisified(process.execPath, [ | ||
'--no-warnings', | ||
'--enable-source-maps', | ||
fixtures.path('source-map/minified-map-sourcemap.js'), | ||
]); | ||
const output = result.stdout.toString().trim(); | ||
match(output, /functionName: 'foo'/); | ||
strictEqual(result.stderr, ''); | ||
strictEqual(result.code, 0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { getCallSite } = require("node:util"), { mapCallSite } = require("node:module"); function foo() { console.log(mapCallSite(getCallSite()[0])) } foo(); | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiZm9vLmpzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJjb25zdCB7IGdldENhbGxTaXRlIH0gPSByZXF1aXJlKCdub2RlOnV0aWwnKTtcbmNvbnN0IHsgbWFwQ2FsbFNpdGUgfSA9IHJlcXVpcmUoJ25vZGU6bW9kdWxlJyk7XG5cbmZ1bmN0aW9uIGZvbygpIHtcbiAgICBjb25zb2xlLmxvZyhtYXBDYWxsU2l0ZShnZXRDYWxsU2l0ZSgpWzBdKSk7XG59XG5cbmZvbygpO1xuIl0sCiAgIm1hcHBpbmdzIjogIkFBQUEsR0FBTSxDQUFFLFlBQUFBLENBQVksRUFBSSxRQUFRLFdBQVcsRUFDckMsQ0FBRSxZQUFBQyxDQUFZLEVBQUksUUFBUSxhQUFhLEVBRTdDLFNBQVNDLEdBQU0sQ0FDWCxRQUFRLElBQUlELEVBQVlELEVBQVksRUFBRSxDQUFDLENBQUMsQ0FBQyxDQUM3QyxDQUVBRSxFQUFJIiwKICAibmFtZXMiOiBbImdldENhbGxTaXRlIiwgIm1hcENhbGxTaXRlIiwgImZvbyJdCn0K | ||
|
||
// > npx esbuild foo.js --outfile=foo.min.js --bundle --minify --sourcemap=inline --platform=node | ||
// | ||
// const { getCallSite } = require('node:util'); | ||
// const { mapCallSite } = require('node:module'); | ||
// | ||
// function foo() { | ||
// console.log(mapCallSite(getCallSite()[0])); | ||
// } | ||
// | ||
// foo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
require('../../../common'); | ||
const fixtures = require('../../../common/fixtures'); | ||
const spawn = require('node:child_process').spawn; | ||
|
||
spawn(process.execPath, | ||
['--no-warnings', '--experimental-transform-types', fixtures.path('typescript/ts/test-callsite.ts')], | ||
{ stdio: 'inherit' }); |
12 changes: 12 additions & 0 deletions
12
test/fixtures/source-map/output/test-map-callsite.snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Without mapCallSite: [Object: null prototype] { | ||
functionName: '', | ||
scriptName: '*fixtures*typescript*ts*test-callsite.ts', | ||
lineNumber: 3, | ||
column: 18 | ||
} | ||
With mapCallSite: [Object: null prototype] { | ||
functionName: '', | ||
scriptName: 'file:**fixtures*typescript*ts*test-callsite.ts', | ||
lineNumber: 9, | ||
column: 18 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { getCallSite } = require('node:util'); | ||
const { mapCallSite } = require('node:module'); | ||
|
||
interface CallSite { | ||
A; | ||
B; | ||
} | ||
|
||
const callSite = getCallSite()[0]; | ||
|
||
console.log('Without mapCallSite: ', callSite); | ||
|
||
console.log('With mapCallSite: ', mapCallSite(callSite)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters