Skip to content

Commit 14caf23

Browse files
committed
Handle objects in action method.
1 parent 9ec98c2 commit 14caf23

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

django_unicorn/static/js/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export function args(func) {
132132
let inDoubleQuote = false;
133133
let parenthesisCount = 0;
134134
let bracketCount = 0;
135+
let curlyCount = 0;
135136

136137
for (let idx = 0; idx < func.length; idx++) {
137138
const c = func.charAt(idx);
@@ -145,6 +146,10 @@ export function args(func) {
145146
parenthesisCount++;
146147
} else if (c === ")") {
147148
parenthesisCount--;
149+
} else if (c === "{") {
150+
curlyCount++;
151+
} else if (c === "}") {
152+
curlyCount--;
148153
} else if (c === "'") {
149154
inSingleQuote = !inSingleQuote;
150155
} else if (c === "\"") {

tests/js/utils/args.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ test("two args with array", (t) => {
2424
t.is(functionArgs[1], "[1, 2]");
2525
});
2626

27+
test("two args with object", (t) => {
28+
const functionArgs = args("test($event.target.value, {\"1\": 2})");
29+
30+
t.is(functionArgs.length, 2);
31+
t.is(functionArgs[0], "$event.target.value");
32+
t.is(functionArgs[1], "{\"1\": 2}");
33+
});
34+
2735
test("two args with comma in double quotes", (t) => {
2836
const functionArgs = args("test($event.target.value, \"1,2\")");
2937

0 commit comments

Comments
 (0)