@@ -45,6 +45,44 @@ function SystemLoader(options) {
45
45
this . paths = { } ;
46
46
}
47
47
48
+ // NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
49
+ function applyPaths ( loader , name ) {
50
+ // most specific (most number of slashes in path) match wins
51
+ var pathMatch = '' , wildcard , maxSlashCount = 0 ;
52
+
53
+ // check to see if we have a paths entry
54
+ for ( var p in loader . paths ) {
55
+ var pathParts = p . split ( '*' ) ;
56
+ if ( pathParts . length > 2 )
57
+ throw new TypeError ( 'Only one wildcard in a path is permitted' ) ;
58
+
59
+ // exact path match
60
+ if ( pathParts . length == 1 ) {
61
+ if ( name == p ) {
62
+ pathMatch = p ;
63
+ break ;
64
+ }
65
+ }
66
+ // wildcard path match
67
+ else {
68
+ var slashCount = p . split ( '/' ) . length ;
69
+ if ( slashCount >= maxSlashCount &&
70
+ name . substr ( 0 , pathParts [ 0 ] . length ) == pathParts [ 0 ] &&
71
+ name . substr ( name . length - pathParts [ 1 ] . length ) == pathParts [ 1 ] ) {
72
+ maxSlashCount = slashCount ;
73
+ pathMatch = p ;
74
+ wildcard = name . substr ( pathParts [ 0 ] . length , name . length - pathParts [ 1 ] . length - pathParts [ 0 ] . length ) ;
75
+ }
76
+ }
77
+ }
78
+
79
+ var outPath = loader . paths [ pathMatch ] || name ;
80
+ if ( wildcard )
81
+ outPath = outPath . replace ( '*' , wildcard ) ;
82
+
83
+ return outPath ;
84
+ }
85
+
48
86
( function ( ) {
49
87
var fetchTextFromURL ;
50
88
if ( typeof XMLHttpRequest != 'undefined' ) {
@@ -123,95 +161,6 @@ function SystemLoader(options) {
123
161
LoaderProto . prototype = Loader . prototype ;
124
162
SystemLoader . prototype = new LoaderProto ( ) ;
125
163
126
- SystemLoader . prototype . normalize = function ( name , parentName , parentAddress ) {
127
- if ( typeof name != 'string' )
128
- throw new TypeError ( 'Module name must be a string' ) ;
129
-
130
- var segments = name . split ( '/' ) ;
131
-
132
- // current segment
133
- var i = 0 ;
134
- // is the module name relative
135
- var rel = false ;
136
- // number of backtracking segments
137
- var dotdots = 0 ;
138
- if ( segments [ 0 ] == '.' ) {
139
- i ++ ;
140
- rel = true ;
141
- }
142
- else {
143
- while ( segments [ i ] == '..' ) {
144
- i ++ ;
145
- }
146
- if ( i )
147
- rel = true ;
148
- dotdots = i ;
149
- }
150
-
151
- if ( ! rel )
152
- return name ;
153
-
154
- // build the full module name
155
- var normalizedParts = [ ] ;
156
- var parentParts = ( parentName || '' ) . split ( '/' ) ;
157
- var normalizedLen = parentParts . length - 1 - dotdots ;
158
-
159
- normalizedParts = normalizedParts . concat ( parentParts . splice ( 0 , parentParts . length - 1 - dotdots ) ) ;
160
- normalizedParts = normalizedParts . concat ( segments . splice ( i , segments . length - i ) ) ;
161
-
162
- return normalizedParts . join ( '/' ) ;
163
- } ;
164
-
165
- var baseURLCache = { } ;
166
-
167
- SystemLoader . prototype . locate = function ( load ) {
168
- var name = load . name ;
169
-
170
- // NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
171
-
172
- // most specific (most number of slashes in path) match wins
173
- var pathMatch = '' , wildcard , maxSlashCount = 0 ;
174
-
175
- // check to see if we have a paths entry
176
- for ( var p in this . paths ) {
177
- var pathParts = p . split ( '*' ) ;
178
- if ( pathParts . length > 2 )
179
- throw new TypeError ( 'Only one wildcard in a path is permitted' ) ;
180
-
181
- // exact path match
182
- if ( pathParts . length == 1 ) {
183
- if ( name == p ) {
184
- pathMatch = p ;
185
- break ;
186
- }
187
- }
188
- // wildcard path match
189
- else {
190
- var slashCount = p . split ( '/' ) . length ;
191
- if ( slashCount >= maxSlashCount &&
192
- name . substr ( 0 , pathParts [ 0 ] . length ) == pathParts [ 0 ] &&
193
- name . substr ( name . length - pathParts [ 1 ] . length ) == pathParts [ 1 ] ) {
194
- maxSlashCount = slashCount ;
195
- pathMatch = p ;
196
- wildcard = name . substr ( pathParts [ 0 ] . length , name . length - pathParts [ 1 ] . length - pathParts [ 0 ] . length ) ;
197
- }
198
- }
199
- }
200
-
201
- var outPath = this . paths [ pathMatch ] || name ;
202
- if ( wildcard )
203
- outPath = outPath . replace ( '*' , wildcard ) ;
204
-
205
- // percent encode just '#' in module names
206
- // according to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js#L238
207
- // we should encode everything, but it breaks for servers that don't expect it
208
- // like in (https://github.com/systemjs/systemjs/issues/168)
209
- if ( isBrowser )
210
- outPath = outPath . replace ( / # / g, '%23' ) ;
211
-
212
- return new URL ( outPath , baseURLCache [ this . baseURL ] = baseURLCache [ this . baseURL ] || new URL ( this . baseURL ) ) . href ;
213
- } ;
214
-
215
164
SystemLoader . prototype . fetch = function ( load ) {
216
165
return new Promise ( function ( resolve , reject ) {
217
166
fetchTextFromURL ( load . address , resolve , reject ) ;
0 commit comments