@@ -4,59 +4,3 @@ export * from './ast/ast-element-node';
4
4
export * from './ast/ast-location' ;
5
5
export * from './ast/ast-node' ;
6
6
export * from './ast/ast-text-node' ;
7
-
8
- import { ASTElementAttribute } from './ast/ast-element-attribute' ;
9
- import { ASTElementNode } from './ast/ast-element-node' ;
10
- import { ASTTextNode } from './ast/ast-text-node' ;
11
- import { ASTLocation } from './ast/ast-location' ;
12
- import { ASTNode } from './ast/ast-node' ;
13
- import { ParserTask } from './parser-task' ;
14
- import { Parser } from './parser' ;
15
-
16
- export class ASTGen extends ParserTask {
17
- public root : ASTNode = null ;
18
-
19
- constructor ( ) { super ( ) ; }
20
-
21
- init ( parser : Parser , path ?: string ) {
22
-
23
- var current = this . root = new ASTNode ( ) ;
24
-
25
- parser . on ( "startTag" , ( tag , attrs , selfClosing , loc ) => {
26
- let next = new ASTElementNode ( ) ;
27
- next . tag = tag ;
28
- next . parent = current ;
29
- next . location = < ASTLocation > { start : loc . startOffset , end : loc . endOffset , line : loc . line , column : loc . col , path : path } ;
30
- next . attrs = attrs . map ( ( x , i ) => {
31
- var attr = new ASTElementAttribute ( ) ;
32
-
33
- attr . name = ( x . prefix !== undefined && x . prefix != "" ) ? `${ x . prefix } :${ x . name } ` : x . name ;
34
-
35
- var attrLoc = loc . attrs [ attr . name ] || loc . attrs [ attr . name . toLowerCase ( ) ] ;
36
-
37
- if ( attrLoc == undefined )
38
- attrLoc = { startOffset : - 1 , endOffset : - 1 , line : - 1 , col : - 1 } ;
39
-
40
- attr . location = < ASTLocation > { start : attrLoc . startOffset , end : attrLoc . endOffset , line : attrLoc . line , column : attrLoc . col , path : path } ;
41
-
42
- return attr ;
43
- } ) ;
44
-
45
- current . children . push ( next ) ;
46
-
47
- if ( ! parser . isVoid ( tag ) )
48
- current = next ;
49
- } ) ;
50
-
51
- parser . on ( "endTag" , ( tag , attrs , selfClosing , loc ) => {
52
- current = current . parent ;
53
- } ) ;
54
-
55
- parser . on ( "text" , ( text , loc ) => {
56
- let child = new ASTTextNode ( ) ;
57
- child . parent = current ;
58
- child . location = < ASTLocation > { start : loc . startOffset , end : loc . endOffset , line : loc . line , column : loc . col , path : path } ;
59
- current . children . push ( child ) ;
60
- } ) ;
61
- }
62
- }
0 commit comments