Wow, cool, thanks Yusuke! I was afraid that it take a lot of time to examine code and extend it properly, so simple!
It works :)
var parse = require('esprima').parse;
ast = parse('list.empty?()')
console.log(JSON.stringify(ast, null, 2))
Output
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"computed": false,
"object": {
"type": "Identifier",
"name": "list"
},
"property": {
"type": "Identifier",
"name": "empty?" <======== :)
}
},
"arguments": []
}
}
]
}
P.S. would be also nice if ESPrima expose its internals, like `isIdentifierPart` - then such extension would be as simple as:
esprima.isIdentifierPartWithoutSpecialSymbols = esprima.isIdentifierPart
esprima.isIdentifierPart = function(ch){
return this.isIdentifierPartWithoutSpecialSymbols(ch) ||
(ch === '-') || (ch === '?') || (ch === '!');
}
Right now its closed in lexical scope and not available for extension.