How to use the @mdx-js/mdx.forEach function in @mdx-js/mdx

To help you get started, we’ve selected a few @mdx-js/mdx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frontarm / mdx-util / packages / mdx.macro / mdx.macro.js View on Github external
referencePath.parentPath.type === 'MemberExpression' &&
      referencePath.parentPath.node.property.name === 'sync'
    ) {
      hasSyncReferences = true
      importSync({referencePath, state, babel})
    } else {
      throw new Error(
        `This is not supported: \`${referencePath
          .findParent(babel.types.isExpression)
          .getSource()}\`. Please see the mdx.macro documentation`,
      )
    }
  })

  let hasInlineMDX = false
  mdx.forEach(referencePath => {
    hasInlineMDX = true
    inlineMDX({referencePath, state, babel})
  })

  if (hasInlineMDX) {
    let program = state.file.path
    let mdxTagImport = babel.transformSync(
      `import { MDXTag } from '@mdx-js/tag'`,
      {
        ast: true,
        filename: "mdx.macro/mdxTagImport.js"
      }
    )
    program.node.body.unshift(mdxTagImport.ast.program.body[0])
  }
}