Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fable Compiler] AST endpoint #3758

Merged
merged 4 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Fable.Cli/Fable.Cli.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<Compile Include="FileWatchers.fsi" />
<Compile Include="FileWatchers.fs" />
<Compile Include="Pipeline.fs" />
<Compile Include="MSBuildCrackerResolver.fs" />
<Compile Include="BuildalyzerCrackerResolver.fs" />
<Compile Include="Main.fs" />
<Compile Include="CustomLogging.fs" />
Expand Down
182 changes: 0 additions & 182 deletions src/Fable.Cli/MSBuildCrackerResolver.fs

This file was deleted.

3 changes: 1 addition & 2 deletions src/Fable.Cli/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ open Fable.Transforms
open Fable.Transforms.State
open Fable.Compiler.ProjectCracker
open Fable.Compiler.Util
open Fable.Cli.MSBuildCrackerResolver

module private Util =
type PathResolver with
Expand Down Expand Up @@ -376,7 +375,7 @@ type ProjectCracked(cliArgs: CliArgs, crackerResponse: CrackerResponse, sourceFi
<| fun () ->
let resolver: ProjectCrackerResolver =
if useMSBuildForCracking then
MSBuildCrackerResolver()
Fable.Compiler.MSBuildCrackerResolver()
else
BuildalyzerCrackerResolver()

Expand Down
4 changes: 4 additions & 0 deletions src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

* [GH-3758](https://github.com/fable-compiler/Fable/pull/3758) Endpoint to get Fable.AST for a file. (by @nojaf)

## 4.0.0-alpha-006 - 2024-02-12

### Changed
Expand Down
1 change: 1 addition & 0 deletions src/Fable.Compiler/Fable.Compiler.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Compile Include="File.fs" />
<Compile Include="ProjectCracker.fsi" />
<Compile Include="ProjectCracker.fs" />
<Compile Include="MSBuildCrackerResolver.fs" />
<Compile Include="Library.fsi"/>
<Compile Include="Library.fs"/>
</ItemGroup>
Expand Down
53 changes: 52 additions & 1 deletion src/Fable.Compiler/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ module CodeServices =
return output
}


let typeCheckProject
(sourceReader: SourceReader)
(checker: InteractiveChecker)
Expand All @@ -142,6 +141,58 @@ module CodeServices =
}
}

let compileFileToFableAST
(sourceReader: SourceReader)
(checker: InteractiveChecker)
(cliArgs: CliArgs)
(crackerResponse: CrackerResponse)
(currentFile: string)
: Async<AST.Fable.File>
=
async {
let! assemblies = checker.GetImportedAssemblies()

// Type-check the project up until the current file.
let! checkProjectResult =
checker.ParseAndCheckProject(
cliArgs.ProjectFile,
crackerResponse.ProjectOptions.SourceFiles,
sourceReader,
lastFile = currentFile
)

let fableProj =
Project.From(
cliArgs.ProjectFile,
crackerResponse.ProjectOptions.SourceFiles,
checkProjectResult.AssemblyContents.ImplementationFiles,
assemblies,
Log.log,
getPlugin = Reflection.loadType cliArgs
)

let opts = cliArgs.CompilerOptions

let fableLibDir = Path.getRelativePath currentFile crackerResponse.FableLibDir

let compiler: Compiler =
CompilerImpl(
currentFile,
fableProj,
opts,
fableLibDir,
crackerResponse.OutputType,
?outDir = cliArgs.OutDir
)

// TODO: make it configurable if FableTransforms.transformFile is applied?
let fableAST =
FSharp2Fable.Compiler.transformFile compiler
|> FableTransforms.transformFile compiler

return fableAST
}

let compileMultipleFilesToJavaScript
(pathResolver: PathResolver)
(cliArgs: CliArgs)
Expand Down
9 changes: 9 additions & 0 deletions src/Fable.Compiler/Library.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ module CodeServices =
crackerResponse: CrackerResponse ->
Async<TypeCheckProjectResult>

/// Transform a file in a project to Fable.AST
val compileFileToFableAST:
sourceReader: SourceReader ->
checker: InteractiveChecker ->
cliArgs: CliArgs ->
crackerResponse: CrackerResponse ->
currentFile: string ->
Async<AST.Fable.File>

/// And compile multiple files of a project to JavaScript.
/// The expected usage of this function is either every file in the project or only the user files.
val compileMultipleFilesToJavaScript:
Expand Down
Loading
Loading