Skip to content

Commit

Permalink
Update the wgxpath library.
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyba committed Jun 13, 2013
1 parent d3d26e5 commit 074c96d
Show file tree
Hide file tree
Showing 30 changed files with 307 additions and 212 deletions.
36 changes: 27 additions & 9 deletions third_party/closure/goog/useragent/useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ goog.userAgent.compare = function(v1, v2) {


/**
* Cache for {@link goog.userAgent.isVersion}. Calls to compareVersions are
* surprisingly expensive and as a browsers version number is unlikely to change
* during a session we cache the results.
* @type {Object}
* Cache for {@link goog.userAgent.isVersionOrHigher}.
* Calls to compareVersions are surprisingly expensive and, as a browser's
* version number is unlikely to change during a session, we cache the results.
* @const
* @private
*/
goog.userAgent.isVersionCache_ = {};
goog.userAgent.isVersionOrHigherCache_ = {};


/**
Expand All @@ -465,14 +465,23 @@ goog.userAgent.isVersionCache_ = {};
* @return {boolean} Whether the user agent version is higher or the same as
* the given version.
*/
goog.userAgent.isVersion = function(version) {
goog.userAgent.isVersionOrHigher = function(version) {
return goog.userAgent.ASSUME_ANY_VERSION ||
goog.userAgent.isVersionCache_[version] ||
(goog.userAgent.isVersionCache_[version] =
goog.userAgent.isVersionOrHigherCache_[version] ||
(goog.userAgent.isVersionOrHigherCache_[version] =
goog.string.compareVersions(goog.userAgent.VERSION, version) >= 0);
};


/**
* Deprecated alias to {@code goog.userAgent.isVersionOrHigher}.
* @param {string|number} version The version to check.
* @return {boolean} Whether the user agent version is higher or the same as
* the given version.
*/
goog.userAgent.isVersion = goog.userAgent.isVersionOrHigher;


/**
* Whether the IE effective document mode is higher or the same as the given
* document mode version.
Expand All @@ -482,11 +491,20 @@ goog.userAgent.isVersion = function(version) {
* @return {boolean} Whether the IE effective document mode is higher or the
* same as the given version.
*/
goog.userAgent.isDocumentMode = function(documentMode) {
goog.userAgent.isDocumentModeOrHigher = function(documentMode) {
return goog.userAgent.IE && goog.userAgent.DOCUMENT_MODE >= documentMode;
};


/**
* Deprecated alias to {@code goog.userAgent.isDocumentModeOrHigher}.
* @param {number} version The version to check.
* @return {boolean} Whether the IE effective document mode is higher or the
* same as the given version.
*/
goog.userAgent.isDocumentMode = goog.userAgent.isDocumentModeOrHigher;


/**
* For IE version < 7, documentMode is undefined, so attempt to use the
* CSS1Compat property to see if we are in standards mode. If we are in
Expand Down
14 changes: 6 additions & 8 deletions third_party/js/wgxpath/binaryExpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ wgxpath.BinaryExpr.prototype.evaluate = function(ctx) {
/**
* @override
*/
wgxpath.BinaryExpr.prototype.toString = function(opt_indent) {
var indent = opt_indent || '';
var text = indent + 'binary expression: ' + this.op_ + '\n';
indent += wgxpath.Expr.INDENT;
text += this.left_.toString(indent) + '\n';
text += this.right_.toString(indent);
wgxpath.BinaryExpr.prototype.toString = function() {
var text = 'Binary Expression: ' + this.op_;
text += wgxpath.Expr.indent(this.left_);
text += wgxpath.Expr.indent(this.right_);
return text;
};

Expand Down Expand Up @@ -249,9 +247,9 @@ wgxpath.BinaryExpr.createOp_ = function(opString, precedence, dataType,
throw new Error('Binary operator already created: ' + opString);
}
// The upcast and then downcast for the JSCompiler.
var op = (/** @type {!Object} */ new wgxpath.BinaryExpr.Op_(
var op = /** @type {!Object} */ (new wgxpath.BinaryExpr.Op_(
opString, precedence, dataType, evaluate));
op = (/** @type {!wgxpath.BinaryExpr.Op} */ op);
op = /** @type {!wgxpath.BinaryExpr.Op} */ (op);
wgxpath.BinaryExpr.stringToOpMap_[op.toString()] = op;
return op;
};
Expand Down
2 changes: 1 addition & 1 deletion third_party/js/wgxpath/binaryExpr_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>
<title>Binary Expression Test</title>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="test_js_deps.js"></script>
<script src="./test_js_deps.js"></script>
<script>
goog.require('goog.testing.jsunit');
goog.require('wgxpath.BinaryExpr');
Expand Down
5 changes: 3 additions & 2 deletions third_party/js/wgxpath/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ python ../closure-library/closure/bin/calcdeps.py \
--path ../closure-library \
--path . \
--input export.js \
--compiler_jar ../closure-compiler/build/compiler.jar \
--output_mode compiled \
--compiler_jar ../closure-compiler/build/compiler.jar \
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" \
--compiler_flags="--output_wrapper=(function(){%output%})()" \
--compiler_flags="--use_types_for_optimization" \
> wgxpath.install.js
--compiler_flags="--warning_level=VERBOSE" \
> wgxpath.install.js
2 changes: 1 addition & 1 deletion third_party/js/wgxpath/context_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<title>context_test</title>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="test_js_deps.js"></script>
<script src="./test_js_deps.js"></script>
<script>
goog.require('goog.testing.jsunit');
goog.require('wgxpath.Context');
Expand Down
15 changes: 7 additions & 8 deletions third_party/js/wgxpath/expr.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ wgxpath.Expr = function(dataType) {


/**
* A default indentation for pretty printing.
* Indentation method for pretty printing.
*
* @const
* @type {string}
* @param {*} obj The object to return a string representation for.
* @return {string} The string prepended with newline and two spaces.
*/
wgxpath.Expr.INDENT = ' ';
wgxpath.Expr.indent = function(obj) {
return '\n ' + obj.toString().split('\n').join('\n ');
};


/**
Expand All @@ -64,10 +66,7 @@ wgxpath.Expr.prototype.evaluate = goog.abstractMethod;


/**
* Returns the string representation of the expression for debugging.
*
* @param {string=} opt_indent An optional indentation.
* @return {string} The string representation.
* @override
*/
wgxpath.Expr.prototype.toString = goog.abstractMethod;

Expand Down
10 changes: 4 additions & 6 deletions third_party/js/wgxpath/filterExpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ wgxpath.FilterExpr.prototype.evaluate = function(ctx) {
/**
* @override
*/
wgxpath.FilterExpr.prototype.toString = function(opt_indent) {
var indent = opt_indent || '';
var text = indent + 'Filter: ' + '\n';
indent += wgxpath.Expr.INDENT;
text += this.primary_.toString(indent);
text += this.predicates_.toString(indent);
wgxpath.FilterExpr.prototype.toString = function() {
var text = 'Filter:';
text += wgxpath.Expr.indent(this.primary_);
text += wgxpath.Expr.indent(this.predicates_);
return text;
};
17 changes: 7 additions & 10 deletions third_party/js/wgxpath/functionCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,13 @@ wgxpath.FunctionCall.prototype.evaluate = function(ctx) {
/**
* @override
*/
wgxpath.FunctionCall.prototype.toString = function(opt_indent) {
var indent = opt_indent || '';
var text = indent + 'Function: ' + this.func_ + '\n';
indent += wgxpath.Expr.INDENT;
wgxpath.FunctionCall.prototype.toString = function() {
var text = 'Function: ' + this.func_;
if (this.args_.length) {
text += indent + 'Arguments:';
indent += wgxpath.Expr.INDENT;
text = goog.array.reduce(this.args_, function(prev, curr) {
return prev + '\n' + curr.toString(indent);
}, text);
var args = goog.array.reduce(this.args_, function(prev, curr) {
return prev + wgxpath.Expr.indent(curr);
}, 'Arguments:');
text += wgxpath.Expr.indent(args);
}
return text;
};
Expand Down Expand Up @@ -228,7 +225,7 @@ wgxpath.FunctionCall.createFunc_ = function(name, dataType,
var func = new wgxpath.FunctionCall.Func_(name, dataType,
needContextPosition, needContextNodeWithoutArgs, needContextNodeWithArgs,
evaluate, minArgs, opt_maxArgs, opt_nodesetsRequired);
func = (/** @type {!wgxpath.FunctionCall.Func} */ func);
func = /** @type {!wgxpath.FunctionCall.Func} */ (func);
wgxpath.FunctionCall.nameToFuncMap_[name] = func;
return func;
};
Expand Down
9 changes: 3 additions & 6 deletions third_party/js/wgxpath/kindTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,11 @@ wgxpath.KindTest.prototype.getName = function() {

/**
* @override
* @param {string=} opt_indent Optional indentation.
* @return {string} The string representation.
*/
wgxpath.KindTest.prototype.toString = function(opt_indent) {
var indent = opt_indent || '';
var text = indent + 'kindtest: ' + this.typeName_;
wgxpath.KindTest.prototype.toString = function() {
var text = 'Kind Test: ' + this.typeName_;
if (!goog.isNull(this.literal_)) {
text += '\n' + this.literal_.toString(indent + wgxpath.Expr.INDENT);
text += wgxpath.Expr.indent(this.literal_);
}
return text;
};
2 changes: 1 addition & 1 deletion third_party/js/wgxpath/kindTest_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<head>
<title>kindTest_test</title>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="test_js_deps.js"></script>
<script src="./test_js_deps.js"></script>
<script>
goog.require('goog.dom.NodeType');
goog.require('goog.testing.jsunit');
Expand Down
2 changes: 1 addition & 1 deletion third_party/js/wgxpath/lexer_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<head>
<title>lexer_test</title>
<script src="../closure-library/closure/goog/base.js"></script>
<script src="test_js_deps.js"></script>
<script src="./test_js_deps.js"></script>
<script>
goog.require('goog.testing.jsunit');
goog.require('wgxpath.Lexer');
Expand Down
5 changes: 2 additions & 3 deletions third_party/js/wgxpath/literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ wgxpath.Literal.prototype.evaluate = function(context) {
/**
* @override
*/
wgxpath.Literal.prototype.toString = function(opt_indent) {
var indent = opt_indent || '';
return indent + 'literal: ' + this.text_;
wgxpath.Literal.prototype.toString = function() {
return 'Literal: ' + this.text_;
};
53 changes: 37 additions & 16 deletions third_party/js/wgxpath/nameTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,54 @@ goog.require('goog.dom.NodeType');
* Constructs a NameTest based on the xpath grammar:
* http://www.w3.org/TR/xpath/#NT-NameTest
*
* <p>If no namespace is provided, the default HTML namespace is used.
*
* @param {string} name Name to be tested.
* @param {string=} opt_namespaceUri Namespace URI; defaults to HTML namespace.
* @constructor
* @implements {wgxpath.NodeTest}
*/
wgxpath.NameTest = function(name) {
wgxpath.NameTest = function(name, opt_namespaceUri) {
/**
* @type {string}
* @private
*/
this.name_ = name.toLowerCase();

/**
* @type {string}
* @private
*/
this.namespaceUri_ = opt_namespaceUri ? opt_namespaceUri.toLowerCase() :
wgxpath.NameTest.HTML_NAMESPACE_URI_;
};


/**
* The default namespace for XHTML nodes.
* The default namespace URI for XHTML nodes.
*
* @const
* @type {string}
* @private
*/
wgxpath.NameTest.HTML_NAMESPACE_ = 'http://www.w3.org/1999/xhtml';
wgxpath.NameTest.HTML_NAMESPACE_URI_ = 'http://www.w3.org/1999/xhtml';


/**
* @override
*/
wgxpath.NameTest.prototype.matches = function(node) {
var type = node.nodeType;
if (type == goog.dom.NodeType.ELEMENT ||
type == goog.dom.NodeType.ATTRIBUTE) {
if (this.name_ == '*' || this.name_ == node.nodeName.toLowerCase()) {
return true;
} else {
var namespace = node.namespaceURI || wgxpath.NameTest.HTML_NAMESPACE_;
return this.name_ == namespace + ':*';
}
if (type != goog.dom.NodeType.ELEMENT &&
type != goog.dom.NodeType.ATTRIBUTE) {
return false;
}
if (this.name_ != '*' && this.name_ != node.nodeName.toLowerCase()) {
return false;
} else {
var namespaceUri = node.namespaceURI ? node.namespaceURI.toLowerCase() :
wgxpath.NameTest.HTML_NAMESPACE_URI_;
return this.namespaceUri_ == namespaceUri;
}
};

Expand All @@ -62,12 +74,21 @@ wgxpath.NameTest.prototype.getName = function() {
};


/**
* Returns the namespace URI to be matched.
*
* @return {string} Namespace URI.
*/
wgxpath.NameTest.prototype.getNamespaceUri = function() {
return this.namespaceUri_;
};


/**
* @override
* @param {string=} opt_indent Optional indentation.
* @return {string} The string representation.
*/
wgxpath.NameTest.prototype.toString = function(opt_indent) {
var indent = opt_indent || '';
return indent + 'nametest: ' + this.name_;
wgxpath.NameTest.prototype.toString = function() {
var prefix = this.namespaceUri_ == wgxpath.NameTest.HTML_NAMESPACE_URI_ ?
'' : this.namespaceUri_ + ':';
return 'Name Test: ' + prefix + this.name_;
};
Loading

0 comments on commit 074c96d

Please sign in to comment.