-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler: Handle TSNonNullAssertion expressions
- Loading branch information
1 parent
3ac551e
commit cff78dd
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...gin-react-compiler/src/__tests__/fixtures/compiler/non-null-assertion.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
12 changes: 12 additions & 0 deletions
12
...ackages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/non-null-assertion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }], | ||
}; |