Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retain pure annotations in class fields #3599

Merged
merged 3 commits into from May 27, 2020

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
Resolves #3591

Description

Unfortunately, acorn-walk is not yet properly updated for the new nodes added for class fields. This adds a temporary patch until this is hopefully resolved once the feature is merged to acorn.

@rollup-bot
Copy link
Collaborator

rollup-bot commented May 27, 2020

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#gh-3591-class-field-annotations

or load it into the REPL:
https://rollupjs.org/repl/?circleci=11427

@codecov
Copy link

codecov bot commented May 27, 2020

Codecov Report

Merging #3599 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3599   +/-   ##
=======================================
  Coverage   96.35%   96.35%           
=======================================
  Files         180      180           
  Lines        6140     6145    +5     
  Branches     1799     1801    +2     
=======================================
+ Hits         5916     5921    +5     
  Misses        111      111           
  Partials      113      113           
Impacted Files Coverage Δ
src/utils/pureComments.ts 100.00% <100.00%> (ø)

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 9bff788...49377f9. Read the comment docs.

@@ -3,6 +3,14 @@ import * as acorn from 'acorn';
import { base as basicWalker } from 'acorn-walk';
import { CommentDescription } from '../Module';

// patch up acorn-walk until class-fields are officially supported
basicWalker.FieldDefinition = function (node: any, st: any, c: any) {
c(node.key, st, 'Expression');
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this line to be if ( node.computed ) { c(node.key, st, 'Expression'); }, just like MethodDefinition / Property do in acorn-work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, was obviously copying without thinking.

@@ -0,0 +1,6 @@
class main {
static k = /*#__PURE__*/ V();
static /*#__PURE__*/ ignored;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this sample line has special meaning in rollup? It seems not a pure mark for function call.
Is it the new feature of rollup?
Or just as a test, to make sure here is no bug, without any other use?

Copy link
Member Author

Choose a reason for hiding this comment

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

The latter, a test to cover a branch in the logic even if it makes no sense to do so in real code.

@lukastaegert lukastaegert force-pushed the gh-3591-class-field-annotations branch from 32e1295 to 49377f9 Compare May 27, 2020 18:11
@lukastaegert lukastaegert merged commit e2a85a1 into master May 27, 2020
@lukastaegert lukastaegert deleted the gh-3591-class-field-annotations branch May 27, 2020 18:17
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.

error when in __PURE__ in class static field
3 participants