@@ -107,6 +107,24 @@ function removeByName(references: Reference[], name: string): void {
107107 }
108108}
109109
110+ /**
111+ * Throw syntax error for empty.
112+ * @param locationCalculator The location calculator to get line/column.
113+ */
114+ function throwEmptyError ( locationCalculator : LocationCalculator , expected : string ) : never {
115+ const loc = locationCalculator . getLocation ( 0 )
116+ const err = new ParseError (
117+ `Expected to be ${ expected } , but got empty.` ,
118+ undefined ,
119+ 0 ,
120+ loc . line ,
121+ loc . column
122+ )
123+ locationCalculator . fixErrorLocation ( err )
124+
125+ throw err
126+ }
127+
110128/**
111129 * Parse the given source code.
112130 *
@@ -218,6 +236,10 @@ export function parseScriptElement(node: VElement, globalLocationCalculator: Loc
218236export function parseExpression ( code : string , locationCalculator : LocationCalculator , parserOptions : any ) : ExpressionParseResult {
219237 debug ( "[script] parse expression: \"(%s)\"" , code )
220238
239+ if ( code . trim ( ) === "" ) {
240+ throwEmptyError ( locationCalculator , "an expression" )
241+ }
242+
221243 const ast = parseScriptFragment (
222244 `(${ code } )` ,
223245 locationCalculator . getSubCalculatorAfter ( - 1 ) ,
@@ -246,6 +268,10 @@ export function parseVForExpression(code: string, locationCalculator: LocationCa
246268 const processedCode = replaceAliasParens ( code )
247269 debug ( "[script] parse v-for expression: \"for(%s);\"" , processedCode )
248270
271+ if ( code . trim ( ) === "" ) {
272+ throwEmptyError ( locationCalculator , "'<alias> in <expression>'" )
273+ }
274+
249275 const replaced = processedCode !== code
250276 const ast = parseScriptFragment (
251277 `for(let ${ processedCode } );` ,
@@ -313,6 +339,10 @@ export function parseVForExpression(code: string, locationCalculator: LocationCa
313339export function parseVOnExpression ( code : string , locationCalculator : LocationCalculator , parserOptions : any ) : ExpressionParseResult {
314340 debug ( "[script] parse v-on expression: \"{%s}\"" , code )
315341
342+ if ( code . trim ( ) === "" ) {
343+ throwEmptyError ( locationCalculator , "statements" )
344+ }
345+
316346 const ast = parseScriptFragment (
317347 `{${ code } }` ,
318348 locationCalculator . getSubCalculatorAfter ( - 1 ) ,
0 commit comments