Skip to content

Commit

Permalink
fix: member expression to reprocess computer properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Harminder Virk authored and Harminder Virk committed Mar 18, 2024
1 parent d90cec7 commit 527cb40
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { processCLIArgs, configure, run } from '@japa/runner'
processCLIArgs(process.argv.slice(2))
configure({
...{
files: ['test/**/*.spec.ts'],
files: ['tests/**/*.spec.ts'],
plugins: [assert()],
},
})
Expand Down
1 change: 1 addition & 0 deletions fixtures/identifier-w-member-expression/index.edge
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The type is {{ types[type] }}
10 changes: 10 additions & 0 deletions fixtures/identifier-w-member-expression/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let out = "";
let $lineNumber = 1;
let $filename = "{{ __dirname }}index.edge";
try {
out += "The type is ";
out += `${ctx.escape(state.types[state.type])}`;
} catch (error) {
ctx.reThrow(error, $filename, $lineNumber);
}
return out;
3 changes: 2 additions & 1 deletion src/expressions/member_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export default {
/**
* Making the following expressions work
*
* types[type]
* user[Object.keys(user).find((k) => k === 'id')]
* [num1, num2, num3].filter((num) => num % 2 === 0)
*/
if (statement.property.type !== 'Identifier') {
if (statement.computed || statement.property.type !== 'Identifier') {
statement.property = transformAst(statement.property, filename, parser)
}
return statement
Expand Down

0 comments on commit 527cb40

Please sign in to comment.