Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename module identifier by wrapping program.body with IIFE. #229

Merged
merged 3 commits into from
Jun 18, 2019

Commits on Jun 18, 2019

  1. Stop emitting variable declaration to capture module as moduleAlias.

    Before this change, in order to obtain a reliable reference to the
    original module object at runtime, the Reify compiler would inject a
    variable declaration at the beginning of the generated code that bound
    some other (uniquely named) variable to the module object, and then that
    unique variable was used in all the other Reify-generated expressions,
    such as module1.export(...) and module1.link(...).
    
    The trouble with this strategy was that the injected variable declaration
    could still collide with other declarations in the module scope that
    involve the `module` identifer.
    
    A better way to solve that problem is to introduce another scope by
    wrapping the module code in an immediately invoked function expression.
    The original module object can be passed as an argument to that function,
    and the corresponding parameter can be uniquely named.
    
    However, this wrapping should happen as late as possible, in some cases
    after multiple invocations of the Reify compiler, so the wrapping should
    not be the responsibility of the Reify compiler itself. Instead, the
    compiler should just use whatever options.moduleAlias is passed in, and
    not second-guess it or attempt to inject any variable bindings.
    benjamn committed Jun 18, 2019
    Configuration menu
    Copy the full SHA
    0cf44b1 View commit details
    Browse the repository at this point in the history
  2. Rename module identifier in Babel plugin by wrapping program.body.

    The Reify transform now runs twice: upon entering the Program AST node, to
    transform any import/export declarations found in the source code; and
    upon exiting the Program node, to transform any import/export declarations
    injected by other Babel transforms, e.g. @babel/plugin-transform-runtime.
    benjamn committed Jun 18, 2019
    Configuration menu
    Copy the full SHA
    7eedd7e View commit details
    Browse the repository at this point in the history
  3. Strengthen tests of Babel plugin output.

    After adding @babel/plugin-transform-runtime to the plugin pipeline, it's
    important to make sure any import declarations it injects into the program
    get handled by Reify.
    benjamn committed Jun 18, 2019
    Configuration menu
    Copy the full SHA
    bb30506 View commit details
    Browse the repository at this point in the history