Port changes to the new template parser

This commit is contained in:
skirtle 2023-12-31 04:44:38 +00:00
parent d352a7a2bc
commit e986337287
2 changed files with 19 additions and 0 deletions

View File

@ -3925,6 +3925,7 @@ exports[`compiler: parse > Errors > X_COLON_BEFORE_DIRECTIVE > <div :v-foo="obj"
},
"modifiers": [],
"name": "bind",
"rawName": ":v-foo",
"type": 7,
},
],
@ -3952,6 +3953,7 @@ exports[`compiler: parse > Errors > X_COLON_BEFORE_DIRECTIVE > <div :v-foo="obj"
"offset": 0,
},
},
"source": "<div :v-foo="obj" />",
"temps": 0,
"type": 0,
}

View File

@ -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