From b596aa14e82967d02d711c48cd62e631c29bea65 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sun, 3 Aug 2014 16:57:26 +0200 Subject: [PATCH] JavaScript: don't choke when returning object literals --- tagmanager/ctags/js.c | 4 ++ tests/ctags/Makefile.am | 1 + tests/ctags/complex-return.js | 61 ++++++++++++++++++++++++++++++ tests/ctags/complex-return.js.tags | 18 +++++++++ 4 files changed, 84 insertions(+) create mode 100644 tests/ctags/complex-return.js create mode 100644 tests/ctags/complex-return.js.tags diff --git a/tagmanager/ctags/js.c b/tagmanager/ctags/js.c index 70b71577..64d84df0 100644 --- a/tagmanager/ctags/js.c +++ b/tagmanager/ctags/js.c @@ -1663,6 +1663,10 @@ static boolean parseLine (tokenInfo *const token, boolean is_inside_class) case KEYWORD_switch: parseSwitch (token); break; + case KEYWORD_return: + findCmdTerm (token); + is_terminated = isType (token, TOKEN_SEMICOLON); + break; default: is_terminated = parseStatement (token, is_inside_class); break; diff --git a/tests/ctags/Makefile.am b/tests/ctags/Makefile.am index a125b14b..b3694bae 100644 --- a/tests/ctags/Makefile.am +++ b/tests/ctags/Makefile.am @@ -112,6 +112,7 @@ test_sources = \ char-selector.f90 \ classes.php \ common.f \ + complex-return.js \ continuation.f90 \ countall.sql \ cpp_destructor.cpp \ diff --git a/tests/ctags/complex-return.js b/tests/ctags/complex-return.js new file mode 100644 index 00000000..e84190e5 --- /dev/null +++ b/tests/ctags/complex-return.js @@ -0,0 +1,61 @@ + +function func1() { + return { a: 1, b:2 }; +} + +function func2() { + return 42; +} + +var class1 = function() { + this.method1 = function() { + return 42; + }; + this.method2 = function() { + return { a:1, b:2 }; + }; + this.method3 = function() { + return [1, 2, 3]; + }; + this.method4 = function() { + return "hello"; + }; +}; + +var class2 = function() { + this.c2m1 = function() { + c2m3(function() { + return { 'test': {} }; + }); + }; + this.c2m2 = function(f) { + return { 'ret': f() }; + }; + this.c2m3 = function(f) { + return f(); + }; +}; + +var class3 = function() { + this.c3m1 = function() { + return function(n) { + if (n == 42) { + return 0; + } else { + return (n + 1) % 42; + } + }; + }; + this.c3m2 = function() { + return 0; + }; +} + +var class4 = function() { + this.method1 = function() { + return [{a:1, b:2}, {a:3, b:4}, {a:5, b:6}]; + }; + this.method2 = function() { + return 0; + }; +}; diff --git a/tests/ctags/complex-return.js.tags b/tests/ctags/complex-return.js.tags new file mode 100644 index 00000000..c086d553 --- /dev/null +++ b/tests/ctags/complex-return.js.tags @@ -0,0 +1,18 @@ +# format=tagmanager +c2m1Ì128Îclass2Ö0 +c2m2Ì128Îclass2Ö0 +c2m3Ì128Îclass2Ö0 +c3m1Ì128Îclass3Ö0 +c3m2Ì128Îclass3Ö0 +class1Ì1Ö0 +class2Ì1Ö0 +class3Ì1Ö0 +class4Ì1Ö0 +func1Ì16Ö0 +func2Ì16Ö0 +method1Ì128Îclass1Ö0 +method1Ì128Îclass4Ö0 +method2Ì128Îclass1Ö0 +method2Ì128Îclass4Ö0 +method3Ì128Îclass1Ö0 +method4Ì128Îclass1Ö0