Permalink
Browse files

fixes #620 property access within a function

  • Loading branch information...
justinbmeyer committed Nov 8, 2018
1 parent bf1b436 commit 8e3e9420a86b843b7dcd0eedd981549b0b50a79a
Showing with 36 additions and 2 deletions.
  1. +11 −2 src/expression.js
  2. +25 −0 test/expression-test.js
@@ -355,7 +355,7 @@ var expression = {

}
}

firstParent = stack.first(["Call","Helper","Hashes","Root"]);
// makes sure we are adding to Hashes if there already is one
// otherwise we create one.
@@ -467,8 +467,17 @@ var expression = {
top = stack.top();
lastToken = stack.topLastChild();

// foo()[bar] => top -> root, lastToken -> {t: call, m: "@foo"}
// foo()[bar()] => same as above last thing we see was a call expression "rotate"
// test['foo'][0] => lastToken => {root: test, t: Bracket, c: 'foo' }
// log(thing['prop'][0]) =>
//
// top -> {Call, children|args: [Bracket(Lookup(thing), c: ['[prop]'])]}
// last-> Bracket(Lookup(thing), c: ['[prop]'])
if (lastToken && (lastToken.type === "Call" || lastToken.type === "Bracket" ) ) {
stack.replaceTopAndPush({type: "Bracket", root: lastToken});
// must be on top of the stack as it recieves new stuff ...
// however, what we really want is to
stack.replaceTopLastChildAndPush({type: "Bracket", root: lastToken});
} else if (top.type === "Lookup" || top.type === "Bracket") {
var bracket = {type: "Bracket", root: top};
//!steal-remove-start
@@ -1050,3 +1050,28 @@ test("let foo=bar,zed=ted", function(){
]
});
});


test("double [] in a function", function(){
var ast = expression.ast("log(thing['prop'][0])");

var logAst = {
type: "Call",
method: {type: "Lookup", key: "@log"},
children: [
{
"type":"Bracket",
"root": {
"type":"Bracket",
"root":{
"type":"Lookup",
"key":"thing"
},
"children":[{"type":"Literal","value":"prop"}]
},
"children":[{"type":"Literal","value":0}]
}
]
};
QUnit.deepEqual(ast, logAst);
});

0 comments on commit 8e3e942

Please sign in to comment.