Skip to content

Commit

Permalink
fix(yaml): end comment in nested mapping (#4918)
Browse files Browse the repository at this point in the history
* test: add tests

* fix(yaml): end comment in nested mapping
  • Loading branch information
ikatyang committed Aug 2, 2018
1 parent 10df246 commit b6077e1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -61,7 +61,7 @@
"unicode-regex": "1.0.1",
"unified": "6.1.6",
"yaml": "1.0.0-rc.7",
"yaml-unist-parser": "1.0.0-rc.2"
"yaml-unist-parser": "1.0.0-rc.3"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.49",
Expand Down
2 changes: 2 additions & 0 deletions src/language-yaml/printer-yaml.js
Expand Up @@ -381,6 +381,8 @@ function _print(node, parentNode, path, options, print) {
needsSpaceInFrontOfMappingValue(node) ? " " : "",
":",
hasLeadingComments(node.value.node) ||
(hasEndComments(node.value) &&
node.value.node.type !== "null") ||
(parentNode.type === "mapping" &&
hasTrailingComments(node.key.node) &&
isInlineNode(node.value.node)) ||
Expand Down
34 changes: 33 additions & 1 deletion tests/yaml_comment/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -31,7 +31,8 @@ f:
empty_content:
# hello world
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a: 123
a:
123
# impicitMappginValue
? b
Expand Down Expand Up @@ -62,6 +63,37 @@ empty_content:
`;

exports[`end-comment.yml - yaml-verify 1`] = `
parent:
one: 1
# two: 2
a:
b:
#b
#a
A:
B:
#A
#A
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parent:
one: 1
# two: 2
a:
b:
#b
#a
A:
? B
#A
#A
`;

exports[`root.yml - yaml-verify 1`] = `
#hello world
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
13 changes: 13 additions & 0 deletions tests/yaml_comment/end-comment.yml
@@ -0,0 +1,13 @@
parent:
one: 1
# two: 2

a:
b:
#b
#a

A:
B:
#A
#A
2 changes: 1 addition & 1 deletion tests/yaml_root/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -262,7 +262,7 @@ omap:
- aardvark: African pig-like ant eater. Ugly.
- anteater: South-American ant eater. Two species.
- anaconda: South-American constrictor snake. Scaly.
# Etc.
# Etc.
# Flow style
Numbers: !!omap [one: 1, two: 2, three: 3]
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -6008,9 +6008,9 @@ yallist@^3.0.0, yallist@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9"

yaml-unist-parser@1.0.0-rc.2:
version "1.0.0-rc.2"
resolved "https://registry.yarnpkg.com/yaml-unist-parser/-/yaml-unist-parser-1.0.0-rc.2.tgz#a9c3597fe8507d7b80c7c51fc1c1ae4773ccdd30"
yaml-unist-parser@1.0.0-rc.3:
version "1.0.0-rc.3"
resolved "https://registry.yarnpkg.com/yaml-unist-parser/-/yaml-unist-parser-1.0.0-rc.3.tgz#d7b396353da92c75bb471a9e65973ba967e0b4f6"
dependencies:
lines-and-columns "^1.1.6"
tslib "^1.9.1"
Expand Down

0 comments on commit b6077e1

Please sign in to comment.