File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-env mocha */
2
2
/* eslint no-template-curly-in-string: 0 */
3
3
import assert from 'assert' ;
4
- import { extractProp } from '../helper' ;
4
+ import { extractProp , changePlugins } from '../helper' ;
5
5
import getPropValue from '../../src/getPropValue' ;
6
6
7
7
describe ( 'getPropValue' , ( ) => {
@@ -111,6 +111,16 @@ describe('getPropValue', () => {
111
111
assert . equal ( expected , actual ) ;
112
112
} ) ;
113
113
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
+
114
124
it ( 'should return undefined when identifier is literally `undefined`' , ( ) => {
115
125
const prop = extractProp ( '<div foo={undefined} />' ) ;
116
126
Original file line number Diff line number Diff line change @@ -70,7 +70,12 @@ export default function extract(value) {
70
70
} else {
71
71
expression = value ;
72
72
}
73
- const { type } = expression ;
73
+ let { type } = expression ;
74
+
75
+ if ( type === 'TSNonNullExpression' ) {
76
+ expression = expression . expression ;
77
+ type = expression . type ;
78
+ }
74
79
75
80
if ( TYPES [ type ] === undefined ) {
76
81
throw new Error ( errorMessage ( type ) ) ;
You can’t perform that action at this time.
0 commit comments