From 1c81f85c11e0bb2472ab4796420d32a18e3a4e79 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 26 Nov 2018 22:34:44 -0500 Subject: [PATCH] fix parser tests --- src/compile/nodes/Binding.ts | 10 +- src/parse/index.ts | 10 + src/parse/state/tag.ts | 2 +- test/hydration/index.js | 2 +- test/parser/index.js | 2 +- .../samples/action-with-call/input.html | 2 +- .../samples/action-with-call/output.json | 22 +-- .../samples/action-with-identifier/input.html | 2 +- .../action-with-identifier/output.json | 4 +- .../samples/action-with-literal/input.html | 2 +- .../samples/action-with-literal/output.json | 14 +- test/parser/samples/action/output.json | 4 +- test/parser/samples/animation/output.json | 4 +- .../attribute-containing-solidus/output.json | 4 +- .../attribute-dynamic-boolean/output.json | 4 +- .../attribute-dynamic-reserved/output.json | 4 +- .../samples/attribute-dynamic/output.json | 4 +- .../samples/attribute-escaped/output.json | 4 +- .../samples/attribute-multiple/output.json | 4 +- .../samples/attribute-shorthand/output.json | 4 +- .../attribute-static-boolean/output.json | 4 +- .../samples/attribute-static/output.json | 4 +- .../samples/attribute-unquoted/output.json | 4 +- .../samples/await-then-catch/output.json | 4 +- .../samples/binding-shorthand/output.json | 8 +- test/parser/samples/binding/output.json | 6 +- test/parser/samples/comment/output.json | 4 +- .../samples/component-dynamic/output.json | 4 +- .../convert-entities-in-element/output.json | 4 +- .../samples/convert-entities/output.json | 4 +- .../samples/css-ref-selector/output.json | 119 ++++++------ test/parser/samples/css/output.json | 116 +++++------ test/parser/samples/dynamic-import/input.html | 14 +- .../parser/samples/dynamic-import/output.json | 180 ++++++++++-------- .../each-block-destructured/output.json | 4 +- .../samples/each-block-else/output.json | 4 +- .../samples/each-block-indexed/output.json | 4 +- .../samples/each-block-keyed/output.json | 4 +- test/parser/samples/each-block/output.json | 4 +- .../samples/element-with-mustache/output.json | 4 +- .../samples/element-with-text/output.json | 4 +- test/parser/samples/elements/output.json | 4 +- .../error-binding-mustaches/error.json | 10 - .../error-binding-mustaches/input.html | 1 - .../samples/error-binding-rvalue/error.json | 10 - .../samples/error-binding-rvalue/input.html | 1 - .../samples/error-event-handler/error.json | 10 - .../samples/error-event-handler/input.html | 1 - .../parser/samples/error-ref-value/error.json | 10 - .../parser/samples/error-ref-value/input.html | 1 - test/parser/samples/event-handler/input.html | 2 +- test/parser/samples/event-handler/output.json | 80 ++++---- test/parser/samples/if-block-else/output.json | 4 +- .../samples/if-block-elseif/output.json | 4 +- test/parser/samples/if-block/output.json | 4 +- .../samples/implicitly-closed-li/output.json | 4 +- test/parser/samples/nbsp/output.json | 4 +- test/parser/samples/raw-mustaches/output.json | 4 +- test/parser/samples/refs/output.json | 7 +- .../samples/script-comment-only/input.html | 6 +- .../samples/script-comment-only/output.json | 26 +-- .../input.html | 10 +- .../output.json | 146 ++++++-------- .../script-comment-trailing/input.html | 10 +- .../script-comment-trailing/output.json | 146 ++++++-------- test/parser/samples/script/input.html | 10 +- test/parser/samples/script/output.json | 146 ++++++-------- .../samples/self-closing-element/output.json | 4 +- .../parser/samples/self-reference/output.json | 4 +- .../space-between-mustaches/output.json | 4 +- test/parser/samples/spread/output.json | 4 +- .../samples/textarea-children/output.json | 4 +- .../transition-intro-no-params/output.json | 4 +- .../samples/transition-intro/input.html | 2 +- .../samples/transition-intro/output.json | 30 +-- .../samples/unusual-identifier/output.json | 4 +- .../whitespace-leading-trailing/output.json | 4 +- .../samples/whitespace-normal/output.json | 4 +- test/parser/samples/yield/output.json | 4 +- 79 files changed, 605 insertions(+), 739 deletions(-) delete mode 100644 test/parser/samples/error-binding-mustaches/error.json delete mode 100644 test/parser/samples/error-binding-mustaches/input.html delete mode 100644 test/parser/samples/error-binding-rvalue/error.json delete mode 100644 test/parser/samples/error-binding-rvalue/input.html delete mode 100644 test/parser/samples/error-event-handler/error.json delete mode 100644 test/parser/samples/error-event-handler/input.html delete mode 100644 test/parser/samples/error-ref-value/error.json delete mode 100644 test/parser/samples/error-ref-value/input.html diff --git a/src/compile/nodes/Binding.ts b/src/compile/nodes/Binding.ts index ffd729431f..a4dcab3244 100644 --- a/src/compile/nodes/Binding.ts +++ b/src/compile/nodes/Binding.ts @@ -1,6 +1,7 @@ import Node from './shared/Node'; import getObject from '../../utils/getObject'; import Expression from './shared/Expression'; +import Component from '../Component'; export default class Binding extends Node { name: string; @@ -10,9 +11,16 @@ export default class Binding extends Node { obj: string; prop: string; - constructor(component, parent, scope, info) { + constructor(component: Component, parent, scope, info) { super(component, parent, scope, info); + if (info.expression.type !== 'Identifier' && info.expression.node.type !== 'MemberExpression') { + component.error(info, { + code: 'invalid-directive-value', + message: 'Can only bind to an identifier (e.g. `foo`) or a member expression (e.g. `foo.bar` or `foo[baz]`)' + }); + } + this.name = info.name; this.expression = new Expression(component, this, scope, info.expression); diff --git a/src/parse/index.ts b/src/parse/index.ts index 891fe0841d..3ae97f2ccf 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -220,6 +220,16 @@ export default function parse( options: ParserOptions = {} ): Ast { const parser = new Parser(template, options); + + // TODO we way want to allow multiple