MCPcopy Create free account
hub / github.com/styleguidist/react-styleguidist / splitExampleCode

Function splitExampleCode

src/client/utils/splitExampleCode.ts:18–38  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

16 * 2. var a = 1; return (React.createElement('i', null, a));
17 */
18export default function splitExampleCode(code: string): { head: string; example: string } {
19 const ast = getAst(code);
20 if (!ast) {
21 return { head: '', example: code };
22 }
23
24 const firstExpression = find(ast.body.reverse(), { type: 'ExpressionStatement' });
25 if (!firstExpression) {
26 return { head: '', example: code };
27 }
28
29 const { start, end } = firstExpression;
30 const head = unsemicolon(code.substring(0, start));
31 const firstExpressionCode = unsemicolon(code.substring(start, end));
32 const example = `${head};\nreturn (${firstExpressionCode});`;
33
34 return {
35 head,
36 example,
37 };
38}

Callers 2

renderMethod · 0.85

Calls 2

unsemicolonFunction · 0.85
getAstFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…