Quick-Turn-Studio / CLionSupportForQt

19 stars 0 forks source link

Modern JavaScript object literal syntax #43

Closed ratijas closed 2 years ago

ratijas commented 3 years ago

Summary

Object literal syntax does not support Shorthand property names (ES2015).

Steps to reproduce

  1. Open or create QML file.
  2. Add some JavaScript context, e.g. declare a function or signal handler.
  3. Initialize an object using shorthand property names, like this:
onReleased: {
    processEvent({ duration });
}

Expected result

Parse object literal as normal. Word duration refers both to the key of this new object and to the existing variable in scope.

Actual result

QmlTokenType.COLON or QmlTokenType.DOT expected, got '}'
grabusr commented 3 years ago

Hi @ratijas

It seems to be easy fix. We will fix this in this week. Thank you for providing good documentation and providing references.

ratijas commented 3 years ago

It's not the only unsupported grammar. Another case I found is just a + operator in a math expression on the right hand side of an assignment in a signal handler. It said something about invalid/unexpected QML_* tokens.

You guys really should reuse JavaScript parser from IntelliJ platform whenever possible, instead of reinventing the wheel. QML just embeds js with custom globals and properties, but without any syntax/grammar modifications.

ratijas commented 3 years ago

Not to mention template string literals and their recursive parsing contexts.

`string text ${expression} string text`

tag`string text ${expression} string text`
grabusr commented 3 years ago

Hi @ratijas

Reusing JB JS parser is not so easy that it seems to be. JS parser is not included by default in every JB editor, eg. in CLion. It is delivered in WebStorm, but this is paid IDE. We are in contact with JetBrains to resolve that, but on this moment we need to support simple javascript syntax on our own.