Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript: improved parsing of anonymous functions #3437

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Units/parser-javascript.r/js-fields.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ field13 input.js /^ ['field13'];$/;" M class:Class0
['field1' + '4'] input.js /^ ['field1' + '4']$/;" M class:Class0
field15 input.js /^ field15 = 1$/;" M class:Class0
field16 input.js /^ field16 = [ function() {return}, function() {return} ]$/;" M class:Class0
anonymousFunction391993410100 input.js /^ field16 = [ function() {return}, function() {return} ]$/;" f class:Class0
anonymousFunction391993410200 input.js /^ field16 = [ function() {return}, function() {return} ]$/;" f class:Class0
method2 input.js /^ method2() {$/;" m class:Class0
method3 input.js /^ method3() {$/;" m class:Class0
Class1 input.js /^class Class1 {$/;" c
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
a input.js /^"a".prototype = function() {}$/;" c
anonymousFunction2e03ffc00100 input.js /^"a".prototype = function() {}$/;" f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
anonymousFunction204aa80e0100 input.js /^(function(x) {$/;" f
a input.js /^ var a = function (o) { return o; };$/;" f function:anonymousFunction204aa80e0100
anonymousFunction204aa80e0200 input.js /^(function(y) {$/;" f
b input.js /^ const b = function (p) { return p; };$/;" f function:anonymousFunction204aa80e0200
anonymousFunction204aa80e0300 input.js /^!function(z) {$/;" f
c input.js /^ const c = function (r) { return r; };$/;" f function:anonymousFunction204aa80e0300
anonymousFunction204aa80e0400 input.js /^console.log("a" + (function (A) {$/;" f
anonymousFunction204aa80e0500 input.js /^}((function (B) {$/;" f
anonymousFunction204aa80e0600 input.js /^}(!function(C) {$/;" f
f input.js /^ var f = function (t) {$/;" f function:anonymousFunction204aa80e0600
26 changes: 26 additions & 0 deletions Units/parser-javascript.r/js-self-invoking-anon-func.d/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(function(x) {
var a = function (o) { return o; };
return x + a (1);
})(1);

(function(y) {
const b = function (p) { return p; };
return y - b (1);
}(1));

!function(z) {
const c = function (r) { return r; };
return z * c (1);
}(1);

console.log("a" + (function (A) {
return A;
}((function (B) {
return B;
}(!function(C) {
var f = function (t) {
return !t;
}
return f(C);
}(true)
)))));
2 changes: 2 additions & 0 deletions parsers/jscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,8 @@ static bool parseStatement (tokenInfo *const token, bool is_inside_class)
{
if (isType (token, TOKEN_OPEN_CURLY))
parseBlock (token, CORK_NIL);
else if (isKeyword (token, KEYWORD_function))
parseFunction (token);

/* Potentially the name of the function */
if (isType (token, TOKEN_PERIOD))
Expand Down