{"version":3,"names":["_assert","require","_core","_helperSimpleAccess","assignmentExpression","callExpression","cloneNode","expressionStatement","getOuterBindingIdentifiers","identifier","isMemberExpression","isVariableDeclaration","jsxIdentifier","jsxMemberExpression","memberExpression","numericLiteral","sequenceExpression","stringLiteral","variableDeclaration","variableDeclarator","t","isInType","path","parent","type","parentPath","exportKind","isStatement","isExpression","rewriteLiveReferences","programPath","metadata","imported","Map","exported","requeueInParent","requeue","source","data","localName","importName","imports","set","importsNamespace","local","exportMeta","get","push","names","rewriteBindingInitVisitorState","scope","traverse","rewriteBindingInitVisitor","bindingNames","Set","Array","from","keys","simplifyAccess","rewriteReferencesVisitorState","seen","WeakSet","buildImportReference","identNode","meta","referenced","lazy","namespace","name","interop","computed","stringSpecifiers","has","rewriteReferencesVisitor","Scope","skip","ClassDeclaration","id","node","Error","exportNames","length","statement","buildBindingExportAssignmentExpression","_blockHoist","insertAfter","VariableDeclaration","Object","forEach","localExpr","exportsObjectName","exportName","currentScope","hasOwnBinding","rename","reduce","expr","buildImportThrow","template","expression","ast","ReferencedIdentifier","add","importData","buildCodeFrameError","localBinding","getBinding","rootBinding","ref","loc","isCallExpression","callee","isOptionalCallExpression","isTaggedTemplateExpression","tag","replaceWith","isJSXIdentifier","object","property","UpdateExpression","arg","update","isIdentifier","exportedNames","operator","prefix","generateDeclaredUidIdentifier","AssignmentExpression","exit","left","assert","assignment","right","ids","programScopeIds","filter","find","items","isExpressionStatement","ForOfStatement|ForInStatement","programScope","didTransformExport","importConstViolationName","loopBodyScope","ensureBlock","bodyPath","newLoopId","generateUidIdentifierBasedOnNode","registerDeclaration","unshiftContainer"],"sources":["../src/rewrite-live-references.ts"],"sourcesContent":["import assert from \"assert\";\nimport { template, types as t } from \"@babel/core\";\nimport type { NodePath, Visitor, Scope } from \"@babel/traverse\";\nimport simplifyAccess from \"@babel/helper-simple-access\";\n\nimport type { ModuleMetadata } from \"./normalize-and-load-metadata\";\n\nconst {\n assignmentExpression,\n callExpression,\n cloneNode,\n expressionStatement,\n getOuterBindingIdentifiers,\n identifier,\n isMemberExpression,\n isVariableDeclaration,\n jsxIdentifier,\n jsxMemberExpression,\n memberExpression,\n numericLiteral,\n sequenceExpression,\n stringLiteral,\n variableDeclaration,\n variableDeclarator,\n} = t;\n\ninterface RewriteReferencesVisitorState {\n exported: Map;\n metadata: ModuleMetadata;\n requeueInParent: (path: NodePath) => void;\n scope: Scope;\n imported: Map;\n buildImportReference: (\n [source, importName, localName]: readonly [string, string, string],\n identNode: t.Identifier | t.CallExpression | t.JSXIdentifier,\n ) => any;\n seen: WeakSet;\n}\n\ninterface RewriteBindingInitVisitorState {\n exported: Map;\n metadata: ModuleMetadata;\n requeueInParent: (path: NodePath) => void;\n scope: Scope;\n}\n\nfunction isInType(path: NodePath) {\n do {\n switch (path.parent.type) {\n case \"TSTypeAnnotation\":\n case \"TSTypeAliasDeclaration\":\n case \"TSTypeReference\":\n case \"TypeAnnotation\":\n case \"TypeAlias\":\n return true;\n case \"ExportSpecifier\":\n return (\n (\n path.parentPath.parent as\n | t.ExportDefaultDeclaration\n | t.ExportNamedDeclaration\n ).exportKind === \"type\"\n );\n default:\n if (path.parentPath.isStatement() || path.parentPath.isExpression()) {\n return false;\n }\n }\n } while ((path = path.parentPath));\n}\n\nexport default function rewriteLiveReferences(\n programPath: NodePath,\n metadata: ModuleMetadata,\n) {\n const imported = new Map();\n const exported = new Map();\n const requeueInParent = (path: NodePath) => {\n // Manually re-queue `exports.default =` expressions so that the ES3\n // transform has an opportunity to convert them. Ideally this would\n // happen automatically from the replaceWith above. See #4140 for\n // more info.\n programPath.requeue(path);\n };\n\n for (const [source, data] of metadata.source) {\n for (const [localName, importName] of data.imports) {\n imported.set(localName, [source, importName, null]);\n }\n for (const localName of data.importsNamespace) {\n imported.set(localName, [source, null, localName]);\n }\n }\n\n for (const [local, data] of metadata.local) {\n let exportMeta = exported.get(local);\n if (!exportMeta) {\n exportMeta = [];\n exported.set(local, exportMeta);\n }\n\n exportMeta.push(...data.names);\n }\n\n // Rewrite initialization of bindings to update exports.\n const rewriteBindingInitVisitorState: RewriteBindingInitVisitorState = {\n metadata,\n requeueInParent,\n scope: programPath.scope,\n exported, // local name => exported name list\n };\n programPath.traverse(\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n rewriteBindingInitVisitor,\n rewriteBindingInitVisitorState,\n );\n\n // NOTE(logan): The 'Array.from' calls are to make this code with in loose mode.\n const bindingNames = new Set([\n ...Array.from(imported.keys()),\n ...Array.from(exported.keys()),\n ]);\n if (process.env.BABEL_8_BREAKING) {\n simplifyAccess(programPath, bindingNames);\n } else {\n // @ts-ignore(Babel 7 vs Babel 8) The third param has been removed in Babel 8.\n simplifyAccess(programPath, bindingNames, false);\n }\n\n // Rewrite reads/writes from imports and exports to have the correct behavior.\n const rewriteReferencesVisitorState: RewriteReferencesVisitorState = {\n seen: new WeakSet(),\n metadata,\n requeueInParent,\n scope: programPath.scope,\n imported, // local / import\n exported, // local name => exported name list\n buildImportReference: ([source, importName, localName], identNode) => {\n const meta = metadata.source.get(source);\n meta.referenced = true;\n\n if (localName) {\n if (meta.lazy) {\n identNode = callExpression(\n // @ts-expect-error Fixme: we should handle the case when identNode is a JSXIdentifier\n identNode,\n [],\n );\n }\n return identNode;\n }\n\n let namespace: t.Expression = identifier(meta.name);\n if (meta.lazy) namespace = callExpression(namespace, []);\n\n if (importName === \"default\" && meta.interop === \"node-default\") {\n return namespace;\n }\n\n const computed = metadata.stringSpecifiers.has(importName);\n\n return memberExpression(\n namespace,\n computed ? stringLiteral(importName) : identifier(importName),\n computed,\n );\n },\n };\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n programPath.traverse(rewriteReferencesVisitor, rewriteReferencesVisitorState);\n}\n\n/**\n * A visitor to inject export update statements during binding initialization.\n */\nconst rewriteBindingInitVisitor: Visitor = {\n Scope(path) {\n path.skip();\n },\n ClassDeclaration(path) {\n const { requeueInParent, exported, metadata } = this;\n\n const { id } = path.node;\n if (!id) throw new Error(\"Expected class to have a name\");\n const localName = id.name;\n\n const exportNames = exported.get(localName) || [];\n if (exportNames.length > 0) {\n const statement = expressionStatement(\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n buildBindingExportAssignmentExpression(\n metadata,\n exportNames,\n identifier(localName),\n path.scope,\n ),\n );\n // @ts-expect-error todo(flow->ts): avoid mutations\n statement._blockHoist = path.node._blockHoist;\n\n requeueInParent(path.insertAfter(statement)[0]);\n }\n },\n VariableDeclaration(path) {\n const { requeueInParent, exported, metadata } = this;\n\n Object.keys(path.getOuterBindingIdentifiers()).forEach(localName => {\n const exportNames = exported.get(localName) || [];\n\n if (exportNames.length > 0) {\n const statement = expressionStatement(\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n buildBindingExportAssignmentExpression(\n metadata,\n exportNames,\n identifier(localName),\n path.scope,\n ),\n );\n // @ts-expect-error todo(flow->ts): avoid mutations\n statement._blockHoist = path.node._blockHoist;\n\n requeueInParent(path.insertAfter(statement)[0]);\n }\n });\n },\n};\n\nconst buildBindingExportAssignmentExpression = (\n metadata: ModuleMetadata,\n exportNames: string[],\n localExpr: t.Expression,\n scope: Scope,\n) => {\n const exportsObjectName = metadata.exportName;\n for (\n let currentScope = scope;\n currentScope != null;\n currentScope = currentScope.parent\n ) {\n if (currentScope.hasOwnBinding(exportsObjectName)) {\n currentScope.rename(exportsObjectName);\n }\n }\n return (exportNames || []).reduce((expr, exportName) => {\n // class Foo {} export { Foo, Foo as Bar };\n // as\n // class Foo {} exports.Foo = exports.Bar = Foo;\n const { stringSpecifiers } = metadata;\n const computed = stringSpecifiers.has(exportName);\n return assignmentExpression(\n \"=\",\n memberExpression(\n identifier(exportsObjectName),\n computed ? stringLiteral(exportName) : identifier(exportName),\n /* computed */ computed,\n ),\n expr,\n );\n }, localExpr);\n};\n\nconst buildImportThrow = (localName: string) => {\n return template.expression.ast`\n (function() {\n throw new Error('\"' + '${localName}' + '\" is read-only.');\n })()\n `;\n};\n\nconst rewriteReferencesVisitor: Visitor = {\n ReferencedIdentifier(path) {\n const { seen, buildImportReference, scope, imported, requeueInParent } =\n this;\n if (seen.has(path.node)) return;\n seen.add(path.node);\n\n const localName = path.node.name;\n\n const importData = imported.get(localName);\n if (importData) {\n if (isInType(path)) {\n throw path.buildCodeFrameError(\n `Cannot transform the imported binding \"${localName}\" since it's also used in a type annotation. ` +\n `Please strip type annotations using @babel/preset-typescript or @babel/preset-flow.`,\n );\n }\n\n const localBinding = path.scope.getBinding(localName);\n const rootBinding = scope.getBinding(localName);\n\n // redeclared in this scope\n if (rootBinding !== localBinding) return;\n\n const ref = buildImportReference(importData, path.node);\n\n // Preserve the binding location so that sourcemaps are nicer.\n ref.loc = path.node.loc;\n\n if (\n (path.parentPath.isCallExpression({ callee: path.node }) ||\n path.parentPath.isOptionalCallExpression({ callee: path.node }) ||\n path.parentPath.isTaggedTemplateExpression({ tag: path.node })) &&\n isMemberExpression(ref)\n ) {\n path.replaceWith(sequenceExpression([numericLiteral(0), ref]));\n } else if (path.isJSXIdentifier() && isMemberExpression(ref)) {\n const { object, property } = ref;\n path.replaceWith(\n jsxMemberExpression(\n // @ts-expect-error todo(flow->ts): possible bug `object` might not have a name\n jsxIdentifier(object.name),\n // @ts-expect-error todo(flow->ts): possible bug `property` might not have a name\n jsxIdentifier(property.name),\n ),\n );\n } else {\n path.replaceWith(ref);\n }\n\n requeueInParent(path);\n\n // The path could have been replaced with an identifier that would\n // otherwise be re-visited, so we skip processing its children.\n path.skip();\n }\n },\n\n UpdateExpression(path) {\n const {\n scope,\n seen,\n imported,\n exported,\n requeueInParent,\n buildImportReference,\n } = this;\n\n if (seen.has(path.node)) return;\n\n seen.add(path.node);\n\n const arg = path.get(\"argument\");\n\n // No change needed\n if (arg.isMemberExpression()) return;\n\n const update = path.node;\n\n if (arg.isIdentifier()) {\n const localName = arg.node.name;\n\n // redeclared in this scope\n if (scope.getBinding(localName) !== path.scope.getBinding(localName)) {\n return;\n }\n\n const exportedNames = exported.get(localName);\n const importData = imported.get(localName);\n\n if (exportedNames?.length > 0 || importData) {\n if (importData) {\n path.replaceWith(\n assignmentExpression(\n update.operator[0] + \"=\",\n buildImportReference(importData, arg.node),\n buildImportThrow(localName),\n ),\n );\n } else if (update.prefix) {\n // ++foo\n // => exports.foo = ++foo\n path.replaceWith(\n buildBindingExportAssignmentExpression(\n this.metadata,\n exportedNames,\n cloneNode(update),\n path.scope,\n ),\n );\n } else {\n // foo++\n // => (ref = i++, exports.i = i, ref)\n const ref = scope.generateDeclaredUidIdentifier(localName);\n\n path.replaceWith(\n sequenceExpression([\n assignmentExpression(\"=\", cloneNode(ref), cloneNode(update)),\n buildBindingExportAssignmentExpression(\n this.metadata,\n exportedNames,\n identifier(localName),\n path.scope,\n ),\n cloneNode(ref),\n ]),\n );\n }\n }\n }\n\n requeueInParent(path);\n path.skip();\n },\n\n AssignmentExpression: {\n exit(path) {\n const {\n scope,\n seen,\n imported,\n exported,\n requeueInParent,\n buildImportReference,\n } = this;\n\n if (seen.has(path.node)) return;\n seen.add(path.node);\n\n const left = path.get(\"left\");\n\n // No change needed\n if (left.isMemberExpression()) return;\n\n if (left.isIdentifier()) {\n // Simple update-assign foo += 1; export { foo };\n // => exports.foo = (foo += 1);\n const localName = left.node.name;\n\n // redeclared in this scope\n if (scope.getBinding(localName) !== path.scope.getBinding(localName)) {\n return;\n }\n\n const exportedNames = exported.get(localName);\n const importData = imported.get(localName);\n if (exportedNames?.length > 0 || importData) {\n assert(path.node.operator === \"=\", \"Path was not simplified\");\n\n const assignment = path.node;\n\n if (importData) {\n assignment.left = buildImportReference(importData, left.node);\n\n assignment.right = sequenceExpression([\n assignment.right,\n buildImportThrow(localName),\n ]);\n }\n\n path.replaceWith(\n buildBindingExportAssignmentExpression(\n this.metadata,\n exportedNames,\n assignment,\n path.scope,\n ),\n );\n requeueInParent(path);\n }\n } else {\n const ids = left.getOuterBindingIdentifiers();\n const programScopeIds = Object.keys(ids).filter(\n localName =>\n scope.getBinding(localName) === path.scope.getBinding(localName),\n );\n const id = programScopeIds.find(localName => imported.has(localName));\n\n if (id) {\n path.node.right = sequenceExpression([\n path.node.right,\n buildImportThrow(id),\n ]);\n }\n\n // Complex ({a, b, c} = {}); export { a, c };\n // => ({a, b, c} = {}), (exports.a = a, exports.c = c);\n const items: t.Expression[] = [];\n programScopeIds.forEach(localName => {\n const exportedNames = exported.get(localName) || [];\n if (exportedNames.length > 0) {\n items.push(\n buildBindingExportAssignmentExpression(\n this.metadata,\n exportedNames,\n identifier(localName),\n path.scope,\n ),\n );\n }\n });\n\n if (items.length > 0) {\n let node: t.Node = sequenceExpression(items);\n if (path.parentPath.isExpressionStatement()) {\n node = expressionStatement(node);\n // @ts-expect-error todo(flow->ts): avoid mutations\n node._blockHoist = path.parentPath.node._blockHoist;\n }\n\n const statement = path.insertAfter(node)[0];\n requeueInParent(statement);\n }\n }\n },\n },\n \"ForOfStatement|ForInStatement\"(\n path: NodePath,\n ) {\n const { scope, node } = path;\n const { left } = node;\n const { exported, imported, scope: programScope } = this;\n\n if (!isVariableDeclaration(left)) {\n let didTransformExport = false,\n importConstViolationName;\n const loopBodyScope = path.get(\"body\").scope;\n for (const name of Object.keys(getOuterBindingIdentifiers(left))) {\n if (programScope.getBinding(name) === scope.getBinding(name)) {\n if (exported.has(name)) {\n didTransformExport = true;\n if (loopBodyScope.hasOwnBinding(name)) {\n loopBodyScope.rename(name);\n }\n }\n if (imported.has(name) && !importConstViolationName) {\n importConstViolationName = name;\n }\n }\n }\n if (!didTransformExport && !importConstViolationName) {\n return;\n }\n\n path.ensureBlock();\n const bodyPath = path.get(\"body\");\n\n const newLoopId = scope.generateUidIdentifierBasedOnNode(left);\n path\n .get(\"left\")\n .replaceWith(\n variableDeclaration(\"let\", [\n variableDeclarator(cloneNode(newLoopId)),\n ]),\n );\n scope.registerDeclaration(path.get(\"left\"));\n\n if (didTransformExport) {\n bodyPath.unshiftContainer(\n \"body\",\n expressionStatement(assignmentExpression(\"=\", left, newLoopId)),\n );\n }\n if (importConstViolationName) {\n bodyPath.unshiftContainer(\n \"body\",\n expressionStatement(buildImportThrow(importConstViolationName)),\n );\n }\n }\n },\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,mBAAA,GAAAF,OAAA;AAIA,MAAM;EACJG,oBAAoB;EACpBC,cAAc;EACdC,SAAS;EACTC,mBAAmB;EACnBC,0BAA0B;EAC1BC,UAAU;EACVC,kBAAkB;EAClBC,qBAAqB;EACrBC,aAAa;EACbC,mBAAmB;EACnBC,gBAAgB;EAChBC,cAAc;EACdC,kBAAkB;EAClBC,aAAa;EACbC,mBAAmB;EACnBC;AACF,CAAC,GAAGC,WAAC;AAsBL,SAASC,QAAQA,CAACC,IAAc,EAAE;EAChC,GAAG;IACD,QAAQA,IAAI,CAACC,MAAM,CAACC,IAAI;MACtB,KAAK,kBAAkB;MACvB,KAAK,wBAAwB;MAC7B,KAAK,iBAAiB;MACtB,KAAK,gBAAgB;MACrB,KAAK,WAAW;QACd,OAAO,IAAI;MACb,KAAK,iBAAiB;QACpB,OAEIF,IAAI,CAACG,UAAU,CAACF,MAAM,CAGtBG,UAAU,KAAK,MAAM;MAE3B;QACE,IAAIJ,IAAI,CAACG,UAAU,CAACE,WAAW,CAAC,CAAC,IAAIL,IAAI,CAACG,UAAU,CAACG,YAAY,CAAC,CAAC,EAAE;UACnE,OAAO,KAAK;QACd;IACJ;EACF,CAAC,QAASN,IAAI,GAAGA,IAAI,CAACG,UAAU;AAClC;AAEe,SAASI,qBAAqBA,CAC3CC,WAAgC,EAChCC,QAAwB,EACxB;EACA,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC1B,MAAMC,QAAQ,GAAG,IAAID,GAAG,CAAC,CAAC;EAC1B,MAAME,eAAe,GAAIb,IAAc,IAAK;IAK1CQ,WAAW,CAACM,OAAO,CAACd,IAAI,CAAC;EAC3B,CAAC;EAED,KAAK,MAAM,CAACe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