Skip to content

Conversation

czosel
Copy link
Collaborator

@czosel czosel commented Jan 1, 2020

Change silent to be handled exactly the same way as cast is handled. Also refactor shouldBeSame for better error reporting.

Fixes #195
Fixes #355

@coveralls
Copy link

coveralls commented Jan 1, 2020

Coverage Status

Coverage increased (+0.1%) to 96.143% when pulling f03c3e7 on czosel:fix-silent-precedence into 917acf3 on glayzzle:master.

@czosel czosel force-pushed the fix-silent-precedence branch from 78d1775 to ec33e9f Compare January 1, 2020 21:49
@czosel czosel requested a review from ichiriac January 1, 2020 22:00
@czosel czosel changed the title fix: silent precendence WIP: fix: silent precendence Jan 1, 2020
@czosel czosel force-pushed the fix-silent-precedence branch from ec33e9f to 05b91b7 Compare January 1, 2020 22:05
@czosel czosel changed the title WIP: fix: silent precendence fix: silent precendence Jan 1, 2020
Copy link
Member

@ichiriac ichiriac left a comment

Choose a reason for hiding this comment

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

great rewrite of shouldBeSame 👍

src/ast.js Outdated
buffer = result.what;
result.what = result.what.left;
this.swapLocations(result, result, result.what, parser);
const subject = result.kind === "cast" ? "what" : "expr";
Copy link
Member

Choose a reason for hiding this comment

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

could be great to rename what property to expr on cast nodes, that way would be more consistent grammatically speaking - the next release will be stable so it's the last chance to introduce breaking changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was hoping you'd suggest that 😉 done!

src/ast.js Outdated
(result.kind === "silent" &&
result.expr &&
!result.expr.parenthesizedExpression)
["silent", "cast"].includes(result.kind) &&
Copy link
Member

Choose a reason for hiding this comment

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

sorry, I'm a bit maniac, could you rewrite the condition to be more optimized as this function is runned over all nodes it may impact a bit :

(result.kind == 'silent' || result.kind == 'cast') && ...

NB : The property check costs less than a function call and a lookup because you have only 2 entries

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed! Might be a good idea to add performance testing in the future 😉

Copy link
Member

Choose a reason for hiding this comment

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

it has something similar :

 PASS  test/perf.test.js
  ● Console

    console.log test/perf.test.js:42
          + Tokens speed  => 205.15K/sec
    console.log test/perf.test.js:56
          + Reading speed => 437.1K/sec
    console.log test/perf.test.js:101
          + Nodes speed  => 79.69K/sec
    console.log test/perf.test.js:115
          + Overall speed => 211.43K/sec

It's not kilobytes but thousands of tokens or nodes dependending on what is tested.

The problem is that depends on the CPU & RAM frequency (disk does not enter into account) so you can't really know automatically it you break/degrade something - any idea is welcome

Copy link
Collaborator Author

@czosel czosel Jan 2, 2020

Choose a reason for hiding this comment

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

Nice! I have no experience with performance testing myself, but I saw that in prettier/prettier something similar is done based on Benchmark.js.

@czosel czosel force-pushed the fix-silent-precedence branch from 25951da to d46ad9c Compare January 2, 2020 13:57
@czosel czosel force-pushed the fix-silent-precedence branch from d46ad9c to f03c3e7 Compare January 2, 2020 14:01
@czosel
Copy link
Collaborator Author

czosel commented Jan 2, 2020

@ichiriac What do you think, is this ready to be merged? 🚀

@ichiriac ichiriac merged commit 407e4d4 into glayzzle:master Jan 2, 2020
@ichiriac ichiriac mentioned this pull request Jan 2, 2020
8 tasks
@czosel czosel deleted the fix-silent-precedence branch January 2, 2020 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid ast for silent [feature] Convert silent mode to a property
3 participants