Skip TSAsExpression when transforming spread in CallExpression (#11404)
* Skip TSAsExpression when transforming spread in CallExpression * Create @babel/helper-get-call-context package * Support OptionalCallExpressions * Use helper in optional chaining plugin, and move tests * Update package.json files * Use dot notation to access property * Remove private method tests until future MR * Update packages/babel-plugin-transform-spread/package.json * Rename @babel/helper-get-call-context to @babel/helper-skip-transparent-expr-wrappers * Handle typed OptionalMemberExpressions * Make @babel/helper-skip-transparent-expr-wrappers a dependency * Support TSNonNullExpressions * Use named import instead of default * Add test for call context when parenthesized call expression has type * Improve handling of member expressions inside transparent expression wrappers * Add comment explaining what a transparent expression wrapper is * Add newlines to test fixtures * Pass correct parameter type to skipTransparentExprWrappers * Rename to babel-helper-skip-transparent-expression-wrappers * Remove getCallContext helper * Fixed exports key * Preserve types in babel-plugin-transform-spread tests * Use external-helpers to avoid inlining helper functions in tests Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import { skipTransparentExprWrappers } from "@babel/helper-skip-transparent-expression-wrappers";
|
||||
import { types as t } from "@babel/core";
|
||||
|
||||
export default declare((api, options) => {
|
||||
@@ -94,7 +95,8 @@ export default declare((api, options) => {
|
||||
const args = node.arguments;
|
||||
if (!hasSpread(args)) return;
|
||||
|
||||
const calleePath = path.get("callee");
|
||||
const calleePath = skipTransparentExprWrappers(path.get("callee"));
|
||||
|
||||
if (calleePath.isSuper()) return;
|
||||
|
||||
let contextLiteral = scope.buildUndefinedNode();
|
||||
@@ -120,7 +122,7 @@ export default declare((api, options) => {
|
||||
node.arguments.push(first);
|
||||
}
|
||||
|
||||
const callee = node.callee;
|
||||
const callee = calleePath.node;
|
||||
|
||||
if (calleePath.isMemberExpression()) {
|
||||
const temp = scope.maybeGenerateMemoised(callee.object);
|
||||
@@ -130,11 +132,11 @@ export default declare((api, options) => {
|
||||
} else {
|
||||
contextLiteral = t.cloneNode(callee.object);
|
||||
}
|
||||
t.appendToMemberExpression(callee, t.identifier("apply"));
|
||||
} else {
|
||||
node.callee = t.memberExpression(node.callee, t.identifier("apply"));
|
||||
}
|
||||
|
||||
// We use the original callee here, to preserve any types/parentheses
|
||||
node.callee = t.memberExpression(node.callee, t.identifier("apply"));
|
||||
|
||||
if (t.isSuper(contextLiteral)) {
|
||||
contextLiteral = t.thisExpression();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user