Skip to content

Commit 00ce04b

Browse files
authored
Merge pull request #382 from nuysoft/hotfix-relative
fix #381
2 parents c4d7cba + 160173f commit 00ce04b

File tree

7 files changed

+134
-118
lines changed

7 files changed

+134
-118
lines changed

dist/mock-min.js

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mock-min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mock.js

+84-80
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ return /******/ (function(modules) { // webpackBootstrap
5252
/************************************************************************/
5353
/******/ ([
5454
/* 0 */
55-
/***/ function(module, exports, __webpack_require__) {
55+
/***/ (function(module, exports, __webpack_require__) {
5656

5757
/* global require, module, window */
5858
var Handler = __webpack_require__(1)
@@ -122,9 +122,9 @@ return /******/ (function(modules) { // webpackBootstrap
122122

123123
module.exports = Mock
124124

125-
/***/ },
125+
/***/ }),
126126
/* 1 */
127-
/***/ function(module, exports, __webpack_require__) {
127+
/***/ (function(module, exports, __webpack_require__) {
128128

129129
/*
130130
## Handler
@@ -617,29 +617,33 @@ return /******/ (function(modules) { // webpackBootstrap
617617
}
618618
}
619619

620-
key = keyPathParts[keyPathParts.length - 1]
621-
var currentContext = options.context.root
622-
var templateCurrentContext = options.context.templateRoot
623-
for (var i = 1; i < absolutePathParts.length - 1; i++) {
624-
currentContext = currentContext[absolutePathParts[i]]
625-
templateCurrentContext = templateCurrentContext[absolutePathParts[i]]
626-
}
627-
// 引用的值已经计算好
628-
if (currentContext && (key in currentContext)) return currentContext[key]
620+
try {
621+
key = keyPathParts[keyPathParts.length - 1]
622+
var currentContext = options.context.root
623+
var templateCurrentContext = options.context.templateRoot
624+
for (var i = 1; i < absolutePathParts.length - 1; i++) {
625+
currentContext = currentContext[absolutePathParts[i]]
626+
templateCurrentContext = templateCurrentContext[absolutePathParts[i]]
627+
}
628+
// 引用的值已经计算好
629+
if (currentContext && (key in currentContext)) return currentContext[key]
630+
631+
// 尚未计算,递归引用数据模板中的属性
632+
if (templateCurrentContext &&
633+
(typeof templateCurrentContext === 'object') &&
634+
(key in templateCurrentContext) &&
635+
(originalKey !== templateCurrentContext[key]) // fix #15 避免自己依赖自己
636+
) {
637+
// 先计算被引用的属性值
638+
templateCurrentContext[key] = Handler.gen(templateCurrentContext[key], key, {
639+
currentContext: currentContext,
640+
templateCurrentContext: templateCurrentContext
641+
})
642+
return templateCurrentContext[key]
643+
}
644+
} catch(err) { }
629645

630-
// 尚未计算,递归引用数据模板中的属性
631-
if (templateCurrentContext &&
632-
(typeof templateCurrentContext === 'object') &&
633-
(key in templateCurrentContext) &&
634-
(originalKey !== templateCurrentContext[key]) // fix #15 避免自己依赖自己
635-
) {
636-
// 先计算被引用的属性值
637-
templateCurrentContext[key] = Handler.gen(templateCurrentContext[key], key, {
638-
currentContext: currentContext,
639-
templateCurrentContext: templateCurrentContext
640-
})
641-
return templateCurrentContext[key]
642-
}
646+
return '@' + keyPathParts.join('/')
643647
},
644648
// https://github.com/kissyteam/kissy/blob/master/src/path/src/path.js
645649
normalizePath: function(pathParts) {
@@ -667,9 +671,9 @@ return /******/ (function(modules) { // webpackBootstrap
667671

668672
module.exports = Handler
669673

670-
/***/ },
674+
/***/ }),
671675
/* 2 */
672-
/***/ function(module, exports) {
676+
/***/ (function(module, exports) {
673677

674678
/*
675679
## Constant
@@ -705,9 +709,9 @@ return /******/ (function(modules) { // webpackBootstrap
705709
// RE_KEY: /^key$/
706710
}
707711

708-
/***/ },
712+
/***/ }),
709713
/* 3 */
710-
/***/ function(module, exports) {
714+
/***/ (function(module, exports) {
711715

712716
/*
713717
## Utilities
@@ -836,9 +840,9 @@ return /******/ (function(modules) { // webpackBootstrap
836840

837841
module.exports = Util
838842

839-
/***/ },
843+
/***/ }),
840844
/* 4 */
841-
/***/ function(module, exports, __webpack_require__) {
845+
/***/ (function(module, exports, __webpack_require__) {
842846

843847
/*
844848
## Parser
@@ -912,9 +916,9 @@ return /******/ (function(modules) { // webpackBootstrap
912916
}
913917
}
914918

915-
/***/ },
919+
/***/ }),
916920
/* 5 */
917-
/***/ function(module, exports, __webpack_require__) {
921+
/***/ (function(module, exports, __webpack_require__) {
918922

919923
/*
920924
## Mock.Random
@@ -941,9 +945,9 @@ return /******/ (function(modules) { // webpackBootstrap
941945

942946
module.exports = Random
943947

944-
/***/ },
948+
/***/ }),
945949
/* 6 */
946-
/***/ function(module, exports) {
950+
/***/ (function(module, exports) {
947951

948952
/*
949953
## Basics
@@ -1072,9 +1076,9 @@ return /******/ (function(modules) { // webpackBootstrap
10721076
}
10731077
}
10741078

1075-
/***/ },
1079+
/***/ }),
10761080
/* 7 */
1077-
/***/ function(module, exports) {
1081+
/***/ (function(module, exports) {
10781082

10791083
/*
10801084
## Date
@@ -1218,9 +1222,9 @@ return /******/ (function(modules) { // webpackBootstrap
12181222
}
12191223
}
12201224

1221-
/***/ },
1225+
/***/ }),
12221226
/* 8 */
1223-
/***/ function(module, exports, __webpack_require__) {
1227+
/***/ (function(module, exports, __webpack_require__) {
12241228

12251229
/* WEBPACK VAR INJECTION */(function(module) {/* global document */
12261230
/*
@@ -1506,9 +1510,9 @@ return /******/ (function(modules) { // webpackBootstrap
15061510
}
15071511
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9)(module)))
15081512

1509-
/***/ },
1513+
/***/ }),
15101514
/* 9 */
1511-
/***/ function(module, exports) {
1515+
/***/ (function(module, exports) {
15121516

15131517
module.exports = function(module) {
15141518
if(!module.webpackPolyfill) {
@@ -1522,9 +1526,9 @@ return /******/ (function(modules) { // webpackBootstrap
15221526
}
15231527

15241528

1525-
/***/ },
1529+
/***/ }),
15261530
/* 10 */
1527-
/***/ function(module, exports, __webpack_require__) {
1531+
/***/ (function(module, exports, __webpack_require__) {
15281532

15291533
/*
15301534
## Color
@@ -1664,9 +1668,9 @@ return /******/ (function(modules) { // webpackBootstrap
16641668
}
16651669
}
16661670

1667-
/***/ },
1671+
/***/ }),
16681672
/* 11 */
1669-
/***/ function(module, exports) {
1673+
/***/ (function(module, exports) {
16701674

16711675
/*
16721676
## Color Convert
@@ -1846,9 +1850,9 @@ return /******/ (function(modules) { // webpackBootstrap
18461850
}
18471851
}
18481852

1849-
/***/ },
1853+
/***/ }),
18501854
/* 12 */
1851-
/***/ function(module, exports) {
1855+
/***/ (function(module, exports) {
18521856

18531857
/*
18541858
## Color 字典数据
@@ -1927,9 +1931,9 @@ return /******/ (function(modules) { // webpackBootstrap
19271931
}
19281932
}
19291933

1930-
/***/ },
1934+
/***/ }),
19311935
/* 13 */
1932-
/***/ function(module, exports, __webpack_require__) {
1936+
/***/ (function(module, exports, __webpack_require__) {
19331937

19341938
/*
19351939
## Text
@@ -2053,9 +2057,9 @@ return /******/ (function(modules) { // webpackBootstrap
20532057
}
20542058
}
20552059

2056-
/***/ },
2060+
/***/ }),
20572061
/* 14 */
2058-
/***/ function(module, exports, __webpack_require__) {
2062+
/***/ (function(module, exports, __webpack_require__) {
20592063

20602064
/*
20612065
## Helpers
@@ -2174,9 +2178,9 @@ return /******/ (function(modules) { // webpackBootstrap
21742178
}
21752179
}
21762180

2177-
/***/ },
2181+
/***/ }),
21782182
/* 15 */
2179-
/***/ function(module, exports) {
2183+
/***/ (function(module, exports) {
21802184

21812185
/*
21822186
## Name
@@ -2266,9 +2270,9 @@ return /******/ (function(modules) { // webpackBootstrap
22662270
}
22672271
}
22682272

2269-
/***/ },
2273+
/***/ }),
22702274
/* 16 */
2271-
/***/ function(module, exports) {
2275+
/***/ (function(module, exports) {
22722276

22732277
/*
22742278
## Web
@@ -2347,9 +2351,9 @@ return /******/ (function(modules) { // webpackBootstrap
23472351
}
23482352
}
23492353

2350-
/***/ },
2354+
/***/ }),
23512355
/* 17 */
2352-
/***/ function(module, exports, __webpack_require__) {
2356+
/***/ (function(module, exports, __webpack_require__) {
23532357

23542358
/*
23552359
## Address
@@ -2399,9 +2403,9 @@ return /******/ (function(modules) { // webpackBootstrap
23992403
// state: function() {},
24002404
}
24012405

2402-
/***/ },
2406+
/***/ }),
24032407
/* 18 */
2404-
/***/ function(module, exports) {
2408+
/***/ (function(module, exports) {
24052409

24062410
/*
24072411
## Address 字典数据
@@ -6472,9 +6476,9 @@ return /******/ (function(modules) { // webpackBootstrap
64726476

64736477
module.exports = DICT_FIXED
64746478

6475-
/***/ },
6479+
/***/ }),
64766480
/* 19 */
6477-
/***/ function(module, exports, __webpack_require__) {
6481+
/***/ (function(module, exports, __webpack_require__) {
64786482

64796483
/*
64806484
## Miscellaneous
@@ -6582,9 +6586,9 @@ return /******/ (function(modules) { // webpackBootstrap
65826586
}
65836587
}
65846588

6585-
/***/ },
6589+
/***/ }),
65866590
/* 20 */
6587-
/***/ function(module, exports, __webpack_require__) {
6591+
/***/ (function(module, exports, __webpack_require__) {
65886592

65896593
var Parser = __webpack_require__(21)
65906594
var Handler = __webpack_require__(22)
@@ -6593,9 +6597,9 @@ return /******/ (function(modules) { // webpackBootstrap
65936597
Handler: Handler
65946598
}
65956599

6596-
/***/ },
6600+
/***/ }),
65976601
/* 21 */
6598-
/***/ function(module, exports) {
6602+
/***/ (function(module, exports) {
65996603

66006604
// https://github.com/nuysoft/regexp
66016605
// forked from https://github.com/ForbesLindesay/regexp
@@ -7168,9 +7172,9 @@ return /******/ (function(modules) { // webpackBootstrap
71687172

71697173
module.exports = parser
71707174

7171-
/***/ },
7175+
/***/ }),
71727176
/* 22 */
7173-
/***/ function(module, exports, __webpack_require__) {
7177+
/***/ (function(module, exports, __webpack_require__) {
71747178

71757179
/*
71767180
## RegExp Handler
@@ -7565,15 +7569,15 @@ return /******/ (function(modules) { // webpackBootstrap
75657569

75667570
module.exports = Handler
75677571

7568-
/***/ },
7572+
/***/ }),
75697573
/* 23 */
7570-
/***/ function(module, exports, __webpack_require__) {
7574+
/***/ (function(module, exports, __webpack_require__) {
75717575

75727576
module.exports = __webpack_require__(24)
75737577

7574-
/***/ },
7578+
/***/ }),
75757579
/* 24 */
7576-
/***/ function(module, exports, __webpack_require__) {
7580+
/***/ (function(module, exports, __webpack_require__) {
75777581

75787582
/*
75797583
## toJSONSchema
@@ -7624,15 +7628,15 @@ return /******/ (function(modules) { // webpackBootstrap
76247628
module.exports = toJSONSchema
76257629

76267630

7627-
/***/ },
7631+
/***/ }),
76287632
/* 25 */
7629-
/***/ function(module, exports, __webpack_require__) {
7633+
/***/ (function(module, exports, __webpack_require__) {
76307634

76317635
module.exports = __webpack_require__(26)
76327636

7633-
/***/ },
7637+
/***/ }),
76347638
/* 26 */
7635-
/***/ function(module, exports, __webpack_require__) {
7639+
/***/ (function(module, exports, __webpack_require__) {
76367640

76377641
/*
76387642
## valid(template, data)
@@ -8080,15 +8084,15 @@ return /******/ (function(modules) { // webpackBootstrap
80808084

80818085
module.exports = valid
80828086

8083-
/***/ },
8087+
/***/ }),
80848088
/* 27 */
8085-
/***/ function(module, exports, __webpack_require__) {
8089+
/***/ (function(module, exports, __webpack_require__) {
80868090

80878091
module.exports = __webpack_require__(28)
80888092

8089-
/***/ },
8093+
/***/ }),
80908094
/* 28 */
8091-
/***/ function(module, exports, __webpack_require__) {
8095+
/***/ (function(module, exports, __webpack_require__) {
80928096

80938097
/* global window, document, location, Event, setTimeout */
80948098
/*
@@ -8533,7 +8537,7 @@ return /******/ (function(modules) { // webpackBootstrap
85338537

85348538
module.exports = MockXMLHttpRequest
85358539

8536-
/***/ }
8540+
/***/ })
85378541
/******/ ])
85388542
});
85398543
;

0 commit comments

Comments
 (0)