-
Notifications
You must be signed in to change notification settings - Fork 123
feat(react): support "jsx": "react-jsx"
#545
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5f222c7
fix(create-rspeedy): monorepo type error
Mori-Yang d57d5ff
Merge branch 'main' into main
Mori-Yang 73945ff
feat(react):standalone namespace JSX
Mori-Yang 95c595a
chore: import types
Mori-Yang d266103
Merge branch 'main' into main
Mori-Yang f2f7e42
Merge branch 'lynx-family:main' into main
Mori-Yang 8e182eb
chore: remove ref types , WIP
Mori-Yang f9d273c
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang 381b5ca
chore: add typecheck
Mori-Yang 9d52ebd
Merge branch 'main' into main
Mori-Yang 044353b
style: remove redundant imports
Mori-Yang 6ddd58f
chore: export JSX
Mori-Yang 751ebfd
Merge branch 'main' into main
Mori-Yang afcb436
chore: some text...
Mori-Yang 357b7fd
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang 306b051
fix: export JSX
Mori-Yang d7826dd
Merge branch 'main' into main
Mori-Yang 31c5310
chore:add tscofnig and type tests
Mori-Yang 4846f02
chore: check
Mori-Yang cf6e176
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang 84d847d
Merge branch 'main' into main
colinaaa e689d0e
chore: modify tests
Mori-Yang 41c5f9e
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang 47e7e88
Merge branch 'main' into main
colinaaa 8d22d9d
chore: modify tests
Mori-Yang d6405ec
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang b2f65e7
Create orange-days-chew.md
colinaaa af47ccc
Create stupid-hounds-reflect.md
colinaaa deff0b8
fix: exclude .test-d.* file when coverage test
Mori-Yang 99f1eae
Merge branch 'main' of https://github.com/Mori-Yang/lynx-stack
Mori-Yang dae5e11
fix: .*
Mori-Yang 65927c5
fix: eslint import order
colinaaa cd76e63
Merge remote-tracking branch 'upstream/main' into Mori-Yang/main
colinaaa d21f113
fix: change template of testing library
colinaaa 9fbd518
ci: run tsc on test-publish
colinaaa c08de88
ci: remove tsc check
colinaaa aa26f1c
Merge remote-tracking branch 'upstream/main' into Mori-Yang/main
colinaaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
| --- | ||
| "@lynx-js/react": patch | ||
| --- | ||
|
|
||
| Support using `"jsx": "react-jsx"` along with `"jsxImportSource": "@lynx-js/react"` in `tsconfig.json`. | ||
|
|
||
| ```json | ||
| { | ||
| "compilerOptions": { | ||
| "jsx": "react-jsx", | ||
| "jsxImportSource": "@lynx-js/react" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This configuration enhances TypeScript definitions for standard JSX elements, | ||
| providing type errors for unsupported elements like `<div>` or `<button>`. |
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "create-rspeedy": patch | ||
| --- | ||
|
|
||
| Use `"jsx": "react-jsx"` with `"jsxImportSource": "@lynx-js/react"`. |
This file contains hidden or 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,9 @@ | ||
| { | ||
| "extends": "../../../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "jsx": "react-jsx", | ||
| "jsxImportSource": "@lynx-js/react", | ||
| "noEmit": true, | ||
| }, | ||
| "include": ["**/*.ts", "**/*.tsx", "../../types/react.d.ts"], | ||
| } |
104 changes: 104 additions & 0 deletions
104
packages/react/runtime/__test__/typecheck/jsx-runtime.test-d.tsx
This file contains hidden or 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,104 @@ | ||
| // Copyright 2024 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import type { JSX } from '../../jsx-runtime/index.js'; | ||
| import type { MainThread, NodesRef, Target, TouchEvent } from '@lynx-js/types'; | ||
| import { assertType, describe, test } from 'vitest'; | ||
| import { useMainThreadRef } from '../../src/lynx-api.js'; | ||
| import { useRef } from '../../src/hooks/react.js'; | ||
|
|
||
| describe('JSX Runtime Types', () => { | ||
| test('should support basic JSX element', () => { | ||
| const viewEle = ( | ||
| <view> | ||
| <text>child node</text> | ||
| </view> | ||
| ); | ||
| assertType<JSX.Element>(viewEle); | ||
| }); | ||
|
|
||
| test('should validate the required props for raw-text', () => { | ||
| // @ts-expect-error: Missing required prop 'text' | ||
| const shouldError = <raw-text></raw-text>; | ||
|
|
||
| const rawTextELe = <raw-text text={'text'}></raw-text>; | ||
| assertType<JSX.Element>(rawTextELe); | ||
| }); | ||
|
|
||
| test('should support JSX.Elements', () => { | ||
| function App() { | ||
| function renderFoo(): JSX.Element { | ||
| return <text></text>; | ||
| } | ||
| return renderFoo(); | ||
| } | ||
| assertType<JSX.Element>(App()); | ||
| }); | ||
|
|
||
| test('should error on unsupported tags', () => { | ||
| // @ts-expect-error: Unsupported tag | ||
| const divElement = <div></div>; | ||
| }); | ||
|
|
||
| test('should support event handlers', () => { | ||
| const viewWithBind = ( | ||
| <view | ||
| bindtap={(e) => { | ||
| assertType<number>(e.detail.x); | ||
| assertType<TouchEvent>(e); | ||
| }} | ||
| > | ||
| </view> | ||
| ); | ||
| const viewWithCatch = ( | ||
| <view | ||
| catchtap={(e) => { | ||
| assertType<Target>(e.currentTarget); | ||
| assertType<TouchEvent>(e); | ||
| }} | ||
| > | ||
| </view> | ||
| ); | ||
| assertType<JSX.Element>(viewWithBind); | ||
| assertType<JSX.Element>(viewWithCatch); | ||
| }); | ||
|
|
||
| test('should support main-thread event handlers', () => { | ||
| const viewWithMainThreadEvent = ( | ||
| <view | ||
| main-thread:bindtap={(e) => { | ||
| assertType<number>(e.detail.x); | ||
| assertType<MainThread.Element>(e.currentTarget); | ||
| }} | ||
| > | ||
| </view> | ||
| ); | ||
| assertType<JSX.Element>(viewWithMainThreadEvent); | ||
| }); | ||
|
|
||
| test('should support ref prop with ref object', () => { | ||
| const ref = useRef<NodesRef>(null); | ||
| const viewWithRefObject = <view ref={ref}></view>; | ||
| assertType<JSX.Element>(viewWithRefObject); | ||
| }); | ||
|
|
||
| test('should support ref prop with function', () => { | ||
| const ref = useRef<NodesRef>(null); | ||
| const viewWithRefCallback = ( | ||
| <view | ||
| ref={(n) => { | ||
| assertType<NodesRef | null>(n); | ||
| ref.current = n; | ||
| }} | ||
| > | ||
| </view> | ||
| ); | ||
| assertType<JSX.Element>(viewWithRefCallback); | ||
| }); | ||
|
|
||
| test('should support main-thread ref', () => { | ||
| const mtRef = useMainThreadRef<MainThread.Element>(null); | ||
| const viewWithMainThreadRef = <view main-thread:ref={mtRef}></view>; | ||
| assertType<JSX.Element>(viewWithMainThreadRef); | ||
| }); | ||
| }); | ||
|
Mori-Yang marked this conversation as resolved.
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,17 @@ | ||
| // Copyright 2024 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import { JSX as _JSX } from 'react'; | ||
|
|
||
| import { IntrinsicElements as _IntrinsicElements } from '@lynx-js/types'; | ||
|
|
||
| export { jsxDEV, Fragment } from 'react/jsx-dev-runtime'; | ||
| export { jsx, jsxs } from 'react/jsx-runtime'; | ||
|
|
||
| export namespace JSX { | ||
| interface IntrinsicElements extends _IntrinsicElements {} | ||
|
|
||
| interface IntrinsicAttributes {} | ||
|
|
||
| type Element = _JSX.Element; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,16 @@ | ||
| // Copyright 2024 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import { JSX as _JSX } from 'react'; | ||
|
|
||
| import { IntrinsicElements as _IntrinsicElements } from '@lynx-js/types'; | ||
|
|
||
| export { jsx, jsxs, Fragment } from 'react/jsx-runtime'; | ||
|
|
||
| export namespace JSX { | ||
| interface IntrinsicElements extends _IntrinsicElements {} | ||
|
|
||
| interface IntrinsicAttributes {} | ||
|
|
||
| type Element = _JSX.Element; | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
packages/rspeedy/create-rspeedy/template-react-ts/tsconfig.json
This file contains hidden or 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
5 changes: 3 additions & 2 deletions
5
packages/rspeedy/create-rspeedy/template-react-vitest-rltl-ts/tsconfig.json
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.