Benedikt Meurer
00342452e2
Fix OOB string character access in Printer#_maybeAddParen. ( #6589 )
...
* Fix OOB string character access in Printer#_maybeAddParen.
The `_maybeAddParen` method of the `Printer` class does
```js
const chaPost = str[i + 1]
```
without checking that `i + 1` is still within the bounds of `str`. It
seems like this triggers fairly often that the `str[i + 1]` access is
out of bounds. The first out of bounds access will turn the KeyedLoadIC
(in case of V8) into *MEGAMORPHIC* state, which is significantly slower
for strings (there's a fix in flight for V8 to mitigate the cost a bit
in that case). Even worse than that, the out of bounds access also
pollutes the later comparisons, namely
```js
chaPost === "/"
```
and
```js
chaPost === "*"
```
which are now no longer monomorphic on strings, since `chaPost` was
sometimes `undefined`.
This is a non-breaking performance fix, which improves babel execution
on the [web-tooling-benchmark](github.com/v8/web-tooling-benchmark)
workload by around 6-9%.
* Restructure and optimize the code a bit.
2017-10-30 09:16:44 -04:00
Henry Zhu
cde0054227
Scoped: change src imports to @babel/ [skip ci]
2017-10-16 22:49:56 -04:00
Brian Ng
7f390b0282
Make terminator paren comment check more strict ( #5651 )
2017-09-15 11:06:24 -07:00
Daniel Tschinder
ca117e08cb
fix(requeue): Always requeue implicitely created BlockStatements ( #6193 )
...
This reverts the former fix done in #5743 and always requeues
BlockStatements when they get created.
This also fixes a bug in babel-generator which would indent code
even though no comments are present.
2017-09-02 01:02:21 -04:00
Sarup Banskota
213ad1ed7a
[generator] remove parens from break & continue ( #5950 )
...
* Remove parens around break and continue
Fixes #5742
* Fix space in doc comment
* Add some tests
* Remove newlines within CommentBlock
* Prevent newline before/after label
* Remove reference to node
* Check for label within startTerminatorless
* Print block instead of single line comment
* Clean up
2017-07-17 09:30:28 -07:00
Sven SAULEAU
b858d7ce5e
chore: remove unused ESLint rule
2017-07-14 11:25:09 +02: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
Brian Ng
e4b35f680d
Run prettier
2017-06-27 12:15:00 -05:00
Erik Simmler
769eddc788
Avoid creating a new line comment when a block comment is preceded by a forward slash ( #5562 )
...
Fixes #5557
2017-04-09 16:36:18 -07:00
Artem Gurzhii
6888a2c51b
Code refactoring for the babel-generator ( #5344 )
...
* refactoring code for babel-generator package
* removing spaces and refactoring if statement
* fixing warnings
2017-03-07 16:41:49 -05:00
Brian Ng
8a82cc060a
Run new lint rules ( #5413 )
2017-03-04 10:46:01 -05:00
Logan Smyth
4ee385e96c
Avoid usage of exports/module.exports/require().
2017-02-21 16:52:42 -08:00
Logan Smyth
b845f2b69d
Re-enable the max-len ESLint rule. ( #5265 )
2017-02-04 11:07:15 -05:00
Henry Zhu
672adba9a1
enable prefer const ( #5113 )
2017-01-14 09:48:52 -05:00
Shine Wang
5075f3cb6f
Bug fix for printing minified literals ( #4830 )
...
* Fixed minified literal generator: now prints the shorter of `raw` and `value`.
2016-11-15 10:50:57 -05:00
Juriy Zaytsev
1d728750c9
Add retainFunctionParens option ( #4621 )
...
* Add retainParens option
* Add doc, remove option
* Add negation test
* Make sure parens are not added
* Change name
* Change dir name
2016-09-30 18:05:33 -04:00
Logan Smyth
a13bf6e0be
Drop the unhelpful 'keyword' helper.
2016-07-18 19:12:22 -07:00
Logan Smyth
1b527eb23c
Perform number decimal checks at the token level.
2016-07-18 19:12:21 -07:00
Logan Smyth
9f49c99774
Drop .getLast().
2016-07-18 19:12:21 -07:00
Logan Smyth
fdc5b7cb5d
Only set the source location when inserting the comment text.
2016-07-17 21:51:01 -07:00
Logan Smyth
4dcec860bd
Drop trailing whitespace after all newlines.
2016-07-17 21:51:01 -07:00
Logan Smyth
59fe72ee7d
Avoid recalculating the current line.
2016-07-17 21:51:01 -07:00
Logan Smyth
1bbf109e8e
Move aux comments entirely into printer.
2016-07-17 21:51:01 -07:00
Logan Smyth
11ee8642fd
Drop the 'after' callback from 'print'.
2016-07-17 21:51:01 -07:00
Logan Smyth
59c1945493
Move whitespace handling into statement list printing.
2016-07-17 21:51:01 -07:00
Logan Smyth
5de7433147
Avoid calls to isUserWhitespacable by explicitly marking statement lists.
2016-07-17 21:51:00 -07:00
Logan Smyth
38b91235cc
Print inter-node newlines before other node items.
2016-07-17 21:51:00 -07:00
Logan Smyth
6bf52b74c0
Include newline insertion in the call sites of rightBrace.
2016-07-17 12:39:22 -07:00
Logan Smyth
0e05e9f216
Rely on .space and .newline behavior instead of explicit format checks.
2016-07-17 12:39:22 -07:00
Logan Smyth
68bc3d7dfb
Standardize on the comment format function.
2016-07-17 12:39:22 -07:00
Logan Smyth
a3c99278ba
Move format definition into Printer.
2016-07-17 11:07:26 -07:00
Logan Smyth
5e730b18bb
Instantiate Whitespace in the printer.
2016-07-17 11:07:25 -07:00
Logan Smyth
ca1d601037
Move property definitions to class props.
2016-07-17 11:07:24 -07:00
Logan Smyth
1d0ff341fd
Skip mutating the 'ignore' flag when printing.
2016-07-17 11:06:31 -07:00
Logan Smyth
44282e4579
Disable indent and inc/dec time.
2016-07-14 22:58:48 -07:00
Logan Smyth
9b8b5112df
Remove unneeded _compact assignment.
2016-07-14 22:58:48 -07:00
Logan Smyth
1bf76b0f33
Use .append to force-commit semicolons for empty statements.
2016-07-14 22:58:48 -07:00
Logan Smyth
bd9bb053c3
Flatten aux comment logic.
2016-07-14 22:58:48 -07:00
Logan Smyth
9483f4bd94
Drop old stale code.
2016-07-14 22:58:47 -07:00
Logan Smyth
b841d12c9e
Initialize inForStatementInitCounter as a public var.
2016-07-14 22:58:47 -07:00
Logan Smyth
e056c0b9d6
Use the presence of _whitespace to toggle its use.
2016-07-14 22:58:47 -07:00
Logan Smyth
6a74731c6b
Drop the private version of ._format
2016-07-14 22:58:47 -07:00
Logan Smyth
55a1ffd266
Mark a bunch of methods private.
2016-07-14 22:58:46 -07:00
Logan Smyth
6b7f3cc4cd
Inline comment generation function.
2016-07-14 21:55:08 -07:00
Logan Smyth
cb60808500
Make buffer a property for managing the token queue.
2016-07-05 21:02:46 -07:00
Logan Smyth
abb9618e8c
Drop array support from endsWith.
2016-07-05 19:44:51 -07:00
Logan Smyth
d6b1e36d49
Make the 'catchUp' call implicit to source location updates.
2016-07-04 22:49:58 -07:00
Logan Smyth
3680d10b6f
Centralize position tracking into buffer.
2016-07-04 22:42:28 -07:00
Logan Smyth
4286cb4f2a
Explicitly label standalone tokens and words.
2016-06-16 22:00:23 -07:00
Logan Smyth
22e2c88269
Drop the unneeded noIndent function param.
2016-06-16 22:00:23 -07:00