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

Function pluginBabelParserTokenType

babel.config.ts:550–575  ·  view source on GitHub ↗
({
  types: { isIdentifier, numericLiteral },
}: PluginAPI)

Source from the content-addressed store, hash-verified

548}
549
550function pluginBabelParserTokenType({
551 types: { isIdentifier, numericLiteral },
552}: PluginAPI) {
553 const tokenTypesMapping = getTokenTypesMapping();
554 return {
555 visitor: {
556 MemberExpression(path) {
557 const { node } = path;
558 if (
559 isIdentifier(node.object, { name: "tt" }) &&
560 isIdentifier(node.property) &&
561 !node.computed
562 ) {
563 const tokenName = node.property.name;
564 const tokenType = tokenTypesMapping.get(node.property.name);
565 if (tokenType === undefined) {
566 throw path.buildCodeFrameError(
567 `${tokenName} is not defined in ${tokenTypeSourcePath}`
568 );
569 }
570 path.replaceWith(numericLiteral(tokenType));
571 }
572 },
573 },
574 } as PluginObject;
575}
576
577function pluginGeneratorOptimization({ types: t }: PluginAPI) {
578 const generatorNames: string[] = [];

Callers

nothing calls this directly

Calls 1

getTokenTypesMappingFunction · 0.85

Tested by

no test coverage detected