diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/exec.js new file mode 100644 index 000000000000..e6e6630bc8c7 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/exec.js @@ -0,0 +1,23 @@ +const classes = []; +for (let i = 0; i <= 10; ++i) { + classes.push( + class A { + [i] = `computed field ${i}`; + static foo = `static field ${i}`; + #bar = `private field ${i}`; + getBar() { + return this.#bar; + } + } + ); +} + +// for(let i=0; i<= 10; ++i) { +// const clazz = classes[i]; +// expect(clazz.foo).toBe('static field ' + i); + +// const instance = new clazz(); +// expect(Object.getOwnPropertyNames(instance)).toEqual([String(i)]) +// expect(instance[i]).toBe('computed field ' + i); +// expect(instance.getBar()).toBe('private field ' + i); +// } \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/input.js new file mode 100644 index 000000000000..f7ca46cc407d --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/input.js @@ -0,0 +1,13 @@ +const classes = []; +for (let i = 0; i <= 10; ++i) { + classes.push( + class A { + [i] = `computed field ${i}`; + static foo = `static field ${i}`; + #bar = `private field ${i}`; + getBar() { + return this.#bar; + } + } + ); +} \ No newline at end of file diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/options.json new file mode 100644 index 000000000000..9d30185b9bff --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js new file mode 100644 index 000000000000..65bf85b82157 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js @@ -0,0 +1,21 @@ +const classes = []; + +for (let i = 0; i <= 10; ++i) { + var _class, _i, _temp, _bar; + + classes.push((_temp = (_i = i, _class = class A { + constructor() { + babelHelpers.defineProperty(this, _i, `computed field ${i}`); + + _bar.set(this, { + writable: true, + value: `private field ${i}` + }); + } + + getBar() { + return babelHelpers.classPrivateFieldGet(this, _bar); + } + + }), _bar = new WeakMap(), babelHelpers.defineProperty(_class, "foo", `static field ${i}`), _temp)); +} diff --git a/packages/babel-traverse/src/path/modification.js b/packages/babel-traverse/src/path/modification.js index abd1890e993e..3b2c7817d92c 100644 --- a/packages/babel-traverse/src/path/modification.js +++ b/packages/babel-traverse/src/path/modification.js @@ -221,7 +221,7 @@ export function unshiftContainer(listKey, nodes) { key: 0, }); - return path.insertBefore(nodes); + return path._containerInsertBefore(nodes); } export function pushContainer(listKey, nodes) { diff --git a/packages/babel-traverse/test/modification.js b/packages/babel-traverse/test/modification.js index 027b71945723..a4ccc90823ab 100644 --- a/packages/babel-traverse/test/modification.js +++ b/packages/babel-traverse/test/modification.js @@ -36,6 +36,19 @@ describe("modification", function() { expect(generateCode(rootPath)).toBe("function test(a) {\n b;\n}"); }); + + it("properly handles more than one arguments", function() { + const code = "foo(a, b);"; + const ast = parse(code); + traverse(ast, { + CallExpression: function(path) { + path.pushContainer("arguments", t.identifier("d")); + expect(generateCode(path)).toBe("foo(a, b, d);"); + path.pushContainer("arguments", t.stringLiteral("s")); + expect(generateCode(path)).toBe(`foo(a, b, d, "s");`); + }, + }); + }); }); describe("unshiftContainer", function() { it("unshifts identifier into params", function() {