diff --git a/src/parse/read/expression.js b/src/parse/read/expression.js index e0d5812d72..61cebc9cc7 100644 --- a/src/parse/read/expression.js +++ b/src/parse/read/expression.js @@ -1,13 +1,24 @@ import { parseExpressionAt } from 'acorn'; export default function readExpression ( parser ) { + const start = parser.index; + + const name = parser.readUntil( /\s*}}/ ); + if ( name && /^\w+$/.test( name ) ) { + return { + type: 'Identifier', + start, + end: start + name.length, + name + }; + } + + parser.index = start; + try { const node = parseExpressionAt( parser.template, parser.index ); parser.index = node.end; - // TODO check it's a valid expression. probably shouldn't have - // [arrow] function expressions, etc - return node; } catch ( err ) { parser.acornError( err ); diff --git a/test/generator/samples/attribute-dynamic-reserved/_config.js b/test/generator/samples/attribute-dynamic-reserved/_config.js new file mode 100644 index 0000000000..e14059fec0 --- /dev/null +++ b/test/generator/samples/attribute-dynamic-reserved/_config.js @@ -0,0 +1,14 @@ +export default { + data: { + class: 'foo' + }, + + html: `
`, + + test ( assert, component, target ) { + component.set({ class: 'bar' }); + assert.equal( target.innerHTML, `
` ); + + component.destroy(); + } +}; diff --git a/test/generator/samples/attribute-dynamic-reserved/main.html b/test/generator/samples/attribute-dynamic-reserved/main.html new file mode 100644 index 0000000000..6b149d165f --- /dev/null +++ b/test/generator/samples/attribute-dynamic-reserved/main.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/input.html b/test/parser/samples/attribute-dynamic-reserved/input.html new file mode 100644 index 0000000000..6b149d165f --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/input.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/output.json b/test/parser/samples/attribute-dynamic-reserved/output.json new file mode 100644 index 0000000000..a097655e2a --- /dev/null +++ b/test/parser/samples/attribute-dynamic-reserved/output.json @@ -0,0 +1,40 @@ +{ + "hash": 3305933215, + "html": { + "start": 0, + "end": 29, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 29, + "type": "Element", + "name": "div", + "attributes": [ + { + "start": 5, + "end": 22, + "type": "Attribute", + "name": "class", + "value": [ + { + "start": 12, + "end": 21, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 14, + "end": 19, + "name": "class" + } + } + ] + } + ], + "children": [] + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file