facebookarchive/prepack

ES2015 class serialization follow-ups

Open

#1,317 opened on Jan 8, 2018

View on GitHub
 (5 comments) (0 reactions) (0 assignees)JavaScript (14,268 stars) (520 forks)batch import
ES6help wanted

Description

The initial functionality of ES2015 classes was merged in https://github.com/facebook/prepack/pull/1176. However, there are still some outstanding areas of functionality that need addressing. These test cases are as follows:

1. Handling of computed methods

class Foo {
  bar() {
  }
}
Foo.prototype['foo bar'] = Foo.prototype.bar;
delete Foo.prototype.bar;
window.Foo = Foo;

Expected output:

class Foo {
  ['foo bar']() {
  }
}
window.Foo = Foo;

2. Ensuring additional static methods aren't serialized with the class

This should work, but we need more tests around it.

class Foo extends Bar {}
Foo.bar = function() {};
window.Foo = Foo;

Expected output:

class Foo extends Bar {}
Foo.bar = function() {};
window.Foo = Foo;

3. Ensuring prototype prorprties are handled properly when deleted

class Foo {
  bar() {
  }
  baz() {
  }
}
Foo.prototype.bar = Foo.prototype.bar.bind({});
var baz = Foo.prototype.baz;
delete Foo.prototype.baz;
var result = { Foo, baz };
window.result = result;

Expected output:

TODO

class Bar {
  bar() {
  }
}
class Foo extends Bar {
  bar() {
    super();
  }
}
window.result = {
  bar: Foo.prototype.bar
};
delete Foo.prototype.bar;

Expected Output:

TODO

4. Deletion of the constructor

class Foo { }
delete Foo.prototype.constructor;
window.Foo = Foo;

Expected Output:

TODO

class Foo {}
result = new Foo();
Foo.prototype = {};
window.Foo = Foo;

Expected Output:

TODO

class Foo { };
var result = Object.create({ constructor: Foo });
window.result = result;

Expected Output:

TODO

5. Handling of static initializers

class Foo {
  bar() {
  }
}
var x = new Foo();
x.bar.taggedFunction = cycle;
window.x = x;

Expected Output:

TODO

class Foo {
  bar() {
  }
}
var result = {
  Foo,
  bar: new Foo().bar
};
window.Foo = result;

Expected Output:

TODO

Each of these issues/cases can be dealt with as separate PRs.

Contributor guide