https://www.mediawiki.org/wiki/Special:Code/MediaWiki/111838

Revision: 111838
Author:   au
Date:     2012-02-18 18:54:12 +0000 (Sat, 18 Feb 2012)
Log Message:
-----------
* Convert __patched-html-parser to .coffee.

  Note that the compiled .js file (generated by "make"/"make test")
  is still under version control so folks can work on the project
  even without a running "coffee" command in PATH.

  Also updated README to mention coffee-script and "make test".

Modified Paths:
--------------
    trunk/extensions/VisualEditor/tests/parser/Makefile
    trunk/extensions/VisualEditor/tests/parser/README
    trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js

Added Paths:
-----------
    trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.coffee

Modified: trunk/extensions/VisualEditor/tests/parser/Makefile
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/Makefile 2012-02-18 17:28:46 UTC 
(rev 111837)
+++ trunk/extensions/VisualEditor/tests/parser/Makefile 2012-02-18 18:54:12 UTC 
(rev 111838)
@@ -1,8 +1,17 @@
-test :: parserTests.txt
+COFFEE = $(shell find . -name '*.coffee' -a ! -regex '.*node_modules.*' | sed 
's/\.coffee/\.js/')
+
+all :: $(COFFEE)
+
+test :: parserTests.txt all
        node ./parserTests.js --cache parserTests.txt
 
 TESTS_URL = 
http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/tests/parser/parserTests.txt
 parserTests.txt ::
        -if [ ! -e parserTests.txt ] ; then curl -O $(TESTS_URL) || wget 
$(TESTS_URL) ; fi
 
-.PHONY: test
+.PHONY: test all
+
+.SUFFIXES: .coffee .js
+
+.coffee.js:
+       coffee -c -b $<

Modified: trunk/extensions/VisualEditor/tests/parser/README
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/README   2012-02-18 17:28:46 UTC 
(rev 111837)
+++ trunk/extensions/VisualEditor/tests/parser/README   2012-02-18 18:54:12 UTC 
(rev 111838)
@@ -14,6 +14,7 @@
 * libxmljs (requires native compilation)
 * optimist (for argument handling)
 * webworker (not needed for parserTests)
+* coffee-script (if you'd like to modify .coffee files)
 
 == Running parserTests.js ==
 
@@ -21,7 +22,8 @@
 either in a phase3 checkout parallel to extensions (tried by default). You can
 also specify a test case file as an argument.
 
-Then, in this directory, try:
+The "make test" target in this directory downloads parserTests.txt and 
specifies
+it as the test case automatically.  Of course, you may also run tests manually:
 
 node ./parserTests.js
 

Added: trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.coffee
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.coffee    
                        (rev 0)
+++ trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.coffee    
2012-02-18 18:54:12 UTC (rev 111838)
@@ -0,0 +1,30 @@
+module.exports = (HTML5) ->
+  htmlparser = new HTML5.Parser
+
+  htmlparser.tree.elementInActiveFormattingElements = (name) ->
+    els = @activeFormattingElements
+    i = els.length - 1
+    while i >= 0
+      break  if els[i].type is HTML5.Marker.type
+      return els[i]  if els[i].tagName.toLowerCase() is name
+      i--
+    return false
+
+  htmlparser.tree.reconstructActiveFormattingElements = ->
+    return  if @activeFormattingElements.length is 0
+    i = @activeFormattingElements.length - 1
+    entry = @activeFormattingElements[i]
+    return  if entry.type is HTML5.Marker.type or 
@open_elements.indexOf(entry) isnt -1
+    while entry.type isnt HTML5.Marker.type and @open_elements.indexOf(entry) 
is -1
+      i -= 1
+      entry = @activeFormattingElements[i]
+      break  unless entry
+    loop
+      i += 1
+      clone = @activeFormattingElements[i].cloneNode()
+      element = @insert_element(clone.tagName, clone.attributes)
+      @activeFormattingElements[i] = element
+      break  if element is @activeFormattingElements.last()
+    return
+
+  return htmlparser

Modified: trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js
===================================================================
--- trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js        
2012-02-18 17:28:46 UTC (rev 111837)
+++ trunk/extensions/VisualEditor/tests/parser/__patched-html5-parser.js        
2012-02-18 18:54:12 UTC (rev 111838)
@@ -1,43 +1,38 @@
-module.exports = function (HTML5) {
-    var htmlparser = new HTML5.Parser();
-    htmlparser.tree.elementInActiveFormattingElements = function(name) {
-        var els = this.activeFormattingElements;
-        for(var i = els.length - 1; i >= 0; i--) {
-                if(els[i].type == HTML5.Marker.type) break;
-                if(els[i].tagName.toLowerCase() == name) return els[i];
-        }
-        return false;
-    };
-    htmlparser.tree.reconstructActiveFormattingElements = function() {
-       // Within this algorithm the order of steps decribed in the 
specification
-       // is not quite the same as the order of steps in the code. It should 
still
-       // do the same though.
 
-       // Step 1: stop if there's nothing to do
-       if(this.activeFormattingElements.length == 0) return;
-
-       // Step 2 and 3: start with the last element
-       var i = this.activeFormattingElements.length - 1;
-       var entry = this.activeFormattingElements[i];
-       if(entry.type == HTML5.Marker.type || this.open_elements.indexOf(entry) 
!= -1) return;
-
-       while(entry.type != HTML5.Marker.type && 
this.open_elements.indexOf(entry) == -1) {
-               i -= 1;
-               entry = this.activeFormattingElements[i];
-               if(!entry) break;
-       }
-
-       while(true) {
-               i += 1;
-               var clone = this.activeFormattingElements[i].cloneNode();
-
-               var element = this.insert_element(clone.tagName, 
clone.attributes);
-
-               this.activeFormattingElements[i] = element;
-
-               if(element == this.activeFormattingElements.last()) break;
-       }
-    };
-
-    return htmlparser;
+module.exports = function(HTML5) {
+  var htmlparser;
+  htmlparser = new HTML5.Parser;
+  htmlparser.tree.elementInActiveFormattingElements = function(name) {
+    var els, i;
+    els = this.activeFormattingElements;
+    i = els.length - 1;
+    while (i >= 0) {
+      if (els[i].type === HTML5.Marker.type) break;
+      if (els[i].tagName.toLowerCase() === name) return els[i];
+      i--;
+    }
+    return false;
+  };
+  htmlparser.tree.reconstructActiveFormattingElements = function() {
+    var clone, element, entry, i;
+    if (this.activeFormattingElements.length === 0) return;
+    i = this.activeFormattingElements.length - 1;
+    entry = this.activeFormattingElements[i];
+    if (entry.type === HTML5.Marker.type || this.open_elements.indexOf(entry) 
!== -1) {
+      return;
+    }
+    while (entry.type !== HTML5.Marker.type && 
this.open_elements.indexOf(entry) === -1) {
+      i -= 1;
+      entry = this.activeFormattingElements[i];
+      if (!entry) break;
+    }
+    while (true) {
+      i += 1;
+      clone = this.activeFormattingElements[i].cloneNode();
+      element = this.insert_element(clone.tagName, clone.attributes);
+      this.activeFormattingElements[i] = element;
+      if (element === this.activeFormattingElements.last()) break;
+    }
+  };
+  return htmlparser;
 };


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to