benjamn / recast

JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator
MIT License
4.91k stars 347 forks source link

`PrivateName` should be migrated to `PrivateIdentifier` #1395

Open btiernay opened 4 months ago

btiernay commented 4 months ago

Per the ESTree specification, PrivateName should should be PrivateIdentifier

image

This will ensure interoperability with other parsers such as esprima-next. Currently the following pre-walk of the raw AST is required:

            // We need to fix the AST to match the expected format of recast (i.e. ast-types)
            const vistitor = new class extends Visitor {
                visitPrivateIdentifier(node) {
                    node.type = 'PrivateName'
                    return super.visitPrivateIdentifier(node);
                }
            }

            vistitor.visit(ast);

See https://github.com/estree/estree/issues/240 for further details.