Skip to content

Commit 15f735d

Browse files
authored
fix: cannot resolve the ast messages which has json path for v9 (#2162)
* fix: cannot resolve the ast messages which has json path for v9 * fix: skip bridge tests, because vue2 and vue-18n v8 no longer support
1 parent 7faf924 commit 15f735d

23 files changed

+533
-167
lines changed

e2e/bridge/basic.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getText } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
3-
describe(`${pattern}`, () => {
3+
describe.skip(`${pattern}`, () => {
44
beforeAll(async () => {
55
await page.goto(
66
`http://localhost:8080/examples/bridge/${pattern}/basic.html`

e2e/bridge/component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getText } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
3-
describe(`${pattern}`, () => {
3+
describe.skip(`${pattern}`, () => {
44
beforeAll(async () => {
55
await page.goto(
66
`http://localhost:8080/examples/bridge/${pattern}/component.html`

e2e/bridge/components/datetime-format.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getText } from '../../helper'
2-
describe(`bridge: datetime format component`, () => {
2+
describe.skip(`bridge: datetime format component`, () => {
33
beforeAll(async () => {
44
await page.goto(
55
`http://localhost:8080/examples/bridge/composition/components/datetime-format.html`

e2e/bridge/components/number-format.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getText } from '../../helper'
2-
describe(`bridge: number format component`, () => {
2+
describe.skip(`bridge: number format component`, () => {
33
beforeAll(async () => {
44
await page.goto(
55
`http://localhost:8080/examples/bridge/composition/components/number-format.html`

e2e/bridge/components/translation.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getText } from '../../helper'
2-
describe(`bridge: translation component`, () => {
2+
describe.skip(`bridge: translation component`, () => {
33
beforeAll(async () => {
44
await page.goto(
55
`http://localhost:8080/examples/bridge/composition/components/translation.html`

e2e/bridge/plural.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getText } from '../helper'
22
;['composition', 'legacy'].forEach(pattern => {
3-
describe(`${pattern}`, () => {
3+
describe.skip(`${pattern}`, () => {
44
beforeAll(async () => {
55
await page.goto(
66
`http://localhost:8080/examples/bridge/${pattern}/plural.html`

e2e/bridge/scope/global.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getText } from '../../helper'
22
;['composition', 'legacy'].forEach(pattern => {
3-
describe(`${pattern}`, () => {
3+
describe.skip(`${pattern}`, () => {
44
beforeAll(async () => {
55
await page.goto(
66
`http://localhost:8080/examples/bridge/${pattern}/scope/global.html`

e2e/bridge/scope/inherit-locale.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getText } from '../../helper'
22
;['composition', 'legacy'].forEach(pattern => {
3-
describe(`${pattern}`, () => {
3+
describe.skip(`${pattern}`, () => {
44
beforeAll(async () => {
55
await page.goto(
66
`http://localhost:8080/examples/bridge/${pattern}/scope/inherit-locale.html`

e2e/bridge/scope/local.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getText } from '../../helper'
22
;['composition', 'legacy'].forEach(pattern => {
3-
describe(`${pattern}`, () => {
3+
describe.skip(`${pattern}`, () => {
44
beforeAll(async () => {
55
await page.goto(
66
`http://localhost:8080/examples/bridge/${pattern}/scope/local.html`

packages/core-base/src/ast.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { NodeTypes } from '@intlify/message-compiler'
2+
import { hasOwn, isObject } from '@intlify/shared'
3+
4+
import type {
5+
LinkedModifierNode,
6+
LinkedNode,
7+
MessageNode,
8+
Node,
9+
PluralNode,
10+
ResourceNode
11+
} from '@intlify/message-compiler'
12+
import type { MessageType } from './runtime'
13+
14+
export function isMessageAST(val: unknown): val is ResourceNode {
15+
return (
16+
isObject(val) &&
17+
resolveType(val as Node) === 0 &&
18+
(hasOwn(val, 'b') || hasOwn(val, 'body'))
19+
)
20+
}
21+
22+
const PROPS_BODY = ['b', 'body']
23+
24+
export function resolveBody(node: ResourceNode) {
25+
return resolveProps<MessageNode | PluralNode>(node, PROPS_BODY)
26+
}
27+
28+
const PROPS_CASES = ['c', 'cases']
29+
30+
export function resolveCases(node: PluralNode) {
31+
return resolveProps<PluralNode['cases'], PluralNode['cases']>(
32+
node,
33+
PROPS_CASES,
34+
[]
35+
)
36+
}
37+
38+
const PROPS_STATIC = ['s', 'static']
39+
40+
export function resolveStatic(node: MessageNode) {
41+
return resolveProps(node, PROPS_STATIC)
42+
}
43+
44+
const PROPS_ITEMS = ['i', 'items']
45+
46+
export function resolveItems(node: MessageNode) {
47+
return resolveProps<MessageNode['items'], MessageNode['items']>(
48+
node,
49+
PROPS_ITEMS,
50+
[]
51+
)
52+
}
53+
54+
const PROPS_TYPE = ['t', 'type']
55+
56+
export function resolveType(node: Node): ReturnType<typeof resolveProps> {
57+
return resolveProps<NodeTypes>(node, PROPS_TYPE)
58+
}
59+
60+
const PROPS_VALUE = ['v', 'value']
61+
62+
export function resolveValue<Message = string>(
63+
node: { v?: MessageType<Message>; value?: MessageType<Message> },
64+
type: NodeTypes
65+
): MessageType<Message> {
66+
const resolved = resolveProps<Message>(
67+
node as Node,
68+
PROPS_VALUE
69+
) as MessageType<Message>
70+
if (resolved != null) {
71+
return resolved
72+
} else {
73+
throw createUnhandleNodeError(type)
74+
}
75+
}
76+
77+
const PROPS_MODIFIER = ['m', 'modifier']
78+
79+
export function resolveLinkedModifier(node: LinkedNode) {
80+
return resolveProps<LinkedModifierNode>(node, PROPS_MODIFIER)
81+
}
82+
83+
const PROPS_KEY = ['k', 'key']
84+
85+
export function resolveLinkedKey(node: LinkedNode) {
86+
const resolved = resolveProps<LinkedNode['key']>(node, PROPS_KEY)
87+
if (resolved) {
88+
return resolved
89+
} else {
90+
throw createUnhandleNodeError(NodeTypes.Linked)
91+
}
92+
}
93+
94+
export function resolveProps<T = string, Default = undefined>(
95+
node: Node,
96+
props: string[],
97+
defaultValue?: Default
98+
): T | Default {
99+
for (let i = 0; i < props.length; i++) {
100+
const prop = props[i]
101+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
102+
if (hasOwn(node, prop) && (node as any)[prop] != null) {
103+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
104+
return (node as any)[prop] as T
105+
}
106+
}
107+
return defaultValue as Default
108+
}
109+
110+
export const AST_NODE_PROPS_KEYS = [
111+
...PROPS_BODY,
112+
...PROPS_CASES,
113+
...PROPS_STATIC,
114+
...PROPS_ITEMS,
115+
...PROPS_KEY,
116+
...PROPS_MODIFIER,
117+
...PROPS_VALUE,
118+
...PROPS_TYPE
119+
]
120+
121+
export function createUnhandleNodeError(type: NodeTypes) {
122+
return new Error(`unhandled node type: ${type}`)
123+
}

0 commit comments

Comments
 (0)