Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/60847
Change subject: JSHint cleanups: forward declarations, disambiguate variables.
......................................................................
JSHint cleanups: forward declarations, disambiguate variables.
Rearrange code where it's possible to ensure functions appear before uses.
In other places, add an explicit forward declaration. This isn't strictly
necessary, but it technically ensures that behavior is the same across
JavaScript implementations (the spec allows different initialization behavior)
and it shuts jshint up. Seems easy enough to make jshint happy.
One case where two variables named 'tsr0' appear in the same scope; renamed
them slightly to avoid the conflict. (This lets jshint catch if I missed a
renaming; if I'd just moved the declaration to the top of the method it
would be possible to hide a scope error.)
Change-Id: I35699cdd5cee02883a9f35fc5de3954080e72e0c
---
M js/lib/ext.core.LinkHandler.js
M js/lib/ext.core.PreHandler.js
M js/lib/mediawiki.DOMPostProcessor.js
M js/lib/mediawiki.Title.js
M js/lib/mediawiki.TokenTransformManager.js
M js/lib/mediawiki.parser.defines.js
M js/lib/mediawiki.parser.js
7 files changed, 61 insertions(+), 48 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid
refs/changes/47/60847/1
diff --git a/js/lib/ext.core.LinkHandler.js b/js/lib/ext.core.LinkHandler.js
index 7eb2666..1458981 100644
--- a/js/lib/ext.core.LinkHandler.js
+++ b/js/lib/ext.core.LinkHandler.js
@@ -858,9 +858,9 @@
//
// targetOff covers all spaces before content
// and we need src without those spaces.
- var tsr0 = dataAttribs.tsr[0] + 1,
- tsr1 = dataAttribs.targetOff -
(token.getAttribute('spaces') || '').length;
- aStart.addNormalizedAttribute( 'href', href,
env.page.src.substring(tsr0, tsr1) );
+ var tsr0a = dataAttribs.tsr[0] + 1,
+ tsr1a = dataAttribs.targetOff -
(token.getAttribute('spaces') || '').length;
+ aStart.addNormalizedAttribute( 'href', href,
env.page.src.substring(tsr0a, tsr1a) );
}
cb( {
tokens: [aStart].concat(content, [new EndTagTk('a')])
@@ -877,11 +877,11 @@
var da = token.dataAttribs,
// targetOff covers all spaces before content
// and we need src without those spaces.
- tsr0 = da.tsr[0] + 1,
- tsr1 = da.targetOff - spaces.length,
+ tsr0b = da.tsr[0] + 1,
+ tsr1b = da.targetOff - spaces.length,
span = new TagTk('span', [new KV('typeof',
'mw:Placeholder')], {
- tsr: [tsr0, tsr1],
- src:
env.page.src.substring(tsr0, tsr1)
+ tsr: [tsr0b, tsr1b],
+ src:
env.page.src.substring(tsr0b, tsr1b)
} );
tokens.push(span);
diff --git a/js/lib/ext.core.PreHandler.js b/js/lib/ext.core.PreHandler.js
index 1c4a194..ee66131 100644
--- a/js/lib/ext.core.PreHandler.js
+++ b/js/lib/ext.core.PreHandler.js
@@ -79,6 +79,8 @@
SelfclosingTagTk = defines.SelfclosingTagTk,
EndTagTk = defines.EndTagTk;
+var init; // forward declaration.
+
// Constructor
function PreHandler( manager, options ) {
this.manager = manager;
@@ -118,7 +120,7 @@
5: 'ignore '
};
-function init(handler, addAnyHandler) {
+init = function(handler, addAnyHandler) {
handler.state = PreHandler.STATE_SOL;
handler.lastNlTk = null;
// Initialize to zero to deal with indent-pre
@@ -133,7 +135,7 @@
handler.manager.addTransform(handler.onAny.bind(handler),
"PreHandler:onAny", handler.anyRank, 'any');
}
-}
+};
PreHandler.prototype.moveToIgnoreState = function() {
this.state = PreHandler.STATE_IGNORE;
diff --git a/js/lib/mediawiki.DOMPostProcessor.js
b/js/lib/mediawiki.DOMPostProcessor.js
index 6bb1aa5..75a5e5c 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -2174,6 +2174,8 @@
return [cs, e];
}
+var saveDataParsoid; // forward declaration
+
function dumpDomWithDataAttribs( root ) {
function cloneData(node, clone) {
var d = node.data;
@@ -2287,6 +2289,8 @@
}
}
+var findAndHandleNeighbour; // forward declaration
+
/**
* Function for fetching the link prefix based on a link node.
*
@@ -2330,7 +2334,7 @@
/**
* Abstraction of both link-prefix and link-trail searches.
*/
-function findAndHandleNeighbour( env, goForward, regex, node, baseAbout ) {
+findAndHandleNeighbour = function( env, goForward, regex, node, baseAbout ) {
var value, matches, document, nextSibling,
nextNode = goForward ? 'nextSibling' : 'previousSibling',
innerNode = goForward ? 'firstChild' : 'lastChild',
@@ -2388,7 +2392,7 @@
}
return result;
-}
+};
/**
* Workhorse function for bringing linktrails and link prefixes into link
content.
@@ -2446,11 +2450,11 @@
*
* Save the data-parsoid attributes on each node.
*/
-function saveDataParsoid( node ) {
+saveDataParsoid = function( node ) {
if ( node.nodeType === node.ELEMENT_NODE && node.data ) {
DU.saveDataAttribs( node );
}
-}
+};
/**
* @method
diff --git a/js/lib/mediawiki.Title.js b/js/lib/mediawiki.Title.js
index 7cffe4e..8e4f90e 100644
--- a/js/lib/mediawiki.Title.js
+++ b/js/lib/mediawiki.Title.js
@@ -2,6 +2,8 @@
var Util = require('./mediawiki.Util.js').Util;
+var Namespace; // forward declaration
+
/**
* @class
*
@@ -103,7 +105,7 @@
* @param {number} id The id of the namespace to represent.
* @param {MWParserEnvironment} env
*/
-function Namespace( id, env ) {
+Namespace = function( id, env ) {
var ids = env.conf.wiki.namespaceIds;
var names = env.conf.wiki.namespaceNames;
this.id = Number( id );
@@ -125,7 +127,7 @@
'0': '',
'14': 'Category'
};
-}
+};
/**
* @method
diff --git a/js/lib/mediawiki.TokenTransformManager.js
b/js/lib/mediawiki.TokenTransformManager.js
index c0be000..dd85379 100644
--- a/js/lib/mediawiki.TokenTransformManager.js
+++ b/js/lib/mediawiki.TokenTransformManager.js
@@ -26,6 +26,9 @@
Params = defines.Params,
ParserValue = defines.ParserValue;
+// forward declarations
+var TokenAccumulator, Frame, ExpansionCache;
+
function verifyTokensIntegrity(ret, nullOkay) {
// FIXME: Where is this coming from?
@@ -1169,14 +1172,14 @@
* @param {Object} manager
* @param {Function} parentCB The callback to call after we've finished
accumulating.
*/
-function TokenAccumulator( manager, parentCB ) {
+TokenAccumulator = function( manager, parentCB ) {
this.uid = tid++; // useful for debugging
this.manager = manager;
this.parentCB = parentCB;
this.siblingToks = [];
this.waitForChild = true;
this.waitForSibling = true;
-}
+};
TokenAccumulator.prototype.setParentCB = function ( cb ) {
this.parentCB = cb;
@@ -1309,7 +1312,7 @@
* exceed the maximum expansion depth.
*/
-function Frame( title, manager, args, parentFrame ) {
+Frame = function( title, manager, args, parentFrame ) {
this.title = title;
this.manager = manager;
this.args = new Params( args );
@@ -1338,7 +1341,7 @@
this.depth = 0;
this._cacheKey = args._cacheKey;
}
-}
+};
/**
* Create a new child frame
@@ -1553,9 +1556,9 @@
*
* A specialized expansion cache, normally associated with a chunk of tokens.
*/
-function ExpansionCache ( n ) {
+ExpansionCache = function( n ) {
this._cache = new LRU( n );
-}
+};
ExpansionCache.prototype.makeKey = function ( frame, options ) {
//console.warn( frame._cacheKey );
diff --git a/js/lib/mediawiki.parser.defines.js
b/js/lib/mediawiki.parser.defines.js
index 6d88a3e..d993319 100644
--- a/js/lib/mediawiki.parser.defines.js
+++ b/js/lib/mediawiki.parser.defines.js
@@ -5,13 +5,6 @@
* @singleton
*/
-/**
- * @class Token
- * @abstract
- *
- * Catch-all class for all token types.
- */
-
var async = require('async'),
$ = require( './fakejquery' );
@@ -19,6 +12,31 @@
String.prototype.isHTMLTag = function() {
return false;
};
+
+/**
+ * @class
+ *
+ * Key-value pair.
+ *
+ * @constructor
+ * @param {Mixed} k
+ * @param {Mixed} v
+ * @param {Array} srcOffsets The source offsets.
+ */
+function KV ( k, v, srcOffsets ) {
+ this.k = k;
+ this.v = v;
+ if (srcOffsets) {
+ this.srcOffsets = srcOffsets;
+ }
+}
+
+/**
+ * @class Token
+ * @abstract
+ *
+ * Catch-all class for all token types.
+ */
/**
* @member Token
@@ -309,24 +327,6 @@
return tsr ? env.page.src.substring(tsr[0], tsr[1]) : null;
}
};
-
-/**
- * @class
- *
- * Key-value pair.
- *
- * @constructor
- * @param {Mixed} k
- * @param {Mixed} v
- * @param {Array} srcOffsets The source offsets.
- */
-function KV ( k, v, srcOffsets ) {
- this.k = k;
- this.v = v;
- if (srcOffsets) {
- this.srcOffsets = srcOffsets;
- }
-}
/**
* @class
diff --git a/js/lib/mediawiki.parser.js b/js/lib/mediawiki.parser.js
index 00498a0..d45f163 100644
--- a/js/lib/mediawiki.parser.js
+++ b/js/lib/mediawiki.parser.js
@@ -42,6 +42,8 @@
TreeBuilder =
require('./mediawiki.HTML5TreeBuilder.node.js').FauxHTML5.TreeBuilder,
DOMPostProcessor =
require('./mediawiki.DOMPostProcessor.js').DOMPostProcessor;
+var ParserPipeline; // forward declaration
+
function ParserPipelineFactory ( env ) {
this.pipelineCache = {};
this.env = env;
@@ -326,7 +328,7 @@
* supposed to emit events, while the first is supposed to support a process()
* method that sets the pipeline in motion.
*/
-function ParserPipeline ( stages, returnToCacheCB, env ) {
+ParserPipeline = function( stages, returnToCacheCB, env ) {
this.stages = stages;
this.first = stages[0];
this.last = stages.last();
@@ -341,7 +343,7 @@
// add a callback to return the pipeline back to the cache
this.last.addListener( 'end', this.returnToCacheCB );
}
-}
+};
/*
* Applies the function across all stages and transformers registered at each
stage
--
To view, visit https://gerrit.wikimedia.org/r/60847
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I35699cdd5cee02883a9f35fc5de3954080e72e0c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits