Skip to content

Commit

Permalink
Get rid of fixFaultyLocations code (#1252)
Browse files Browse the repository at this point in the history
As I was debugging #1248, I found out that the code to fix was actually making things worse. The other two branches are for decorators and deleting some random value of a function. I ran all the tests and the flow object is actually now preserving empty lines and didn't change anything else.

I'd rather remove all those and if something comes up then fix it properly upstream than having those crutches that we don't know why they exist anymore.
  • Loading branch information
vjeux committed Apr 14, 2017
1 parent 9d616fc commit 6a259b6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 58 deletions.
5 changes: 0 additions & 5 deletions src/comments.js
Expand Up @@ -15,7 +15,6 @@ var align = docBuilders.align;
var lineSuffix = docBuilders.lineSuffix;
var join = docBuilders.join;
var util = require("./util");
var comparePos = util.comparePos;
var childNodesCacheKey = Symbol("child-nodes");
var locStart = util.locStart;
var locEnd = util.locEnd;
Expand All @@ -29,10 +28,6 @@ function getSortedChildNodes(node, text, resultArray) {
return;
}

// The loc checks below are sensitive to some of the problems that
// are fixed by this utility function.
util.fixFaultyLocations(node, text);

if (resultArray) {
if (n.Node.check(node) && node.type !== "EmptyStatement") {
// This reverse insertion sort almost always takes constant
Expand Down
53 changes: 0 additions & 53 deletions src/util.js
Expand Up @@ -3,57 +3,6 @@
var types = require("ast-types");
var n = types.namedTypes;

function comparePos(pos1, pos2) {
return pos1.line - pos2.line || pos1.column - pos2.column;
}

function expandLoc(parentNode, childNode) {
if (locStart(childNode) - locStart(parentNode) < 0) {
setLocStart(parentNode, locStart(childNode));
}

if (locEnd(parentNode) - locEnd(childNode) < 0) {
setLocEnd(parentNode, locEnd(childNode));
}
}

function fixFaultyLocations(node, text) {
if (node.decorators) {
// Expand the loc of the node responsible for printing the decorators
// (here, the decorated node) so that it includes node.decorators.
node.decorators.forEach(function(decorator) {
expandLoc(node, decorator);
});
} else if (node.declaration && isExportDeclaration(node)) {
// Expand the loc of the node responsible for printing the decorators
// (here, the export declaration) so that it includes node.decorators.
var decorators = node.declaration.decorators;
if (decorators) {
decorators.forEach(function(decorator) {
expandLoc(node, decorator);
});
}
} else if (
(n.MethodDefinition && n.MethodDefinition.check(node)) ||
(n.Property.check(node) && (node.method || node.shorthand))
) {
if (n.FunctionExpression.check(node.value)) {
// FunctionExpression method values should be anonymous,
// because their .id fields are ignored anyway.
node.value.id = null;
}
} else if (node.type === "ObjectTypeProperty") {
var end = skipSpaces(text, locEnd(node), true);
if (end !== false && text.charAt(end) === ",") {
// Some parsers accidentally include trailing commas in the
// end information for ObjectTypeProperty nodes.
if ((end = skipSpaces(text, end - 1, true)) !== false) {
setLocEnd(node, end);
}
}
}
}

function isExportDeclaration(node) {
if (node)
switch (node.type) {
Expand Down Expand Up @@ -322,9 +271,7 @@ function getPrecedence(op) {
}

module.exports = {
comparePos,
getPrecedence,
fixFaultyLocations,
isExportDeclaration,
getParentExportDeclaration,
getPenultimate,
Expand Down
Expand Up @@ -457,15 +457,20 @@ class C extends A {}
type T = {
goodGetterWithAnnotation: () => number,
goodSetterWithAnnotation: (x: number) => void,
propWithMatchingGetterAndSetter: () => number,
propWithMatchingGetterAndSetter: (x: number) => void,
// The getter and setter need not have the same type
propWithSubtypingGetterAndSetter: () => ?number, // OK
propWithSubtypingGetterAndSetter: (x: number) => void,
propWithSubtypingGetterAndSetterReordered: (x: number) => void, // OK
propWithSubtypingGetterAndSetterReordered: () => ?number,
exampleOfOrderOfGetterAndSetter: () => A,
exampleOfOrderOfGetterAndSetter: (x: B) => void,
exampleOfOrderOfGetterAndSetterReordered: (x: B) => void,
exampleOfOrderOfGetterAndSetterReordered: () => A
};
Expand Down

0 comments on commit 6a259b6

Please sign in to comment.