Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit fa27d92

Browse files
author
Steffan
committed
v1.0.7
1 parent c0f986d commit fa27d92

File tree

6 files changed

+95
-68
lines changed

6 files changed

+95
-68
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ $ npm install vue-fields
1616
```
1717

1818
### CDN
19-
Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-fields@1.0.6) or [unpkg](https://unpkg.com/vue-fields@1.0.6).
19+
Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-fields@1.0.7) or [unpkg](https://unpkg.com/vue-fields@1.0.7).
2020
```html
21-
<script src="https://cdn.jsdelivr.net/npm/vue-fields@1.0.6"></script>
21+
<script src="https://cdn.jsdelivr.net/npm/vue-fields@1.0.7"></script>
2222
```
2323

2424
## Changelog

dist/vue-fields.common.js

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-fields v1.0.6
2+
* vue-fields v1.0.7
33
* https://github.com/pagekit/vue-fields
44
* Released under the MIT License.
55
*/
@@ -83,15 +83,25 @@ function set(obj, key, val) {
8383
_set(obj, parts.shift(), val);
8484
}
8585

86-
function evaluate(self, expr, context) {
86+
var parsedFunc = {};
87+
var expressionRe = /((?:\d|true|false|null|undefined|(?:this\.|\$)[\S]+|\W)*)([\w][\w+.]*)?/g;
88+
var quotedStringRe = /([^"']+)((.)(?:[^\3\\]|\\.)*?\3|.)?/g;
8789

88-
try {
89-
return (Function('c', ("with(c){return " + expr + "}"))).call(self, context);
90-
} catch (e) {
91-
warn(e);
92-
}
90+
function parse(expr) {
91+
return parsedFunc[expr] = parsedFunc[expr] ||
92+
Function('$values', '$context', ("with($context){return " + (expr.replace(quotedStringRe,
93+
function (match, unquoted, quoted) {
94+
if ( quoted === void 0 ) quoted = '';
95+
96+
return unquoted.replace(expressionRe,
97+
function (match, prefix, expression) {
98+
if ( prefix === void 0 ) prefix = '';
9399

94-
return false;
100+
return match ? ("" + prefix + (expression ? ("$get('" + expression + "')") : '')) : '';
101+
}
102+
) + quoted;
103+
}
104+
)) + "}"));
95105
}
96106

97107
function each(obj, iterator) {
@@ -319,26 +329,25 @@ var Fields = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_
319329
}
320330
},
321331

322-
evaluate: function evaluate$1(expr, values, config) {
332+
evaluate: function evaluate(expression, values) {
323333
if ( values === void 0 ) values = this.values;
324-
if ( config === void 0 ) config = this.config;
325-
326334

327-
if (isString(expr)) {
328335

329-
var context = {$match: $match, $values: values};
336+
try {
330337

331-
each(config, function (ref, key) {
332-
var name = ref.name; if ( name === void 0 ) name = key;
333-
334-
return set(context, name, get(values, name));
338+
if (isString(expression)) {
339+
expression = parse(expression);
335340
}
336-
);
337341

338-
return evaluate(this, expr, assign(context, values));
342+
return expression.call(this, values, {
343+
$match: $match, $get: function (key) { return get(values, key); }
344+
});
345+
346+
} catch (e) {
347+
warn(e);
339348
}
340349

341-
return expr.call(this, values, this);
350+
return true;
342351
},
343352

344353
prepare: function prepare(config, prefix) {
@@ -409,7 +418,7 @@ var Plugin = {
409418
Vue.component('fields', Fields);
410419
},
411420

412-
version: '1.0.6'
421+
version: '1.0.7'
413422
};
414423

415424
if (typeof window !== 'undefined' && window.Vue) {

dist/vue-fields.esm.js

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-fields v1.0.6
2+
* vue-fields v1.0.7
33
* https://github.com/pagekit/vue-fields
44
* Released under the MIT License.
55
*/
@@ -81,15 +81,25 @@ function set(obj, key, val) {
8181
_set(obj, parts.shift(), val);
8282
}
8383

84-
function evaluate(self, expr, context) {
84+
var parsedFunc = {};
85+
var expressionRe = /((?:\d|true|false|null|undefined|(?:this\.|\$)[\S]+|\W)*)([\w][\w+.]*)?/g;
86+
var quotedStringRe = /([^"']+)((.)(?:[^\3\\]|\\.)*?\3|.)?/g;
8587

86-
try {
87-
return (Function('c', ("with(c){return " + expr + "}"))).call(self, context);
88-
} catch (e) {
89-
warn(e);
90-
}
88+
function parse(expr) {
89+
return parsedFunc[expr] = parsedFunc[expr] ||
90+
Function('$values', '$context', ("with($context){return " + (expr.replace(quotedStringRe,
91+
function (match, unquoted, quoted) {
92+
if ( quoted === void 0 ) quoted = '';
93+
94+
return unquoted.replace(expressionRe,
95+
function (match, prefix, expression) {
96+
if ( prefix === void 0 ) prefix = '';
9197

92-
return false;
98+
return match ? ("" + prefix + (expression ? ("$get('" + expression + "')") : '')) : '';
99+
}
100+
) + quoted;
101+
}
102+
)) + "}"));
93103
}
94104

95105
function each(obj, iterator) {
@@ -317,26 +327,25 @@ var Fields = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_
317327
}
318328
},
319329

320-
evaluate: function evaluate$1(expr, values, config) {
330+
evaluate: function evaluate(expression, values) {
321331
if ( values === void 0 ) values = this.values;
322-
if ( config === void 0 ) config = this.config;
323-
324332

325-
if (isString(expr)) {
326333

327-
var context = {$match: $match, $values: values};
334+
try {
328335

329-
each(config, function (ref, key) {
330-
var name = ref.name; if ( name === void 0 ) name = key;
331-
332-
return set(context, name, get(values, name));
336+
if (isString(expression)) {
337+
expression = parse(expression);
333338
}
334-
);
335339

336-
return evaluate(this, expr, assign(context, values));
340+
return expression.call(this, values, {
341+
$match: $match, $get: function (key) { return get(values, key); }
342+
});
343+
344+
} catch (e) {
345+
warn(e);
337346
}
338347

339-
return expr.call(this, values, this);
348+
return true;
340349
},
341350

342351
prepare: function prepare(config, prefix) {
@@ -407,7 +416,7 @@ var Plugin = {
407416
Vue.component('fields', Fields);
408417
},
409418

410-
version: '1.0.6'
419+
version: '1.0.7'
411420
};
412421

413422
if (typeof window !== 'undefined' && window.Vue) {

dist/vue-fields.js

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-fields v1.0.6
2+
* vue-fields v1.0.7
33
* https://github.com/pagekit/vue-fields
44
* Released under the MIT License.
55
*/
@@ -87,15 +87,25 @@
8787
_set(obj, parts.shift(), val);
8888
}
8989

90-
function evaluate(self, expr, context) {
90+
var parsedFunc = {};
91+
var expressionRe = /((?:\d|true|false|null|undefined|(?:this\.|\$)[\S]+|\W)*)([\w][\w+.]*)?/g;
92+
var quotedStringRe = /([^"']+)((.)(?:[^\3\\]|\\.)*?\3|.)?/g;
9193

92-
try {
93-
return (Function('c', ("with(c){return " + expr + "}"))).call(self, context);
94-
} catch (e) {
95-
warn(e);
96-
}
94+
function parse(expr) {
95+
return parsedFunc[expr] = parsedFunc[expr] ||
96+
Function('$values', '$context', ("with($context){return " + (expr.replace(quotedStringRe,
97+
function (match, unquoted, quoted) {
98+
if ( quoted === void 0 ) quoted = '';
99+
100+
return unquoted.replace(expressionRe,
101+
function (match, prefix, expression) {
102+
if ( prefix === void 0 ) prefix = '';
97103

98-
return false;
104+
return match ? ("" + prefix + (expression ? ("$get('" + expression + "')") : '')) : '';
105+
}
106+
) + quoted;
107+
}
108+
)) + "}"));
99109
}
100110

101111
function each(obj, iterator) {
@@ -323,26 +333,25 @@
323333
}
324334
},
325335

326-
evaluate: function evaluate$1(expr, values, config) {
336+
evaluate: function evaluate(expression, values) {
327337
if ( values === void 0 ) values = this.values;
328-
if ( config === void 0 ) config = this.config;
329-
330338

331-
if (isString(expr)) {
332339

333-
var context = {$match: $match, $values: values};
340+
try {
334341

335-
each(config, function (ref, key) {
336-
var name = ref.name; if ( name === void 0 ) name = key;
337-
338-
return set(context, name, get(values, name));
342+
if (isString(expression)) {
343+
expression = parse(expression);
339344
}
340-
);
341345

342-
return evaluate(this, expr, assign(context, values));
346+
return expression.call(this, values, {
347+
$match: $match, $get: function (key) { return get(values, key); }
348+
});
349+
350+
} catch (e) {
351+
warn(e);
343352
}
344353

345-
return expr.call(this, values, this);
354+
return true;
346355
},
347356

348357
prepare: function prepare(config, prefix) {
@@ -413,7 +422,7 @@
413422
Vue.component('fields', Fields);
414423
},
415424

416-
version: '1.0.6'
425+
version: '1.0.7'
417426
};
418427

419428
if (typeof window !== 'undefined' && window.Vue) {

0 commit comments

Comments
 (0)