Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter fails to parse public class fields #166

Closed
twity1337 opened this issue Jul 23, 2021 · 9 comments
Closed

Linter fails to parse public class fields #166

twity1337 opened this issue Jul 23, 2021 · 9 comments

Comments

@twity1337
Copy link

Describe the problem and steps to reproduce it:

We developed an Thunderbird addon using modern ES6 modules, as described here https://developer.thunderbird.net/add-ons/mailextensions#webextension-scripts

Unfortunately after months of developing the addon, we were not able to upload it on the AMO.
Linter reports syntax errors in two of our files. It seems, it does not understand all language features of ES6.

The addon works quite fine in current version of Thunderbird (version 78.12.0, 64-bit). So I can't understand, why the validation process is blocking the submission.

What happened?

Uploading the addon is not possible, because the linter cannot parse our addon code (a glimpse of the affected file is given below). Instead the following syntax errors are thrown:

JavaScript syntax error - Error: There is a JavaScript syntax error in your code; validation cannot continue on this file.
chrome/content/lib/db/DatabaseManager.js line 1 column 1

JavaScript syntax error - Error: There is a JavaScript syntax error in your code; validation cannot continue on this file.
chrome/content/lib/repository/ConversationRepository.js line 1 column 1

I think it is noteworthy, that only 2 of our files are reported. We have more files with ES6 features in our addon, but those are not mentioned in the validation report.

What did you expect to happen?

Linter should understand export and import statements and class members defined in class scope.

Anything else we should know?

DatabaseManager.js, Line 1 - 10

export class DatabaseManager {
  __dbConnection
  __dbName

  constructor (name) {
    console.assert(window.indexedDB !== undefined)
    this.__dbConnection = null
    this.__dbName = name
    this.__objectStoreInUse = null
  }
// ....

ConversationRepository.js, Line 1-20

import { DatabaseManager } from '../db/DatabaseManager.js'

export class ConversationRepository {
  __dbManager
  tableName = 'conversation'

  constructor () {
    let ths = this
    this.__dbManager = new DatabaseManager('myname')
    this.__dbManager.initializeDatabase(function (connection, oldVersion, newVersion) {
      if (oldVersion < 1) {
        connection.createObjectStore(ths.tableName, {
          keyPath: 'email',
          autoIncrement: false
        })
      }
    })
    this.__dbManager.useObjectStore(this.tableName)
  }
@Sancus
Copy link
Member

Sancus commented Jul 24, 2021

addons-linter likely needs to be on a newer version, I can do that on Monday.

@Sancus
Copy link
Member

Sancus commented Aug 1, 2021

Try submitting your add-on again please.

@twity1337
Copy link
Author

twity1337 commented Aug 1, 2021

Try submitting your add-on again please.

After resubmitting I get the following errors instead:
chrome/content/lib/db/DatabaseManager.js line 2 column 1:

JavaScript syntax error (Parsing as module error: Unexpected token __dbName at line: 3 and column: 3) (Parsing as script error: 'import' and 'export' may appear only with 'sourceType: module' at line: 2 and column: 1)

chrome/content/lib/repository/ConversationRepository.js line 1 column 1:

JavaScript syntax error (Parsing as module error: Unexpected token tableName at line: 5 and column: 3) (Parsing as script error: 'import' and 'export' may appear only with 'sourceType: module' at line: 1 and column: 1)

These errors are solved after removing the public class fields in the two files. Submission is no longer blocked.

After submitting the addon I'll post the addon name here, so further debugging can proceed.

@twity1337
Copy link
Author

Okay, I now managed to submit the addon for review.
If you want to check the validation for the addon, check this out: https://addons.thunderbird.net/en-US/thunderbird/addon/smartcompose/

@Sancus
Copy link
Member

Sancus commented Aug 1, 2021

OK, so the underlying issue here is that eslint does not support public class fields yet, and therefore addons-linter does not, see: mozilla/addons-linter#3836

We cannot resolve this until those upstream issues are fixed, sorry.

@Sancus Sancus changed the title Linter fails to parse ES6 Linter fails to parse public class fields Aug 1, 2021
@jobisoft
Copy link

The AMO bug mentioned a dependency on a ESLint bug, which seems to be fixed now:
eslint/eslint#14343

Does that mean this issue can move forward?

@lieser
Copy link

lieser commented Feb 22, 2022

Any update on this? Like @jobisoft mentioned this works since ESLint 8,.0.0 (https://eslint.org/blog/2021/10/eslint-v8.0.0-released).
Also seems to be fixed upstream (mozilla/addons-linter#3062).

This is currently preventing me to upload a new release, since I started to use static fields in classes.
Could of course revert the usage of static fields, but would really like to avoid that.

@Sancus
Copy link
Member

Sancus commented Feb 23, 2022

Thanks for the reminder, I've updated the linter and deployed the change, so this should work now. Let me know if it doesn't.

ef373a3

@Sancus Sancus closed this as completed Feb 23, 2022
@lieser
Copy link

lieser commented Feb 23, 2022

Thanks a lot for the quick fix. Can confirm that uploading to ATN worked now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants