Skip to content

[Plugin] Adding data to the 'import' like remark-frontmatter #2524

Answered by remcohaszing
mattoni asked this question in Q&A
Discussion options

You must be logged in to vote

I think you’re looking to largely recreate remark-mdx-frontmatter, notably this part:

ast.children.unshift({
  type: 'mdxjsEsm',
  value: '',
  data: {
    estree: {
      type: 'Program',
      sourceType: 'module',
      body: [
        {
          type: 'ExportNamedDeclaration',
          specifiers: [],
          declaration: {
            type: 'VariableDeclaration',
            kind: 'const',
            declarations: [
              {
                type: 'VariableDeclarator',
                id: { type: 'Identifier', name },
                init: valueToEstree(data, { preserveReferences: true })
              }
            ]
          }
        }
      ]
    }
  }
})

You need to …

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@mattoni
Comment options

Comment options

You must be logged in to vote
2 replies
@mattoni
Comment options

@wooorm
Comment options

Comment options

You must be logged in to vote
1 reply
@mattoni
Comment options

Answer selected by mattoni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants