fix(es/react): Don't panic on invalid react pragma (#5101)

This commit is contained in:
magic-akari 2022-07-04 19:55:08 +08:00 committed by GitHub
parent b79593f7ef
commit cc555ef225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 82 additions and 13 deletions

View File

@ -313,17 +313,26 @@ impl JsxDirectives {
Some("@jsxRuntime") => match val {
Some("classic") => res.runtime = Some(Runtime::Classic),
Some("automatic") => res.runtime = Some(Runtime::Automatic),
_ => todo!("proper error reporting for wrong `@jsxRuntime`"),
None => {}
_ => {
HANDLER.with(|handler| {
handler
.struct_span_err(
cmt.span,
"Runtime must be either `classic` or `automatic`.",
)
.emit()
});
}
},
Some("@jsxImportSource") => match val {
Some(src) => {
Some("@jsxImportSource") => {
if let Some(src) = val {
res.runtime = Some(Runtime::Automatic);
res.import_source = Some(src.into());
}
_ => todo!("proper error reporting for wrong `@jsxImportSource`"),
},
Some("@jsxFrag") => match val {
Some(src) => {
}
Some("@jsxFrag") => {
if let Some(src) = val {
// TODO: Optimize
let mut e = (*parse_expr_for_jsx(
cm,
@ -335,10 +344,9 @@ impl JsxDirectives {
respan(&mut e, cmt.span);
res.pragma_frag = Some(e.into())
}
_ => todo!("proper error reporting for wrong `@jsxFrag`"),
},
Some("@jsx") => match val {
Some(src) => {
}
Some("@jsx") => {
if let Some(src) = val {
// TODO: Optimize
let mut e = (*parse_expr_for_jsx(
cm,
@ -350,8 +358,7 @@ impl JsxDirectives {
respan(&mut e, cmt.span);
res.pragma = Some(e.into());
}
_ => todo!("proper error reporting for wrong `@jsxFrag`"),
},
}
_ => {}
}
}

View File

@ -0,0 +1,26 @@
/** @jsx h */
/** @jsxFrag */
import { h } from "preact";
import { Marked } from "markdown";
export const handler = {
async GET(req, ctx) {
const markdown = await Deno.readTextFile(`posts/${ctx.params.id}.md`);
const markup = Marked.parse(markdown);
const resp = await ctx.render({ markup });
return resp;
},
};
export default function Greet(props) {
return (
<>
<div
dangerouslySetInnerHTML={{
__html: props.data.markup.content,
}}
/>
</>
);
}

View File

@ -0,0 +1,19 @@
/** @jsx h */ /** @jsxFrag */ import { h } from "preact";
import { Marked } from "markdown";
export const handler = {
async GET (req, ctx) {
const markdown = await Deno.readTextFile(`posts/${ctx.params.id}.md`);
const markup = Marked.parse(markdown);
const resp = await ctx.render({
markup
});
return resp;
}
};
export default function Greet(props) {
return /*#__PURE__*/ h(React.Fragment, null, /*#__PURE__*/ h("div", {
dangerouslySetInnerHTML: {
__html: props.data.markup.content
}
}));
};

View File

@ -0,0 +1,3 @@
/** @jsxRuntime typo */
<></>;

View File

@ -0,0 +1 @@
/** @jsxRuntime typo */ /*#__PURE__*/ React.createElement(React.Fragment, null);

View File

@ -0,0 +1,6 @@
x Runtime must be either `classic` or `automatic`.
,-[input.js:1:1]
1 | /** @jsxRuntime typo */
: ^^^^^^^^^^^^^^^^^^^^^^^
`----

View File

@ -0,0 +1,6 @@
/** @jsxRuntime */
/** @jsxImportSource */
/** @jsxFrag */
/** @jsx */
<></>;

View File

@ -0,0 +1 @@
/** @jsxRuntime */ /** @jsxImportSource */ /** @jsxFrag */ /** @jsx */ /*#__PURE__*/ React.createElement(React.Fragment, null);