Issue 1:
Bug Report

I would like to work on a fix!

Current Behavior

This bug occurrs when transpile TypeScript codes.

define a function that has function type argument with default value and rest parameters.

define a variable that has same name as the argument function's argument name in the function body.

then compile, and 'var' expression in a for sentence is disappearing from output JS codes.

JS runtime will throw an error like ReferenceError: _len is not defined because the assignment of a global variable is not allowed with "use strict";.

change the BUGGY_ARGUMENT to DIFFERENT_ARGUMENT

works fine

Input Code

const func = (
someFunc: (BUGGY_ARGUMENT: number[]) => boolean = () => false,
...restParameters: number[]
) => {
const BUGGY_ARGUMENT = someFunc(restParameters);
console.log(BUGGY_ARGUMENT);
};

// output js codes
"use strict";

var func = function func() {
var someFunc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
return false;
};
return function () {
// THIS '_len' WILL THROW AN ERROR:
// `ReferenceError: _len is not defined`
for (_len = arguments.length, restParameters = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
restParameters[_key - 1] = arguments[_key];
}

var BUGGY_ARGUMENT = someFunc(restParameters);
console.log(BUGGY_ARGUMENT);
}.apply(null, arguments);
};

Expected behavior/code

const func = (
someFunc: (DIFFERENT_ARGUMENT: number[]) => boolean = () => false,
...restParameters: number[]
) => {
const BUGGY_ARGUMENT = someFunc(restParameters);
console.log(BUGGY_ARGUMENT);
};

"use strict";

var func = function func() {
var someFunc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
return false;
};
// THIS _len WORKS FINE!!
for (var _len = arguments.length, restParameters = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
restParameters[_key - 1] = arguments[_key];
}

var BUGGY_ARGUMENT = someFunc(restParameters);
console.log(BUGGY_ARGUMENT);
};

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

Filename: .babelrc

{
"presets": [
["@babel/env", {
"targets": {
"browsers": ["last 2 versions"]
}
}],
"@babel/typescript"
]
}

Environment

Babel version(s): 7.7.7

Node/npm version: Node 10

OS: macOS 10.14.6

Monorepo: no

How you are using Babel: cli

Possible Solution

Additional context/Screenshots

Add any other context about the problem here. If applicable, add screenshots to help explain.

This also occurs on online playground like the following

https://babeljs.io/repl#?browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=MYewdgzgLgBAZgVzMGBeGAKAUDGEQC2ApgGJLABcmAQgKoDi9AmgPoCCASvbQLICiAOQAqVMAgIAjIgCcA2gF0AlGgB8MCSBAAbIgEMwaTMtRq4urRCIAaHDAB0D6UWgAFXdN3EoMiKPFS5eSxjNQBvW1BIWDpGVk5ufmFDfGIyZAwnV3dPIm9pCEUAbgjwfB07LRAAcwwY5nYuXkEhIqwAX2KsRHSMEJgoaQQiVqA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Creact%2Cstage-2%2Ctypescript&prettier=false&targets=&version=7.7.7&externalPlugins=

Issue 2:
Bug Report

Current Behavior

Playground:

https://babeljs.io/repl#?browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABFApgZygClJRBeRTASnwD5EBvAKEUQDcBDAJ0Qf0QEYBuGxCBNHAA2KAHRC4Ac0wMiPAL4lqtRiwAOTFHXgg07AAwKuQA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015&prettier=false&targets=&version=7.7.4&externalPlugins=

Input Code

function test(func = () => {
var a = 1;
console.log(a);
}) {
var previous = 0;
};

Translate these with es2015 presets, the result is:

"use strict";

function test() {
var func = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
var a = 1;
console.log(a);
};
return function () {
previous = 0;
}();
}

;

We can see that the generated function returns a closure, and the various previous is not declared in the closure.

in strict mode, we will get the exception:

Uncaught ReferenceError: previous is not defined

Expected behavior/code

The var expression won't be removed.

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

Babel playground with es2015 preset config.

Additional context/Screenshots