Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: Handle TSNonNullAssertion expressions #29218

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,10 @@ function lowerExpression(
loc: expr.node.loc ?? GeneratedSource,
};
}
case "TSNonNullExpression": {
let expr = exprPath as NodePath<t.TSNonNullExpression>;
return lowerExpression(builder, expr.get("expression"));
}
default: {
builder.errors.push({
reason: `(BuildHIR::lowerExpression) Handle ${exprPath.type} expressions`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

## Input

```javascript
interface ComponentProps {
name?: string;
}

function Component(props: ComponentProps) {
return props.name!.toUpperCase();
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ name: "Alice" }],
};

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
interface ComponentProps {
name?: string;
}

function Component(props) {
const $ = _c(2);
let t0;
if ($[0] !== props.name) {
t0 = props.name.toUpperCase();
$[0] = props.name;
$[1] = t0;
} else {
t0 = $[1];
}
return t0;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ name: "Alice" }],
};

```

### Eval output
(kind: ok) "ALICE"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface ComponentProps {
name?: string;
}

function Component(props: ComponentProps) {
return props.name!.toUpperCase();
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: [{ name: "Alice" }],
};