@@ -92,22 +92,24 @@ function Angular2ConventionsLoader(source, sourcemap) {
92
92
93
93
94
94
source = source . replace ( componentRegex , function ( match , decorator , metadata , offset , src ) {
95
- if ( templateUrlRegex . test ( metadata ) ) {
95
+ if ( decorator === 'Component' && templateUrlRegex . test ( metadata ) ) {
96
96
metadata = metadata
97
97
. replace ( templateUrlRegex , function ( match , url ) {
98
98
// replace: templateUrl: './path/to/template.html'
99
99
// with: template: require('./path/to/template.html')
100
100
return 'template:' + replaceStringsWithRequires ( url ) ;
101
101
} )
102
102
}
103
- if ( templateUrlRegex . test ( metadata ) ) {
103
+ if ( decorator === 'Component' && templateUrlRegex . test ( metadata ) ) {
104
104
metadata = metadata
105
105
. replace ( styleUrlsRegex , function ( match , urls ) {
106
106
// replace: stylesUrl: ['./foo.css', "./baz.css", "./index.component.css"]
107
107
// with: styles: [require('./foo.css'), require("./baz.css"), require("./index.component.css")]
108
108
return 'styles:' + replaceStringsWithRequires ( urls ) ;
109
109
} ) ;
110
110
}
111
+
112
+ // get relative file name
111
113
var fileContext = self . request . split ( self . context )
112
114
var lastFileName = fileContext [ fileContext . length - 1 ] ;
113
115
lastFileName = lastFileName . replace ( / \. [ ^ / . ] + $ / g, "" ) ;
@@ -117,7 +119,7 @@ function Angular2ConventionsLoader(source, sourcemap) {
117
119
118
120
var __selector ;
119
121
if ( ! ( / s e l e c t o r \s * : \s * ( ' | " ) ( .* ) ( ' | " ) , ? / . test ( metadata ) ) ) {
120
-
122
+ // grab classname and set selector
121
123
// TODO(gdi2290): become a regexp master to fix this
122
124
var __args = / @ ( C o m p o n e n t | D i r e c t i v e ) \( { ( [ \s \S ] * ?) } \) \s * e x p o r t \s * c l a s s \s * ( [ \s \S ] + ) \s * ( e x t e n d s | i m p l e m e n t s | { ) $ / m. exec ( src . slice ( offset ) ) ;
123
125
if ( __args && __args [ 3 ] ) {
@@ -128,13 +130,15 @@ function Angular2ConventionsLoader(source, sourcemap) {
128
130
__args = null ;
129
131
}
130
132
} else if ( / s e l e c t o r \s * : \s * ( ' | " ) ( .* ) ( ' | " ) / ) {
133
+ // grab selector from metadata
131
134
var getSelector = / s e l e c t o r \s * : \s * ( ' | " ) ( .* ) ( ' | " ) / . exec ( metadata )
132
135
__selector = getSelector [ 2 ] ;
133
136
}
134
137
var hasSameFileSelector = __selector && lastFileName . toLowerCase ( ) . indexOf ( __selector . toLowerCase ( ) ) !== - 1 ;
135
138
136
- if ( ! ( / t e m p l a t e \s * : ( .* ) / g. test ( metadata ) ) ) {
139
+ if ( decorator === 'Component' && ! ( / t e m p l a t e \s * : ( .* ) / g. test ( metadata ) ) ) {
137
140
var _hasHtmlFile ;
141
+ // if selector and filename are the same
138
142
if ( hasSameFileSelector ) {
139
143
try {
140
144
_hasHtmlFile = fs . statSync ( path . join ( self . context , lastFileName + htmlExtension ) ) ;
@@ -146,11 +150,13 @@ function Angular2ConventionsLoader(source, sourcemap) {
146
150
metadata = 'template: "",' + metadata ;
147
151
}
148
152
}
153
+ // set file in metadata
149
154
if ( _hasHtmlFile ) {
150
155
metadata = 'template: require("' + relativePathStart + lastFileName + htmlExtension + '"),\n' + metadata ;
151
156
}
152
157
}
153
- if ( ! ( / s t y l e s \s * : ( \s * \[ [ \s \S ] * ?\] ) / g. test ( metadata ) ) ) {
158
+ // do the same for styles
159
+ if ( decorator === 'Component' && ! ( / s t y l e s \s * : ( \s * \[ [ \s \S ] * ?\] ) / g. test ( metadata ) ) ) {
154
160
var _hasCssFile ;
155
161
if ( hasSameFileSelector ) {
156
162
try {
@@ -169,6 +175,7 @@ function Angular2ConventionsLoader(source, sourcemap) {
169
175
// strip moduleId
170
176
metadata = metadata . replace ( / m o d u l e I d : m o d u l e .i d , / , '' ) ;
171
177
178
+ // return updated metadata
172
179
return '@' + decorator + '({' + metadata + '})' ;
173
180
} ) ;
174
181
0 commit comments