Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Feb 25, 2018
1 parent 42f7d78 commit df0ee35
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/utils/binding-parser.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@
(function() {
'use strict';

/**
* The open and corresponding closing brackets for surrounding bindings.
* @enum {string}
*/
const BINDINGS = {
'{': '}',
'[': ']'
};

/**
* All states that the parser can be in. The states represent the state-machine as a whole.
* @enum {number}
*/
const STATE = {
INITIAL: 1,
FIRSTOPENINGBINDING: 2,
Expand Down Expand Up @@ -98,26 +106,30 @@
}

/**
* Module with utilities for converting between "dash-case" and "camelCase"
* identifiers.
* Module that parses binding expressions and generates corresponding metadata.
*
* @namespace
* @memberof Polymer
* @summary Module that provides utilities for converting between "dash-case"
* and "camelCase".
* @summary Module that parses binding expressions and generates corresponding metadata.
*/
const BindingParser = {

/**
* @param {string} text Text to parse from attribute or textContent
* @param {Object} templateInfo Current template metadata
* @return {Array<!BindingPart>} Array of binding part metadata
*/
parse(text, templateInfo) {
const parts = [];
let bindingData = {};
let escaped = false;
/** @type {string} */
let quote;

/** @type {number} */
let state = STATE.INITIAL;
let i,l;

for (i=0,l=text.length; i<l; i++) {
for (let i=0,l=text.length; i<l; i++) {
const char = text.charAt(i);
switch (state) {
case STATE.INITIAL: {
Expand Down Expand Up @@ -326,7 +338,7 @@
if (char === BINDINGS[bindingData.mode]) {
state = STATE.METHODCLOSEDBINDING;
} else if (char !== ' ' && char !== '\t' && char !== '\n') {
// console.warn(`Invalid binding: "${text}"`);
console.warn(`Expected two closing "${BINDINGS[bindingData.mode]}" for binding "${text}"`);
}
break;
}
Expand All @@ -336,7 +348,7 @@
parts.push(bindingData);
state = STATE.INITIAL;
} else if (char !== ' ' && char !== '\t' && char !== '\n') {
// console.warn(`Invalid binding: "${text}"`);
console.warn(`Expected one closing "${BINDINGS[bindingData.mode]}" for binding "${text}"`);
}
break;
}
Expand Down

0 comments on commit df0ee35

Please sign in to comment.