Last active
February 17, 2023 04:00
-
-
Save huacnlee/5be555d95d93068307e849d96a3ec525 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('parser') | |
input = "function foo() {}" | |
buf = Parser::Source::Buffer.new("test", 1, source: input) | |
tr = Parser::Source::TreeRewriter::new(buf) | |
def range(buf, start_pos, end_pos) | |
Parser::Source::Range::new(buf, start_pos, end_pos) | |
end | |
tr.insert_after(range(buf, 13, 13), "arg1") | |
tr.replace(range(buf, 1, 2), "12") | |
tr.replace(range(buf, 1, 2), "U") | |
tr.replace(range(buf, 2, 4), "34") | |
tr.remove(range(buf, 4, 5)); | |
out = tr.process | |
puts out.inspect | |
# out: "fU34ion foo(arg1) {}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment