@@ -18,6 +18,7 @@ import { extract_names as extractNames } from 'periscopic'
18
18
import { walk as eswalk } from 'estree-walker'
19
19
import type { RawSourceMap } from '@ampproject/remapping'
20
20
import { parseAstAsync as rolldownParseAstAsync } from 'rolldown/parseAst'
21
+ import { moduleRunnerTransform } from 'oxc-transform'
21
22
import type { TransformResult } from '../server/transformRequest'
22
23
import {
23
24
combineSourcemaps ,
@@ -84,6 +85,44 @@ async function ssrTransformScript(
84
85
url : string ,
85
86
originalCode : string ,
86
87
) : Promise < TransformResult | null > {
88
+ if ( ! process . env [ 'DISABLE_OXC_MODULE_TRANSFORM' ] ) {
89
+ const result = moduleRunnerTransform ( 'test.js' , code , { sourcemap : true } )
90
+ if ( result . errors . length ) {
91
+ // eslint-disable-next-line no-console
92
+ console . log ( JSON . stringify ( result . errors , null , 2 ) , '\n' , code )
93
+ throw new AggregateError ( result . errors )
94
+ }
95
+ let map : TransformResult [ 'map' ] = inMap
96
+ if ( inMap ?. mappings === '' ) {
97
+ map = inMap
98
+ } else if ( result . map ) {
99
+ map = result . map as SourceMap
100
+ map . sources = [ path . basename ( url ) ]
101
+ // needs to use originalCode instead of code
102
+ // because code might be already transformed even if map is null
103
+ map . sourcesContent = [ originalCode ]
104
+ if (
105
+ inMap &&
106
+ inMap . mappings &&
107
+ 'sources' in inMap &&
108
+ inMap . sources . length > 0
109
+ ) {
110
+ map = combineSourcemaps ( url , [
111
+ map as RawSourceMap ,
112
+ inMap as RawSourceMap ,
113
+ ] ) as SourceMap
114
+ }
115
+ }
116
+
117
+ return {
118
+ code : result . code ,
119
+ map,
120
+ ssr : true ,
121
+ deps : [ ...result . deps ] ,
122
+ dynamicDeps : [ ...result . dynamicDeps ] ,
123
+ }
124
+ }
125
+
87
126
const s = new MagicString ( code )
88
127
89
128
let ast : any
0 commit comments