Use blocked scoped variables

In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions

View File

@@ -36,8 +36,8 @@ import _ol_xml_ from '../xml.js';
* Optional configuration object.
* @extends {ol.format.XMLFeature}
*/
var GMLBase = function(opt_options) {
var options = /** @type {olx.format.GMLOptions} */
const GMLBase = function(opt_options) {
const options = /** @type {olx.format.GMLOptions} */
(opt_options ? opt_options : {});
/**
@@ -70,9 +70,9 @@ var GMLBase = function(opt_options) {
this.FEATURE_COLLECTION_PARSERS = {};
this.FEATURE_COLLECTION_PARSERS[GMLBase.GMLNS] = {
'featureMember': _ol_xml_.makeReplacer(
GMLBase.prototype.readFeaturesInternal),
GMLBase.prototype.readFeaturesInternal),
'featureMembers': _ol_xml_.makeReplacer(
GMLBase.prototype.readFeaturesInternal)
GMLBase.prototype.readFeaturesInternal)
};
XMLFeature.call(this);
@@ -109,34 +109,36 @@ GMLBase.ONLY_WHITESPACE_RE_ = /^[\s\xa0]*$/;
* @return {Array.<ol.Feature> | undefined} Features.
*/
GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
var localName = node.localName;
var features = null;
const localName = node.localName;
let features = null;
if (localName == 'FeatureCollection') {
if (node.namespaceURI === 'http://www.opengis.net/wfs') {
features = _ol_xml_.pushParseAndPop([],
this.FEATURE_COLLECTION_PARSERS, node,
objectStack, this);
this.FEATURE_COLLECTION_PARSERS, node,
objectStack, this);
} else {
features = _ol_xml_.pushParseAndPop(null,
this.FEATURE_COLLECTION_PARSERS, node,
objectStack, this);
this.FEATURE_COLLECTION_PARSERS, node,
objectStack, this);
}
} else if (localName == 'featureMembers' || localName == 'featureMember') {
var context = objectStack[0];
var featureType = context['featureType'];
var featureNS = context['featureNS'];
var i, ii, prefix = 'p', defaultPrefix = 'p0';
const context = objectStack[0];
let featureType = context['featureType'];
let featureNS = context['featureNS'];
let i, ii;
const prefix = 'p';
const defaultPrefix = 'p0';
if (!featureType && node.childNodes) {
featureType = [], featureNS = {};
for (i = 0, ii = node.childNodes.length; i < ii; ++i) {
var child = node.childNodes[i];
const child = node.childNodes[i];
if (child.nodeType === 1) {
var ft = child.nodeName.split(':').pop();
const ft = child.nodeName.split(':').pop();
if (featureType.indexOf(ft) === -1) {
var key = '';
var count = 0;
var uri = child.namespaceURI;
for (var candidate in featureNS) {
let key = '';
let count = 0;
const uri = child.namespaceURI;
for (const candidate in featureNS) {
if (featureNS[candidate] === uri) {
key = candidate;
break;
@@ -158,16 +160,16 @@ GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
}
}
if (typeof featureNS === 'string') {
var ns = featureNS;
const ns = featureNS;
featureNS = {};
featureNS[defaultPrefix] = ns;
}
var parsersNS = {};
var featureTypes = Array.isArray(featureType) ? featureType : [featureType];
for (var p in featureNS) {
var parsers = {};
const parsersNS = {};
const featureTypes = Array.isArray(featureType) ? featureType : [featureType];
for (const p in featureNS) {
const parsers = {};
for (i = 0, ii = featureTypes.length; i < ii; ++i) {
var featurePrefix = featureTypes[i].indexOf(':') === -1 ?
const featurePrefix = featureTypes[i].indexOf(':') === -1 ?
defaultPrefix : featureTypes[i].split(':')[0];
if (featurePrefix === p) {
parsers[featureTypes[i].split(':').pop()] =
@@ -197,12 +199,12 @@ GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
* @return {ol.geom.Geometry|undefined} Geometry.
*/
GMLBase.prototype.readGeometryElement = function(node, objectStack) {
var context = /** @type {Object} */ (objectStack[0]);
const context = /** @type {Object} */ (objectStack[0]);
context['srsName'] = node.firstElementChild.getAttribute('srsName');
context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
/** @type {ol.geom.Geometry} */
var geometry = _ol_xml_.pushParseAndPop(null,
this.GEOMETRY_PARSERS_, node, objectStack, this);
const geometry = _ol_xml_.pushParseAndPop(null,
this.GEOMETRY_PARSERS_, node, objectStack, this);
if (geometry) {
return (
/** @type {ol.geom.Geometry} */ transformWithOptions(geometry, false, context)
@@ -219,19 +221,20 @@ GMLBase.prototype.readGeometryElement = function(node, objectStack) {
* @return {ol.Feature} Feature.
*/
GMLBase.prototype.readFeatureElement = function(node, objectStack) {
var n;
var fid = node.getAttribute('fid') ||
let n;
const fid = node.getAttribute('fid') ||
_ol_xml_.getAttributeNS(node, GMLBase.GMLNS, 'id');
var values = {}, geometryName;
const values = {};
let geometryName;
for (n = node.firstElementChild; n; n = n.nextElementSibling) {
var localName = n.localName;
const localName = n.localName;
// Assume attribute elements have one child node and that the child
// is a text or CDATA node (to be treated as text).
// Otherwise assume it is a geometry node.
if (n.childNodes.length === 0 ||
(n.childNodes.length === 1 &&
(n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
var value = _ol_xml_.getAllTextContent(n, false);
let value = _ol_xml_.getAllTextContent(n, false);
if (GMLBase.ONLY_WHITESPACE_RE_.test(value)) {
value = undefined;
}
@@ -244,7 +247,7 @@ GMLBase.prototype.readFeatureElement = function(node, objectStack) {
values[localName] = this.readGeometryElement(n, objectStack);
}
}
var feature = new Feature(values);
const feature = new Feature(values);
if (geometryName) {
feature.setGeometryName(geometryName);
}
@@ -261,10 +264,10 @@ GMLBase.prototype.readFeatureElement = function(node, objectStack) {
* @return {ol.geom.Point|undefined} Point.
*/
GMLBase.prototype.readPoint = function(node, objectStack) {
var flatCoordinates =
const flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (flatCoordinates) {
var point = new Point(null);
const point = new Point(null);
point.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
return point;
}
@@ -278,8 +281,8 @@ GMLBase.prototype.readPoint = function(node, objectStack) {
*/
GMLBase.prototype.readMultiPoint = function(node, objectStack) {
/** @type {Array.<Array.<number>>} */
var coordinates = _ol_xml_.pushParseAndPop([],
this.MULTIPOINT_PARSERS_, node, objectStack, this);
const coordinates = _ol_xml_.pushParseAndPop([],
this.MULTIPOINT_PARSERS_, node, objectStack, this);
if (coordinates) {
return new MultiPoint(coordinates);
} else {
@@ -295,10 +298,10 @@ GMLBase.prototype.readMultiPoint = function(node, objectStack) {
*/
GMLBase.prototype.readMultiLineString = function(node, objectStack) {
/** @type {Array.<ol.geom.LineString>} */
var lineStrings = _ol_xml_.pushParseAndPop([],
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
const lineStrings = _ol_xml_.pushParseAndPop([],
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
if (lineStrings) {
var multiLineString = new MultiLineString(null);
const multiLineString = new MultiLineString(null);
multiLineString.setLineStrings(lineStrings);
return multiLineString;
} else {
@@ -314,10 +317,10 @@ GMLBase.prototype.readMultiLineString = function(node, objectStack) {
*/
GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
/** @type {Array.<ol.geom.Polygon>} */
var polygons = _ol_xml_.pushParseAndPop([],
this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
const polygons = _ol_xml_.pushParseAndPop([],
this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
if (polygons) {
var multiPolygon = new MultiPolygon(null);
const multiPolygon = new MultiPolygon(null);
multiPolygon.setPolygons(polygons);
return multiPolygon;
} else {
@@ -333,7 +336,7 @@ GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
*/
GMLBase.prototype.pointMemberParser_ = function(node, objectStack) {
_ol_xml_.parseNode(this.POINTMEMBER_PARSERS_,
node, objectStack, this);
node, objectStack, this);
};
@@ -344,7 +347,7 @@ GMLBase.prototype.pointMemberParser_ = function(node, objectStack) {
*/
GMLBase.prototype.lineStringMemberParser_ = function(node, objectStack) {
_ol_xml_.parseNode(this.LINESTRINGMEMBER_PARSERS_,
node, objectStack, this);
node, objectStack, this);
};
@@ -355,7 +358,7 @@ GMLBase.prototype.lineStringMemberParser_ = function(node, objectStack) {
*/
GMLBase.prototype.polygonMemberParser_ = function(node, objectStack) {
_ol_xml_.parseNode(this.POLYGONMEMBER_PARSERS_, node,
objectStack, this);
objectStack, this);
};
@@ -365,10 +368,10 @@ GMLBase.prototype.polygonMemberParser_ = function(node, objectStack) {
* @return {ol.geom.LineString|undefined} LineString.
*/
GMLBase.prototype.readLineString = function(node, objectStack) {
var flatCoordinates =
const flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (flatCoordinates) {
var lineString = new LineString(null);
const lineString = new LineString(null);
lineString.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
return lineString;
} else {
@@ -384,9 +387,9 @@ GMLBase.prototype.readLineString = function(node, objectStack) {
* @return {Array.<number>|undefined} LinearRing flat coordinates.
*/
GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
var ring = _ol_xml_.pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
objectStack, this);
const ring = _ol_xml_.pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
objectStack, this);
if (ring) {
return ring;
} else {
@@ -401,10 +404,10 @@ GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
* @return {ol.geom.LinearRing|undefined} LinearRing.
*/
GMLBase.prototype.readLinearRing = function(node, objectStack) {
var flatCoordinates =
const flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (flatCoordinates) {
var ring = new LinearRing(null);
const ring = new LinearRing(null);
ring.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
return ring;
} else {
@@ -420,19 +423,19 @@ GMLBase.prototype.readLinearRing = function(node, objectStack) {
*/
GMLBase.prototype.readPolygon = function(node, objectStack) {
/** @type {Array.<Array.<number>>} */
var flatLinearRings = _ol_xml_.pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
const flatLinearRings = _ol_xml_.pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
if (flatLinearRings && flatLinearRings[0]) {
var polygon = new Polygon(null);
var flatCoordinates = flatLinearRings[0];
var ends = [flatCoordinates.length];
var i, ii;
const polygon = new Polygon(null);
const flatCoordinates = flatLinearRings[0];
const ends = [flatCoordinates.length];
let i, ii;
for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
extend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length);
}
polygon.setFlatCoordinates(
GeometryLayout.XYZ, flatCoordinates, ends);
GeometryLayout.XYZ, flatCoordinates, ends);
return polygon;
} else {
return undefined;
@@ -448,8 +451,8 @@ GMLBase.prototype.readPolygon = function(node, objectStack) {
*/
GMLBase.prototype.readFlatCoordinatesFromNode_ = function(node, objectStack) {
return _ol_xml_.pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
objectStack, this);
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
objectStack, this);
};
@@ -461,9 +464,9 @@ GMLBase.prototype.readFlatCoordinatesFromNode_ = function(node, objectStack) {
GMLBase.prototype.MULTIPOINT_PARSERS_ = {
'http://www.opengis.net/gml': {
'pointMember': _ol_xml_.makeArrayPusher(
GMLBase.prototype.pointMemberParser_),
GMLBase.prototype.pointMemberParser_),
'pointMembers': _ol_xml_.makeArrayPusher(
GMLBase.prototype.pointMemberParser_)
GMLBase.prototype.pointMemberParser_)
}
};
@@ -476,9 +479,9 @@ GMLBase.prototype.MULTIPOINT_PARSERS_ = {
GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': _ol_xml_.makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_),
GMLBase.prototype.lineStringMemberParser_),
'lineStringMembers': _ol_xml_.makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_)
GMLBase.prototype.lineStringMemberParser_)
}
};
@@ -491,9 +494,9 @@ GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
'http://www.opengis.net/gml': {
'polygonMember': _ol_xml_.makeArrayPusher(
GMLBase.prototype.polygonMemberParser_),
GMLBase.prototype.polygonMemberParser_),
'polygonMembers': _ol_xml_.makeArrayPusher(
GMLBase.prototype.polygonMemberParser_)
GMLBase.prototype.polygonMemberParser_)
}
};
@@ -506,7 +509,7 @@ GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
GMLBase.prototype.POINTMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'Point': _ol_xml_.makeArrayPusher(
GMLBase.prototype.readFlatCoordinatesFromNode_)
GMLBase.prototype.readFlatCoordinatesFromNode_)
}
};
@@ -519,7 +522,7 @@ GMLBase.prototype.POINTMEMBER_PARSERS_ = {
GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'LineString': _ol_xml_.makeArrayPusher(
GMLBase.prototype.readLineString)
GMLBase.prototype.readLineString)
}
};
@@ -532,7 +535,7 @@ GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'Polygon': _ol_xml_.makeArrayPusher(
GMLBase.prototype.readPolygon)
GMLBase.prototype.readPolygon)
}
};
@@ -545,7 +548,7 @@ GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
GMLBase.prototype.RING_PARSERS = {
'http://www.opengis.net/gml': {
'LinearRing': _ol_xml_.makeReplacer(
GMLBase.prototype.readFlatLinearRing_)
GMLBase.prototype.readFlatLinearRing_)
}
};
@@ -554,8 +557,8 @@ GMLBase.prototype.RING_PARSERS = {
* @inheritDoc
*/
GMLBase.prototype.readGeometryFromNode = function(node, opt_options) {
var geometry = this.readGeometryElement(node,
[this.getReadOptions(node, opt_options ? opt_options : {})]);
const geometry = this.readGeometryElement(node,
[this.getReadOptions(node, opt_options ? opt_options : {})]);
return geometry ? geometry : null;
};
@@ -576,14 +579,14 @@ GMLBase.prototype.readFeatures;
* @inheritDoc
*/
GMLBase.prototype.readFeaturesFromNode = function(node, opt_options) {
var options = {
const options = {
featureType: this.featureType,
featureNS: this.featureNS
};
if (opt_options) {
_ol_obj_.assign(options, this.getReadOptions(node, opt_options));
}
var features = this.readFeaturesInternal(node, [options]);
const features = this.readFeaturesInternal(node, [options]);
return features || [];
};