",
"temps": 0,
"type": 0,
}
@@ -4185,10 +4186,9 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT >
Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT >
",
"temps": 0,
"type": 0,
}
diff --git a/packages/compiler-core/__tests__/parse.spec.ts b/packages/compiler-core/__tests__/parse.spec.ts
index 6fc30821b..986326185 100644
--- a/packages/compiler-core/__tests__/parse.spec.ts
+++ b/packages/compiler-core/__tests__/parse.spec.ts
@@ -2063,6 +2063,9 @@ describe('compiler: parse', () => {
exp: undefined,
arg: undefined,
})
+ expect(
+ `the directive shorthand '#' cannot be used without an argument`,
+ ).toHaveBeenWarned()
})
// edge case found in vue-macros where the input is TS or JSX
diff --git a/packages/compiler-core/src/parser.ts b/packages/compiler-core/src/parser.ts
index e73bffdeb..468e39742 100644
--- a/packages/compiler-core/src/parser.ts
+++ b/packages/compiler-core/src/parser.ts
@@ -243,7 +243,21 @@ const tokenizer = new Tokenizer(stack, {
},
ondirarg(start, end) {
- if (start === end) return
+ if (start === end) {
+ if (__DEV__) {
+ const currentDir = currentProp as DirectiveNode
+
+ if (currentDir.rawName?.length === 1) {
+ emitWarning(
+ ErrorCodes.X_DIRECTIVE_SHORTHAND_NO_ARGUMENT,
+ start - 1,
+ `the directive shorthand '${currentDir.rawName}' cannot be used without an argument. ` +
+ `Use v-${currentDir.name} instead or provide an argument.`,
+ )
+ }
+ }
+ return
+ }
const arg = getSlice(start, end)
if (inVPre) {
;(currentProp as AttributeNode).name += arg
@@ -1007,6 +1021,12 @@ function emitError(code: ErrorCodes, index: number, message?: string) {
)
}
+function emitWarning(code: ErrorCodes, index: number, message?: string) {
+ currentOptions.onWarn(
+ createCompilerError(code, getLoc(index, index), undefined, message),
+ )
+}
+
function reset() {
tokenizer.reset()
currentOpenTag = null