( ast: html.Block, connectedBlocks: html.Block[], visitor: html.Visitor, bindingParser: BindingParser, )
| 56 | |
| 57 | /** Creates a deferred block from an HTML AST node. */ |
| 58 | export function createDeferredBlock( |
| 59 | ast: html.Block, |
| 60 | connectedBlocks: html.Block[], |
| 61 | visitor: html.Visitor, |
| 62 | bindingParser: BindingParser, |
| 63 | ): {node: t.DeferredBlock; errors: ParseError[]} { |
| 64 | const errors: ParseError[] = []; |
| 65 | const {placeholder, loading, error} = parseConnectedBlocks(connectedBlocks, errors, visitor); |
| 66 | const {triggers, prefetchTriggers, hydrateTriggers} = parsePrimaryTriggers( |
| 67 | ast, |
| 68 | bindingParser, |
| 69 | errors, |
| 70 | placeholder, |
| 71 | ); |
| 72 | |
| 73 | // The `defer` block has a main span encompassing all of the connected branches as well. |
| 74 | let lastEndSourceSpan = ast.endSourceSpan; |
| 75 | let endOfLastSourceSpan = ast.sourceSpan.end; |
| 76 | if (connectedBlocks.length > 0) { |
| 77 | const lastConnectedBlock = connectedBlocks[connectedBlocks.length - 1]; |
| 78 | lastEndSourceSpan = lastConnectedBlock.endSourceSpan; |
| 79 | endOfLastSourceSpan = lastConnectedBlock.sourceSpan.end; |
| 80 | } |
| 81 | |
| 82 | const sourceSpanWithConnectedBlocks = new ParseSourceSpan( |
| 83 | ast.sourceSpan.start, |
| 84 | endOfLastSourceSpan, |
| 85 | ); |
| 86 | |
| 87 | const node = new t.DeferredBlock( |
| 88 | html.visitAll(visitor, ast.children, ast.children), |
| 89 | triggers, |
| 90 | prefetchTriggers, |
| 91 | hydrateTriggers, |
| 92 | placeholder, |
| 93 | loading, |
| 94 | error, |
| 95 | ast.nameSpan, |
| 96 | sourceSpanWithConnectedBlocks, |
| 97 | ast.sourceSpan, |
| 98 | ast.startSourceSpan, |
| 99 | lastEndSourceSpan, |
| 100 | ast.i18n, |
| 101 | ); |
| 102 | |
| 103 | return {node, errors}; |
| 104 | } |
| 105 | |
| 106 | function parseConnectedBlocks( |
| 107 | connectedBlocks: html.Block[], |
no test coverage detected
searching dependent graphs…