JavaScript: don't choke when returning object literals

This commit is contained in:
Colomban Wendling 2014-08-03 16:57:26 +02:00
parent bc9b2fa444
commit b596aa14e8
4 changed files with 84 additions and 0 deletions

View File

@ -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;

View File

@ -112,6 +112,7 @@ test_sources = \
char-selector.f90 \
classes.php \
common.f \
complex-return.js \
continuation.f90 \
countall.sql \
cpp_destructor.cpp \

View File

@ -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;
};
};

View File

@ -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