Skip to content

Recast is adding extra newlines in ObjectExpressions #242

@kumarharsh

Description

@kumarharsh

Refer to the following fiddle: http://astexplorer.net/#/27xKOBJJGN

When I have an object with a structure such as this:

const styles = {
  base: {
    height: '100%',
  },
  ribbon: {
    backgroundColor: 'black',
  },
};

and I do anything with the body of the ObjectExpression like this:

export default function(file, api) {
  const j = api.jscodeshift;
  window.j = j;
  const { statement, statements } = j.template;
  return j(file.source)
    .find(j.VariableDeclarator)
    .replaceWith(p => {
        p.node.init = j.objectExpression(p.node.init.properties);
        return p.node;
    })
    .toSource();
};

then the following output is gotten:

const styles = {
  base: {
    height: '100%',
  },

  ribbon: {
    backgroundColor: 'black',
  }
};

see that extra newline after base and before ribbon. These lines are added after every property, which is adding unnecessary changes to my codebase. Is there a way to suppress that? or is that a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions