Skip to content

Commit 2c1a08e

Browse files
authored
fix(core-base): wrong list index resolving on jit optimization (#1571)
1 parent 1a919da commit 2c1a08e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/core-base/src/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function formatMessagePart<Message = string>(
8686
return ctx.interpolate(ctx.named(named.k || named.key))
8787
case NodeTypes.List:
8888
const list = node as ListNode
89-
return ctx.interpolate(ctx.list(list.i || list.index))
89+
return ctx.interpolate(ctx.list(list.i != null ? list.i : list.index))
9090
case NodeTypes.Linked:
9191
const linked = node as LinkedNode
9292
const modifier = linked.m || linked.modifier

packages/core-base/test/compilation.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ describe('compile', () => {
8888
})
8989
})
9090

91+
test('list issue', () => {
92+
const { ast } = baseCompile('hello {0}!', {
93+
location: false,
94+
jit: true,
95+
minify: true
96+
})
97+
const msg = compile(ast, DEFAULT_CONTEXT)
98+
const ctx = context({
99+
list: ['kazupon']
100+
})
101+
expect(msg(ctx)).toBe('hello kazupon!')
102+
})
103+
91104
test('error', () => {
92105
let occured = false
93106
compile('hello {name!', {

0 commit comments

Comments
 (0)