File tree Expand file tree Collapse file tree 5 files changed +42
-9
lines changed Expand file tree Collapse file tree 5 files changed +42
-9
lines changed Original file line number Diff line number Diff line change @@ -2817,6 +2817,9 @@ exports.For = For = (function(superclass){
2817
2817
o . ref = this . item . value ;
2818
2818
}
2819
2819
if ( this [ 'let' ] ) {
2820
+ if ( that = this . body . getJump ( ) ) {
2821
+ that instanceof Return || that . carp ( 'inconvertible statement' ) ;
2822
+ }
2820
2823
if ( this . returns ) {
2821
2824
this . body = this . body . makeReturn ( ) ;
2822
2825
}
Original file line number Diff line number Diff line change @@ -136,6 +136,9 @@ exports.doID = function(code, index){
136
136
case 'super' :
137
137
return this . token ( 'LITERAL' , id , true ) . length ;
138
138
case 'for' :
139
+ if ( ( ref$ = this . tokens ) [ ref$ . length - 1 ] [ 0 ] === 'LET' ) {
140
+ this . carp ( "unexpected 'FOR'" ) ;
141
+ }
139
142
this . seenFor = true ;
140
143
this . wantBy = false ;
141
144
break ;
@@ -206,9 +209,11 @@ exports.doID = function(code, index){
206
209
break ;
207
210
case 'let' :
208
211
if ( ( ref$ = this . tokens ) [ ref$ . length - 1 ] [ 0 ] === 'FOR' ) {
209
- this . tokens . pop ( ) ;
210
- this . token ( 'LET' , 'let' ) ;
211
- this . token ( 'FOR' , 'for' ) ;
212
+ this . tokens . splice ( this . tokens . length - 1 , 0 , [ 'LET' , 'let' ] ) ;
213
+ return input . length ;
214
+ }
215
+ if ( ( ref$ = this . tokens ) [ ref$ . length - 1 ] [ 0 ] === 'OWN' && ( ref$ = this . tokens ) [ ref$ . length - 2 ] [ 0 ] === 'FOR' ) {
216
+ this . tokens . splice ( this . tokens . length - 2 , 0 , [ 'LET' , 'let' ] ) ;
212
217
return input . length ;
213
218
}
214
219
break ;
Original file line number Diff line number Diff line change @@ -1746,6 +1746,8 @@ class exports.For extends While
1746
1746
head += \\n + o.indent + itemAssign.compile(o, LEVEL_TOP) + \;
1747
1747
o.ref = @item.value if @ref
1748
1748
if @let
1749
+ if @body.getJump!
1750
+ that instanceof Return or that.carp 'inconvertible statement'
1749
1751
@body.=makeReturn! if @returns
1750
1752
@body = Block Call.let capture, @body
1751
1753
body = @compileBody o
Original file line number Diff line number Diff line change @@ -105,7 +105,10 @@ exports import
105
105
case \return \throw then tag = \HURL
106
106
case \break \continue then tag = \JUMP
107
107
case \this \eval \super then return @token(\LITERAL id, true)length
108
- case \for then @seenFor = true; @wantBy = false
108
+ case \for then
109
+ if @tokens[*-1]0 is \LET
110
+ @carp "unexpected 'FOR'"
111
+ @seenFor = true; @wantBy = false
109
112
case \then then @seenFor = @wantBy = false
110
113
case \catch \function then id = ''
111
114
case \in \of
@@ -139,11 +142,13 @@ exports import
139
142
if able @tokens then id = \<<<; break
140
143
fallthrough
141
144
case \export \const \var then tag = \DECL
142
- case \let then if @tokens[*-1]0 is \FOR
143
- @tokens.pop!
144
- @token \LET \let
145
- @token \FOR \for
146
- return input.length
145
+ case \let then
146
+ if @tokens[*-1]0 is \FOR
147
+ @tokens.splice @tokens.length-1 0 <[LET let]>
148
+ return input.length
149
+ if @tokens[*-1]0 is \OWN and @tokens[*-2]0 is \FOR
150
+ @tokens.splice @tokens.length-2 0 <[LET let]>
151
+ return input.length
147
152
default
148
153
break if id of KEYWORDS_SHARED
149
154
@carp "reserved word \"#id\"" if id of KEYWORDS_UNUSED
Original file line number Diff line number Diff line change @@ -342,6 +342,24 @@ for [0]
342
342
for [2] => ok 2 of [2]
343
343
ok 3 not in []
344
344
345
+ # `(1; continue)` to avoid `continue` getting optimized away by `While::addBody`
346
+ compileThrows 'inconvertible statement' 1 'for let a in b then (1; continue)'
347
+ compileThrows 'inconvertible statement' 1 'for let a in b then break'
348
+ compileThrows "unexpected 'FOR'" 1 'let for a in b then'
349
+
350
+ # parses correctly with `own`
351
+ for own let a in []
352
+ 1
353
+
354
+ for let own a in []
355
+ 1
356
+
357
+ i = 2
358
+ a = while --i
359
+ for let a of [0 1]
360
+ a + i
361
+ ok '' ''+a
362
+
345
363
x = 2
346
364
for let a in []
347
365
x = 3
You can’t perform that action at this time.
0 commit comments