@@ -41,6 +41,25 @@ function getDocumentUris(documents) {
41
41
return documents . reduce ( addDocumentUri , [ ] ) ;
42
42
}
43
43
44
+ /** @ignore */
45
+ function compareDocuments ( firstDoc , secondDoc ) {
46
+ const hasFirstDoc = ( firstDoc !== null ) ;
47
+ const hasSecondDoc = ( secondDoc !== null ) ;
48
+ if ( ! hasFirstDoc && ! hasSecondDoc ) return 0 ;
49
+ if ( ! hasFirstDoc && hasSecondDoc ) return - 1 ;
50
+ if ( hasFirstDoc && ! hasSecondDoc ) return 1 ;
51
+ const firstUri = firstDoc . uri ;
52
+ const secondUri = secondDoc . uri ;
53
+ const hasFirstUri = ( ( typeof firstUri === 'string' || firstUri instanceof String ) && firstUri . length > 0 ) ;
54
+ const hasSecondUri = ( ( typeof secondUri === 'string' || secondUri instanceof String ) && secondUri . length > 0 ) ;
55
+ if ( ! hasFirstUri && ! hasSecondUri ) return 0 ;
56
+ if ( ! hasFirstUri && hasSecondUri ) return - 1 ;
57
+ if ( hasFirstUri && ! hasSecondUri ) return 1 ;
58
+ if ( firstUri < secondUri ) return - 1 ;
59
+ if ( firstUri > secondUri ) return 1 ;
60
+ return 0 ;
61
+ }
62
+
44
63
/** @ignore */
45
64
function uriErrorTransform ( message ) {
46
65
/*jshint validthis:true */
@@ -1206,6 +1225,10 @@ function writeContent(contentOnly, document, requestParams, categories, requestT
1206
1225
/** @ignore */
1207
1226
function writeDocumentList ( contentOnly , documents , requestParams , categories ) {
1208
1227
/*jshint validthis:true */
1228
+ if ( documents . length > 1 ) {
1229
+ documents = documents . sort ( compareDocuments ) ;
1230
+ }
1231
+
1209
1232
var requestPartList = [ ] ;
1210
1233
for ( var i = 0 ; i < documents . length ; i ++ ) {
1211
1234
addDocumentParts ( requestPartList , documents [ i ] , false ) ;
0 commit comments