Skip to content
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

Fix rewriteThis in helper-module-transforms for computed class elements #11109

Merged
merged 13 commits into from Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/babel-helper-module-transforms/package.json
Expand Up @@ -12,6 +12,7 @@
"main": "lib/index.js",
"dependencies": {
"@babel/helper-module-imports": "^7.8.3",
"@babel/helper-replace-supers": "^7.8.3",
"@babel/helper-simple-access": "^7.8.3",
"@babel/helper-split-export-declaration": "^7.8.3",
"@babel/template": "^7.8.3",
Expand Down
6 changes: 4 additions & 2 deletions packages/babel-helper-module-transforms/src/rewrite-this.js
@@ -1,3 +1,4 @@
import { skipAllButComputedKey } from "@babel/helper-replace-supers";
export default function rewriteThis(programPath: NodePath) {
// Rewrite "this" to be "undefined".
programPath.traverse(rewriteThisVisitor);
Expand All @@ -12,10 +13,11 @@ const rewriteThisVisitor = {
path.replaceWith(path.scope.buildUndefinedNode());
},
Function(path) {
if (!path.isArrowFunctionExpression()) path.skip();
if (path.isMethod()) skipAllButComputedKey(path);
sidntrivedi012 marked this conversation as resolved.
Show resolved Hide resolved
else if (!path.isArrowFunctionExpression()) path.skip();
},
ClassProperty(path) {
path.skip();
skipAllButComputedKey(path);
},
ClassPrivateProperty(path) {
path.skip();
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-replace-supers/src/index.js
Expand Up @@ -26,7 +26,7 @@ function getPrototypeOfExpression(objectRef, isStatic, file, isPrivateMethod) {
return t.callExpression(file.addHelper("getPrototypeOf"), [targetRef]);
}

function skipAllButComputedKey(path: NodePath) {
export function skipAllButComputedKey(path: NodePath) {
// If the path isn't computed, just skip everything.
if (!path.node.computed) {
path.skip();
Expand Down
@@ -0,0 +1 @@
export class C { [this.name]() {} }
@@ -0,0 +1,7 @@
{
"plugins": [
"external-helpers",
"transform-modules-commonjs",
"syntax-class-properties"
]
}
@@ -0,0 +1,13 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.C = void 0;

class C {
[(void 0).name]() {}

}

exports.C = C;
@@ -0,0 +1,3 @@
class A {
[() => this.name]() {}
}
@@ -0,0 +1,7 @@
{
"plugins": [
"external-helpers",
"transform-modules-commonjs",
"syntax-class-properties"
]
}
@@ -0,0 +1,6 @@
"use strict";

class A {
[() => (void 0).name]() {}

}
@@ -0,0 +1,3 @@
class A {
[function () { this.name; }]() {}
}
@@ -0,0 +1,7 @@
{
"plugins": [
"external-helpers",
"transform-modules-commonjs",
"syntax-class-properties"
]
}
@@ -0,0 +1,8 @@
"use strict";

class A {
[function () {
this.name;
}]() {}

}
@@ -0,0 +1 @@
export class C { [this.name] = 42 }
@@ -0,0 +1,7 @@
{
"plugins": [
"external-helpers",
"transform-modules-commonjs",
"syntax-class-properties"
]
}
@@ -0,0 +1,12 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.C = void 0;

class C {
[(void 0).name] = 42;
}

exports.C = C;