@@ -29,7 +29,7 @@ analyze = function(ast, buffer) {
29
29
} ;
30
30
31
31
_analyze = function ( node , buffer , bufferLengthMinus ) {
32
- var currScope , i , isScope , name , parent , scope , sub , _i , _len , _ref ;
32
+ var currScope , i , isScope , name , parent , part , scope , sub , _i , _j , _len , _len1 , _ref ;
33
33
if ( bufferLengthMinus == null ) {
34
34
bufferLengthMinus = 1 ;
35
35
}
@@ -44,17 +44,32 @@ _analyze = function(node, buffer, bufferLengthMinus) {
44
44
scope . _childScopes = [ ] ;
45
45
scope . _unscopedVars = [ ] ;
46
46
buffer . push ( scope ) ;
47
- } else if ( name === 'get' || name === 'virtual' ) {
47
+ } else if ( name === 'get' ) {
48
48
currScope = buffer [ buffer . length - bufferLengthMinus ] ;
49
49
if ( currScope ) {
50
50
if ( node . length === 2 ) {
51
51
node . _varKey = node . toString ( ) ;
52
52
currScope . _unscopedVars . push ( node ) ;
53
53
}
54
54
}
55
+ } else if ( name instanceof Array ) {
56
+ for ( _i = 0 , _len = node . length ; _i < _len ; _i ++ ) {
57
+ part = node [ _i ] ;
58
+ if ( part [ 0 ] === 'virtual' ) {
59
+ part . _dontHoist = true ;
60
+ }
61
+ }
62
+ } else if ( name === 'virtual' ) {
63
+ currScope = buffer [ buffer . length - bufferLengthMinus ] ;
64
+ if ( currScope ) {
65
+ if ( ! node . _dontHoist ) {
66
+ node . _varKey = node . toString ( ) ;
67
+ currScope . _unscopedVars . push ( node ) ;
68
+ }
69
+ }
55
70
}
56
71
_ref = node . slice ( 0 , + node . length + 1 || 9e9 ) ;
57
- for ( i = _i = 0 , _len = _ref . length ; _i < _len ; i = ++ _i ) {
72
+ for ( i = _j = 0 , _len1 = _ref . length ; _j < _len1 ; i = ++ _j ) {
58
73
sub = _ref [ i ] ;
59
74
if ( sub instanceof Array ) {
60
75
if ( name === 'rule' && i === 1 ) {
@@ -81,7 +96,7 @@ mutate = function(buffer) {
81
96
} ;
82
97
83
98
_mutate = function ( node ) {
84
- var child , hoistLevel , hoister , level , parent , unscoped , upper_unscoped , _i , _j , _k , _len , _len1 , _len2 , _ref , _ref1 , _ref2 , _ref3 , _results ;
99
+ var child , clone , hoistLevel , hoister , level , parent , unscoped , unscopedCommand , upper_unscoped , _i , _j , _k , _len , _len1 , _len2 , _ref , _ref1 , _ref2 , _ref3 , _results ;
85
100
_ref = node . _childScopes ;
86
101
for ( _i = 0 , _len = _ref . length ; _i < _len ; _i ++ ) {
87
102
child = _ref [ _i ] ;
@@ -112,7 +127,16 @@ _mutate = function(node) {
112
127
if ( hoistLevel > 1 ) {
113
128
hoister . push ( hoistLevel ) ;
114
129
}
115
- _results . push ( unscoped . splice ( 1 , 0 , hoister ) ) ;
130
+ unscopedCommand = unscoped [ 0 ] ;
131
+ if ( unscopedCommand === 'get' ) {
132
+ _results . push ( unscoped . splice ( 1 , 0 , hoister ) ) ;
133
+ } else if ( unscopedCommand === 'virtual' ) {
134
+ clone = unscoped . splice ( 0 , 2 ) ;
135
+ unscoped . push ( hoister ) ;
136
+ _results . push ( unscoped . push ( clone ) ) ;
137
+ } else {
138
+ _results . push ( void 0 ) ;
139
+ }
116
140
} else {
117
141
_results . push ( void 0 ) ;
118
142
}
0 commit comments