Fix locEnd() for postcss parser (#2295)

* Fix locEnd() for postcss parser

`node.source` doesn't have an `end`, but `node.nodes[-1].source` does.

Fixes https://github.com/prettier/prettier/issues/2267

* Add regression test for https://github.com/prettier/prettier/issues/2267

See https://github.com/prettier/prettier/pull/2295#issuecomment-311484343

* Make locEnd() postcss fix more focused

This passes the tests again.

* Use getLast() instead of .slice()

See https://github.com/prettier/prettier/pull/2295#discussion_r124398553

* Move CSS range test into tests/range_css

This is so that the AST_COMPARE=1 tests don't try to parse CSS with Flow.
This commit is contained in:
Joseph Frazier authored and Christopher Chedeau committed 2017-06-27 15:12:22 -07:00
1 parent adc71ef6ae
commit 5f063ab168
4 files changed
+15

No files matched your search

+5
View File
@@ -236,6 +236,11 @@ function locStart(node) {
}
function locEnd(node) {
const endNode = node.nodes && getLast(node.nodes);
if (endNode && node.source && !node.source.end) {
node = endNode;
}
let loc;
if (node.range) {
loc = node.range[1];
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`issue2267.css 1`] = `
.x{}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.x{}
`;
+1
View File
@@ -0,0 +1 @@
.x{}<<<PRETTIER_RANGE_END>>>
+1
View File
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "postcss" });