securityos/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata...

1 line
33 KiB
Plaintext

{"version":3,"names":["hasExports","metadata","isSideEffectImport","source","imports","size","importsNamespace","reexports","reexportNamespace","reexportAll","validateImportInteropOption","importInterop","Error","resolveImportInterop","filename","normalizeModuleAndLoadMetadata","programPath","exportName","initializeReexports","lazy","esNamespaceOnly","scope","generateUidIdentifier","name","stringSpecifiers","Set","nameAnonymousExports","local","sources","getModuleMetadata","removeImportExportDeclarations","values","next","value","resolvedInterop","interop","exportNameListName","getExportSpecifierName","path","isIdentifier","node","isStringLiteral","stringValue","isIdentifierName","add","type","assertExportSpecifier","isExportSpecifier","isExportNamespaceSpecifier","buildCodeFrameError","localData","getLocalExportMetadata","sourceData","Map","getData","sourceNode","data","get","basename","extname","loc","referenced","set","forEach","child","isImportDeclaration","spec","isImportDefaultSpecifier","localName","reexport","delete","names","isImportNamespaceSpecifier","isImportSpecifier","importName","isExportAllDeclaration","isExportNamedDeclaration","isExportDefaultDeclaration","needsDefault","needsNamed","test","Array","isArray","indexOf","bindingKindLookup","kind","declaration","isFunctionDeclaration","isClassDeclaration","isVariableDeclaration","Object","keys","getOuterBindingIdentifiers","localMetadata","getLocalMetadata","idPath","undefined","ids","getOuterBindingIdentifierPaths","push","exported","splitExportDeclaration","remove","_blockHoist","replaceWith"],"sources":["../src/normalize-and-load-metadata.ts"],"sourcesContent":["import { basename, extname } from \"path\";\nimport type * as t from \"@babel/types\";\n\nimport { isIdentifierName } from \"@babel/helper-validator-identifier\";\nimport splitExportDeclaration from \"@babel/helper-split-export-declaration\";\nimport type { NodePath } from \"@babel/traverse\";\n\nexport interface ModuleMetadata {\n exportName: string;\n // The name of the variable that will reference an object containing export names.\n exportNameListName: null | string;\n hasExports: boolean;\n // Lookup from local binding to export information.\n local: Map<string, LocalExportMetadata>;\n // Lookup of source file to source file metadata.\n source: Map<string, SourceModuleMetadata>;\n // List of names that should only be printed as string literals.\n // i.e. `import { \"any unicode\" as foo } from \"some-module\"`\n // `stringSpecifiers` is Set(1) [\"any unicode\"]\n // In most cases `stringSpecifiers` is an empty Set\n stringSpecifiers: Set<string>;\n}\n\nexport type InteropType =\n | \"default\" // Babel interop for default-only imports\n | \"namespace\" // Babel interop for namespace or default+named imports\n | \"node-default\" // Node.js interop for default-only imports\n | \"node-namespace\" // Node.js interop for namespace or default+named imports\n | \"none\"; // No interop, or named-only imports\n\nexport type ImportInterop =\n | \"none\"\n | \"babel\"\n | \"node\"\n | ((source: string, filename?: string) => \"none\" | \"babel\" | \"node\");\n\nexport type Lazy = boolean | string[] | ((source: string) => boolean);\n\nexport interface SourceModuleMetadata {\n // A unique variable name to use for this namespace object. Centralized for simplicity.\n name: string;\n loc: t.SourceLocation | undefined | null;\n interop: InteropType;\n // Local binding to reference from this source namespace. Key: Local name, value: Import name\n imports: Map<string, string>;\n // Local names that reference namespace object.\n importsNamespace: Set<string>;\n // Reexports to create for namespace. Key: Export name, value: Import name\n reexports: Map<string, string>;\n // List of names to re-export namespace as.\n reexportNamespace: Set<string>;\n // Tracks if the source should be re-exported.\n reexportAll: null | {\n loc: t.SourceLocation | undefined | null;\n };\n lazy?: Lazy;\n referenced: boolean;\n}\n\nexport interface LocalExportMetadata {\n names: Array<string>; // names of exports,\n kind: \"import\" | \"hoisted\" | \"block\" | \"var\";\n}\n\n/**\n * Check if the module has any exports that need handling.\n */\nexport function hasExports(metadata: ModuleMetadata) {\n return metadata.hasExports;\n}\n\n/**\n * Check if a given source is an anonymous import, e.g. \"import 'foo';\"\n */\nexport function isSideEffectImport(source: SourceModuleMetadata) {\n return (\n source.imports.size === 0 &&\n source.importsNamespace.size === 0 &&\n source.reexports.size === 0 &&\n source.reexportNamespace.size === 0 &&\n !source.reexportAll\n );\n}\n\nexport function validateImportInteropOption(\n importInterop: any,\n): importInterop is ImportInterop {\n if (\n typeof importInterop !== \"function\" &&\n importInterop !== \"none\" &&\n importInterop !== \"babel\" &&\n importInterop !== \"node\"\n ) {\n throw new Error(\n `.importInterop must be one of \"none\", \"babel\", \"node\", or a function returning one of those values (received ${importInterop}).`,\n );\n }\n return importInterop;\n}\n\nfunction resolveImportInterop(\n importInterop: ImportInterop,\n source: string,\n filename: string | undefined,\n) {\n if (typeof importInterop === \"function\") {\n return validateImportInteropOption(importInterop(source, filename));\n }\n return importInterop;\n}\n\n/**\n * Remove all imports and exports from the file, and return all metadata\n * needed to reconstruct the module's behavior.\n */\nexport default function normalizeModuleAndLoadMetadata(\n programPath: NodePath<t.Program>,\n exportName: string,\n {\n importInterop,\n initializeReexports = false,\n lazy = false,\n esNamespaceOnly = false,\n filename,\n }: {\n importInterop: ImportInterop;\n initializeReexports: boolean | void;\n lazy: Lazy;\n esNamespaceOnly: boolean;\n filename: string;\n },\n): ModuleMetadata {\n if (!exportName) {\n exportName = programPath.scope.generateUidIdentifier(\"exports\").name;\n }\n const stringSpecifiers = new Set<string>();\n\n nameAnonymousExports(programPath);\n\n const { local, sources, hasExports } = getModuleMetadata(\n programPath,\n { initializeReexports, lazy },\n stringSpecifiers,\n );\n\n removeImportExportDeclarations(programPath);\n\n // Reuse the imported namespace name if there is one.\n for (const [source, metadata] of sources) {\n if (metadata.importsNamespace.size > 0) {\n // This is kind of gross. If we stop using `loose: true` we should\n // just make this destructuring assignment.\n metadata.name = metadata.importsNamespace.values().next().value;\n }\n\n const resolvedInterop = resolveImportInterop(\n importInterop,\n source,\n filename,\n );\n\n if (resolvedInterop === \"none\") {\n metadata.interop = \"none\";\n } else if (resolvedInterop === \"node\" && metadata.interop === \"namespace\") {\n metadata.interop = \"node-namespace\";\n } else if (resolvedInterop === \"node\" && metadata.interop === \"default\") {\n metadata.interop = \"node-default\";\n } else if (esNamespaceOnly && metadata.interop === \"namespace\") {\n // Both the default and namespace interops pass through __esModule\n // objects, but the namespace interop is used to enable Babel's\n // destructuring-like interop behavior for normal CommonJS.\n // Since some tooling has started to remove that behavior, we expose\n // it as the `esNamespace` option.\n metadata.interop = \"default\";\n }\n }\n\n return {\n exportName,\n exportNameListName: null,\n hasExports,\n local,\n source: sources,\n stringSpecifiers,\n };\n}\n\nfunction getExportSpecifierName(\n path: NodePath,\n stringSpecifiers: Set<string>,\n): string {\n if (path.isIdentifier()) {\n return path.node.name;\n } else if (path.isStringLiteral()) {\n const stringValue = path.node.value;\n // add specifier value to `stringSpecifiers` only when it can not be converted to an identifier name\n // i.e In `import { \"foo\" as bar }`\n // we do not consider `\"foo\"` to be a `stringSpecifier` because we can treat it as\n // `import { foo as bar }`\n // This helps minimize the size of `stringSpecifiers` and reduce overhead of checking valid identifier names\n // when building transpiled code from metadata\n if (!isIdentifierName(stringValue)) {\n stringSpecifiers.add(stringValue);\n }\n return stringValue;\n } else {\n throw new Error(\n `Expected export specifier to be either Identifier or StringLiteral, got ${path.node.type}`,\n );\n }\n}\n\nfunction assertExportSpecifier(\n path: NodePath,\n): asserts path is NodePath<t.ExportSpecifier> {\n if (path.isExportSpecifier()) {\n return;\n } else if (path.isExportNamespaceSpecifier()) {\n throw path.buildCodeFrameError(\n \"Export namespace should be first transformed by `@babel/plugin-proposal-export-namespace-from`.\",\n );\n } else {\n throw path.buildCodeFrameError(\"Unexpected export specifier type\");\n }\n}\n\n/**\n * Get metadata about the imports and exports present in this module.\n */\nfunction getModuleMetadata(\n programPath: NodePath<t.Program>,\n {\n lazy,\n initializeReexports,\n }: {\n // todo(flow-ts) changed from boolean, to match expected usage inside the function\n lazy: boolean | string[] | ((source: string) => boolean);\n initializeReexports: boolean | void;\n },\n stringSpecifiers: Set<string>,\n) {\n const localData = getLocalExportMetadata(\n programPath,\n initializeReexports,\n stringSpecifiers,\n );\n\n const sourceData = new Map<string, SourceModuleMetadata>();\n const getData = (sourceNode: t.StringLiteral) => {\n const source = sourceNode.value;\n\n let data = sourceData.get(source);\n if (!data) {\n data = {\n name: programPath.scope.generateUidIdentifier(\n basename(source, extname(source)),\n ).name,\n\n interop: \"none\",\n\n loc: null,\n\n // Data about the requested sources and names.\n imports: new Map(),\n importsNamespace: new Set(),\n\n // Metadata about data that is passed directly from source to export.\n reexports: new Map(),\n reexportNamespace: new Set(),\n reexportAll: null,\n\n lazy: false,\n\n referenced: false,\n };\n sourceData.set(source, data);\n }\n return data;\n };\n let hasExports = false;\n programPath.get(\"body\").forEach(child => {\n if (child.isImportDeclaration()) {\n const data = getData(child.node.source);\n if (!data.loc) data.loc = child.node.loc;\n\n child.get(\"specifiers\").forEach(spec => {\n if (spec.isImportDefaultSpecifier()) {\n const localName = spec.get(\"local\").node.name;\n\n data.imports.set(localName, \"default\");\n\n const reexport = localData.get(localName);\n if (reexport) {\n localData.delete(localName);\n\n reexport.names.forEach(name => {\n data.reexports.set(name, \"default\");\n });\n data.referenced = true;\n }\n } else if (spec.isImportNamespaceSpecifier()) {\n const localName = spec.get(\"local\").node.name;\n\n data.importsNamespace.add(localName);\n const reexport = localData.get(localName);\n if (reexport) {\n localData.delete(localName);\n\n reexport.names.forEach(name => {\n data.reexportNamespace.add(name);\n });\n data.referenced = true;\n }\n } else if (spec.isImportSpecifier()) {\n const importName = getExportSpecifierName(\n spec.get(\"imported\"),\n stringSpecifiers,\n );\n const localName = spec.get(\"local\").node.name;\n\n data.imports.set(localName, importName);\n\n const reexport = localData.get(localName);\n if (reexport) {\n localData.delete(localName);\n\n reexport.names.forEach(name => {\n data.reexports.set(name, importName);\n });\n data.referenced = true;\n }\n }\n });\n } else if (child.isExportAllDeclaration()) {\n hasExports = true;\n const data = getData(child.node.source);\n if (!data.loc) data.loc = child.node.loc;\n\n data.reexportAll = {\n loc: child.node.loc,\n };\n data.referenced = true;\n } else if (child.isExportNamedDeclaration() && child.node.source) {\n hasExports = true;\n const data = getData(child.node.source);\n if (!data.loc) data.loc = child.node.loc;\n\n child.get(\"specifiers\").forEach(spec => {\n assertExportSpecifier(spec);\n const importName = getExportSpecifierName(\n spec.get(\"local\"),\n stringSpecifiers,\n );\n const exportName = getExportSpecifierName(\n spec.get(\"exported\"),\n stringSpecifiers,\n );\n\n data.reexports.set(exportName, importName);\n data.referenced = true;\n\n if (exportName === \"__esModule\") {\n throw spec\n .get(\"exported\")\n .buildCodeFrameError('Illegal export \"__esModule\".');\n }\n });\n } else if (\n child.isExportNamedDeclaration() ||\n child.isExportDefaultDeclaration()\n ) {\n hasExports = true;\n }\n });\n\n for (const metadata of sourceData.values()) {\n let needsDefault = false;\n let needsNamed = false;\n\n if (metadata.importsNamespace.size > 0) {\n needsDefault = true;\n needsNamed = true;\n }\n\n if (metadata.reexportAll) {\n needsNamed = true;\n }\n\n for (const importName of metadata.imports.values()) {\n if (importName === \"default\") needsDefault = true;\n else needsNamed = true;\n }\n for (const importName of metadata.reexports.values()) {\n if (importName === \"default\") needsDefault = true;\n else needsNamed = true;\n }\n\n if (needsDefault && needsNamed) {\n // TODO(logan): Using the namespace interop here is unfortunate. Revisit.\n metadata.interop = \"namespace\";\n } else if (needsDefault) {\n metadata.interop = \"default\";\n }\n }\n\n for (const [source, metadata] of sourceData) {\n if (\n lazy !== false &&\n !(isSideEffectImport(metadata) || metadata.reexportAll)\n ) {\n if (lazy === true) {\n // 'true' means that local relative files are eagerly loaded and\n // dependency modules are loaded lazily.\n metadata.lazy = !/\\./.test(source);\n } else if (Array.isArray(lazy)) {\n metadata.lazy = lazy.indexOf(source) !== -1;\n } else if (typeof lazy === \"function\") {\n metadata.lazy = lazy(source);\n } else {\n throw new Error(`.lazy must be a boolean, string array, or function`);\n }\n }\n }\n\n return {\n hasExports,\n local: localData,\n sources: sourceData,\n };\n}\n\ntype ModuleBindingKind = \"import\" | \"hoisted\" | \"block\" | \"var\";\n/**\n * Get metadata about local variables that are exported.\n */\nfunction getLocalExportMetadata(\n programPath: NodePath<t.Program>,\n initializeReexports: boolean | void,\n stringSpecifiers: Set<string>,\n): Map<string, LocalExportMetadata> {\n const bindingKindLookup = new Map();\n\n programPath.get(\"body\").forEach((child: NodePath) => {\n let kind: ModuleBindingKind;\n if (child.isImportDeclaration()) {\n kind = \"import\";\n } else {\n if (child.isExportDefaultDeclaration()) {\n child = child.get(\"declaration\");\n }\n if (child.isExportNamedDeclaration()) {\n if (child.node.declaration) {\n child = child.get(\"declaration\");\n } else if (\n initializeReexports &&\n child.node.source &&\n child.get(\"source\").isStringLiteral()\n ) {\n child.get(\"specifiers\").forEach(spec => {\n assertExportSpecifier(spec);\n bindingKindLookup.set(spec.get(\"local\").node.name, \"block\");\n });\n return;\n }\n }\n\n if (child.isFunctionDeclaration()) {\n kind = \"hoisted\";\n } else if (child.isClassDeclaration()) {\n kind = \"block\";\n } else if (child.isVariableDeclaration({ kind: \"var\" })) {\n kind = \"var\";\n } else if (child.isVariableDeclaration()) {\n kind = \"block\";\n } else {\n return;\n }\n }\n\n Object.keys(child.getOuterBindingIdentifiers()).forEach(name => {\n bindingKindLookup.set(name, kind);\n });\n });\n\n const localMetadata = new Map();\n const getLocalMetadata = (idPath: NodePath<t.Identifier>) => {\n const localName = idPath.node.name;\n let metadata = localMetadata.get(localName);\n\n if (!metadata) {\n const kind = bindingKindLookup.get(localName);\n\n if (kind === undefined) {\n throw idPath.buildCodeFrameError(\n `Exporting local \"${localName}\", which is not declared.`,\n );\n }\n\n metadata = {\n names: [],\n kind,\n };\n localMetadata.set(localName, metadata);\n }\n return metadata;\n };\n\n programPath.get(\"body\").forEach(child => {\n if (\n child.isExportNamedDeclaration() &&\n (initializeReexports || !child.node.source)\n ) {\n if (child.node.declaration) {\n const declaration = child.get(\"declaration\");\n const ids = declaration.getOuterBindingIdentifierPaths();\n Object.keys(ids).forEach(name => {\n if (name === \"__esModule\") {\n throw declaration.buildCodeFrameError(\n 'Illegal export \"__esModule\".',\n );\n }\n getLocalMetadata(ids[name]).names.push(name);\n });\n } else {\n child.get(\"specifiers\").forEach(spec => {\n const local = spec.get(\"local\");\n const exported = spec.get(\"exported\");\n const localMetadata = getLocalMetadata(local);\n const exportName = getExportSpecifierName(exported, stringSpecifiers);\n\n if (exportName === \"__esModule\") {\n throw exported.buildCodeFrameError('Illegal export \"__esModule\".');\n }\n localMetadata.names.push(exportName);\n });\n }\n } else if (child.isExportDefaultDeclaration()) {\n const declaration = child.get(\"declaration\");\n if (\n declaration.isFunctionDeclaration() ||\n declaration.isClassDeclaration()\n ) {\n // @ts-expect-error todo(flow->ts): improve babel-types\n getLocalMetadata(declaration.get(\"id\")).names.push(\"default\");\n } else {\n // These should have been removed by the nameAnonymousExports() call.\n throw declaration.buildCodeFrameError(\n \"Unexpected default expression export.\",\n );\n }\n }\n });\n return localMetadata;\n}\n\n/**\n * Ensure that all exported values have local binding names.\n */\nfunction nameAnonymousExports(programPath: NodePath<t.Program>) {\n // Name anonymous exported locals.\n programPath.get(\"body\").forEach(child => {\n if (!child.isExportDefaultDeclaration()) return;\n splitExportDeclaration(child);\n });\n}\n\nfunction removeImportExportDeclarations(programPath: NodePath<t.Program>) {\n programPath.get(\"body\").forEach(child => {\n if (child.isImportDeclaration()) {\n child.remove();\n } else if (child.isExportNamedDeclaration()) {\n if (child.node.declaration) {\n // @ts-expect-error todo(flow->ts): avoid mutations\n child.node.declaration._blockHoist = child.node._blockHoist;\n child.replaceWith(child.node.declaration);\n } else {\n child.remove();\n }\n } else if (child.isExportDefaultDeclaration()) {\n // export default foo;\n const declaration = child.get(\"declaration\");\n if (\n declaration.isFunctionDeclaration() ||\n declaration.isClassDeclaration()\n ) {\n // @ts-expect-error todo(flow->ts): avoid mutations\n declaration._blockHoist = child.node._blockHoist;\n child.replaceWith(\n declaration as NodePath<t.FunctionDeclaration | t.ClassDeclaration>,\n );\n } else {\n // These should have been removed by the nameAnonymousExports() call.\n throw declaration.buildCodeFrameError(\n \"Unexpected default expression export.\",\n );\n }\n } else if (child.isExportAllDeclaration()) {\n child.remove();\n }\n });\n}\n"],"mappings":";;;;;;;;;AAAA;AAGA;AACA;AA+DO,SAASA,UAAU,CAACC,QAAwB,EAAE;EACnD,OAAOA,QAAQ,CAACD,UAAU;AAC5B;AAKO,SAASE,kBAAkB,CAACC,MAA4B,EAAE;EAC/D,OACEA,MAAM,CAACC,OAAO,CAACC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