Skip to content

Commit 272555e

Browse files
authored
fix: cannot resolve linked refer message (#1549)
* docs: add build.transpile option resolve #1546 * fix: cannot resolve linked refer message
1 parent 4da7270 commit 272555e

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

packages/message-compiler/src/tokenizer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const enum TokenChars {
2828
Pipe = '|',
2929
BraceLeft = '{',
3030
BraceRight = '}',
31+
ParenLeft = '(',
32+
ParenRight = ')',
3133
Modulo = '%',
3234
LinkedAlias = '@',
3335
LinkedDot = '.',
@@ -655,6 +657,8 @@ export function createTokenizer(
655657
ch === TokenChars.Modulo ||
656658
ch === TokenChars.LinkedAlias ||
657659
ch === TokenChars.Pipe ||
660+
ch === TokenChars.ParenLeft ||
661+
ch === TokenChars.ParenRight ||
658662
!ch
659663
) {
660664
return buf
@@ -664,8 +668,6 @@ export function createTokenizer(
664668
buf += ch
665669
scnr.next()
666670
return fn(detect, buf)
667-
} else if (!isIdentifierStart(ch)) {
668-
return buf
669671
} else {
670672
buf += ch
671673
scnr.next()

packages/message-compiler/test/tokenizer/linked.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,3 +921,38 @@ describe('errors', () => {
921921
] as CompileError[])
922922
})
923923
})
924+
925+
test('issue #1547', () => {
926+
const tokenizer = createTokenizer('@:product.tc.howToUse.content1')
927+
expect(tokenizer.nextToken()).toEqual({
928+
type: TokenTypes.LinkedAlias,
929+
value: '@',
930+
loc: {
931+
start: { line: 1, column: 1, offset: 0 },
932+
end: { line: 1, column: 2, offset: 1 }
933+
}
934+
})
935+
expect(tokenizer.nextToken()).toEqual({
936+
type: TokenTypes.LinkedDelimiter,
937+
value: ':',
938+
loc: {
939+
start: { line: 1, column: 2, offset: 1 },
940+
end: { line: 1, column: 3, offset: 2 }
941+
}
942+
})
943+
expect(tokenizer.nextToken()).toEqual({
944+
type: TokenTypes.LinkedKey,
945+
value: 'product.tc.howToUse.content1',
946+
loc: {
947+
start: { line: 1, column: 3, offset: 2 },
948+
end: { line: 1, column: 31, offset: 30 }
949+
}
950+
})
951+
expect(tokenizer.nextToken()).toEqual({
952+
type: TokenTypes.EOF,
953+
loc: {
954+
start: { line: 1, column: 31, offset: 30 },
955+
end: { line: 1, column: 31, offset: 30 }
956+
}
957+
})
958+
})

packages/vue-i18n-core/test/issues.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,3 +986,38 @@ test('issue #1392', async () => {
986986

987987
expect(wrapper.html()).toEqual(`<div> component: works<br> t: works</div>`)
988988
})
989+
990+
test('issue #1547', async () => {
991+
const i18n = createI18n({
992+
legacy: false,
993+
locale: 'en',
994+
fallbackLocale: 'en',
995+
messages: {
996+
en: {
997+
product: {
998+
tc: {
999+
howToUse: {
1000+
content1: 'Deep Linked message'
1001+
},
1002+
usage: {
1003+
content2: {
1004+
content: '@:product.tc.howToUse.content1'
1005+
}
1006+
}
1007+
}
1008+
}
1009+
}
1010+
}
1011+
})
1012+
1013+
const App = defineComponent({
1014+
setup() {
1015+
const { t } = useI18n()
1016+
return { t }
1017+
},
1018+
template: `<div>{{ t('product.tc.usage.content2.content') }}</div>`
1019+
})
1020+
const wrapper = await mount(App, i18n)
1021+
1022+
expect(wrapper.html()).toEqual('<div>Deep Linked message</div>')
1023+
})

0 commit comments

Comments
 (0)