Merge pull request #7948 from fredj/typecheck

Better type definition
This commit is contained in:
Frédéric Junod
2018-03-08 09:21:45 +01:00
committed by GitHub
30 changed files with 80 additions and 116 deletions

View File

@@ -321,7 +321,7 @@ const PluggableMap = function(options) {
/**
* @private
* @type {Array.<module:ol/types~PostRenderFunction>}
* @type {!Array.<module:ol/types~PostRenderFunction>}
*/
this.postRenderFunctions_ = [];
@@ -1232,8 +1232,7 @@ PluggableMap.prototype.renderFrame_ = function(time) {
if (frameState.animate) {
this.render();
}
Array.prototype.push.apply(
this.postRenderFunctions_, frameState.postRenderFunctions);
Array.prototype.push.apply(this.postRenderFunctions_, frameState.postRenderFunctions);
if (previousFrameState) {
const moveStart = !this.previousExtent_ ||

View File

@@ -21,13 +21,12 @@ inherits(TileCache, LRUCache);
/**
* @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
* @param {!Object.<string, ol.TileRange>} usedTiles Used tiles.
*/
TileCache.prototype.expireCache = function(usedTiles) {
let tile, zKey;
while (this.canExpireCache()) {
tile = this.peekLast();
zKey = tile.tileCoord[0].toString();
const tile = this.peekLast();
const zKey = tile.tileCoord[0].toString();
if (zKey in usedTiles && usedTiles[zKey].contains(tile.tileCoord)) {
break;
} else {

View File

@@ -40,7 +40,7 @@ const VectorImageTile = function(tileCoord, state, sourceRevision, format,
/**
* @private
* @type {Object.<string, CanvasRenderingContext2D>}
* @type {!Object.<string, CanvasRenderingContext2D>}
*/
this.context_ = {};
@@ -52,7 +52,7 @@ const VectorImageTile = function(tileCoord, state, sourceRevision, format,
/**
* @private
* @type {Object.<string, ol.TileReplayState>}
* @type {!Object.<string, ol.TileReplayState>}
*/
this.replayState_ = {};

View File

@@ -126,15 +126,13 @@ export function reverseSubArray(arr, begin, end) {
/**
* @param {Array.<VALUE>} arr The array to modify.
* @param {Array.<VALUE>|VALUE} data The elements or arrays of elements
* to add to arr.
* @param {!Array.<VALUE>|VALUE} data The elements or arrays of elements to add to arr.
* @template VALUE
*/
export function extend(arr, data) {
let i;
const extension = Array.isArray(data) ? data : [data];
const length = extension.length;
for (i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
arr[arr.length] = extension[i];
}
}
@@ -160,7 +158,7 @@ export function remove(arr, obj) {
* @param {Array.<VALUE>} arr The array to search in.
* @param {function(VALUE, number, ?) : boolean} func The function to compare.
* @template VALUE
* @return {VALUE} The element found.
* @return {VALUE|null} The element found or null.
*/
export function find(arr, func) {
const length = arr.length >>> 0;

View File

@@ -130,7 +130,7 @@ inherits(Attribution, Control);
Attribution.prototype.getSourceAttributions_ = function(frameState) {
/**
* Used to determine if an attribution already exists.
* @type {Object.<string, boolean>}
* @type {!Object.<string, boolean>}
*/
const lookup = {};

View File

@@ -379,7 +379,7 @@ const GPX_SERIALIZERS = makeStructureNS(
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {ol.LayoutOptions} layoutOptions Layout options.
* @param {Node} node Node.
* @param {Object} values Values.
* @param {!Object} values Values.
* @return {Array.<number>} Flat coordinates.
*/
function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
@@ -477,14 +477,11 @@ function parseExtensions(node, objectStack) {
* @param {Array.<*>} objectStack Object stack.
*/
function parseRtePt(node, objectStack) {
const values = pushParseAndPop(
{}, RTEPT_PARSERS, node, objectStack);
const values = pushParseAndPop({}, RTEPT_PARSERS, node, objectStack);
if (values) {
const rteValues = /** @type {Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array.<number>} */
(rteValues['flatCoordinates']);
const layoutOptions = /** @type {ol.LayoutOptions} */
(rteValues['layoutOptions']);
const rteValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array.<number>} */ (rteValues['flatCoordinates']);
const layoutOptions = /** @type {ol.LayoutOptions} */ (rteValues['layoutOptions']);
appendCoordinate(flatCoordinates, layoutOptions, node, values);
}
}
@@ -497,11 +494,9 @@ function parseRtePt(node, objectStack) {
function parseTrkPt(node, objectStack) {
const values = pushParseAndPop({}, TRKPT_PARSERS, node, objectStack);
if (values) {
const trkValues = /** @type {Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array.<number>} */
(trkValues['flatCoordinates']);
const layoutOptions = /** @type {ol.LayoutOptions} */
(trkValues['layoutOptions']);
const trkValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array.<number>} */ (trkValues['flatCoordinates']);
const layoutOptions = /** @type {ol.LayoutOptions} */ (trkValues['layoutOptions']);
appendCoordinate(flatCoordinates, layoutOptions, node, values);
}
}

View File

@@ -277,7 +277,7 @@ const KML = function(opt_options) {
/**
* @private
* @type {Object.<string, (Array.<ol.style.Style>|string)>}
* @type {!Object.<string, (Array.<ol.style.Style>|string)>}
*/
this.sharedStyles_ = {};
@@ -384,14 +384,11 @@ function createNameStyleFunction(foundStyle, name) {
* @param {Array.<ol.style.Style>|undefined} style Style.
* @param {string} styleUrl Style URL.
* @param {Array.<ol.style.Style>} defaultStyle Default style.
* @param {Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles Shared
* styles.
* @param {boolean|undefined} showPointNames true to show names for point
* placemarks.
* @param {!Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles Shared styles.
* @param {boolean|undefined} showPointNames true to show names for point placemarks.
* @return {ol.StyleFunction} Feature style function.
*/
function createFeatureStyleFunction(style, styleUrl,
defaultStyle, sharedStyles, showPointNames) {
function createFeatureStyleFunction(style, styleUrl, defaultStyle, sharedStyles, showPointNames) {
return (
/**
@@ -418,25 +415,21 @@ function createFeatureStyleFunction(style, styleUrl,
if (style) {
if (drawName) {
nameStyle = createNameStyleFunction(style[0],
name);
nameStyle = createNameStyleFunction(style[0], name);
return style.concat(nameStyle);
}
return style;
}
if (styleUrl) {
const foundStyle = findStyle(styleUrl, defaultStyle,
sharedStyles);
const foundStyle = findStyle(styleUrl, defaultStyle, sharedStyles);
if (drawName) {
nameStyle = createNameStyleFunction(foundStyle[0],
name);
nameStyle = createNameStyleFunction(foundStyle[0], name);
return foundStyle.concat(nameStyle);
}
return foundStyle;
}
if (drawName) {
nameStyle = createNameStyleFunction(defaultStyle[0],
name);
nameStyle = createNameStyleFunction(defaultStyle[0], name);
return defaultStyle.concat(nameStyle);
}
return defaultStyle;
@@ -448,7 +441,7 @@ function createFeatureStyleFunction(style, styleUrl,
/**
* @param {Array.<ol.style.Style>|string|undefined} styleValue Style value.
* @param {Array.<ol.style.Style>} defaultStyle Default style.
* @param {Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles
* @param {!Object.<string, (Array.<ol.style.Style>|string)>} sharedStyles
* Shared styles.
* @return {Array.<ol.style.Style>} Style.
*/
@@ -462,8 +455,7 @@ function findStyle(styleValue, defaultStyle, sharedStyles) {
if (!(styleValue in sharedStyles) && ('#' + styleValue in sharedStyles)) {
styleValue = '#' + styleValue;
}
return findStyle(
sharedStyles[styleValue], defaultStyle, sharedStyles);
return findStyle(sharedStyles[styleValue], defaultStyle, sharedStyles);
} else {
return defaultStyle;
}

View File

@@ -446,8 +446,7 @@ function readCapabilityLayer(node, objectStack) {
* @return {Object|undefined} Layer object.
*/
function readLayer(node, objectStack) {
const parentLayerObject = /** @type {Object.<string,*>} */
(objectStack[objectStack.length - 1]);
const parentLayerObject = /** @type {!Object.<string,*>} */ (objectStack[objectStack.length - 1]);
const layerObject = pushParseAndPop({}, LAYER_PARSERS, node, objectStack);

View File

@@ -32,7 +32,7 @@ function line(interpolate, transform, squaredTolerance) {
/** @type {Array.<number>} */
const fractionStack = [1, 0];
/** @type {Object.<string, boolean>} */
/** @type {!Object.<string, boolean>} */
const fractions = {};
let maxIterations = 1e5;

View File

@@ -223,7 +223,7 @@ const Modify = function(options) {
/**
* @const
* @private
* @type {Object.<string, function(ol.Feature, ol.geom.Geometry)>}
* @type {!Object.<string, function(ol.Feature, ol.geom.Geometry)>}
*/
this.SEGMENT_WRITERS_ = {
'Point': this.writePointGeometry_,

View File

@@ -97,7 +97,7 @@ const PointerInteraction = function(opt_options) {
this.handlingDownUpSequence = false;
/**
* @type {Object.<string, ol.pointer.PointerEvent>}
* @type {!Object.<string, ol.pointer.PointerEvent>}
* @private
*/
this.trackedPointers_ = {};

View File

@@ -97,7 +97,7 @@ const Snap = function(opt_options) {
* If a feature geometry changes while a pointer drag|move event occurs, the
* feature doesn't get updated right away. It will be at the next 'pointerup'
* event fired.
* @type {Object.<number, ol.Feature>}
* @type {!Object.<number, ol.Feature>}
* @private
*/
this.pendingFeatures_ = {};

View File

@@ -6,7 +6,7 @@ import {isEmpty} from '../obj.js';
/**
* @private
* @type {Object.<string, Object.<string, ol.TransformFunction>>}
* @type {!Object.<string, !Object.<string, ol.TransformFunction>>}
*/
let transforms = {};

View File

@@ -129,7 +129,7 @@ const CanvasReplay = function(tolerance, maxExtent, resolution, pixelRatio, over
/**
* @private
* @type {Object.<number,ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>>}
* @type {!Object.<number,ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>>}
*/
this.coordinateCache_ = {};

View File

@@ -100,8 +100,7 @@ const CanvasReplayGroup = function(
/**
* @private
* @type {!Object.<string,
* Object.<ol.render.ReplayType, ol.render.canvas.Replay>>}
* @type {!Object.<string, !Object.<ol.render.ReplayType, ol.render.canvas.Replay>>}
*/
this.replaysByZIndex_ = {};

View File

@@ -79,7 +79,7 @@ const CanvasTextReplay = function(
this.textFillState_ = null;
/**
* @type {Object.<string, ol.CanvasFillState>}
* @type {!Object.<string, ol.CanvasFillState>}
*/
this.fillStates = {};
@@ -90,7 +90,7 @@ const CanvasTextReplay = function(
this.textStrokeState_ = null;
/**
* @type {Object.<string, ol.CanvasStrokeState>}
* @type {!Object.<string, ol.CanvasStrokeState>}
*/
this.strokeStates = {};
@@ -101,7 +101,7 @@ const CanvasTextReplay = function(
this.textState_ = /** @type {ol.CanvasTextState} */ ({});
/**
* @type {Object.<string, ol.CanvasTextState>}
* @type {!Object.<string, ol.CanvasTextState>}
*/
this.textStates = {};

View File

@@ -242,9 +242,8 @@ WebGLTextureReplay.prototype.drawCoordinates = function(flatCoordinates, offset,
/**
* @protected
* @param {Array.<WebGLTexture>} textures Textures.
* @param {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>} images
* Images.
* @param {Object.<string, WebGLTexture>} texturePerImage Texture cache.
* @param {Array.<HTMLCanvasElement|HTMLImageElement|HTMLVideoElement>} images Images.
* @param {!Object.<string, WebGLTexture>} texturePerImage Texture cache.
* @param {WebGLRenderingContext} gl Gl.
*/
WebGLTextureReplay.prototype.createTextures = function(textures, images, texturePerImage, gl) {

View File

@@ -164,7 +164,7 @@ LayerRenderer.prototype.scheduleExpireCache = function(frameState, tileSource) {
/**
* @param {Object.<string, Object.<string, ol.TileRange>>} usedTiles Used tiles.
* @param {!Object.<string, !Object.<string, ol.TileRange>>} usedTiles Used tiles.
* @param {ol.source.Tile} tileSource Tile source.
* @param {number} z Z.
* @param {ol.TileRange} tileRange Tile range.

View File

@@ -32,7 +32,7 @@ const MapRenderer = function(container, map) {
/**
* @private
* @type {Object.<string, ol.renderer.Layer>}
* @type {!Object.<string, ol.renderer.Layer>}
*/
this.layerRenderers_ = {};

View File

@@ -253,14 +253,13 @@ CanvasVectorLayerRenderer.prototype.forEachFeatureAtCoordinate = function(coordi
const resolution = frameState.viewState.resolution;
const rotation = frameState.viewState.rotation;
const layer = /** @type {ol.layer.Vector} */ (this.getLayer());
/** @type {Object.<string, boolean>} */
/** @type {!Object.<string, boolean>} */
const features = {};
const result = this.replayGroup_.forEachFeatureAtCoordinate(coordinate, resolution,
rotation, hitTolerance, {},
const result = this.replayGroup_.forEachFeatureAtCoordinate(coordinate, resolution, rotation, hitTolerance, {},
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @return {?} Callback result.
*/
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @return {?} Callback result.
*/
function(feature) {
const key = getUid(feature).toString();
if (!(key in features)) {

View File

@@ -265,7 +265,7 @@ CanvasVectorTileLayerRenderer.prototype.forEachFeatureAtCoordinate = function(co
const rotation = frameState.viewState.rotation;
hitTolerance = hitTolerance == undefined ? 0 : hitTolerance;
const layer = this.getLayer();
/** @type {Object.<string, boolean>} */
/** @type {!Object.<string, boolean>} */
const features = {};
/** @type {Array.<ol.VectorImageTile>} */
@@ -290,8 +290,7 @@ CanvasVectorTileLayerRenderer.prototype.forEachFeatureAtCoordinate = function(co
continue;
}
replayGroup = sourceTile.getReplayGroup(layer, tile.tileCoord.toString());
found = found || replayGroup.forEachFeatureAtCoordinate(
coordinate, resolution, rotation, hitTolerance, {},
found = found || replayGroup.forEachFeatureAtCoordinate(coordinate, resolution, rotation, hitTolerance, {},
/**
* @param {ol.Feature|ol.render.Feature} feature Feature.
* @return {?} Callback result.

View File

@@ -143,7 +143,7 @@ WebGLVectorLayerRenderer.prototype.forEachFeatureAtCoordinate = function(coordin
const viewState = frameState.viewState;
const layer = this.getLayer();
const layerState = this.layerState_;
/** @type {Object.<string, boolean>} */
/** @type {!Object.<string, boolean>} */
const features = {};
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
context, viewState.center, viewState.resolution, viewState.rotation,

View File

@@ -61,13 +61,13 @@ const TileImage = function(options) {
/**
* @protected
* @type {Object.<string, ol.TileCache>}
* @type {!Object.<string, ol.TileCache>}
*/
this.tileCacheForProjection = {};
/**
* @protected
* @type {Object.<string, ol.tilegrid.TileGrid>}
* @type {!Object.<string, ol.tilegrid.TileGrid>}
*/
this.tileGridForProjection = {};
@@ -173,8 +173,7 @@ TileImage.prototype.getTileGridForProjection = function(projection) {
} else {
const projKey = getUid(projection).toString();
if (!(projKey in this.tileGridForProjection)) {
this.tileGridForProjection[projKey] =
getTileGridForProjection(projection);
this.tileGridForProjection[projKey] = getTileGridForProjection(projection);
}
return /** @type {!ol.tilegrid.TileGrid} */ (this.tileGridForProjection[projKey]);
}

View File

@@ -63,7 +63,7 @@ const UrlTile = function(options) {
/**
* @private
* @type {Object.<number, boolean>}
* @type {!Object.<number, boolean>}
*/
this.tileLoadingKeys_ = {};

View File

@@ -126,21 +126,21 @@ const VectorSource = function(opt_options) {
/**
* @private
* @type {Object.<string, ol.Feature>}
* @type {!Object.<string, ol.Feature>}
*/
this.nullGeometryFeatures_ = {};
/**
* A lookup of features by id (the return from feature.getId()).
* @private
* @type {Object.<string, ol.Feature>}
* @type {!Object.<string, ol.Feature>}
*/
this.idIndex_ = {};
/**
* A lookup of features without id (keyed by ol.getUid(feature)).
* @private
* @type {Object.<string, ol.Feature>}
* @type {!Object.<string, ol.Feature>}
*/
this.undefIdIndex_ = {};

View File

@@ -288,7 +288,7 @@ WMTS.prototype.updateDimensions = function(dimensions) {
/**
* Generate source options from a capabilities object.
* @param {Object} wmtsCap An object representing the capabilities document.
* @param {Object} config Configuration properties for the layer. Defaults for
* @param {!Object} config Configuration properties for the layer. Defaults for
* the layer will apply if not provided.
*
* Required config properties:

View File

@@ -46,7 +46,7 @@ const PriorityQueue = function(priorityFunction, keyFunction) {
this.priorities_ = [];
/**
* @type {Object.<string, boolean>}
* @type {!Object.<string, boolean>}
* @private
*/
this.queuedElements_ = {};

View File

@@ -10,7 +10,7 @@ import {asString} from '../color.js';
const IconImageCache = function() {
/**
* @type {Object.<string, ol.style.IconImage>}
* @type {!Object.<string, ol.style.IconImage>}
* @private
*/
this.cache_ = {};

View File

@@ -34,19 +34,19 @@ const WebGLContext = function(canvas, gl) {
/**
* @private
* @type {Object.<string, ol.WebglBufferCacheEntry>}
* @type {!Object.<string, ol.WebglBufferCacheEntry>}
*/
this.bufferCache_ = {};
/**
* @private
* @type {Object.<string, WebGLShader>}
* @type {!Object.<string, WebGLShader>}
*/
this.shaderCache_ = {};
/**
* @private
* @type {Object.<string, WebGLProgram>}
* @type {!Object.<string, WebGLProgram>}
*/
this.programCache_ = {};

View File

@@ -133,8 +133,7 @@ export function makeArrayExtender(valueReader, opt_this) {
function(node, objectStack) {
const value = valueReader.call(opt_this, node, objectStack);
if (value !== undefined) {
const array = /** @type {Array.<*>} */
(objectStack[objectStack.length - 1]);
const array = /** @type {Array.<*>} */ (objectStack[objectStack.length - 1]);
extend(array, value);
}
}
@@ -157,8 +156,7 @@ export function makeArrayPusher(valueReader, opt_this) {
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
const value = valueReader.call(opt_this !== undefined ? opt_this : this,
node, objectStack);
const value = valueReader.call(opt_this !== undefined ? opt_this : this, node, objectStack);
if (value !== undefined) {
const array = objectStack[objectStack.length - 1];
array.push(value);
@@ -182,8 +180,7 @@ export function makeReplacer(valueReader, opt_this) {
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
const value = valueReader.call(opt_this !== undefined ? opt_this : this,
node, objectStack);
const value = valueReader.call(opt_this !== undefined ? opt_this : this, node, objectStack);
if (value !== undefined) {
objectStack[objectStack.length - 1] = value;
}
@@ -207,13 +204,10 @@ export function makeObjectPropertyPusher(valueReader, opt_property, opt_this) {
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
const value = valueReader.call(opt_this !== undefined ? opt_this : this,
node, objectStack);
const value = valueReader.call(opt_this !== undefined ? opt_this : this, node, objectStack);
if (value !== undefined) {
const object = /** @type {Object} */
(objectStack[objectStack.length - 1]);
const property = opt_property !== undefined ?
opt_property : node.localName;
const object = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const property = opt_property !== undefined ? opt_property : node.localName;
let array;
if (property in object) {
array = object[property];
@@ -241,13 +235,10 @@ export function makeObjectPropertySetter(valueReader, opt_property, opt_this) {
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
const value = valueReader.call(opt_this !== undefined ? opt_this : this,
node, objectStack);
const value = valueReader.call(opt_this !== undefined ? opt_this : this, node, objectStack);
if (value !== undefined) {
const object = /** @type {Object} */
(objectStack[objectStack.length - 1]);
const property = opt_property !== undefined ?
opt_property : node.localName;
const object = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const property = opt_property !== undefined ? opt_property : node.localName;
object[property] = value;
}
});
@@ -266,8 +257,7 @@ export function makeObjectPropertySetter(valueReader, opt_property, opt_this) {
*/
export function makeChildAppender(nodeWriter, opt_this) {
return function(node, value, objectStack) {
nodeWriter.call(opt_this !== undefined ? opt_this : this,
node, value, objectStack);
nodeWriter.call(opt_this !== undefined ? opt_this : this, node, value, objectStack);
const parent = objectStack[objectStack.length - 1];
const parentNode = parent.node;
parentNode.appendChild(node);
@@ -430,11 +420,10 @@ export function parseNode(parsersNS, node, objectStack, opt_this) {
* @return {T} Object.
* @template T
*/
export function pushParseAndPop(
object, parsersNS, node, objectStack, opt_this) {
export function pushParseAndPop(object, parsersNS, node, objectStack, opt_this) {
objectStack.push(object);
parseNode(parsersNS, node, objectStack, opt_this);
return objectStack.pop();
return /** @type {T} */ (objectStack.pop());
}
@@ -501,10 +490,8 @@ export function serialize(
* @return {O|undefined} Object.
* @template O, T
*/
export function pushSerializeAndPop(object,
serializersNS, nodeFactory, values, objectStack, opt_keys, opt_this) {
export function pushSerializeAndPop(object, serializersNS, nodeFactory, values, objectStack, opt_keys, opt_this) {
objectStack.push(object);
serialize(
serializersNS, nodeFactory, values, objectStack, opt_keys, opt_this);
return objectStack.pop();
serialize(serializersNS, nodeFactory, values, objectStack, opt_keys, opt_this);
return /** @type {O|undefined} */ (objectStack.pop());
}