This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 248443 - Wrong code format for function named catch
Summary: Wrong code format for function named catch
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Assignee: Roman Svitanic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-06 00:31 UTC by _ gtzabari
Modified: 2014-12-13 06:12 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2014-11-06 00:31:49 UTC
Javascript Promises require the use of a function named "catch". Netbeans' Javascript parser mistreats this function call as a try-catch block resulting in two problems:

1. Th wrong code-formatting rules get applied, resulting in "catch (foo)" instead of "catch(foo)".
2. The word "catch" is highlighted as a reserved word.

This bug prevents me from enabling https://github.com/jscs-dev/node-jscs rule "disallowSpacesInCallExpression: true".
Comment 1 Vladimir Riha 2014-11-06 08:37:43 UTC
Well catch is a reserved keyword in JavaScript and thus function/variables cannot be named with "catch". Check [1] and [2].

   function catch(){} is illegal, but 

   myObject.catch = function(){} is legal (although in some older browsers still could cause issues)


How exactly do you use it with Promises? I think it is similar to

   promise.then(function(){}).catch(function(){})


which works fine for me. Could you please post here your code? Thank you


[1] http://www.w3schools.com/js/js_reserved.asp
[2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar
Comment 2 _ gtzabari 2014-11-06 16:28:44 UTC
1. I am aware this syntax will cause problems for older browsers. I am working exclusively with modern browsers and I expect Netbeans to support them.

2. You are right that some cases of catch() works properly. Here is a specific use-case to help you reproduce the problem:

This works:

return Authentication.insert(email, password).catch(function(error)
{
	// do something
});

This does not:

return Authentication.insert(email, password).
  catch (function(error)
  {
	// do something
  });

The only difference seems to be whether "catch" shows up on a newline. In the case case, the word "catch" is highlighted in blue (like a reserved word) and there is an undesirable space between "catch" and the braces.
Comment 3 Roman Svitanic 2014-12-12 15:18:30 UTC
Changeset: 11c2f8942d19
Author:    Roman Svitanic <rsvitanic@netbeans.org>
Date:      2014-12-12 16:18
Message:   #248443: Wrong code format for function named catch - fixed
Comment 4 Quality Engineering 2014-12-13 06:12:22 UTC
Integrated into 'main-silver', will be available in build *201412130001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/11c2f8942d19
User: Roman Svitanic <rsvitanic@netbeans.org>
Log: #248443: Wrong code format for function named catch - fixed
Task #248443 - Wrong code format for function named catch