fix(jq): support quoted string key shorthand in object construction#108
Open
skoblenick wants to merge 3 commits intovercel-labs:mainfrom
Open
fix(jq): support quoted string key shorthand in object construction#108skoblenick wants to merge 3 commits intovercel-labs:mainfrom
skoblenick wants to merge 3 commits intovercel-labs:mainfrom
Conversation
|
@skoblenick is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
a6432d5 to
01a8e76
Compare
…ction
In real jq, quoted string keys can be used as shorthand in object
construction without a colon, e.g. {"name"} is equivalent to
{"name": .name}. The parser does not support this — the STRING branch
in parseObjectConstruction() (parser.ts:1032-1035) unconditionally
requires a colon after string keys, causing a parse error.
This affects patterns like:
{"name"} -> Expected ":" error
{"name", "label"} -> Expected ":" error
{"if"} -> Expected ":" error (keyword as string key)
{"name", "v": .x} -> Expected ":" error (mixed shorthand/explicit)
Note: unquoted identifier shorthand ({name, label}) works correctly
since isIdentLike() handles IDENT and keyword tokens. The bug is
specifically in the quoted string key path.
Adds 15 unit tests and 5 comparison tests (all currently failing).
The parser unconditionally required a colon after string keys in object
literals, causing filters like {"name"} and {"if"} to fail with a parse
error. Real jq treats these as shorthand for {"name": .name}.
Mirror the existing isIdentLike() shorthand logic in the STRING
branch by checking for a colon and falling back to a Field
access node when absent.
…nd edge cases
- Assert entry count, key strings, and Field node shape in parser tests
- Add non-identifier key tests: hyphenated ("a-b"), numeric ("1"), empty ("")
- Add regression test for explicit key-value with string key ("name": .x)
- Add comparison tests for non-identifier key shorthands
- Extract expectShorthandEntry() helper to reduce duplication
01a8e76 to
edcebfa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The jq parser did not support quoted string key shorthand syntax in object construction. In real jq,
{"name"}is valid shorthand for{"name": .name}, allowing users to quickly project fields from an object. Our parser required a colon and explicit value after every quoted string key, causing expressions like{"name"},{"name", "label"}, and keyword keys like{"if"}to fail with a parse error.This broke real-world pipelines such as:
Fix
Updated the query-engine parser (
src/commands/query-engine/parser.ts) to handle quoted string keys the same way as unquoted identifier keys: when a quoted string key is not followed by a colon, it is treated as shorthand — the key becomes the string value and the value becomes.key(a field access). When a colon follows, the existing explicit key-value behavior is preserved.Tests
src/commands/jq/jq.string-key-shorthand.test.ts): 21 tests covering parser AST correctness and evaluation for standard keys, keyword keys ("if","true","null","as","try"), non-identifier keys ("a-b"), numeric string keys ("1"), empty string keys (""), mixed shorthand + explicit entries, andfromjsonpipelines.src/comparison-tests/jq.comparison.test.ts): 8 tests validating output parity with real bashjqacross all shorthand variants.