Skip to content

Commit 8934933

Browse files
authored
fix(message-compiler): cannot resolve none-identifier characters at linked key (#1813)
* fix(message-compiler): cannot resolve none-identifier characters at linked key * fix: remove comment
1 parent a1d857e commit 8934933

File tree

6 files changed

+129
-71
lines changed

6 files changed

+129
-71
lines changed

packages/message-compiler/src/tokenizer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export function createTokenizer(
321321
return fn()
322322
} else {
323323
// other characters
324-
return isIdentifierStart(ch)
324+
return isTextStart(scnr, false)
325325
}
326326
}
327327

@@ -680,7 +680,7 @@ export function createTokenizer(
680680
}
681681

682682
function readLinkedRefer(scnr: Scanner): string {
683-
const fn = (detect = false, buf: string): string => {
683+
const fn = (buf: string): string => {
684684
const ch = scnr.currentChar()
685685
if (
686686
ch === TokenChars.BraceLeft ||
@@ -697,15 +697,15 @@ export function createTokenizer(
697697
} else if (ch === NEW_LINE || ch === DOT) {
698698
buf += ch
699699
scnr.next()
700-
return fn(detect, buf)
700+
return fn(buf)
701701
} else {
702702
buf += ch
703703
scnr.next()
704-
return fn(true, buf)
704+
return fn(buf)
705705
}
706706
}
707707

708-
return fn(false, '')
708+
return fn('')
709709
}
710710

711711
function readPlural(scnr: Scanner): string {

packages/message-compiler/test/__snapshots__/parser.test.ts.snap

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -525,28 +525,6 @@ exports[`parse > linked key paren error with modifier: "@.lower:(foo)" 1`] = `
525525
}
526526
`;
527527

528-
exports[`parse > linked key paren error with modifier: "@.lower:(foo)" errors 1`] = `
529-
[
530-
{
531-
"code": 13,
532-
"domain": "parser",
533-
"location": {
534-
"end": {
535-
"column": 14,
536-
"line": 1,
537-
"offset": 13,
538-
},
539-
"start": {
540-
"column": 8,
541-
"line": 1,
542-
"offset": 7,
543-
},
544-
},
545-
"message": "Unexpected empty linked key",
546-
},
547-
]
548-
`;
549-
550528
exports[`parse > linked key paren error: "@:(foo)" 1`] = `
551529
{
552530
"body": {
@@ -640,28 +618,6 @@ exports[`parse > linked key paren error: "@:(foo)" 1`] = `
640618
}
641619
`;
642620

643-
exports[`parse > linked key paren error: "@:(foo)" errors 1`] = `
644-
[
645-
{
646-
"code": 13,
647-
"domain": "parser",
648-
"location": {
649-
"end": {
650-
"column": 8,
651-
"line": 1,
652-
"offset": 7,
653-
},
654-
"start": {
655-
"column": 2,
656-
"line": 1,
657-
"offset": 1,
658-
},
659-
},
660-
"message": "Unexpected empty linked key",
661-
},
662-
]
663-
`;
664-
665621
exports[`parse > linked key with named and modifier: "hi @._upper:{_name} !" 1`] = `
666622
{
667623
"body": {
@@ -2024,16 +1980,6 @@ exports[`parser options > location disable > linked key paren error with modifie
20241980
}
20251981
`;
20261982

2027-
exports[`parser options > location disable > linked key paren error with modifier: "@.lower:(foo)" errors 1`] = `
2028-
[
2029-
{
2030-
"code": 13,
2031-
"domain": "parser",
2032-
"message": "Unexpected empty linked key",
2033-
},
2034-
]
2035-
`;
2036-
20371983
exports[`parser options > location disable > linked key paren error: "@:(foo)" 1`] = `
20381984
{
20391985
"body": {
@@ -2056,16 +2002,6 @@ exports[`parser options > location disable > linked key paren error: "@:(foo)" 1
20562002
}
20572003
`;
20582004

2059-
exports[`parser options > location disable > linked key paren error: "@:(foo)" errors 1`] = `
2060-
[
2061-
{
2062-
"code": 13,
2063-
"domain": "parser",
2064-
"message": "Unexpected empty linked key",
2065-
},
2066-
]
2067-
`;
2068-
20692005
exports[`parser options > location disable > linked key with named and modifier: "hi @._upper:{_name} !" 1`] = `
20702006
{
20712007
"body": {

packages/message-compiler/test/__snapshots__/tokenizer.test.ts.snap

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,6 +4370,90 @@ exports[`token analysis > "hi @:name !" tokens 1`] = `
43704370
]
43714371
`;
43724372
4373+
exports[`token analysis > "hi @:名前" tokens 1`] = `
4374+
[
4375+
{
4376+
"loc": {
4377+
"end": {
4378+
"column": 4,
4379+
"line": 1,
4380+
"offset": 3,
4381+
},
4382+
"start": {
4383+
"column": 1,
4384+
"line": 1,
4385+
"offset": 0,
4386+
},
4387+
},
4388+
"type": 0,
4389+
"value": "hi ",
4390+
},
4391+
{
4392+
"loc": {
4393+
"end": {
4394+
"column": 5,
4395+
"line": 1,
4396+
"offset": 4,
4397+
},
4398+
"start": {
4399+
"column": 4,
4400+
"line": 1,
4401+
"offset": 3,
4402+
},
4403+
},
4404+
"type": 8,
4405+
"value": "@",
4406+
},
4407+
{
4408+
"loc": {
4409+
"end": {
4410+
"column": 6,
4411+
"line": 1,
4412+
"offset": 5,
4413+
},
4414+
"start": {
4415+
"column": 5,
4416+
"line": 1,
4417+
"offset": 4,
4418+
},
4419+
},
4420+
"type": 10,
4421+
"value": ":",
4422+
},
4423+
{
4424+
"loc": {
4425+
"end": {
4426+
"column": 8,
4427+
"line": 1,
4428+
"offset": 7,
4429+
},
4430+
"start": {
4431+
"column": 6,
4432+
"line": 1,
4433+
"offset": 5,
4434+
},
4435+
},
4436+
"type": 11,
4437+
"value": "名前",
4438+
},
4439+
{
4440+
"loc": {
4441+
"end": {
4442+
"column": 8,
4443+
"line": 1,
4444+
"offset": 7,
4445+
},
4446+
"start": {
4447+
"column": 8,
4448+
"line": 1,
4449+
"offset": 7,
4450+
},
4451+
},
4452+
"type": 14,
4453+
},
4454+
]
4455+
`;
4456+
43734457
exports[`token analysis > "hi @\\n. upper\\n: {'name'}\\n !" errors 1`] = `
43744458
[
43754459
{
@@ -10520,6 +10604,30 @@ exports[`tokenize options: location disable > "hi @:name !" tokens 1`] = `
1052010604
]
1052110605
`;
1052210606
10607+
exports[`tokenize options: location disable > "hi @:名前" tokens 1`] = `
10608+
[
10609+
{
10610+
"type": 0,
10611+
"value": "hi ",
10612+
},
10613+
{
10614+
"type": 8,
10615+
"value": "@",
10616+
},
10617+
{
10618+
"type": 10,
10619+
"value": ":",
10620+
},
10621+
{
10622+
"type": 11,
10623+
"value": "名前",
10624+
},
10625+
{
10626+
"type": 14,
10627+
},
10628+
]
10629+
`;
10630+
1052310631
exports[`tokenize options: location disable > "hi @\\n. upper\\n: {'name'}\\n !" errors 1`] = `
1052410632
[
1052510633
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const CASES = [
8080
`hi @.upper\n{name} !`,
8181
`hi @.upper {name} !`,
8282
`hi @:\nname !`,
83+
`hi @:名前`,
8384
`hi @: {'name'} !`,
8485
`hi @\n. upper\n: {'name'}\n !`,
8586
` | | |`,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,3 +1437,16 @@ test('#1796', async () => {
14371437
})
14381438
).toEqual('My message with hello world.')
14391439
})
1440+
1441+
test('#1809', async () => {
1442+
const i18n = createI18n({
1443+
locale: 'en',
1444+
messages: {
1445+
en: {
1446+
hi: 'hi @:名前',
1447+
名前: 'kazupon'
1448+
}
1449+
}
1450+
})
1451+
expect(i18n.global.t('hi')).toEqual('hi kazupon')
1452+
})

spec/syntax.ebnf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(*
2-
* Inltify message syntax v0.3
2+
* Inltify message syntax v0.4.0
33
* (vue-i18n compatible)
44
*)
55
@@ -18,7 +18,7 @@ Named ::= Modulo? "{" Space? (NamedIdentifier) Space? "}";
1818
List ::= "{" Space? (NumberLiteral) Space? "}";
1919
Linked ::= "@" (LinkedModifier)? LinkedDelimiter LinkedRefer;
2020
LinkedRefer ::= LinkedKey | Placeholder;
21-
LinkedKey ::= Identifier;
21+
LinkedKey ::= Text;
2222
LinkedModifier ::= LinkedDot Identifier;
2323
LinkedDelimiter ::= ":";
2424
LinkedDot ::= ".";

0 commit comments

Comments
 (0)