[js] Generate ES modules#12882
Open
Frixuu wants to merge 16 commits into
Open
Conversation
Contributor
|
|
Contributor
Author
|
Contributor
the more you know |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new define called
js.module. It accepts one of the following values:es: New, focus of this PR. Generates an ECMAScript (ES) module,iife: Default behavior in Haxe 3 and 4. Generates an IIFE,classic: Default behavior in Haxe 2. Generates code that writes to global scope directly. This option replaces current switch-D js-classic.If
js.moduleis not defined, the compiler assumes optioniifefor compatibility with existing Haxe 4 code.Example
With the following arguments, this Haxe code transpiles to:
-D js.module=es -D js-es=6-D js.module=es -D js-es=2020-D js.module=iife -D js-es=6-D js.module=classic -D js-es=6Assumptions & questions
-D js.module=eswill refuse to work with-D js-es=5.export defaultgeneration.export default? What use case would necessitate it?$hx_exports, which["created"]["an"]["object"]["for"]["every"]["subpackage"], this PR's module implementation exports all symbols as flat identifiers to help with this goal.export class foo_Bar. There are no subpackages. Other JS modules may import this class withimport { foo_Bar } from "./generated.js".-D js-esis set to 2022 or above. This potentially makes the class above importable as{ "foo.Bar" as somethingElse }, for example when running-D js-unflatten. Is this desired behavior? Should this choice be declared explicitly, or not exist at all?Supersedes #10003. Closes #8033.