Repository: babel/babel (TypeScript)

Issue:
[Bug]: wrong code generation for yield expressions followed by a type expression
### 💻

- [X] Would you like to work on a fix?

### How are you using Babel?

Programmatic API (`babel.transform`, `babel.parse`)

### Input code

```js
import { parse } from "@babel/parser";
import generator from "@babel/generator";

const code = `
function* generator() {
    const one = (yield "one") as number;
    console.log(one);
}
`;

const ast = parse(code, {
    plugins: ["typescript"],
});

const output = generator.default(ast);

console.log(output.code);
```

### Configuration file name

_No response_

### Configuration

_No response_

### Current and expected behavior

### Current behavior

parentheses gets removed for the `yield` expression during generation. this changes the meaning of the expression and creates type errors

```js
const one = (yield "one" as number);
```

### Expected behavior

```js
const one = ((yield "one") as number);
```

Update: this issue can be observed for `await` expressions as well

### Environment

System:
  OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
Binaries:
  Node: 22.3.0 - ~/.nvm/versions/node/v22.3.0/bin/node
  Yarn: 4.2.2 - /mnt/c/Users/sreen/AppData/Roaming/npm/yarn
  npm: 10.8.1 - ~/.nvm/versions/node/v22.3.0/bin/npm
Monorepos:
  Yarn Workspaces: 4.2.2
npmPackages:
  @babel/cli: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/core: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/eslint-config-internal: workspace:^ => 7.24.6 
  @babel/eslint-parser: workspace:^ => 7.24.7 
  @babel/eslint-plugin-development: workspace:^ => 7.24.7 
  @babel/eslint-plugin-development-internal: workspace:^ => 7.24.7 
  @babel/plugin-proposal-json-modules: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/plugin-transform-dynamic-import: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/plugin-transform-export-namespace-from: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/plugin-transform-modules-commonjs: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/plugin-transform-object-rest-spread: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/plugin-transform-runtime: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/preset-env: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/preset-typescript: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  @babel/runtime: 8.0.0-alpha.8 => 8.0.0-alpha.8 
  babel-plugin-transform-charcodes: ^0.2.0 => 0.2.0 
  eslint: ^9.2.0 => 9.2.0 
  jest: ^30.0.0-alpha.2 => 30.0.0-alpha.2

### Possible solution

add parentheses around yield expressions if its parent is of type `TSAsExpression`, `TSSatisfiesExpression` or `TSTypeAssertion`

### Additional context

_No response_


Hints:
Hey @SreeXD! 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](https://babeljs.slack.com) that typically always has someone willing to help. You can sign-up [here](https://slack.babeljs.io/) for an invite.

Patch:
diff --git a/packages/babel-generator/src/node/parentheses.ts b/packages/babel-generator/src/node/parentheses.ts
--- a/packages/babel-generator/src/node/parentheses.ts
+++ b/packages/babel-generator/src/node/parentheses.ts
@@ -307,7 +307,8 @@ export function YieldExpression(
     hasPostfixPart(node, parent) ||
     (parentType === "AwaitExpression" && isYieldExpression(node)) ||
     (parentType === "ConditionalExpression" && node === parent.test) ||
-    isClassExtendsClause(node, parent)
+    isClassExtendsClause(node, parent) ||
+    isTSTypeExpression(parentType)
   );
 }
 


Test patch:
diff --git a/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/input.js b/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/input.js
@@ -0,0 +1,5 @@
+function* generator() {
+    const one = (yield "one") as number;
+    const two = <number>(yield "two");
+    const three = (yield "three") satisfies number;
+}
diff --git a/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/options.json b/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/options.json
@@ -0,0 +1,3 @@
+{
+  "plugins": ["typescript"]
+}
diff --git a/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/output.js b/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-generator/test/fixtures/typescript/yield-expression-inside-type-expression/output.js
@@ -0,0 +1,5 @@
+function* generator() {
+  const one = ((yield "one") as number);
+  const two = (<number> (yield "two"));
+  const three = ((yield "three") satisfies number);
+}
\ No newline at end of file