@@ -264,11 +264,12 @@ if (typeof J$ === 'undefined') {
264264 var visitorReplaceInExpr = {
265265 'Identifier' : function ( node ) {
266266 if ( node . name . indexOf ( RP ) === 0 ) {
267- var i = parseInt ( node . name . substring ( RP . length ) ) ;
268- return asts [ i ] ;
269- } else {
270- return node ;
267+ var suffix = node . name . substring ( RP . length ) ;
268+ if ( ! isNaN ( suffix ) ) {
269+ return asts [ suffix ] ;
270+ }
271271 }
272+ return node ;
272273 } ,
273274 'BlockStatement' : function ( node ) {
274275 if ( node . body [ 0 ] . type === 'ExpressionStatement' && isArr ( node . body [ 0 ] . expression ) ) {
@@ -1819,9 +1820,19 @@ if (typeof J$ === 'undefined') {
18191820 }
18201821 }
18211822 for ( var i = startIndex ; i < ast . body . length ; i ++ ) {
1822-
18231823 if ( ast . body [ i ] . type === 'FunctionDeclaration' ) {
1824- newBody . push ( ast . body [ i ] ) ;
1824+ var name = ast . body [ i ] . id . name ;
1825+ var params = ast . body [ i ] . params . map ( function ( param ) { return param . name ; } ) . join ( ', ' ) ;
1826+ var assignStmt ;
1827+ if ( ast . body [ i ] . body === null ) {
1828+ assignStmt = acorn . parse (
1829+ "var " + name + " = function " + name + "(" + params + ") {}" ) . body ;
1830+ } else {
1831+ assignStmt = replaceInStatement (
1832+ "var " + name + " = function " + name + "(" + params + ") { " + RP + "1 }" ,
1833+ ast . body [ i ] . body . body ) ;
1834+ }
1835+ newBody . push ( assignStmt [ 0 ] ) ;
18251836 if ( newBody . length !== i + 1 ) {
18261837 hoisteredFunctions . push ( ast . body [ i ] . id . name ) ;
18271838 }
@@ -1835,9 +1846,7 @@ if (typeof J$ === 'undefined') {
18351846 while ( ast . body . length > 0 ) {
18361847 ast . body . pop ( ) ;
18371848 }
1838- for ( var i = 0 ; i < newBody . length ; i ++ ) {
1839- ast . body . push ( newBody [ i ] ) ;
1840- }
1849+ Array . prototype . push . apply ( ast . body , newBody ) ;
18411850 } else {
18421851 //console.log(typeof ast.body);
18431852 }
0 commit comments