(code: string)
| 16 | * 2. var a = 1; return (React.createElement('i', null, a)); |
| 17 | */ |
| 18 | export 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 | } |
no test coverage detected
searching dependent graphs…