( ast: html.Block, connectedBlocks: html.Block[], visitor: html.Visitor, bindingParser: BindingParser, )
| 22 | } |
| 23 | |
| 24 | export function createBoundaryBlock( |
| 25 | ast: html.Block, |
| 26 | connectedBlocks: html.Block[], |
| 27 | visitor: html.Visitor, |
| 28 | bindingParser: BindingParser, |
| 29 | ): {node: t.BoundaryBlock | null; errors: ParseError[]} { |
| 30 | const errors: ParseError[] = []; |
| 31 | const errorBlocks: t.BoundaryErrorBlock[] = []; |
| 32 | |
| 33 | if (ast.parameters.length > 0) { |
| 34 | errors.push(new ParseError(ast.sourceSpan, '@boundary block cannot have parameters')); |
| 35 | } |
| 36 | |
| 37 | for (let blockIndex = 0; blockIndex < connectedBlocks.length; blockIndex++) { |
| 38 | const block = connectedBlocks[blockIndex]; |
| 39 | if (block.name !== 'error') { |
| 40 | errors.push( |
| 41 | new ParseError(block.sourceSpan, `Unrecognized @boundary connected block @${block.name}`), |
| 42 | ); |
| 43 | continue; |
| 44 | } |
| 45 | const emptySpan = new ParseSourceSpan(block.startSourceSpan.end, block.startSourceSpan.end); |
| 46 | const contextVariables: t.Variable[] = [ |
| 47 | new t.Variable('$error', '$error', emptySpan, emptySpan, emptySpan), |
| 48 | new t.Variable('$reset', '$reset', emptySpan, emptySpan, emptySpan), |
| 49 | ]; |
| 50 | let expression: AST | null = null; |
| 51 | |
| 52 | for (const param of block.parameters) { |
| 53 | const letMatch = param.expression.match(LET_PATTERN); |
| 54 | const isAliasMatch = param.expression.match(/^\s*[$A-Z_][0-9A-Z_$]*\s*=/i) !== null; |
| 55 | |
| 56 | if (letMatch !== null || isAliasMatch) { |
| 57 | const expressionToParse = letMatch !== null ? letMatch[1] : param.expression; |
| 58 | const variablesSpan = |
| 59 | letMatch !== null |
| 60 | ? new ParseSourceSpan( |
| 61 | param.sourceSpan.start.moveBy(letMatch[0].length - letMatch[1].length), |
| 62 | param.sourceSpan.end, |
| 63 | ) |
| 64 | : param.sourceSpan; |
| 65 | |
| 66 | parseLetParameters( |
| 67 | param.sourceSpan, |
| 68 | expressionToParse, |
| 69 | variablesSpan, |
| 70 | contextVariables, |
| 71 | errors, |
| 72 | (name, variableName, sourceSpan) => { |
| 73 | if (variableName !== '$error' && variableName !== '$reset') { |
| 74 | errors.push( |
| 75 | new ParseError( |
| 76 | sourceSpan, |
| 77 | `Unknown context variable "${variableName}". Only "$error" and "$reset" are allowed`, |
| 78 | ), |
| 79 | ); |
| 80 | } else if (contextVariables.some((v) => v.name === name)) { |
| 81 | errors.push( |
no test coverage detected