shapesecurity / shift-parser-js

ECMAScript parser that produces a Shift format AST
http://shift-ast.org/parser.html
Apache License 2.0
251 stars 28 forks source link

Add String.raw values to LiteralStringExpression types using template tags #441

Closed ghost closed 4 years ago

ghost commented 4 years ago

If I run the following code:

let Shift = require('shift-ast/checked');

let src = `
0 + 1;
`;

let replaced = applyTemplate(src, {
  foo: node => new Shift.LiteralNumericExpression({ value: node.value + 1 }),
});

I receive the following error:

TypeError: Provided replacements for nodes named "foo", but no corresponding nodes were found.

Is there any way to apply template based on the node type of AST rather than the name? My use case is to get all LiteralNumericExpressions and make its value be node.value+1.

michaelficarra commented 4 years ago

You're looking for shift-reducer. We actually have your exact use case as one of the examples. Closing as this isn't the appropriate repo.