{"ast":null,"code":"import { IdentifierRole } from \"../parser/tokenizer\";\nimport { TokenType as tt } from \"../parser/tokenizer/types\";\nimport Transformer from \"./Transformer\";\n\n/**\n * Implementation of babel-plugin-transform-react-display-name, which adds a\n * display name to usages of React.createClass and createReactClass.\n */\nexport default class ReactDisplayNameTransformer extends Transformer {\n  constructor(rootTransformer, tokens, importProcessor, options) {\n    super();\n    this.rootTransformer = rootTransformer;\n    this.tokens = tokens;\n    this.importProcessor = importProcessor;\n    this.options = options;\n    ;\n  }\n  process() {\n    const startIndex = this.tokens.currentIndex();\n    if (this.tokens.identifierName() === \"createReactClass\") {\n      const newName = this.importProcessor && this.importProcessor.getIdentifierReplacement(\"createReactClass\");\n      if (newName) {\n        this.tokens.replaceToken(`(0, ${newName})`);\n      } else {\n        this.tokens.copyToken();\n      }\n      this.tryProcessCreateClassCall(startIndex);\n      return true;\n    }\n    if (this.tokens.matches3(tt.name, tt.dot, tt.name) && this.tokens.identifierName() === \"React\" && this.tokens.identifierNameAtIndex(this.tokens.currentIndex() + 2) === \"createClass\") {\n      const newName = this.importProcessor ? this.importProcessor.getIdentifierReplacement(\"React\") || \"React\" : \"React\";\n      if (newName) {\n        this.tokens.replaceToken(newName);\n        this.tokens.copyToken();\n        this.tokens.copyToken();\n      } else {\n        this.tokens.copyToken();\n        this.tokens.copyToken();\n        this.tokens.copyToken();\n      }\n      this.tryProcessCreateClassCall(startIndex);\n      return true;\n    }\n    return false;\n  }\n\n  /**\n   * This is called with the token position at the open-paren.\n   */\n  tryProcessCreateClassCall(startIndex) {\n    const displayName = this.findDisplayName(startIndex);\n    if (!displayName) {\n      return;\n    }\n    if (this.classNeedsDisplayName()) {\n      this.tokens.copyExpectedToken(tt.parenL);\n      this.tokens.copyExpectedToken(tt.braceL);\n      this.tokens.appendCode(`displayName: '${displayName}',`);\n      this.rootTransformer.processBalancedCode();\n      this.tokens.copyExpectedToken(tt.braceR);\n      this.tokens.copyExpectedToken(tt.parenR);\n    }\n  }\n  findDisplayName(startIndex) {\n    if (startIndex < 2) {\n      return null;\n    }\n    if (this.tokens.matches2AtIndex(startIndex - 2, tt.name, tt.eq)) {\n      // This is an assignment (or declaration) and the LHS is either an identifier or a member\n      // expression ending in an identifier, so use that identifier name.\n      return this.tokens.identifierNameAtIndex(startIndex - 2);\n    }\n    if (startIndex >= 2 && this.tokens.tokens[startIndex - 2].identifierRole === IdentifierRole.ObjectKey) {\n      // This is an object literal value.\n      return this.tokens.identifierNameAtIndex(startIndex - 2);\n    }\n    if (this.tokens.matches2AtIndex(startIndex - 2, tt._export, tt._default)) {\n      return this.getDisplayNameFromFilename();\n    }\n    return null;\n  }\n  getDisplayNameFromFilename() {\n    const filePath = this.options.filePath || \"unknown\";\n    const pathSegments = filePath.split(\"/\");\n    const filename = pathSegments[pathSegments.length - 1];\n    const dotIndex = filename.lastIndexOf(\".\");\n    const baseFilename = dotIndex === -1 ? filename : filename.slice(0, dotIndex);\n    if (baseFilename === \"index\" && pathSegments[pathSegments.length - 2]) {\n      return pathSegments[pathSegments.length - 2];\n    } else {\n      return baseFilename;\n    }\n  }\n\n  /**\n   * We only want to add a display name when this is a function call containing\n   * one argument, which is an object literal without `displayName` as an\n   * existing key.\n   */\n  classNeedsDisplayName() {\n    let index = this.tokens.currentIndex();\n    if (!this.tokens.matches2(tt.parenL, tt.braceL)) {\n      return false;\n    }\n    // The block starts on the {, and we expect any displayName key to be in\n    // that context. We need to ignore other other contexts to avoid matching\n    // nested displayName keys.\n    const objectStartIndex = index + 1;\n    const objectContextId = this.tokens.tokens[objectStartIndex].contextId;\n    if (objectContextId == null) {\n      throw new Error(\"Expected non-null context ID on object open-brace.\");\n    }\n    for (; index < this.tokens.tokens.length; index++) {\n      const token = this.tokens.tokens[index];\n      if (token.type === tt.braceR && token.contextId === objectContextId) {\n        index++;\n        break;\n      }\n      if (this.tokens.identifierNameAtIndex(index) === \"displayName\" && this.tokens.tokens[index].identifierRole === IdentifierRole.ObjectKey && token.contextId === objectContextId) {\n        // We found a displayName key, so bail out.\n        return false;\n      }\n    }\n    if (index === this.tokens.tokens.length) {\n      throw new Error(\"Unexpected end of input when processing React class.\");\n    }\n\n    // If we got this far, we know we have createClass with an object with no\n    // display name, so we want to proceed as long as that was the only argument.\n    return this.tokens.matches1AtIndex(index, tt.parenR) || this.tokens.matches2AtIndex(index, tt.comma, tt.parenR);\n  }\n}","map":{"version":3,"names":["IdentifierRole","TokenType","tt","Transformer","ReactDisplayNameTransformer","constructor","rootTransformer","tokens","importProcessor","options","process","startIndex","currentIndex","identifierName","newName","getIdentifierReplacement","replaceToken","copyToken","tryProcessCreateClassCall","matches3","name","dot","identifierNameAtIndex","displayName","findDisplayName","classNeedsDisplayName","copyExpectedToken","parenL","braceL","appendCode","processBalancedCode","braceR","parenR","matches2AtIndex","eq","identifierRole","ObjectKey","_export","_default","getDisplayNameFromFilename","filePath","pathSegments","split","filename","length","dotIndex","lastIndexOf","baseFilename","slice","index","matches2","objectStartIndex","objectContextId","contextId","Error","token","type","matches1AtIndex","comma"],"sources":["C:/Users/user/Desktop/000newport/node_modules/sucrase/dist/esm/transformers/ReactDisplayNameTransformer.js"],"sourcesContent":["\n\nimport {IdentifierRole} from \"../parser/tokenizer\";\nimport {TokenType as tt} from \"../parser/tokenizer/types\";\n\n\nimport Transformer from \"./Transformer\";\n\n/**\n * Implementation of babel-plugin-transform-react-display-name, which adds a\n * display name to usages of React.createClass and createReactClass.\n */\nexport default class ReactDisplayNameTransformer extends Transformer {\n  constructor(\n     rootTransformer,\n     tokens,\n     importProcessor,\n     options,\n  ) {\n    super();this.rootTransformer = rootTransformer;this.tokens = tokens;this.importProcessor = importProcessor;this.options = options;;\n  }\n\n  process() {\n    const startIndex = this.tokens.currentIndex();\n    if (this.tokens.identifierName() === \"createReactClass\") {\n      const newName =\n        this.importProcessor && this.importProcessor.getIdentifierReplacement(\"createReactClass\");\n      if (newName) {\n        this.tokens.replaceToken(`(0, ${newName})`);\n      } else {\n        this.tokens.copyToken();\n      }\n      this.tryProcessCreateClassCall(startIndex);\n      return true;\n    }\n    if (\n      this.tokens.matches3(tt.name, tt.dot, tt.name) &&\n      this.tokens.identifierName() === \"React\" &&\n      this.tokens.identifierNameAtIndex(this.tokens.currentIndex() + 2) === \"createClass\"\n    ) {\n      const newName = this.importProcessor\n        ? this.importProcessor.getIdentifierReplacement(\"React\") || \"React\"\n        : \"React\";\n      if (newName) {\n        this.tokens.replaceToken(newName);\n        this.tokens.copyToken();\n        this.tokens.copyToken();\n      } else {\n        this.tokens.copyToken();\n        this.tokens.copyToken();\n        this.tokens.copyToken();\n      }\n      this.tryProcessCreateClassCall(startIndex);\n      return true;\n    }\n    return false;\n  }\n\n  /**\n   * This is called with the token position at the open-paren.\n   */\n   tryProcessCreateClassCall(startIndex) {\n    const displayName = this.findDisplayName(startIndex);\n    if (!displayName) {\n      return;\n    }\n\n    if (this.classNeedsDisplayName()) {\n      this.tokens.copyExpectedToken(tt.parenL);\n      this.tokens.copyExpectedToken(tt.braceL);\n      this.tokens.appendCode(`displayName: '${displayName}',`);\n      this.rootTransformer.processBalancedCode();\n      this.tokens.copyExpectedToken(tt.braceR);\n      this.tokens.copyExpectedToken(tt.parenR);\n    }\n  }\n\n   findDisplayName(startIndex) {\n    if (startIndex < 2) {\n      return null;\n    }\n    if (this.tokens.matches2AtIndex(startIndex - 2, tt.name, tt.eq)) {\n      // This is an assignment (or declaration) and the LHS is either an identifier or a member\n      // expression ending in an identifier, so use that identifier name.\n      return this.tokens.identifierNameAtIndex(startIndex - 2);\n    }\n    if (\n      startIndex >= 2 &&\n      this.tokens.tokens[startIndex - 2].identifierRole === IdentifierRole.ObjectKey\n    ) {\n      // This is an object literal value.\n      return this.tokens.identifierNameAtIndex(startIndex - 2);\n    }\n    if (this.tokens.matches2AtIndex(startIndex - 2, tt._export, tt._default)) {\n      return this.getDisplayNameFromFilename();\n    }\n    return null;\n  }\n\n   getDisplayNameFromFilename() {\n    const filePath = this.options.filePath || \"unknown\";\n    const pathSegments = filePath.split(\"/\");\n    const filename = pathSegments[pathSegments.length - 1];\n    const dotIndex = filename.lastIndexOf(\".\");\n    const baseFilename = dotIndex === -1 ? filename : filename.slice(0, dotIndex);\n    if (baseFilename === \"index\" && pathSegments[pathSegments.length - 2]) {\n      return pathSegments[pathSegments.length - 2];\n    } else {\n      return baseFilename;\n    }\n  }\n\n  /**\n   * We only want to add a display name when this is a function call containing\n   * one argument, which is an object literal without `displayName` as an\n   * existing key.\n   */\n   classNeedsDisplayName() {\n    let index = this.tokens.currentIndex();\n    if (!this.tokens.matches2(tt.parenL, tt.braceL)) {\n      return false;\n    }\n    // The block starts on the {, and we expect any displayName key to be in\n    // that context. We need to ignore other other contexts to avoid matching\n    // nested displayName keys.\n    const objectStartIndex = index + 1;\n    const objectContextId = this.tokens.tokens[objectStartIndex].contextId;\n    if (objectContextId == null) {\n      throw new Error(\"Expected non-null context ID on object open-brace.\");\n    }\n\n    for (; index < this.tokens.tokens.length; index++) {\n      const token = this.tokens.tokens[index];\n      if (token.type === tt.braceR && token.contextId === objectContextId) {\n        index++;\n        break;\n      }\n\n      if (\n        this.tokens.identifierNameAtIndex(index) === \"displayName\" &&\n        this.tokens.tokens[index].identifierRole === IdentifierRole.ObjectKey &&\n        token.contextId === objectContextId\n      ) {\n        // We found a displayName key, so bail out.\n        return false;\n      }\n    }\n\n    if (index === this.tokens.tokens.length) {\n      throw new Error(\"Unexpected end of input when processing React class.\");\n    }\n\n    // If we got this far, we know we have createClass with an object with no\n    // display name, so we want to proceed as long as that was the only argument.\n    return (\n      this.tokens.matches1AtIndex(index, tt.parenR) ||\n      this.tokens.matches2AtIndex(index, tt.comma, tt.parenR)\n    );\n  }\n}\n"],"mappings":"AAEA,SAAQA,cAAc,QAAO,qBAAqB;AAClD,SAAQC,SAAS,IAAIC,EAAE,QAAO,2BAA2B;AAGzD,OAAOC,WAAW,MAAM,eAAe;;AAEvC;AACA;AACA;AACA;AACA,eAAe,MAAMC,2BAA2B,SAASD,WAAW,CAAC;EACnEE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