From f97036dd391bb49bd3f5570fad40adfe1b913279 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 15 Mar 2018 14:49:37 -0400 Subject: [PATCH] error if ref:foo has a value --- src/parse/read/directives.ts | 9 +++++++-- test/parser/samples/error-ref-value/error.json | 8 ++++++++ test/parser/samples/error-ref-value/input.html | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/parser/samples/error-ref-value/error.json create mode 100644 test/parser/samples/error-ref-value/input.html diff --git a/src/parse/read/directives.ts b/src/parse/read/directives.ts index f197c8aac9..4c8bcd3ea7 100644 --- a/src/parse/read/directives.ts +++ b/src/parse/read/directives.ts @@ -1,5 +1,6 @@ import { parseExpressionAt } from 'acorn'; import repeat from '../../utils/repeat'; +import list from '../../utils/list'; import { Parser } from '../index'; const DIRECTIVES = { @@ -137,8 +138,12 @@ export function readDirective( } expression = readExpression(parser, expressionStart, quoteMark); - if (directive.allowedExpressionTypes.indexOf(expression.type) === -1) { - parser.error(`Expected ${directive.allowedExpressionTypes.join(' or ')}`, expressionStart); + if (directive.allowedExpressionTypes) { + if (directive.allowedExpressionTypes.indexOf(expression.type) === -1) { + parser.error(`Expected ${list(directive.allowedExpressionTypes)}`, expressionStart); + } + } else { + parser.error(`${directiveName} directives cannot have a value`, expressionStart); } } diff --git a/test/parser/samples/error-ref-value/error.json b/test/parser/samples/error-ref-value/error.json new file mode 100644 index 0000000000..963c4656eb --- /dev/null +++ b/test/parser/samples/error-ref-value/error.json @@ -0,0 +1,8 @@ +{ + "message": "ref directives cannot have a value", + "loc": { + "line": 1, + "column": 14 + }, + "pos": 14 +} \ No newline at end of file diff --git a/test/parser/samples/error-ref-value/input.html b/test/parser/samples/error-ref-value/input.html new file mode 100644 index 0000000000..8ad19958e3 --- /dev/null +++ b/test/parser/samples/error-ref-value/input.html @@ -0,0 +1 @@ +
\ No newline at end of file