Skip to content

Commit

Permalink
Edge case from review
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 20, 2023
1 parent e2c3742 commit a0624ee
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 4 deletions.
Expand Up @@ -22,6 +22,7 @@
"bugfix"
],
"dependencies": {
"@babel/helper-environment-visitor": "workspace:^",
"@babel/helper-plugin-utils": "workspace:^"
},
"peerDependencies": {
Expand Down
@@ -1,5 +1,6 @@
import type { NodePath, Visitor } from "@babel/traverse";
import { types as t } from "@babel/core";
import { requeueComputedKeyAndDecorators } from "@babel/helper-environment-visitor";

function isNameOrLength(key: t.Node): boolean {
if (t.isIdentifier(key)) {
Expand Down Expand Up @@ -47,10 +48,14 @@ const hasReferenceOrThisVisitor: Visitor<{ name?: string; ref: () => void }> = {
}
},
FunctionParent(path, state) {
if (path.isArrowFunctionExpression()) return;
if (state.name && !path.scope.hasOwnBinding(state.name)) {
path.traverse(hasReferenceVisitor, state);
}
path.skip();
if (path.isMethod()) {
requeueComputedKeyAndDecorators(path);
}
},
};

Expand Down Expand Up @@ -189,14 +194,16 @@ export function getNameOrLengthStaticFieldsIndexes(path: NodePath<t.Class>) {
return indexes;
}

type Range = [start: number, end: number];

/**
* Converts a sorted list of numbers into a list of (inclusive-exclusive)
* ranges representing the same numbers.
*
* @example toRanges([1, 3, 4, 5, 8, 9]) -> [[1, 2], [3, 6], [8, 10]]
*/
export function toRanges(nums: number[]): [start: number, end: number][] {
const ranges = [];
export function toRanges(nums: number[]): Range[] {
const ranges: Range[] = [];

if (nums.length === 0) return ranges;

Expand Down
@@ -0,0 +1,15 @@
class C {
static p = class {
[magic(C)](C) {}
}
static x = 2;
}

class D {
static p = class {
x(C) {
magic(C);
}
}
static x = 2;
}
@@ -0,0 +1,16 @@
class C {
static {
babelHelpers.defineProperty(this, "p", class {
[magic(C)](C) {}
});
babelHelpers.defineProperty(this, "x", 2);
}
}
class D {
static p = class {
x(C) {
magic(C);
}
};
static x = 2;
}
@@ -0,0 +1,4 @@
class C {
static p = (() => magic(this))();
static q = 2;
}
@@ -0,0 +1,6 @@
class C {
static {
babelHelpers.defineProperty(this, "p", (() => magic(this))());
babelHelpers.defineProperty(this, "q", 2);
}
}
Expand Up @@ -4,8 +4,7 @@ import {
toRanges,
} from "../lib/util.js";

import babel from "@babel/core";
const { parseSync, traverse } = babel;
import { parseSync, traverse } from "@babel/core";

function classPath(input) {
let targetPath;
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Expand Up @@ -1383,6 +1383,7 @@ __metadata:
resolution: "@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly@workspace:packages/babel-plugin-bugfix-v8-static-class-fields-redefine-readonly"
dependencies:
"@babel/core": "workspace:^"
"@babel/helper-environment-visitor": "workspace:^"
"@babel/helper-plugin-test-runner": "workspace:^"
"@babel/helper-plugin-utils": "workspace:^"
"@babel/traverse": "workspace:^"
Expand Down

0 comments on commit a0624ee

Please sign in to comment.