error if ref:foo has a value

pull/1245/head
Rich Harris 7 years ago
parent bd74929920
commit f97036dd39

@ -1,5 +1,6 @@
import { parseExpressionAt } from 'acorn'; import { parseExpressionAt } from 'acorn';
import repeat from '../../utils/repeat'; import repeat from '../../utils/repeat';
import list from '../../utils/list';
import { Parser } from '../index'; import { Parser } from '../index';
const DIRECTIVES = { const DIRECTIVES = {
@ -137,8 +138,12 @@ export function readDirective(
} }
expression = readExpression(parser, expressionStart, quoteMark); expression = readExpression(parser, expressionStart, quoteMark);
if (directive.allowedExpressionTypes) {
if (directive.allowedExpressionTypes.indexOf(expression.type) === -1) { if (directive.allowedExpressionTypes.indexOf(expression.type) === -1) {
parser.error(`Expected ${directive.allowedExpressionTypes.join(' or ')}`, expressionStart); parser.error(`Expected ${list(directive.allowedExpressionTypes)}`, expressionStart);
}
} else {
parser.error(`${directiveName} directives cannot have a value`, expressionStart);
} }
} }

@ -0,0 +1,8 @@
{
"message": "ref directives cannot have a value",
"loc": {
"line": 1,
"column": 14
},
"pos": 14
}
Loading…
Cancel
Save