1
- /** @import { ArrowFunctionExpression, Expression, Identifier } from 'estree' */
1
+ /** @import { ArrowFunctionExpression, Expression, Identifier, Pattern } from 'estree' */
2
2
/** @import { AST } from '#compiler' */
3
3
/** @import { Parser } from '../index.js' */
4
4
import read_pattern from '../read/context.js' ;
@@ -143,16 +143,29 @@ function open(parser) {
143
143
parser . index = end ;
144
144
}
145
145
}
146
- parser . eat ( 'as' , true ) ;
147
- parser . require_whitespace ( ) ;
148
-
149
- const context = read_pattern ( parser ) ;
150
-
151
- parser . allow_whitespace ( ) ;
152
146
147
+ // TODO replace with guaranteed-not-conflicting identifier, or make context possibly null
148
+ /** @type {Pattern } */
149
+ let context = { type : 'Identifier' , start : - 1 , end : - 1 , name : '_' } ;
153
150
let index ;
154
151
let key ;
155
152
153
+ const has_as = parser . match ( 'as' ) ;
154
+
155
+ if ( has_as ) {
156
+ parser . eat ( 'as' , true ) ;
157
+ parser . require_whitespace ( ) ;
158
+
159
+ context = read_pattern ( parser ) ;
160
+ } else {
161
+ // {#each Array.from({ length: 10 }), i } is read as a sequence expression,
162
+ // which is set back above - we now gotta reset the index as a consequence
163
+ // to properly read the , i part
164
+ parser . index = /** @type {number } */ ( expression . end ) ;
165
+ }
166
+
167
+ parser . allow_whitespace ( ) ;
168
+
156
169
if ( parser . eat ( ',' ) ) {
157
170
parser . allow_whitespace ( ) ;
158
171
index = parser . read_identifier ( ) ;
@@ -164,6 +177,10 @@ function open(parser) {
164
177
}
165
178
166
179
if ( parser . eat ( '(' ) ) {
180
+ if ( ! has_as ) {
181
+ e . expected_token ( parser . index , '}' ) ;
182
+ }
183
+
167
184
parser . allow_whitespace ( ) ;
168
185
169
186
key = read_expression ( parser ) ;
0 commit comments