@@ -50,6 +50,10 @@ type info = {
5050 warnFlags : string ,
5151 jsxPreserveMode : bool ,
5252 experimentalFeatures : array <PlaygroundConfig .experimentalFeature >,
53+ gentypeEnabled : bool ,
54+ sourceMapMode : PlaygroundConfig .sourceMapMode ,
55+ sourceMapSourcesContent : bool ,
56+ sourceMapRoot : string ,
5357 libraries : array <string >,
5458}
5559
@@ -59,6 +63,8 @@ type success = {
5963 typedtree : string ,
6064 lambda : string ,
6165 lam : string ,
66+ gentype : option <string >,
67+ sourceMap : option <string >,
6268 warnings : array <string >,
6369 time : float ,
6470}
@@ -78,6 +84,10 @@ type normalizedConfig = {
7884 warnFlags : string ,
7985 jsxPreserveMode : bool ,
8086 experimentalFeatures : array <PlaygroundConfig .experimentalFeature >,
87+ gentypeEnabled : bool ,
88+ sourceMapMode : PlaygroundConfig .sourceMapMode ,
89+ sourceMapSourcesContent : bool ,
90+ sourceMapRoot : string ,
8191}
8292
8393let defaultWarnFlags = "+a-4-9-20-40-41-42-50-61-102-109"
@@ -90,6 +100,10 @@ let defaultConfig: PlaygroundConfig.t = {
90100 warnFlags : defaultWarnFlags ,
91101 jsxPreserveMode : false ,
92102 experimentalFeatures : [],
103+ gentypeEnabled : false ,
104+ sourceMapMode : Disabled ,
105+ sourceMapSourcesContent : true ,
106+ sourceMapRoot : "" ,
93107}
94108
95109let pathFromBase = relativePath => {
@@ -207,6 +221,10 @@ let applyConfig = (
207221 ~moduleSystem : PlaygroundConfig .moduleSystem ,
208222 ~warnFlags ,
209223 ~jsxPreserveMode ,
224+ ~gentypeEnabled ,
225+ ~sourceMapMode : PlaygroundConfig .sourceMapMode ,
226+ ~sourceMapSourcesContent ,
227+ ~sourceMapRoot ,
210228 ~experimentalFeatures : array <PlaygroundConfig .experimentalFeature >,
211229) => {
212230 if hasFunction (instance , "setModuleSystem" ) {
@@ -221,6 +239,18 @@ let applyConfig = (
221239 if hasFunction (instance , "setJsxPreserveMode" ) {
222240 instance -> Instance .setJsxPreserveMode (jsxPreserveMode )
223241 }
242+ if hasFunction (instance , "setGentypeEnabled" ) {
243+ instance -> Instance .setGentypeEnabled (gentypeEnabled )
244+ }
245+ if hasFunction (instance , "setSourceMapMode" ) {
246+ instance -> Instance .setSourceMapMode (sourceMapMode -> PlaygroundConfig .sourceMapModeCompilerValue )
247+ }
248+ if hasFunction (instance , "setSourceMapSourcesContent" ) {
249+ instance -> Instance .setSourceMapSourcesContent (sourceMapSourcesContent )
250+ }
251+ if hasFunction (instance , "setSourceMapRoot" ) {
252+ instance -> Instance .setSourceMapRoot (sourceMapRoot )
253+ }
224254 if hasFunction (instance , "setExperimentalFeatures" ) {
225255 instance -> Instance .setExperimentalFeatures (
226256 experimentalFeatures -> Array .map (feature => (feature :> string )),
@@ -245,13 +275,27 @@ let experimentalFeaturesFromConfig = configValue =>
245275 | None => []
246276 }
247277
278+ let sourceMapModeFromConfig = configValue =>
279+ switch configValue -> Config .sourceMapMode {
280+ | Some (sourceMapMode ) =>
281+ switch sourceMapMode -> PlaygroundConfig .parseSourceMapMode {
282+ | Some (sourceMapMode ) => sourceMapMode
283+ | None => defaultConfig .sourceMapMode
284+ }
285+ | None => defaultConfig .sourceMapMode
286+ }
287+
248288let normalizeConfig = (configValue : option <compilerConfig >): normalizedConfig =>
249289 switch configValue {
250290 | None => {
251291 moduleSystem : Esmodule ,
252292 warnFlags : defaultConfig .warnFlags ,
253293 jsxPreserveMode : false ,
254294 experimentalFeatures : [],
295+ gentypeEnabled : defaultConfig .gentypeEnabled ,
296+ sourceMapMode : defaultConfig .sourceMapMode ,
297+ sourceMapSourcesContent : defaultConfig .sourceMapSourcesContent ,
298+ sourceMapRoot : defaultConfig .sourceMapRoot ,
255299 }
256300 | Some (configValue ) => {
257301 moduleSystem : configValue -> moduleSystemFromConfig ,
@@ -264,6 +308,19 @@ let normalizeConfig = (configValue: option<compilerConfig>): normalizedConfig =>
264308 | None => false
265309 },
266310 experimentalFeatures : configValue -> experimentalFeaturesFromConfig ,
311+ gentypeEnabled : switch configValue -> Config .gentypeEnabled {
312+ | Some (gentypeEnabled ) => gentypeEnabled
313+ | None => defaultConfig .gentypeEnabled
314+ },
315+ sourceMapMode : configValue -> sourceMapModeFromConfig ,
316+ sourceMapSourcesContent : switch configValue -> Config .sourceMapSourcesContent {
317+ | Some (sourceMapSourcesContent ) => sourceMapSourcesContent
318+ | None => defaultConfig .sourceMapSourcesContent
319+ },
320+ sourceMapRoot : switch configValue -> Config .sourceMapRoot {
321+ | Some (sourceMapRoot ) => sourceMapRoot
322+ | None => defaultConfig .sourceMapRoot
323+ },
267324 }
268325 }
269326
@@ -351,7 +408,10 @@ let normalize = (compileOutput, elapsedMs): compileResult => {
351408 | None => ""
352409 }
353410
354- Ok ({jsCode , parsetree , typedtree , lambda , lam , warnings , time : elapsedMs })
411+ let gentype = compileOutput -> CompileResult .gentype
412+ let sourceMap = compileOutput -> CompileResult .sourceMap
413+
414+ Ok ({jsCode , parsetree , typedtree , lambda , lam , gentype , sourceMap , warnings , time : elapsedMs })
355415
356416 | _ => Error (failureFromCompileOutput (compileOutput , elapsedMs ))
357417 }
@@ -418,6 +478,10 @@ let ensureCompiler = async version => {
418478 ~moduleSystem = Esmodule ,
419479 ~warnFlags = defaultConfig .warnFlags ,
420480 ~jsxPreserveMode = false ,
481+ ~gentypeEnabled = defaultConfig .gentypeEnabled ,
482+ ~sourceMapMode = defaultConfig .sourceMapMode ,
483+ ~sourceMapSourcesContent = defaultConfig .sourceMapSourcesContent ,
484+ ~sourceMapRoot = defaultConfig .sourceMapRoot ,
421485 ~experimentalFeatures = [],
422486 )
423487
@@ -470,6 +534,10 @@ let init = async version => {
470534 warnFlags : config .warnFlags ,
471535 jsxPreserveMode : config .jsxPreserveMode ,
472536 experimentalFeatures : config .experimentalFeatures ,
537+ gentypeEnabled : config .gentypeEnabled ,
538+ sourceMapMode : config .sourceMapMode ,
539+ sourceMapSourcesContent : config .sourceMapSourcesContent ,
540+ sourceMapRoot : config .sourceMapRoot ,
473541 libraries ,
474542 }
475543}
@@ -483,6 +551,10 @@ let compile = async (source, config: PlaygroundConfig.t) => {
483551 ~moduleSystem = config .moduleSystem ,
484552 ~warnFlags = config .warnFlags ,
485553 ~jsxPreserveMode = config .jsxPreserveMode ,
554+ ~gentypeEnabled = config .gentypeEnabled ,
555+ ~sourceMapMode = config .sourceMapMode ,
556+ ~sourceMapSourcesContent = config .sourceMapSourcesContent ,
557+ ~sourceMapRoot = config .sourceMapRoot ,
486558 ~experimentalFeatures = config .experimentalFeatures ,
487559 )
488560
@@ -507,6 +579,10 @@ let format = async (source, config: PlaygroundConfig.t) => {
507579 ~moduleSystem = config .moduleSystem ,
508580 ~warnFlags = config .warnFlags ,
509581 ~jsxPreserveMode = config .jsxPreserveMode ,
582+ ~gentypeEnabled = config .gentypeEnabled ,
583+ ~sourceMapMode = config .sourceMapMode ,
584+ ~sourceMapSourcesContent = config .sourceMapSourcesContent ,
585+ ~sourceMapRoot = config .sourceMapRoot ,
510586 ~experimentalFeatures = config .experimentalFeatures ,
511587 )
512588
0 commit comments