Add support for transpiling per-file jsx pragmas - #21218
Add support for transpiling per-file jsx pragmas#21218Wesley Wigham (weswigham) merged 5 commits into
Conversation
Ben Lichtman (uniqueiniquity)
left a comment
There was a problem hiding this comment.
Currently, JSX Fragments emit an error when used when jsxFactory is defined in the compiler options. This may change in the future, but until then you might need additional changes to ensure the error happens when the factory is only defined locally.
28a1178 to
52a6f22
Compare
|
Ben Lichtman (@uniqueiniquity) A similar error is now present when a fragment is used alongside an inline jsx pragma. 🌞 |
|
Mohamed Hegazy (@mhegazy) Do you wanna give this a brief look-over before it's merged? |
| } | ||
| export function dom(): void; | ||
| // @filename: index.tsx | ||
| /** @jsx dom */ |
There was a problem hiding this comment.
add a test with ** @jsx React.createElement */
| const referencedFiles: FileReference[] = []; | ||
| const typeReferenceDirectives: FileReference[] = []; | ||
| const amdDependencies: { path: string; name: string }[] = []; | ||
| let pragmas: { pragma: string, value: string | undefined }[] = []; |
There was a problem hiding this comment.
if we gonna add a new concept, then we should consolidate the other ones under pargma.. and we should allow /// as well as multi-line comments.
I would also have helper functions for getting all of these like amdDependecies, amdModuleNAme, checkJs, etc..
There was a problem hiding this comment.
Sure! I wanted to consolidate them, anyway, just didn't think this PR was appropriate.
There was a problem hiding this comment.
We need to ensure this works well when doing incremental parsing as well and need test for the same.
| if (file.localJsxNamespace) { | ||
| return file.localJsxNamespace; | ||
| } | ||
| const jsxPragma = file.pragmas.get("jsx"); |
There was a problem hiding this comment.
why is it jsx and not jsxNamespace like the compiler option?
There was a problem hiding this comment.
Babel supports jsx and I figured we'd want to support the same thing - we can alias jsxNamespace, if you'd like?
| } | ||
| } | ||
| export function dom(): void; | ||
| // @filename: index.tsx |
There was a problem hiding this comment.
also add a test with two files, and @jsxNamespace defined, and one of them with the new pragma.
7a7f20e to
3abda0a
Compare
This adds support for per-file jsx factory pragmas (similar to babel):
becomes
We still expect the global
jsxcompiler option to be set and the file extension to be tsx or jsx; but now you can mix multiple jsx frameworks in one project (just not more than one per file). This only affects emit and not typechecking - multiple different frameworks' types attempting to define, eg,JSX.Elementcan still result in type errors if those definitions conflict.Fixes #21114, probably?
ref #18131