mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
fix(es/react): Don't panic on invalid react pragma (#5101)
This commit is contained in:
parent
b79593f7ef
commit
cc555ef225
@ -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`"),
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
@ -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
|
||||
}
|
||||
}));
|
||||
};
|
@ -0,0 +1,3 @@
|
||||
/** @jsxRuntime typo */
|
||||
|
||||
<></>;
|
@ -0,0 +1 @@
|
||||
/** @jsxRuntime typo */ /*#__PURE__*/ React.createElement(React.Fragment, null);
|
@ -0,0 +1,6 @@
|
||||
|
||||
x Runtime must be either `classic` or `automatic`.
|
||||
,-[input.js:1:1]
|
||||
1 | /** @jsxRuntime typo */
|
||||
: ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
`----
|
@ -0,0 +1,6 @@
|
||||
/** @jsxRuntime */
|
||||
/** @jsxImportSource */
|
||||
/** @jsxFrag */
|
||||
/** @jsx */
|
||||
|
||||
<></>;
|
@ -0,0 +1 @@
|
||||
/** @jsxRuntime */ /** @jsxImportSource */ /** @jsxFrag */ /** @jsx */ /*#__PURE__*/ React.createElement(React.Fragment, null);
|
Loading…
Reference in New Issue
Block a user