lab icon indicating copy to clipboard operation
lab copied to clipboard

Private fields causes parsing issue.

Open cpomerantz opened this issue 7 years ago • 2 comments

Support plan

  • which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
  • is this issue currently blocking your project? (yes/no):yes
  • is this issue affecting a production system? (yes/no):no

Context

  • node version: 12.13.1
  • module version with issue: 21.0.0
  • last module version without issue:
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...):hapi application
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

I am using private fields and getting a Unexpected character '#' error when code coverage is enabled. I have also tried excluding that file and using /* $lab:coverage:off$ */ where that file is being required. It looks like the issue is actually happening in Espree, but I also thought I should be able to exclude this file from being parsed.

What was the result you got?

Full stack trace is here:

Unexpected character '#'

      at Espree.raise (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/espree/lib/espree.js:256:25)
      at Espree.pp$9.getTokenFromCode (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:4569:10)
      at Espree.pp$9.readToken (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:4297:17)
      at Espree.pp$9.nextToken (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:4288:17)
      at Espree.pp$9.next (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:4245:10)
      at Espree.pp.eat (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:619:12)
      at Espree.pp.expect (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:683:10)
      at Espree.pp$1.parseClass (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:1313:10)
      at Espree.pp$1.parseStatement (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:833:19)
      at Espree.pp$1.parseTopLevel (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:746:23)
      at Espree.parseTopLevel (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/espree/lib/espree.js:244:26)
      at Espree.parse (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/acorn/dist/acorn.js:553:17)
      at Espree.parse (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/espree/lib/espree.js:210:35)
      at Object.parse (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/node_modules/espree/espree.js:133:38)
      at Object.internals.instrument (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/lib/coverage.js:333:25)
      at Object.require.extensions.<computed> [as .js] (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/lib/coverage.js:122:55)
      at Object.require.extensions.<computed> (/Users/cpomer/src/greenlight-service/node_modules/proxyquire/lib/proxyquire.js:311:43)
      at Module.load (internal/modules/cjs/loader.js:815:32)
      at Function.Module._load (internal/modules/cjs/loader.js:727:14)
      at Proxyquire._require (/Users/cpomer/src/greenlight-service/node_modules/proxyquire/lib/proxyquire.js:201:19)
      at require (internal/modules/cjs/helpers.js:74:18)
      at Object.<anonymous> (/Users/cpomer/src/greenlight-service/src/shared/models/inquiries/model.js:12:18)
      at Module._compile (internal/modules/cjs/loader.js:959:30)
      at Object.require.extensions.<computed> [as .js] (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/lib/coverage.js:122:36)
      at Object.require.extensions.<computed> (/Users/cpomer/src/greenlight-service/node_modules/proxyquire/lib/proxyquire.js:311:43)
      at Module.load (internal/modules/cjs/loader.js:815:32)
      at Function.Module._load (internal/modules/cjs/loader.js:727:14)
      at Module.require (internal/modules/cjs/loader.js:852:19)
      at Proxyquire._withoutCache (/Users/cpomer/src/greenlight-service/node_modules/proxyquire/lib/proxyquire.js:222:12)
      at Proxyquire.load (/Users/cpomer/src/greenlight-service/node_modules/proxyquire/lib/proxyquire.js:129:15)
      at /Users/cpomer/src/greenlight-service/test/unit/shared/models/inquiries/model.test.js:27:13
      at Immediate.<anonymous> (/Users/cpomer/src/greenlight-service/node_modules/@hapi/lab/lib/runner.js:662:31)
      at processImmediate (internal/timers.js:439:21)
      at process.topLevelDomainCallback (domain.js:130:23)

What result did you expect?

I was expecting the offending file to be excluded from code coverage and then hopefully from any kind of parsing that is going on.

cpomerantz avatar Nov 25 '19 18:11 cpomerantz

It looks like private class fields are still stage 3. ESLint only supports stage 4 language features. It looks like the ESLint team recommends using the babel-eslint parser for now.

cjihrig avatar Nov 25 '19 18:11 cjihrig

Ah, I see. I'll change my code then. It just really helped me out in this particular circumstance.

cpomerantz avatar Nov 25 '19 22:11 cpomerantz