Skip to content

Commit

Permalink
Retain pure annotations in class fields (#3599)
Browse files Browse the repository at this point in the history
* Retain pure annotations in class fields

* Improve coverage

* Only check key if it is computed
  • Loading branch information
lukastaegert committed May 27, 2020
1 parent 9bff788 commit e2a85a1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/utils/pureComments.ts
Expand Up @@ -3,6 +3,16 @@ 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) {
if (node.computed) {
c(node.key, st, 'Expression');
}
if (node.value) {
c(node.value, st, 'Expression');
}
};

function handlePureAnnotationsOfNode(
node: acorn.Node,
state: { commentIndex: number; commentNodes: CommentDescription[] },
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/pure-class-field/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'retains pure annotations in class fields'
};
6 changes: 6 additions & 0 deletions test/form/samples/pure-class-field/_expected.js
@@ -0,0 +1,6 @@
class main {
static k = /*#__PURE__*/ V();
static [/*#__PURE__*/ W()];
}

export default main;
4 changes: 4 additions & 0 deletions test/form/samples/pure-class-field/main.js
@@ -0,0 +1,4 @@
export default class {
static k = /*#__PURE__*/ V();
static [/*#__PURE__*/ W()];
}

0 comments on commit e2a85a1

Please sign in to comment.