-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix sourcemap when using object as
define
value (#15805)
- Loading branch information
Showing
7 changed files
with
124 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import assert from 'node:assert' | ||
import { fileURLToPath } from 'node:url' | ||
import { createServer } from 'vite' | ||
|
||
async function runTest() { | ||
const server = await createServer({ | ||
root: fileURLToPath(new URL('.', import.meta.url)), | ||
configFile: false, | ||
optimizeDeps: { | ||
noDiscovery: true, | ||
}, | ||
server: { | ||
middlewareMode: true, | ||
hmr: false, | ||
}, | ||
define: { | ||
__testDefineObject: '{ "hello": "test" }', | ||
}, | ||
}) | ||
const mod = await server.ssrLoadModule('/with-define-object-ssr.ts') | ||
const error = await getError(() => mod.error()) | ||
server.ssrFixStacktrace(error) | ||
assert.match(error.stack, /at errorInner (.*with-define-object-ssr.ts:7:9)/) | ||
await server.close() | ||
} | ||
|
||
async function getError(f) { | ||
let error | ||
try { | ||
await f() | ||
} catch (e) { | ||
error = e | ||
} | ||
assert.ok(error) | ||
return error | ||
} | ||
|
||
runTest() |
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,8 @@ | ||
export function error() { | ||
errorInner() | ||
} | ||
|
||
function errorInner() { | ||
// @ts-expect-error "define" | ||
throw new Error('with-define-object: ' + JSON.stringify(__testDefineObject)) | ||
} |
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 @@ | ||
// test complicated stack since broken sourcemap | ||
// might still look correct with a simple case | ||
function main() { | ||
mainInner() | ||
} | ||
|
||
function mainInner() { | ||
// @ts-expect-error "define" | ||
console.trace('with-define-object', __testDefineObject) | ||
} | ||
|
||
main() |