Make polymer-expressions/path-parser a simple CommonJS module.

The weird module.exports code broke the webpack parser.
This commit is contained in:
Hristo Deshev
2015-12-02 18:47:05 +02:00
parent 643f9bf901
commit fa264d9374

View File

@ -7,10 +7,9 @@
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
(function (global) {
'use strict';
'use strict';
function detectEval() {
function detectEval() {
// Don't test for eval if we're running in a Chrome App environment.
// We check for APIs set that only exist in a Chrome App context.
if (typeof chrome !== 'undefined' && chrome.app && chrome.app.runtime) {
@ -30,36 +29,36 @@
} catch (ex) {
return false;
}
}
}
var hasEval = detectEval();
var hasEval = detectEval();
function isIndex(s) {
function isIndex(s) {
return +s === s >>> 0 && s !== '';
}
}
function toNumber(s) {
function toNumber(s) {
return +s;
}
}
function isObject(obj) {
function isObject(obj) {
return obj === Object(obj);
}
}
var numberIsNaN = global.Number.isNaN || function (value) {
return typeof value === 'number' && global.isNaN(value);
}
var numberIsNaN = Number.isNaN || function (value) {
return typeof value === 'number' && isNaN(value);
}
function areSameValue(left, right) {
function areSameValue(left, right) {
if (left === right)
return left !== 0 || 1 / left === 1 / right;
if (numberIsNaN(left) && numberIsNaN(right))
return true;
return left !== left && right !== right;
}
}
var createObject = ('__proto__' in {}) ?
var createObject = ('__proto__' in {}) ?
function (obj) { return obj; } :
function (obj) {
var proto = obj.__proto__;
@ -73,11 +72,11 @@
return newObject;
};
var identStart = '[\$_a-zA-Z]';
var identPart = '[\$_a-zA-Z0-9]';
var identRegExp = new RegExp('^' + identStart + '+' + identPart + '*' + '$');
var identStart = '[\$_a-zA-Z]';
var identPart = '[\$_a-zA-Z0-9]';
var identRegExp = new RegExp('^' + identStart + '+' + identPart + '*' + '$');
function getPathCharType(char) {
function getPathCharType(char) {
if (char === undefined)
return 'eof';
@ -116,9 +115,9 @@
return 'number';
return 'else';
}
}
var pathStateMachine = {
var pathStateMachine = {
'beforePath': {
'ws': ['beforePath'],
'ident': ['inIdent', 'append'],
@ -184,11 +183,11 @@
'ws': ['afterElement'],
']': ['inPath', 'push']
}
}
}
function noop() { }
function noop() { }
function parsePath(path) {
function parsePath(path) {
var keys = [];
var index = -1;
var c, newChar, key, type, transition, action, typeMap, mode = 'beforePath';
@ -249,15 +248,15 @@
}
return; // parse error
}
}
function isIdent(s) {
function isIdent(s) {
return identRegExp.test(s);
}
}
var constructorIsPrivate = {};
var constructorIsPrivate = {};
function Path(parts, privateToken) {
function Path(parts, privateToken) {
if (privateToken !== constructorIsPrivate)
throw Error('Use Path.get to retrieve path objects');
@ -268,12 +267,12 @@
if (hasEval && this.length) {
this.getValueFrom = this.compiledGetValueFromFn();
}
}
}
// TODO(rafaelw): Make simple LRU cache
var pathCache = {};
// TODO(rafaelw): Make simple LRU cache
var pathCache = {};
function getPath(pathString) {
function getPath(pathString) {
if (pathString instanceof Path)
return pathString;
@ -300,19 +299,19 @@
var path = new Path(parts, constructorIsPrivate);
pathCache[pathString] = path;
return path;
}
}
Path.get = getPath;
Path.get = getPath;
function formatAccessor(key) {
function formatAccessor(key) {
if (isIndex(key)) {
return '[' + key + ']';
} else {
return '["' + key.replace(/"/g, '\\"') + '"]';
}
}
}
Path.prototype = createObject({
Path.prototype = createObject({
__proto__: [],
valid: true,
@ -385,25 +384,10 @@
obj[this[i]] = value;
return true;
}
});
});
var invalidPath = new Path('', constructorIsPrivate);
invalidPath.valid = false;
invalidPath.getValueFrom = invalidPath.setValueFrom = function () { };
var invalidPath = new Path('', constructorIsPrivate);
invalidPath.valid = false;
invalidPath.getValueFrom = invalidPath.setValueFrom = function () { };
// Export the observe-js object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're in
// the browser, export as a global object.
var expose = global;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
expose = exports = module.exports;
}
expose = exports;
}
expose.Path = Path;
})(typeof global !== 'undefined' && global && typeof module !== 'undefined' && module ? global : this || window);
exports.Path = Path;