Skip to content

Commit

Permalink
Move MapEntry type def to global scope.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148802193
  • Loading branch information
qiy authored and brad4d committed Mar 2, 2017
1 parent 819a1f1 commit 3a7464d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
87 changes: 48 additions & 39 deletions src/com/google/javascript/jscomp/js/es6/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@
'require util/owns';
'require util/polyfill';


/**
* Internal record type for entries.
* @record
* @template KEY, VALUE
*/
$jscomp.MapEntry = function() {};


/** @type {!$jscomp.MapEntry<KEY, VALUE>} */
$jscomp.MapEntry.prototype.previous;


/** @type {!$jscomp.MapEntry<KEY, VALUE>} */
$jscomp.MapEntry.prototype.next;


/** @type {?Object} */
$jscomp.MapEntry.prototype.head;


/** @type {KEY} */
$jscomp.MapEntry.prototype.key;


/** @type {VALUE} */
$jscomp.MapEntry.prototype.value;


/**
* Whether to skip the conformance check and simply use the polyfill always.
* @define {boolean}
Expand Down Expand Up @@ -70,34 +99,6 @@ $jscomp.polyfill('Map', function(NativeMap) {
var idMap = new WeakMap();


/**
* Internal record type for entries.
* @record
* @template KEY, VALUE
*/
var MapEntry = function() {};


/** @type {!MapEntry<KEY, VALUE>} */
MapEntry.prototype.previous;


/** @type {!MapEntry<KEY, VALUE>} */
MapEntry.prototype.next;


/** @type {?Object} */
MapEntry.prototype.head;


/** @type {KEY} */
MapEntry.prototype.key;


/** @type {VALUE} */
MapEntry.prototype.value;


/**
* Polyfill for the global Map data type.
* @constructor
Expand All @@ -110,10 +111,10 @@ $jscomp.polyfill('Map', function(NativeMap) {
*/
// TODO(sdh): fix param type if heterogeneous arrays ever supported.
var PolyfillMap = function(opt_iterable) {
/** @private {!Object<!Array<!MapEntry<KEY, VALUE>>>} */
/** @private {!Object<!Array<!$jscomp.MapEntry<KEY, VALUE>>>} */
this.data_ = {};

/** @private {!MapEntry<KEY, VALUE>} */
/** @private {!$jscomp.MapEntry<KEY, VALUE>} */
this.head_ = createHead();

// Note: this property should not be changed. If we're willing to give up
Expand Down Expand Up @@ -200,20 +201,28 @@ $jscomp.polyfill('Map', function(NativeMap) {

/** @override */
PolyfillMap.prototype.entries = function() {
return makeIterator(
this, function(entry) { return [entry.key, entry.value]; });
return makeIterator(this, /** @return {!Array<(KEY|VALUE)>} */ function(
/** !$jscomp.MapEntry<KEY, VALUE> */ entry) {
return ([entry.key, entry.value]);
});
};


/** @override */
PolyfillMap.prototype.keys = function() {
return makeIterator(this, function(entry) { return entry.key; });
return makeIterator(this, /** @return {KEY} */ function(
/** !$jscomp.MapEntry<KEY, VALUE> */ entry) {
return entry.key;
});
};


/** @override */
PolyfillMap.prototype.values = function() {
return makeIterator(this, function(entry) { return entry.value; });
return makeIterator(this, /** @return {VALUE} */ function(
/** !$jscomp.MapEntry<KEY, VALUE> */ entry) {
return entry.value;
});
};


Expand Down Expand Up @@ -241,9 +250,9 @@ $jscomp.polyfill('Map', function(NativeMap) {
* @param {!PolyfillMap<KEY, VALUE>} map
* @param {KEY} key
* @return {{id: string,
* list: (!Array<!MapEntry<KEY, VALUE>>|undefined),
* list: (!Array<!$jscomp.MapEntry<KEY, VALUE>>|undefined),
* index: number,
* entry: (!MapEntry<KEY, VALUE>|undefined)}}
* entry: (!$jscomp.MapEntry<KEY, VALUE>|undefined)}}
* @template KEY, VALUE
*/
var maybeGetEntry = function(map, key) {
Expand All @@ -264,7 +273,7 @@ $jscomp.polyfill('Map', function(NativeMap) {
/**
* Maps over the entries with the given function.
* @param {!PolyfillMap<KEY, VALUE>} map
* @param {function(!MapEntry<KEY, VALUE>): T} func
* @param {function(!$jscomp.MapEntry<KEY, VALUE>): T} func
* @return {!IteratorIterable<T>}
* @template KEY, VALUE, T
* @private
Expand All @@ -289,12 +298,12 @@ $jscomp.polyfill('Map', function(NativeMap) {

/**
* Makes a new "head" element.
* @return {!MapEntry<KEY, VALUE>}
* @return {!$jscomp.MapEntry<KEY, VALUE>}
* @template KEY, VALUE
* @suppress {checkTypes} ignore missing key/value for head only
*/
var createHead = function() {
var head = /** type {!MapEntry<KEY, VALUE>} */ ({});
var head = /** type {!$jscomp.MapEntry<KEY, VALUE>} */ ({});
head.previous = head.next = head.head = head;
return head;
};
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/resources.json

Large diffs are not rendered by default.

0 comments on commit 3a7464d

Please sign in to comment.