File tree 2 files changed +72
-6
lines changed
2 files changed +72
-6
lines changed Original file line number Diff line number Diff line change @@ -482,13 +482,17 @@ function OutputStream(options) {
482
482
nodetype . DEFMETHOD ( "_codegen" , generator ) ;
483
483
} ;
484
484
485
- var use_asm = false ;
486
485
var in_directive = false ;
486
+ var active_scope = null ;
487
+ var use_asm = null ;
487
488
488
489
AST_Node . DEFMETHOD ( "print" , function ( stream , force_parens ) {
489
- var self = this , generator = self . _codegen , prev_use_asm = use_asm ;
490
- if ( self instanceof AST_Directive && self . value == "use asm" && stream . parent ( ) instanceof AST_Scope ) {
491
- use_asm = true ;
490
+ var self = this , generator = self . _codegen ;
491
+ if ( self instanceof AST_Scope ) {
492
+ active_scope = self ;
493
+ }
494
+ else if ( ! use_asm && self instanceof AST_Directive && self . value == "use asm" ) {
495
+ use_asm = active_scope ;
492
496
}
493
497
function doit ( ) {
494
498
self . add_comments ( stream ) ;
@@ -502,8 +506,8 @@ function OutputStream(options) {
502
506
doit ( ) ;
503
507
}
504
508
stream . pop_node ( ) ;
505
- if ( self instanceof AST_Scope ) {
506
- use_asm = prev_use_asm ;
509
+ if ( self === use_asm ) {
510
+ use_asm = null ;
507
511
}
508
512
} ) ;
509
513
AST_Node . DEFMETHOD ( "_print" , AST_Node . prototype . print ) ;
Original file line number Diff line number Diff line change @@ -104,3 +104,65 @@ asm_mixed: {
104
104
}
105
105
}
106
106
107
+ asm_toplevel: {
108
+ options = { }
109
+ input: {
110
+ "use asm" ;
111
+ 0.0 ;
112
+ function f ( ) {
113
+ 0.0 ;
114
+ ( function ( ) {
115
+ 0.0 ;
116
+ } ) ;
117
+ }
118
+ 0.0 ;
119
+ }
120
+ expect_exact: '"use asm";0.0;function f(){0.0;(function(){0.0})}0.0;'
121
+ }
122
+
123
+ asm_function_expression: {
124
+ options = { }
125
+ input: {
126
+ 0.0 ;
127
+ var a = function ( ) {
128
+ "use asm" ;
129
+ 0.0 ;
130
+ }
131
+ function f ( ) {
132
+ 0.0 ;
133
+ return function ( ) {
134
+ "use asm" ;
135
+ 0.0 ;
136
+ }
137
+ 0.0 ;
138
+ }
139
+ 0.0 ;
140
+ }
141
+ expect_exact: '0;var a=function(){"use asm";0.0};function f(){0;return function(){"use asm";0.0};0}0;'
142
+ }
143
+
144
+ asm_nested_functions: {
145
+ options = { }
146
+ input: {
147
+ 0.0 ;
148
+ function a ( ) {
149
+ "use asm" ;
150
+ 0.0 ;
151
+ }
152
+ 0.0 ;
153
+ function b ( ) {
154
+ 0.0 ;
155
+ function c ( ) {
156
+ "use asm" ;
157
+ 0.0 ;
158
+ }
159
+ 0.0 ;
160
+ function d ( ) {
161
+ 0.0 ;
162
+ }
163
+ 0.0 ;
164
+ }
165
+ 0.0 ;
166
+ }
167
+ expect_exact: '0;function a(){"use asm";0.0}0;function b(){0;function c(){"use asm";0.0}0;function d(){0}0}0;'
168
+ }
You can’t perform that action at this time.
0 commit comments