r110508 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110507‎ | r110508 | r110509 >
Date:18:37, 1 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Remove type attribute for tag tokens.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.Util.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.Sanitizer.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js
@@ -168,7 +168,7 @@
169169 }
170170 }
171171 } else if ( ( ctx.prevToken.constructor === NlTk ||
172 - ctx.prevToken.type === 'TAG' ) &&
 172+ ctx.prevToken.constructor === TagTk ) &&
173173 firstmultiletterword == -1 ) {
174174 // This is an approximation, as the original doQuotes
175175 // operates on the source and just looks at space vs.
@@ -244,18 +244,15 @@
245245 //console.log( 'quotesToTags t: ' + JSON.stringify( t, null, 2));
246246
247247 if(toggle) {
248 - t.type = 'TAG';
 248+ chunks[j][0] = new TagTk( name, t.attribs );
249249 } else {
250 - t.type = 'ENDTAG';
 250+ chunks[j][0] = new EndTagTk( name, t.attribs );
251251 }
252 - t.name = name;
253 - delete t.value;
254 - chunks[j][0] = t;
255252 toggle = !toggle;
256253 }
257254 if (!toggle) {
258255 // Add end tag
259 - this.currentChunk.push( {type: 'ENDTAG', name: name} );
 256+ this.currentChunk.push( new EndTagTk( name ) );
260257 }
261258 };
262259
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js
@@ -17,7 +17,7 @@
1818 this.parser.parse(this);
1919
2020 // implicitly start a new document
21 - this.processToken({type: 'TAG', name: 'body'});
 21+ this.processToken(new TagTk( 'body' ));
2222 };
2323
2424 // Inherit from EventEmitter
@@ -53,7 +53,7 @@
5454
5555 // XXX: more clean up to allow reuse.
5656 this.parser.setup();
57 - this.processToken({type: 'TAG', name: 'body'});
 57+ this.processToken(new TagTk( 'body' ));
