Skip to content

Commit

Permalink
Fix #1165 bis: Return sourceFiles for .fsproj files
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Feb 26, 2018
1 parent 7e72a71 commit c7fc246
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/dotnet/Fable.Compiler/AST/AST.Babel.fs
Expand Up @@ -130,7 +130,7 @@ type Directive(value, ?loc) =
/// A complete program source tree.
/// Parsers must specify sourceType as "module" if the source has been parsed as an ES6 module.
/// Otherwise, sourceType must be "script".
type Program(fileName, body, ?directives, ?logs, ?dependencies) =
type Program(fileName, body, ?directives, ?logs, ?dependencies, ?sourceFiles) =
inherit Node("Program")
member __.sourceType = "module" // Don't use "script"
member __.body: U2<Statement, ModuleDeclaration> list = body
Expand All @@ -139,6 +139,7 @@ type Program(fileName, body, ?directives, ?logs, ?dependencies) =
member __.fileName: string = fileName
member __.logs: Map<string, string list> = defaultArg logs Map.empty
member __.dependencies: string[] = defaultArg dependencies [||]
member __.sourceFiles: string[] = defaultArg sourceFiles [||]

(** ##Statements *)
/// An expression statement, i.e., a statement consisting of a single expression.
Expand Down
27 changes: 14 additions & 13 deletions src/dotnet/Fable.Compiler/CLI/Agent.fs
Expand Up @@ -178,22 +178,23 @@ let addFSharpErrorLogs (com: ICompiler) (errors: FSharpErrorInfo array) (fileFil
com.AddLog(msg, severity, range, fileName, "FSHARP"))

let compile (com: Compiler) (project: Project) =
let babel =
if com.CurrentFile.EndsWith(".fsproj") then
// If we compile the last file here, Webpack watcher will ignore changes in it
Fable2Babel.Compiler.createFacade project.ProjectOptions.SourceFiles com.CurrentFile
else
if com.CurrentFile.EndsWith(".fsproj") then
// If we compile the last file here, Webpack watcher will ignore changes in it
Fable2Babel.Compiler.createFacade project.ProjectOptions.SourceFiles com.CurrentFile
|> toJson
else
let babel =
FSharp2Fable.Compiler.transformFile com project.ImplementationFiles
|> FableTransforms.optimizeFile com
|> Fable2Babel.Compiler.transformFile com
// If this is the first compilation, add errors to each respective file
if not project.IsWatchCompile then
addFSharpErrorLogs com project.Errors (Some com.CurrentFile)
project.MarkSent(com.CurrentFile)
// Don't send dependencies to JS client (see #1241)
project.AddDependencies(com.CurrentFile, babel.dependencies)
Babel.Program(babel.fileName, babel.body, babel.directives, com.ReadAllLogs())
|> toJson
// If this is the first compilation, add errors to each respective file
if not project.IsWatchCompile then
addFSharpErrorLogs com project.Errors (Some com.CurrentFile)
project.MarkSent(com.CurrentFile)
// Don't send dependencies to JS client (see #1241)
project.AddDependencies(com.CurrentFile, babel.dependencies)
Babel.Program(babel.fileName, babel.body, babel.directives, com.ReadAllLogs())
|> toJson

type Command = string * (string -> unit)

Expand Down
6 changes: 3 additions & 3 deletions src/dotnet/Fable.Compiler/Transforms/Fable2Babel.fs
Expand Up @@ -889,12 +889,12 @@ module Util =
module Compiler =
open Util

let createFacade (dependencies: string[]) (facadeFile: string) =
let createFacade (sourceFiles: string[]) (facadeFile: string) =
let decls =
let importFile = Array.last dependencies
let importFile = Array.last sourceFiles
StringLiteral(Path.getRelativeFileOrDirPath false facadeFile false importFile)
|> ExportAllDeclaration :> ModuleDeclaration |> U2.Case2 |> List.singleton
Program(facadeFile, decls, dependencies=dependencies)
Program(facadeFile, decls, sourceFiles=sourceFiles)

let transformFile (com: ICompiler) (file: Fable.File) =
try
Expand Down
2 changes: 1 addition & 1 deletion src/js/fable-splitter/src/index.ts
Expand Up @@ -180,7 +180,7 @@ async function getFileAstAsync(path: string, options: FableSplitterOptions, info
if (babelAst.error) {
throw new Error(babelAst.error);
} else if (path.endsWith(".fsproj")) {
info.projectFiles = babelAst.dependencies;
info.projectFiles = babelAst.sourceFiles;
}
addLogs(babelAst.logs, info);
ast = Babel.transformFromAst(babelAst, undefined, { code: false });
Expand Down

0 comments on commit c7fc246

Please sign in to comment.