Async functions don't compile without exception identifier
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.
This issue has been linked to a new work item: W-10823976
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).
This will be fixed in Winter '24 due to dropping support for IE11 and legacy browsers (LWC v3.0.0).
Thank you for reporting!