BowlerHatLLC / vscode-as3mxml

ActionScript & MXML language extension for Visual Studio Code. Develop apps for Adobe AIR, Adobe Flash Player, or Apache Royale.
https://as3mxml.com/
Apache License 2.0
257 stars 39 forks source link

'(' is not allowed here for property names inside an Object literal #725

Closed hachigoro closed 9 months ago

hachigoro commented 9 months ago

Hello, I have been working on a large AS3 project on FlashDevelop for a long time, and I am trying to move it to VS Code. I am getting some errors on the editor that FlashDevelop. One error is highlighting the parenthesis inside an Object definition:

public static const ageGroups:Object = {
    (AgeTypes.BABY.toString()):   KeysGP.AGE_BABY,
    (AgeTypes.CHILD.toString()):  KeysGP.AGE_CHILD
};

The '(' before AgeTypes.BABY is marked as an error that says "'(' is not allowed here". This code builds fine and is not highlighted by FlashDevelop or IntelliJ IDEA. Any help would be appreciated.

Thanks!

joshtynjala commented 9 months ago

In all my many years of working with AS3, I have never seen that syntax before. Crazy!

I did some tests, and I see that this syntax is supported by the old Flex SDK compiler. However, it is not supported by the newer ASC 2.0 compiler in the AIR SDK & Compiler bundle, and it is not supported by the Apache Royale compiler (which is a fork of ASC 2.0). vscode-as3mxml uses the Royale compiler to power its code intelligence. I don't see this syntax being supported by the Royale compiler in the future, especially considering that ASC 2.0 doesn't support it either.

Just out of curiosity, I also checked JavaScript (AS3 was originally based on it), and this style of syntax isn't supported there either.

I'm not sure that this is officially supported syntax, even if it works (I have encountered some other quirky things over the years that "worked", but weren't actually supposed to). Even if it was intentionally supported in the past, it's clear that Adobe decided to stop allowing it later in ASC 2.0.

I'm going to mark this won't fix, and I recommend changing your code. If you ever want to move to the newer ASC 2.0, you're going to need to do that anyway. I believe that this is equivalent:

public static const ageGroups:Object = {};
ageGroups[AgeTypes.BABY.toString()] = KeysGP.AGE_BABY;
ageGroups[AgeTypes.CHILD.toString()] = KeysGP.AGE_CHILD;
hachigoro commented 9 months ago

Thanks for looking into it, I was not aware that was not supported anymore. I have updated the code and now it has no complaints.