Skip to content
This repository was archived by the owner on May 19, 2018. It is now read-only.
/ babylon Public archive

Use prettier#390

Closed
danez wants to merge 1 commit intomasterfrom
prettier
Closed

Use prettier#390
danez wants to merge 1 commit intomasterfrom
prettier

Conversation

@danez
Copy link
Copy Markdown
Member

@danez danez commented Mar 1, 2017

The changes are very minimal, only in state.js prettier created a super long line, but we could also optimize this by hand and instead initialize every property individual.

Thoughts?

  • add to pre-commit hook + travis
  • adjust eslint

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 1, 2017

Codecov Report

Merging #390 into master will increase coverage by 0.07%.
The diff coverage is 98.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #390      +/-   ##
==========================================
+ Coverage   98.14%   98.21%   +0.07%     
==========================================
  Files          22       22              
  Lines        3663     3988     +325     
  Branches     1024     1219     +195     
==========================================
+ Hits         3595     3917     +322     
- Misses         25       28       +3     
  Partials       43       43
Flag Coverage Δ
#babel 80.94% <72.15%> (+1.28%) ⬆️
#babylon 96.99% <97.81%> (+0.15%) ⬆️
Impacted Files Coverage Δ
src/plugins/jsx/xhtml.js 100% <ø> (ø) ⬆️
src/plugins/flow.js 98.47% <ø> (+0.07%) ⬆️
src/parser/base.js 100% <ø> (ø) ⬆️
src/options.js 100% <ø> (ø) ⬆️
src/util/location.js 100% <ø> (ø) ⬆️
src/parser/location.js 100% <100%> (ø) ⬆️
src/tokenizer/types.js 100% <100%> (ø) ⬆️
src/parser/util.js 90.62% <100%> (+0.62%) ⬆️
src/parser/node.js 96.66% <100%> (ø) ⬆️
src/parser/statement.js 99.2% <100%> (+0.08%) ⬆️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc87d99...b439cbd. Read the comment docs.

@danez danez changed the base branch from 7.0 to master March 1, 2017 11:19
@existentialism
Copy link
Copy Markdown
Member

We'll probably want a eslint-config-babel that contains no styling rules (or also extend https://github.com/prettier/eslint-config-prettier)?

@vjeux
Copy link
Copy Markdown

vjeux commented Mar 3, 2017

This is super exciting! Do not hesitate to open up issues on the prettier repo if you see anything that isn't printed in a way that you would have written code. I want to know about it :)

this.inType =
this.noAnonFunctionType =
false;
this.inMethod = this.inFunction = this.inGenerator = this.inAsync = this.inPropertyName = this.inType = this.noAnonFunctionType = false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no idea people would chain this kind of calls! We could support it in prettier but that would add quite a bit of complexity. Since you are already writing them each on their own line, I think that it would be better to just rewrite is as

this.inMethod = false;
this.inFunction = false;
// ...

Copy link
Copy Markdown
Member

@hzoo hzoo Mar 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably specific to the parser/acorn, not common, we could probably just ignore for certain sections that aren't going to change much

Copy link
Copy Markdown
Member Author

@danez danez Mar 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vjeux Yes I mentioned that in the description above too. It is probably more readable if we rewrite it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to add // @prettier-ignore just before if you want to keep formatting for some special cases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One case I know of is Babel actually outputs code like this in the case of exports at the moment. See https://babeljs.io/repl/#?babili=false&evaluate=false&lineWrap=false&presets=es2015&targets=&browsers=&builtIns=false&code=import%20thing%20from%20'bar'%3B%0A%0Aexport%20var%20a%2C%20b%2C%20c%2C%20d%2C%20e%2C%20f%2C%20g%2C%20h%2C%20i%2C%20j%2C%20k%2C%20l%2C%20m%2C%20n%20%2Co%2C%20p%2C%20q%2C%20r%2C%20s%2C%20t%2C%20u%2C%20v%2C%20x%2C%20y%2C%20z%3B&experimental=true&loose=false&spec=false&playground=true&stage=0

includes

exports.z = exports.y = exports.x = exports.v = exports.u = exports.t = exports.s = exports.r = exports.q = exports.p = exports.o = exports.n = exports.m = exports.l = exports.k = exports.j = exports.i = exports.h = exports.g = exports.f = exports.e = exports.d = exports.c = exports.b = exports.a = undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just output though so it's fine?

// offset to the next range, and then a size of the range. They were
// generated by `bin/generate-identifier-regex.js`.
// eslint-disable-next-line comma-spacing
const astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,65,0,32,6124,20,754,9486,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,60,67,1213,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, you can use // @prettier-ignore in order to print it as is and not have every argument expanded in a single line.

if (isIdentifierStart(code) || code === 92 /* '\' */) {
return this.readWord();
if (isIdentifierStart(code) || code === 92) {
/* '\' */ return this.readWord();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not intended, I just created an issue for it: prettier/prettier#867


if (!openingElement.selfClosing) {
contents: for (;;) {
contents:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be fixed in the next release: prettier/prettier#860

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Mar 3, 2017

Can we just target 7.0 for this? We can cherry pick other prs if necessary

case tt._import:
if (this.hasPlugin("dynamicImport") && this.lookahead().type === tt.parenL) break;
if (
this.hasPlugin("dynamicImport") && this.lookahead().type === tt.parenL
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened prettier/prettier#868 as it looks a bit weird

// Astral code point; split in surrogate halves
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xD800;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always so interesting how little things trigger knee-jerk reactions. I always prefer capitalized hex haha.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is pretty impressive!

For this one, we looked at github search results and it seems like the majority of js code uses lowercase. Also, Chrome devtools forces lowercase.

image

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Mar 21, 2017

We moved the previous 7.0 branch to be master now, and master is now 6.x

@danez
Copy link
Copy Markdown
Member Author

danez commented Apr 21, 2017

I just rerun prettier 1.2.2 on the source and all the mentioned things are fixed now. :)

@danez
Copy link
Copy Markdown
Member Author

danez commented Jun 9, 2017

Okay rebased and change everything to work. Ready for review.

const startData = generate(start);
const contData = generate(cont);

console.log("let nonASCIIidentifierStartChars = \"" + startData.nonASCII + "\";");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use template strings here, don't have to change in this pr


this.finishNode(node, (op === tt.logicalOR || op === tt.logicalAND) ? "LogicalExpression" : "BinaryExpression");
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn);
node.right = this.parseExprOp(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol this whole block

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Jun 9, 2017

Just going to be annoying for @Andy-MS ts pr

@bakkot
Copy link
Copy Markdown
Contributor

bakkot commented Jun 9, 2017

@hzoo after this lands he can just run prettier on his pr, presumably!

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Jun 10, 2017

That's the idea! I guess you would run beforehand and then rebase 7.0 and it would be ok?

@existentialism existentialism mentioned this pull request Jun 28, 2017
@hzoo
Copy link
Copy Markdown
Member

hzoo commented Jun 28, 2017

Moving to #600

@hzoo hzoo closed this Jun 28, 2017
@hzoo hzoo deleted the prettier branch June 30, 2017 11:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants