Closed JounQin closed 3 years ago
Besides, if we only have the following
import React from "react";
export { React };
Another error is thrown:
/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/util/slice-chunks.js:11
view = [chunks[startIndex].slice(startBufferIndex, endBufferIndex)]
^
TypeError: Cannot read property 'slice' of null
at sliceChunks (/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/util/slice-chunks.js:11:32)
at sliceStream (/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/util/create-tokenizer.js:89:12)
at Object.sliceSerialize (/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/util/create-tokenizer.js:85:28)
at atEnd (/Users/JounQin/Workspaces/Local/test/node_modules/micromark-extension-mdxjs-esm/index.js:123:24)
at rest (/Users/JounQin/Workspaces/Local/test/node_modules/micromark-extension-mdxjs-esm/index.js:86:16)
at lineStart (/Users/JounQin/Workspaces/Local/test/node_modules/micromark-extension-mdxjs-esm/index.js:111:14)
at go (/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/util/create-tokenizer.js:136:13)
at main (/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/util/create-tokenizer.js:130:9)
at Object.write (/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/util/create-tokenizer.js:70:5)
at exitContainers (/Users/JounQin/Workspaces/Local/test/node_modules/micromark/dist/initialize/document.js:126:17)
Huh, looks weird that this is happening (there are a ton of tests). Could you post the code you're using to run this / their versions too? Or attaxh the mdx sample as a file instead (maybe line endings is the problem?)
I’m now getting, for: import a from "b";\n\nexport {a};\n\nc
, the error: "Could not parse import/exports with acorn: SyntaxError: Export 'a' is not defined"
.
I guess acorn is failing because I’m parsing them separately. And the second is failing because it doesn’t “know” there was an a
imported before.
But this is still a different error from what you’re seeing
My testing code, all installed latest.
const fs = require("fs");
const fromMarkdown = require("mdast-util-from-markdown");
const toHast = require("mdast-util-to-hast");
const mdxFromMarkdown = require("mdast-util-mdx").fromMarkdown;
const mdxjs = require("micromark-extension-mdxjs");
const toEstree = require("hast-util-to-estree");
const doc = fs.readFileSync("./test.mdx", "utf8");
const mdast = fromMarkdown(doc, {
extensions: [mdxjs()],
mdastExtensions: [mdxFromMarkdown],
});
const hast = toHast(mdast, {
passThrough: [
"mdxFlowExpression",
"mdxJsxFlowElement",
"mdxJsxTextElement",
"mdxTextExpression",
"mdxjsEsm",
],
});
fs.writeFileSync("./test.json", JSON.stringify(toEstree(hast), null, 2));
Thanks for that repro! Removing the blank line between the import/export for now works.
Weird stuff!
Fixed!
Subject of the issue
Your environment
micromark-extension-mdxjs-esm@0.1.1
Steps to reproduce
Expected behavior
No error
Actual behavior
Error