Skip to content

Commit

Permalink
[WIP] Make field() correctly escape []
Browse files Browse the repository at this point in the history
Fix #1949
  • Loading branch information
kanitw committed Feb 16, 2017
1 parent 7ffa07a commit 9679106
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/fielddef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ export interface FieldRefOption {

export function field(fieldDef: FieldDef, opt: FieldRefOption = {}) {
let field = fieldDef.field;

const bracketsEscaped = field.charAt(0) === '['
&& field.charAt(field.length - 1) === ']';

if (bracketsEscaped) {
field = field.slice(1, field.length -1);
}

let prefix = opt.prefix;
let suffix = opt.suffix;

Expand Down Expand Up @@ -170,10 +178,11 @@ export function field(fieldDef: FieldDef, opt: FieldRefOption = {}) {
}

if (opt.datum) {
field = `datum["${field}"]`;
// for datum, we never have to wrap with []
return `datum["${field}"]`;
}

return field;
return bracketsEscaped ? `[${field}]` : field;
}

function _isFieldDimension(fieldDef: FieldDef) {
Expand Down

0 comments on commit 9679106

Please sign in to comment.