Skip to content

Commit 0fc514d

Browse files
committed
fix #4442, better support of named function expression in raw
the use case is for recursive function
1 parent ccb3484 commit 0fc514d

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

jscomp/core/classify_function.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let classify (prog : string) : Js_raw_info.exp =
2626
match Parser_flow.parse_expression
2727
(Parser_env.init_env None prog) false with
2828
| (_, Function {
29-
id = None;
29+
id = _;
3030
params = (_, {params});
3131
async = false;
3232
generator = false;

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ build test/gpr_4274_test.cmi test/gpr_4274_test.cmj : cc test/gpr_4274_test.ml |
324324
build test/gpr_4280_test.cmi test/gpr_4280_test.cmj : cc test/gpr_4280_test.ml | test/mt.cmj $stdlib
325325
build test/gpr_4407_test.cmi test/gpr_4407_test.cmj : cc test/gpr_4407_test.ml | test/debug_mode_value.cmj test/mt.cmj $stdlib
326326
build test/gpr_441.cmi test/gpr_441.cmj : cc test/gpr_441.ml | $stdlib
327+
build test/gpr_4442_test.cmi test/gpr_4442_test.cmj : cc test/gpr_4442_test.ml | test/mt.cmj $stdlib
327328
build test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
328329
build test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib
329330
build test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib

jscomp/test/gpr_4442_test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
var Mt = require("./mt.js");
4+
5+
var suites = {
6+
contents: /* [] */0
7+
};
8+
9+
var test_id = {
10+
contents: 0
11+
};
12+
13+
function eq(loc, x, y) {
14+
return Mt.eq_suites(test_id, suites, loc, x, y);
15+
}
16+
17+
var u = (function fib(n){
18+
if(n===0||n==1){
19+
return 1
20+
}
21+
return fib(n-1) + fib(n-2)
22+
});
23+
24+
eq("File \"gpr_4442_test.ml\", line 14, characters 6-13", u(2), 2);
25+
26+
eq("File \"gpr_4442_test.ml\", line 15, characters 6-13", u(3), 3);
27+
28+
Mt.from_pair_suites("gpr_4442_test.ml", suites.contents);
29+
30+
exports.suites = suites;
31+
exports.test_id = test_id;
32+
exports.eq = eq;
33+
exports.u = u;
34+
/* Not a pure module */

jscomp/test/gpr_4442_test.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
let suites : Mt.pair_suites ref = ref []
3+
let test_id = ref 0
4+
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
5+
6+
let u = [%raw{|function fib(n){
7+
if(n===0||n==1){
8+
return 1
9+
}
10+
return fib(n-1) + fib(n-2)
11+
}|}]
12+
13+
14+
;; eq __LOC__ (u 2) 2
15+
;; eq __LOC__ (u 3) 3
16+
17+
;; Mt.from_pair_suites __FILE__ !suites

0 commit comments

Comments
 (0)