From e986337287bf64594d238186ca23eda6aa72a0a8 Mon Sep 17 00:00:00 2001
From: skirtle <65301168+skirtles-code@users.noreply.github.com>
Date: Sun, 31 Dec 2023 04:44:38 +0000
Subject: [PATCH] Port changes to the new template parser
---
.../__tests__/__snapshots__/parse.spec.ts.snap | 2 ++
packages/compiler-core/src/parser.ts | 17 +++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap
index 8c9d875c4..fd2bfd2f8 100644
--- a/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap
+++ b/packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap
@@ -3925,6 +3925,7 @@ exports[`compiler: parse > Errors > X_COLON_BEFORE_DIRECTIVE >
Errors > X_COLON_BEFORE_DIRECTIVE >
",
"temps": 0,
"type": 0,
}
diff --git a/packages/compiler-core/src/parser.ts b/packages/compiler-core/src/parser.ts
index e73bffdeb..0750a1858 100644
--- a/packages/compiler-core/src/parser.ts
+++ b/packages/compiler-core/src/parser.ts
@@ -256,6 +256,17 @@ const tokenizer = new Tokenizer(stack, {
getLoc(start, end),
isStatic ? ConstantTypes.CAN_STRINGIFY : ConstantTypes.NOT_CONSTANT,
)
+ if (
+ __DEV__ &&
+ arg.startsWith('v-') &&
+ (currentProp as DirectiveNode).rawName === ':'
+ ) {
+ emitWarning(
+ ErrorCodes.X_COLON_BEFORE_DIRECTIVE,
+ start - 1,
+ `the attribute name :${arg} is probably a mistake. Did you mean ${arg} instead?`,
+ )
+ }
}
},
@@ -1007,6 +1018,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