Skip to content

Commit 2a1fdb0

Browse files
committed
Handle TSNonNullExpression and test it
1 parent b63574a commit 2a1fdb0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

__tests__/src/getPropValue-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-env mocha */
22
/* eslint no-template-curly-in-string: 0 */
33
import assert from 'assert';
4-
import { extractProp } from '../helper';
4+
import { extractProp, changePlugins } from '../helper';
55
import getPropValue from '../../src/getPropValue';
66

77
describe('getPropValue', () => {
@@ -111,6 +111,16 @@ describe('getPropValue', () => {
111111
assert.equal(expected, actual);
112112
});
113113

114+
it('should work with a Typescript non-null assertion', () => {
115+
changePlugins(pls => [...pls, 'typescript']);
116+
const prop = extractProp('<div foo={bar!} />');
117+
118+
const expected = 'bar';
119+
const actual = getPropValue(prop);
120+
121+
assert.equal(expected, actual);
122+
});
123+
114124
it('should return undefined when identifier is literally `undefined`', () => {
115125
const prop = extractProp('<div foo={undefined} />');
116126

src/values/expressions/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ export default function extract(value) {
7070
} else {
7171
expression = value;
7272
}
73-
const { type } = expression;
73+
let { type } = expression;
74+
75+
if (type === 'TSNonNullExpression') {
76+
expression = expression.expression;
77+
type = expression.type;
78+
}
7479

7580
if (TYPES[type] === undefined) {
7681
throw new Error(errorMessage(type));

0 commit comments

Comments
 (0)