Skip to content

Commit

Permalink
js:Enable ADVANCED_OPTIMIZATIONS in Closure Compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbubudi committed Dec 30, 2018
1 parent 2194073 commit fb8c6bf
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 61 deletions.
78 changes: 78 additions & 0 deletions js/binary/reader.js

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions js/binary/writer.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions js/commonjs/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ goog.require('jspb.ExtensionFieldInfo');
goog.require('jspb.Message');
goog.require('jspb.Map');

exports.Map = jspb.Map;
exports.Message = jspb.Message;
exports.BinaryReader = jspb.BinaryReader;
exports.BinaryWriter = jspb.BinaryWriter;
exports.ExtensionFieldInfo = jspb.ExtensionFieldInfo;
exports.ExtensionFieldBinaryInfo = jspb.ExtensionFieldBinaryInfo;
exports['Map'] = jspb.Map;
exports['Message'] = jspb.Message;
exports['BinaryReader'] = jspb.BinaryReader;
exports['BinaryWriter'] = jspb.BinaryWriter;
exports['ExtensionFieldInfo'] = jspb.ExtensionFieldInfo;
exports['ExtensionFieldBinaryInfo'] = jspb.ExtensionFieldBinaryInfo;

// These are used by generated code but should not be used directly by clients.
exports.exportSymbol = goog.exportSymbol;
exports.inherits = goog.inherits;
exports.object = {extend: goog.object.extend};
exports.typeOf = goog.typeOf;
exports['exportSymbol'] = goog.exportSymbol;
exports['inherits'] = goog.inherits;
exports['object'] = {extend: goog.object.extend};
exports['typeOf'] = goog.typeOf;
7 changes: 0 additions & 7 deletions js/commonjs/export_testdeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,5 @@ goog.provide('jspb.ExportTestDeps');

goog.require('goog.crypt.base64');
goog.require('goog.testing.PropertyReplacer');
goog.require('jspb.arith.Int64');
goog.require('jspb.arith.UInt64');
goog.require('jspb.BinaryEncoder');
goog.require('jspb.BinaryDecoder');
goog.require('jspb.BinaryWriter');
goog.require('jspb.utils');

exports.goog = goog;
exports.jspb = jspb;
2 changes: 1 addition & 1 deletion js/commonjs/rewrite_tests_for_commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ console.log("var global = Function('return this')();");
console.log("var googleProtobuf = require('google-protobuf');");
console.log("var testdeps = require('testdeps_commonjs');");
console.log("global.goog = testdeps.goog;");
console.log("global.jspb = testdeps.jspb;");
console.log("global.jspb = googleProtobuf.jspb;");
console.log("var asserts = require('closure_asserts_commonjs');");
console.log("");
console.log("// Bring asserts into the global namespace.");
Expand Down
15 changes: 12 additions & 3 deletions js/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,18 @@ gulp.task('genproto_group3_commonjs_strict', function (cb) {
});


