(start: CharacterCursor, nameStart: CharacterCursor)
| 1323 | } |
| 1324 | |
| 1325 | private _consumeDirective(start: CharacterCursor, nameStart: CharacterCursor) { |
| 1326 | this._requireCharCode(chars.$AT); |
| 1327 | |
| 1328 | // Skip over the @ since it's not part of the name. |
| 1329 | this._cursor.advance(); |
| 1330 | |
| 1331 | // Capture the rest of the name. |
| 1332 | while (isSelectorlessNameChar(this._cursor.peek())) { |
| 1333 | this._cursor.advance(); |
| 1334 | } |
| 1335 | |
| 1336 | // Capture the opening token. |
| 1337 | this._beginToken(TokenType.DIRECTIVE_NAME, start); |
| 1338 | const name = this._cursor.getChars(nameStart); |
| 1339 | this._endToken([name]); |
| 1340 | this._attemptCharCodeUntilFn(isNotWhitespace); |
| 1341 | |
| 1342 | // Optionally there might be attributes bound to the specific directive. |
| 1343 | // Stop parsing if there's no opening character for them. |
| 1344 | if (this._cursor.peek() !== chars.$LPAREN) { |
| 1345 | return; |
| 1346 | } |
| 1347 | |
| 1348 | this._openDirectiveCount++; |
| 1349 | this._beginToken(TokenType.DIRECTIVE_OPEN); |
| 1350 | this._cursor.advance(); |
| 1351 | this._endToken([]); |
| 1352 | this._attemptCharCodeUntilFn(isNotWhitespace); |
| 1353 | |
| 1354 | // Capture all the attributes until we hit a closing paren. |
| 1355 | while (!isAttributeTerminator(this._cursor.peek()) && this._cursor.peek() !== chars.$RPAREN) { |
| 1356 | this._consumeAttribute(); |
| 1357 | } |
| 1358 | |
| 1359 | // Trim any trailing whitespace. |
| 1360 | this._attemptCharCodeUntilFn(isNotWhitespace); |
| 1361 | this._openDirectiveCount--; |
| 1362 | |
| 1363 | if (this._cursor.peek() !== chars.$RPAREN) { |
| 1364 | // Stop parsing, instead of throwing, if we've hit the end of the tag. |
| 1365 | // This can be handled better later when turning the tokens into AST. |
| 1366 | if (this._cursor.peek() === chars.$GT || this._cursor.peek() === chars.$SLASH) { |
| 1367 | return; |
| 1368 | } |
| 1369 | |
| 1370 | throw this._createError( |
| 1371 | _unexpectedCharacterErrorMsg(this._cursor.peek()), |
| 1372 | this._cursor.getSpan(start), |
| 1373 | ); |
| 1374 | } |
| 1375 | |
| 1376 | // Capture the closing token. |
| 1377 | this._beginToken(TokenType.DIRECTIVE_CLOSE); |
| 1378 | this._cursor.advance(); |
| 1379 | this._endToken([]); |
| 1380 | this._attemptCharCodeUntilFn(isNotWhitespace); |
| 1381 | } |
| 1382 |
no test coverage detected