packages/ast/jsxParse
AST package: strict JSX parsing on typescript-estree (the JSX edit/analysis family, #173).
AST, v0.8. Source: packages/ast/jsxParse.mjs.
Functions#
checkJsxReplacement()#
checkJsxReplacement(
snippet): {ok:true; } | {error:string;kind:"parse";ok:false; } | {kind:"shape";ok:false; }
Defined in: packages/ast/jsxParse.mjs:85
Check a replacement snippet that is to be spliced in place of one JSX node: it must parse on its
own as a JSX expression, and be exactly one element or fragment. Returns {ok: true}, or
{ok: false, kind: 'parse', error} (not valid JSX) / {ok: false, kind: 'shape'} (valid, but not a
single JSX element/fragment).
Parameters#
snippet
string
Candidate replacement for one JSX node.
Returns#
{ ok: true; } | { error: string; kind: "parse"; ok: false; } | { kind: "shape"; ok: false; }
Whether the snippet is exactly one element or fragment.
Example#
checkJsxReplacement('<b>hi</b>'); // => { ok: true }
jsxParseError()#
jsxParseError(
source):string
Defined in: packages/ast/jsxParse.mjs:64
The parser's error message if source is not a valid JSX/TSX module, else null.
Parameters#
source
string
JSX or TSX module text.
Returns#
string
The parser's message, or null when the source is valid.
parseJsx()#
parseJsx(
source):any
Defined in: packages/ast/jsxParse.mjs:52
Parse source as a JSX/TSX module. Throws (a plain Error carrying the parser's message) on a syntax error.
Parameters#
source
string
JSX or TSX module text.
Returns#
any
A typescript-estree Program node.
Throws#
Carrying the parser's message on a syntax error.
Since#
0.8