51 Commits

Author SHA1 Message Date
Nicolò Ribaudo
f3912ac08f
Mark transpiled JSX elements as pure (#11126)
* Mark transpiled JSX elements as pure

* Avoid duble annotation

* Add "pure" option to the React preset

* Fix generator indentation

* Update tests

* Add tests for the "pure" option

* Update windows fixtures
2020-03-19 15:43:54 +01:00
Nicolò Ribaudo
d21e2217d5
Skip newlines around inline #__PURE__ annotations (#11133)
* Skip newlines around #__PURE__ annotations

* Update tests
2020-02-13 19:16:33 +01:00
Nicolò Ribaudo
a677d59a63
Archive syntax plugins enabled by default (#10820)
* Remove syntax plugins enabled by default

Moved to babel-archive: babel/babel-archive@8f23ddce03

- `@babel/plugin-syntax-async-generators`
- `@babel/plugin-syntax-bigint`
- `@babel/plugin-syntax-dynamic-import`
- `@babel/plugin-syntax-json-strings`
- `@babel/plugin-syntax-nullish-coalescing-operator`
- `@babel/plugin-syntax-object-rest-spread`
- `@babel/plugin-syntax-optional-catch-binding`
- `@babel/plugin-syntax-optional-chaining`

* Fix build script

* Fix jest config

* Remove archived plugins from tests
2020-01-13 00:31:48 +01:00
Nicolò Ribaudo
3498195ae2
Do not hoist jsx referencing a mutable binding (#10529) 2019-10-08 18:50:03 +02:00
Serge Havas
a112be2fa0 [fix] jsx helper calls order (#10307)
imitate properly react createElement calls order
2019-08-08 22:43:57 +02:00
Artem Butusov
5b86353b35 Added es3 backward compatibility for react helper code (#10155)
* Added es3 backward compatibility for react helper code

* tweak comment [skip ci]
2019-07-03 16:49:20 +02:00
Logan Smyth
79b2af5997
Format fixture JSON with Prettier. (#8658) 2018-09-09 17:57:52 -07:00
Justin Ridgewell
e229ebbb8a
Optimize async to generator (#8267)
* Optimize async to generator

We can reuse the step function, avoiding a closure on every invocation.

* Rename step
2018-07-05 10:51:16 -04:00
Nicolò Ribaudo
9f4e2f81d8
[class-properties] Remove unnecessary return and temp variable (#8123)
* Remove unnecessary temp variable

* Update tests
2018-06-08 07:02:36 +02:00
Justin Ridgewell
43040a4181
Private Properties phase 1 (#7666)
* Private Properties phase 1

Co-authored-by: CodingItWrong

* Private fields are optional

* Docs update
2018-04-05 11:17:34 +01:00
Logan Smyth
7cc00cce0d Require output fixture extension to match sourceType output. 2018-03-04 13:31:33 -08:00
Logan Smyth
beb99dfda1 Rename test fixtures using module syntax to .mjs files. 2018-03-04 13:31:32 -08:00
Mateusz Burzyński
d283324f8a
Mark hoisted react constant elements as #__PURE__ (#7372) 2018-02-21 18:58:56 +01:00
Jorrit Schippers
3c8d831fe4 Prevent object shape change in jsx helper (#7170)
Keeping the shape of an object constant is a performance improvement for modern javascript engines. At the point of the code change it is certain that the `children` property will be set later, so the property can already be set to `undefined`.
2018-01-15 16:37:57 +01:00
Nicolò Ribaudo
8659e1a88c Remove old expected.{js,json} files (#7187) 2018-01-09 13:10:30 -06:00
Raja Sekar
0f42accb87 Renamed files 2018-01-09 15:36:42 +01:00
Henry Zhu
9ac326b075
remove es20xx prefixes from plugins and rename folders (#6575) 2017-10-28 20:43:15 -04:00
Henry Zhu
c41abd79a1
Rename all proposal plugins to -proposal- from -transform- (#6570) 2017-10-27 15:26:38 -04:00
Henry Zhu
691f90a774 Scoped: change test imports to @babel/ [skip ci] 2017-10-16 22:49:56 -04:00
Mateusz Burzyński
88b7983e4f Fixed asyncToGenerator helper using arrow function (#6289) 2017-09-21 17:09:43 -07:00
Pranav Prakash
e98bb3dc60 Use new Array instead of Array for V8 optimization (#6250)
* Use new Array instead of Array for V8 optimization

* fix spacing [skip ci]

* Remove extraneous use strict clauses
2017-09-18 14:14:46 -04:00
Logan Smyth
158e9fbfd7 Represent helpers as simple modules. 2017-09-12 22:15:16 -07:00
Noah Lemen
4fdd75695b Update Class Fields to Stage 3 and change default behavior (#6076)
* add transform-class-properties to stage 3, set spec mode to default

* update readme with examples; use `buildUndefinedNode()`; change behavior to always define both static and nonstatic class properties regardless of spec/loose mode; update tests
2017-08-10 11:19:49 -04:00
Logan Smyth
d86ae2fb84
Remove _blockHoist usage from param processing. 2017-08-03 20:56:50 -05:00
Henry Zhu
0f823beeb1 Newlines in fixtures (#6044)
* write newlines for fixtures

* rerun fixtures
2017-08-02 15:35:29 -04:00
Samuel Reed
e0b4543601 feature: Support whitelisting mutable props for react-constant-elements (#5307) 2017-07-25 13:34:21 -05:00
Peeyush Kushwaha
4a35243118 Non string computed keys in object-rest-spread (#5757) 2017-07-25 09:46:52 -05:00
Daniel Tschinder
b3372a572d Remove whitespace generation (#5833)
* Remove whitespace generation and rely on default printing

Changes to printing:
* Add newline after last empty SwitchCase
* Add newlines around block comments if they are non-flow comments or contain newlines

* Fix a few more fixtures
2017-06-27 21:57:02 -05:00
Henry Zhu
123dce5fcd Hardcode to double quotes, indent to 2 spaces (#5824) 2017-06-05 22:14:37 -05:00
Buu Nguyen
f58f4ac351 Fix incorrect destructuring in for loop let initialization (#5763)
* Fix incorrect destructuring in for loop `let` initialization

* Improve approach and fix tests
2017-05-31 15:29:50 -04:00
Samuel Reed
853b9f8ece Fix multiple var declarations in transform-react-constant-elements (#5732) (#5756)
This was broken by a legacy attachment path conditional that
is no longer needed.
2017-05-22 17:46:53 -04:00
Samuel Reed
83232bb4ff
Add regression test for transform-react-constant-elements (#5552) 2017-05-21 11:47:35 -05:00
Steven Hargrove
d5aa6d3ff8 Fix for #4943 "Calling an async function with default parameter as function for arguments checking handled synchonous" (#5688)
* moved applying arguments inside new Promise handler block

* updated test fixture to reflect change

* corrected the apply to use correct scope and arguments

* added regression test for issue #4943, added async-to-generator/async-default-arguments test

* added regression test for issue #4943

* switched back to using arrow function, since now pointing to v7 release base branch

* simplified async-to-generator regression test for issue #4943, imrproved change to self/arguments refs by using arrow function on returned promise

* updated text fixtures

* removed es2015 preset usage from issue #4943 regression exec test

* added use strict to test fixture

* added use strict to test fixture

* added destructing transform to test options

* removed use strict from exec test

* added parameters & destructing transforms to test
2017-05-03 21:44:41 -07:00
Samuel Reed
c307bbb3a9 Fix PathHoister hoisting before a same-scope variable declaration.
Seems we didn't have tests running for this very simple case.

Also fixes #5520
2017-05-01 14:32:11 -07:00
Samuel Reed
c3e8cc8ad6 Fix PathHoister error attaching after export declarations.
Fixes #5369.

See also 4ee385e96c/packages/babel-plugin-transform-class-properties/src/index.js (L167)
2017-05-01 12:41:29 -07:00
Samuel Reed
f20da57317 Fix PathHoister attaching to default parameters. (#5415)
* Fix PathHoister attaching to default parameters.

Ref: #5315

* Update hoister.js
2017-03-22 16:37:53 -04:00
Ben Alpert
14d3c2e256 Avoid adding unnecessary closure for block scoping (#5246)
When you write

```
for (const x of l) {
  setTimeout(() => x);
}
```

we need to add a closure because the variable is meant to be block-scoped and recreated each time the block runs. We do this.

However, we also add the closure when no loop is present. This isn't necessary, because if no loop is present then each piece of code runs at most once. I changed the transform to only add a closure if a variable is referenced from within a loop.
2017-02-13 13:46:00 -08:00
Samuel Reed
2aa2de8c6f feature: Support pure expressions in transform-react-constant-elements (#4812) 2017-02-12 20:02:38 -08:00
Samuel Reed
f4e3dfee74 Fix PathHoister hoisting before bindings. (#5153)
Fixes #5149 and enables a few additional safe hoists.
2017-02-12 18:35:08 -08:00
Samuel Reed
eb91bd831c Fix PathHoister hoisting JSX member expressions on "this". (#5143)
The PathHoister ignored member references on "this", causing it
to potentially hoist an expression above its function scope.

This patch tells the hoister to watch for "this", and if seen,
mark the nearest non-arrow function scope as the upper limit
for hoistng.

This fixes #4397 and is an alternative to #4787.
2017-02-12 18:34:07 -08:00
Jason Aslakson
ef25bebfa8 fix issue #5012 - Cannot read property 'declarations' of null (#5019)
- temporary fix
2017-01-19 21:36:18 -05:00
Sergey Rubanov
292c3ca206 Refactor test packages to use ES modules instead of CJS (#5138) 2017-01-16 11:25:04 -05:00
Scott Kyle
c438209718 Fix constant elements hoisted before declarator (#4804)
When multiple declarators are present in a declaration, we want to insert the constant element inside the declaration rather than placing it before because it may rely on a declarator inside that same declaration.
2016-12-03 20:19:32 -08:00
Scott Kyle
5a9509205b Fix constant elements hoisted out of block (#4419)
When block scoped variables caused the block to be wrapped in a closure, the variable `bindings` remained in parent function scope, which caused the JSX element to be hoisted out of the closure.
2016-12-03 19:54:53 -08:00
Samuel Reed
5678e61c0f fix binding kind of destructured variables. (#4813)
Fixes #4516 and any other code that hoists into a scope
where function params are destructured.
2016-11-08 13:51:54 -05:00
Sebastian McKenzie
3b4b3656a8 Fix React constant elements transform from hoisting elements to positions where their referenced bindings haven't been evaluated yet (#3596) 2016-07-27 10:54:21 -04:00
Leonid Nikiforenko
822e8804d5 Make JSXText Immutable (#3510) 2016-05-25 23:30:29 -04:00
Amjad Masad
0d8e5a9e86 Fix over-parenthesizing of function expressions 2015-12-24 14:55:51 -08:00
Ben Alpert
d1b8db1532 React inlining: Refactor to reduce parsing cost
- Have the `jsx` helper do the `defaultProps` work instead of calling `defaultProps` inline.
- Put `key` after `props` and make it optional.
- Inline `children` as rest args instead of in the object.
- Rename `createRawReactElement` to `jsx`. I wish I was kidding.

Most of these are silly microoptimizations. In my test file (based off an internal RN app), this reduces the parsing overhead of inlining from around 1% to 0.1% in JSC and from 0.6% to 0.0% in V8 (compared to element inlining before this commit).

Once parsed, the initial render with inlining is the same speed as not inlining in JSC and ~1% slower in V8. A second initial render in the same context (reusing the function objects, JIT, etc) is 2.0% faster in JSC and 5.5% faster in V8.
2015-11-12 18:05:57 -08:00
Ben Alpert
3cad287233 Use a helper function for React "inlining"
Either due to lower parsing costs or better type inference, this seems
to perform better than direct object inlining. (All along, the main win
was skipping a loop through props, not avoiding a function call.)
2015-11-10 21:10:06 -08:00