Skip to content

Commit

Permalink
Handle TSNonNullExpression and test it
Browse files Browse the repository at this point in the history
  • Loading branch information
vhfmag committed Feb 6, 2019
1 parent 544b0bb commit ea9e7a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion __tests__/src/getPropValue-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
/* eslint no-template-curly-in-string: 0 */
import assert from 'assert';
import { extractProp } from '../helper';
import { extractProp, changePlugins } from '../helper';
import getPropValue from '../../src/getPropValue';

describe('getPropValue', () => {
Expand Down Expand Up @@ -111,6 +111,16 @@ describe('getPropValue', () => {
assert.equal(expected, actual);
});

it('should work with a Typescript non-null assertion', () => {
changePlugins(pls => [...pls, 'typescript']);
const prop = extractProp('<div foo={bar!} />');

const expected = 'bar';
const actual = getPropValue(prop);

assert.equal(expected, actual);
});

it('should return undefined when identifier is literally `undefined`', () => {
const prop = extractProp('<div foo={undefined} />');

Expand Down
7 changes: 6 additions & 1 deletion src/values/expressions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ export default function extract(value) {
} else {
expression = value;
}
const { type } = expression;
let { type } = expression;

if (type === 'TSNonNullExpression') {
expression = expression.expression;
type = expression.type;
}

if (TYPES[type] === undefined) {
throw new Error(errorMessage(type));
Expand Down

0 comments on commit ea9e7a2

Please sign in to comment.