Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRaw returns extra characters if unicode #130

Open
ainthek opened this issue May 20, 2019 · 1 comment
Open

getRaw returns extra characters if unicode #130

ainthek opened this issue May 20, 2019 · 1 comment

Comments

@ainthek
Copy link

ainthek commented May 20, 2019

when grasp is using flow parser , the AST returns ranges and getRaw returns incorrect match.
See test case. This is eather bug in flow-parser or bad interpretation of range in grasp implementation of getRaw. Any hints ? Thanx

const grasp = require("grasp");
var raw;
var replacer = grasp.replace('equery', 'var INPUT=$x;', function(getRaw, node, query, named) {
raw = getRaw(node);
return "";
});
replacer("var INPUT={test:'aa'};var UNEXPECTED;");
console.assert(raw==="var INPUT={test:'aa'};");

replacer("var INPUT={test:'až'};var UNEXPECTED;");
console.log(raw); //contains extra char, range from AST is wrong
console.assert(raw==="var INPUT={test:'až'};"); //FAILS

@ainthek
Copy link
Author

ainthek commented May 20, 2019

Just a note: On the other hand, it seems that -o option works , because formatResult function does not work with node.range but works with node.loc.

Please can you explain also parser options range:true and false ? I tried to switch it to false for flow-parser but it seems to have no effect and node.rage is still calculated (and incorrectly) interpreted in replaceFunction (getRaw)

parser: ['flow-parser',
{ loc: true, sourceType: 'module', range: "false" }
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant