ctags-patterns-for-javascript icon indicating copy to clipboard operation
ctags-patterns-for-javascript copied to clipboard

Export Class Support

Open evanleck opened this issue 7 years ago • 8 comments

I'm pretty unfamiliar with the syntax for ctags regex and was wondering if there's a reason that the following wouldn't work?

export class Foo {
  // ...
}

I'd expect to be able to reach Foo as a class if that makes sense.

evanleck avatar Apr 22 '18 18:04 evanleck

The pattern for the Class kind assumes this structure:

[BOL][0+ whitespace][class][1+ whitespace][name]

You would need to add another pattern for that one:

[BOL][0+ whitespace][export][1+ whitespace][class][1+ whitespace][name]

But I'm conflicted about this request as Foo would be both a named export and a class.

romainl avatar Apr 22 '18 20:04 romainl

Hm, yeah I see get the conflict. Is that just a semantic difference in ctags or is it more meaningful?

evanleck avatar Apr 23 '18 19:04 evanleck

For the pattern, would this make sense?

--regex-javascript=/^[ \t]export[ \t]*class[ \t]\{1,\}\([A-Za-z0-9_$]\{1,\}\)/\1/C,Class,Classes/b

I just added export[ \t] in front of *class...

evanleck avatar Apr 23 '18 19:04 evanleck

This is better:

--regex-javascript=/^[ \t]*export[ \t]\{1,\}class[ \t]\{1,\}\([A-Za-z0-9_$]\{1,\}\)/\1/C,Class,Classes/b

This is not a technical problem, really, but a semantic problem: is that a named export or class definition?

romainl avatar Apr 23 '18 20:04 romainl

Makes sense, thanks! And it’s really both. I have a single file with a single class definition that it exports as a named export (i.e. not the default export).

evanleck avatar Apr 23 '18 21:04 evanleck

Hey Romain, thanks a lot for creating this super useful setup! I stumbled across the same problem. Do you think it would be possible to add the regex from your comment above to the repository?

tom3q avatar Sep 06 '19 10:09 tom3q

@tom3q I'm still not sure how to classify that thing: "class definition" or "named export", as it's both and I have no desire to have dupes in the generated tags file. Either way, you could add it to your own fork in the mean time.

romainl avatar Sep 06 '19 11:09 romainl

Okay, thanks for explanation. I'll keep it in my fork.

tom3q avatar Sep 08 '19 05:09 tom3q