-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TS import elision for JSX fragments and custom pragmas (#403)
Fixes #395 Previously, we added the `React` identifier as non-type identifier when seeing any JSX name, but this meant that fragment syntax didn't keep that import. We also shouldn't hard-code React, and instead use whatever the pragma base values are.
- Loading branch information
1 parent
b7b9ad1
commit 83f1178
Showing
9 changed files
with
115 additions
and
32 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
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
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
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
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
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,22 @@ | ||
import {Options} from "../index"; | ||
|
||
export interface JSXPragmaInfo { | ||
base: string; | ||
suffix: string; | ||
fragmentBase: string; | ||
fragmentSuffix: string; | ||
} | ||
|
||
export default function getJSXPragmaInfo(options: Options): JSXPragmaInfo { | ||
const [base, suffix] = splitPragma(options.jsxPragma || "React.createElement"); | ||
const [fragmentBase, fragmentSuffix] = splitPragma(options.jsxFragmentPragma || "React.Fragment"); | ||
return {base, suffix, fragmentBase, fragmentSuffix}; | ||
} | ||
|
||
function splitPragma(pragma: string): [string, string] { | ||
let dotIndex = pragma.indexOf("."); | ||
if (dotIndex === -1) { | ||
dotIndex = pragma.length; | ||
} | ||
return [pragma.slice(0, dotIndex), pragma.slice(dotIndex)]; | ||
} |
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
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
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