HaxeFoundation / HaxeFoundation/haxe

Custom js generator, dce and typedefs

Open
#9,252 4 comments 0 reactions 0 assignees View on GitHub
platform-javascript
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

When enabling DCE, a custom js generator receives only those concrete types that need to be generated. However it also receives every typedef included in the class path (even in unused modules). I'm generating Typescript definitions - and some of these typedefs reference concrete types that are not part of the generation (making Typescript upset). So I'm looking to either have unused typedefs not pass through to the `generate` call or for a way to check during generation if a typedef is in use?

````haxe
#if macro
import haxe.macro.Compiler;
import haxe.macro.JSGenApi;
#end

typedef Unused = {a: Int}

class Main {
#if macro
static function generate(api: JSGenApi) {
for (type in api.types)
switch type {
case TType(t, _): trace(t);
default:
}
}
public static function use() {
Compiler.setCustomJSGenerator(generate);
}
#end
static function main() {
trace('hello');
}
}
````
````bash
$ haxe --macro Main.use() --main Main --js out.js --dce full
Main.hx:13: Unused
Main.hx:13: Iterator
Main.hx:13: Iterable
Main.hx:13: KeyValueIterator
Main.hx:13: KeyValueIterable
Main.hx:13: js.lib.ObjectPrototype
Main.hx:13: js.lib.ObjectPropertyDescriptor
````

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.