@@ -2,6 +2,7 @@ import * as Babel from "@babel/standalone"
22import { resolveFilePathOrThrow } from "lib/runner/resolveFilePath"
33import { dirname } from "lib/utils/dirname"
44import { getImportsFromCode } from "lib/utils/get-imports-from-code"
5+ import { addSourceLineToError } from "lib/utils/addSourceLineToError"
56import { evalCompiledJs } from "./eval-compiled-js"
67import type { ExecutionContext } from "./execution-context"
78import { importEvalPath } from "./import-eval-path"
@@ -38,8 +39,12 @@ export const importLocalFile = async (
3839 const result = Babel . transform ( fileContent , {
3940 presets : [ "react" , "typescript" ] ,
4041 plugins : [ "transform-modules-commonjs" ] ,
41- filename : "virtual.tsx" ,
42+ filename : fsPath ,
43+ sourceMaps : true ,
4244 } )
45+ if ( result . map ) {
46+ ctx . sourceMaps [ fsPath ] = result . map
47+ }
4348
4449 if ( ! result || ! result . code ) {
4550 throw new Error ( "Failed to transform code" )
@@ -50,9 +55,11 @@ export const importLocalFile = async (
5055 result . code ,
5156 preSuppliedImports ,
5257 dirname ( fsPath ) ,
58+ fsPath ,
5359 )
5460 preSuppliedImports [ fsPath ] = importRunResult . exports
5561 } catch ( error : any ) {
62+ await addSourceLineToError ( error , ctx . fsMap , ctx . sourceMaps )
5663 throw new Error (
5764 `Eval compiled js error for "${ importName } ": ${ error . message } ` ,
5865 )
@@ -63,7 +70,11 @@ export const importLocalFile = async (
6370 presets : [ "env" ] ,
6471 plugins : [ "transform-modules-commonjs" ] ,
6572 filename : fsPath ,
73+ sourceMaps : true ,
6674 } )
75+ if ( result . map ) {
76+ ctx . sourceMaps [ fsPath ] = result . map
77+ }
6778
6879 if ( ! result || ! result . code ) {
6980 throw new Error ( "Failed to transform JS code" )
@@ -73,6 +84,7 @@ export const importLocalFile = async (
7384 result . code ,
7485 preSuppliedImports ,
7586 dirname ( fsPath ) ,
87+ fsPath ,
7688 ) . exports
7789 } else {
7890 throw new Error (
0 commit comments