This repository was archived by the owner on Mar 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed
Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -143,12 +143,14 @@ JsFile.prototype = {
143143 // in duplicate tokens on `export default function() {}`
144144 // (https://code.google.com/p/esprima/issues/detail?id=631)
145145 if ( this . getDialect ( ) === 'es6' ) {
146- var lastToken ;
146+ var tokenHash = { } ;
147147 this . _tree . tokens = this . _tree . tokens . filter ( function ( token , i ) {
148- var prevToken = lastToken ;
149- lastToken = token ;
148+ var hashKey = token . range [ 0 ] + '_' + token . range [ 1 ] ;
149+ var isDuplicate = tokenHash [ hashKey ] ;
150150
151- return ! prevToken || prevToken . range [ 0 ] !== token . range [ 0 ] || prevToken . range [ 1 ] !== token . range [ 1 ] ;
151+ tokenHash [ hashKey ] = true ;
152+
153+ return ! isDuplicate ;
152154 } ) ;
153155 }
154156
Original file line number Diff line number Diff line change @@ -205,6 +205,15 @@ describe('modules/js-file', function() {
205205 createHarmonyJsFile ( 'export default function() {}' ) . iterateTokenByValue ( '(' , spy ) ;
206206 assert ( spy . calledOnce ) ;
207207 } ) ;
208+
209+ it ( 'should not have duplicate tokens in es6 export default statements' , function ( ) {
210+ var spy = sinon . spy ( ) ;
211+ createHarmonyJsFile ( 'export default function init() {\n' +
212+ ' window.addEventListener(\'fb-flo-reload\', function(ev) {\n' +
213+ ' });\n' +
214+ '}' ) . iterateTokenByValue ( '(' , spy ) ;
215+ assert ( spy . calledThrice ) ;
216+ } ) ;
208217 } ) ;
209218
210219 describe ( 'getNodeByRange' , function ( ) {
You can’t perform that action at this time.
0 commit comments