52 Commits

Author SHA1 Message Date
Bogdan Savluk
4108524856
Update prettier to v2 (#11579)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
2020-06-07 22:21:33 +02:00
Gvozd
653318b7e4 Always transform for-await in async functions. (#7446)
for-await was transformed in @babel/helper-remap-async-to-generator, which was
called by @babel/plugin-transform-async-to-generator and
@babel/plugin-proposal-async-generator-functions. This prevented for-await
statements in async functions to be transpiled if the
transform-async-to-generator plugin was't enabled.
2018-03-05 09:30:25 +01:00
Nicolò Ribaudo
252ea5a966 Fix reused nodes - part 2 (#7149) 2018-01-29 22:59:06 +01:00
Diogo Franco
0f60d42fdf
Avoid adding #__PURE__ annotation to .bind(this)() expressions (#7043)
* Avoid adding #__PURE__ annotation to .bind(this)() expressions

Fixes the #__PURE__ annotation getting added to (async () => {})() IIFEs when the arrow function transform is running with spec: true.

* Return false instead of undefined

* Fix indentation in json files

* Add one more case to the async-iife fixtures
2017-12-28 17:02:54 +09:00
Nicolò Ribaudo
05b22d2597
Update @babel/helper-wrap-function templates (#6984)
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`).
2017-12-13 16:21:58 +01:00
Diogo Franco
82357d79a7 Workaround bad #__PURE__ annotation placement on IIFEs (#6999)
Based on a fix suggested by @kzc
2017-12-08 09:51:48 -05:00
Satyajit Sahoo
7ae6e1e5a0 Add /*#__PURE__*/ annotatiotion for babel-plugin-async-to-generator. Fixes #6572 2017-11-12 18:31:48 +05:30
Mateusz Burzyński
4684edaec7 Adhering to async generator yield behavior change (#6452) 2017-10-21 21:48:27 +02:00
Logan Smyth
afc3963848 Clean up template calls. 2017-10-18 13:55:14 -07:00
Henry Zhu
cde0054227 Scoped: change src imports to @babel/ [skip ci] 2017-10-16 22:49:56 -04:00
Mateusz Burzyński
e52f6caa18 Drop old compatibility if statement targeting babel@6.15 and earlier (#6451) 2017-10-09 13:49:06 -04:00
Artem Yavorsky
b2b3d7944a Spec compatibility for iteratorClose condition. (#6094)
* for-of: IteratorClose spec compatibility.

See #3:
https://tc39.github.io/ecma262/#sec-iteratorclose

* Update spec fixtures for for-of.

* Fix IteratorClose case for remap-async-to-generator.

* Fix IteratorClose case for async-generator-function test output.

* Modify few tests according to iteratorClose fix.

* Fix iteratorClose for helpers.slicedToArray also.

* Update iteratorClose fixture for commonjs.
2017-08-28 13:39:02 -06:00
Nicolò Ribaudo
fb9a752262 Function sent (#5920)
* Create "babel-helper-wrap-function"

It contains the logic to wrap a function inside a call expression.
It was part of the "babel-helper-remap-async-to-generator" package, but
it is needed to transpile "function.sent"

* Create "babel-transform-function-sent"

It transforms the "function.sent" meta property by replacing it with
"yield" and making the generator ignore the first ".next()" call.

* "function.sent" is the last value passed to .next(), not the first one

* Disable exec tests on old node

* Fix flow error

* Add "transform-function-sent" to "stage-2" preset

* Do every trasformation in one traversal

* Test for "yield function.sent"

* [skip ci]

* Fix some typos [skip ci]
2017-07-25 11:07:01 -04:00
Justin Ridgewell
51ff4dd936 Fix async-to-generator ForAwait transform (#5932)
The old transform called an external `babel-traverse`, which doesn’t
does something funky.
2017-07-09 23:49:44 -05:00
Brian Ng
e4b35f680d
Run prettier 2017-06-27 12:15:00 -05:00
Logan Smyth
14584c218c Kill the "shadow-functions.js" internal plugin in favor of an explicit helper (#5677)
* Handle arrow function processing via shared API rather than default plugin.

* Fix a few small PR comments.

* Preserve existing spec arrow 'this' rewrites, and support spec in subclass constructors.
2017-05-05 13:27:18 -07:00
Brian Ng
8a82cc060a Run new lint rules (#5413) 2017-03-04 10:46:01 -05:00
Henry Zhu
b363e7b199 add @danez's changes 2017-03-01 12:54:22 -05:00
Daniel Tschinder
7c62278dcd [7.0] Change for-await to use new AST (#5321) 2017-02-15 17:29:09 -05:00
Henry Zhu
672adba9a1 enable prefer const (#5113) 2017-01-14 09:48:52 -05:00
Logan Smyth
5aa87aab8d Calculate the correct arity for async functions with destructuring - fixes #4977 (#4978) 2016-12-08 21:51:24 -05:00
Logan Smyth
80dfdd2a43 Only base async fn arity on non-default/non-rest params - fixes #4891 (#4901) 2016-12-08 09:48:15 -05:00
Jamesernator
dc4140dc5f Fixed incorrect compilation of async iterator methods (#4719) 2016-10-14 14:38:57 -04:00
Daniel Tschinder
5a1984aa41 make babel-helper-remap-async-to-generator bc with babel 6.15 and lower (#4603) 2016-09-29 08:14:39 -04:00
Dan Harper
682e9658c9 Fix bodyless async functions (#4600)
* fix bodyless async functions (#4599)

* Do the same in the async-generator-functions transform
2016-09-29 12:01:37 +02:00
zenparsing
26e79c5433 Implement support for async generator functions and for-await statements 2016-09-27 17:37:21 -04:00
Logan Smyth
231f27f170 Fix non-unique 'ref' binding name - fixes T7468 2016-06-28 19:16:44 -07:00
Logan Smyth
42d3844f24 Revert special arrow wrapper and avoid shadowing arguments. 2016-03-07 20:45:20 -08:00
Amjad Masad
5d0645e308 Merge pull request #3381 from keijokapp/fix-named-functionexpression-scoping-issue
Fix named async FunctionExpression scoping issue.
2016-03-07 13:39:52 -08:00
Amjad Masad
12ee11a0a4 Revert "Remove Flow annotations and pragmas"
This reverts commit 4252244d06b225ab26a02d52c04f9940a3e4d6a2.
2016-03-03 15:03:55 -08:00
keijokapp
105299f26d Fix named FunctionExpression scoping issue. 2016-02-29 19:21:48 +02:00
Sam Goldman
4252244d06 Remove Flow annotations and pragmas 2016-02-28 13:18:57 -10:00
Henry Zhu
26a3fdc3df Merge pull request #3336 from erikdesjardins/async-arrow-rest
Fix T3077 (incorrect _arguments for async arrow functions with rest params)
2016-02-17 15:26:58 -05:00
Sebastian McKenzie
b5bcd64120 noflow some files 2016-02-14 23:58:37 +00:00
Erik Desjardins
a3bca783dd Transformed generators for async function expressions should not be shadow functions 2016-02-12 11:25:11 -05:00
Erik
ec61bd9386 Revert "Don't mark async functions as hoist"
This reverts commit d34cb69912ee5789c7d1029c3be75d22d13e7bf8.
2016-02-02 22:13:26 -05:00
horpto
d0a932d0e8 [hotfix][T2765#72428] Wrong 'this' for nested arrow in arrow function 2016-01-22 10:29:04 +05:00
Amjad Masad
9980b6b8b2 [hotfix][T7006] Arrow functions don't have arguments bound 2016-01-20 00:41:17 -08:00
horpto
fa9f8ea4be Fix for deeply nested async arrows 2016-01-11 04:37:16 +05:00
horpto
f2fdc74d1b [2765] transform-async-to-generator doesn't work for this inside arrow
function
2016-01-10 21:52:04 +05:00
Henry Zhu
1d4526cd69 Merge pull request #3109 from phantom10111/additional-validators
Additional validators for CallExpression, NewExpresion,TemplateLiteral, ArrayExpression, SequenceExpression
2015-11-29 21:35:18 -05:00
Sławomir Laskowski
d34cb69912 Don't mark async functions as hoist
`babel-template` no longer crashes in IE attempting to access unpopulated error stack
2015-11-29 01:47:24 +01:00
phantom10111
615160ba66 Fix babel-helper-remap-async-to-generator to not fail with the new validation rules 2015-11-25 23:09:21 +01:00
phantom10111
1f38dcdf8a Set the correct node type in helper-remap-async-to-generator 2015-11-07 23:06:02 +01:00
Henry Zhu
042af348bc helper-remap-async-to-generator: account for ObjectMethod - fixes #2838 2015-11-05 23:57:53 -05:00
Sebastian McKenzie
1796b1926c Merge pull request #2798 from amasad/fix-2782
Fix recursion in async-to-generator transforms
2015-11-04 19:19:15 +00:00
Amjad Masad
2220167903 Fix recursion in async-to-generator transforms
We're naming the inner generator function in the name of the
original async function. This means when people have recursive
await calls it refers to the generator version. Which is fine
if we had a `yield *` (delegate). However, if not it leads to
returning an unresolved generator object.

We can either capture all recursive calls and add a delegate, which
becomes really hard with expressions. I choose to have the name
reserved to the exposed function `retFunction`.

Fixes #2782
2015-11-03 17:05:41 -08:00
Amjad Masad
e33ad7d2fb Convert arrow functions when remaping to generator. Fixes #2789 2015-11-03 14:58:31 -08:00
Sebastian McKenzie
d2d48e9f7f fix bug where async class methods weren't having their awaits converted to yields in the async to generator helper - fixes #2661 2015-11-02 07:05:00 +00:00
Sebastian McKenzie
39bdecb119 fix async function remap helper from outputing incorrect calls causing wrong scoping - fixes #2708 - fixes #2715 2015-11-01 04:39:31 +00:00