fix(ts): parenthesized assert and assign#12933
Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/44539/ |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 62dc9f1:
|
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
Can you add a test that with the TS plugin and createParenthesizedExpression ({}) = x still throws?
|
It broke that, what about adding a check like this to the superclass' isParenthesizedAssignable(node) {
const type = node.type
return (
type === "TSParameterProperty" ||
type === "TSAsExpression" ||
... ||
super.isParenthesizedAssignable(node)
)
} |
Co-Authored-By: Nicolò Ribaudo <7000710+nicolo-ribaudo@users.noreply.github.com>
| case "ParenthesizedExpression": | ||
| if ( | ||
| node.expression.type === "TSAsExpression" || | ||
| node.expression.type === "ParenthesizedExpression" |
There was a problem hiding this comment.
I guess TSNonNullExpression and TSTypeAssertion should be here too
There was a problem hiding this comment.
Yes, I tried running some tests on those, but they work like magic😁
JLHwung
left a comment
There was a problem hiding this comment.
Like @thorn0 said, we still need to check for TSNonNullExpression and TSTypeAssertion. It the test is passing maybe there isn't a test which enables createParenthesizedExpressions. Clearly Babel parser 7.12 fails: https://astexplorer.net/#/gist/910487b331a19aac83c5489fa4203e66/4180181cff60d53a164ab16afb82a8e6e7d5698c
The error is thrown from
, which assumes that parenthesized assignment can be either identifier / member expression. This is not the cases for TypeScript, whereTSNonNullExpression, TSAsExpression and TSTypeAssertion plays a role of transparent expression wrapper, which should have been unwrapped before check. Consider handle this as we did in
I think we can also simplifies how we handle toAssignable in the typescript plugin using this helper.
Maybe I got confused and I tested it with this code which does almost the same of that helper. |
|
Can you add following test cases with (a!) = null;
(<string>a) = null;Like Georgii mentioned before, they should not throw. |
|
Thanks! |
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
I'll merge this in 15 mins, as soon as the release CI job on main finishes
* Throw errors for invalid left-hand side assignment * Fix tests * FIx tests * Add tests from babel/babel#12933
We treat
ParenthesizedExpressionnode as aTSAsExpressionin#toAssignable()so that the function recurses one more time.