Skip to content

Commit

Permalink
Fix elm string representation parsing when keys are empty strings or …
Browse files Browse the repository at this point in the history
…contain spaces

Closes #23
  • Loading branch information
kachkaev committed Mar 17, 2019
1 parent 13b7be2 commit 2572105
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packages/elm-string-representation/src/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,33 @@ export const testCases: Array<{
},
},
{
input: ['{ = "test", b = 42 }', '{ b = 42, = "test" }'],
input: [
'{ = "test", b = 42 }',
'{ b = 42, = "test" }',
'{ = "test", b = 42 }',
],
output: {
"": "test",
b: 42,
},
},
{
input: ['{ two words = "test", b = 42 }', '{ b = 42, two words = "test" }'],
output: {
"two words": "test",
b: 42,
},
},
{
input: [
'{ a lot of words = "test", b = 42 }',
'{ b = 42, a lot of words = "test" }',
],
output: {
"a lot of words": "test",
b: 42,
},
},
{
input: ["( 1, 2 )", "(1,2)"],
output: [1, 2],
Expand Down
2 changes: 1 addition & 1 deletion packages/elm-string-representation/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default (text: string): any => {
chunk
.replace(/ = True/g, " = true")
.replace(/ = False/g, " = false")
.replace(/(,|{)(| ([$a-zA-Z_0-9]+)) = /g, '$1 "$3": ')
.replace(/(,|{)\s*(|([$a-zA-Z_0-9 ]*)\s+)= /g, '$1 "$3": ')
.replace(/\(/g, "[")
.replace(/\)/g, "]"),
);
Expand Down

0 comments on commit 2572105

Please sign in to comment.