Skip to content

Commit

Permalink
Merge pull request #16 from segmentio/fix-escape-after-dot
Browse files Browse the repository at this point in the history
unlex: Escape identifiers after dots
  • Loading branch information
tysonmote authored Sep 25, 2019
2 parents 85a4316 + 4d1ad60 commit 980c384
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@segment/fql",
"version": "1.7.0",
"version": "1.7.1",
"main": "dist/index.js",
"browser": "dist/index.js",
"bin": "dist/index.js",
Expand Down
5 changes: 2 additions & 3 deletions src/unlexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ test('Unlexer can convert tokens into a string', () => {
})

test('Unlexer escapes', () => {
const str = unlex([t.Ident('a \\ b $')]).code

expect(str).toEqual('a\\ \\\\\\ b\\ \\$')
expect(unlex([t.Ident('a \\ b $')]).code).toEqual('a\\ \\\\\\ b\\ \\$')
expect(unlex([t.Ident('a'), t.Dot(), t.Ident('b c')]).code).toEqual('a.b\\ c')
})

test('Unlexer and lexer play nicely together', () => {
Expand Down
11 changes: 5 additions & 6 deletions src/unlexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ export default function unlex(tokens: Token[]): UnLexResponse {
continue
}

// Don't add unnecessary spaces after dots
if (i !== 0 && tokens[i - 1].type === TokenType.Dot) {
str += token.value
continue
// Add a space, but not after dots
if (i > 0 && tokens[i - 1].type !== TokenType.Dot) {
str += ' '
}

if (token.type === TokenType.Ident) {
str += ' ' + escape(token.value)
str += escape(token.value)
} else {
str += ' ' + token.value
str += token.value
}
}

Expand Down

0 comments on commit 980c384

Please sign in to comment.