From 81f5d1ad90763a26958d3554c6698c7298779ae8 Mon Sep 17 00:00:00 2001 From: Rob Eisenberg Date: Thu, 9 Apr 2015 02:26:11 -0400 Subject: [PATCH] chore(all): prepare release 0.10.0 --- bower.json | 8 +- config.js | 58 ++-- dist/amd/binding-language.js | 510 +++++++++++++-------------- dist/amd/index.js | 27 +- dist/amd/syntax-interpreter.js | 282 +++++++-------- dist/commonjs/binding-language.js | 517 +++++++++++++--------------- dist/commonjs/index.js | 31 +- dist/commonjs/syntax-interpreter.js | 284 +++++++-------- dist/es6/binding-language.js | 1 + dist/es6/syntax-interpreter.js | 4 +- dist/system/binding-language.js | 501 +++++++++++++-------------- dist/system/index.js | 10 +- dist/system/syntax-interpreter.js | 264 +++++++------- doc/CHANGELOG.md | 9 + package.json | 8 +- 15 files changed, 1174 insertions(+), 1340 deletions(-) diff --git a/bower.json b/bower.json index cbad370..7ddc414 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-binding", - "version": "0.9.0", + "version": "0.10.0", "description": "An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.", "keywords": [ "aurelia", @@ -18,8 +18,8 @@ "url": "http://github.com/aurelia/templating-binding" }, "dependencies": { - "aurelia-binding": "^0.4.0", - "aurelia-logging": "^0.2.6", - "aurelia-templating": "^0.9.0" + "aurelia-binding": "^0.5.0", + "aurelia-logging": "^0.3.0", + "aurelia-templating": "^0.10.0" } } diff --git a/config.js b/config.js index 18d09d7..c06be61 100644 --- a/config.js +++ b/config.js @@ -9,41 +9,39 @@ System.config({ System.config({ "map": { - "aurelia-binding": "github:aurelia/binding@0.4.0", - "aurelia-logging": "github:aurelia/logging@0.2.6", - "aurelia-templating": "github:aurelia/templating@0.9.0", - "github:aurelia/binding@0.4.0": { - "aurelia-dependency-injection": "github:aurelia/dependency-injection@0.5.0", - "aurelia-metadata": "github:aurelia/metadata@0.3.4", - "aurelia-task-queue": "github:aurelia/task-queue@0.2.5" + "aurelia-binding": "github:aurelia/binding@0.5.0", + "aurelia-logging": "github:aurelia/logging@0.3.0", + "aurelia-templating": "github:aurelia/templating@0.10.0", + "github:aurelia/binding@0.5.0": { + "aurelia-dependency-injection": "github:aurelia/dependency-injection@0.6.0", + "aurelia-metadata": "github:aurelia/metadata@0.4.0", + "aurelia-task-queue": "github:aurelia/task-queue@0.3.0", + "core-js": "github:zloirock/core-js@0.8.1" }, - "github:aurelia/dependency-injection@0.5.0": { - "aurelia-logging": "github:aurelia/logging@0.2.6", - "aurelia-metadata": "github:aurelia/metadata@0.3.4", - "core-js": "npm:core-js@0.4.10" + "github:aurelia/dependency-injection@0.6.0": { + "aurelia-logging": "github:aurelia/logging@0.3.0", + "aurelia-metadata": "github:aurelia/metadata@0.4.0", + "core-js": "github:zloirock/core-js@0.8.1" }, - "github:aurelia/loader@0.4.0": { - "aurelia-html-template-element": "github:aurelia/html-template-element@0.1.3", - "aurelia-path": "github:aurelia/path@0.4.6", - "core-js": "npm:core-js@0.4.10", + "github:aurelia/loader@0.5.0": { + "aurelia-html-template-element": "github:aurelia/html-template-element@0.2.0", + "aurelia-path": "github:aurelia/path@0.5.0", + "core-js": "github:zloirock/core-js@0.8.1", "webcomponentsjs": "github:webcomponents/webcomponentsjs@0.5.5" }, - "github:aurelia/templating@0.9.0": { - "aurelia-binding": "github:aurelia/binding@0.4.0", - "aurelia-dependency-injection": "github:aurelia/dependency-injection@0.5.0", - "aurelia-html-template-element": "github:aurelia/html-template-element@0.1.3", - "aurelia-loader": "github:aurelia/loader@0.4.0", - "aurelia-logging": "github:aurelia/logging@0.2.6", - "aurelia-metadata": "github:aurelia/metadata@0.3.4", - "aurelia-path": "github:aurelia/path@0.4.6", - "aurelia-task-queue": "github:aurelia/task-queue@0.2.5", - "core-js": "npm:core-js@0.4.10" + "github:aurelia/metadata@0.4.0": { + "core-js": "github:zloirock/core-js@0.8.1" }, - "github:jspm/nodelibs-process@0.1.1": { - "process": "npm:process@0.10.1" - }, - "npm:core-js@0.4.10": { - "process": "github:jspm/nodelibs-process@0.1.1" + "github:aurelia/templating@0.10.0": { + "aurelia-binding": "github:aurelia/binding@0.5.0", + "aurelia-dependency-injection": "github:aurelia/dependency-injection@0.6.0", + "aurelia-html-template-element": "github:aurelia/html-template-element@0.2.0", + "aurelia-loader": "github:aurelia/loader@0.5.0", + "aurelia-logging": "github:aurelia/logging@0.3.0", + "aurelia-metadata": "github:aurelia/metadata@0.4.0", + "aurelia-path": "github:aurelia/path@0.5.0", + "aurelia-task-queue": "github:aurelia/task-queue@0.3.0", + "core-js": "github:zloirock/core-js@0.8.1" } } }); diff --git a/dist/amd/binding-language.js b/dist/amd/binding-language.js index 8137bc1..12d51ba 100644 --- a/dist/amd/binding-language.js +++ b/dist/amd/binding-language.js @@ -1,201 +1,183 @@ -define(["exports", "aurelia-templating", "aurelia-binding", "./syntax-interpreter", "aurelia-logging"], function (exports, _aureliaTemplating, _aureliaBinding, _syntaxInterpreter, _aureliaLogging) { - "use strict"; +define(['exports', 'aurelia-templating', 'aurelia-binding', './syntax-interpreter', 'aurelia-logging'], function (exports, _aureliaTemplating, _aureliaBinding, _syntaxInterpreter, _aureliaLogging) { + 'use strict'; - var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; + var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; + var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - var BindingLanguage = _aureliaTemplating.BindingLanguage; - var Parser = _aureliaBinding.Parser; - var ObserverLocator = _aureliaBinding.ObserverLocator; - var BindingExpression = _aureliaBinding.BindingExpression; - var NameExpression = _aureliaBinding.NameExpression; - var ONE_WAY = _aureliaBinding.ONE_WAY; - var SyntaxInterpreter = _syntaxInterpreter.SyntaxInterpreter; - var LogManager = _aureliaLogging; + var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + + Object.defineProperty(exports, '__esModule', { + value: true + }); var info = {}, - logger = LogManager.getLogger("templating-binding"); + logger = _aureliaLogging.getLogger('templating-binding'); - var TemplatingBindingLanguage = exports.TemplatingBindingLanguage = (function (BindingLanguage) { + var TemplatingBindingLanguage = (function (_BindingLanguage) { function TemplatingBindingLanguage(parser, observerLocator, syntaxInterpreter) { _classCallCheck(this, TemplatingBindingLanguage); + _get(Object.getPrototypeOf(TemplatingBindingLanguage.prototype), 'constructor', this).call(this); this.parser = parser; this.observerLocator = observerLocator; this.syntaxInterpreter = syntaxInterpreter; - this.emptyStringExpression = this.parser.parse("''"); + this.emptyStringExpression = this.parser.parse('\'\''); syntaxInterpreter.language = this; this.attributeMap = syntaxInterpreter.attributeMap = { - "class": "className", - "for": "htmlFor", - tabindex: "tabIndex", - textcontent: "textContent", - innerhtml: "innerHTML", - // HTMLInputElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement - maxlength: "maxLength", - minlength: "minLength", - formaction: "formAction", - formenctype: "formEncType", - formmethod: "formMethod", - formnovalidate: "formNoValidate", - formtarget: "formTarget" }; + 'class': 'className', + 'for': 'htmlFor', + tabindex: 'tabIndex', + textcontent: 'textContent', + innerhtml: 'innerHTML', + maxlength: 'maxLength', + minlength: 'minLength', + formaction: 'formAction', + formenctype: 'formEncType', + formmethod: 'formMethod', + formnovalidate: 'formNoValidate', + formtarget: 'formTarget' }; } - _inherits(TemplatingBindingLanguage, BindingLanguage); - - _prototypeProperties(TemplatingBindingLanguage, { - inject: { - value: function inject() { - return [Parser, ObserverLocator, SyntaxInterpreter]; - }, - writable: true, - configurable: true + _inherits(TemplatingBindingLanguage, _BindingLanguage); + + _createClass(TemplatingBindingLanguage, [{ + key: 'inspectAttribute', + value: function inspectAttribute(resources, attrName, attrValue) { + var parts = attrName.split('.'); + + info.defaultBindingMode = null; + + if (parts.length == 2) { + info.attrName = parts[0].trim(); + info.attrValue = attrValue; + info.command = parts[1].trim(); + info.expression = null; + } else if (attrName == 'ref') { + info.attrName = attrName; + info.attrValue = attrValue; + info.command = null; + info.expression = new _aureliaBinding.NameExpression(attrValue, 'element'); + } else { + info.attrName = attrName; + info.attrValue = attrValue; + info.command = null; + info.expression = this.parseContent(resources, attrName, attrValue); + } + + return info; } }, { - inspectAttribute: { - value: function inspectAttribute(resources, attrName, attrValue) { - var parts = attrName.split("."); - - info.defaultBindingMode = null; - - if (parts.length == 2) { - info.attrName = parts[0].trim(); - info.attrValue = attrValue; - info.command = parts[1].trim(); - info.expression = null; - } else if (attrName == "ref") { - info.attrName = attrName; - info.attrValue = attrValue; - info.command = null; - info.expression = new NameExpression(attrValue, "element"); - } else { - info.attrName = attrName; - info.attrValue = attrValue; - info.command = null; - info.expression = this.parseContent(resources, attrName, attrValue); + key: 'createAttributeInstruction', + value: function createAttributeInstruction(resources, element, info, existingInstruction) { + var instruction; + + if (info.expression) { + if (info.attrName === 'ref') { + return info.expression; } - return info; - }, - writable: true, - configurable: true - }, - createAttributeInstruction: { - value: function createAttributeInstruction(resources, element, info, existingInstruction) { - var instruction; - - if (info.expression) { - if (info.attrName === "ref") { - return info.expression; + instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; + instruction.attributes[info.attrName] = info.expression; + } else if (info.command) { + instruction = this.syntaxInterpreter.interpret(resources, element, info, existingInstruction); + } + + return instruction; + } + }, { + key: 'parseText', + value: function parseText(resources, value) { + return this.parseContent(resources, 'textContent', value); + } + }, { + key: 'parseContent', + value: function parseContent(resources, attrName, attrValue) { + var i = attrValue.indexOf('${', 0), + ii = attrValue.length, + char, + pos = 0, + open = 0, + quote = null, + interpolationStart, + parts, + partIndex = 0; + while (i >= 0 && i < ii - 2) { + open = 1; + interpolationStart = i; + i += 2; + + do { + char = attrValue[i]; + i++; + switch (char) { + case '\'': + case '"': + if (quote === null) { + quote = char; + } else if (quote === char) { + quote = null; + } + continue; + case '\\': + i++; + continue; } - instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = info.expression; - } else if (info.command) { - instruction = this.syntaxInterpreter.interpret(resources, element, info, existingInstruction); - } + if (quote !== null) { + continue; + } - return instruction; - }, - writable: true, - configurable: true - }, - parseText: { - value: function parseText(resources, value) { - return this.parseContent(resources, "textContent", value); - }, - writable: true, - configurable: true - }, - parseContent: { - value: function parseContent(resources, attrName, attrValue) { - var i = attrValue.indexOf("${", 0), - ii = attrValue.length, - char, - pos = 0, - open = 0, - quote = null, - interpolationStart, - parts, - partIndex = 0; - while (i >= 0 && i < ii - 2) { - open = 1; - interpolationStart = i; - i += 2; - - do { - char = attrValue[i]; - i++; - switch (char) { - case "'": - case "\"": - if (quote === null) { - quote = char; - } else if (quote === char) { - quote = null; - } - continue; - case "\\": - i++; - continue; - } - - if (quote !== null) { - continue; - } - - if (char === "{") { - open++; - } else if (char === "}") { - open--; - } - } while (open > 0 && i < ii); - - if (open === 0) { - // lazy allocate array - parts = parts || []; - if (attrValue[interpolationStart - 1] === "\\" && attrValue[interpolationStart - 2] !== "\\") { - // escaped interpolation - parts[partIndex] = attrValue.substring(pos, interpolationStart - 1) + attrValue.substring(interpolationStart, i); - partIndex++; - parts[partIndex] = this.emptyStringExpression; - partIndex++; - } else { - // standard interpolation - parts[partIndex] = attrValue.substring(pos, interpolationStart); - partIndex++; - parts[partIndex] = this.parser.parse(attrValue.substring(interpolationStart + 2, i - 1)); - partIndex++; - } - pos = i; - i = attrValue.indexOf("${", i); + if (char === '{') { + open++; + } else if (char === '}') { + open--; + } + } while (open > 0 && i < ii); + + if (open === 0) { + parts = parts || []; + if (attrValue[interpolationStart - 1] === '\\' && attrValue[interpolationStart - 2] !== '\\') { + parts[partIndex] = attrValue.substring(pos, interpolationStart - 1) + attrValue.substring(interpolationStart, i); + partIndex++; + parts[partIndex] = this.emptyStringExpression; + partIndex++; } else { - break; + parts[partIndex] = attrValue.substring(pos, interpolationStart); + partIndex++; + parts[partIndex] = this.parser.parse(attrValue.substring(interpolationStart + 2, i - 1)); + partIndex++; } + pos = i; + i = attrValue.indexOf('${', i); + } else { + break; } + } - // no interpolation. - if (partIndex === 0) { - return null; - } + if (partIndex === 0) { + return null; + } - // literal. - parts[partIndex] = attrValue.substr(pos); + parts[partIndex] = attrValue.substr(pos); - return new InterpolationBindingExpression(this.observerLocator, this.attributeMap[attrName] || attrName, parts, ONE_WAY, resources.valueConverterLookupFunction, attrName); - }, - writable: true, - configurable: true + return new InterpolationBindingExpression(this.observerLocator, this.attributeMap[attrName] || attrName, parts, _aureliaBinding.ONE_WAY, resources.valueConverterLookupFunction, attrName); } - }); + }], [{ + key: 'inject', + value: function inject() { + return [_aureliaBinding.Parser, _aureliaBinding.ObserverLocator, _syntaxInterpreter.SyntaxInterpreter]; + } + }]); return TemplatingBindingLanguage; - })(BindingLanguage); + })(_aureliaTemplating.BindingLanguage); + + exports.TemplatingBindingLanguage = TemplatingBindingLanguage; - var InterpolationBindingExpression = exports.InterpolationBindingExpression = (function () { + var InterpolationBindingExpression = (function () { function InterpolationBindingExpression(observerLocator, targetProperty, parts, mode, valueConverterLookupFunction, attribute) { _classCallCheck(this, InterpolationBindingExpression); @@ -208,27 +190,26 @@ define(["exports", "aurelia-templating", "aurelia-binding", "./syntax-interprete this.discrete = false; } - _prototypeProperties(InterpolationBindingExpression, null, { - createBinding: { - value: function createBinding(target) { - return new InterpolationBinding(this.observerLocator, this.parts, target, this.targetProperty, this.mode, this.valueConverterLookupFunction); - }, - writable: true, - configurable: true + _createClass(InterpolationBindingExpression, [{ + key: 'createBinding', + value: function createBinding(target) { + return new InterpolationBinding(this.observerLocator, this.parts, target, this.targetProperty, this.mode, this.valueConverterLookupFunction); } - }); + }]); return InterpolationBindingExpression; })(); + exports.InterpolationBindingExpression = InterpolationBindingExpression; + var InterpolationBinding = (function () { function InterpolationBinding(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { _classCallCheck(this, InterpolationBinding); - if (targetProperty === "style") { - logger.info("Internet Explorer does not support interpolation in \"style\" attributes. Use the style attribute's alias, \"css\" instead."); - } else if (target.parentElement && target.parentElement.nodeName === "TEXTAREA" && targetProperty === "textContent") { - throw new Error("Interpolation binding cannot be used in the content of a textarea element. Use instead."); + if (targetProperty === 'style') { + logger.info('Internet Explorer does not support interpolation in "style" attributes. Use the style attribute\'s alias, "css" instead.'); + } else if (target.parentElement && target.parentElement.nodeName === 'TEXTAREA' && targetProperty === 'textContent') { + throw new Error('Interpolation binding cannot be used in the content of a textarea element. Use instead.'); } this.observerLocator = observerLocator; this.parts = parts; @@ -238,111 +219,92 @@ define(["exports", "aurelia-templating", "aurelia-binding", "./syntax-interprete this.toDispose = []; } - _prototypeProperties(InterpolationBinding, null, { - getObserver: { - value: function getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); - }, - writable: true, - configurable: true - }, - bind: { - value: function bind(source) { - this.source = source; - - if (this.mode == ONE_WAY) { - this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); - } - }, - writable: true, - configurable: true - }, - setValue: { - value: function setValue() { - var value = this.interpolate(); - this.targetProperty.setValue(value); - }, - writable: true, - configurable: true - }, - connect: { - value: function connect() { - var _this = this; - - var info, - parts = this.parts, - source = this.source, - toDispose = this.toDispose = [], - i, - ii; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 === 0) {} else { - info = parts[i].connect(this, source); - if (info.observer) { - toDispose.push(info.observer.subscribe(function (newValue) { - _this.setValue(); - })); - } + _createClass(InterpolationBinding, [{ + key: 'getObserver', + value: function getObserver(obj, propertyName) { + return this.observerLocator.getObserver(obj, propertyName); + } + }, { + key: 'bind', + value: function bind(source) { + this.source = source; + + if (this.mode == _aureliaBinding.ONE_WAY) { + this.unbind(); + this.connect(); + this.setValue(); + } else { + this.setValue(); + } + } + }, { + key: 'setValue', + value: function setValue() { + var value = this.interpolate(); + this.targetProperty.setValue(value); + } + }, { + key: 'connect', + value: function connect() { + var _this = this; + + var info, + parts = this.parts, + source = this.source, + toDispose = this.toDispose = [], + i, + ii; + + for (i = 0, ii = parts.length; i < ii; ++i) { + if (i % 2 === 0) {} else { + info = parts[i].connect(this, source); + if (info.observer) { + toDispose.push(info.observer.subscribe(function (newValue) { + _this.setValue(); + })); } } - }, - writable: true, - configurable: true - }, - interpolate: { - value: function interpolate() { - var value = "", - parts = this.parts, - source = this.source, - valueConverterLookupFunction = this.valueConverterLookupFunction, - i, - ii, - temp; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 === 0) { - value += parts[i]; - } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += typeof temp !== "undefined" && temp !== null ? temp.toString() : ""; - } + } + } + }, { + key: 'interpolate', + value: function interpolate() { + var value = '', + parts = this.parts, + source = this.source, + valueConverterLookupFunction = this.valueConverterLookupFunction, + i, + ii, + temp; + + for (i = 0, ii = parts.length; i < ii; ++i) { + if (i % 2 === 0) { + value += parts[i]; + } else { + temp = parts[i].evaluate(source, valueConverterLookupFunction); + value += typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''; } + } - return value; - }, - writable: true, - configurable: true - }, - unbind: { - value: function unbind() { - var i, - ii, - toDispose = this.toDispose; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } + return value; + } + }, { + key: 'unbind', + value: function unbind() { + var i, + ii, + toDispose = this.toDispose; + + if (toDispose) { + for (i = 0, ii = toDispose.length; i < ii; ++i) { + toDispose[i](); } + } - this.toDispose = null; - }, - writable: true, - configurable: true + this.toDispose = null; } - }); + }]); return InterpolationBinding; })(); - - Object.defineProperty(exports, "__esModule", { - value: true - }); -}); - -//do nothing \ No newline at end of file +}); \ No newline at end of file diff --git a/dist/amd/index.js b/dist/amd/index.js index 26ddfa1..2fe4699 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -1,29 +1,26 @@ -define(["exports", "aurelia-templating", "./binding-language", "./syntax-interpreter"], function (exports, _aureliaTemplating, _bindingLanguage, _syntaxInterpreter) { - "use strict"; +define(['exports', 'aurelia-templating', './binding-language', './syntax-interpreter'], function (exports, _aureliaTemplating, _bindingLanguage, _syntaxInterpreter) { + 'use strict'; - var BindingLanguage = _aureliaTemplating.BindingLanguage; - var TemplatingBindingLanguage = _bindingLanguage.TemplatingBindingLanguage; - var SyntaxInterpreter = _syntaxInterpreter.SyntaxInterpreter; + Object.defineProperty(exports, '__esModule', { + value: true + }); function install(aurelia) { var instance, getInstance = function getInstance(c) { - return instance || (instance = c.invoke(TemplatingBindingLanguage)); + return instance || (instance = c.invoke(_bindingLanguage.TemplatingBindingLanguage)); }; - if (aurelia.container.hasHandler(TemplatingBindingLanguage)) { - instance = aurelia.container.get(TemplatingBindingLanguage); + if (aurelia.container.hasHandler(_bindingLanguage.TemplatingBindingLanguage)) { + instance = aurelia.container.get(_bindingLanguage.TemplatingBindingLanguage); } else { - aurelia.container.registerHandler(TemplatingBindingLanguage, getInstance); + aurelia.container.registerHandler(_bindingLanguage.TemplatingBindingLanguage, getInstance); } - aurelia.container.registerHandler(BindingLanguage, getInstance); + aurelia.container.registerHandler(_aureliaTemplating.BindingLanguage, getInstance); } - exports.TemplatingBindingLanguage = TemplatingBindingLanguage; - exports.SyntaxInterpreter = SyntaxInterpreter; + exports.TemplatingBindingLanguage = _bindingLanguage.TemplatingBindingLanguage; + exports.SyntaxInterpreter = _syntaxInterpreter.SyntaxInterpreter; exports.install = install; - Object.defineProperty(exports, "__esModule", { - value: true - }); }); \ No newline at end of file diff --git a/dist/amd/syntax-interpreter.js b/dist/amd/syntax-interpreter.js index a5b3895..c22496c 100644 --- a/dist/amd/syntax-interpreter.js +++ b/dist/amd/syntax-interpreter.js @@ -1,22 +1,15 @@ -define(["exports", "aurelia-binding"], function (exports, _aureliaBinding) { - "use strict"; +define(['exports', 'aurelia-binding'], function (exports, _aureliaBinding) { + 'use strict'; - var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; + var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - var Parser = _aureliaBinding.Parser; - var ObserverLocator = _aureliaBinding.ObserverLocator; - var EventManager = _aureliaBinding.EventManager; - var ListenerExpression = _aureliaBinding.ListenerExpression; - var BindingExpression = _aureliaBinding.BindingExpression; - var NameExpression = _aureliaBinding.NameExpression; - var CallExpression = _aureliaBinding.CallExpression; - var ONE_WAY = _aureliaBinding.ONE_WAY; - var TWO_WAY = _aureliaBinding.TWO_WAY; - var ONE_TIME = _aureliaBinding.ONE_TIME; + Object.defineProperty(exports, '__esModule', { + value: true + }); - var SyntaxInterpreter = exports.SyntaxInterpreter = (function () { + var SyntaxInterpreter = (function () { function SyntaxInterpreter(parser, observerLocator, eventManager) { _classCallCheck(this, SyntaxInterpreter); @@ -25,199 +18,178 @@ define(["exports", "aurelia-binding"], function (exports, _aureliaBinding) { this.eventManager = eventManager; } - _prototypeProperties(SyntaxInterpreter, { - inject: { - value: function inject() { - return [Parser, ObserverLocator, EventManager]; - }, - writable: true, - configurable: true + _createClass(SyntaxInterpreter, [{ + key: 'interpret', + value: function interpret(resources, element, info, existingInstruction) { + if (info.command in this) { + return this[info.command](resources, element, info, existingInstruction); + } + + return this.handleUnknownCommand(resources, element, info, existingInstruction); } }, { - interpret: { - value: function interpret(resources, element, info, existingInstruction) { - if (info.command in this) { - return this[info.command](resources, element, info, existingInstruction); - } + key: 'handleUnknownCommand', + value: function handleUnknownCommand(resources, element, info, existingInstruction) { + var attrName = info.attrName, + command = info.command; - return this.handleUnknownCommand(resources, element, info, existingInstruction); - }, - writable: true, - configurable: true - }, - handleUnknownCommand: { - value: function handleUnknownCommand(resources, element, info, existingInstruction) { - var attrName = info.attrName, - command = info.command; - - var instruction = this.options(resources, element, info, existingInstruction); - - instruction.alteredAttr = true; - instruction.attrName = "global-behavior"; - instruction.attributes.aureliaAttrName = attrName; - instruction.attributes.aureliaCommand = command; - - return instruction; - }, - writable: true, - configurable: true - }, - determineDefaultBindingMode: { - value: function determineDefaultBindingMode(element, attrName) { - var tagName = element.tagName.toLowerCase(); - - if (tagName === "input") { - return attrName === "value" || attrName === "checked" ? TWO_WAY : ONE_WAY; - } else if (tagName == "textarea" || tagName == "select") { - return attrName == "value" ? TWO_WAY : ONE_WAY; - } else if (attrName === "textcontent" || attrName === "innerhtml") { - return element.contentEditable === "true" ? TWO_WAY : ONE_WAY; - } + var instruction = this.options(resources, element, info, existingInstruction); - return ONE_WAY; - }, - writable: true, - configurable: true - }, - bind: { - value: function bind(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName), resources.valueConverterLookupFunction); - - return instruction; - }, - writable: true, - configurable: true - }, - trigger: { - value: function trigger(resources, element, info) { - return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), false, true); - }, - writable: true, - configurable: true - }, - delegate: { - value: function delegate(resources, element, info) { - return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), true, true); - }, - writable: true, - configurable: true - }, - call: { - value: function call(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - - instruction.attributes[info.attrName] = new CallExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), resources.valueConverterLookupFunction); - - return instruction; - }, - writable: true, - configurable: true - }, - options: { - value: function options(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }, - attrValue = info.attrValue, - language = this.language, - name = null, - target = "", - current, - i, - ii; - - for (i = 0, ii = attrValue.length; i < ii; ++i) { - current = attrValue[i]; - - if (current === ";") { - info = language.inspectAttribute(resources, name, target.trim()); - language.createAttributeInstruction(resources, element, info, instruction); - - if (!instruction.attributes[info.attrName]) { - instruction.attributes[info.attrName] = info.attrValue; - } - - target = ""; - name = null; - } else if (current === ":" && name === null) { - name = target.trim(); - target = ""; - } else { - target += current; - } - } + instruction.alteredAttr = true; + instruction.attrName = 'global-behavior'; + instruction.attributes.aureliaAttrName = attrName; + instruction.attributes.aureliaCommand = command; + + return instruction; + } + }, { + key: 'determineDefaultBindingMode', + value: function determineDefaultBindingMode(element, attrName) { + var tagName = element.tagName.toLowerCase(); + + if (tagName === 'input') { + return attrName === 'value' || attrName === 'checked' ? _aureliaBinding.TWO_WAY : _aureliaBinding.ONE_WAY; + } else if (tagName == 'textarea' || tagName == 'select') { + return attrName == 'value' ? _aureliaBinding.TWO_WAY : _aureliaBinding.ONE_WAY; + } else if (attrName === 'textcontent' || attrName === 'innerhtml') { + return element.contentEditable === 'true' ? _aureliaBinding.TWO_WAY : _aureliaBinding.ONE_WAY; + } + + return _aureliaBinding.ONE_WAY; + } + }, { + key: 'bind', + value: function bind(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - if (name !== null) { + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName), resources.valueConverterLookupFunction); + + return instruction; + } + }, { + key: 'trigger', + value: function trigger(resources, element, info) { + return new _aureliaBinding.ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), false, true); + } + }, { + key: 'delegate', + value: function delegate(resources, element, info) { + return new _aureliaBinding.ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), true, true); + } + }, { + key: 'call', + value: function call(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; + + instruction.attributes[info.attrName] = new _aureliaBinding.CallExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), resources.valueConverterLookupFunction); + + return instruction; + } + }, { + key: 'options', + value: function options(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }, + attrValue = info.attrValue, + language = this.language, + name = null, + target = '', + current, + i, + ii; + + for (i = 0, ii = attrValue.length; i < ii; ++i) { + current = attrValue[i]; + + if (current === ';') { info = language.inspectAttribute(resources, name, target.trim()); language.createAttributeInstruction(resources, element, info, instruction); if (!instruction.attributes[info.attrName]) { instruction.attributes[info.attrName] = info.attrValue; } + + target = ''; + name = null; + } else if (current === ':' && name === null) { + name = target.trim(); + target = ''; + } else { + target += current; } + } - return instruction; - }, - writable: true, - configurable: true + if (name !== null) { + info = language.inspectAttribute(resources, name, target.trim()); + language.createAttributeInstruction(resources, element, info, instruction); + + if (!instruction.attributes[info.attrName]) { + instruction.attributes[info.attrName] = info.attrValue; + } + } + + return instruction; + } + }], [{ + key: 'inject', + value: function inject() { + return [_aureliaBinding.Parser, _aureliaBinding.ObserverLocator, _aureliaBinding.EventManager]; } - }); + }]); return SyntaxInterpreter; })(); - SyntaxInterpreter.prototype["for"] = function (resources, element, info, existingInstruction) { - var parts = info.attrValue.split(" of "); + exports.SyntaxInterpreter = SyntaxInterpreter; + + SyntaxInterpreter.prototype['for'] = function (resources, element, info, existingInstruction) { + var parts = info.attrValue.split(' of '); if (parts.length !== 2) { - throw new Error("Incorrect syntax for \"for\". The form is: \"$local of $items\"."); + throw new Error('Incorrect syntax for "for". The form is: "$local of $items".'); } var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; if (parts[0].match(/[[].+[,]\s.+[\]]/)) { var firstPart = parts[0]; - parts[0] = firstPart.substr(1, firstPart.indexOf(",") - 1); - parts.splice(1, 0, firstPart.substring(firstPart.indexOf(", ") + 2, firstPart.length - 1)); + parts[0] = firstPart.substr(1, firstPart.indexOf(',') - 1); + parts.splice(1, 0, firstPart.substring(firstPart.indexOf(', ') + 2, firstPart.length - 1)); instruction.attributes.key = parts[0]; instruction.attributes.value = parts[1]; } else { instruction.attributes.local = parts[0]; } - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, info.attrName, this.parser.parse(parts[parts.length - 1]), ONE_WAY, resources.valueConverterLookupFunction); + instruction.attributes.items = new _aureliaBinding.BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[parts.length - 1]), _aureliaBinding.ONE_WAY, resources.valueConverterLookupFunction); return instruction; }; - SyntaxInterpreter.prototype["two-way"] = function (resources, element, info, existingInstruction) { + SyntaxInterpreter.prototype['two-way'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), TWO_WAY, resources.valueConverterLookupFunction); + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.TWO_WAY, resources.valueConverterLookupFunction); return instruction; }; - SyntaxInterpreter.prototype["one-way"] = function (resources, element, info, existingInstruction) { + SyntaxInterpreter.prototype['one-way'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), ONE_WAY, resources.valueConverterLookupFunction); + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.ONE_WAY, resources.valueConverterLookupFunction); return instruction; }; - SyntaxInterpreter.prototype["one-time"] = function (resources, element, info, existingInstruction) { + SyntaxInterpreter.prototype['one-time'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), ONE_TIME, resources.valueConverterLookupFunction); + instruction.attributes[info.attrName] = new _aureliaBinding.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _aureliaBinding.ONE_TIME, resources.valueConverterLookupFunction); return instruction; }; - SyntaxInterpreter.prototype["view-model"] = function (resources, element, info) { - return new NameExpression(info.attrValue, "view-model"); + SyntaxInterpreter.prototype['view-model'] = function (resources, element, info) { + return new _aureliaBinding.NameExpression(info.attrValue, 'view-model'); }; - Object.defineProperty(exports, "__esModule", { - value: true - }); }); \ No newline at end of file diff --git a/dist/commonjs/binding-language.js b/dist/commonjs/binding-language.js index 95be376..8f48bc9 100644 --- a/dist/commonjs/binding-language.js +++ b/dist/commonjs/binding-language.js @@ -1,207 +1,194 @@ -"use strict"; +'use strict'; -var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; }; +var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; +var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; +var _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; -var BindingLanguage = require("aurelia-templating").BindingLanguage; +var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; -var _aureliaBinding = require("aurelia-binding"); +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _BindingLanguage2 = require('aurelia-templating'); -var Parser = _aureliaBinding.Parser; -var ObserverLocator = _aureliaBinding.ObserverLocator; -var BindingExpression = _aureliaBinding.BindingExpression; -var NameExpression = _aureliaBinding.NameExpression; -var ONE_WAY = _aureliaBinding.ONE_WAY; +var _Parser$ObserverLocator$BindingExpression$NameExpression$ONE_WAY = require('aurelia-binding'); -var SyntaxInterpreter = require("./syntax-interpreter").SyntaxInterpreter; +var _SyntaxInterpreter = require('./syntax-interpreter'); -var LogManager = _interopRequireWildcard(require("aurelia-logging")); +var _import = require('aurelia-logging'); + +var LogManager = _interopRequireWildcard(_import); var info = {}, - logger = LogManager.getLogger("templating-binding"); + logger = LogManager.getLogger('templating-binding'); -var TemplatingBindingLanguage = exports.TemplatingBindingLanguage = (function (BindingLanguage) { +var TemplatingBindingLanguage = (function (_BindingLanguage) { function TemplatingBindingLanguage(parser, observerLocator, syntaxInterpreter) { _classCallCheck(this, TemplatingBindingLanguage); + _get(Object.getPrototypeOf(TemplatingBindingLanguage.prototype), 'constructor', this).call(this); this.parser = parser; this.observerLocator = observerLocator; this.syntaxInterpreter = syntaxInterpreter; - this.emptyStringExpression = this.parser.parse("''"); + this.emptyStringExpression = this.parser.parse('\'\''); syntaxInterpreter.language = this; this.attributeMap = syntaxInterpreter.attributeMap = { - "class": "className", - "for": "htmlFor", - tabindex: "tabIndex", - textcontent: "textContent", - innerhtml: "innerHTML", - // HTMLInputElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement - maxlength: "maxLength", - minlength: "minLength", - formaction: "formAction", - formenctype: "formEncType", - formmethod: "formMethod", - formnovalidate: "formNoValidate", - formtarget: "formTarget" }; + 'class': 'className', + 'for': 'htmlFor', + tabindex: 'tabIndex', + textcontent: 'textContent', + innerhtml: 'innerHTML', + maxlength: 'maxLength', + minlength: 'minLength', + formaction: 'formAction', + formenctype: 'formEncType', + formmethod: 'formMethod', + formnovalidate: 'formNoValidate', + formtarget: 'formTarget' }; } - _inherits(TemplatingBindingLanguage, BindingLanguage); - - _prototypeProperties(TemplatingBindingLanguage, { - inject: { - value: function inject() { - return [Parser, ObserverLocator, SyntaxInterpreter]; - }, - writable: true, - configurable: true + _inherits(TemplatingBindingLanguage, _BindingLanguage); + + _createClass(TemplatingBindingLanguage, [{ + key: 'inspectAttribute', + value: function inspectAttribute(resources, attrName, attrValue) { + var parts = attrName.split('.'); + + info.defaultBindingMode = null; + + if (parts.length == 2) { + info.attrName = parts[0].trim(); + info.attrValue = attrValue; + info.command = parts[1].trim(); + info.expression = null; + } else if (attrName == 'ref') { + info.attrName = attrName; + info.attrValue = attrValue; + info.command = null; + info.expression = new _Parser$ObserverLocator$BindingExpression$NameExpression$ONE_WAY.NameExpression(attrValue, 'element'); + } else { + info.attrName = attrName; + info.attrValue = attrValue; + info.command = null; + info.expression = this.parseContent(resources, attrName, attrValue); + } + + return info; } }, { - inspectAttribute: { - value: function inspectAttribute(resources, attrName, attrValue) { - var parts = attrName.split("."); - - info.defaultBindingMode = null; - - if (parts.length == 2) { - info.attrName = parts[0].trim(); - info.attrValue = attrValue; - info.command = parts[1].trim(); - info.expression = null; - } else if (attrName == "ref") { - info.attrName = attrName; - info.attrValue = attrValue; - info.command = null; - info.expression = new NameExpression(attrValue, "element"); - } else { - info.attrName = attrName; - info.attrValue = attrValue; - info.command = null; - info.expression = this.parseContent(resources, attrName, attrValue); + key: 'createAttributeInstruction', + value: function createAttributeInstruction(resources, element, info, existingInstruction) { + var instruction; + + if (info.expression) { + if (info.attrName === 'ref') { + return info.expression; } - return info; - }, - writable: true, - configurable: true - }, - createAttributeInstruction: { - value: function createAttributeInstruction(resources, element, info, existingInstruction) { - var instruction; - - if (info.expression) { - if (info.attrName === "ref") { - return info.expression; + instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; + instruction.attributes[info.attrName] = info.expression; + } else if (info.command) { + instruction = this.syntaxInterpreter.interpret(resources, element, info, existingInstruction); + } + + return instruction; + } + }, { + key: 'parseText', + value: function parseText(resources, value) { + return this.parseContent(resources, 'textContent', value); + } + }, { + key: 'parseContent', + value: function parseContent(resources, attrName, attrValue) { + var i = attrValue.indexOf('${', 0), + ii = attrValue.length, + char, + pos = 0, + open = 0, + quote = null, + interpolationStart, + parts, + partIndex = 0; + while (i >= 0 && i < ii - 2) { + open = 1; + interpolationStart = i; + i += 2; + + do { + char = attrValue[i]; + i++; + switch (char) { + case '\'': + case '"': + if (quote === null) { + quote = char; + } else if (quote === char) { + quote = null; + } + continue; + case '\\': + i++; + continue; } - instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = info.expression; - } else if (info.command) { - instruction = this.syntaxInterpreter.interpret(resources, element, info, existingInstruction); - } + if (quote !== null) { + continue; + } - return instruction; - }, - writable: true, - configurable: true - }, - parseText: { - value: function parseText(resources, value) { - return this.parseContent(resources, "textContent", value); - }, - writable: true, - configurable: true - }, - parseContent: { - value: function parseContent(resources, attrName, attrValue) { - var i = attrValue.indexOf("${", 0), - ii = attrValue.length, - char, - pos = 0, - open = 0, - quote = null, - interpolationStart, - parts, - partIndex = 0; - while (i >= 0 && i < ii - 2) { - open = 1; - interpolationStart = i; - i += 2; - - do { - char = attrValue[i]; - i++; - switch (char) { - case "'": - case "\"": - if (quote === null) { - quote = char; - } else if (quote === char) { - quote = null; - } - continue; - case "\\": - i++; - continue; - } - - if (quote !== null) { - continue; - } - - if (char === "{") { - open++; - } else if (char === "}") { - open--; - } - } while (open > 0 && i < ii); - - if (open === 0) { - // lazy allocate array - parts = parts || []; - if (attrValue[interpolationStart - 1] === "\\" && attrValue[interpolationStart - 2] !== "\\") { - // escaped interpolation - parts[partIndex] = attrValue.substring(pos, interpolationStart - 1) + attrValue.substring(interpolationStart, i); - partIndex++; - parts[partIndex] = this.emptyStringExpression; - partIndex++; - } else { - // standard interpolation - parts[partIndex] = attrValue.substring(pos, interpolationStart); - partIndex++; - parts[partIndex] = this.parser.parse(attrValue.substring(interpolationStart + 2, i - 1)); - partIndex++; - } - pos = i; - i = attrValue.indexOf("${", i); + if (char === '{') { + open++; + } else if (char === '}') { + open--; + } + } while (open > 0 && i < ii); + + if (open === 0) { + parts = parts || []; + if (attrValue[interpolationStart - 1] === '\\' && attrValue[interpolationStart - 2] !== '\\') { + parts[partIndex] = attrValue.substring(pos, interpolationStart - 1) + attrValue.substring(interpolationStart, i); + partIndex++; + parts[partIndex] = this.emptyStringExpression; + partIndex++; } else { - break; + parts[partIndex] = attrValue.substring(pos, interpolationStart); + partIndex++; + parts[partIndex] = this.parser.parse(attrValue.substring(interpolationStart + 2, i - 1)); + partIndex++; } + pos = i; + i = attrValue.indexOf('${', i); + } else { + break; } + } - // no interpolation. - if (partIndex === 0) { - return null; - } + if (partIndex === 0) { + return null; + } - // literal. - parts[partIndex] = attrValue.substr(pos); + parts[partIndex] = attrValue.substr(pos); - return new InterpolationBindingExpression(this.observerLocator, this.attributeMap[attrName] || attrName, parts, ONE_WAY, resources.valueConverterLookupFunction, attrName); - }, - writable: true, - configurable: true + return new InterpolationBindingExpression(this.observerLocator, this.attributeMap[attrName] || attrName, parts, _Parser$ObserverLocator$BindingExpression$NameExpression$ONE_WAY.ONE_WAY, resources.valueConverterLookupFunction, attrName); } - }); + }], [{ + key: 'inject', + value: function inject() { + return [_Parser$ObserverLocator$BindingExpression$NameExpression$ONE_WAY.Parser, _Parser$ObserverLocator$BindingExpression$NameExpression$ONE_WAY.ObserverLocator, _SyntaxInterpreter.SyntaxInterpreter]; + } + }]); return TemplatingBindingLanguage; -})(BindingLanguage); +})(_BindingLanguage2.BindingLanguage); + +exports.TemplatingBindingLanguage = TemplatingBindingLanguage; -var InterpolationBindingExpression = exports.InterpolationBindingExpression = (function () { +var InterpolationBindingExpression = (function () { function InterpolationBindingExpression(observerLocator, targetProperty, parts, mode, valueConverterLookupFunction, attribute) { _classCallCheck(this, InterpolationBindingExpression); @@ -214,27 +201,26 @@ var InterpolationBindingExpression = exports.InterpolationBindingExpression = (f this.discrete = false; } - _prototypeProperties(InterpolationBindingExpression, null, { - createBinding: { - value: function createBinding(target) { - return new InterpolationBinding(this.observerLocator, this.parts, target, this.targetProperty, this.mode, this.valueConverterLookupFunction); - }, - writable: true, - configurable: true + _createClass(InterpolationBindingExpression, [{ + key: 'createBinding', + value: function createBinding(target) { + return new InterpolationBinding(this.observerLocator, this.parts, target, this.targetProperty, this.mode, this.valueConverterLookupFunction); } - }); + }]); return InterpolationBindingExpression; })(); +exports.InterpolationBindingExpression = InterpolationBindingExpression; + var InterpolationBinding = (function () { function InterpolationBinding(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { _classCallCheck(this, InterpolationBinding); - if (targetProperty === "style") { - logger.info("Internet Explorer does not support interpolation in \"style\" attributes. Use the style attribute's alias, \"css\" instead."); - } else if (target.parentElement && target.parentElement.nodeName === "TEXTAREA" && targetProperty === "textContent") { - throw new Error("Interpolation binding cannot be used in the content of a textarea element. Use instead."); + if (targetProperty === 'style') { + logger.info('Internet Explorer does not support interpolation in "style" attributes. Use the style attribute\'s alias, "css" instead.'); + } else if (target.parentElement && target.parentElement.nodeName === 'TEXTAREA' && targetProperty === 'textContent') { + throw new Error('Interpolation binding cannot be used in the content of a textarea element. Use instead.'); } this.observerLocator = observerLocator; this.parts = parts; @@ -244,110 +230,91 @@ var InterpolationBinding = (function () { this.toDispose = []; } - _prototypeProperties(InterpolationBinding, null, { - getObserver: { - value: function getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); - }, - writable: true, - configurable: true - }, - bind: { - value: function bind(source) { - this.source = source; - - if (this.mode == ONE_WAY) { - this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); - } - }, - writable: true, - configurable: true - }, - setValue: { - value: function setValue() { - var value = this.interpolate(); - this.targetProperty.setValue(value); - }, - writable: true, - configurable: true - }, - connect: { - value: function connect() { - var _this = this; - - var info, - parts = this.parts, - source = this.source, - toDispose = this.toDispose = [], - i, - ii; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 === 0) {} else { - info = parts[i].connect(this, source); - if (info.observer) { - toDispose.push(info.observer.subscribe(function (newValue) { - _this.setValue(); - })); - } + _createClass(InterpolationBinding, [{ + key: 'getObserver', + value: function getObserver(obj, propertyName) { + return this.observerLocator.getObserver(obj, propertyName); + } + }, { + key: 'bind', + value: function bind(source) { + this.source = source; + + if (this.mode == _Parser$ObserverLocator$BindingExpression$NameExpression$ONE_WAY.ONE_WAY) { + this.unbind(); + this.connect(); + this.setValue(); + } else { + this.setValue(); + } + } + }, { + key: 'setValue', + value: function setValue() { + var value = this.interpolate(); + this.targetProperty.setValue(value); + } + }, { + key: 'connect', + value: function connect() { + var _this = this; + + var info, + parts = this.parts, + source = this.source, + toDispose = this.toDispose = [], + i, + ii; + + for (i = 0, ii = parts.length; i < ii; ++i) { + if (i % 2 === 0) {} else { + info = parts[i].connect(this, source); + if (info.observer) { + toDispose.push(info.observer.subscribe(function (newValue) { + _this.setValue(); + })); } } - }, - writable: true, - configurable: true - }, - interpolate: { - value: function interpolate() { - var value = "", - parts = this.parts, - source = this.source, - valueConverterLookupFunction = this.valueConverterLookupFunction, - i, - ii, - temp; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 === 0) { - value += parts[i]; - } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += typeof temp !== "undefined" && temp !== null ? temp.toString() : ""; - } + } + } + }, { + key: 'interpolate', + value: function interpolate() { + var value = '', + parts = this.parts, + source = this.source, + valueConverterLookupFunction = this.valueConverterLookupFunction, + i, + ii, + temp; + + for (i = 0, ii = parts.length; i < ii; ++i) { + if (i % 2 === 0) { + value += parts[i]; + } else { + temp = parts[i].evaluate(source, valueConverterLookupFunction); + value += typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''; } + } - return value; - }, - writable: true, - configurable: true - }, - unbind: { - value: function unbind() { - var i, - ii, - toDispose = this.toDispose; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } + return value; + } + }, { + key: 'unbind', + value: function unbind() { + var i, + ii, + toDispose = this.toDispose; + + if (toDispose) { + for (i = 0, ii = toDispose.length; i < ii; ++i) { + toDispose[i](); } + } - this.toDispose = null; - }, - writable: true, - configurable: true + this.toDispose = null; } - }); + }]); return InterpolationBinding; -})(); - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -//do nothing \ No newline at end of file +})(); \ No newline at end of file diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index 813420b..10f9a25 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -1,29 +1,30 @@ -"use strict"; +'use strict'; -var BindingLanguage = require("aurelia-templating").BindingLanguage; +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _BindingLanguage = require('aurelia-templating'); -var TemplatingBindingLanguage = require("./binding-language").TemplatingBindingLanguage; +var _TemplatingBindingLanguage = require('./binding-language'); -var SyntaxInterpreter = require("./syntax-interpreter").SyntaxInterpreter; +var _SyntaxInterpreter = require('./syntax-interpreter'); function install(aurelia) { var instance, getInstance = function getInstance(c) { - return instance || (instance = c.invoke(TemplatingBindingLanguage)); + return instance || (instance = c.invoke(_TemplatingBindingLanguage.TemplatingBindingLanguage)); }; - if (aurelia.container.hasHandler(TemplatingBindingLanguage)) { - instance = aurelia.container.get(TemplatingBindingLanguage); + if (aurelia.container.hasHandler(_TemplatingBindingLanguage.TemplatingBindingLanguage)) { + instance = aurelia.container.get(_TemplatingBindingLanguage.TemplatingBindingLanguage); } else { - aurelia.container.registerHandler(TemplatingBindingLanguage, getInstance); + aurelia.container.registerHandler(_TemplatingBindingLanguage.TemplatingBindingLanguage, getInstance); } - aurelia.container.registerHandler(BindingLanguage, getInstance); + aurelia.container.registerHandler(_BindingLanguage.BindingLanguage, getInstance); } -exports.TemplatingBindingLanguage = TemplatingBindingLanguage; -exports.SyntaxInterpreter = SyntaxInterpreter; -exports.install = install; -Object.defineProperty(exports, "__esModule", { - value: true -}); \ No newline at end of file +exports.TemplatingBindingLanguage = _TemplatingBindingLanguage.TemplatingBindingLanguage; +exports.SyntaxInterpreter = _SyntaxInterpreter.SyntaxInterpreter; +exports.install = install; \ No newline at end of file diff --git a/dist/commonjs/syntax-interpreter.js b/dist/commonjs/syntax-interpreter.js index 6c5f9a1..eac13ec 100644 --- a/dist/commonjs/syntax-interpreter.js +++ b/dist/commonjs/syntax-interpreter.js @@ -1,23 +1,16 @@ -"use strict"; +'use strict'; -var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; +var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var _aureliaBinding = require("aurelia-binding"); +Object.defineProperty(exports, '__esModule', { + value: true +}); -var Parser = _aureliaBinding.Parser; -var ObserverLocator = _aureliaBinding.ObserverLocator; -var EventManager = _aureliaBinding.EventManager; -var ListenerExpression = _aureliaBinding.ListenerExpression; -var BindingExpression = _aureliaBinding.BindingExpression; -var NameExpression = _aureliaBinding.NameExpression; -var CallExpression = _aureliaBinding.CallExpression; -var ONE_WAY = _aureliaBinding.ONE_WAY; -var TWO_WAY = _aureliaBinding.TWO_WAY; -var ONE_TIME = _aureliaBinding.ONE_TIME; +var _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME = require('aurelia-binding'); -var SyntaxInterpreter = exports.SyntaxInterpreter = (function () { +var SyntaxInterpreter = (function () { function SyntaxInterpreter(parser, observerLocator, eventManager) { _classCallCheck(this, SyntaxInterpreter); @@ -26,198 +19,177 @@ var SyntaxInterpreter = exports.SyntaxInterpreter = (function () { this.eventManager = eventManager; } - _prototypeProperties(SyntaxInterpreter, { - inject: { - value: function inject() { - return [Parser, ObserverLocator, EventManager]; - }, - writable: true, - configurable: true + _createClass(SyntaxInterpreter, [{ + key: 'interpret', + value: function interpret(resources, element, info, existingInstruction) { + if (info.command in this) { + return this[info.command](resources, element, info, existingInstruction); + } + + return this.handleUnknownCommand(resources, element, info, existingInstruction); } }, { - interpret: { - value: function interpret(resources, element, info, existingInstruction) { - if (info.command in this) { - return this[info.command](resources, element, info, existingInstruction); - } + key: 'handleUnknownCommand', + value: function handleUnknownCommand(resources, element, info, existingInstruction) { + var attrName = info.attrName, + command = info.command; - return this.handleUnknownCommand(resources, element, info, existingInstruction); - }, - writable: true, - configurable: true - }, - handleUnknownCommand: { - value: function handleUnknownCommand(resources, element, info, existingInstruction) { - var attrName = info.attrName, - command = info.command; - - var instruction = this.options(resources, element, info, existingInstruction); - - instruction.alteredAttr = true; - instruction.attrName = "global-behavior"; - instruction.attributes.aureliaAttrName = attrName; - instruction.attributes.aureliaCommand = command; - - return instruction; - }, - writable: true, - configurable: true - }, - determineDefaultBindingMode: { - value: function determineDefaultBindingMode(element, attrName) { - var tagName = element.tagName.toLowerCase(); - - if (tagName === "input") { - return attrName === "value" || attrName === "checked" ? TWO_WAY : ONE_WAY; - } else if (tagName == "textarea" || tagName == "select") { - return attrName == "value" ? TWO_WAY : ONE_WAY; - } else if (attrName === "textcontent" || attrName === "innerhtml") { - return element.contentEditable === "true" ? TWO_WAY : ONE_WAY; - } + var instruction = this.options(resources, element, info, existingInstruction); - return ONE_WAY; - }, - writable: true, - configurable: true - }, - bind: { - value: function bind(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName), resources.valueConverterLookupFunction); - - return instruction; - }, - writable: true, - configurable: true - }, - trigger: { - value: function trigger(resources, element, info) { - return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), false, true); - }, - writable: true, - configurable: true - }, - delegate: { - value: function delegate(resources, element, info) { - return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), true, true); - }, - writable: true, - configurable: true - }, - call: { - value: function call(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - - instruction.attributes[info.attrName] = new CallExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), resources.valueConverterLookupFunction); - - return instruction; - }, - writable: true, - configurable: true - }, - options: { - value: function options(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }, - attrValue = info.attrValue, - language = this.language, - name = null, - target = "", - current, - i, - ii; - - for (i = 0, ii = attrValue.length; i < ii; ++i) { - current = attrValue[i]; - - if (current === ";") { - info = language.inspectAttribute(resources, name, target.trim()); - language.createAttributeInstruction(resources, element, info, instruction); - - if (!instruction.attributes[info.attrName]) { - instruction.attributes[info.attrName] = info.attrValue; - } - - target = ""; - name = null; - } else if (current === ":" && name === null) { - name = target.trim(); - target = ""; - } else { - target += current; - } - } + instruction.alteredAttr = true; + instruction.attrName = 'global-behavior'; + instruction.attributes.aureliaAttrName = attrName; + instruction.attributes.aureliaCommand = command; + + return instruction; + } + }, { + key: 'determineDefaultBindingMode', + value: function determineDefaultBindingMode(element, attrName) { + var tagName = element.tagName.toLowerCase(); + + if (tagName === 'input') { + return attrName === 'value' || attrName === 'checked' ? _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.TWO_WAY : _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ONE_WAY; + } else if (tagName == 'textarea' || tagName == 'select') { + return attrName == 'value' ? _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.TWO_WAY : _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ONE_WAY; + } else if (attrName === 'textcontent' || attrName === 'innerhtml') { + return element.contentEditable === 'true' ? _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.TWO_WAY : _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ONE_WAY; + } + + return _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ONE_WAY; + } + }, { + key: 'bind', + value: function bind(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; + + instruction.attributes[info.attrName] = new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName), resources.valueConverterLookupFunction); + + return instruction; + } + }, { + key: 'trigger', + value: function trigger(resources, element, info) { + return new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), false, true); + } + }, { + key: 'delegate', + value: function delegate(resources, element, info) { + return new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), true, true); + } + }, { + key: 'call', + value: function call(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - if (name !== null) { + instruction.attributes[info.attrName] = new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.CallExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), resources.valueConverterLookupFunction); + + return instruction; + } + }, { + key: 'options', + value: function options(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }, + attrValue = info.attrValue, + language = this.language, + name = null, + target = '', + current, + i, + ii; + + for (i = 0, ii = attrValue.length; i < ii; ++i) { + current = attrValue[i]; + + if (current === ';') { info = language.inspectAttribute(resources, name, target.trim()); language.createAttributeInstruction(resources, element, info, instruction); if (!instruction.attributes[info.attrName]) { instruction.attributes[info.attrName] = info.attrValue; } + + target = ''; + name = null; + } else if (current === ':' && name === null) { + name = target.trim(); + target = ''; + } else { + target += current; } + } - return instruction; - }, - writable: true, - configurable: true + if (name !== null) { + info = language.inspectAttribute(resources, name, target.trim()); + language.createAttributeInstruction(resources, element, info, instruction); + + if (!instruction.attributes[info.attrName]) { + instruction.attributes[info.attrName] = info.attrValue; + } + } + + return instruction; + } + }], [{ + key: 'inject', + value: function inject() { + return [_Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.Parser, _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ObserverLocator, _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.EventManager]; } - }); + }]); return SyntaxInterpreter; })(); -SyntaxInterpreter.prototype["for"] = function (resources, element, info, existingInstruction) { - var parts = info.attrValue.split(" of "); +exports.SyntaxInterpreter = SyntaxInterpreter; + +SyntaxInterpreter.prototype['for'] = function (resources, element, info, existingInstruction) { + var parts = info.attrValue.split(' of '); if (parts.length !== 2) { - throw new Error("Incorrect syntax for \"for\". The form is: \"$local of $items\"."); + throw new Error('Incorrect syntax for "for". The form is: "$local of $items".'); } var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; if (parts[0].match(/[[].+[,]\s.+[\]]/)) { var firstPart = parts[0]; - parts[0] = firstPart.substr(1, firstPart.indexOf(",") - 1); - parts.splice(1, 0, firstPart.substring(firstPart.indexOf(", ") + 2, firstPart.length - 1)); + parts[0] = firstPart.substr(1, firstPart.indexOf(',') - 1); + parts.splice(1, 0, firstPart.substring(firstPart.indexOf(', ') + 2, firstPart.length - 1)); instruction.attributes.key = parts[0]; instruction.attributes.value = parts[1]; } else { instruction.attributes.local = parts[0]; } - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, info.attrName, this.parser.parse(parts[parts.length - 1]), ONE_WAY, resources.valueConverterLookupFunction); + instruction.attributes.items = new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[parts.length - 1]), _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ONE_WAY, resources.valueConverterLookupFunction); return instruction; }; -SyntaxInterpreter.prototype["two-way"] = function (resources, element, info, existingInstruction) { +SyntaxInterpreter.prototype['two-way'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), TWO_WAY, resources.valueConverterLookupFunction); + instruction.attributes[info.attrName] = new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.BindingExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.TWO_WAY, resources.valueConverterLookupFunction); return instruction; }; -SyntaxInterpreter.prototype["one-way"] = function (resources, element, info, existingInstruction) { +SyntaxInterpreter.prototype['one-way'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), ONE_WAY, resources.valueConverterLookupFunction); + instruction.attributes[info.attrName] = new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ONE_WAY, resources.valueConverterLookupFunction); return instruction; }; -SyntaxInterpreter.prototype["one-time"] = function (resources, element, info, existingInstruction) { +SyntaxInterpreter.prototype['one-time'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), ONE_TIME, resources.valueConverterLookupFunction); + instruction.attributes[info.attrName] = new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.ONE_TIME, resources.valueConverterLookupFunction); return instruction; }; -SyntaxInterpreter.prototype["view-model"] = function (resources, element, info) { - return new NameExpression(info.attrValue, "view-model"); -}; -Object.defineProperty(exports, "__esModule", { - value: true -}); \ No newline at end of file +SyntaxInterpreter.prototype['view-model'] = function (resources, element, info) { + return new _Parser$ObserverLocator$EventManager$ListenerExpression$BindingExpression$NameExpression$CallExpression$ONE_WAY$TWO_WAY$ONE_TIME.NameExpression(info.attrValue, 'view-model'); +}; \ No newline at end of file diff --git a/dist/es6/binding-language.js b/dist/es6/binding-language.js index e90ce28..d7138e7 100644 --- a/dist/es6/binding-language.js +++ b/dist/es6/binding-language.js @@ -9,6 +9,7 @@ var info = {}, export class TemplatingBindingLanguage extends BindingLanguage { static inject() { return [Parser, ObserverLocator, SyntaxInterpreter]; } constructor(parser, observerLocator, syntaxInterpreter){ + super(); this.parser = parser; this.observerLocator = observerLocator; this.syntaxInterpreter = syntaxInterpreter; diff --git a/dist/es6/syntax-interpreter.js b/dist/es6/syntax-interpreter.js index 3a16d5f..aee6d03 100644 --- a/dist/es6/syntax-interpreter.js +++ b/dist/es6/syntax-interpreter.js @@ -161,9 +161,9 @@ SyntaxInterpreter.prototype['for'] = function(resources, element, info, existing instruction.attributes.local = parts[0]; } - instruction.attributes[info.attrName] = new BindingExpression( + instruction.attributes.items = new BindingExpression( this.observerLocator, - info.attrName, + 'items', this.parser.parse(parts[parts.length - 1]), ONE_WAY, resources.valueConverterLookupFunction diff --git a/dist/system/binding-language.js b/dist/system/binding-language.js index 526a92a..bd89a25 100644 --- a/dist/system/binding-language.js +++ b/dist/system/binding-language.js @@ -1,5 +1,5 @@ -System.register(["aurelia-templating", "aurelia-binding", "./syntax-interpreter", "aurelia-logging"], function (_export) { - var BindingLanguage, Parser, ObserverLocator, BindingExpression, NameExpression, ONE_WAY, SyntaxInterpreter, LogManager, _prototypeProperties, _inherits, _classCallCheck, info, logger, TemplatingBindingLanguage, InterpolationBindingExpression, InterpolationBinding; +System.register(['aurelia-templating', 'aurelia-binding', './syntax-interpreter', 'aurelia-logging'], function (_export) { + var BindingLanguage, Parser, ObserverLocator, BindingExpression, NameExpression, ONE_WAY, SyntaxInterpreter, LogManager, _classCallCheck, _createClass, _get, _inherits, info, logger, TemplatingBindingLanguage, InterpolationBindingExpression, InterpolationBinding; return { setters: [function (_aureliaTemplating) { @@ -16,192 +16,181 @@ System.register(["aurelia-templating", "aurelia-binding", "./syntax-interpreter" LogManager = _aureliaLogging; }], execute: function () { - "use strict"; + 'use strict'; - _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; + _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; + _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; + _get = function get(object, property, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + + _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }; info = {}; - logger = LogManager.getLogger("templating-binding"); - TemplatingBindingLanguage = _export("TemplatingBindingLanguage", (function (BindingLanguage) { + logger = LogManager.getLogger('templating-binding'); + + TemplatingBindingLanguage = (function (_BindingLanguage) { function TemplatingBindingLanguage(parser, observerLocator, syntaxInterpreter) { _classCallCheck(this, TemplatingBindingLanguage); + _get(Object.getPrototypeOf(TemplatingBindingLanguage.prototype), 'constructor', this).call(this); this.parser = parser; this.observerLocator = observerLocator; this.syntaxInterpreter = syntaxInterpreter; - this.emptyStringExpression = this.parser.parse("''"); + this.emptyStringExpression = this.parser.parse('\'\''); syntaxInterpreter.language = this; this.attributeMap = syntaxInterpreter.attributeMap = { - "class": "className", - "for": "htmlFor", - tabindex: "tabIndex", - textcontent: "textContent", - innerhtml: "innerHTML", - // HTMLInputElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement - maxlength: "maxLength", - minlength: "minLength", - formaction: "formAction", - formenctype: "formEncType", - formmethod: "formMethod", - formnovalidate: "formNoValidate", - formtarget: "formTarget" }; + 'class': 'className', + 'for': 'htmlFor', + tabindex: 'tabIndex', + textcontent: 'textContent', + innerhtml: 'innerHTML', + maxlength: 'maxLength', + minlength: 'minLength', + formaction: 'formAction', + formenctype: 'formEncType', + formmethod: 'formMethod', + formnovalidate: 'formNoValidate', + formtarget: 'formTarget' }; } - _inherits(TemplatingBindingLanguage, BindingLanguage); - - _prototypeProperties(TemplatingBindingLanguage, { - inject: { - value: function inject() { - return [Parser, ObserverLocator, SyntaxInterpreter]; - }, - writable: true, - configurable: true + _inherits(TemplatingBindingLanguage, _BindingLanguage); + + _createClass(TemplatingBindingLanguage, [{ + key: 'inspectAttribute', + value: function inspectAttribute(resources, attrName, attrValue) { + var parts = attrName.split('.'); + + info.defaultBindingMode = null; + + if (parts.length == 2) { + info.attrName = parts[0].trim(); + info.attrValue = attrValue; + info.command = parts[1].trim(); + info.expression = null; + } else if (attrName == 'ref') { + info.attrName = attrName; + info.attrValue = attrValue; + info.command = null; + info.expression = new NameExpression(attrValue, 'element'); + } else { + info.attrName = attrName; + info.attrValue = attrValue; + info.command = null; + info.expression = this.parseContent(resources, attrName, attrValue); + } + + return info; } }, { - inspectAttribute: { - value: function inspectAttribute(resources, attrName, attrValue) { - var parts = attrName.split("."); - - info.defaultBindingMode = null; - - if (parts.length == 2) { - info.attrName = parts[0].trim(); - info.attrValue = attrValue; - info.command = parts[1].trim(); - info.expression = null; - } else if (attrName == "ref") { - info.attrName = attrName; - info.attrValue = attrValue; - info.command = null; - info.expression = new NameExpression(attrValue, "element"); - } else { - info.attrName = attrName; - info.attrValue = attrValue; - info.command = null; - info.expression = this.parseContent(resources, attrName, attrValue); + key: 'createAttributeInstruction', + value: function createAttributeInstruction(resources, element, info, existingInstruction) { + var instruction; + + if (info.expression) { + if (info.attrName === 'ref') { + return info.expression; } - return info; - }, - writable: true, - configurable: true - }, - createAttributeInstruction: { - value: function createAttributeInstruction(resources, element, info, existingInstruction) { - var instruction; - - if (info.expression) { - if (info.attrName === "ref") { - return info.expression; + instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; + instruction.attributes[info.attrName] = info.expression; + } else if (info.command) { + instruction = this.syntaxInterpreter.interpret(resources, element, info, existingInstruction); + } + + return instruction; + } + }, { + key: 'parseText', + value: function parseText(resources, value) { + return this.parseContent(resources, 'textContent', value); + } + }, { + key: 'parseContent', + value: function parseContent(resources, attrName, attrValue) { + var i = attrValue.indexOf('${', 0), + ii = attrValue.length, + char, + pos = 0, + open = 0, + quote = null, + interpolationStart, + parts, + partIndex = 0; + while (i >= 0 && i < ii - 2) { + open = 1; + interpolationStart = i; + i += 2; + + do { + char = attrValue[i]; + i++; + switch (char) { + case '\'': + case '"': + if (quote === null) { + quote = char; + } else if (quote === char) { + quote = null; + } + continue; + case '\\': + i++; + continue; } - instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - instruction.attributes[info.attrName] = info.expression; - } else if (info.command) { - instruction = this.syntaxInterpreter.interpret(resources, element, info, existingInstruction); - } + if (quote !== null) { + continue; + } - return instruction; - }, - writable: true, - configurable: true - }, - parseText: { - value: function parseText(resources, value) { - return this.parseContent(resources, "textContent", value); - }, - writable: true, - configurable: true - }, - parseContent: { - value: function parseContent(resources, attrName, attrValue) { - var i = attrValue.indexOf("${", 0), - ii = attrValue.length, - char, - pos = 0, - open = 0, - quote = null, - interpolationStart, - parts, - partIndex = 0; - while (i >= 0 && i < ii - 2) { - open = 1; - interpolationStart = i; - i += 2; - - do { - char = attrValue[i]; - i++; - switch (char) { - case "'": - case "\"": - if (quote === null) { - quote = char; - } else if (quote === char) { - quote = null; - } - continue; - case "\\": - i++; - continue; - } - - if (quote !== null) { - continue; - } - - if (char === "{") { - open++; - } else if (char === "}") { - open--; - } - } while (open > 0 && i < ii); - - if (open === 0) { - // lazy allocate array - parts = parts || []; - if (attrValue[interpolationStart - 1] === "\\" && attrValue[interpolationStart - 2] !== "\\") { - // escaped interpolation - parts[partIndex] = attrValue.substring(pos, interpolationStart - 1) + attrValue.substring(interpolationStart, i); - partIndex++; - parts[partIndex] = this.emptyStringExpression; - partIndex++; - } else { - // standard interpolation - parts[partIndex] = attrValue.substring(pos, interpolationStart); - partIndex++; - parts[partIndex] = this.parser.parse(attrValue.substring(interpolationStart + 2, i - 1)); - partIndex++; - } - pos = i; - i = attrValue.indexOf("${", i); + if (char === '{') { + open++; + } else if (char === '}') { + open--; + } + } while (open > 0 && i < ii); + + if (open === 0) { + parts = parts || []; + if (attrValue[interpolationStart - 1] === '\\' && attrValue[interpolationStart - 2] !== '\\') { + parts[partIndex] = attrValue.substring(pos, interpolationStart - 1) + attrValue.substring(interpolationStart, i); + partIndex++; + parts[partIndex] = this.emptyStringExpression; + partIndex++; } else { - break; + parts[partIndex] = attrValue.substring(pos, interpolationStart); + partIndex++; + parts[partIndex] = this.parser.parse(attrValue.substring(interpolationStart + 2, i - 1)); + partIndex++; } + pos = i; + i = attrValue.indexOf('${', i); + } else { + break; } + } - // no interpolation. - if (partIndex === 0) { - return null; - } + if (partIndex === 0) { + return null; + } - // literal. - parts[partIndex] = attrValue.substr(pos); + parts[partIndex] = attrValue.substr(pos); - return new InterpolationBindingExpression(this.observerLocator, this.attributeMap[attrName] || attrName, parts, ONE_WAY, resources.valueConverterLookupFunction, attrName); - }, - writable: true, - configurable: true + return new InterpolationBindingExpression(this.observerLocator, this.attributeMap[attrName] || attrName, parts, ONE_WAY, resources.valueConverterLookupFunction, attrName); } - }); + }], [{ + key: 'inject', + value: function inject() { + return [Parser, ObserverLocator, SyntaxInterpreter]; + } + }]); return TemplatingBindingLanguage; - })(BindingLanguage)); - InterpolationBindingExpression = _export("InterpolationBindingExpression", (function () { + })(BindingLanguage); + + _export('TemplatingBindingLanguage', TemplatingBindingLanguage); + + InterpolationBindingExpression = (function () { function InterpolationBindingExpression(observerLocator, targetProperty, parts, mode, valueConverterLookupFunction, attribute) { _classCallCheck(this, InterpolationBindingExpression); @@ -214,27 +203,26 @@ System.register(["aurelia-templating", "aurelia-binding", "./syntax-interpreter" this.discrete = false; } - _prototypeProperties(InterpolationBindingExpression, null, { - createBinding: { - value: function createBinding(target) { - return new InterpolationBinding(this.observerLocator, this.parts, target, this.targetProperty, this.mode, this.valueConverterLookupFunction); - }, - writable: true, - configurable: true + _createClass(InterpolationBindingExpression, [{ + key: 'createBinding', + value: function createBinding(target) { + return new InterpolationBinding(this.observerLocator, this.parts, target, this.targetProperty, this.mode, this.valueConverterLookupFunction); } - }); + }]); return InterpolationBindingExpression; - })()); + })(); + + _export('InterpolationBindingExpression', InterpolationBindingExpression); InterpolationBinding = (function () { function InterpolationBinding(observerLocator, parts, target, targetProperty, mode, valueConverterLookupFunction) { _classCallCheck(this, InterpolationBinding); - if (targetProperty === "style") { - logger.info("Internet Explorer does not support interpolation in \"style\" attributes. Use the style attribute's alias, \"css\" instead."); - } else if (target.parentElement && target.parentElement.nodeName === "TEXTAREA" && targetProperty === "textContent") { - throw new Error("Interpolation binding cannot be used in the content of a textarea element. Use instead."); + if (targetProperty === 'style') { + logger.info('Internet Explorer does not support interpolation in "style" attributes. Use the style attribute\'s alias, "css" instead.'); + } else if (target.parentElement && target.parentElement.nodeName === 'TEXTAREA' && targetProperty === 'textContent') { + throw new Error('Interpolation binding cannot be used in the content of a textarea element. Use instead.'); } this.observerLocator = observerLocator; this.parts = parts; @@ -244,109 +232,94 @@ System.register(["aurelia-templating", "aurelia-binding", "./syntax-interpreter" this.toDispose = []; } - _prototypeProperties(InterpolationBinding, null, { - getObserver: { - value: function getObserver(obj, propertyName) { - return this.observerLocator.getObserver(obj, propertyName); - }, - writable: true, - configurable: true - }, - bind: { - value: function bind(source) { - this.source = source; - - if (this.mode == ONE_WAY) { - this.unbind(); - this.connect(); - this.setValue(); - } else { - this.setValue(); - } - }, - writable: true, - configurable: true - }, - setValue: { - value: function setValue() { - var value = this.interpolate(); - this.targetProperty.setValue(value); - }, - writable: true, - configurable: true - }, - connect: { - value: function connect() { - var _this = this; - - var info, - parts = this.parts, - source = this.source, - toDispose = this.toDispose = [], - i, - ii; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 === 0) {} else { - info = parts[i].connect(this, source); - if (info.observer) { - toDispose.push(info.observer.subscribe(function (newValue) { - _this.setValue(); - })); - } + _createClass(InterpolationBinding, [{ + key: 'getObserver', + value: function getObserver(obj, propertyName) { + return this.observerLocator.getObserver(obj, propertyName); + } + }, { + key: 'bind', + value: function bind(source) { + this.source = source; + + if (this.mode == ONE_WAY) { + this.unbind(); + this.connect(); + this.setValue(); + } else { + this.setValue(); + } + } + }, { + key: 'setValue', + value: function setValue() { + var value = this.interpolate(); + this.targetProperty.setValue(value); + } + }, { + key: 'connect', + value: function connect() { + var _this = this; + + var info, + parts = this.parts, + source = this.source, + toDispose = this.toDispose = [], + i, + ii; + + for (i = 0, ii = parts.length; i < ii; ++i) { + if (i % 2 === 0) {} else { + info = parts[i].connect(this, source); + if (info.observer) { + toDispose.push(info.observer.subscribe(function (newValue) { + _this.setValue(); + })); } } - }, - writable: true, - configurable: true - }, - interpolate: { - value: function interpolate() { - var value = "", - parts = this.parts, - source = this.source, - valueConverterLookupFunction = this.valueConverterLookupFunction, - i, - ii, - temp; - - for (i = 0, ii = parts.length; i < ii; ++i) { - if (i % 2 === 0) { - value += parts[i]; - } else { - temp = parts[i].evaluate(source, valueConverterLookupFunction); - value += typeof temp !== "undefined" && temp !== null ? temp.toString() : ""; - } + } + } + }, { + key: 'interpolate', + value: function interpolate() { + var value = '', + parts = this.parts, + source = this.source, + valueConverterLookupFunction = this.valueConverterLookupFunction, + i, + ii, + temp; + + for (i = 0, ii = parts.length; i < ii; ++i) { + if (i % 2 === 0) { + value += parts[i]; + } else { + temp = parts[i].evaluate(source, valueConverterLookupFunction); + value += typeof temp !== 'undefined' && temp !== null ? temp.toString() : ''; } + } - return value; - }, - writable: true, - configurable: true - }, - unbind: { - value: function unbind() { - var i, - ii, - toDispose = this.toDispose; - - if (toDispose) { - for (i = 0, ii = toDispose.length; i < ii; ++i) { - toDispose[i](); - } + return value; + } + }, { + key: 'unbind', + value: function unbind() { + var i, + ii, + toDispose = this.toDispose; + + if (toDispose) { + for (i = 0, ii = toDispose.length; i < ii; ++i) { + toDispose[i](); } + } - this.toDispose = null; - }, - writable: true, - configurable: true + this.toDispose = null; } - }); + }]); return InterpolationBinding; })(); } }; -}); - -//do nothing \ No newline at end of file +}); \ No newline at end of file diff --git a/dist/system/index.js b/dist/system/index.js index fa739f3..295630f 100644 --- a/dist/system/index.js +++ b/dist/system/index.js @@ -1,4 +1,4 @@ -System.register(["aurelia-templating", "./binding-language", "./syntax-interpreter"], function (_export) { +System.register(['aurelia-templating', './binding-language', './syntax-interpreter'], function (_export) { var BindingLanguage, TemplatingBindingLanguage, SyntaxInterpreter; function install(aurelia) { @@ -25,13 +25,13 @@ System.register(["aurelia-templating", "./binding-language", "./syntax-interpret SyntaxInterpreter = _syntaxInterpreter.SyntaxInterpreter; }], execute: function () { - "use strict"; + 'use strict'; - _export("TemplatingBindingLanguage", TemplatingBindingLanguage); + _export('TemplatingBindingLanguage', TemplatingBindingLanguage); - _export("SyntaxInterpreter", SyntaxInterpreter); + _export('SyntaxInterpreter', SyntaxInterpreter); - _export("install", install); + _export('install', install); } }; }); \ No newline at end of file diff --git a/dist/system/syntax-interpreter.js b/dist/system/syntax-interpreter.js index a795caf..e3ac084 100644 --- a/dist/system/syntax-interpreter.js +++ b/dist/system/syntax-interpreter.js @@ -1,5 +1,5 @@ -System.register(["aurelia-binding"], function (_export) { - var Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, NameExpression, CallExpression, ONE_WAY, TWO_WAY, ONE_TIME, _prototypeProperties, _classCallCheck, SyntaxInterpreter; +System.register(['aurelia-binding'], function (_export) { + var Parser, ObserverLocator, EventManager, ListenerExpression, BindingExpression, NameExpression, CallExpression, ONE_WAY, TWO_WAY, ONE_TIME, _classCallCheck, _createClass, SyntaxInterpreter; return { setters: [function (_aureliaBinding) { @@ -15,13 +15,13 @@ System.register(["aurelia-binding"], function (_export) { ONE_TIME = _aureliaBinding.ONE_TIME; }], execute: function () { - "use strict"; + 'use strict'; - _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; + _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; + _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - SyntaxInterpreter = _export("SyntaxInterpreter", (function () { + SyntaxInterpreter = (function () { function SyntaxInterpreter(parser, observerLocator, eventManager) { _classCallCheck(this, SyntaxInterpreter); @@ -30,172 +30,154 @@ System.register(["aurelia-binding"], function (_export) { this.eventManager = eventManager; } - _prototypeProperties(SyntaxInterpreter, { - inject: { - value: function inject() { - return [Parser, ObserverLocator, EventManager]; - }, - writable: true, - configurable: true + _createClass(SyntaxInterpreter, [{ + key: 'interpret', + value: function interpret(resources, element, info, existingInstruction) { + if (info.command in this) { + return this[info.command](resources, element, info, existingInstruction); + } + + return this.handleUnknownCommand(resources, element, info, existingInstruction); } }, { - interpret: { - value: function interpret(resources, element, info, existingInstruction) { - if (info.command in this) { - return this[info.command](resources, element, info, existingInstruction); - } + key: 'handleUnknownCommand', + value: function handleUnknownCommand(resources, element, info, existingInstruction) { + var attrName = info.attrName, + command = info.command; - return this.handleUnknownCommand(resources, element, info, existingInstruction); - }, - writable: true, - configurable: true - }, - handleUnknownCommand: { - value: function handleUnknownCommand(resources, element, info, existingInstruction) { - var attrName = info.attrName, - command = info.command; - - var instruction = this.options(resources, element, info, existingInstruction); - - instruction.alteredAttr = true; - instruction.attrName = "global-behavior"; - instruction.attributes.aureliaAttrName = attrName; - instruction.attributes.aureliaCommand = command; - - return instruction; - }, - writable: true, - configurable: true - }, - determineDefaultBindingMode: { - value: function determineDefaultBindingMode(element, attrName) { - var tagName = element.tagName.toLowerCase(); - - if (tagName === "input") { - return attrName === "value" || attrName === "checked" ? TWO_WAY : ONE_WAY; - } else if (tagName == "textarea" || tagName == "select") { - return attrName == "value" ? TWO_WAY : ONE_WAY; - } else if (attrName === "textcontent" || attrName === "innerhtml") { - return element.contentEditable === "true" ? TWO_WAY : ONE_WAY; - } + var instruction = this.options(resources, element, info, existingInstruction); - return ONE_WAY; - }, - writable: true, - configurable: true - }, - bind: { - value: function bind(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName), resources.valueConverterLookupFunction); - - return instruction; - }, - writable: true, - configurable: true - }, - trigger: { - value: function trigger(resources, element, info) { - return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), false, true); - }, - writable: true, - configurable: true - }, - delegate: { - value: function delegate(resources, element, info) { - return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), true, true); - }, - writable: true, - configurable: true - }, - call: { - value: function call(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; - - instruction.attributes[info.attrName] = new CallExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), resources.valueConverterLookupFunction); - - return instruction; - }, - writable: true, - configurable: true - }, - options: { - value: function options(resources, element, info, existingInstruction) { - var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }, - attrValue = info.attrValue, - language = this.language, - name = null, - target = "", - current, - i, - ii; - - for (i = 0, ii = attrValue.length; i < ii; ++i) { - current = attrValue[i]; - - if (current === ";") { - info = language.inspectAttribute(resources, name, target.trim()); - language.createAttributeInstruction(resources, element, info, instruction); - - if (!instruction.attributes[info.attrName]) { - instruction.attributes[info.attrName] = info.attrValue; - } - - target = ""; - name = null; - } else if (current === ":" && name === null) { - name = target.trim(); - target = ""; - } else { - target += current; - } - } + instruction.alteredAttr = true; + instruction.attrName = 'global-behavior'; + instruction.attributes.aureliaAttrName = attrName; + instruction.attributes.aureliaCommand = command; + + return instruction; + } + }, { + key: 'determineDefaultBindingMode', + value: function determineDefaultBindingMode(element, attrName) { + var tagName = element.tagName.toLowerCase(); + + if (tagName === 'input') { + return attrName === 'value' || attrName === 'checked' ? TWO_WAY : ONE_WAY; + } else if (tagName == 'textarea' || tagName == 'select') { + return attrName == 'value' ? TWO_WAY : ONE_WAY; + } else if (attrName === 'textcontent' || attrName === 'innerhtml') { + return element.contentEditable === 'true' ? TWO_WAY : ONE_WAY; + } + + return ONE_WAY; + } + }, { + key: 'bind', + value: function bind(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; + + instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), info.defaultBindingMode || this.determineDefaultBindingMode(element, info.attrName), resources.valueConverterLookupFunction); - if (name !== null) { + return instruction; + } + }, { + key: 'trigger', + value: function trigger(resources, element, info) { + return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), false, true); + } + }, { + key: 'delegate', + value: function delegate(resources, element, info) { + return new ListenerExpression(this.eventManager, info.attrName, this.parser.parse(info.attrValue), true, true); + } + }, { + key: 'call', + value: function call(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; + + instruction.attributes[info.attrName] = new CallExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), resources.valueConverterLookupFunction); + + return instruction; + } + }, { + key: 'options', + value: function options(resources, element, info, existingInstruction) { + var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }, + attrValue = info.attrValue, + language = this.language, + name = null, + target = '', + current, + i, + ii; + + for (i = 0, ii = attrValue.length; i < ii; ++i) { + current = attrValue[i]; + + if (current === ';') { info = language.inspectAttribute(resources, name, target.trim()); language.createAttributeInstruction(resources, element, info, instruction); if (!instruction.attributes[info.attrName]) { instruction.attributes[info.attrName] = info.attrValue; } + + target = ''; + name = null; + } else if (current === ':' && name === null) { + name = target.trim(); + target = ''; + } else { + target += current; + } + } + + if (name !== null) { + info = language.inspectAttribute(resources, name, target.trim()); + language.createAttributeInstruction(resources, element, info, instruction); + + if (!instruction.attributes[info.attrName]) { + instruction.attributes[info.attrName] = info.attrValue; } + } - return instruction; - }, - writable: true, - configurable: true + return instruction; + } + }], [{ + key: 'inject', + value: function inject() { + return [Parser, ObserverLocator, EventManager]; } - }); + }]); return SyntaxInterpreter; - })()); + })(); + + _export('SyntaxInterpreter', SyntaxInterpreter); - SyntaxInterpreter.prototype["for"] = function (resources, element, info, existingInstruction) { - var parts = info.attrValue.split(" of "); + SyntaxInterpreter.prototype['for'] = function (resources, element, info, existingInstruction) { + var parts = info.attrValue.split(' of '); if (parts.length !== 2) { - throw new Error("Incorrect syntax for \"for\". The form is: \"$local of $items\"."); + throw new Error('Incorrect syntax for "for". The form is: "$local of $items".'); } var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; if (parts[0].match(/[[].+[,]\s.+[\]]/)) { var firstPart = parts[0]; - parts[0] = firstPart.substr(1, firstPart.indexOf(",") - 1); - parts.splice(1, 0, firstPart.substring(firstPart.indexOf(", ") + 2, firstPart.length - 1)); + parts[0] = firstPart.substr(1, firstPart.indexOf(',') - 1); + parts.splice(1, 0, firstPart.substring(firstPart.indexOf(', ') + 2, firstPart.length - 1)); instruction.attributes.key = parts[0]; instruction.attributes.value = parts[1]; } else { instruction.attributes.local = parts[0]; } - instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, info.attrName, this.parser.parse(parts[parts.length - 1]), ONE_WAY, resources.valueConverterLookupFunction); + instruction.attributes.items = new BindingExpression(this.observerLocator, 'items', this.parser.parse(parts[parts.length - 1]), ONE_WAY, resources.valueConverterLookupFunction); return instruction; }; - SyntaxInterpreter.prototype["two-way"] = function (resources, element, info, existingInstruction) { + SyntaxInterpreter.prototype['two-way'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, info.attrName, this.parser.parse(info.attrValue), TWO_WAY, resources.valueConverterLookupFunction); @@ -203,7 +185,7 @@ System.register(["aurelia-binding"], function (_export) { return instruction; }; - SyntaxInterpreter.prototype["one-way"] = function (resources, element, info, existingInstruction) { + SyntaxInterpreter.prototype['one-way'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), ONE_WAY, resources.valueConverterLookupFunction); @@ -211,7 +193,7 @@ System.register(["aurelia-binding"], function (_export) { return instruction; }; - SyntaxInterpreter.prototype["one-time"] = function (resources, element, info, existingInstruction) { + SyntaxInterpreter.prototype['one-time'] = function (resources, element, info, existingInstruction) { var instruction = existingInstruction || { attrName: info.attrName, attributes: {} }; instruction.attributes[info.attrName] = new BindingExpression(this.observerLocator, this.attributeMap[info.attrName] || info.attrName, this.parser.parse(info.attrValue), ONE_TIME, resources.valueConverterLookupFunction); @@ -219,8 +201,8 @@ System.register(["aurelia-binding"], function (_export) { return instruction; }; - SyntaxInterpreter.prototype["view-model"] = function (resources, element, info) { - return new NameExpression(info.attrValue, "view-model"); + SyntaxInterpreter.prototype['view-model'] = function (resources, element, info) { + return new NameExpression(info.attrValue, 'view-model'); }; } }; diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 5069dff..4b32b80 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -1,3 +1,12 @@ +## 0.10.0 (2015-04-09) + + +#### Bug Fixes + +* **all:** upgrade compiler ([9676dd24](http://github.com/aurelia/templating-binding/commit/9676dd2442a3a3ccfa4a0873ee52c2ae7148b1a4)) +* **syntax-interpreter:** make repeater to work with new behavior model ([5e1137e3](http://github.com/aurelia/templating-binding/commit/5e1137e3a8272bd6f9d1e3eb13a535de9346528e)) + + ## 0.9.0 (2015-03-25) #### Features diff --git a/package.json b/package.json index 77983eb..13319c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-templating-binding", - "version": "0.9.0", + "version": "0.10.0", "description": "An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.", "keywords": [ "aurelia", @@ -26,9 +26,9 @@ "lib": "dist/system" }, "dependencies": { - "aurelia-binding": "github:aurelia/binding@^0.4.0", - "aurelia-logging": "github:aurelia/logging@^0.2.6", - "aurelia-templating": "github:aurelia/templating@^0.9.0" + "aurelia-binding": "github:aurelia/binding@^0.5.0", + "aurelia-logging": "github:aurelia/logging@^0.3.0", + "aurelia-templating": "github:aurelia/templating@^0.10.0" } }, "devDependencies": {