gkz / grasp

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

Major refactor for more powerful lib append #113

Open kristianmandrup opened 7 years ago

kristianmandrup commented 7 years ago

Currently working on a major refactoring to allow for:

    test 'with named append' ->
      const find = """
        class[key=#Hello] body[type=#ClassBody]
      """

      const replace = """
        {{ .body | append:fn }}
      """

      const code = '''class Hello {
      }'''

      const replacer = grasp.replace 'squery', {find, replace }
      const result = replacer.replace(code, [{
        action: 'append',
        name: 'fn',
        node: {
          type: 'Raw',
          raw: 'hello () { }'
        }
      }])
      const expected = """class Hello {
        hello () { }
      }"""

      equal (result, expected)