From 13b834dfb73abd8eab306c37db43978216b26444 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Tue, 1 Aug 2017 21:07:19 -0700 Subject: [PATCH] Rewrite expression parser to state machine --- lib/mixins/property-effects.html | 65 +---- lib/utils/binding-parser.html | 397 +++++++++++++++++++++++++++++++ test/unit/property-effects.html | 2 +- 3 files changed, 402 insertions(+), 62 deletions(-) create mode 100644 lib/utils/binding-parser.html diff --git a/lib/mixins/property-effects.html b/lib/mixins/property-effects.html index 827c6de1a9..5d78c7cda8 100644 --- a/lib/mixins/property-effects.html +++ b/lib/mixins/property-effects.html @@ -13,6 +13,7 @@ + @@ -2627,67 +2628,9 @@ * @protected */ static _parseBindings(text, templateInfo) { - let parts = []; - let lastIndex = 0; - let m; - // Example: "literal1{{prop}}literal2[[!compute(foo,bar)]]final" - // Regex matches: - // Iteration 1: Iteration 2: - // m[1]: '{{' '[[' - // m[2]: '' '!' - // m[3]: 'prop' 'compute(foo,bar)' - while ((m = bindingRegex.exec(text)) !== null) { - // Add literal part - if (m.index > lastIndex) { - parts.push({literal: text.slice(lastIndex, m.index)}); - } - // Add binding part - let mode = m[1][0]; - let negate = Boolean(m[2]); - let source = m[3].trim(); - let customEvent = false, notifyEvent = '', colon = -1; - if (mode == '{' && (colon = source.indexOf('::')) > 0) { - notifyEvent = source.substring(colon + 2); - source = source.substring(0, colon); - customEvent = true; - } - let signature = parseMethod(source); - let dependencies = []; - if (signature) { - // Inline computed function - let {args, methodName} = signature; - for (let i=0; i + + diff --git a/test/unit/property-effects.html b/test/unit/property-effects.html index 2a7581fbb5..c272c04127 100644 --- a/test/unit/property-effects.html +++ b/test/unit/property-effects.html @@ -1252,7 +1252,7 @@ test('malformed bindings ignored', function() { el.bool = true; - assert.isTrue(el.$.boundChild.textContent.indexOf('really.long.identifier.in.malformed.binding.should.be.ignored') >= 0, true); + assert.isFalse(el.$.boundChild.textContent.indexOf('really.long.identifier.in.malformed.binding.should.be.ignored') >= 0, true); assert.isTrue(el.$.boundChild.textContent.indexOf('really.long.literal.in.malformed.binding.should.be.ignored') >= 0, true); assert.isTrue(el.$.boundChild.textContent.indexOf('3foo') >= 0, true); });