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

Update ESLint to version 7.8+ for more optional chaining support in TM editor #1060

Closed
Eccenux opened this issue Nov 1, 2020 · 6 comments
Closed

Comments

@Eccenux
Copy link

Eccenux commented Nov 1, 2020

I have this in code:

		let title = document.querySelector('#portaldetails .title')?.textContent;
		let url = document.querySelector('#portaldetails .linkdetails a')?.href;

Expected Behavior

Optional chaining should be permitted.

See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

Actual Behavior

This brakes ESLint built in TM editor and also code highlighting goes funky... For example text in backticks never ends. See example script below.

Specifications

  • Chrome: 86.0.4240.111 (same on Fox)
  • TM: 4.11
  • OS: Windows 10

Script

You can see an example code here:
https://github.com/Eccenux/iitc-plugin-fs-puzzle-helper/tree/master/my-plugin/dist

@derjanb derjanb added this to the 4.12 milestone Nov 2, 2020
@spiralx
Copy link

spiralx commented Nov 11, 2020

There are a few related new operators that need support:

Optional chaining operator

obj.val?.prop
obj.val?.[expr]
obj.arr?.[index]
obj.func?.(args)

Null-ish coalescing operator

leftExpr ?? rightExpr

Logical assignment operators

expr1 &&= expr2 // AND
expr1 ||= expr2 // OR
expr1 ??= expr2 // null-ish coalescing

Also the new async loop syntax:

for await (variable of iterable) {
  statement
}

and the private field syntax for classes:

class ClassWithPrivateField {
  #privateField
}

class ClassWithPrivateMethod { 
  #privateMethod() { 
    return 'hello world'
  }
}

class ClassWithPrivateStaticField {
  static #PRIVATE_STATIC_FIELD
}

I think that's everything that's not supported in the current spec.

@derjanb
Copy link
Member

derjanb commented Nov 11, 2020

All, except

expr1 &&= expr2 // AND

should work at the latest BETA version 4.12.6121.

@Dediggefedde
Copy link

Optional chaining seems to break indentation in general and highlighting when used in template-strings.

By changing el.thumb.coverImage to el.thumb?.coverImage in line 165 the following string template gets a bit crazy after ${ at starting/ending/escaping.

code_working
code_notworking

@derjanb
Copy link
Member

derjanb commented Dec 30, 2020

@Dediggefedde What is the Tampermonkey version used for your test?

@Dediggefedde
Copy link

Dediggefedde commented Jan 2, 2021

@derjanb
I have Tampermonkey v4.11.6120.
It looks the same in Firefox 84.0.1 and Chrome 87.0.4280.

A minimal example would be

function test() {
    document?.head;
    `asd${document.head}`;
    "asd";
}

Remove the ? and highlighting/indention seems fine. Execution with ? works without errors or warnings.

@derjanb
Copy link
Member

derjanb commented Jan 3, 2021

All, except
expr1 &&= expr2 // AND
should work at the latest BETA version 4.12.6121.

You can get the beta version from here: https://www.tampermonkey.net/?browser=firefox

@derjanb derjanb removed this from the 4.12 milestone May 20, 2021
@derjanb derjanb changed the title Optional chaining support in TM editor Update ESLint to version 7.8+ for more optional chaining support in TM editor May 20, 2021
@derjanb derjanb added this to the 4.14 milestone May 20, 2021
@derjanb derjanb closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants