Issue 1:
Bug Report

Current Behavior

const aren't being transpiled in the following situation:

they are defined on a dependency file, in node_modules

they have a function assigned const a = param => 'whatever'

that function is used by another function that is consumed by the entry point

Input Code

Filename: entry.js

import { foo } from 'package_in_node_modules';

export default class Whatever {
constructor(param) {
console.log(foo(param));
}
}

Filename: package_in_node_modules/index.js

const helper = param => param.length;

export function foo(param) {
return helper(param)
}

build ouptut

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

const helper = param => param.length;

function foo(param) {
return helper(param);
}

var Whatever = function Whatever(param) {
_classCallCheck(this, Whatever);

console.log(foo(param));
};

export default Whatever;

Expected behavior/code

const helper being replaced by var helper

expected ouptut

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

var helper = param => param.length;

function foo(param) {
return helper(param);
}

var Whatever = function Whatever(param) {
_classCallCheck(this, Whatever);

console.log(foo(param));
};

export default Whatever;

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

Filename: .babelrc

{
"env": {
"es5": {
"presets": [
["@babel/preset-env", {
"useBuiltIns": "usage",
"corejs": 3,
"modules": false,
"targets": ">= 0.01%"
}]
]
}
}
}

Filename: rollup.config.js

import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

export default {
input: ['./entry.js'],
output: [
{
file: `./dist/index.es5.js`,
format: 'esm'
}
],
plugins: [
resolve(),
commonjs(),
babel({
envName: 'es5'
})
]
};

Environment

Babel version(s): 7.7.4

Node/npm version: node 8.16.2 / npm: 6.4.1

OS: macOS 10.15.1

Monorepo: Lerna

How you are using Babel: loader

Issue 2:
Input Code

In a new folder run npm install babel-core babylon, then put the following code in traverse-error.js

var code = `
import foo from './foo'
const foo = undefined
`

var babelCore = require('babel-core')
var babylon = require('babylon')

var ast = {
type: 'File',
start: 0,
end: code.length,
program: babylon.parse(code, {
sourceType: 'module'
})
}

babelCore.traverse(ast, {})

Expected Behavior

node traverse-error.js should run with no output. If you simply rename the import foo or const foo to avoid the collision, it will run as expected.

Current Behavior

asa@asa:/tmp/babel-issue$ node traverse-error.js
/tmp/babel-issue/node_modules/babel-traverse/lib/scope/index.js:397
throw this.hub.file.buildCodeFrameError(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
^

TypeError: Cannot read property 'file' of undefined
at Scope.checkBlockScopedCollisions (/tmp/babel-issue/node_modules/babel-traverse/lib/scope/index.js:397:21)
at Scope.registerBinding (/tmp/babel-issue/node_modules/babel-traverse/lib/scope/index.js:579:16)
at Scope.registerDeclaration (/tmp/babel-issue/node_modules/babel-traverse/lib/scope/index.js:483:14)
at Object.BlockScoped (/tmp/babel-issue/node_modules/babel-traverse/lib/scope/index.js:185:28)
at Object.newFn (/tmp/babel-issue/node_modules/babel-traverse/lib/visitors.js:318:17)
at NodePath._call (/tmp/babel-issue/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/tmp/babel-issue/node_modules/babel-traverse/lib/path/context.js:44:14)
at NodePath.visit (/tmp/babel-issue/node_modules/babel-traverse/lib/path/context.js:105:12)
at TraversalContext.visitQueue (/tmp/babel-issue/node_modules/babel-traverse/lib/context.js:150:16)
at TraversalContext.visitMultiple (/tmp/babel-issue/node_modules/babel-traverse/lib/context.js:103:17)

Context

I have an Atom plugin called js-hyperclick. It parses your JS files and allows you to ctrl+click filenames or variables to jump to their definitions. Today I've been working on getting js-hyperclick to inform the user when it can't function. If you have a syntax error that causes babylon.parse to throw I can help the user:

Because this error happens when traversing and the error points to babel-traverse code, showing the user doesn't help them:

I tend to run into this when I'm trying to extract foo into its own file. I'll add import foo from './new-file', then if this were able to parse I could ctrl+click the ./new-file or foo to open a new editor at that path and cut/paste whatever foo needs.

Your Environment

software
version

Babel
5.8.25 and 6.17.0

node
4 and 6

I wouldn't expect it to get fixed back in Babel5, but the code above also demonstrates the error with npm install babel-core@5 and replace babylon.parse with babelCore.parse