Skip to content

Commit

Permalink
fix unshiftContainer and insertBefore
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed May 26, 2019
1 parent 7fd8eb5 commit e20517e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
@@ -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);
// }
@@ -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;
}
}
);
}
@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "proposal-class-properties"]
}
@@ -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));
}
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/path/modification.js
Expand Up @@ -221,7 +221,7 @@ export function unshiftContainer(listKey, nodes) {
key: 0,
});

return path.insertBefore(nodes);
return path._containerInsertBefore(nodes);
}

export function pushContainer(listKey, nodes) {
Expand Down
13 changes: 13 additions & 0 deletions packages/babel-traverse/test/modification.js
Expand Up @@ -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() {
Expand Down

0 comments on commit e20517e

Please sign in to comment.