Skip to content

Commit

Permalink
fix(gatsby-transformer-remark): always include the root node of AST (#…
Browse files Browse the repository at this point in the history
…12647)

## Description

Fixes a bug in `cloneTreeUntil` function in `gatsby-transformer-remark`, where it only returns the last child node. This function is expected to clone a `root` node, but the current implementation forgets to revert the variable back to the `root` node. Reassigning `clonedRoot = newNode` (originally this is the argument `root`) should fix this. By resolving this bug, it appears to correctly returns the entire root node of AST in `excerptAst` of the markdown node, instead of returning the partial result.

## Related Issues

Related to #11237
  • Loading branch information
chitoku-k authored and DSchau committed Mar 19, 2019
1 parent 8c8b9b5 commit f480a35
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ Object {
"excerptAst": Object {
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony?",
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony?",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
"data": Object {
"quirksMode": false,
},
"type": "root",
},
"frontmatter": Object {
"title": "my little pony",
Expand All @@ -42,13 +50,21 @@ Object {
"excerptAst": Object {
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony? Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi auctor sit amet velit id facilisis. Nulla…",
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony? Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi auctor sit amet velit id facilisis. Nulla…",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
"data": Object {
"quirksMode": false,
},
"type": "root",
},
"frontmatter": Object {
"title": "my little pony",
Expand All @@ -62,13 +78,21 @@ Object {
"excerptAst": Object {
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony? Lorem ipsum…",
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony? Lorem ipsum…",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
"data": Object {
"quirksMode": false,
},
"type": "root",
},
"frontmatter": Object {
"title": "my little pony",
Expand All @@ -82,13 +106,21 @@ Object {
"excerptAst": Object {
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony? Lorem ipsum dol…",
"children": Array [
Object {
"type": "text",
"value": "Where oh where is my little pony? Lorem ipsum dol…",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
"data": Object {
"quirksMode": false,
},
"type": "root",
},
"frontmatter": Object {
"title": "my little pony",
Expand Down Expand Up @@ -135,73 +167,81 @@ Object {
"excerpt": "<p>Where oh <a href=\\"nick.com\\"><em>where</em></a> <strong><em>is</em></strong> <img src=\\"pony.png\\" alt=\\"that pony\\">?</p>",
"excerptAst": Object {
"children": Array [
Object {
"type": "text",
"value": "Where oh ",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "Where oh ",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "where",
"children": Array [
Object {
"type": "text",
"value": "where",
},
],
"properties": Object {},
"tagName": "em",
"type": "element",
},
],
"properties": Object {},
"tagName": "em",
"properties": Object {
"href": "nick.com",
},
"tagName": "a",
"type": "element",
},
],
"properties": Object {
"href": "nick.com",
},
"tagName": "a",
"type": "element",
},
Object {
"type": "text",
"value": " ",
},
Object {
"children": Array [
Object {
"type": "text",
"value": " ",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "is",
"children": Array [
Object {
"type": "text",
"value": "is",
},
],
"properties": Object {},
"tagName": "em",
"type": "element",
},
],
"properties": Object {},
"tagName": "em",
"tagName": "strong",
"type": "element",
},
Object {
"type": "text",
"value": " ",
},
Object {
"children": Array [],
"properties": Object {
"alt": "that pony",
"src": "pony.png",
},
"tagName": "img",
"type": "element",
},
Object {
"type": "text",
"value": "?",
},
],
"properties": Object {},
"tagName": "strong",
"type": "element",
},
Object {
"type": "text",
"value": " ",
},
Object {
"children": Array [],
"properties": Object {
"alt": "that pony",
"src": "pony.png",
},
"tagName": "img",
"tagName": "p",
"type": "element",
},
Object {
"type": "text",
"value": "?",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
"data": Object {
"quirksMode": false,
},
"type": "root",
},
"frontmatter": Object {
"title": "my little pony",
Expand All @@ -215,13 +255,21 @@ Object {
"excerptAst": Object {
"children": Array [
Object {
"type": "text",
"value": "Where oh where is that pony? Is he in the stable…",
"children": Array [
Object {
"type": "text",
"value": "Where oh where is that pony? Is he in the stable…",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
"data": Object {
"quirksMode": false,
},
"type": "root",
},
"frontmatter": Object {
"title": "my little pony",
Expand Down Expand Up @@ -283,29 +331,37 @@ Object {
"excerpt": "<p>Where is my <code>pony</code> named leo?</p>",
"excerptAst": Object {
"children": Array [
Object {
"type": "text",
"value": "Where is my ",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "pony",
"value": "Where is my ",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "pony",
},
],
"properties": Object {},
"tagName": "code",
"type": "element",
},
Object {
"type": "text",
"value": " named leo?",
},
],
"properties": Object {},
"tagName": "code",
"tagName": "p",
"type": "element",
},
Object {
"type": "text",
"value": " named leo?",
},
],
"properties": Object {},
"tagName": "p",
"type": "element",
"data": Object {
"quirksMode": false,
},
"type": "root",
},
"frontmatter": Object {
"title": "my little pony",
Expand Down
Loading

0 comments on commit f480a35

Please sign in to comment.