ProjectEvergreen / wcc

Experimental native Web Components compiler.
https://merry-caramel-524e61.netlify.app
90 stars 7 forks source link

escodegen fails on Class fields usage #174

Open thescientist13 opened 4 days ago

thescientist13 commented 4 days ago

Type of Change

Bug

Summary

Observed while working on https://github.com/ProjectEvergreen/greenwood/pull/1321 / https://github.com/ProjectEvergreen/greenwood/issues/1183 that it looks like various Class related features don't seem to work

class Counter extends HTMLElement {
  static staticProperty = 'foo';
  #count;

  // ...
}

customElements.define('wcc-counter', Counter);
    1) Run WCC For 
       "before all" hook in "Run WCC For ":
     TypeError: this[type] is not a function
      at CodeGenerator.generateExpression (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:2514:24)
      at file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:1131:34
      at withIndent (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:579:5)
      at CodeGenerator.ClassBody (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:1126:9)
      at CodeGenerator.generateStatement (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:2527:29)
      at CodeGenerator.ClassDeclaration (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:1157:26)
      at CodeGenerator.generateStatement (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:2527:29)
      at CodeGenerator.Program (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:1716:39)
      at CodeGenerator.generateStatement (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:2527:29)
      at generateInternal (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:2548:24)
      at generate (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/@projectevergreen/escodegen-esm/escodegen.js:2616:14)
      at Object.ExpressionStatement (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/src/wcc.js:130:19)
      at c (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:24:41)
      at Object.skipThrough (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:180:37)
      at c (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:23:22)
      at base.Program.base.BlockStatement.base.StaticBlock (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:192:5)
      at c (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:23:22)
      at Module.simple (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:25:5)
      at registerDependencies (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/src/wcc.js:101:8)
      at Object.ImportDeclaration (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/src/wcc.js:115:9)
      at c (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:24:41)
      at Object.skipThrough (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:180:37)
      at c (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:23:22)
      at base.Program.base.BlockStatement.base.StaticBlock (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:192:5)
      at c (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:23:22)
      at Module.simple (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/node_modules/acorn-walk/dist/walk.mjs:25:5)
      at registerDependencies (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/src/wcc.js:101:8)
      at initializeCustomElement (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/src/wcc.js:203:5)
      at renderToString (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/src/wcc.js:241:33)
      at async Context. (file:///Users/owenbuckley/Workspace/project-evergreen/wcc/test/cases/attributes/attributes.spec.js:26:22)
  

Details

It looks this is a known issue with ecodegen but unfortunately there are PRs open, but their review / merging has gone stale 😞

It looks like there may be a way to patch this behavior https://github.com/estools/escodegen/pull/438#issuecomment-998670099

which would have to be done in our fork https://www.npmjs.com/package/@projectevergreen/escodegen-esm