@@ -2,56 +2,8 @@ import Expression from './shared/Expression';
22import map_children from './shared/map_children' ;
33import TemplateScope from './shared/TemplateScope' ;
44import AbstractBlock from './shared/AbstractBlock' ;
5- import { x } from 'code-red' ;
6- import { Node , Identifier , RestElement } from 'estree' ;
7-
8- interface Context {
9- key : Identifier ;
10- name ?: string ;
11- modifier : ( node : Node ) => Node ;
12- }
13-
14- function unpack_destructuring ( contexts : Context [ ] , node : Node , modifier : ( node : Node ) => Node ) {
15- if ( ! node ) return ;
16-
17- if ( node . type === 'Identifier' || ( node as any ) . type === 'RestIdentifier' ) { // TODO is this right? not RestElement?
18- contexts . push ( {
19- key : node as Identifier ,
20- modifier
21- } ) ;
22- } else if ( node . type === 'ArrayPattern' ) {
23- node . elements . forEach ( ( element , i ) => {
24- if ( element && ( element as any ) . type === 'RestIdentifier' ) {
25- unpack_destructuring ( contexts , element , node => x `${ modifier ( node ) } .slice(${ i } )` as Node ) ;
26- } else {
27- unpack_destructuring ( contexts , element , node => x `${ modifier ( node ) } [${ i } ]` as Node ) ;
28- }
29- } ) ;
30- } else if ( node . type === 'ObjectPattern' ) {
31- const used_properties = [ ] ;
32-
33- node . properties . forEach ( ( property , i ) => {
34- if ( ( property as any ) . kind === 'rest' ) { // TODO is this right?
35- const replacement : RestElement = {
36- type : 'RestElement' ,
37- argument : property . key as Identifier
38- } ;
39-
40- node . properties [ i ] = replacement as any ;
41-
42- unpack_destructuring (
43- contexts ,
44- property . value ,
45- node => x `@object_without_properties(${ modifier ( node ) } , [${ used_properties } ])` as Node
46- ) ;
47- } else {
48- used_properties . push ( x `"${ ( property . key as Identifier ) . name } "` ) ;
49-
50- unpack_destructuring ( contexts , property . value , node => x `${ modifier ( node ) } .${ ( property . key as Identifier ) . name } ` as Node ) ;
51- }
52- } ) ;
53- }
54- }
5+ import { Context , unpack_destructuring } from './shared/Context' ;
6+ import { Node } from 'estree' ;
557
568export default class WithBlock extends AbstractBlock {
579 type : 'WithBlock' ;
0 commit comments