5858 };
5959
6060 FauxHTML5.TreeBuilder.prototype._att = function (maybeAttribs) {
@@ -77,30 +77,30 @@
7878 break;
7979 case NlTk:
8080 break;
 81+ case TagTk:
 82+ this.emit('token', {type: 'StartTag',
 83+ name: token.name,
 84+ data: this._att(token.attribs)});
 85+ break;
 86+ case SelfclosingTagTk:
 87+ this.emit('token', {type: 'StartTag',
 88+ name: token.name,
 89+ data: this._att(token.attribs)});
 90+ if ( HTML5.VOID_ELEMENTS.indexOf( token.name.toLowerCase() ) < 0 ) {
 91+ // VOID_ELEMENTS are automagically treated as self-closing by
 92+ // the tree builder
 93+ this.emit('token', {type: 'EndTag',
 94+ name: token.name,
 95+ data: this._att(token.attribs)});
 96+ }
 97+ break;
 98+ case EndTagTk:
 99+ this.emit('token', {type: 'EndTag',
 100+ name: token.name,
 101+ data: this._att(token.attribs)});
 102+ break;
81103 default:
82104 switch (token.type) {
83 - case "TAG":
84 - this.emit('token', {type: 'StartTag',
85 - name: token.name,
86 - data: this._att(token.attribs)});
87 - break;
88 - case "ENDTAG":
89 - this.emit('token', {type: 'EndTag',
90 - name: token.name,
91 - data: this._att(token.attribs)});
92 - break;
93 - case "SELFCLOSINGTAG":
94 - this.emit('token', {type: 'StartTag',
95 - name: token.name,
96 - data: this._att(token.attribs)});
97 - if ( HTML5.VOID_ELEMENTS.indexOf( token.name.toLowerCase() ) < 0 ) {
98 - // VOID_ELEMENTS are automagically treated as self-closing by
99 - // the tree builder
100 - this.emit('token', {type: 'EndTag',
101 - name: token.name,
102 - data: this._att(token.attribs)});
103 - }
104 - break;
105105 case "COMMENT":
106106 this.emit('token', {type: 'Comment',
107107 data: token.value});
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -494,13 +494,13 @@
495495 case NlTk:
496496 res = this._transformToken( token, cb, phaseEndRank, ts.newline );
497497 break;
 498+ case TagTk:
 499+ case EndTagTk:
 500+ case SelfclosingTagTk:
 501+ res = this._transformTagToken( token, cb, phaseEndRank );
 502+ break;
498503 default:
499504 switch( token.type ) {
500 - case 'TAG':
501 - case 'ENDTAG':
502 - case 'SELFCLOSINGTAG':
503 - res = this._transformTagToken( token, cb, phaseEndRank );
504 - break;
505505 case 'COMMENT':
506506 res = this._transformToken( token, cb, phaseEndRank, ts.comment);
507507 break;
@@ -676,13 +676,13 @@
677677 case NlTk:
678678 res = this._transformToken( token, cb, this.phaseEndRank, ts.newline );
679679 break;
 680+ case TagTk:
 681+ case EndTagTk:
 682+ case SelfclosingTagTk:
 683+ res = this._transformTagToken( token, cb, this.phaseEndRank );
 684+ break;
680685 default:
681686 switch( token.type ) {
682 - case 'TAG':
683 - case 'ENDTAG':
684 - case 'SELFCLOSINGTAG':
685 - res = this._transformTagToken( token, cb, this.phaseEndRank );
686 - break;
687687 case 'COMMENT':
688688 res = this._transformToken( token, cb, this.phaseEndRank, ts.comment );
689689 break;
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js
@@ -3,18 +3,18 @@
44 * strings or String objects (if attributes are needed).
55 */
66 function TagTk( name, attribs ) {
7 - this.type = 'TAG';
 7+ //this.type = 'TAG';
88 this.name = name;
99 this.attribs = attribs || [];
1010 }
1111
1212 function EndTagTk( name, attribs ) {
13 - this.type = 'ENDTAG';
 13+ //this.type = 'ENDTAG';
1414 this.name = name;
1515 this.attribs = attribs || [];
1616 }
1717 function SelfclosingTagTk( name, attribs ) {
18 - this.type = 'SELFCLOSINGTAG';
 18+ //this.type = 'SELFCLOSINGTAG';
1919 this.name = name;
2020 this.attribs = attribs || [];
2121 }
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js
@@ -80,7 +80,7 @@
8181 };
8282
8383 ParserFunctions.prototype['pf_#tag'] = function ( target, argList, argDict ) {
84 - return [{type: 'TAG', name: target, attribs: argList}];
 84+ return [new TagTk(target, argList)];
8585 };
8686
8787 // A first approximation, anyway..
Index: trunk/extensions/VisualEditor/modules/parser/ext.Util.js
@@ -16,9 +16,9 @@
1717 * @returns {Boolean}: True if token is block-level, false otherwise.
1818 */
1919 Util.prototype.isBlockToken = function ( token ) {
20 - if ( token.type === 'TAG' ||
21 - token.type === 'ENDTAG' ||
22 - token.type === 'SELFCLOSINGTAG' ) {
 20+ if ( token.constructor === TagTk ||
 21+ token.constructor === EndTagTk ||
 22+ token.constructor === SelfclosingTagTk ) {
2323 return this.isBlockTag( token.name.toLowerCase() );
2424 } else {
2525 return false;
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -150,8 +150,8 @@
151151
152152 for (var i = 0, length = tokens.length; i < length; i++) {
153153 var token = tokens[i];
154 - switch ( token.type ) {
155 - case 'TAG':
 154+ switch ( token.constructor ) {
 155+ case TagTk:
156156 switch (token.name) {
157157 case 'list':
158158 // ignore token
@@ -168,7 +168,7 @@
169169 break;
170170 }
171171 break;
172 - case 'ENDTAG':
 172+ case EndTagTk:
173173 if ( token.name == 'list' ) {
174174 // pop all open list item tokens
175175 popTags(bstack.length);
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.Sanitizer.js
@@ -29,7 +29,7 @@
3030
3131 Sanitizer.prototype.onAnchor = function ( token ) {
3232 // perform something similar to Sanitizer::cleanUrl
33 - if ( token.type === 'ENDTAG' ) {
 33+ if ( token.constructor === EndTagTk ) {
3434 return { token: token };
3535 }
3636 var hrefKV = this.manager.env.lookupKV( token.attribs, 'href' );
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js
@@ -85,7 +85,7 @@
8686 // None of the tokens we are interested in, so abort processing..
8787 //console.log( 'PostExpandParagraphHandler.onAny: ' + JSON.stringify( this.tokens, null , 2 ) );
8888 if ( this.newLines >= 2 && ! u.isBlockToken( token ) ) {
89 - return { tokens: [ { type: 'TAG', name: 'p' } ].concat( this._finish() ) };
 89+ return { tokens: [ new TagTk( 'p' ) ].concat( this._finish() ) };
9090 } else {
9191 return { tokens: this._finish() };
9292 }

Status & tagging log