Fix decorators location (#1779)

Babylon has a bug (I guess) with locations for classes where decorators are involved. Instead of the class starting at the first decorator, it starts at the beginning of the `class` keyword. By moving the location to the first comment, it solves --some-- of the issues with decorator comments.
master
Christopher Chedeau 2017-05-27 14:51:00 -07:00 committed by GitHub
parent c0d6ce53b7
commit 383aaca0e4
3 changed files with 36 additions and 0 deletions

View File

@ -206,6 +206,9 @@ function hasSpaces(text, index, opts) {
}
function locStart(node) {
if (node.decorators && node.decorators.length > 0) {
return locStart(node.decorators[0]);
}
if (node.range) {
return node.range[0];
}

View File

@ -1,5 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`comments.js 1`] = `
var x = 100
@Hello({
a: 'a', // Comment is in the wrong place
// test
b: '2'
})
class X {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x = 100;
@Hello({
a: "a", // Comment is in the wrong place
// test
b: "2"
})
class X {}
`;
exports[`mobx.js 1`] = `
import {observable} from "mobx";

View File

@ -0,0 +1,10 @@
var x = 100
@Hello({
a: 'a', // Comment is in the wrong place
// test
b: '2'
})
class X {
}