Issue 1:
Choose one: bug report (possibly)

I'm new to Babel and trying to figure out the correct way to make use of babel-external-helpers in a project that uses ES6 modules and targets Node and browsers.

I have a lengthy question about this on StackOverflow, and a repo demonstrating the issue, but the SO question hasn't received much attention yet. In the interest of brevity, I'll give the condensed version here.

I've created a babel-external-helpers file with the -t global option, so I am referencing it in my index.js file like this so that it can run before everything else and add the helpers to the global scope:

import './babel-helpers';

export * from './fileThatNeedsExternalHelpers';

If I run this through Babel with the env preset and the external-helpers plugin, I get this output:

'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _fileThatNeedsExternalHelpers = require('./fileThatNeedsExternalHelpers');

Object.keys(_fileThatNeedsExternalHelpers).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _fileThatNeedsExternalHelpers[key];
}
});
});

require('./babel-helpers');

We can see that what corresponds to the import has been moved to the end of the file, and my code won't run because my fileThatNeedsExternalHelpers needs the external helpers to be in the global scope when it executes (e.g. it uses syntax which, when transpiled, uses the defineProperty helper). If I manually edit the output file to move require('./babel-helpers'); above the var line, everything runs fine.

So my questions are:

What is the reason for rearranging imports and exports like this, and is there a (simple) way to control/suppress it?

Am I going about using external helpers the wrong way? Is there a better approach? I believe I could put the helpers in a module and explicitly import them in each file that needs them, but that doesn't seem like a very good solution.

software
version(s)

Babel
6.26.0

node
8.9.1

npm
5.0.3

Operating System
Win 10

Issue 2:
I have encountered something that's very likely a bug.

In the same module, the transpiled code for export ... from ... appears before the transpiled code for import ... in the output.

This scenario has already been asked here - unfortunately without an answer.

I think this is a bug because the 2 following snippets should be equivalent:

import foo from 'foo';
export { default as bar } from 'bar';

import foo from 'foo';
import bar from 'bar';
export { bar }

Input Code

import foo from 'foo';
export { default as bar } from 'bar';

see the REPL

Babel Configuration (.babelrc, package.json, cli command)

Part of my package.json:

{
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react-native": "^4.0.0",
"eslint": "^4.6.1",
"eslint-plugin-react": "^7.3.0",
"react-test-renderer": "16.0.0-alpha.12"
},
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
},
"dependencies": {
"immutable": "^3.8.1",
"prop-types": "^15.5.10",
"react": "16.0.0-alpha.12",
"react-native": "0.47",
"react-navigation": "^1.0.0-beta.11",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-promise": "^0.5.3",
"redux-thunk": "^2.2.0"
}
}

Expected Behavior

The behavior should be equivalent to

import foo from 'foo';
import bar from 'bar';
export { bar }

Current Behavior

Currently the code gets executed as if it was written like this:

export { default as bar } from 'bar';
import foo from 'foo';

'bar' is required before 'foo' no matter what exactly is put between export and from (e.g. the problem also occurs for export * from ...).

Context

I am exporting multiple moddules from an index.js file.

All exports depend on some code that must have been run.

import "./this_code_must_be_run_before_the_exports"
export * from "./first"
export * from "./second"

Your Environment

I am using babel with React Native.

software
version(s)

Babel
latest (https://babeljs.io/repl/)

node
8.7.0

npm
5.4.2

Operating System
macOS 10.12.6