Skip to content

Commit

Permalink
Compile third_party/jstemplate/ with Closure Compiler
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
vitalyp authored and Commit bot committed Sep 26, 2014
1 parent 90d07e6 commit 51a0be3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 43 deletions.
17 changes: 17 additions & 0 deletions third_party/jstemplate/compiled_resources.gyp
Original file line number Diff line number Diff line change
@@ -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'],
}
],
}
36 changes: 18 additions & 18 deletions third_party/jstemplate/jsevalcontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;

Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand Down
19 changes: 6 additions & 13 deletions third_party/jstemplate/jstemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}


Expand All @@ -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'
Expand Down Expand Up @@ -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_;
};
28 changes: 16 additions & 12 deletions third_party/jstemplate/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -66,8 +71,6 @@ function jsLength(obj) {
return obj.length;
}

function assert(obj) {}

/**
* Copies all properties from second object to the first. Modifies to.
*
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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));
}


Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 51a0be3

Please sign in to comment.