Skip to content

Commit

Permalink
Throw when compiling spread in super() but not classes (#12722)
Browse files Browse the repository at this point in the history
* Throw when compiling spread in `super()` but not classes

* Add comment
  • Loading branch information
nicolo-ribaudo committed Feb 1, 2021
1 parent 4f2d475 commit d0a965b
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/babel-plugin-transform-spread/src/index.js
Expand Up @@ -97,7 +97,13 @@ export default declare((api, options) => {

const calleePath = skipTransparentExprWrappers(path.get("callee"));

if (calleePath.isSuper()) return;
if (calleePath.isSuper()) {
// NOTE: spread and classes have almost the same compat data, so this is very unlikely to happen in practice.
throw path.buildCodeFrameError(
"It's not possible to compile spread arguments in `super()` without compiling classes.\n" +
"Please add '@babel/plugin-transform-classes' to your Babel configuration.",
);
}

let contextLiteral = scope.buildUndefinedNode();

Expand Down
@@ -0,0 +1,5 @@
class A extends B {
constructor() {
super(...foo);
}
}
@@ -0,0 +1,7 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
"transform-spread",
"transform-classes"
]
}
@@ -0,0 +1,14 @@
let A = /*#__PURE__*/function (_B) {
"use strict";

babelHelpers.inherits(A, _B);

var _super = babelHelpers.createSuper(A);

function A() {
babelHelpers.classCallCheck(this, A);
return _super.call.apply(_super, [this].concat(babelHelpers.toConsumableArray(foo)));
}

return A;
}(B);
@@ -0,0 +1,5 @@
class A extends B {
constructor() {
super(...foo);
}
}
@@ -0,0 +1,7 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
"transform-classes",
"transform-spread"
]
}
@@ -0,0 +1,14 @@
let A = /*#__PURE__*/function (_B) {
"use strict";

babelHelpers.inherits(A, _B);

var _super = babelHelpers.createSuper(A);

function A() {
babelHelpers.classCallCheck(this, A);
return _super.call.apply(_super, [this].concat(babelHelpers.toConsumableArray(foo)));
}

return A;
}(B);
@@ -0,0 +1,5 @@
class A extends B {
constructor() {
super(...foo);
}
}
@@ -0,0 +1,7 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
"transform-spread"
],
"throws": "It's not possible to compile spread arguments in `super()` without compiling classes."
}

0 comments on commit d0a965b

Please sign in to comment.