FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Avoid IIFE definitions in generated JavaScript · Issue #2206 · purescript/purescript · GitHub

Avoid IIFE definitions in generated JavaScript #2206

Description

Tagging this with discussion, because I'm not sure if doing so is problematic.

An example of the offending code:

var Just = (function () {
    function Just(value0) {
        this.value0 = value0;
    };
    Just.create = function (value0) {
        return new Just(value0);
    };
    return Just;
})();

var Nothing = (function () {
    function Nothing() {
    };
    Nothing.value = new Nothing();
    return Nothing;
})();

The IIFE exists so that the definition of Just and Nothing do not involve statements at the module level (the create / value property assignments). In theory this makes them easier to erase, since the whole value can be eliminated, but apparently Uglify considers this to be side-effectful. I assume it takes that stance with any IIFE definition, since here only values in the internal scope of the IIFE are referenced.

I actually don't remember exactly why I did introduce the IIFE... it may purely be to avoid the module-level statements, or perhaps codegen can only produce single AST values for declarations. The latter wouldn't be too much of a problem to change, it's just a bit of refactoring.

/cc @AppShipIt @spicydonuts

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions


Back | FazBrowse Home | New Git URL