New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert @babel/helper-explode-assignable-expression
to ts
#12417
Convert @babel/helper-explode-assignable-expression
to ts
#12417
Conversation
if (t.isPrivateName(prop)) { | ||
throw new Error( | ||
"We can't generate property ref for private name, please install `@babel/plugin-proposal-class-properties`", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already throws when private name is in property (REPL)
Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got "PrivateName"
Now we throws polished error message.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/41276/ |
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 bf43768:
|
let ref; | ||
if (t.isSuper(node)) { | ||
// Super cannot be directly assigned so lets return it directly | ||
return node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unreachable per Babel's usage:
babel/packages/babel-helper-builder-binary-assignment-operator-visitor/src/index.js
Line 13 in 9891c02
const exploded = explode(node.left, nodes, this, scope); |
The left of an assignment expression can never be a Super
.
Even if anyone passes a Super
here, it will throw in
nodes.push(t.assignmentExpression("=", t.cloneNode(temp), t.cloneNode(prop))); |
because t.cloneNode(node.property)
is undefined
and the AssignmentExpression
constructor will reject undefined as input. So we better throw early that Super
can not be exploded.
} { | ||
let obj; | ||
if (t.isIdentifier(node) && allowedSingleIdent) { | ||
obj = node; | ||
} else { | ||
obj = getObjRef(node, nodes, file, scope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file
is unused. I leave it in public interface for compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a TODO(Babel 8)
, so we don't forget about removing it.
@@ -28,7 +36,7 @@ function getObjRef(node, nodes, file, scope) { | |||
return ref; | |||
} | |||
} else { | |||
throw new Error(`We can't explode this node type ${node.type}`); | |||
throw new Error(`We can't explode this node type ${node["type"]}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise TS will think this branch is unreachable and type
property is not defined in never
.
} { | ||
let obj; | ||
if (t.isIdentifier(node) && allowedSingleIdent) { | ||
obj = node; | ||
} else { | ||
obj = getObjRef(node, nodes, file, scope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a TODO(Babel 8)
, so we don't forget about removing it.
Converted to draft since type checking it depends on transition of |
@JLHwung |
b117ce8
to
e901434
Compare
@babel/helper-explode-assignable-expression
to ts
See review comments below