Skip to content

Add support for generating a javascript module #11

@noxabellus

Description

@noxabellus

Most use of javascript today utilizes the module syntax, rather than declaring global variables. Support is now pretty much ubiquitous, and many projects use bundlers like webpack anyway, which understand the module syntax as well. The global variable export is still useful for some situations, but it would be nice to have a flag that can be passed to generate_js to allow the creation of a module instead. Perhaps a module could be the default, even. Alternatively, the generate_js cli could also just detect whether the output file extension is .js or .mjs and switch on that instead of a flag.

In any case, the required change would be fairly simple.

The existing definition created here could be rewritten as:

try writer.writeAll("class ");
try writer.writeAll(args[2]);
try writer.writeAll(
  \\ {
  ...

This would not change the existing semantics as far as I'm aware.

Then, configuration based on the flag/file extension could guard a small addition proceeding those lines:

if (makeModule) {
  try writer.writeAll("export default ");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions