@@ -18,13 +18,16 @@ export function parseCell(input, {tag, raw, globals, ...options} = {}) {
18
18
// is consistent for all empty input cases.
19
19
if ( tag != null && input ) {
20
20
cell = TemplateCellParser . parse ( input , options ) ;
21
- cell . tag = tag ;
21
+ const parsedTag = CellTagParser . parse ( tag , options ) ;
22
+ parseReferences ( parsedTag , tag , globals ) ;
23
+ parseFeatures ( parsedTag , tag ) ;
24
+ cell . tag = parsedTag ;
22
25
cell . raw = ! ! raw ;
23
26
} else {
24
27
cell = CellParser . parse ( input , options ) ;
25
28
}
26
29
parseReferences ( cell , input , globals ) ;
27
- parseFeatures ( cell ) ;
30
+ parseFeatures ( cell , input ) ;
28
31
return cell ;
29
32
}
30
33
@@ -386,6 +389,45 @@ export class ModuleParser extends CellParser {
386
389
}
387
390
}
388
391
392
+ export class CellTagParser extends Parser {
393
+ constructor ( options , ...args ) {
394
+ super ( Object . assign ( { ecmaVersion : 12 } , options ) , ...args ) ;
395
+ }
396
+ enterScope ( flags ) {
397
+ if ( flags & SCOPE_FUNCTION ) ++ this . O_function ;
398
+ return super . enterScope ( flags ) ;
399
+ }
400
+ exitScope ( ) {
401
+ if ( this . currentScope ( ) . flags & SCOPE_FUNCTION ) -- this . O_function ;
402
+ return super . exitScope ( ) ;
403
+ }
404
+ parseForIn ( node , init ) {
405
+ if ( this . O_function === 1 && node . await ) this . O_async = true ;
406
+ return super . parseForIn ( node , init ) ;
407
+ }
408
+ parseAwait ( ) {
409
+ if ( this . O_function === 1 ) this . O_async = true ;
410
+ return super . parseAwait ( ) ;
411
+ }
412
+ parseYield ( noIn ) {
413
+ if ( this . O_function === 1 ) this . O_generator = true ;
414
+ return super . parseYield ( noIn ) ;
415
+ }
416
+ parseTopLevel ( node ) {
417
+ this . O_function = 0 ;
418
+ this . O_async = false ;
419
+ this . O_generator = false ;
420
+ this . strict = true ;
421
+ this . enterScope ( SCOPE_FUNCTION | SCOPE_ASYNC | SCOPE_GENERATOR ) ;
422
+ node . body = this . parseExpression ( ) ;
423
+ node . input = this . input ;
424
+ node . async = this . O_async ;
425
+ node . generator = this . O_generator ;
426
+ this . exitScope ( ) ;
427
+ return this . finishNode ( node , "CellTag" ) ;
428
+ }
429
+ }
430
+
389
431
// Find references.
390
432
// Check for illegal references to arguments.
391
433
// Check for illegal assignments to global references.
0 commit comments