gkz / grasp

JavaScript structural search, replace, and refactor
http://graspjs.com
MIT License
1.28k stars 33 forks source link

First level of quotes in replacements is ignored #5

Closed jakobwesthoff closed 10 years ago

jakobwesthoff commented 10 years ago

If the replacement feature is used and the replacement is surrounded by qoutes (single or double), those quotes are not used as part of the replacement, but are ignored.

Example

Take the following is the input file:

var foo = {
  a: "value A",
  "b": "value B",
  c: "value C"
}

grasp is supposed to be used to ensure every key in this code example is encapsulated in double quotes. The following command is therefore issued:

$ grasp 'prop[key!=String] > @key' example --replace '"{{}}"'

Problem the replacement is identical to the input, as the surrounding doubles quotes are ignored.

Doubling the quotes issues the correct result:

$ grasp 'prop[key!=String] > @key' example --replace '""{{}}""'
gkz commented 10 years ago

Thanks for the bug report. Turned out to be a bug with levn, and it is now fixed. Levn is used in optionator, which Grasp uses for option parsing, so I'll bump up all the versions before the next release so it is fixed.

gkz commented 10 years ago

Grasp 0.2.0 was released today http://graspjs.com/blog/2013/12/17/grasp-0.2.0-released/ which fixes this bug.

Also, the @prop syntax was removed. You can do the search you were doing previously simply as:

prop.key:not(String)