@@ -28,6 +28,10 @@ type info = {
2828 warnFlags : string ,
2929 jsxPreserveMode : bool ,
3030 experimentalFeatures : array <PlaygroundConfig .experimentalFeature >,
31+ gentypeEnabled : bool ,
32+ sourceMapMode : PlaygroundConfig .sourceMapMode ,
33+ sourceMapSourcesContent : bool ,
34+ sourceMapRoot : string ,
3135 libraries : array <string >,
3236}
3337
@@ -37,6 +41,8 @@ type success = {
3741 typedtree : string ,
3842 lambda : string ,
3943 lam : string ,
44+ gentype : option <string >,
45+ sourceMap : option <string >,
4046 warnings : array <string >,
4147 time : float ,
4248}
@@ -56,6 +62,10 @@ type normalizedConfig = {
5662 warnFlags : string ,
5763 jsxPreserveMode : bool ,
5864 experimentalFeatures : array <PlaygroundConfig .experimentalFeature >,
65+ gentypeEnabled : bool ,
66+ sourceMapMode : PlaygroundConfig .sourceMapMode ,
67+ sourceMapSourcesContent : bool ,
68+ sourceMapRoot : string ,
5969}
6070
6171let defaultWarnFlags = "+a-4-9-20-40-41-42-50-61-102-109"
@@ -68,6 +78,10 @@ let defaultConfig: PlaygroundConfig.t = {
6878 warnFlags : defaultWarnFlags ,
6979 jsxPreserveMode : false ,
7080 experimentalFeatures : [],
81+ gentypeEnabled : false ,
82+ sourceMapMode : Disabled ,
83+ sourceMapSourcesContent : true ,
84+ sourceMapRoot : "" ,
7185}
7286
7387let pathFromBase = relativePath => {
@@ -147,6 +161,10 @@ let applyConfig = (
147161 ~moduleSystem : PlaygroundConfig .moduleSystem ,
148162 ~warnFlags ,
149163 ~jsxPreserveMode ,
164+ ~gentypeEnabled ,
165+ ~sourceMapMode : PlaygroundConfig .sourceMapMode ,
166+ ~sourceMapSourcesContent ,
167+ ~sourceMapRoot ,
150168 ~experimentalFeatures : array <PlaygroundConfig .experimentalFeature >,
151169) => {
152170 if hasFunction (instance , "setModuleSystem" ) {
@@ -161,6 +179,18 @@ let applyConfig = (
161179 if hasFunction (instance , "setJsxPreserveMode" ) {
162180 instance -> Instance .setJsxPreserveMode (jsxPreserveMode )
163181 }
182+ if hasFunction (instance , "setGentypeEnabled" ) {
183+ instance -> Instance .setGentypeEnabled (gentypeEnabled )
184+ }
185+ if hasFunction (instance , "setSourceMapMode" ) {
186+ instance -> Instance .setSourceMapMode (sourceMapMode -> PlaygroundConfig .sourceMapModeCompilerValue )
187+ }
188+ if hasFunction (instance , "setSourceMapSourcesContent" ) {
189+ instance -> Instance .setSourceMapSourcesContent (sourceMapSourcesContent )
190+ }
191+ if hasFunction (instance , "setSourceMapRoot" ) {
192+ instance -> Instance .setSourceMapRoot (sourceMapRoot )
193+ }
164194 if hasFunction (instance , "setExperimentalFeatures" ) {
165195 instance -> Instance .setExperimentalFeatures (
166196 experimentalFeatures -> Array .map (feature => (feature :> string )),
@@ -185,13 +215,27 @@ let experimentalFeaturesFromConfig = configValue =>
185215 | None => []
186216 }
187217
218+ let sourceMapModeFromConfig = configValue =>
219+ switch configValue -> Config .sourceMapMode {
220+ | Some (sourceMapMode ) =>
221+ switch sourceMapMode -> PlaygroundConfig .parseSourceMapMode {
222+ | Some (sourceMapMode ) => sourceMapMode
223+ | None => defaultConfig .sourceMapMode
224+ }
225+ | None => defaultConfig .sourceMapMode
226+ }
227+
188228let normalizeConfig = (configValue : option <compilerConfig >): normalizedConfig =>
189229 switch configValue {
190230 | None => {
191231 moduleSystem : Esmodule ,
192232 warnFlags : defaultConfig .warnFlags ,
193233 jsxPreserveMode : false ,
194234 experimentalFeatures : [],
235+ gentypeEnabled : defaultConfig .gentypeEnabled ,
236+ sourceMapMode : defaultConfig .sourceMapMode ,
237+ sourceMapSourcesContent : defaultConfig .sourceMapSourcesContent ,
238+ sourceMapRoot : defaultConfig .sourceMapRoot ,
195239 }
196240 | Some (configValue ) => {
197241 moduleSystem : configValue -> moduleSystemFromConfig ,
@@ -204,6 +248,19 @@ let normalizeConfig = (configValue: option<compilerConfig>): normalizedConfig =>
204248 | None => false
205249 },
206250 experimentalFeatures : configValue -> experimentalFeaturesFromConfig ,
251+ gentypeEnabled : switch configValue -> Config .gentypeEnabled {
252+ | Some (gentypeEnabled ) => gentypeEnabled
253+ | None => defaultConfig .gentypeEnabled
254+ },
255+ sourceMapMode : configValue -> sourceMapModeFromConfig ,
256+ sourceMapSourcesContent : switch configValue -> Config .sourceMapSourcesContent {
257+ | Some (sourceMapSourcesContent ) => sourceMapSourcesContent
258+ | None => defaultConfig .sourceMapSourcesContent
259+ },
260+ sourceMapRoot : switch configValue -> Config .sourceMapRoot {
261+ | Some (sourceMapRoot ) => sourceMapRoot
262+ | None => defaultConfig .sourceMapRoot
263+ },
207264 }
208265 }
209266
@@ -291,7 +348,10 @@ let normalize = (compileOutput, elapsedMs): compileResult => {
291348 | None => ""
292349 }
293350
294- Ok ({jsCode , parsetree , typedtree , lambda , lam , warnings , time : elapsedMs })
351+ let gentype = compileOutput -> CompileResult .gentype
352+ let sourceMap = compileOutput -> CompileResult .sourceMap
353+
354+ Ok ({jsCode , parsetree , typedtree , lambda , lam , gentype , sourceMap , warnings , time : elapsedMs })
295355
296356 | _ => Error (failureFromCompileOutput (compileOutput , elapsedMs ))
297357 }
@@ -358,6 +418,10 @@ let ensureCompiler = async version => {
358418 ~moduleSystem = Esmodule ,
359419 ~warnFlags = defaultConfig .warnFlags ,
360420 ~jsxPreserveMode = false ,
421+ ~gentypeEnabled = defaultConfig .gentypeEnabled ,
422+ ~sourceMapMode = defaultConfig .sourceMapMode ,
423+ ~sourceMapSourcesContent = defaultConfig .sourceMapSourcesContent ,
424+ ~sourceMapRoot = defaultConfig .sourceMapRoot ,
361425 ~experimentalFeatures = [],
362426 )
363427
@@ -410,6 +474,10 @@ let init = async version => {
410474 warnFlags : config .warnFlags ,
411475 jsxPreserveMode : config .jsxPreserveMode ,
412476 experimentalFeatures : config .experimentalFeatures ,
477+ gentypeEnabled : config .gentypeEnabled ,
478+ sourceMapMode : config .sourceMapMode ,
479+ sourceMapSourcesContent : config .sourceMapSourcesContent ,
480+ sourceMapRoot : config .sourceMapRoot ,
413481 libraries ,
414482 }
415483}
@@ -423,6 +491,10 @@ let compile = async (source, config: PlaygroundConfig.t) => {
423491 ~moduleSystem = config .moduleSystem ,
424492 ~warnFlags = config .warnFlags ,
425493 ~jsxPreserveMode = config .jsxPreserveMode ,
494+ ~gentypeEnabled = config .gentypeEnabled ,
495+ ~sourceMapMode = config .sourceMapMode ,
496+ ~sourceMapSourcesContent = config .sourceMapSourcesContent ,
497+ ~sourceMapRoot = config .sourceMapRoot ,
426498 ~experimentalFeatures = config .experimentalFeatures ,
427499 )
428500
@@ -447,6 +519,10 @@ let format = async (source, config: PlaygroundConfig.t) => {
447519 ~moduleSystem = config .moduleSystem ,
448520 ~warnFlags = config .warnFlags ,
449521 ~jsxPreserveMode = config .jsxPreserveMode ,
522+ ~gentypeEnabled = config .gentypeEnabled ,
523+ ~sourceMapMode = config .sourceMapMode ,
524+ ~sourceMapSourcesContent = config .sourceMapSourcesContent ,
525+ ~sourceMapRoot = config .sourceMapRoot ,
450526 ~experimentalFeatures = config .experimentalFeatures ,
451527 )
452528
0 commit comments