26 Commits

Author SHA1 Message Date
Huáng Jùnliàng
82e089c7dd
Evaluate object and initializer when setting a private method (#12707)
* fix: evaluate initializer when a private method is set as a field

* make legacy node happy

* add accessor test cases

* fix: evaluate object before RHS

* fix: evaluate object before throwing writeOnlyError
2021-03-01 17:49:59 -05:00
Huáng Jùnliàng
33fbf84fa3 Optimās: respect noDocumentAll when transforming obj?.#p (#12762) 2021-02-21 17:09:46 +01:00
Nicolò Ribaudo
6ef7b51a11 Implement assumptions defined in the babel/rfcs#5 RFC
- `mutableTemplateObject` and `ignoreToPrimitiveHint` (#12408)
- `setClassMethods` (#12407)
- `setComputedProperties` (#12490)
- `ignoreFunctionLength` (#12491)
- `noDocumentAll` (#12481)
- `iterableIsArray` and `arrayLikeIsIterable` (#12489)
- `pureGetters` (#12504)
- `skipForOfIteratorClosing` (#12496)
- `objectRestNoSymbols`, `setSpreadProperties` and `pureGetters` (#12505)
- `noNewArrows` (#12613, #12793)
- `setPublicClassFields` and `privateFieldsAsProperties` (#12497)
- `constantReexports` and `enumerableModuleMeta` (#12618)
- `constantSuper`, `superIsCallableConstructor` and `noClassCalls` (#12726)

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
Co-authored-by: Huáng Jùnliàng <JLHwung@users.noreply.github.com>
2021-02-21 17:09:45 +01:00
Nicolò Ribaudo
8063fde0d8
Reuse the readOnlyError helper for private methods (#12792) 2021-02-12 14:33:23 +01:00
Nicolò Ribaudo
3d69dc9471
Add # to the private name in "write-only" errors (#12713) 2021-01-29 17:58:13 +01:00
Federico Ciardi
5a020b24b7
fix: throw error when accessing private method without a getter (#12689)
* fix: class private accessor without getter

* Provide default return if 'writeOnlyError' is not available

* Add warning for old `@babel/helpers`

* Add missing helper call
2021-01-26 11:16:47 -05:00
Zen
cba64f9a09
Correctly access shadowed class binding in super.* (#12544)
* rename own binding inside methods if it collides with class ref. fix #11994

* fix name collisions in constructor

* do fix name collisions in constructor

* move logic in ReplaceSupers

* fix tests of helper-create-class-features-plugin

* remove replaceSupers in pushConstructor

* use environmentVisitor

* skip classLike nodes

* fix super ref in computed key
2021-01-12 02:31:06 +01:00
Huáng Jùnliàng
5dd64ecc4a
Disallow duplicated AST nodes (#11807) 2020-07-14 08:32:16 -05:00
Huáng Jùnliàng
1e115aed33
fix: ensure (a?.b)() has proper this (#11623)
* fix: ensure (a?.b)() has proper this

* let test be more restrictive

* fix: transformed member call should preserve computed

* chore: revamp test files

* refactor: simplify

* fix: unwrap parthenthesizedExpression

* add loose test cases

* add `(a?.#b)()` support

* add with-transform test cases

* Update packages/babel-plugin-proposal-optional-chaining/src/index.js

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>

* address review comments

* update test fixtures

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
2020-06-01 10:25:22 -04:00
Justin Ridgewell
bda759ac3d Handle private access chained on an optional chain (#11248)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
2020-05-26 22:18:17 +02:00
Justin Ridgewell
7459038db8 Add private-property-in-object support (#11372)
https://github.com/tc39/proposal-private-fields-in-in

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-Authored-By: Huáng Jùnliàng <jlhwung@gmail.com>
2020-05-26 22:18:17 +02:00
Justin Ridgewell
d6efed5b22
Fix redeclaring private in nested class's superClass (#11424)
If a nested class's `superClass` redeclares the outer class's private field and access it in a computed key, that should fail.

Follow up to #11405.
2020-04-20 16:54:14 +02:00
Justin Ridgewell
9b48a8ead7
Fix nested classes reference private fields (#11405)
* Fix nested classes reference private fields

* Process only visible private fields when redeclaring

* Comments

* Skip class traversal if there are no private fields

* Handle redeclared private field in computed key
2020-04-14 21:51:51 +02:00
Nicolò Ribaudo
e9c1bce50f
Add support for TS declare modifier on fields (#10545)
* [parser] Add support for TS declare modifier on fields (#10484)

* [parser] Add support for TS declare modifier on fields

* Use Object.create(null)

* Comment

* Add support for TS declare types to types and generator (#10544)

* Transform TypeScript "declare" fields (#10546)

* Transform TypeScript "declare" fields

* Remove multiple spaces

* declareFields -> allowDeclareFields

* Update after rebase
2019-11-05 10:56:57 +01:00
Tim McClure
3e4889d649 Class Private Static Accessors (#10217)
* Remove error for static private accessors

* Private static accessors strict

* Add loose mode support

* Move `value` decl for early return

* Reuse getter/setter template

* Reuse getter/setter templates

* Use `buildUndefinedNode` in accessor templates

* Extract `isAccessor` variable
2019-09-06 18:08:10 +02:00
Tan Li Hau
d3fe22f0e1 destructuring private fields with array pattern / object patte… (#10017)
* destructuring private fields with array pattern / object pattern

* wip: new test cases

* destrucuring and rest for private properties

* test case for loose private-loose

* add transform-desturcturing for exec

* update test case

* remove getPrototypeOf imports from get and set

* wip: destructure super assignment

* throw "Destructuring to a super field is not supported yet."

* fix tests and fix assignment pattern

* remove CallExpression from AssignmentPattern
2019-07-15 01:00:20 +02:00
Mattias Buelens
3c11a4a930 Fix super method call in private instance method calling overridden method (#9801)
* Fix super method call in private instance method calling overridden method

* Change return value in test fixtures

* Update tests to verify that overridden method is not called
2019-03-31 18:50:29 -04:00
Tim McClure
e068281e28 Fix super Method Calls in Class Private Methods (#9704)
This fixes an issue with the use of super method calls in class private methods. See https://github.com/babel/babel/issues/9580 for more info re: behavior of the bug.
2019-03-19 18:43:02 +01:00
Tim McClure
81c130ffc9 Private Static Class Methods (Stage 3) (#9446) 2019-03-13 00:11:16 +01:00
Nicolò Ribaudo
0b01b5217b
Use correct "this" in static fields (#9508) 2019-02-24 08:14:49 +01:00
Nicolò Ribaudo
d37c958637
Transform private async and generator functions (#9423) 2019-02-04 15:10:46 +01:00
Tim McClure
e8de6fa5d4 Private Class Methods Stage 3: Private Accessors (#9101)
* Add accessor loose support

* Add private accessors spec support

* Fix private dupe name check

* Changes from code review

* Add duplicated names tests

* Add get/set-only tests

* Move accessors tests

* Split out updates tests

* Add helper change tests

* Update test output

* Update test options
2019-01-21 22:05:37 +01:00
Nicolò Ribaudo
865eb93c2d
[private methods] Define private methods before executing initializers (#9248) 2019-01-03 20:33:44 +01:00
Nicolò Ribaudo
d1d3c823cc
Move decorators transform to @babel/helper-create-class-features-plugin (#9059)
* Move decorators to @babel/plugin-class-features

* Minor refactoring

* Use the new helper package
2018-12-09 12:30:25 +01:00
Nicolò Ribaudo
b927fb2a7e
Don't use isClassPrivateMethod because is isn't supported in <7.2.0 (#9121) 2018-12-04 08:35:10 +01:00
Nicolò Ribaudo
4e28459a2f
Make @babel/plugin-class-features a normal helper package (#9083)
* Make @babel/plugin-class-features a normal helper package

This effectively disallows using it directly.

* Rename helper

* Style

* Don't add prefix to plugin name

* Move private methods plugin
2018-11-29 16:42:45 +01:00