Skip to content

Commit e986337

Browse files
committed
Port changes to the new template parser
1 parent d352a7a commit e986337

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3925,6 +3925,7 @@ exports[`compiler: parse > Errors > X_COLON_BEFORE_DIRECTIVE > <div :v-foo="obj"
39253925
},
39263926
"modifiers": [],
39273927
"name": "bind",
3928+
"rawName": ":v-foo",
39283929
"type": 7,
39293930
},
39303931
],
@@ -3952,6 +3953,7 @@ exports[`compiler: parse > Errors > X_COLON_BEFORE_DIRECTIVE > <div :v-foo="obj"
39523953
"offset": 0,
39533954
},
39543955
},
3956+
"source": "<div :v-foo="obj" />",
39553957
"temps": 0,
39563958
"type": 0,
39573959
}

packages/compiler-core/src/parser.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ const tokenizer = new Tokenizer(stack, {
256256
getLoc(start, end),
257257
isStatic ? ConstantTypes.CAN_STRINGIFY : ConstantTypes.NOT_CONSTANT,
258258
)
259+
if (
260+
__DEV__ &&
261+
arg.startsWith('v-') &&
262+
(currentProp as DirectiveNode).rawName === ':'
263+
) {
264+
emitWarning(
265+
ErrorCodes.X_COLON_BEFORE_DIRECTIVE,
266+
start - 1,
267+
`the attribute name :${arg} is probably a mistake. Did you mean ${arg} instead?`,
268+
)
269+
}
259270
}
260271
},
261272

@@ -1007,6 +1018,12 @@ function emitError(code: ErrorCodes, index: number, message?: string) {
10071018
)
10081019
}
10091020

1021+
function emitWarning(code: ErrorCodes, index: number, message?: string) {
1022+
currentOptions.onWarn(
1023+
createCompilerError(code, getLoc(index, index), undefined, message),
1024+
)
1025+
}
1026+
10101027
function reset() {
10111028
tokenizer.reset()
10121029
currentOpenTag = null

0 commit comments

Comments
 (0)