MCPcopy Create free account
hub / github.com/MirrowApp/mirrow / parseJsEventDirectives

Method parseJsEventDirectives

packages/core/src/compiler/parser.ts:656–714  ·  view source on GitHub ↗
(
    parentKeyword: Keyword,
    directiveId: string
  )

Source from the content-addressed store, hash-verified

654 }
655
656 private parseJsEventDirectives(
657 parentKeyword: Keyword,
658 directiveId: string
659 ): JsEventDirective[] {
660 const { directives, blockToken } =
661 this.parseDirectiveGroup<JsEventDirective>({
662 parseDirective: () => {
663 const onToken = this.consume(
664 TokenType.IDENTIFIER,
665 `Unexpected identifier in <${parentKeyword.name}>`
666 );
667 if (onToken.value !== "on") {
668 throw new ParserError(
669 `Unexpected identifier '${onToken.value}' inside <${parentKeyword.name}>`,
670 onToken.position
671 );
672 }
673
674 this.consume(
675 TokenType.COLON,
676 `Expected ':' after 'on' in <${parentKeyword.name}>`
677 );
678
679 const eventToken = this.consume(
680 TokenType.IDENTIFIER,
681 `Expected event name after 'on:' in <${parentKeyword.name}>`
682 );
683
684 if (!isJsEvent(eventToken.value)) {
685 throw new ParserError(
686 `Unknown JavaScript event '${eventToken.value}'`,
687 eventToken.position
688 );
689 }
690
691 return {
692 type: "JsEvent",
693 name: eventToken.value,
694 dataId: directiveId,
695 block: "",
696 position: onToken.position,
697 } satisfies JsEventDirective;
698 },
699 hasNext: () =>
700 this.check(TokenType.COMMA) &&
701 this.peek(1).type === TokenType.IDENTIFIER &&
702 this.peek(1).value === "on" &&
703 this.peek(2).type === TokenType.COLON,
704 separatorMessage: "Expected ',' between JavaScript events",
705 blockMessageFor: (directive) =>
706 `Expected block for event '${directive.name}' in <${parentKeyword.name}>`,
707 });
708
709 const blockValue = blockToken.value;
710 return directives.map((directive) => ({
711 ...directive,
712 block: blockValue,
713 }));

Callers 1

collectBlockEntriesMethod · 0.95

Calls 5

parseDirectiveGroupMethod · 0.95
consumeMethod · 0.95
checkMethod · 0.95
peekMethod · 0.95
isJsEventFunction · 0.85

Tested by

no test coverage detected