Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -458,11 +458,6 @@ |
459 | 459 | this.tailAccumulator = res.async; |
460 | 460 | this.tokenCB = res.async.getParentCB ( 'sibling' ); |
461 | 461 | } |
462 | | - |
463 | | - // The next processed chunk should call back as a sibling to last |
464 | | - // accumulator, if any. |
465 | | - //if ( res.async ) { |
466 | | - //} |
467 | 462 | }; |
468 | 463 | |
469 | 464 | /** |
— | — | @@ -952,21 +947,36 @@ |
953 | 948 | */ |
954 | 949 | TokenAccumulator.prototype._returnTokens = |
955 | 950 | function ( reference, tokens, notYetDone, allTokensProcessed ) { |
956 | | - var res, |
957 | | - cb, |
| 951 | + var cb, |
958 | 952 | returnTokens = []; |
959 | 953 | |
| 954 | + |
960 | 955 | if ( ! notYetDone ) { |
961 | 956 | this.outstanding--; |
962 | 957 | } |
963 | 958 | |
964 | 959 | //console.warn( 'TokenAccumulator._returnTokens' ); |
965 | 960 | if ( reference === 'child' ) { |
966 | | - tokens = tokens.concat( this.accum ); |
| 961 | + var res = {}; |
| 962 | + if( !allTokensProcessed ) { |
| 963 | + // There might be transformations missing on the returned tokens, |
| 964 | + // re-transform to make sure those are applied too. |
| 965 | + res = this.manager.transformTokens( tokens, this.parentCB ); |
| 966 | + tokens = res.tokens; |
| 967 | + } |
| 968 | + |
| 969 | + if ( !notYetDone ) { |
| 970 | + // empty accum too |
| 971 | + tokens = tokens.concat( this.accum ); |
| 972 | + this.accum = []; |
| 973 | + } |
967 | 974 | this.manager.env.dp( 'TokenAccumulator._returnTokens child: ', |
968 | 975 | tokens, ' outstanding: ', this.outstanding ); |
969 | | - this.accum = []; |
970 | | - this.parentCB( tokens, this.outstanding ); |
| 976 | + this.parentCB( tokens, this.outstanding, true ); |
| 977 | + |
| 978 | + if ( res.async ) { |
| 979 | + this.parentCB = res.async.getParentCB( 'sibling' ); |
| 980 | + } |
971 | 981 | return null; |
972 | 982 | } else { |
973 | 983 | // sibling |
— | — | @@ -977,7 +987,7 @@ |
978 | 988 | this.manager.env.dp( 'TokenAccumulator._returnTokens: ', |
979 | 989 | 'sibling done and parentCB ', |
980 | 990 | tokens ); |
981 | | - this.parentCB( tokens, false ); |
| 991 | + this.parentCB( tokens, false, true ); |
982 | 992 | return null; |
983 | 993 | } else if ( this.outstanding === 1 && notYetDone ) { |
984 | 994 | this.manager.env.dp( 'TokenAccumulator._returnTokens: ', |
— | — | @@ -987,7 +997,7 @@ |
988 | 998 | // allow the sibling to go direct, and call back parent with |
989 | 999 | // tokens. The internal accumulator is empty at this stage, as its |
990 | 1000 | // tokens are passed to the parent when the child is done. |
991 | | - return this.parentCB( tokens, true); |
| 1001 | + return this.parentCB( tokens, true, true); |
992 | 1002 | } else { |
993 | 1003 | this.accum = this.accum.concat( tokens ); |
994 | 1004 | this.manager.env.dp( 'TokenAccumulator._returnTokens: sibling done, but not overall. notYetDone=', |