Skip to content

Commit

Permalink
[Fix] TSNonNullExpression: Handle function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
vbfox authored and ljharb committed Jun 16, 2023
1 parent a0f4f38 commit 26cc3c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions __tests__/src/getPropValue-babelparser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,13 @@ describe('getPropValue', () => {
assert.equal(actual, expected);
});

it('should return string representation of a TSNonNullExpression of form `function()!.property`', () => {
const prop = extractProp('<div foo={bar()!.bar} />');
const expected = 'bar()!.bar';
const actual = getPropValue(prop);
assert.equal(actual, expected);
});

it('should return string representation of a TSNonNullExpression of form `object!.property!`', () => {
const prop = extractProp('<div foo={bar!.bar!} />');
const actual = getPropValue(prop);
Expand Down
5 changes: 5 additions & 0 deletions src/values/expressions/TSNonNullExpression.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const extractValueFromThisExpression = require('./ThisExpression').default;
const extractValueFromCallExpression = require('./CallExpression').default;

function navigate(obj, prop, value) {
if (value.computed) {
Expand Down Expand Up @@ -35,6 +36,10 @@ export default function extractValueFromTSNonNullExpression(value) {
return extractValueFromTSNonNullExpression(value.expression);
}

if (value.type === 'CallExpression') {
return extractValueFromCallExpression(value);
}

if (value.type === 'ThisExpression') {
return extractValueFromThisExpression();
}
Expand Down

0 comments on commit 26cc3c4

Please sign in to comment.