Skip to content

export {func} not hoisted above import #5654

Closed

Description

@lukescott

I initially found an issue with webpack's module system. I reported that issue here webpack/webpack#4753.

I asked on the babel slack channel which behavior was correct, and @loganfsmyth said:

Looks like they are both a little wrong.

function foo(){}
export {foo};

and

export function foo(){}

should both export foo before processing the imported modules. Functions declaration bindings are initialized with their values before evaluating their imported modules.

Input Code

foo.js

import {bar} from "./bar";
function foo() {}
export {foo}

Expected Behavior

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.foo = foo; // <--- foo should be exported before import

var _bar = require("./bar");

function foo() {}

Current Behavior

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.foo = undefined; // <--- foo is not undefined

var _bar = require("./bar");

function foo() {}
exports.foo = foo; // <--- foo is defined after the import

Context

If I change my code to this I get the "Expected Behavior":

import {bar} from "./bar";
export function foo() {}

The original issue deals with circular dependencies. As such, I also have bar.js:

import {foo} from "./foo";
console.log(foo);

Your Environment

software version(s)
Babel 6.24.1 & REPL
node 7.8.0
npm 4.2.0
Operating System Mac OS 10.11.6

Activity

  1. babel-bot commented on Apr 20, 2017

    @babel-bot
    Collaborator

    Hey @lukescott! We really appreciate you taking the time to report an issue. The collaborators
    on this project attempt to help as many people as possible, but we're a limited number of volunteers,
    so it's possible this won't be addressed swiftly.

    If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
    community that typically always has someone willing to help. You can sign-up here
    for an invite.

  2. added
    outdated
    on May 4, 2018
  3. locked as resolved and limited conversation to collaborators on May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRarea: modulesoutdated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions