MCPcopy Index your code
hub / github.com/angular/angular / _consumeDirective

Method _consumeDirective

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

Source from the content-addressed store, hash-verified

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

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