Open nashid opened 2 years ago
That's because it's a WeakMap. That's how WeakMaps work. What are you expecting?
I need to serialize the location information. For each AST node, I need to determine the start and end line number.
You can just stick the location information on the nodes, if you want:
let { tree, locations } = parseScriptWithLocation(`whatever`);
function addLocationInformation(node) {
node.loc = locations.get(node);
for (let field of Object.values(node)) {
if (Array.isArray(field)) {
field.forEach(addLocationInformation);
} else if (typeof field === 'object' && field !== null) {
addLocationInformation(field);
}
}
}
addLocationInformation(tree);
console.log(JSON.stringify(tree));
Should show line number information.
Test case:
Output = {}
Expected: Can show locations Actual: Shows empty array
{}