mirror of https://github.com/vuejs/core.git
Port changes to the new template parser
This commit is contained in:
parent
6014976d00
commit
63f96a2ace
|
@ -3905,10 +3905,9 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div #="
|
|||
"offset": 5,
|
||||
},
|
||||
},
|
||||
"modifiers": [
|
||||
"",
|
||||
],
|
||||
"modifiers": [],
|
||||
"name": "slot",
|
||||
"rawName": "#",
|
||||
"type": 7,
|
||||
},
|
||||
],
|
||||
|
@ -3936,6 +3935,7 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div #="
|
|||
"offset": 0,
|
||||
},
|
||||
},
|
||||
"source": "<div #="obj" />",
|
||||
"temps": 0,
|
||||
"type": 0,
|
||||
}
|
||||
|
@ -3999,10 +3999,10 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div .="
|
|||
},
|
||||
},
|
||||
"modifiers": [
|
||||
"",
|
||||
"prop",
|
||||
],
|
||||
"name": "bind",
|
||||
"rawName": ".",
|
||||
"type": 7,
|
||||
},
|
||||
],
|
||||
|
@ -4030,6 +4030,7 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div .="
|
|||
"offset": 0,
|
||||
},
|
||||
},
|
||||
"source": "<div .="obj" />",
|
||||
"temps": 0,
|
||||
"type": 0,
|
||||
}
|
||||
|
@ -4092,10 +4093,9 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div :="
|
|||
"offset": 5,
|
||||
},
|
||||
},
|
||||
"modifiers": [
|
||||
"",
|
||||
],
|
||||
"modifiers": [],
|
||||
"name": "bind",
|
||||
"rawName": ":",
|
||||
"type": 7,
|
||||
},
|
||||
],
|
||||
|
@ -4123,6 +4123,7 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div :="
|
|||
"offset": 0,
|
||||
},
|
||||
},
|
||||
"source": "<div :="obj" />",
|
||||
"temps": 0,
|
||||
"type": 0,
|
||||
}
|
||||
|
@ -4185,10 +4186,9 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div @="
|
|||
"offset": 5,
|
||||
},
|
||||
},
|
||||
"modifiers": [
|
||||
"",
|
||||
],
|
||||
"modifiers": [],
|
||||
"name": "on",
|
||||
"rawName": "@",
|
||||
"type": 7,
|
||||
},
|
||||
],
|
||||
|
@ -4216,6 +4216,7 @@ exports[`compiler: parse > Errors > X_DIRECTIVE_SHORTHAND_NO_ARGUMENT > <div @="
|
|||
"offset": 0,
|
||||
},
|
||||
},
|
||||
"source": "<div @="obj" />",
|
||||
"temps": 0,
|
||||
"type": 0,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue