Skip to content

Commit 9763972

Browse files
vbfoxljharb
authored andcommitted
[Fix] Handle as casts in TSNonNullExpression
1 parent 5a81aca commit 9763972

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Unreleased
22
==================
3+
- [Fix] Handle `as` casts in TSNonNullExpression
34

45
3.3.1 / 2022-06-22
56
==================

__tests__/src/getPropValue-babelparser-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,13 @@ describe('getPropValue', () => {
11831183
assert.equal(actual, expected);
11841184
});
11851185

1186+
it('should return string representation of a cast wrapped in a deep Typescript non-null assertion', () => {
1187+
const prop = extractProp('<div foo={(bar as Bar).baz!} />');
1188+
const actual = getPropValue(prop);
1189+
const expected = 'bar.baz!';
1190+
assert.equal(actual, expected);
1191+
});
1192+
11861193
it('should return string representation of an object wrapped in a deep Typescript non-null assertion', () => {
11871194
const prop = extractProp('<div foo={(bar.bar)!} />');
11881195
const expected = '(bar.bar)!';

src/values/expressions/TSNonNullExpression.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export default function extractValueFromTSNonNullExpression(value) {
3131
return value.value;
3232
}
3333

34+
if (value.type === 'TSAsExpression') {
35+
return extractValueFromTSNonNullExpression(value.expression);
36+
}
37+
3438
if (value.type === 'ThisExpression') {
3539
return extractValueFromThisExpression();
3640
}

0 commit comments

Comments
 (0)