Issue 1:
💻

Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

type key = null;

export function schema(schema) {
for (const key in obj) {
const subpath = key ? `${key}.test` : null;
if (typeof obj[key] === 'string') {
result[key] = (a) => t(subpath, a);
} else {
result[key] = toFunc(obj[key], subpath);
}
}
}

Configuration file name

babel.config.js

Configuration

babel.config.js

{
"presets": [
"@babel/env",
"@babel/typescript"
]
}

.babelrc.json

{
"presets": [
[
"react-app",
{
"runtime": "automatic",
"flow": false
}
]
],
"plugins": []
}

Current and expected behavior

It seems typescript typings are affecting the generated babel output. I was able to reproduce the issue on the babel repl:

in the input code type key = null

https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=false&spec=false&loose=false&code_lz=C4TwDgpgBA1hJQLxQHYFcA2GDcAoXEAHmAPYBOwUAZmigMbACWJKUAznQBYQC2AhgAoO3fgEooAb1wBIKuSgC6LNpTgJGrEgCMAVuKnTpSlCvZotYPsE5JY8KAH4oAAwAkEtQF8AdMAgrnKAAuVEwcGWlGKgVQSBJo7R0AbTUAXSREZAByFTINAHMs_QjpMn9MYBT4dOQBPnFEAD4oYCFzS2sAGih6vENPKAgMNmgDQzK2CqqQGpaSADFaOgFE6dTuyYsrTlE-6U8ZA4OgA&debug=false&forceAllTransforms=true&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Ctypescript&prettier=false&targets=&version=7.20.13&externalPlugins=babel-plugin-styled-components%402.0.7%2Cbabel-plugin-lodash%403.3.4&assumptions=%7B%7D

after changing type key = null to type key2 = null

https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=false&spec=false&loose=false&code_lz=C4TwDgpgBA1hICYoF4oDsCuAbLBuAUPhAB5gD2ATsFAGYZoDGwAlmWlAM4MAWEAtgEMAFF16CAlFADe-AJA1KUIQzYdqcEFGbsyAIwBWkmbNkq0azhl1gBwbiljwoAfigADACRSNAXwB0wBBqblAAXOjYeHKyzDRKoJBkcXr6ANoaALooyKgA5GoU2gDmuUbRshRB2MDp8FmoQgKSyAB8UMAiVjZ2ADRQTQQmPlAQWBzQxiaVHNW1IPXtZABi9AxCKXMZfTPWttzig7I-csfHQA&debug=false&forceAllTransforms=true&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Ctypescript&prettier=false&targets=&version=7.20.13&externalPlugins=babel-plugin-styled-components%402.0.7%2Cbabel-plugin-lodash%403.3.4&assumptions=%7B%7D

The first link results in invalid code.

In this case it seems the key symbol from the type definition is interfering with the js code and causing duplicate symbols

Environment

@babel/core: ^7.20.12 => 7.20.12
@babel/preset-env: ^7.20.2 => 7.20.2
@babel/preset-react: ^7.18.6 => 7.18.6
@babel/preset-typescript: ^7.18.6 => 7.18.6
babel-polyfill: ^6.26.0 => 6.26.0
babel-preset-react-app: ^10.0.1 => 10.0.1

Node: 16.15.0
npm: 8.10.0

OS: Linux

Possible solution

No response

Additional context

This started happening after upgrading to babel latest version

Issue 2:
💻

Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

const test = (data) => {
for (let i = 0; i < data.length; i++) {
const x = data[i];
data.find((item) => item === x);
}
for (let i = 0; i < data.length; i++) {
const x = data[i];
data.find((item) => item === x);
}
}

Configuration file name

.babelrc

Configuration

{

"presets": [

"@babel/preset-env"

]

}

Current and expected behavior

current output:

"use strict";

var test = function test(data) {
var _loop = function _loop() {
var x = data[i];
data.find(function (item) {
return item === x;
});
};
for (var i = 0; i < data.length; i++) {
_loop();
}
var _loop2 = function _loop2() {
var x = data[i];
data.find(function (item) {
return item === x;
});
};
for (var _i = 0; _i < data.length; _i++) {
_loop2();
}
};

the second var x = data[i]; should be var x = data[_i];

Environment

System:

OS: macOS 12.6.2

Binaries:

Node: 14.19.0 - /usr/local/bin/node

Yarn: 1.22.17 - /usr/local/bin/yarn

npm: 6.14.16 - /usr/local/bin/npm

npmPackages:

@babel/cli: ^7.17.6 => 7.17.6

@babel/core: ^7.20.7 => 7.20.7

@babel/node: ^7.16.8 => 7.16.8

@babel/plugin-transform-block-scoping: ^7.20.9 => 7.20.9

@babel/preset-env: ^7.16.11 => 7.16.11

Possible solution

No response

Additional context

No response