Skip to content

Allow customizing the quoting behavior of emit. #34

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

Closed
TimHambourger opened this issue Jul 4, 2022 · 1 comment
Closed

Allow customizing the quoting behavior of emit. #34

TimHambourger opened this issue Jul 4, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@TimHambourger
Copy link
Contributor

Is your feature request related to a problem? Please describe.
This is definitely a nice-to-have, not an urgent need. Something I noticed while working on #32 is that the emitter has good internal support for using either quote character (double or single) to escape comparison values, but that emit itself currently only supports using the double quote character. Among other things, this means the emitted RSQL can end up being longer than it it needs to be if the AST being emitted contains a lot of comparison values with double quotes in them.

Describe the solution you'd like
I'd propose adding an optional second parameter to emit giving it the following signature:

type Quote = '"' | "'";

interface EmitOptions {
  /**
   * The preferred quote character to use when `emit` encounters a comparison value that needs to be escaped by wrapping
   * in quotes. Either `"` (the ASCII double quote character) or `'` (the ASCII single quote character). Defaults to `"`
   * (the ASCII double quote character).
   */
  preferredQuote?: Quote;
  /**
   * If `true`, `emit` will override the `preferredQuote` setting on a comparison value-by-comparison value basis if
   * doing so would shorten the emitted RSQL. If `false`, `emit` will use the `preferredQuote` as the quote character
   * for all comparison values encountered. Defaults to `true`.
   */
  optimizeQuotes?: boolean;
}

function emit(expression: ExpressionNode, opts?: EmitOptions): string;

I'll submit a PR for this in just a min.

@TimHambourger TimHambourger added the enhancement New feature or request label Jul 4, 2022
TimHambourger pushed a commit to TimHambourger/rsql that referenced this issue Jul 4, 2022
TimHambourger pushed a commit to TimHambourger/rsql that referenced this issue Jul 8, 2022
TimHambourger pushed a commit to TimHambourger/rsql that referenced this issue Jul 8, 2022
piotr-oles pushed a commit that referenced this issue Jul 8, 2022
Add an optional second parameter to emit to customize quotes output

Co-authored-by: Tim Hambourger <[email protected]>
@piotr-oles
Copy link
Owner

Implemented in #35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants