Retain JSX pragma if defined as a comment (#9095)
This commit is contained in:
parent
7dc157f9be
commit
03230eaa9c
@ -25,6 +25,8 @@ const PARSED_PARAMS = new WeakSet();
|
||||
export default declare((api, { jsxPragma = "React" }) => {
|
||||
api.assertVersion(7);
|
||||
|
||||
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
|
||||
|
||||
return {
|
||||
name: "transform-typescript",
|
||||
inherits: syntaxTypeScript,
|
||||
@ -38,6 +40,17 @@ export default declare((api, { jsxPragma = "React" }) => {
|
||||
Program(path, state: State) {
|
||||
state.programPath = path;
|
||||
|
||||
const { file } = state;
|
||||
|
||||
if (file.ast.comments) {
|
||||
for (const comment of (file.ast.comments: Array<Object>)) {
|
||||
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
|
||||
if (jsxMatches) {
|
||||
jsxPragma = jsxMatches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove type imports
|
||||
for (const stmt of path.get("body")) {
|
||||
if (t.isImportDeclaration(stmt)) {
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
/* @jsx htm */
|
||||
// Don't elide htm if a JSX element appears somewhere.
|
||||
import { htm } from "fake-jsx-package";
|
||||
<div></div>;
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"plugins": [["transform-typescript", { "isTSX": true }]]
|
||||
}
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
/* @jsx htm */
|
||||
// Don't elide htm if a JSX element appears somewhere.
|
||||
import { htm } from "fake-jsx-package";
|
||||
<div></div>;
|
||||
Loading…
x
Reference in New Issue
Block a user