-
Notifications
You must be signed in to change notification settings - Fork 611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use consistent quotes that don't need to be escaped #9234
Changes from all commits
ad7a5cc
f87403d
ccd43a2
ccfafff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,23 +209,26 @@ export function fieldFilterExpression(predicate: FieldPredicate, useInRange = tr | |
: rawFieldExpr; | ||
|
||
if (isFieldEqualPredicate(predicate)) { | ||
return `${fieldExpr}===${predicateValueExpr(predicate.equal, unit)}`; | ||
const equal = predicate.equal; | ||
return `${fieldExpr} === ${predicateValueExpr(equal, unit)}`; | ||
} else if (isFieldLTPredicate(predicate)) { | ||
const upper = predicate.lt; | ||
return `${fieldExpr}<${predicateValueExpr(upper, unit)}`; | ||
return `${fieldExpr} < ${predicateValueExpr(upper, unit)}`; | ||
} else if (isFieldGTPredicate(predicate)) { | ||
const lower = predicate.gt; | ||
return `${fieldExpr}>${predicateValueExpr(lower, unit)}`; | ||
return `${fieldExpr} > ${predicateValueExpr(lower, unit)}`; | ||
} else if (isFieldLTEPredicate(predicate)) { | ||
const upper = predicate.lte; | ||
return `${fieldExpr}<=${predicateValueExpr(upper, unit)}`; | ||
return `${fieldExpr} <= ${predicateValueExpr(upper, unit)}`; | ||
} else if (isFieldGTEPredicate(predicate)) { | ||
const lower = predicate.gte; | ||
return `${fieldExpr}>=${predicateValueExpr(lower, unit)}`; | ||
return `${fieldExpr} >= ${predicateValueExpr(lower, unit)}`; | ||
} else if (isFieldOneOfPredicate(predicate)) { | ||
return `indexof([${predicateValuesExpr(predicate.oneOf, unit).join(',')}], ${fieldExpr}) !== -1`; | ||
const oneOf = predicate.oneOf; | ||
return `indexof([${predicateValuesExpr(oneOf, unit).join(',')}], ${fieldExpr}) !== -1`; | ||
} else if (isFieldValidPredicate(predicate)) { | ||
return fieldValidPredicate(fieldExpr, predicate.valid); | ||
const valid = predicate.valid; | ||
return fieldValidPredicate(fieldExpr, valid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really a need to define a variable for one use. |
||
} else if (isFieldRangePredicate(predicate)) { | ||
const {range} = predicate; | ||
const lower = isSignalRef(range) ? {signal: `${range.signal}[0]`} : range[0]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,13 +288,17 @@ export function accessPathWithDatum(path: string, datum = 'datum') { | |
* @param datum The string to use for `datum`. | ||
*/ | ||
export function flatAccessWithDatum(path: string, datum: 'datum' | 'parent' | 'datum.datum' = 'datum') { | ||
return `${datum}[${stringValue(splitAccessPath(path).join('.'))}]`; | ||
return `${datum}[${doubleQuotes2Single(stringValue(splitAccessPath(path).join('.')))}]`; | ||
} | ||
|
||
function escapePathAccess(string: string) { | ||
return string.replace(/(\[|\]|\.|'|")/g, '\\$1'); | ||
} | ||
|
||
function doubleQuotes2Single(string: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we can't do this. It's too brittle and possibly introduces errors. If we want to change the quotes, we need to extend |
||
return string.replace(/"/g, "'"); | ||
} | ||
|
||
/** | ||
* Replaces path accesses with access to non-nested field. | ||
* For example, `foo["bar"].baz` becomes `foo\\.bar\\.baz`. | ||
|
@@ -476,7 +480,7 @@ export function stringify(data: any) { | |
|
||
if (node === undefined) return undefined; | ||
if (typeof node == 'number') return isFinite(node) ? '' + node : 'null'; | ||
if (typeof node !== 'object') return JSON.stringify(node); | ||
if (typeof node !== 'object') return doubleQuotes2Single(JSON.stringify(node)); | ||
|
||
let i, out; | ||
if (Array.isArray(node)) { | ||
|
@@ -503,7 +507,7 @@ export function stringify(data: any) { | |
|
||
if (!value) continue; | ||
if (out) out += ','; | ||
out += JSON.stringify(key) + ':' + value; | ||
out += doubleQuotes2Single(JSON.stringify(key)) + ':' + value; | ||
} | ||
seen.splice(seenIndex, 1); | ||
return `{${out}}`; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change spacing in a separate pull request.