Failed to parse .js files with decorators

  • Server machine:

    • SonarQube Community Edition 8.9.1 (build 44547)
    • SonarJS plugin: sonar-javascript-plugin-
  • Scanner machine:

    • SonarScanner (Java version)
    • node.js 14

Problem: Some .js files are not parsed, with errors like these in the SonarScanner debug output:

16:06:59.234 DEBUG: Failed to parse /home/jenkins/agent/workspace/sonar-scan_NG-r02_dui-widget-modules_digitalexp-shakenremix-base-l9-module/cust/digitalExpUI/dui-widget-modules/digitalexp-shakenremix-base-l9-module/src/widget/Shakenremix.connect.js with TypeScript compiler: Property assignment expected.
16:06:59.250 ERROR: Failed to parse file [ cust/digitalExpUI/dui-widget-modules/digitalexp-shakenremix-base-l9-module/src/widget/Shakenremix.connect.js ] at line 99: unknown: Support for the experimental syntax 'decorators-legacy' isn't currently enabled (99:9):

   97 |         },
   98 |
>  99 |         @errorDecorator
      |         ^
  100 |         @loaderDecorator
  101 |         selectItem: (plan, activateNow) => {
  102 |             mobileCartItemApi.setSelectedPlan(plan, plan.selectedCommitment);

From [ Support parsing of non-standard JavaScript decorators · Issue #2174 · SonarSource/SonarJS · GitHub ] I learned that:

  • “JavaScript decorators are not part of the standard”

  • “We just added the support of JavaScript decorators. It will be part of SonarJS 6.6”

  • An ESlint parser can correctly parse these code samples using the following configuration:

    parserOptions: {
    ecmaFeatures: {
    legacyDecorators: true,

So I updated my SonarQube stack to get past SonarJS 6.6.
Also nodejs was upgraded to version 14 in order to get past the unsupported version 11.

But the problem stayed.

SonarJS Plugin:

commit “Support parsing of non-standard JavaScript decorators”
[ Support parsing of non-standard JavaScript decorators by yassin-kammoun-sonarsource · Pull Request #2268 · SonarSource/SonarJS · GitHub ]

shows eslint-bridge configured (like ESlint in issue #1247) to accept the “legacyDecorators”

This commit is behind 27505f009 (tag: - version cited in issue #1247), itself behind currently installed version (7.4.x).

So the used SonarJS plugin should have regularly parsed [.js] with decorators - unless (1) further configurations needed, or (2) unless legacy logic (SonarQube native parser) took precedence over ESlint bridge.

I tried unsuccesfully to add ESlint decorator configurations in the source tree, either in “package.json” or in a stand alone “.eslintrc.js” file.
But most probably these configurations in the source tree affect local (developer side) ESlint plugins and not the component used by SonarScanner.

From [ ] :
“In order to incrementally deliver some value and get some feedback we will rely on the two frontends simultaneously: the one we have already and the one coming from ESLint. This way we can iteratively migrate the features from one frontend to another.”

Possibly related to
[ SonarJS and ES2017 Decorators ]

Hi Edgar,

Welcome to the SonarSource community.

Have you tried adding plugin-proposal-decorators to your Babel config,
as discussed in this StackOverflow or this blog?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.