lwc icon indicating copy to clipboard operation
lwc copied to clipboard

Async functions don't compile without exception identifier

Open filiprafalowicz opened this issue 3 years ago • 1 comments

Description

Per MDN docs (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#the_exception_identifier) exception identifier can be omitted when you don't need to use it in catch block. This works fine if you create LWC module with the code from the example:

export function isValidJSON(text) {
    try {
        JSON.parse(text);
        return true;
    } catch {
        return false;
    }
}

But if you change this function to be async, you'll get:

LWC1001: Unexpected compilation error: /home/sfdc/tools/lwc/2.5.13-236.1/myCmp.js: Cannot read property 'type' of null

Steps to Reproduce

Try to compile following code in LWC:

export async function isValidJSONAsync(text) {
    try {
        JSON.parse(text);
        return true;
    } catch {
        return false;
    }
}

Expected Results

LWC is compiled

Actual Results

Compilation error is thrown

Browsers Affected

N/A

Version

  • LWC: 2.5.13-236.1

Additional context/Screenshots I get this error when I deploy the code with sfdx.

filiprafalowicz avatar Mar 09 '22 11:03 filiprafalowicz

This issue has been linked to a new work item: W-10823976

uip-robot-zz avatar Mar 10 '22 16:03 uip-robot-zz

Just ran into this issue myself! thank you for reporting it as it gave me a direction to fix (as the error message was not really helpful).

zerkz avatar Jun 22 '23 04:06 zerkz

This will be fixed in Winter '24 due to dropping support for IE11 and legacy browsers (LWC v3.0.0).

Thank you for reporting!

nolanlawson avatar Jul 17 '23 23:07 nolanlawson