Skip to content

Commit

Permalink
Move goog.reflect code from lib/base.js to lib/reflect.js for ease in…
Browse files Browse the repository at this point in the history
… migration.

PiperOrigin-RevId: 635949985
  • Loading branch information
Closure Team authored and copybara-github committed May 21, 2024
1 parent 29b2b21 commit ea46242
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 71 deletions.
71 changes: 0 additions & 71 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,74 +943,3 @@ goog.exportSymbol = function(publicPath, object, objectToExportTo) {
goog.exportProperty = function(object, publicName, symbol) {
object[publicName] = symbol;
};


/**
* Useful compiler idioms related to renaming.
* @const
*/
goog.reflect = {};


/**
* Syntax for object literal casts.
* @see https://goo.gl/CRs09P
*
* Use this if you have an object literal whose keys need to have the same names
* as the properties of some class even after they are renamed by the compiler.
*
* @param {!Function} type Type to cast to.
* @param {!Object} object Object literal to cast.
* @return {!Object} The object literal.
*/
goog.reflect.object = function(type, object) {
'use strict';
return object;
};


/**
* Syntax for renaming property strings.
* @see https://goo.gl/CRs09P
*
* Use this if you have an need to access a property as a string, but want
* to also have the property renamed by the compiler. In contrast to
* goog.reflect.object, this method takes an instance of an object.
*
* Properties must be simple names (not qualified names).
*
* @param {string} prop Name of the property
* @param {!Object} object Instance of the object whose type will be used
* for renaming
* @return {string} The renamed property.
*/
goog.reflect.objectProperty = function(prop, object) {
'use strict';
return prop;
};


/**
* To assert to the compiler that an operation is needed when it would
* otherwise be stripped. For example:
*
* ```javascript
* // Force a layout
* goog.reflect.sinkValue(dialog.offsetHeight);
* ```
* @param {T} x
* @return {T}
* @template T
*/
goog.reflect.sinkValue = function(x) {
'use strict';
goog.reflect.sinkValue[' '](x);
return x;
};


/**
* The compiler should optimize this function away iff no one ever uses
* goog.reflect.sinkValue.
*/
goog.reflect.sinkValue[' '] = function() {};
76 changes: 76 additions & 0 deletions lib/reflect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @license
* Copyright The Closure Library Authors.
* Copyright The Closure Compiler Authors.
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Useful compiler idioms related to renaming.
*/

goog.provide('goog.reflect');


/**
* Syntax for object literal casts.
* @see https://goo.gl/CRs09P
*
* Use this if you have an object literal whose keys need to have the same names
* as the properties of some class even after they are renamed by the compiler.
*
* @param {!Function} type Type to cast to.
* @param {!Object} object Object literal to cast.
* @return {!Object} The object literal.
*/
goog.reflect.object = function(type, object) {
'use strict';
return object;
};


/**
* Syntax for renaming property strings.
* @see https://goo.gl/CRs09P
*
* Use this if you have an need to access a property as a string, but want
* to also have the property renamed by the compiler. In contrast to
* goog.reflect.object, this method takes an instance of an object.
*
* Properties must be simple names (not qualified names).
*
* @param {string} prop Name of the property
* @param {!Object} object Instance of the object whose type will be used
* for renaming
* @return {string} The renamed property.
*/
goog.reflect.objectProperty = function(prop, object) {
'use strict';
return prop;
};


/**
* To assert to the compiler that an operation is needed when it would
* otherwise be stripped. For example:
*
* ```javascript
* // Force a layout
* goog.reflect.sinkValue(dialog.offsetHeight);
* ```
* @param {T} x
* @return {T}
* @template T
*/
goog.reflect.sinkValue = function(x) {
'use strict';
goog.reflect.sinkValue[' '](x);
return x;
};


/**
* The compiler should optimize this function away iff no one ever uses
* goog.reflect.sinkValue.
*/
goog.reflect.sinkValue[' '] = function() {};

0 comments on commit ea46242

Please sign in to comment.