ReWriteVisitor malforms code for argument nodes and symbols
castwide opened this issue · comments
Fred Snyder commented
When I pass a node two ReWriteVisior.createCodeFromNode, block arguments do not have separators and symbols do not have colons.
Sample Java code:
Parser rubyParser = new Parser();
String source = "method do |one, two|\n {\n :foo => bar,\n :baz => bot\n }\nend\n";
StringReader in = new StringReader(source);
CompatVersion version = CompatVersion.RUBY1_9;
ParserConfiguration config = new ParserConfiguration(0, version);
Node node = rubyParser.parse("<code>", in, config);
String dummy = "";
String result = ReWriteVisitor.createCodeFromNode(node, dummy);
System.out.println(result);
Expected output:
method() do |one, two|
{:foo => bar, :baz => bot}
end
Actual output:
method() do |onetwo|
{foo => bar, baz => bot}
end
I submitted a pull request that fixes both issues.
Thomas E Enebo commented
Beyond merging your PR I also changed SymbolNode to return :name for getLexical name and added some specs in d796b3e. Thanks for the fix. I thnk at some point we need to modify the AST so that:
{foo: :bar}
knows enough to differeniate and re-write differently than:
{:foo => :bar}
but emitting valid Ruby is good enough for now :)