Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Range for object literal shorthand methods doesn't include params #1029
Comments
Previously, the range and loc for get, set, and shorthand methods inside object literal properties included only the method body, meaning a method's parameters were outside the range of their parent `FunctionExpression` node. This was happening because the `FunctionExpression` node wasn't being created until `parsePropertyFunction` was called, by which point the method's parameters had already been parsed. This PR solves the issue by creating the `FunctionExpression` node as soon as it determines that the property is a get, set, or shorthand method, then passing the node into `parsePropertyFunction`. Closes jquery#1029
|
I took a look at property setter and it seems to have the same problem: #1040. |
Previously, the range and loc for get, set, and shorthand methods inside object literal properties included only the method body, meaning a method's parameters were outside the range of their parent `FunctionExpression` node. This was happening because the `FunctionExpression` node wasn't being created until `parsePropertyFunction` was called, by which point the method's parameters had already been parsed. This PR solves the issue by creating the `FunctionExpression` node as soon as it determines that the property is a get, set, or shorthand method, then passing the node into `parsePropertyFunction`. Closes jquery#1029 Closes jquery#1040
What steps will reproduce the problem?
On a fresh checkout of the harmony branch:
What is the expected output?
I would expect the FunctionExpression's range to include the method's parameters as well as the body as in
(arg1) {}.It makes sense that the method's name is not included, as that is the Property's key and does not belong to the FunctionExpression.
What do you see instead?
The FunctionExpression's range includes only the body,
{}, leading to a scenario in which a traversal starting at the FunctionExpression, range 21-23, would reach the parameter, whose range, 15-19, lies outside that of its parent.(Migrated from https://code.google.com/p/esprima/issues/detail?id=625, as reported by @btmills)