Skip to content

Commit 19c65a6

Browse files
znckyyx990803
authored andcommitted
refactor(compiler-core): use directive name in error code identifier (vuejs#163)
1 parent 723dc87 commit 19c65a6

File tree

10 files changed

+52
-49
lines changed

10 files changed

+52
-49
lines changed

packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ describe('compiler: transform <slot> outlets', () => {
317317
parseWithSlots(source, { onError })
318318
const index = source.indexOf('v-foo')
319319
expect(onError.mock.calls[0][0]).toMatchObject({
320-
code: ErrorCodes.X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
320+
code: ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
321321
loc: {
322322
source: `v-foo`,
323323
start: {

packages/compiler-core/__tests__/transforms/vFor.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ describe('compiler: v-for', () => {
219219
expect(onError).toHaveBeenCalledTimes(1)
220220
expect(onError).toHaveBeenCalledWith(
221221
expect.objectContaining({
222-
code: ErrorCodes.X_FOR_NO_EXPRESSION
222+
code: ErrorCodes.X_V_FOR_NO_EXPRESSION
223223
})
224224
)
225225
})
@@ -231,7 +231,7 @@ describe('compiler: v-for', () => {
231231
expect(onError).toHaveBeenCalledTimes(1)
232232
expect(onError).toHaveBeenCalledWith(
233233
expect.objectContaining({
234-
code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
234+
code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
235235
})
236236
)
237237
})
@@ -243,7 +243,7 @@ describe('compiler: v-for', () => {
243243
expect(onError).toHaveBeenCalledTimes(1)
244244
expect(onError).toHaveBeenCalledWith(
245245
expect.objectContaining({
246-
code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
246+
code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
247247
})
248248
)
249249
})
@@ -255,7 +255,7 @@ describe('compiler: v-for', () => {
255255
expect(onError).toHaveBeenCalledTimes(1)
256256
expect(onError).toHaveBeenCalledWith(
257257
expect.objectContaining({
258-
code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
258+
code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
259259
})
260260
)
261261
})
@@ -267,7 +267,7 @@ describe('compiler: v-for', () => {
267267
expect(onError).toHaveBeenCalledTimes(1)
268268
expect(onError).toHaveBeenCalledWith(
269269
expect.objectContaining({
270-
code: ErrorCodes.X_FOR_MALFORMED_EXPRESSION
270+
code: ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION
271271
})
272272
)
273273
})

packages/compiler-core/__tests__/transforms/vIf.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('compiler: v-if', () => {
195195
const { node: node1 } = parseWithIfTransform(`<div v-else/>`, { onError })
196196
expect(onError.mock.calls[0]).toMatchObject([
197197
{
198-
code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
198+
code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
199199
loc: node1.loc
200200
}
201201
])
@@ -207,7 +207,7 @@ describe('compiler: v-if', () => {
207207
)
208208
expect(onError.mock.calls[1]).toMatchObject([
209209
{
210-
code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
210+
code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
211211
loc: node2.loc
212212
}
213213
])
@@ -219,7 +219,7 @@ describe('compiler: v-if', () => {
219219
)
220220
expect(onError.mock.calls[2]).toMatchObject([
221221
{
222-
code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
222+
code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
223223
loc: node3.loc
224224
}
225225
])
@@ -233,7 +233,7 @@ describe('compiler: v-if', () => {
233233
})
234234
expect(onError.mock.calls[0]).toMatchObject([
235235
{
236-
code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
236+
code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
237237
loc: node1.loc
238238
}
239239
])
@@ -245,7 +245,7 @@ describe('compiler: v-if', () => {
245245
)
246246
expect(onError.mock.calls[1]).toMatchObject([
247247
{
248-
code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
248+
code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
249249
loc: node2.loc
250250
}
251251
])
@@ -257,7 +257,7 @@ describe('compiler: v-if', () => {
257257
)
258258
expect(onError.mock.calls[2]).toMatchObject([
259259
{
260-
code: ErrorCodes.X_ELSE_NO_ADJACENT_IF,
260+
code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
261261
loc: node3.loc
262262
}
263263
])

packages/compiler-core/__tests__/transforms/vSlot.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ describe('compiler: transform component slots', () => {
556556
parseWithSlots(source, { onError })
557557
const index = source.indexOf('bar')
558558
expect(onError.mock.calls[0][0]).toMatchObject({
559-
code: ErrorCodes.X_EXTRANEOUS_NON_SLOT_CHILDREN,
559+
code: ErrorCodes.X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN,
560560
loc: {
561561
source: `bar`,
562562
start: {
@@ -579,7 +579,7 @@ describe('compiler: transform component slots', () => {
579579
parseWithSlots(source, { onError })
580580
const index = source.lastIndexOf('#foo')
581581
expect(onError.mock.calls[0][0]).toMatchObject({
582-
code: ErrorCodes.X_DUPLICATE_SLOT_NAMES,
582+
code: ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES,
583583
loc: {
584584
source: `#foo`,
585585
start: {
@@ -602,7 +602,7 @@ describe('compiler: transform component slots', () => {
602602
parseWithSlots(source, { onError })
603603
const index = source.lastIndexOf('#foo')
604604
expect(onError.mock.calls[0][0]).toMatchObject({
605-
code: ErrorCodes.X_MIXED_SLOT_USAGE,
605+
code: ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE,
606606
loc: {
607607
source: `#foo`,
608608
start: {
@@ -625,7 +625,7 @@ describe('compiler: transform component slots', () => {
625625
parseWithSlots(source, { onError })
626626
const index = source.indexOf('v-slot')
627627
expect(onError.mock.calls[0][0]).toMatchObject({
628-
code: ErrorCodes.X_MISPLACED_V_SLOT,
628+
code: ErrorCodes.X_V_SLOT_MISPLACED,
629629
loc: {
630630
source: `v-slot`,
631631
start: {
@@ -648,7 +648,7 @@ describe('compiler: transform component slots', () => {
648648
parseWithSlots(source, { onError })
649649
const index = source.indexOf('v-slot')
650650
expect(onError.mock.calls[0][0]).toMatchObject({
651-
code: ErrorCodes.X_NAMED_SLOT_ON_COMPONENT,
651+
code: ErrorCodes.X_V_SLOT_NAMED_SLOT_ON_COMPONENT,
652652
loc: {
653653
source: `v-slot:foo`,
654654
start: {

packages/compiler-core/src/errors.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ export const enum ErrorCodes {
6262
X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END,
6363

6464
// transform errors
65-
X_IF_NO_EXPRESSION,
66-
X_ELSE_NO_ADJACENT_IF,
67-
X_FOR_NO_EXPRESSION,
68-
X_FOR_MALFORMED_EXPRESSION,
65+
X_V_IF_NO_EXPRESSION,
66+
X_V_ELSE_NO_ADJACENT_IF,
67+
X_V_FOR_NO_EXPRESSION,
68+
X_V_FOR_MALFORMED_EXPRESSION,
6969
X_V_BIND_NO_EXPRESSION,
7070
X_V_ON_NO_EXPRESSION,
7171
X_V_HTML_NO_EXPRESSION,
7272
X_V_HTML_WITH_CHILDREN,
73-
X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
74-
X_NAMED_SLOT_ON_COMPONENT,
75-
X_MIXED_SLOT_USAGE,
76-
X_DUPLICATE_SLOT_NAMES,
77-
X_EXTRANEOUS_NON_SLOT_CHILDREN,
78-
X_MISPLACED_V_SLOT,
73+
X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
74+
X_V_SLOT_NAMED_SLOT_ON_COMPONENT,
75+
X_V_SLOT_MIXED_SLOT_USAGE,
76+
X_V_SLOT_DUPLICATE_SLOT_NAMES,
77+
X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN,
78+
X_V_SLOT_MISPLACED,
7979

8080
// generic errors
8181
X_PREFIX_ID_NOT_SUPPORTED,
@@ -140,27 +140,27 @@ export const errorMessages: { [code: number]: string } = {
140140
'Note that dynamic directive argument cannot contain spaces.',
141141

142142
// transform errors
143-
[ErrorCodes.X_IF_NO_EXPRESSION]: `v-if/v-else-if is missing expression.`,
144-
[ErrorCodes.X_ELSE_NO_ADJACENT_IF]: `v-else/v-else-if has no adjacent v-if.`,
145-
[ErrorCodes.X_FOR_NO_EXPRESSION]: `v-for is missing expression.`,
146-
[ErrorCodes.X_FOR_MALFORMED_EXPRESSION]: `v-for has invalid expression.`,
143+
[ErrorCodes.X_V_IF_NO_EXPRESSION]: `v-if/v-else-if is missing expression.`,
144+
[ErrorCodes.X_V_ELSE_NO_ADJACENT_IF]: `v-else/v-else-if has no adjacent v-if.`,
145+
[ErrorCodes.X_V_FOR_NO_EXPRESSION]: `v-for is missing expression.`,
146+
[ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION]: `v-for has invalid expression.`,
147147
[ErrorCodes.X_V_BIND_NO_EXPRESSION]: `v-bind is missing expression.`,
148148
[ErrorCodes.X_V_ON_NO_EXPRESSION]: `v-on is missing expression.`,
149149
[ErrorCodes.X_V_HTML_NO_EXPRESSION]: `v-html is missing epxression.`,
150150
[ErrorCodes.X_V_HTML_WITH_CHILDREN]: `v-html will override element children.`,
151-
[ErrorCodes.X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET]: `Unexpected custom directive on <slot> outlet.`,
152-
[ErrorCodes.X_NAMED_SLOT_ON_COMPONENT]:
151+
[ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET]: `Unexpected custom directive on <slot> outlet.`,
152+
[ErrorCodes.X_V_SLOT_NAMED_SLOT_ON_COMPONENT]:
153153
`Named v-slot on component. ` +
154154
`Named slots should use <template v-slot> syntax nested inside the component.`,
155-
[ErrorCodes.X_MIXED_SLOT_USAGE]:
155+
[ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE]:
156156
`Mixed v-slot usage on both the component and nested <template>.` +
157157
`The default slot should also use <template> syntax when there are other ` +
158158
`named slots to avoid scope ambiguity.`,
159-
[ErrorCodes.X_DUPLICATE_SLOT_NAMES]: `Duplicate slot names found. `,
160-
[ErrorCodes.X_EXTRANEOUS_NON_SLOT_CHILDREN]:
159+
[ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES]: `Duplicate slot names found. `,
160+
[ErrorCodes.X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN]:
161161
`Extraneous children found when component has explicit slots. ` +
162162
`These children will be ignored.`,
163-
[ErrorCodes.X_MISPLACED_V_SLOT]: `v-slot can only be used on components or <template> tags.`,
163+
[ErrorCodes.X_V_SLOT_MISPLACED]: `v-slot can only be used on components or <template> tags.`,
164164

165165
// generic errors
166166
[ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler.`,

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export function buildProps(
228228
if (name === 'slot') {
229229
if (!isComponent) {
230230
context.onError(
231-
createCompilerError(ErrorCodes.X_MISPLACED_V_SLOT, loc)
231+
createCompilerError(ErrorCodes.X_V_SLOT_MISPLACED, loc)
232232
)
233233
}
234234
continue

packages/compiler-core/src/transforms/transformSlotOutlet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
5959
if (directives.length) {
6060
context.onError(
6161
createCompilerError(
62-
ErrorCodes.X_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
62+
ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
6363
directives[0].loc
6464
)
6565
)

packages/compiler-core/src/transforms/vFor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ export const transformFor = createStructuralDirectiveTransform(
159159
}
160160
} else {
161161
context.onError(
162-
createCompilerError(ErrorCodes.X_FOR_MALFORMED_EXPRESSION, dir.loc)
162+
createCompilerError(ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, dir.loc)
163163
)
164164
}
165165
} else {
166166
context.onError(
167-
createCompilerError(ErrorCodes.X_FOR_NO_EXPRESSION, dir.loc)
167+
createCompilerError(ErrorCodes.X_V_FOR_NO_EXPRESSION, dir.loc)
168168
)
169169
}
170170
}

packages/compiler-core/src/transforms/vIf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const transformIf = createStructuralDirectiveTransform(
4646
) {
4747
const loc = dir.exp ? dir.exp.loc : node.loc
4848
context.onError(
49-
createCompilerError(ErrorCodes.X_IF_NO_EXPRESSION, dir.loc)
49+
createCompilerError(ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc)
5050
)
5151
dir.exp = createSimpleExpression(`true`, false, loc)
5252
}
@@ -125,7 +125,7 @@ export const transformIf = createStructuralDirectiveTransform(
125125
}
126126
} else {
127127
context.onError(
128-
createCompilerError(ErrorCodes.X_ELSE_NO_ADJACENT_IF, node.loc)
128+
createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, node.loc)
129129
)
130130
}
131131
break

packages/compiler-core/src/transforms/vSlot.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function buildSlots(
119119
const { arg, exp, loc } = explicitDefaultSlot
120120
if (arg) {
121121
context.onError(
122-
createCompilerError(ErrorCodes.X_NAMED_SLOT_ON_COMPONENT, loc)
122+
createCompilerError(ErrorCodes.X_V_SLOT_NAMED_SLOT_ON_COMPONENT, loc)
123123
)
124124
}
125125
slotsProperties.push(buildDefaultSlot(exp, children, loc))
@@ -148,7 +148,7 @@ export function buildSlots(
148148
if (explicitDefaultSlot) {
149149
// already has on-component default slot - this is incorrect usage.
150150
context.onError(
151-
createCompilerError(ErrorCodes.X_MIXED_SLOT_USAGE, slotDir.loc)
151+
createCompilerError(ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, slotDir.loc)
152152
)
153153
break
154154
}
@@ -224,7 +224,7 @@ export function buildSlots(
224224
: buildDynamicSlot(slotName, slotFunction)
225225
} else {
226226
context.onError(
227-
createCompilerError(ErrorCodes.X_ELSE_NO_ADJACENT_IF, vElse.loc)
227+
createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, vElse.loc)
228228
)
229229
}
230230
} else if ((vFor = findDir(slotElement, 'for'))) {
@@ -247,15 +247,18 @@ export function buildSlots(
247247
)
248248
} else {
249249
context.onError(
250-
createCompilerError(ErrorCodes.X_FOR_MALFORMED_EXPRESSION, vFor.loc)
250+
createCompilerError(ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, vFor.loc)
251251
)
252252
}
253253
} else {
254254
// check duplicate static names
255255
if (staticSlotName) {
256256
if (seenSlotNames.has(staticSlotName)) {
257257
context.onError(
258-
createCompilerError(ErrorCodes.X_DUPLICATE_SLOT_NAMES, dirLoc)
258+
createCompilerError(
259+
ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES,
260+
dirLoc
261+
)
259262
)
260263
continue
261264
}
@@ -268,7 +271,7 @@ export function buildSlots(
268271
if (hasTemplateSlots && extraneousChild) {
269272
context.onError(
270273
createCompilerError(
271-
ErrorCodes.X_EXTRANEOUS_NON_SLOT_CHILDREN,
274+
ErrorCodes.X_V_SLOT_EXTRANEOUS_NON_SLOT_CHILDREN,
272275
extraneousChild.loc
273276
)
274277
)

0 commit comments

Comments
 (0)