Skip to content

Commit

Permalink
Support Nullish coalescing operator ("??") (#67)
Browse files Browse the repository at this point in the history
It's Stage 3 and already supported in TypeScript 3.7
  • Loading branch information
naruaway authored and alexanderwallin committed Dec 27, 2019
1 parent 562a883 commit cc9d71d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export const BABEL_PARSING_OPTS = {
'functionSent',
'dynamicImport',
'optionalChaining',
'nullishCoalescingOperator',
],
}
10 changes: 10 additions & 0 deletions tests/fixtures/NullishCoalescing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { gettext } from 'gettext-lib'

const someObject = {}

const OptionalChaining = () => {
const expressionUsingOptionalChaining = someObject.something ?? 'defaultValue'
gettext('Nullish coalescing works')
}

export default OptionalChaining
9 changes: 9 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,13 @@ describe('react-gettext-parser', () => {
expect(messages[0].msgid).to.equal('Optional chaining works')
})
})

describe('nullish coalescing support', () => {
it('should parse javascript that contains nullish coalescing operator', () => {
const code = getSource('NullishCoalescing.js')
const messages = extractMessages(code)
expect(messages).to.have.length(1)
expect(messages[0].msgid).to.equal('Nullish coalescing works')
})
})
})

0 comments on commit cc9d71d

Please sign in to comment.