diff --git a/src/fable-standalone/src/Interfaces.fs b/src/fable-standalone/src/Interfaces.fs index 13a817b12f..7f49341ecb 100644 --- a/src/fable-standalone/src/Interfaces.fs +++ b/src/fable-standalone/src/Interfaces.fs @@ -40,6 +40,7 @@ type IChecker = interface end type IParseResults = + abstract OtherFSharpOptions: string[] abstract Errors: Error[] type IBabelResult = @@ -50,9 +51,9 @@ type IFableManager = abstract CreateChecker: references: string[] * readAllBytes: (string -> byte[]) * defines: string[] * optimize: bool -> IChecker abstract CreateChecker: references: string[] * readAllBytes: (string -> byte[]) * otherOptions: string[] -> IChecker abstract ClearParseCaches: checker: IChecker -> unit - abstract ParseFSharpScript: checker: IChecker * fileName: string * source: string -> IParseResults - abstract ParseFSharpProject: checker: IChecker * projectFileName: string * fileNames: string[] * sources: string[] -> IParseResults - abstract ParseFSharpFileInProject: checker: IChecker * fileName: string * projectFileName: string * fileNames: string[] * sources: string[] -> IParseResults + abstract ParseFSharpScript: checker: IChecker * fileName: string * source: string * ?otherFSharpOptions: string[] -> IParseResults + abstract ParseFSharpProject: checker: IChecker * projectFileName: string * fileNames: string[] * sources: string[] * ?otherFSharpOptions: string[] -> IParseResults + abstract ParseFSharpFileInProject: checker: IChecker * fileName: string * projectFileName: string * fileNames: string[] * sources: string[] * ?otherFSharpOptions: string[] -> IParseResults abstract GetParseErrors: parseResults: IParseResults -> Error[] abstract GetDeclarationLocation: parseResults: IParseResults * line: int * col: int * lineText: string -> Async abstract GetToolTipText: parseResults: IParseResults * line: int * col: int * lineText: string -> Async diff --git a/src/fable-standalone/src/Main.fs b/src/fable-standalone/src/Main.fs index a1c9bad2c1..45b9285858 100644 --- a/src/fable-standalone/src/Main.fs +++ b/src/fable-standalone/src/Main.fs @@ -29,7 +29,8 @@ type ParseResults (optimizedProject: Lazy, unoptimizedProject: Lazy, parseFileResultsOpt: FSharpParseFileResults option, checkFileResultsOpt: FSharpCheckFileResults option, - checkProjectResults: FSharpCheckProjectResults) = + checkProjectResults: FSharpCheckProjectResults, + otherFSharpOptions: string[]) = member __.GetProject (optimized: bool) = if optimized @@ -41,6 +42,7 @@ type ParseResults (optimizedProject: Lazy, member __.CheckProjectResults = checkProjectResults interface IParseResults with + member __.OtherFSharpOptions = otherFSharpOptions member __.Errors = checkProjectResults.Errors |> Array.map mapError let inline private tryGetLexerSymbolIslands (sym: Lexer.LexerSymbol) = @@ -104,12 +106,12 @@ let convertGlyph glyph = | FSharpGlyph.Event -> Glyph.Event -let makeProjOptions projectFileName fileNames = +let makeProjOptions projectFileName fileNames otherFSharpOptions = let projOptions: FSharpProjectOptions = { ProjectFileName = projectFileName ProjectId = None SourceFiles = fileNames - OtherOptions = [| |] + OtherOptions = otherFSharpOptions ReferencedProjects = [| |] IsIncompleteTypeCheckEnvironment = false UseScriptResolutionRules = false @@ -131,27 +133,27 @@ let makeProject projectOptions (projectResults: FSharpCheckProjectResults) optim implFiles |> Seq.map (fun file -> Fable.Path.normalizePathAndEnsureFsExtension file.FileName, file) |> dict Project(projectOptions, implFilesMap, projectResults.Errors) -let parseFSharpScript (checker: InteractiveChecker) projectFileName fileName source = +let parseFSharpScript (checker: InteractiveChecker) projectFileName fileName source otherFSharpOptions = let parseResults, checkResults, projectResults = checker.ParseAndCheckScript (projectFileName, fileName, source) - let projectOptions = makeProjOptions projectFileName [| fileName |] + let projectOptions = makeProjOptions projectFileName [| fileName |] otherFSharpOptions let optimizedProject = lazy (makeProject projectOptions projectResults true) let unoptimizedProject = lazy (makeProject projectOptions projectResults false) - ParseResults (optimizedProject, unoptimizedProject, Some parseResults, Some checkResults, projectResults) + ParseResults (optimizedProject, unoptimizedProject, Some parseResults, Some checkResults, projectResults, otherFSharpOptions) -let parseFSharpProject (checker: InteractiveChecker) projectFileName fileNames sources = +let parseFSharpProject (checker: InteractiveChecker) projectFileName fileNames sources otherFSharpOptions = let projectResults = checker.ParseAndCheckProject (projectFileName, fileNames, sources) - let projectOptions = makeProjOptions projectFileName fileNames + let projectOptions = makeProjOptions projectFileName fileNames otherFSharpOptions let optimizedProject = lazy (makeProject projectOptions projectResults true) let unoptimizedProject = lazy (makeProject projectOptions projectResults false) - ParseResults (optimizedProject, unoptimizedProject, None, None, projectResults) + ParseResults (optimizedProject, unoptimizedProject, None, None, projectResults, otherFSharpOptions) -let parseFSharpFileInProject (checker: InteractiveChecker) fileName projectFileName fileNames sources = +let parseFSharpFileInProject (checker: InteractiveChecker) fileName projectFileName fileNames sources otherFSharpOptions = let parseResults, checkResultsOpt, projectResults = checker.ParseAndCheckFileInProject (fileName, projectFileName, fileNames, sources) - let projectOptions = makeProjOptions projectFileName fileNames + let projectOptions = makeProjOptions projectFileName fileNames otherFSharpOptions let optimizedProject = lazy (makeProject projectOptions projectResults true) let unoptimizedProject = lazy (makeProject projectOptions projectResults false) - ParseResults (optimizedProject, unoptimizedProject, Some parseResults, checkResultsOpt, projectResults) + ParseResults (optimizedProject, unoptimizedProject, Some parseResults, checkResultsOpt, projectResults, otherFSharpOptions) let tooltipToString (el: FSharpToolTipElement): string[] = let dataToString (data: FSharpToolTipElementData) = @@ -218,11 +220,11 @@ let getCompletionsAtLocation (parseResults: ParseResults) (line: int) (col: int) return [||] } -let makeCompiler fableLibrary fileName (project: Project) precompiledLib = +let makeCompiler fableLibrary fileName (project: Project) precompiledLib (otherFSharpOptions: string[]) = let options: Fable.CompilerOptions = { typedArrays = true clampByteArrays = false - debugMode = true + debugMode = otherFSharpOptions |> Array.exists ((=) "--define:DEBUG") verbosity = Fable.Verbosity.Normal outputPublicInlinedFunctions = false precompiledLib = precompiledLib } @@ -248,18 +250,21 @@ let init () = let c = checker :?> CheckerImpl c.Checker.ClearCache() - member __.ParseFSharpScript(checker, fileName, source) = + member __.ParseFSharpScript(checker, fileName, source, ?otherFSharpOptions) = let c = checker :?> CheckerImpl + let otherFSharpOptions = defaultArg otherFSharpOptions [||] let projectFileName = "project" // TODO: make it an argument - parseFSharpScript c.Checker projectFileName fileName source :> IParseResults + parseFSharpScript c.Checker projectFileName fileName source otherFSharpOptions :> IParseResults - member __.ParseFSharpProject(checker, projectFileName, fileNames, sources) = + member __.ParseFSharpProject(checker, projectFileName, fileNames, sources, ?otherFSharpOptions) = let c = checker :?> CheckerImpl - parseFSharpProject c.Checker projectFileName fileNames sources :> IParseResults + let otherFSharpOptions = defaultArg otherFSharpOptions [||] + parseFSharpProject c.Checker projectFileName fileNames sources otherFSharpOptions :> IParseResults - member __.ParseFSharpFileInProject(checker, fileName, projectFileName, fileNames, sources) = + member __.ParseFSharpFileInProject(checker, fileName, projectFileName, fileNames, sources, ?otherFSharpOptions) = let c = checker :?> CheckerImpl - parseFSharpFileInProject c.Checker fileName projectFileName fileNames sources :> IParseResults + let otherFSharpOptions = defaultArg otherFSharpOptions [||] + parseFSharpFileInProject c.Checker fileName projectFileName fileNames sources otherFSharpOptions :> IParseResults member __.GetParseErrors(parseResults:IParseResults) = parseResults.Errors @@ -279,7 +284,7 @@ let init () = member __.CompileToBabelAst(fableLibrary:string, parseResults:IParseResults, fileName:string, optimized: bool, ?precompiledLib) = let res = parseResults :?> ParseResults let project = res.GetProject (optimized) - let com = makeCompiler fableLibrary fileName project precompiledLib + let com = makeCompiler fableLibrary fileName project precompiledLib parseResults.OtherFSharpOptions let ast = compileAst com project let errors = com.GetLogs() diff --git a/src/fable-standalone/src/Worker/Shared.fs b/src/fable-standalone/src/Worker/Shared.fs index 8b13c2782d..19b72ae220 100644 --- a/src/fable-standalone/src/Worker/Shared.fs +++ b/src/fable-standalone/src/Worker/Shared.fs @@ -9,8 +9,8 @@ open Thoth.Json type WorkerRequest = /// * refsExtraSuffix: e.g. add .txt extension to enable gzipping in Github Pages | CreateChecker of refsDirUrl: string * extraRefs: string[] * refsExtraSuffix: string option * libJsonUrl: string option - | ParseCode of fsharpCode: string - | CompileCode of fsharpCode: string * optimize: bool + | ParseCode of fsharpCode: string * otherFSharpOptions: string[] + | CompileCode of fsharpCode: string * otherFSharpOptions: string[] * optimize: bool | GetTooltip of id: Guid * line: int * column: int * lineText: string | GetCompletions of id: Guid * line: int * column: int * lineText: string | GetDeclarationLocation of id: Guid * line: int * column: int * lineText: string diff --git a/src/fable-standalone/src/Worker/Worker.fs b/src/fable-standalone/src/Worker/Worker.fs index 9b1c42b971..e2c9591bec 100644 --- a/src/fable-standalone/src/Worker/Worker.fs +++ b/src/fable-standalone/src/Worker/Worker.fs @@ -73,14 +73,14 @@ let rec loop (box: MailboxProcessor) (state: State) = async { | None, _ | Some _, CreateChecker _ -> return! loop box state - | Some fable, ParseCode fsharpCode -> - let res = fable.Manager.ParseFSharpScript(fable.Checker, FILE_NAME, fsharpCode) + | Some fable, ParseCode(fsharpCode, otherFSharpOptions) -> + let res = fable.Manager.ParseFSharpScript(fable.Checker, FILE_NAME, fsharpCode, otherFSharpOptions) ParsedCode res.Errors |> state.Worker.Post return! loop box { state with CurrentResults = Some res } - | Some fable, CompileCode(fsharpCode, optimize) -> + | Some fable, CompileCode(fsharpCode, otherFSharpOptions, optimize) -> try - let (parseResults, parsingTime) = measureTime fable.Manager.ParseFSharpScript (fable.Checker, FILE_NAME, fsharpCode) + let (parseResults, parsingTime) = measureTime (fun () -> fable.Manager.ParseFSharpScript(fable.Checker, FILE_NAME, fsharpCode, otherFSharpOptions)) () let (res, fableTransformTime) = measureTime (fun () -> fable.Manager.CompileToBabelAst("fable-library", parseResults, FILE_NAME, optimize, fun x -> resolveLibCall(fable.LibMap, x))) () let (jsCode, babelTime, babelErrors) =