Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ JsonTemplate.prototype.compile = function() {

function parse(item) {
let matched = false;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:]+))?(:(\w+))?)\}/g;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:]+))?(:(\w+))?)\}/g;
/* eslint-disable no-cond-assign */
while (match = templates.exec(item)) {
/* eslint-enable no-cond-assign */
matched = true;
const param = /([[\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:]+))?(:(\w+))?/.exec(match[1]);
const param = /([[\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:]+))?(:(\w+))?/.exec(match[1]);
if (!param || !param[1]) {
throw new Error(g.f('Invalid parameter: %s', match[1]));
}
Expand Down Expand Up @@ -120,7 +120,7 @@ JsonTemplate.prototype.build = function(parameters) {
function transform(obj) {
return traverse(obj).map(function(item) {
const ctx = this;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:\{\}]+))?(:(\w+))?)\}/g;
const templates = /\{(([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:\{\}]+))?(:(\w+))?)\}/g;
function build(item) {
let match = null;
const parsed = [];
Expand All @@ -134,7 +134,7 @@ JsonTemplate.prototype.build = function(parameters) {
parsed.push(item.substring(index, match.index));
}
// The variable pattern is {name=defaultValue:type}
const param = /([\!\^]?[a-zA-Z\$_][\w\$]*)\s*(=([^:\{\}]+))?(:(\w+))?/.exec(match[1]);
const param = /([\!\^]?[a-zA-Z\$_][\w\$-]*)\s*(=([^:\{\}]+))?(:(\w+))?/.exec(match[1]);
if (!param || !param[1]) {
throw new Error(g.f('Invalid parameter: %s', match[1]));
}
Expand Down