{"version":3,"file":"transformFlow.js","names":[],"sources":["esm/transformFlow.js"],"sourcesContent":["import remapping from \"@jridgewell/remapping\";\nimport { generate } from \"astring\";\nimport { parse, SimpleTraverser, Transforms } from \"hermes-parser\";\nimport MagicString from \"magic-string\";\nasync function stripFlowTypes(id, code, sourceMaps = true) {\n  const edited = new MagicString(code);\n  if (/\\benum\\b/.test(code)) {\n    const program = parse(code, { flow: \"all\", sourceType: \"module\" });\n    SimpleTraverser.traverse(program, {\n      enter(node, parent) {\n        if (node.type !== \"EnumDeclaration\") return;\n        const declaration = parent?.type === \"ExportDefaultDeclaration\" ? parent : node;\n        const [start, end] = declaration.range;\n        const lowered = Transforms.transformEnumSyntax(\n          { ...program, body: [declaration] },\n          {}\n        );\n        edited.overwrite(start, end, generate(lowered).trimEnd());\n      },\n      leave() {\n      }\n    });\n  }\n  const { transform } = await import(\"@swc/core\");\n  const result = await transform(edited.toString(), {\n    filename: id,\n    swcrc: false,\n    configFile: false,\n    inputSourceMap: false,\n    sourceMaps,\n    jsc: {\n      target: \"esnext\",\n      parser: {\n        syntax: \"flow\",\n        all: true,\n        jsx: true,\n        enums: true,\n        components: true,\n        patternMatching: true\n      },\n      // match Flow's declaration erasure before the native class-field pass.\n      transform: {\n        react: { runtime: \"preserve\" },\n        useDefineForClassFields: false\n      }\n    }\n  });\n  const map = result.map ? JSON.parse(result.map) : void 0;\n  return {\n    code: result.code,\n    map: map && edited.hasChanged() ? remapping(\n      [\n        map,\n        edited.generateMap({\n          source: id,\n          includeContent: true,\n          hires: true\n        })\n      ],\n      () => null\n    ) : map\n  };\n}\nexport {\n  stripFlowTypes\n};\n//# sourceMappingURL=transformFlow.js.map\n"],"mappings":";;;;;;AAIA,eAAe,eAAe,IAAI,MAAM,aAAa,MAAM;CACzD,MAAM,SAAS,IAAI,YAAY,IAAI;CACnC,IAAI,WAAW,KAAK,IAAI,GAAG;EACzB,MAAM,UAAU,MAAM,MAAM;GAAE,MAAM;GAAO,YAAY;EAAS,CAAC;EACjE,gBAAgB,SAAS,SAAS;GAChC,MAAM,MAAM,QAAQ;IAClB,IAAI,KAAK,SAAS,mBAAmB;IACrC,MAAM,cAAc,QAAQ,SAAS,6BAA6B,SAAS;IAC3E,MAAM,CAAC,OAAO,OAAO,YAAY;IACjC,MAAM,UAAU,WAAW,oBACzB;KAAE,GAAG;KAAS,MAAM,CAAC,WAAW;IAAE,GAClC,CAAC,CACH;IACA,OAAO,UAAU,OAAO,KAAK,SAAS,OAAO,CAAC,CAAC,QAAQ,CAAC;GAC1D;GACA,QAAQ,CACR;EACF,CAAC;CACH;CACA,MAAM,EAAE,cAAc,MAAM,OAAO;CACnC,MAAM,SAAS,MAAM,UAAU,OAAO,SAAS,GAAG;EAChD,UAAU;EACV,OAAO;EACP,YAAY;EACZ,gBAAgB;EAChB;EACA,KAAK;GACH,QAAQ;GACR,QAAQ;IACN,QAAQ;IACR,KAAK;IACL,KAAK;IACL,OAAO;IACP,YAAY;IACZ,iBAAiB;GACnB;GAEA,WAAW;IACT,OAAO,EAAE,SAAS,WAAW;IAC7B,yBAAyB;GAC3B;EACF;CACF,CAAC;CACD,MAAM,MAAM,OAAO,MAAM,KAAK,MAAM,OAAO,GAAG,IAAI,KAAK;CACvD,OAAO;EACL,MAAM,OAAO;EACb,KAAK,OAAO,OAAO,WAAW,IAAI,UAChC,CACE,KACA,OAAO,YAAY;GACjB,QAAQ;GACR,gBAAgB;GAChB,OAAO;EACT,CAAC,CACH,SACM,IACR,IAAI;CACN;AACF"}