Skip to content

Commit

Permalink
JavaScript: capture the right side object of destructuring assignment…
Browse files Browse the repository at this point in the history
… as anonymous class

The JavaScript parser captures a variable, to which an object is
assigned, with class kind.

Input:

  var x = { prop: "value" };

Tags output (x.js):

  prop	/tmp/x.js	/^var x = { prop: "value" };$/;"	p	class:x
  x	/tmp/x.js	/^var x = { prop: "value" };$/;"	c

In a statement of destructuring assignment, there is no variable to
which an object is assigned though an object exists at the right side.
The JavaScript parser cannot provide the scope name when capturing
a property in the object. That causes "null tag" warning.

Input (y.js):

  var {prop} = { prop: "value" };

Tags output of the original JavaScript parser:

  ctags: Warning: ignoring null tag in /tmp/y.js(line: 1)
  prop	/tmp/y.js	/^var {prop} = { prop: "value" };$/;"	p

This change introduces an anonymous class to capture the right side
object with class kind.

Tags output of the JavaScript parser with this change:

  AnonymousClass322d0fb80101	/tmp/y.js	/^var {prop} = { prop: "value" };$/;"	c
  prop	/tmp/y.js	/^var {prop} = { prop: "value" };$/;"	p	class:AnonymousClass322d0fb80101

About destructuring binding, see
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Jul 8, 2019
1 parent ad75553 commit e977d56
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Units/parser-javascript.r/js-empty-class-name.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
2 changes: 2 additions & 0 deletions Units/parser-javascript.r/js-empty-class-name.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prop input.js /^var {prop} = { prop: "value" };$/;" p class:AnonymousClass4ca5b60a0101
AnonymousClass4ca5b60a0101 input.js /^var {prop} = { prop: "value" };$/;" c
1 change: 1 addition & 0 deletions Units/parser-javascript.r/js-empty-class-name.d/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var {prop} = { prop: "value" };
5 changes: 4 additions & 1 deletion parsers/jscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,9 +2225,12 @@ static bool parseStatement (tokenInfo *const token, bool is_inside_class)
* Or checks if this is a hash variable.
* var z = {};
*/
bool anonClass = vStringIsEmpty (name->string);
if (anonClass)
anonGenerate (name->string, "AnonymousClass", JSTAG_CLASS);
has_methods = parseMethods(token, name, false);
if (has_methods)
makeJsTag (name, JSTAG_CLASS, NULL, NULL);
makeJsTagCommon (name, JSTAG_CLASS, NULL, NULL, anonClass);
else
{
/*
Expand Down

0 comments on commit e977d56

Please sign in to comment.