grasp icon indicating copy to clipboard operation
grasp copied to clipboard

getRaw returns extra characters if unicode

Open ainthek opened this issue 5 years ago • 1 comments

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 avatar May 20 '19 13:05 ainthek

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" } ],

ainthek avatar May 20 '19 14:05 ainthek