I write a javascript editor , and use syntax(view.state) to parse code await p( )
and replace with a decoration widget , but when I write code await \n p( )
to the editor , syntax(view.state) will get a wrong tree, “await \n” will be parsed to an ExpressionStatement , and “await” is a VariableName.
If I put await \n p( )
in an editor in JavaScript mode, the syntax tree I get does parse it as an AwaitExpression
.
I use the code from CodeMirror Decoration Example ,
copy the code from :
https://codemirror.net/examples/decoration/checkbox.js
syntaxTree() is import from :
const {syntaxTree} = CM["@codemirror/language"];
for (let {from, to} of view.visibleRanges) {
syntaxTree(view.state).iterate({
from, to,
enter: (node) => {
console.log(node.name);
}
})
}
How can I do to get the right node name AwaitExpression
for await \n p( )
?