1- /** @import { ArrowFunctionExpression, Expression, Identifier } from 'estree' */
1+ /** @import { ArrowFunctionExpression, Expression, Identifier, Pattern } from 'estree' */
22/** @import { AST } from '#compiler' */
33/** @import { Parser } from '../index.js' */
44import read_pattern from '../read/context.js' ;
@@ -143,16 +143,29 @@ function open(parser) {
143143 parser . index = end ;
144144 }
145145 }
146- parser . eat ( 'as' , true ) ;
147- parser . require_whitespace ( ) ;
148-
149- const context = read_pattern ( parser ) ;
150-
151- parser . allow_whitespace ( ) ;
152146
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 : '_' } ;
153150 let index ;
154151 let key ;
155152
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+
156169 if ( parser . eat ( ',' ) ) {
157170 parser . allow_whitespace ( ) ;
158171 index = parser . read_identifier ( ) ;
@@ -164,6 +177,10 @@ function open(parser) {
164177 }
165178
166179 if ( parser . eat ( '(' ) ) {
180+ if ( ! has_as ) {
181+ e . expected_token ( parser . index , '}' ) ;
182+ }
183+
167184 parser . allow_whitespace ( ) ;
168185
169186 key = read_expression ( parser ) ;
0 commit comments