facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.32k stars 481 forks source link

Reprinting file without changes line break changes #52

Open sophiebits opened 9 years ago

sophiebits commented 9 years ago

Parsing and reprinting

// I have a parent
newNode.parent
  && (
    (// Or I did but its different than the one I have now.
      !originalNode.parent ||
      newNode.parent.key !== originalNode.parent.key
    )
  )

outputs

// I have a parent
newNode.parent
  && (
    (// Or I did but its different than the one I have now.
      (!originalNode.parent || newNode.parent.key !== originalNode.parent.key)
    )
  )

which is inconvenient for codemods. Live test: http://felix-kling.de/esprima_ast_explorer/#/NvtYJQH95L.

fkling commented 9 years ago

All the printing is done by recast. You should file an issue there.

Though for jscodeshift specifically, you can simply return nothing from the transformer. That tells the runner/worker that the file is not supposed to change (and of course it won't be overridden since there was no return value).

sophiebits commented 9 years ago

Okay, thanks: https://github.com/benjamn/recast/issues/215.