Skip to content

Commit

Permalink
refactor(value-prop-parser): simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Oct 10, 2018
1 parent 7607378 commit 49a80f8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
50 changes: 50 additions & 0 deletions src/__tests__/__snapshots__/interpreter.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ exports[`interpreter correct target tree .apple.pear 1`] = `
Object {
"status": true,
"value": Object {
"end": Object {
"column": 12,
"line": 1,
"offset": 11,
},
"name": "valueProp",
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
"value": Object {
"left": Object {
"name": "inputProp",
Expand All @@ -105,7 +115,17 @@ exports[`interpreter correct target tree .apple.pear.bar 1`] = `
Object {
"status": true,
"value": Object {
"end": Object {
"column": 16,
"line": 1,
"offset": 15,
},
"name": "valueProp",
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
"value": Object {
"left": Object {
"name": "inputProp",
Expand Down Expand Up @@ -831,7 +851,17 @@ Object {
"value": "\\"original\\"",
},
Object {
"end": Object {
"column": 19,
"line": 1,
"offset": 18,
},
"name": "valueProp",
"start": Object {
"column": 14,
"line": 1,
"offset": 13,
},
"value": Object {
"left": Object {
"name": "input",
Expand Down Expand Up @@ -949,7 +979,17 @@ Object {
"value": "\\"original\\"",
},
Object {
"end": Object {
"column": 28,
"line": 1,
"offset": 27,
},
"name": "valueProp",
"start": Object {
"column": 23,
"line": 1,
"offset": 22,
},
"value": Object {
"left": Object {
"name": "input",
Expand Down Expand Up @@ -1007,7 +1047,17 @@ Object {
"value": "\\"original\\"",
},
Object {
"end": Object {
"column": 28,
"line": 1,
"offset": 27,
},
"name": "valueProp",
"start": Object {
"column": 23,
"line": 1,
"offset": 22,
},
"value": Object {
"left": Object {
"name": "input",
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/__tests__/valueProp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('valueProp parser', () => {
expect(parser.parse('.false.true.boo').status).toBe(true)
})
it('returns correct value', () => {
expect(parser.parse('.foo.bar').value).toEqual({
expect(parser.parse('.foo.bar').value).toMatchObject({
name: 'valueProp',
value: {
left: {
Expand Down
17 changes: 8 additions & 9 deletions src/parsers/valueProp.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// @flow

import P from 'parsimmon'
import type { NodeType, ValuePropNodeType } from '../types'
import type { NodeType } from '../types'

const valueProp = P.lazy((): mixed => {
const ValueParser = require('./value').default
return P.seq(
ValueParser,
P.regexp(/(\.[$A-Z_][0-9A-Z_$]*)+/i)
).map(([left, right]: [NodeType, string]): ValuePropNodeType => ({
name: 'valueProp',
value: {
return P.seq(ValueParser, P.regexp(/(\.[$A-Z_][0-9A-Z_$]*)+/i))
.map(([left, right]: [NodeType, string]): {
left: NodeType,
right: string
} => ({
left,
right
}
}))
}))
.node('valueProp')
})

export default valueProp

0 comments on commit 49a80f8

Please sign in to comment.