Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mdx-js/mdx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.20.2
Choose a base ref
...
head repository: mdx-js/mdx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.20.3
Choose a head ref
  • 4 commits
  • 15 files changed
  • 1 contributor

Commits on Mar 5, 2019

  1. 1
    Copy the full SHA
    a591a58 View commit details

Commits on Mar 6, 2019

  1. 1
    Copy the full SHA
    e1bcf1b View commit details
  2. Grouped imports shouldn't have empty newline separation (#405)

    * Begin spiking out import separation repro
    
    * Combine adjacent nodes of the same type into a single node
    
    * Improve readability, remove mutation of node combination
    
    * Improve test by properly ordering
    johno authored Mar 6, 2019
    1
    Copy the full SHA
    cca8acc View commit details
  3. v0.20.3

    johno committed Mar 6, 2019
    1
    Copy the full SHA
    f7a232c View commit details
1 change: 1 addition & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -126,6 +126,7 @@ If you’re having issues installing locally you might need to run

## Resources

* [Good first issues in the MDX repository](https://github.com/mdx-js/mdx/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
* [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
* [Making your first contribution](https://medium.com/@vadimdemedes/making-your-first-contribution-de6576ddb190)
* [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "3.4.0",
"version": "0.20.2",
"version": "0.20.3",
"packages": [
"packages/*"
],
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
"test": "remark . -qf && eslint . && lerna run test",
"format": "remark . -qfo && eslint . --fix",
"publish": "lerna publish",
"publish-ci": "lerna publish -y --canary --preid ci --npm-tag ci"
"publish-ci": "lerna publish -y --canary --preid ci --npm-tag ci --npm-client npm"
},
"workspaces": [
"packages/*"
2 changes: 1 addition & 1 deletion packages/create-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-mdx",
"version": "0.18.0",
"version": "0.20.3",
"description": "Initialize an MDX project",
"license": "MIT",
"keywords": [
6 changes: 3 additions & 3 deletions packages/loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/loader",
"version": "0.20.2",
"version": "0.20.3",
"description": "Loader for MDX",
"license": "MIT",
"keywords": [
@@ -27,8 +27,8 @@
"index.js"
],
"dependencies": {
"@mdx-js/mdx": "^0.20.2",
"@mdx-js/tag": "^0.18.0",
"@mdx-js/mdx": "^0.20.3",
"@mdx-js/tag": "^0.20.3",
"loader-utils": "^1.1.0"
},
"devDependencies": {
4 changes: 2 additions & 2 deletions packages/mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/mdx",
"version": "0.20.2",
"version": "0.20.3",
"description": "Parse MDX and transpile to JSX",
"license": "MIT",
"keywords": [
@@ -46,7 +46,7 @@
"@babel/core": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.1.6",
"@mapbox/rehype-prism": "^0.3.0",
"@mdx-js/tag": "^0.18.0",
"@mdx-js/tag": "^0.20.3",
"hast-util-select": "^3.0.0",
"jest": "^23.6.0",
"prettier": "^1.14.2",
2 changes: 1 addition & 1 deletion packages/mdxast/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/mdxast",
"version": "0.18.0",
"version": "0.20.3",
"description": "Transforms MDAST to MDXAST",
"license": "MIT",
"keywords": [
4 changes: 2 additions & 2 deletions packages/parcel-plugin-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/parcel-plugin-mdx",
"version": "0.20.2",
"version": "0.20.3",
"description": "Parcel plugin for MDX",
"license": "MIT",
"keywords": [
@@ -27,7 +27,7 @@
"src"
],
"dependencies": {
"@mdx-js/mdx": "^0.20.2",
"@mdx-js/mdx": "^0.20.3",
"parcel-bundler": "^1.4.1"
},
"peerDependencies": {
35 changes: 34 additions & 1 deletion packages/remark-mdx/extract-imports-and-exports.js
Original file line number Diff line number Diff line change
@@ -49,8 +49,41 @@ module.exports = value => {
const nodeStarts = sortedNodes.map(n => n.start)
const values = partitionString(value, nodeStarts)

return sortedNodes.map(({start: _, ...node}, i) => {
const allNodes = sortedNodes.map(({start: _, ...node}, i) => {
const value = values[i]
return {...node, value}
})

// Group adjacent nodes of the same type so that they can be combined
// into a single node later, this also ensures that order is preserved
let currType = allNodes[0].type
const groupedNodes = allNodes.reduce(
(acc, curr) => {
// Default export nodes shouldn't be grouped with other exports
// because they're handled specially by MDX
if (curr.default) {
currType = 'default'
return [...acc, [curr]]
}
if (curr.type === currType) {
const lastNodes = acc.pop()
return [...acc, [...lastNodes, curr]]
}
currType = curr.type
return [...acc, [curr]]
},
[[]]
)

// Combine adjacent nodes into a single node
return groupedNodes
.filter(a => a.length)
.reduce((acc, curr) => {
const node = curr.reduce((acc, curr) => ({
...acc,
value: acc.value + curr.value
}))

return [...acc, node]
}, [])
}
2 changes: 1 addition & 1 deletion packages/remark-mdx/index.js
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ function attachCompiler(compiler) {
}

function stringifyEsSyntax(node) {
return node.value
return node.value.trim()
}

function tokenizeEsSyntax(eat, value) {
2 changes: 1 addition & 1 deletion packages/remark-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remark-mdx",
"version": "0.18.2",
"version": "0.20.3",
"description": "Support import, export, and JSX in markdown",
"license": "MIT",
"keywords": [
13 changes: 13 additions & 0 deletions packages/remark-mdx/test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -184,3 +184,16 @@ Object {
"type": "root",
}
`;
exports[`removes newlines between imports and exports 1`] = `
"import Foo1 from \\"./foo\\"
import Foo2 from \\"./foo\\"
import Foo3 from \\"./foo\\"
export const foo = \\"bar\\"
export default props => <article {...props} />
export const fred = \\"flintstone\\"
"
`;
27 changes: 27 additions & 0 deletions packages/remark-mdx/test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const unified = require('unified')
const remarkParse = require('remark-parse')
const remarkStringify = require('remark-stringify')

const remarkMdx = require('..')
const mdxAstToMdxHast = require('../../mdx/mdx-ast-to-mdx-hast')
const mdxHastToJsx = require('../../mdx/mdx-hast-to-jsx')
@@ -41,6 +43,16 @@ const parse = mdx => {
return result
}

const stringify = mdx => {
const result = unified()
.use(remarkParse)
.use(remarkStringify)
.use(remarkMdx)
.processSync(mdx)

return result.contents
}

it('correctly transpiles', () => {
const result = transpile(FIXTURE)

@@ -52,3 +64,18 @@ it('maintains the proper positional info', () => {

expect(result).toMatchSnapshot()
})

it('removes newlines between imports and exports', () => {
const fixture = [
'import Foo1 from "./foo"',
'import Foo2 from "./foo"',
'import Foo3 from "./foo"',
'export const foo = "bar"',
'export default props => <article {...props} />',
'export const fred = "flintstone"'
].join('\n')

const result = stringify(fixture)

expect(result).toMatchSnapshot()
})
6 changes: 3 additions & 3 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/runtime",
"version": "0.20.2",
"version": "0.20.3",
"description": "Parse and render MDX in a runtime environment",
"license": "MIT",
"keywords": [
@@ -33,8 +33,8 @@
"src/"
],
"dependencies": {
"@mdx-js/mdx": "^0.20.2",
"@mdx-js/tag": "^0.18.0",
"@mdx-js/mdx": "^0.20.3",
"@mdx-js/tag": "^0.20.3",
"buble": "^0.19.6"
},
"devDependencies": {
2 changes: 1 addition & 1 deletion packages/tag/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mdx-js/tag",
"version": "0.18.0",
"version": "0.20.3",
"description": "A fully-featured Markdown/MDX React component for ambitious projects",
"license": "MIT",
"keywords": [