diff options
author | vitalyp <vitalyp@chromium.org> | 2014-09-26 13:18:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-26 20:18:19 +0000 |
commit | 51a0be3f517537580b83752b7c569d163f42216d (patch) | |
tree | b3eba4ce3450d5ba4656696e7923805953360f2a /third_party/jstemplate | |
parent | 90d07e614c526dd382e7dbb64732a73781b31af3 (diff) | |
download | chromium_src-51a0be3f517537580b83752b7c569d163f42216d.zip chromium_src-51a0be3f517537580b83752b7c569d163f42216d.tar.gz chromium_src-51a0be3f517537580b83752b7c569d163f42216d.tar.bz2 |
Compile third_party/jstemplate/ with Closure Compiler
R=arv@chromium.org
BUG=393873
TEST=GYP_GENERATORS=ninja gyp --depth . third_party/jstemplate/compiled_resources.gyp && ninja -C out/Default
Review URL: https://codereview.chromium.org/603693002
Cr-Commit-Position: refs/heads/master@{#297018}
Diffstat (limited to 'third_party/jstemplate')
-rw-r--r-- | third_party/jstemplate/compiled_resources.gyp | 17 | ||||
-rw-r--r-- | third_party/jstemplate/jsevalcontext.js | 36 | ||||
-rw-r--r-- | third_party/jstemplate/jstemplate.js | 19 | ||||
-rw-r--r-- | third_party/jstemplate/util.js | 28 |
4 files changed, 57 insertions, 43 deletions
diff --git a/third_party/jstemplate/compiled_resources.gyp b/third_party/jstemplate/compiled_resources.gyp new file mode 100644 index 0000000..7ad8373 --- /dev/null +++ b/third_party/jstemplate/compiled_resources.gyp @@ -0,0 +1,17 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +{ + 'targets': [ + { + 'target_name': 'jstemplate', + 'variables': { + 'depends': [ + 'util.js', + 'jsevalcontext.js', + ], + }, + 'includes': ['../../third_party/closure_compiler/compile_js.gypi'], + } + ], +} diff --git a/third_party/jstemplate/jsevalcontext.js b/third_party/jstemplate/jsevalcontext.js index 0fc00ff7..52bbc62c 100644 --- a/third_party/jstemplate/jsevalcontext.js +++ b/third_party/jstemplate/jsevalcontext.js @@ -50,8 +50,8 @@ var REGEXP_semicolon = /\s*;\s*/; /** * See constructor_() - * @param {Object|null} opt_data - * @param {Object} opt_parent + * @param {Object|null=} opt_data + * @param {Object=} opt_parent * @constructor */ function JsEvalContext(opt_data, opt_parent) { @@ -69,22 +69,23 @@ function JsEvalContext(opt_data, opt_parent) { * variables are inherited. Normally the context object of the parent * context is the object whose property the parent object is. Null for the * context of the root object. + * @private */ JsEvalContext.prototype.constructor_ = function(opt_data, opt_parent) { var me = this; - /** - * The context for variable definitions in which the jstemplate - * expressions are evaluated. Other than for the local context, - * which replaces the parent context, variable definitions of the - * parent are inherited. The special variable $this points to data_. - * - * If this instance is recycled from the cache, then the property is - * already initialized. - * - * @type {Object} - */ if (!me.vars_) { + /** + * The context for variable definitions in which the jstemplate + * expressions are evaluated. Other than for the local context, + * which replaces the parent context, variable definitions of the + * parent are inherited. The special variable $this points to data_. + * + * If this instance is recycled from the cache, then the property is + * already initialized. + * + * @type {Object} + */ me.vars_ = {}; } if (opt_parent) { @@ -102,7 +103,7 @@ JsEvalContext.prototype.constructor_ = function(opt_data, opt_parent) { /** * The current context object is assigned to the special variable * $this so it is possible to use it in expressions. - * @type Object + * @type {Object} */ me.vars_[VAR_this] = opt_data; @@ -123,7 +124,7 @@ JsEvalContext.prototype.constructor_ = function(opt_data, opt_parent) { * above, but for the expression context we replace null and * undefined by the empty string. * - * @type {Object|null} + * @type {*} */ me.data_ = getDefaultObject(opt_data, STRING_empty); @@ -264,8 +265,7 @@ JsEvalContext.prototype.clone = function(data, index, count) { * API they only have to be valid javascript identifier. * * @param {string} name - * - * @param {Object?} value + * @param {*} value */ JsEvalContext.prototype.setVariable = function(name, value) { this.vars_[name] = value; @@ -280,7 +280,7 @@ JsEvalContext.prototype.setVariable = function(name, value) { * * @param {string} name * - * @return {Object?} value + * @return {*} value */ JsEvalContext.prototype.getVariable = function(name) { return this.vars_[name]; diff --git a/third_party/jstemplate/jstemplate.js b/third_party/jstemplate/jstemplate.js index 39cbc4df..ac113d4 100644 --- a/third_party/jstemplate/jstemplate.js +++ b/third_party/jstemplate/jstemplate.js @@ -823,7 +823,7 @@ JstProcessor.prototype.jstAttributes_ = function(template) { * returning the template. * * @param {string} name The ID of the HTML element used as template. - * @param {Function} opt_loadHtmlFn A function which, when called, will return + * @param {Function=} opt_loadHtmlFn A function which, when called, will return * HTML that contains an element whose ID is 'name'. * * @return {Element|null} The DOM node of the template. (Only element nodes @@ -860,8 +860,10 @@ function jstGetTemplate(name, opt_loadHtmlFn) { */ function jstGetTemplateOrDie(name, opt_loadHtmlFn) { var x = jstGetTemplate(name, opt_loadHtmlFn); - check(x !== null); - return /** @type Element */(x); + if (x === null) { + throw new Error('jstGetTemplate() returned null'); + } + return /** @type {Element} */(x); } @@ -873,7 +875,7 @@ function jstGetTemplateOrDie(name, opt_loadHtmlFn) { * @param {string} name * @param {Function} loadHtmlFn A function that returns HTML to be inserted * into the DOM. - * @param {string} opt_target The id of a DOM object under which to attach the + * @param {string=} opt_target The id of a DOM object under which to attach the * HTML once it's inserted. An object with this id is created if it does not * exist. * @return {Element} The node whose id is 'name' @@ -956,12 +958,3 @@ function jstSetInstance(template, values, index) { JstProcessor.prototype.logState_ = function( caller, template, jstAttributeValues) { }; - - -/** - * Retrieve the processing logs. - * @return {Array.<string>} The processing logs. - */ -JstProcessor.prototype.getLogs = function() { - return this.logs_; -}; diff --git a/third_party/jstemplate/util.js b/third_party/jstemplate/util.js index beed591..798998c 100644 --- a/third_party/jstemplate/util.js +++ b/third_party/jstemplate/util.js @@ -55,7 +55,12 @@ function jsEval(expr) { // function literals in IE. // e.g. eval("(function() {})") returns undefined, and not a function // object, in IE. - return eval('[' + expr + '][0]'); + var result = eval('[' + expr + '][0]'); + if (typeof result != 'object') { + throw new Error('expression of type Object expected, ' + + typeof result + ' found'); + } + return /** @type {Object} */(result); } catch (e) { log('EVAL FAILED ' + expr + ': ' + e); return null; @@ -66,8 +71,6 @@ function jsLength(obj) { return obj.length; } -function assert(obj) {} - /** * Copies all properties from second object to the first. Modifies to. * @@ -82,14 +85,13 @@ function copyProperties(to, from) { /** - * @param {Object|null|undefined} value The possible value to use. - * @param {Object} defaultValue The default if the value is not set. - * @return {Object} The value, if it is - * defined and not null; otherwise the default + * @param {*} value The possible value to use. + * @param {*} defaultValue The default if the value is not set. + * @return {*} The value, if it is defined and not null; otherwise the default. */ function getDefaultObject(value, defaultValue) { if (typeof value != TYPE_undefined && value != null) { - return /** @type Object */(value); + return value; } else { return defaultValue; } @@ -112,9 +114,9 @@ function isArray(value) { /** * Finds a slice of an array. * - * @param {Array} array Array to be sliced. + * @param {Array|Arguments} array Array to be sliced. * @param {number} start The start of the slice. - * @param {number} opt_end The end of the slice (optional). + * @param {number=} opt_end The end of the slice (optional). * @return {Array} array The slice of the array from start to end. */ function arraySlice(array, start, opt_end) { @@ -125,7 +127,8 @@ function arraySlice(array, start, opt_end) { // here because of a bug in the FF and IE implementations of // Array.prototype.slice which causes this function to return an empty list // if opt_end is not provided. - return Function.prototype.call.apply(Array.prototype.slice, arguments); + return /** @type {Array} */( + Function.prototype.call.apply(Array.prototype.slice, arguments)); } @@ -161,6 +164,7 @@ function arrayClear(array) { * * @param {Object|null} object The object that the method call targets. * @param {Function} method The target method. + * @param {...*} var_args * @return {Function} Method with the target object bound to it and curried by * the provided arguments. */ @@ -420,7 +424,7 @@ function domRemoveNode(node) { /** * Remove a child from the specified (parent) node. * - * @param {Element} node Parent element. + * @param {Node} node Parent element. * @param {Node} child Child node to remove. * @return {Node} Removed node. */ |