function getClosureBuilderCommand(exportsFile, outputFile) {
function getClosureBuilderCommand(exportsFile, outputFile, keepSymbols) {
var compilationLevel = 'ADVANCED_OPTIMIZATIONS';
if (keepSymbols === true) {
compilationLevel = 'SIMPLE_OPTIMIZATIONS';
}
return './node_modules/google-closure-library/closure/bin/build/closurebuilder.py ' +
'--root node_modules ' +
'-o compiled ' +
'--compiler_jar node_modules/google-closure-compiler/compiler.jar ' +
`--compiler_flags="--compilation_level=${compilationLevel}" ` +
'--compiler_flags="--generate_exports" ' +
'--compiler_flags="--export_local_property_definitions" ' +
'-i ' + exportsFile + ' ' +
'map.js message.js binary/arith.js binary/constants.js binary/decoder.js ' +
'binary/encoder.js binary/reader.js binary/utils.js binary/writer.js ' +
Expand All @@ -159,7 +166,8 @@ gulp.task('commonjs_asserts', function (cb) {
exec('mkdir -p commonjs_out/test_node_modules && ' +
getClosureBuilderCommand(
'commonjs/export_asserts.js',
'commonjs_out/test_node_modules/closure_asserts_commonjs.js'),
'commonjs_out/test_node_modules/closure_asserts_commonjs.js',
true),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
Expand All @@ -171,7 +179,8 @@ gulp.task('commonjs_testdeps', function (cb) {
exec('mkdir -p commonjs_out/test_node_modules && ' +
getClosureBuilderCommand(
'commonjs/export_testdeps.js',
'commonjs_out/test_node_modules/testdeps_commonjs.js'),
'commonjs_out/test_node_modules/testdeps_commonjs.js',
true),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
Expand Down
18 changes: 18 additions & 0 deletions js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ goog.forwardDeclare('jspb.BinaryWriter');
*
* @constructor
* @struct
* @export
*/
jspb.Map = function(arr, opt_valueCtor) {
/** @const @private */
Expand All @@ -68,6 +69,7 @@ jspb.Map = function(arr, opt_valueCtor) {
/**
* Is `this.arr_ updated with respect to `this.map_`?
* @type {boolean}
* @export
*/
this.arrClean = true;

Expand Down Expand Up @@ -95,6 +97,7 @@ jspb.Map.prototype.loadFromArray_ = function() {
/**
* Synchronize content to underlying array, if needed, and return it.
* @return {!Array<!Array<!Object>>}
* @export
*/
jspb.Map.prototype.toArray = function() {
if (this.arrClean) {
Expand Down Expand Up @@ -139,6 +142,7 @@ jspb.Map.prototype.toArray = function() {
* @param {function((boolean|undefined),V):!Object=} valueToObject
* The static toObject() method, if V is a message type.
* @return {!Array<!Array<!Object>>}
* @export
*/
jspb.Map.prototype.toObject = function(includeInstance, valueToObject) {
var rawArray = this.toArray();
Expand Down Expand Up @@ -170,6 +174,7 @@ jspb.Map.prototype.toObject = function(includeInstance, valueToObject) {
* @param {function(!Object):V} valueFromObject
* The fromObject function for type V.
* @return {!jspb.Map<K, V>}
* @export
*/
jspb.Map.fromObject = function(entries, valueCtor, valueFromObject) {
var result = new jspb.Map([], valueCtor);
Expand Down Expand Up @@ -219,6 +224,7 @@ if (typeof(Symbol) != 'undefined') {
/**
* Returns the map's length (number of key/value pairs).
* @return {number}
* @export
*/
jspb.Map.prototype.getLength = function() {
return this.stringKeys_().length;
Expand All @@ -227,6 +233,7 @@ jspb.Map.prototype.getLength = function() {

/**
* Clears the map.
* @export
*/
jspb.Map.prototype.clear = function() {
this.map_ = {};
Expand All @@ -241,6 +248,7 @@ jspb.Map.prototype.clear = function() {
* @this {jspb.Map}
* @param {K} key
* @return {boolean} Whether any entry with this key was deleted.
* @export
*/
jspb.Map.prototype.del = function(key) {
var keyValue = key.toString();
Expand All @@ -259,6 +267,7 @@ jspb.Map.prototype.del = function(key) {
* option.
*
* @return {!Array<!Array<K|V>>}
* @export
*/
jspb.Map.prototype.getEntryList = function() {
var entries = [];
Expand All @@ -276,6 +285,7 @@ jspb.Map.prototype.getEntryList = function() {
* Returns an iterator-iterable over [key, value] pairs in the map.
* Closure compiler sadly doesn't support tuples, ie. Iterator<[K,V]>.
* @return {!IteratorIterable<!Array<K|V>>} The iterator-iterable.
* @export
*/
jspb.Map.prototype.entries = function() {
var entries = [];
Expand All @@ -292,6 +302,7 @@ jspb.Map.prototype.entries = function() {
/**
* Returns an iterator-iterable over keys in the map.
* @return {!IteratorIterable<K>} The iterator-iterable.
* @export
*/
jspb.Map.prototype.keys = function() {
var keys = [];
Expand All @@ -308,6 +319,7 @@ jspb.Map.prototype.keys = function() {
/**
* Returns an iterator-iterable over values in the map.
* @return {!IteratorIterable<V>} The iterator-iterable.
* @export
*/
jspb.Map.prototype.values = function() {
var values = [];
Expand All @@ -326,6 +338,7 @@ jspb.Map.prototype.values = function() {
* @template T
* @param {function(this:T, V, K, ?jspb.Map<K, V>)} cb
* @param {T=} opt_thisArg
* @export
*/
jspb.Map.prototype.forEach = function(cb, opt_thisArg) {
var strKeys = this.stringKeys_();
Expand All @@ -342,6 +355,7 @@ jspb.Map.prototype.forEach = function(cb, opt_thisArg) {
* @param {K} key The key
* @param {V} value The value
* @return {!jspb.Map<K,V>}
* @export
*/
jspb.Map.prototype.set = function(key, value) {
var entry = new jspb.Map.Entry_(key);
Expand Down Expand Up @@ -382,6 +396,7 @@ jspb.Map.prototype.wrapEntry_ = function(entry) {
* Gets the value corresponding to a key in the map.
* @param {K} key
* @return {V|undefined} The value, or `undefined` if key not present
* @export
*/
jspb.Map.prototype.get = function(key) {
var keyValue = key.toString();
Expand All @@ -398,6 +413,7 @@ jspb.Map.prototype.get = function(key) {
* Determines whether the given key is present in the map.
* @param {K} key
* @return {boolean} `true` if the key is present
* @export
*/
jspb.Map.prototype.has = function(key) {
var keyValue = key.toString();
Expand All @@ -419,6 +435,7 @@ jspb.Map.prototype.has = function(key) {
* @param {function(V,!jspb.BinaryWriter)=} opt_valueWriterCallback
* The BinaryWriter serialization callback for type V, if V is a message
* type.
* @export
*/
jspb.Map.prototype.serializeBinary = function(
fieldNumber, writer, keyWriterFn, valueWriterFn, opt_valueWriterCallback) {
Expand Down Expand Up @@ -465,6 +482,7 @@ jspb.Map.prototype.serializeBinary = function(
* entries with unset keys is required for maps to be backwards compatible
* with the repeated message representation described here: goo.gl/zuoLAC
*
* @export
*/
jspb.Map.deserializeBinary = function(map, reader, keyReaderFn, valueReaderFn,
opt_valueReaderCallback, opt_defaultKey) {
Expand Down
Loading

0 comments on commit fb8c6bf

Please sign in to comment.