diff --git a/src/compiler/fan/assembler/Assembler.fan b/src/compiler/fan/assembler/Assembler.fan index b3daff898..027425875 100644 --- a/src/compiler/fan/assembler/Assembler.fan +++ b/src/compiler/fan/assembler/Assembler.fan @@ -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 } @@ -169,4 +170,5 @@ class Assembler : CompilerSupport, FConst ////////////////////////////////////////////////////////////////////////// FPod? fpod -} \ No newline at end of file +} + diff --git a/src/compiler/fan/ast/PodDef.fan b/src/compiler/fan/ast/PodDef.fan index a2aedb225..08e5bb668 100644 --- a/src/compiler/fan/ast/PodDef.fan +++ b/src/compiler/fan/ast/PodDef.fan @@ -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 + +} -} \ No newline at end of file diff --git a/src/compiler/fan/fcode/FPod.fan b/src/compiler/fan/fcode/FPod.fan index 0b535ec6d..40a8e30b3 100644 --- a/src/compiler/fan/fcode/FPod.fan +++ b/src/compiler/fan/fcode/FPod.fan @@ -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 - -} \ No newline at end of file + 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 + +} + diff --git a/src/compiler/fan/namespace/CPod.fan b/src/compiler/fan/namespace/CPod.fan index d33eed983..b4905d45c 100644 --- a/src/compiler/fan/namespace/CPod.fan +++ b/src/compiler/fan/namespace/CPod.fan @@ -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 @@ -87,4 +97,5 @@ mixin CPod return name } -} \ No newline at end of file +} + diff --git a/src/compiler/fan/namespace/ReflectPod.fan b/src/compiler/fan/namespace/ReflectPod.fan index 87c3d2589..19f0bfb1c 100644 --- a/src/compiler/fan/namespace/ReflectPod.fan +++ b/src/compiler/fan/namespace/ReflectPod.fan @@ -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) @@ -60,4 +62,5 @@ class ReflectPod : CPod private Str:ReflectType typeMap := Str:ReflectType[:] private Bool loadedAllTypes := false -} \ No newline at end of file +} + diff --git a/src/compiler/fan/steps/CompileJs.fan b/src/compiler/fan/steps/CompileJs.fan index 2230bcc75..acd87934f 100644 --- a/src/compiler/fan/steps/CompileJs.fan +++ b/src/compiler/fan/steps/CompileJs.fan @@ -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) @@ -71,6 +69,11 @@ class CompileJs : CompilerStep } } + Bool needCompileEs() + { + needCompileJs + } + Bool needCompileJs() { // in JS mode we force JS compilation @@ -89,4 +92,5 @@ class CompileJs : CompilerStep return this.hasJs } -} \ No newline at end of file +} + diff --git a/src/compilerJava/fan/JavaPod.fan b/src/compilerJava/fan/JavaPod.fan index aec385cf0..c8915a375 100644 --- a/src/compilerJava/fan/JavaPod.fan +++ b/src/compilerJava/fan/JavaPod.fan @@ -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 @@ -68,4 +70,5 @@ class JavaPod : CPod ** Is this the fanx.interop package? const Bool isInterop -} \ No newline at end of file +} + diff --git a/src/doc/docIntro/doc/ChangeLog.fandoc b/src/doc/docIntro/doc/ChangeLog.fandoc index d4933b943..79ec0b09b 100644 --- a/src/doc/docIntro/doc/ChangeLog.fandoc +++ b/src/doc/docIntro/doc/ChangeLog.fandoc @@ -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 diff --git a/src/doc/docLang/doc/Pods.fandoc b/src/doc/docLang/doc/Pods.fandoc index 4b4f80c35..fb9d76e7d 100644 --- a/src/doc/docLang/doc/Pods.fandoc +++ b/src/doc/docLang/doc/Pods.fandoc @@ -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)