MCPcopy
hub / github.com/formatjs/formatjs / parseArgument

Method parseArgument

packages/icu-messageformat-parser/parser.ts:530–614  ·  view source on GitHub ↗
(
    nestingLevel: number,
    expectingCloseTag: boolean
  )

Source from the content-addressed store, hash-verified

528 }
529
530 private parseArgument(
531 nestingLevel: number,
532 expectingCloseTag: boolean
533 ): Result<MessageFormatElement, ParserError> {
534 const openingBracePosition = this.clonePosition()
535 this.bump() // `{`
536
537 this.bumpSpace()
538
539 if (this.isEOF()) {
540 return this.error(
541 ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE,
542 createLocation(openingBracePosition, this.clonePosition())
543 )
544 }
545
546 if (this.char() === 125 /* `}` */) {
547 this.bump()
548 return this.error(
549 ErrorKind.EMPTY_ARGUMENT,
550 createLocation(openingBracePosition, this.clonePosition())
551 )
552 }
553
554 // argument name
555 let value = this.parseIdentifierIfPossible().value
556 if (!value) {
557 return this.error(
558 ErrorKind.MALFORMED_ARGUMENT,
559 createLocation(openingBracePosition, this.clonePosition())
560 )
561 }
562
563 this.bumpSpace()
564
565 if (this.isEOF()) {
566 return this.error(
567 ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE,
568 createLocation(openingBracePosition, this.clonePosition())
569 )
570 }
571
572 switch (this.char()) {
573 // Simple argument: `{name}`
574 case 125 /* `}` */: {
575 this.bump() // `}`
576 return {
577 val: {
578 type: TYPE.argument,
579 // value does not include the opening and closing braces.
580 value,
581 location: createLocation(
582 openingBracePosition,
583 this.clonePosition()
584 ),
585 },
586 err: null,
587 }

Callers 1

parseMessageMethod · 0.95

Calls 9

clonePositionMethod · 0.95
bumpMethod · 0.95
bumpSpaceMethod · 0.95
isEOFMethod · 0.95
errorMethod · 0.95
charMethod · 0.95
parseArgumentOptionsMethod · 0.95
createLocationFunction · 0.85

Tested by

no test coverage detected