Download next.js/packages/next/src/build/babel/plugins/commonjs.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 969 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/build/babel/plugins/commonjs.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/build/babel/plugins/commonjs.ts
-
curl -L -o commonjs.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/build/babel/plugins/commonjs.ts
969 Bytes
| import type { NodePath, types } from 'next/dist/compiled/babel/core' | |
| import type { PluginObj } from 'next/dist/compiled/babel/core' | |
| import commonjsPlugin from 'next/dist/compiled/babel/plugin-transform-modules-commonjs' | |
| // Handle module.exports in user code | |
| export default function CommonJSModulePlugin(...args: any): PluginObj { | |
| const commonjs = commonjsPlugin(...args) | |
| return { | |
| visitor: { | |
| Program: { | |
| exit(path: NodePath<types.Program>, state) { | |
| let foundModuleExports = false | |
| path.traverse({ | |
| MemberExpression(expressionPath: any) { | |
| if (expressionPath.node.object.name !== 'module') return | |
| if (expressionPath.node.property.name !== 'exports') return | |
| foundModuleExports = true | |
| }, | |
| }) | |
| if (!foundModuleExports) { | |
| return | |
| } | |
| commonjs.visitor.Program.exit.call(this, path, state) | |
| }, | |
| }, | |
| }, | |
| } | |
| } | |