Skip to content

Commit

Permalink
compiler: compile pod.js meta flag, redesign ES to only run with JS p…
Browse files Browse the repository at this point in the history
…lug-in runs

The behavior since 6-Sept-2023 has been to run es compiler on every single pod
separately from if JS compiler was needed.  But this results in generating js
for pods like doc pods.

This changeset introduces two changes:

1. add pod.js flag if we generate es code into the pod (and APIs to check it via CPod)

2. changes es code generation to use same check as js code generation

This change now requires that ES depends are omitted if dependency has no js code
  • Loading branch information
briansfrank committed Mar 29, 2024
1 parent 989e3ec commit 19556d6
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 37 deletions.
4 changes: 3 additions & 1 deletion src/compiler/fan/assembler/Assembler.fan
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Assembler : CompilerSupport, FConst
{
meta := pod.meta
meta["pod.fcode"] = (!types.isEmpty).toStr
meta["pod.js"] = (compiler.cjs != null || compiler.isSys).toStr
return meta
}

Expand Down Expand Up @@ -169,4 +170,5 @@ class Assembler : CompilerSupport, FConst
//////////////////////////////////////////////////////////////////////////

FPod? fpod
}
}

15 changes: 8 additions & 7 deletions src/compiler/fan/ast/PodDef.fan
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ class PodDef : Node, CPod
// Fields
//////////////////////////////////////////////////////////////////////////

override CNamespace ns // compiler's namespace
override const Str name // simple pod name
Str:Str meta := Str:Str[:] // pod meta-data props
Str:Obj index := Str:Obj[:] // pod index props (vals are Str or Str[])
CompilationUnit[] units // Tokenize
[Str:TypeDef]? typeDefs // ScanForUsingsAndTypes
override CNamespace ns // compiler's namespace
override const Str name // simple pod name
override Str:Str meta := Str:Str[:] // pod meta-data props
Str:Obj index := Str:Obj[:] // pod index props (vals are Str or Str[])
CompilationUnit[] units // Tokenize
[Str:TypeDef]? typeDefs // ScanForUsingsAndTypes

}

}
41 changes: 21 additions & 20 deletions src/compiler/fan/fcode/FPod.fan
Original file line number Diff line number Diff line change
Expand Up @@ -293,24 +293,25 @@ final class FPod : CPod, FConst
// Fields
//////////////////////////////////////////////////////////////////////////

override CNamespace ns // compiler's namespace
override Str name // pod's unique name
override Version version // pod version
override CNamespace ns // compiler's namespace
override Str name // pod's unique name
override Version version // pod version
override CDepend[] depends // pod dependencies
Str:Str meta // pod meta
Str:Obj index // pod index
Zip? zip // zipped storage
FType[]? ftypes // pod's declared types
FTable names // identifier names: foo
FTable typeRefs // types refs: [pod,type,sig]
FTable fieldRefs // fields refs: [parent,name,type]
FTable methodRefs // methods refs: [parent,name,ret,params]
FTable ints // Int literals
FTable floats // Float literals
FTable decimals // Decimal literals
FTable strs // Str literals
FTable durations // Duration literals
FTable uris // Uri literals
[Str:FType]? ftypesByName // if loaded

}
override Str:Str meta // pod meta
Str:Obj index // pod index
Zip? zip // zipped storage
FType[]? ftypes // pod's declared types
FTable names // identifier names: foo
FTable typeRefs // types refs: [pod,type,sig]
FTable fieldRefs // fields refs: [parent,name,type]
FTable methodRefs // methods refs: [parent,name,ret,params]
FTable ints // Int literals
FTable floats // Float literals
FTable decimals // Decimal literals
FTable strs // Str literals
FTable durations // Duration literals
FTable uris // Uri literals
[Str:FType]? ftypesByName // if loaded

}

13 changes: 12 additions & 1 deletion src/compiler/fan/namespace/CPod.fan
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ mixin CPod
**
abstract File file()

**
** Pod meta data
**
abstract Str:Str meta()

**
** Return if this pod has client side JavaScript
**
Bool hasJs() { meta["pod.js"] == "true" || name == "sys" }

**
** Lookup a type by its simple name. If the type doesn't
** exist and checked is true then throw UnknownTypeErr
Expand Down Expand Up @@ -87,4 +97,5 @@ mixin CPod
return name
}

}
}

5 changes: 4 additions & 1 deletion src/compiler/fan/namespace/ReflectPod.fan
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ReflectPod : CPod

override once File file() { Env.cur.findPodFile(name) }

override Str:Str meta() { pod.meta }

override CType[] types()
{
if (!loadedAllTypes)
Expand Down Expand Up @@ -60,4 +62,5 @@ class ReflectPod : CPod
private Str:ReflectType typeMap := Str:ReflectType[:]
private Bool loadedAllTypes := false

}
}

16 changes: 10 additions & 6 deletions src/compiler/fan/steps/CompileJs.fan
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ class CompileJs : CompilerStep
if (needCompileJs)
{
compile("compilerJs::CompileJsPlugin")
genTsDecl
}

if (pod.name != "sys")
if (needCompileEs)
{
// we need to generate new javascript for all pods even if no js types
compile("compilerEs::CompileEsPlugin")
if (pod.name != "sys") compile("compilerEs::CompileEsPlugin")
genTsDecl
}

}

private Void compile(Str qname)
Expand Down Expand Up @@ -71,6 +69,11 @@ class CompileJs : CompilerStep
}
}

Bool needCompileEs()
{
needCompileJs
}

Bool needCompileJs()
{
// in JS mode we force JS compilation
Expand All @@ -89,4 +92,5 @@ class CompileJs : CompilerStep
return this.hasJs
}

}
}

5 changes: 4 additions & 1 deletion src/compilerJava/fan/JavaPod.fan
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class JavaPod : CPod

override File file() { throw UnsupportedErr() }

override const Str:Str meta := [:]

const Str packageName

override const Version version := Version.defVal
Expand All @@ -68,4 +70,5 @@ class JavaPod : CPod
** Is this the fanx.interop package?
const Bool isInterop

}
}

2 changes: 2 additions & 0 deletions src/doc/docIntro/doc/ChangeLog.fandoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
- Fix Color HSL implementation to match browser behavoir
- Add MimeType.isText
- Add util::LockFile
- Redesign ES compiler to not generate code for every pod
- Include TypeScript decl file in pods with JS code

*Build 1.0.79 (17 Jul 2023)*
- New yaml API
Expand Down
1 change: 1 addition & 0 deletions src/doc/docLang/doc/Pods.fandoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The following are the standardized keys automatically defined by compiler:
- 'pod.isScript': was the pod compiled in script mode
- 'pod.docSrc': should documentation include source code, see [BuildPod]`build::BuildPod.docSrc`
- 'pod.docApi': should pod be included in documentation, see [BuildPod]`build::BuildPod.docApi`
- 'pod.js': does pod include client side JavaScript code (true or false)
- 'pod.native.java': does pod use native Java code (true or false)
- 'pod.native.dotnet': does pod use native .NET code (true or false)
- 'pod.native.js': does pod use native JavaScript code (true or false)
Expand Down

0 comments on commit 19556d6

Please sign in to comment.