Skip to content

Commit e2f904c

Browse files
committed
wip
1 parent 0a3130b commit e2f904c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -912,13 +912,25 @@ function transformTwig(ast: any, { env, changes }: TransformerContext) {
912912
},
913913

914914
CallExpression(node, _path, meta) {
915-
if (node.callee.type === 'MemberExpression') {
916-
if (!node.callee.property) return
917-
if (!functions.has(node.callee.property.name)) return
918-
} else if (node.callee.type === 'Identifier') {
919-
if (!functions.has(node.callee.name)) return
920-
} else {
921-
return
915+
// Traverse property accesses and function calls to find the *trailing* ident
916+
while (
917+
node.type === 'CallExpression' ||
918+
node.type === 'MemberExpression'
919+
) {
920+
if (node.type === 'CallExpression') {
921+
node = node.callee
922+
} else if (node.type === 'MemberExpression') {
923+
// TODO: This is *different* than `isSortableExpression` and that doesn't feel right
924+
// but they're mutually exclusive implementations
925+
//
926+
// This is to handle foo.fnNameHere(…) where `isSortableExpression` is intentionally
927+
// handling `fnNameHere.foo(…)`.
928+
node = node.property
929+
}
930+
}
931+
932+
if (node.type === 'Identifier') {
933+
if (!functions.has(node.name)) return
922934
}
923935

924936
meta.sortTextNodes = true

0 commit comments

Comments
 (0)