escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Support static class fields

Open pYr0x opened this issue 3 years ago • 5 comments

i was playing around with AST by using acorn. Acorn has a plugin to parse code with static class fields. https://github.com/acornjs/acorn-static-class-features Unfortuallity escodegen can't handle this feature. So i wrote a function that generates a static assignment from the AST provided by acorn. if you want this snippet inside your codebase i can contribute and create a PR.

PropertyDefinition: function (expr, precedence, flags) {
          var result;
          if (expr['static']) {
            result = ['static' + space];
          } else {
            result = [];
          }
          result.push(this.generateAssignment(expr.key, expr.value, '=', precedence, flags));
          result.push(this.semicolon(flags));
          return result;
        },

pYr0x avatar Mar 27 '21 11:03 pYr0x

Peanut gallery observation: I'm guessing this won't work until at least https://github.com/estools/escodegen/pull/438 lands, and that one I just noticed can't work with the Node versions this project tests for. I'm pretty sure based on Mozilla's documentation this won't work until Node 12+ is the minimum version escodegen supports...

Which is really unfortunate.

ajvincent avatar Apr 05 '21 18:04 ajvincent

This feature just has been implemented in my fork: https://www.npmjs.com/package/@javascript-obfuscator/escodegen

PR: https://github.com/javascript-obfuscator/escodegen/pull/3

sanex3339 avatar May 06 '21 07:05 sanex3339

I have the same problem, but the problem seems to still exist.

imtaotao avatar Jan 07 '22 07:01 imtaotao

Same problem here, PropertyDefinition is missing.

stepankuzmin avatar Feb 23 '23 16:02 stepankuzmin

I implemented this: https://github.com/estools/escodegen/pull/465

kevincox avatar Apr 07 '24 14:04 kevincox