This is similar to ec69b4bb1256c061ac76f53dfed09c4283ec6a31, which
was about private instance fields.
Private properties can be non-writable (thanks to decorators), or have
get/set accessors. If we stored this information on the `privateClass`
object, we would need to always use `Object.getOwnPropertyDescriptor`
before reading or writing a property because accessors need to be called
with the correct `this` context (it should be the actual class, not the
object hat stores the private properties). This commit simplifies that
operation a bit by removing the container object.
It also have another advantage, which instance fields already have
thanks to the use of separate weakmaps: unused private static fields
can be tree-shaken away or garbage-collected, while properties of an
object can't. Also, they can be easilier minified.
* Private Static Class Fields Implementation
* Redo testing without class transform for static private
* Add a call() test for private static
* Use Object.defineProperty in loose mode
* Save full descriptor instead of only value for private fields.
Decorators can make private fields non-writable, so we need to store this
information somewhere.
The descriptor can also be used to implement private accessors.
This is going to be required so we can add support for other proposals,
as well as later set the accepted proposal as the default.
Update stage-0 and stage-1 presets with `pipelineProposal` to thread down to
the plugin.
* Revert "Move subclass inheritance to end (#7772)"
This reverts commit f8ab9466d331871a90f458af40b14e8d831e0c29.
* Only use getPrototypeOf if setPrototypeOf is implemented
* Update fixtures
* Helpers updates
* Update fixtures
* Fall back to getPrototypeOf
* Update fixtures
* Update member-expression-to-functions
1. Babel using British spellings, so `memoise`
2. Provide a helper `AssignmentMemoiser` class, which will assign the memo'd value with the `n`th access.
* Private properties!
* Fixes
* Tests
* Update helper name
* Fix privates that reference other privates
* Don't extend a builtin
* Rebase
This undoes the property call folding from #6656.
It complicates the private property transforms, since they boil down to `map.set(this, vlaue)` and we definitely don't want the next call define a property on the map.
/cc @Andarist
Yes, the output is uglier. But, this is necessary for me to refactor
`replaceSupers` for #7733, which is necessary for both #7555 and
https://github.com/babel/babel/pull/7553#issuecomment-381434519.
I'm still in the middle of cleaning up all this code. Don't expect
`transformClass` to survive much longer as it's written currently.
We were using `Object.create` to setup the prototype chain at the start of the class definition, which lead to #7771.
I was a bit worried about a speed hit, but it seems everyone optimizes the two patterns the same way.
https://jsbench.github.io/#f9fca52407643d96458a35763b201215Fixes#7771.
* Fix class properties after nested class' bare super
Fixes#7371.
* Fix node 4 test
* This damn node 4 test
* All of the ClassBody, but not the methods or field inits
* tmp
* tmp
* Use common class environment visitor
* Tests
* Use skipKey to avoid recursive traversal
* Remove old state
* Use jest expect
* Properly traverse nested class for supers
* Add object nested in class cases
* Add object nested object cases
* Test class properties
* Undo changes to lerna.json
* Add tests arournd prefix/postfix super increment
* tmp
* Use sets
* Improve get/set helper
* fixtures
* Edge cases
* Add loose edge cases
* Spec compliant
* Add issue case
* Even more edge cases!
* Final updates
* Fix name
* Use Reflect.{get, set} when available
* Avoid block scoping in loose
* Remove semicolon
* Do not redefine a non-enumerable
* Get strictness from call site, not helpers
* Add called assertions
* Classes are always strict
* Update test fixture
* #7349
- Add "use strict" directive to transformed class bodies
* Update tests (#7349)
* Add test for program with use strict directive (#7349)
* Update tests (#7349)
* Update source mapping (#7349)
* Add test for parent blockStatement with use strict directive (#7349)
* Update tests (#7349)
* Update tests (#7349)
* Update tests (#7349)
* Add test for constructor-only class (#7349)
* Constructor only classes are strict, too
But constructor only that use non-simple parameters must use a strict function wrapper.
* Fix test
* Wrapper not needed if class is already strict
* Revert change to lerna.json
It was needed to avoid collision of identifiers used in fields
initializers with variables declared in the constructor, but it
broke `this` handling.
This commit removes that behavior and instead renames the
colliding variables.
* Update line endings in test fixtures to match current output
* Fix incorrectly set up static-property-tdz fixtures
It seems the fixture runner does not look into subfolders.
* Remove expected file that should not exist
* Reenable disable optimisation test
* Reenable disabled nbsp tests
* Reenable comments between props test
The comments adjacent to children test is still broken so it stays off.
This commit introduces 4 changes:
1) Function declarations are wrapped using function declarations.
This has two advantages:
- We can rely on native hoisting, instead of using _blockHoist
- The function isn't wrapped until it is called. This avoids
problems where `regeneratorRuntime.wrap` was called before
that `babel-polyfill` was imported.
Example:
function fn() {}
// becomes
function fn() { return _fn.apply(this, arguments); }
function _fn() {
_fn = _wrapper(/* Original function ... */);
return _fn.apply(this, arguments);
}
2) Use a single template for both named and anonymous function
expressions. They already had the same behavior, but the one
used for named functions was a bit longer.
3) Use normal functions instead of arrow functions to wrap
function expressions.
4) Generate a name based on the original one for wrapped
functions (e.g. `foo` becomes `_foo` instead of `_ref`).
* First implementation sketch and testcase
* Use helper instead of inline IIFE's
* minNodeVersion 6.0.0
* Hoisted visitor for subtraversal and fixed edgest case
* Resolve merge conflicts in helpers
* Remove duplicated helper from messing up Git