MCPcopy Create free account
hub / github.com/angular/angular / _consumeDirective

Method _consumeDirective

packages/compiler/src/ml_parser/lexer.ts:1340–1396  ·  view source on GitHub ↗
(start: CharacterCursor, nameStart: CharacterCursor)

Source from the content-addressed store, hash-verified

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

Callers 1

_consumeTagOpenMethod · 0.95

Calls 13

_requireCharCodeMethod · 0.95
_beginTokenMethod · 0.95
_endTokenMethod · 0.95
_consumeAttributeMethod · 0.95
_createErrorMethod · 0.95
isSelectorlessNameCharFunction · 0.85
isAttributeTerminatorFunction · 0.85
advanceMethod · 0.65
peekMethod · 0.65
getCharsMethod · 0.65

Tested by

no test coverage detected