MCPcopy Create free account
hub / github.com/babel/babel / TypeScriptParserMixin

Class TypeScriptParserMixin

packages/babel-parser/src/plugins/typescript/index.ts:448–5239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446
447export default (superClass: ClassWithMixin<typeof Parser, IJSXParserMixin>) =>
448 class TypeScriptParserMixin extends superClass implements Parser {
449 declare scope: TypeScriptScopeHandler;
450 getScopeHandler(): new (...args: any) => TypeScriptScopeHandler {
451 return TypeScriptScopeHandler;
452 }
453
454 tsIsIdentifier(): boolean {
455 // TODO: actually a bit more complex in TypeScript, but shouldn't matter.
456 // See https://github.com/Microsoft/TypeScript/issues/15008
457 return tokenIsIdentifier(this.state.type);
458 }
459
460 tsTokenCanFollowModifier() {
461 return (
462 this.match(tt.bracketL) ||
463 this.match(tt.braceL) ||
464 this.match(tt.star) ||
465 this.match(tt.ellipsis) ||
466 this.match(tt.privateName) ||
467 this.isLiteralPropertyName()
468 );
469 }
470
471 tsNextTokenOnSameLineAndCanFollowModifier() {
472 this.next();
473 if (this.hasPrecedingLineBreak()) {
474 return false;
475 }
476 return this.tsTokenCanFollowModifier();
477 }
478
479 tsNextTokenCanFollowModifier() {
480 // Note: TypeScript's implementation is much more complicated because
481 // more things are considered modifiers there.
482 // This implementation only handles modifiers not handled by @babel/parser itself. And "static".
483 if (this.match(tt._static)) {
484 this.next();
485 return this.tsTokenCanFollowModifier();
486 }
487 return this.tsNextTokenOnSameLineAndCanFollowModifier();
488 }
489
490 /** Parses a modifier matching one the given modifier names. */
491 tsParseModifier<T extends TsModifier>(
492 modifiers: Map<T, boolean>,
493 stopOnStartOfClassStaticBlock?: boolean,
494 hasSeenStaticModifier?: boolean | null,
495 ): T | undefined | null {
496 if (
497 !tokenIsIdentifier(this.state.type) &&
498 this.state.type !== tt._in &&
499 this.state.type !== tt._const
500 ) {
501 return undefined;
502 }
503
504 const modifier = this.state.value;
505 if (modifiers.has(modifier)) {

Callers

nothing calls this directly

Calls 1

buildModifiersMapFunction · 0.85

Tested by

no test coverage detected