| 2113 | return null; |
| 2114 | } |
| 2115 | function parsePatternElements(elements = [], commonIndent) { |
| 2116 | while (true) { |
| 2117 | if (test(RE_TEXT_RUN)) { |
| 2118 | elements.push(match1(RE_TEXT_RUN)); |
| 2119 | continue; |
| 2120 | } |
| 2121 | if (source[cursor] === "{") { |
| 2122 | elements.push(parsePlaceable()); |
| 2123 | continue; |
| 2124 | } |
| 2125 | if (source[cursor] === "}") { |
| 2126 | throw new SyntaxError("Unbalanced closing brace"); |
| 2127 | } |
| 2128 | let indent = parseIndent(); |
| 2129 | if (indent) { |
| 2130 | elements.push(indent); |
| 2131 | commonIndent = Math.min(commonIndent, indent.length); |
| 2132 | continue; |
| 2133 | } |
| 2134 | break; |
| 2135 | } |
| 2136 | let lastIndex = elements.length - 1; |
| 2137 | let lastElement = elements[lastIndex]; |
| 2138 | if (typeof lastElement === "string") { |
| 2139 | elements[lastIndex] = trim(lastElement, RE_TRAILING_SPACES); |
| 2140 | } |
| 2141 | let baked = []; |
| 2142 | for (let element of elements) { |
| 2143 | if (element instanceof Indent) { |
| 2144 | element = element.value.slice(0, element.value.length - commonIndent); |
| 2145 | } |
| 2146 | if (element) { |
| 2147 | baked.push(element); |
| 2148 | } |
| 2149 | } |
| 2150 | return baked; |
| 2151 | } |
| 2152 | function parsePlaceable() { |
| 2153 | consumeToken(TOKEN_BRACE_OPEN, SyntaxError); |
| 2154 | let selector = parseInlineExpression(); |