1
1
import * as fs from 'fs' ;
2
2
import { ArrayUtils , Config , FileSystemUtils } from "@src" ;
3
- import { Component , Directive , Injectable , Pipe , Project } from '@model' ;
3
+ import { Component , Directive , Injectable , NamedEntity , Pipe , Project } from '@model' ;
4
4
5
5
export class NgModule {
6
6
public imports : string [ ] = [ ] ;
@@ -40,13 +40,13 @@ export class ModuleManager {
40
40
project . components . set ( file . name , file ) ;
41
41
}
42
42
else if ( file instanceof Pipe ) {
43
- project . pipes . set ( file . name , file . name ) ;
43
+ project . pipes . set ( file . name , new NamedEntity ( file . name , filename ) ) ;
44
44
}
45
45
else if ( file instanceof Directive ) {
46
- project . directives . set ( file . name , file . name ) ;
46
+ project . directives . set ( file . name , new NamedEntity ( file . name , filename ) ) ;
47
47
}
48
48
else if ( file instanceof Injectable ) {
49
- project . directives . set ( file . name , file . name ) ;
49
+ project . directives . set ( file . name , new NamedEntity ( file . name , filename ) ) ;
50
50
}
51
51
} ) ;
52
52
return project ;
@@ -73,25 +73,25 @@ export class ModuleManager {
73
73
var match = regex . exec ( fileContents . toString ( ) ) ;
74
74
if ( match !== null ) {
75
75
const className = match [ 2 ] ;
76
- const component = new Component ( className ) ;
76
+ const component = new Component ( className , filename ) ;
77
77
const classBody = match [ 3 ] ;
78
78
this . enrichComponent ( component , classBody ) ;
79
79
return component ;
80
80
}
81
81
regex = / @ D i r e c t i v e \s * \( \s * ( \{ .+ ?\} ) \s * \) \s * e x p o r t \s + c l a s s \s + ( \w + ) \s + / ims;
82
82
var match = regex . exec ( fileContents . toString ( ) ) ;
83
83
if ( match !== null ) {
84
- return new Directive ( match [ 2 ] ) ;
84
+ return new Directive ( match [ 2 ] , filename ) ;
85
85
}
86
86
regex = / @ P i p e \s * \( \s * ( \{ .+ ?\} ) \s * \) \s * e x p o r t \s + c l a s s \s + ( \w + ) \s + / ims;
87
87
var match = regex . exec ( fileContents . toString ( ) ) ;
88
88
if ( match !== null ) {
89
- return new Pipe ( match [ 2 ] ) ;
89
+ return new Pipe ( match [ 2 ] , filename ) ;
90
90
}
91
91
regex = / @ I n j e c t a b l e \s * \( \s * ( \{ .+ ?\} ) \s * \) \s * e x p o r t \s + c l a s s \s + ( \w + ) \s + / ims;
92
92
var match = regex . exec ( fileContents . toString ( ) ) ;
93
93
if ( match !== null ) {
94
- return new Injectable ( match [ 2 ] ) ;
94
+ return new Injectable ( match [ 2 ] , filename ) ;
95
95
}
96
96
}
97
97
@@ -102,35 +102,35 @@ export class ModuleManager {
102
102
const constructorParameters = match [ 1 ] ;
103
103
regex = / \s * \w + \s + \w + \s * : \s * ( \w + ) [ , ] * / gims;
104
104
while ( match = regex . exec ( constructorParameters ) ) {
105
- component . dependencyInjections . push ( match [ 1 ] ) ;
105
+ component . dependencyInjections . push ( new NamedEntity ( match [ 1 ] , component . filename ) ) ;
106
106
}
107
107
}
108
- this . matchMultipleSpecificDecorator ( classBody , '@Input' , component . inputs ) ;
109
- this . matchMultipleSpecificDecorator ( classBody , '@output' , component . outputs ) ;
110
- this . matchSpecificDecorator ( classBody , '@ViewChild' , component . viewchilds ) ;
111
- this . matchSpecificDecorator ( classBody , '@ViewChildren' , component . viewchildren ) ;
112
- this . matchSpecificDecorator ( classBody , '@ContentChild' , component . contentchilds ) ;
113
- this . matchSpecificDecorator ( classBody , '@ContentChildren' , component . contentchildren ) ;
108
+ this . matchMultipleSpecificDecorator ( classBody , '@Input' , component . filename , component . inputs ) ;
109
+ this . matchMultipleSpecificDecorator ( classBody , '@output' , component . filename , component . outputs ) ;
110
+ this . matchSpecificDecorator ( classBody , '@ViewChild' , component . filename , component . viewchilds ) ;
111
+ this . matchSpecificDecorator ( classBody , '@ViewChildren' , component . filename , component . viewchildren ) ;
112
+ this . matchSpecificDecorator ( classBody , '@ContentChild' , component . filename , component . contentchilds ) ;
113
+ this . matchSpecificDecorator ( classBody , '@ContentChildren' , component . filename , component . contentchildren ) ;
114
114
}
115
115
116
- private static matchMultipleSpecificDecorator ( classBody : string , decorator : string , decoratorArray : string [ ] ) {
116
+ private static matchMultipleSpecificDecorator ( classBody : string , decorator : string , filename : string , decoratorArray : NamedEntity [ ] ) {
117
117
const regex = new RegExp ( decorator + '\\(\\)\\s+(?:public)?(?:protected)?(?:private)?\\s*(?:[gs]et)?\\s*(\\w+)\\s*[:=(]|' + decorator + '\\(["\'](.*?)["\']\\)' , 'gms' ) ;
118
118
let match : RegExpExecArray | null = null ;
119
119
while ( match = regex . exec ( classBody ) ) {
120
120
if ( match [ 1 ] ) {
121
- decoratorArray . push ( match [ 1 ] ) ;
121
+ decoratorArray . push ( new NamedEntity ( match [ 1 ] , filename ) ) ;
122
122
} else if ( match [ 2 ] ) {
123
- decoratorArray . push ( match [ 2 ] ) ;
123
+ decoratorArray . push ( new NamedEntity ( match [ 2 ] , filename ) ) ;
124
124
}
125
125
}
126
126
}
127
127
128
- private static matchSpecificDecorator ( classBody : string , decorator : string , decoratorArray : string [ ] ) {
128
+ private static matchSpecificDecorator ( classBody : string , decorator : string , filename : string , decoratorArray : NamedEntity [ ] ) {
129
129
const regex = new RegExp ( decorator + '\\s*\\(\\s*[\'"]?(\\w+)[\'"]?.*?\\)' , 'gms' ) ;
130
130
let match : RegExpExecArray | null = null ;
131
131
while ( match = regex . exec ( classBody ) ) {
132
132
if ( match [ 1 ] ) {
133
- decoratorArray . push ( match [ 1 ] ) ;
133
+ decoratorArray . push ( new NamedEntity ( match [ 1 ] , filename ) ) ;
134
134
}
135
135
}
136
136
}
0 commit comments