UNPKG

27.1 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../../../build/babel/plugins/next-ssg-transform.ts"],"names":["EXPORT_NAME_GET_STATIC_PROPS","EXPORT_NAME_GET_STATIC_PATHS","EXPORT_NAME_GET_SERVER_PROPS","ssgExports","Set","decorateSsgExport","t","path","state","gsspName","isPrerender","STATIC_PROPS_ID","SERVER_PROPS_ID","gsspId","identifier","addGsspExport","exportPath","done","pageCompPath","replaceWithMultiple","exportNamedDeclaration","variableDeclaration","variableDeclarator","booleanLiteral","exportSpecifier","node","scope","registerDeclaration","traverse","ExportDefaultDeclaration","exportDefaultPath","ExportNamedDeclaration","exportNamedPath","isDataIdentifier","name","has","Error","SERVER_PROPS_SSG_CONFLICT","isServerProps","nextTransformSsg","types","getIdentifier","parentPath","type","pp","get","id","isIdentifierReferenced","ident","b","getBinding","referenced","constantViolations","concat","referencePaths","every","ref","findParent","p","markFunction","refs","add","markImport","local","visitor","Program","enter","VariableDeclarator","variablePath","variableState","pattern","properties","forEach","elements","e","FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","ImportSpecifier","ImportDefaultSpecifier","ImportNamespaceSpecifier","exportNamedState","specifiers","length","s","isIdentifier","exported","value","remove","decl","inner","d","count","sweepFunction","sweepPath","isAssignmentExpression","isVariableDeclarator","sweepImport","parent","crawl","beforeCount"],"mappings":"4LAKA,iDACA,8DAKO,KAAMA,CAAAA,4BAA4B,CAAG,gBAArC,C,kEACA,KAAMC,CAAAA,4BAA4B,CAAG,gBAArC,C,kEACA,KAAMC,CAAAA,4BAA4B,CAAG,oBAArC,C,kEAEP,KAAMC,CAAAA,UAAU,CAAG,GAAIC,CAAAA,GAAJ,CAAQ,CACzBJ,4BADyB,CAEzBC,4BAFyB,CAGzBC,4BAHyB,CAKzB;AACA;AACC,yBAPwB,CAQxB,yBARwB,CASxB,yBATwB,CAUxB,6BAVwB,CAAR,CAAnB,CAoBA,QAASG,CAAAA,iBAAT,CACEC,CADF,CAEEC,IAFF,CAGEC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FLICT } from '../../../lib/constants'\nimport {\n SERVER_PROPS_ID,\n STATIC_PROPS_ID,\n} from '../../../next-server/lib/constants'\n\nexport const EXPORT_NAME_GET_STATIC_PROPS = 'getStaticProps'\nexport const EXPORT_NAME_GET_STATIC_PATHS = 'getStaticPaths'\nexport const EXPORT_NAME_GET_SERVER_PROPS = 'getServerSideProps'\n\nconst ssgExports = new Set([\n EXPORT_NAME_GET_STATIC_PROPS,\n EXPORT_NAME_GET_STATIC_PATHS,\n EXPORT_NAME_GET_SERVER_PROPS,\n\n // legacy methods added so build doesn't fail from importing\n // server-side only methods\n `unstable_getStaticProps`,\n `unstable_getStaticPaths`,\n `unstable_getServerProps`,\n `unstable_getServerSideProps`,\n])\n\ntype PluginState = {\n refs: Set<NodePath<BabelTypes.Identifier>>\n isPrerender: boolean\n isServerProps: boolean\n done: boolean\n}\n\nfunction decorateSsgExport(\n t: typeof BabelTypes,\n path: NodePath<BabelTypes.Program>,\n state: PluginState\n): void {\n const gsspName = state.isPrerender ? STATIC_PROPS_ID : SERVER_PROPS_ID\n const gsspId = t.identifier(gsspName)\n\n const addGsspExport = (\n exportPath:\n | NodePath<BabelTypes.ExportDefaultDeclaration>\n | NodePath<BabelTypes.ExportNamedDeclaration>\n ): void => {\n if (state.done) {\n return\n }\n state.done = true\n\n const [pageCompPath] = exportPath.replaceWithMultiple([\n t.exportNamedDeclaration(\n t.variableDeclaration(\n // We use 'var' instead of 'let' or 'const' for ES5 support. Since\n // this runs in `Program#exit`, no ES2015 transforms (preset env)\n // will be ran against this code.\n 'var',\n [t.variableDeclarator(gsspId, t.booleanLiteral(true))]\n ),\n [t.exportSpecifier(gsspId, gsspId)]\n ),\n exportPath.node,\n ])\n exportPath.scope.registerDeclaration(\n pageCompPath as NodePath<BabelTypes.Node>\n )\n }\n\n path.traverse({\n ExportDefaultDeclaration(exportDefaultPath) {\n addGsspExport(exportDefaultPath)\n },\n ExportNamedDeclaration(exportNamedPath) {\n addGsspExport(exportNamedPath)\n },\n })\n}\n\nconst isDataIdentifier = (name: string, state: PluginState): boolean => {\n if (ssgExports.has(name)) {\n if (name === EXPORT_NAME_GET_SERVER_PROPS) {\n if (state.isPrerender) {\n throw new Error(SERVER_PROPS_SSG_CONFLICT)\n }\n state.isServerProps = true\n } else {\n if (state.isServerProps) {\n throw new Error(SERVER_PROPS_SSG_CONFLICT)\n }\n state.isPrerender = true\n }\n return true\n }\n return false\n}\n\nexport default function nextTransformSsg({\n types: t,\n}: {\n types: typeof BabelTypes\n}): PluginObj<PluginState> {\n function getIdentifier(\n path:\n | NodePath<BabelTypes.FunctionDeclaration>\n | NodePath<BabelTypes.FunctionExpression>\n | NodePath<BabelTypes.ArrowFunctionExpression>\n ): NodePath<BabelTypes.Identifier> | null {\n const parentPath = path.parentPath\n if (parentPath.type === 'VariableDeclarator') {\n const pp = parentPath as NodePath<BabelTypes.VariableDeclarator>\n const name = pp.get('id')\n return name.node.type === 'Identifier'\n ? (name as NodePath<BabelTypes.Identifier>)\n : null\n }\n\n if (parentPath.type === 'AssignmentExpression') {\n const pp = parentPath as NodePath<BabelTypes.AssignmentExpression>\n const name = pp.get('left')\n return name.node.type === 'Identifier'\n ? (name as NodePath<BabelTypes.Identifier>)\n : null\n }\n\n if (path.node.type === 'ArrowFunctionExpression') {\n return null\n }\n\n return path.node.id && path.node.id.type === 'Identifier'\n ? (path.get('id') as NodePath<BabelTypes.Identifier>)\n : null\n }\n\n function isIdentifierReferenced(\n ident: NodePath<BabelTypes.Identifier>\n ): boolean {\n const b = ident.scope.getBinding(ident.node.name)\n if (b?.referenced) {\n // Functions can reference themselves, so we need to check if there's a\n // binding outside the function scope or not.\n if (b.path.type === 'FunctionDeclaration') {\n return !b.constantViolations\n .concat(b.referencePaths)\n // Check that every reference is contained within the function:\n .every((ref) => ref.findParent((p) => p === b.path))\n }\n\n return true\n }\n return false\n }\n\n function markFunction(\n path:\n | NodePath<BabelTypes.FunctionDeclaration>\n | NodePath<BabelTypes.FunctionExpression>\n | NodePath<BabelTypes.ArrowFunctionExpression>,\n state: PluginState\n ): void {\n const ident = getIdentifier(path)\n if (ident?.node && isIdentifierReferenced(ident)) {\n state.refs.add(ident)\n }\n }\n\n function markImport(\n path:\n | NodePath<BabelTypes.ImportSpecifier>\n | NodePath<BabelTypes.ImportDefaultSpecifier>\n | NodePath<BabelTypes.ImportNamespaceSpecifier>,\n state: PluginState\n ): void {\n const local = path.get('local') as NodePath<BabelTypes.Identifier>\n if (isIdentifierReferenced(local)) {\n state.refs.add(local)\n }\n }\n\n return {\n visitor: {\n Program: {\n enter(path, state) {\n state.refs = new Set<NodePath<BabelTypes.Identifier>>()\n state.isPrerender = false\n state.isServerProps = false\n state.done = false\n\n path.traverse(\n {\n VariableDeclarator(variablePath, variableState) {\n if (variablePath.node.id.type === 'Identifier') {\n const local = variablePath.get('id') as NodePath<\n BabelTypes.Identifier\n >\n if (isIdentifierReferenced(local)) {\n variableState.refs.add(local)\n }\n } else if (variablePath.node.id.type === 'ObjectPattern') {\n const pattern = variablePath.get('id') as NodePath<\n BabelTypes.ObjectPattern\n >\n\n const properties = pattern.get('properties')\n properties.forEach((p) => {\n const local = p.get(\n p.node.type === 'ObjectProperty'\n ? 'value'\n : p.node.type === 'RestElement'\n ? 'argument'\n : (function () {\n throw new Error('invariant')\n })()\n ) as NodePath<BabelTypes.Identifier>\n if (isIdentifierReferenced(local)) {\n variableState.refs.add(local)\n }\n })\n } else if (variablePath.node.id.type === 'ArrayPattern') {\n const pattern = variablePath.get('id') as NodePath<\n BabelTypes.ArrayPattern\n >\n\n const elements = pattern.get('elements')\n elements.forEach((e) => {\n let local: NodePath<BabelTypes.Identifier>\n if (e.node?.type === 'Identifier') {\n local = e as NodePath<BabelTypes.Identifier>\n } else if (e.node?.type === 'RestElement') {\n local = e.get('argument') as NodePath<\n BabelTypes.Identifier\n >\n } else {\n return\n }\n\n if (isIdentifierReferenced(local)) {\n variableState.refs.add(local)\n }\n })\n }\n },\n FunctionDeclaration: markFunction,\n FunctionExpression: markFunction,\n ArrowFunctionExpression: markFunction,\n ImportSpecifier: markImport,\n ImportDefaultSpecifier: markImport,\n ImportNamespaceSpecifier: markImport,\n ExportNamedDeclaration(exportNamedPath, exportNamedState) {\n const specifiers = exportNamedPath.get('specifiers')\n if (specifiers.length) {\n specifiers.forEach((s) => {\n if (\n isDataIdentifier(\n t.isIdentifier(s.node.exported)\n ? s.node.exported.name\n : s.node.exported.value,\n exportNamedState\n )\n ) {\n s.remove()\n }\n })\n\n if (exportNamedPath.node.specifiers.length < 1) {\n exportNamedPath.remove()\n }\n return\n }\n\n const decl = exportNamedPath.get('declaration') as NodePath<\n | BabelTypes.FunctionDeclaration\n | BabelTypes.VariableDeclaration\n >\n if (decl == null || decl.node == null) {\n return\n }\n\n switch (decl.node.type) {\n case 'FunctionDeclaration': {\n const name = decl.node.id!.name\n if (isDataIdentifier(name, exportNamedState)) {\n exportNamedPath.remove()\n }\n break\n }\n case 'VariableDeclaration': {\n const inner = decl.get('declarations') as NodePath<\n BabelTypes.VariableDeclarator\n >[]\n inner.forEach((d) => {\n if (d.node.id.type !== 'Identifier') {\n return\n }\n const name = d.node.id.name\n if (isDataIdentifier(name, exportNamedState)) {\n d.remove()\n }\n })\n break\n }\n default: {\n break\n }\n }\n },\n },\n state\n )\n\n if (!state.isPrerender && !state.isServerProps) {\n return\n }\n\n const refs = state.refs\n let count: number\n\n function sweepFunction(\n sweepPath:\n | NodePath<BabelTypes.FunctionDeclaration>\n | NodePath<BabelTypes.FunctionExpression>\n | NodePath<BabelTypes.ArrowFunctionExpression>\n ): void {\n const ident = getIdentifier(sweepPath)\n if (\n ident?.node &&\n refs.has(ident) &&\n !isIdentifierReferenced(ident)\n ) {\n ++count\n\n if (\n t.isAssignmentExpression(sweepPath.parentPath) ||\n t.isVariableDeclarator(sweepPath.parentPath)\n ) {\n sweepPath.parentPath.remove()\n } else {\n sweepPath.remove()\n }\n }\n }\n\n function sweepImport(\n sweepPath:\n | NodePath<BabelTypes.ImportSpecifier>\n | NodePath<BabelTypes.ImportDefaultSpecifier>\n | NodePath<BabelTypes.ImportNamespaceSpecifier>\n ): void {\n const local = sweepPath.get('local') as NodePath<\n BabelTypes.Identifier\n >\n if (refs.has(local) && !isIdentifierReferenced(local)) {\n ++count\n sweepPath.remove()\n if (\n (sweepPath.parent as BabelTypes.ImportDeclaration).specifiers\n .length === 0\n ) {\n sweepPath.parentPath.remove()\n }\n }\n }\n\n do {\n ;(path.scope as any).crawl()\n count = 0\n\n path.traverse({\n // eslint-disable-next-line no-loop-func\n VariableDeclarator(variablePath) {\n if (variablePath.node.id.type === 'Identifier') {\n const local = variablePath.get('id') as NodePath<\n BabelTypes.Identifier\n >\n if (refs.has(local) && !isIdentifierReferenced(local)) {\n ++count\n variablePath.remove()\n }\n } else if (variablePath.node.id.type === 'ObjectPattern') {\n const pattern = variablePath.get('id') as NodePath<\n BabelTypes.ObjectPattern\n >\n\n const beforeCount = count\n const properties = pattern.get('properties')\n properties.forEach((p) => {\n const local = p.get(\n p.node.type === 'ObjectProperty'\n ? 'value'\n : p.node.type === 'RestElement'\n ? 'argument'\n : (function () {\n throw new Error('invariant')\n })()\n ) as NodePath<BabelTypes.Identifier>\n\n if (refs.has(local) && !isIdentifierReferenced(local)) {\n ++count\n p.remove()\n }\n })\n\n if (\n beforeCount !== count &&\n pattern.get('properties').length < 1\n ) {\n variablePath.remove()\n }\n } else if (variablePath.node.id.type === 'ArrayPattern') {\n const pattern = variablePath.get('id') as NodePath<\n BabelTypes.ArrayPattern\n >\n\n const beforeCount = count\n const elements = pattern.get('elements')\n elements.forEach((e) => {\n let local: NodePath<BabelTypes.Identifier>\n if (e.node?.type === 'Identifier') {\n local = e as NodePath<BabelTypes.Identifier>\n } else if (e.node?.type === 'RestElement') {\n local = e.get('argument') as NodePath<\n BabelTypes.Identifier\n >\n } else {\n return\n }\n\n if (refs.has(local) && !isIdentifierReferenced(local)) {\n ++count\n e.remove()\n }\n })\n\n if (\n beforeCount !== count &&\n pattern.get('elements').length < 1\n ) {\n variablePath.remove()\n }\n }\n },\n FunctionDeclaration: sweepFunction,\n FunctionExpression: sweepFunction,\n ArrowFunctionExpression: sweepFunction,\n ImportSpecifier: sweepImport,\n ImportDefaultSpecifier: sweepImport,\n ImportNamespaceSpecifier: sweepImport,\n })\n } while (count)\n\n decorateSsgExport(t, path, state)\n },\n },\n },\n }\n}\n"]}
\No newline at end of file