Skip to content

Commit 0365836

Browse files
committed
Fix issue where pipe "->" processing eats up attributes.
1 parent cf177c6 commit 0365836

File tree

6 files changed

+100
-28
lines changed

6 files changed

+100
-28
lines changed

jscomp/frontend/ast_exp_apply.ml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
7070
| _ -> None
7171

7272
let inner_ops = [ "##"; "#@" ]
73-
7473
let infix_ops = [ "|."; "#="; "##" ]
7574

7675
let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
@@ -110,16 +109,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
110109
let fn = self.expr self fn in
111110
match fn.pexp_desc with
112111
| Pexp_variant (label, None) ->
113-
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
112+
{
113+
fn with
114+
pexp_desc = Pexp_variant (label, Some new_obj_arg);
115+
pexp_loc = e.pexp_loc;
116+
}
114117
| Pexp_construct (ctor, None) ->
115-
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
116-
| Pexp_apply (fn, args) ->
118+
{
119+
fn with
120+
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
121+
pexp_loc = e.pexp_loc;
122+
}
123+
| Pexp_apply (fn1, args) ->
117124
Bs_ast_invariant.warn_discarded_unused_attributes
118-
fn.pexp_attributes;
125+
fn1.pexp_attributes;
119126
{
120-
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
121-
pexp_attributes = [];
127+
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
122128
pexp_loc = e.pexp_loc;
129+
pexp_attributes = e.pexp_attributes;
123130
}
124131
| _ -> (
125132
match Ast_open_cxt.destruct fn [] with

jscomp/test/res_debug.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3+
var Curry = require("../../lib/js/curry.js");
34
var Caml_obj = require("../../lib/js/caml_obj.js");
5+
var Caml_option = require("../../lib/js/caml_option.js");
46

57
function f($$window, a, b) {
68
return $$window.location(a, b);
@@ -24,6 +26,29 @@ function testMatch(v) {
2426
}
2527
}
2628

29+
function optionMap(x, f) {
30+
if (x !== undefined) {
31+
return Caml_option.some(Curry._1(f, Caml_option.valFromOption(x)));
32+
}
33+
34+
}
35+
36+
var ok_name = optionMap(undefined, (function (x) {
37+
return x;
38+
}));
39+
40+
var ok = {
41+
name: ok_name
42+
};
43+
44+
var bad_name = optionMap(undefined, (function (x) {
45+
return x;
46+
}));
47+
48+
var bad = {
49+
name: bad_name
50+
};
51+
2752
var v2 = newrecord;
2853

2954
var v1 = {
@@ -35,11 +60,17 @@ var h = /* '\522' */128522;
3560

3661
var hey = "hello, 世界";
3762

63+
var name;
64+
3865
exports.f = f;
3966
exports.v0 = v0;
4067
exports.v2 = v2;
4168
exports.v1 = v1;
4269
exports.testMatch = testMatch;
4370
exports.h = h;
4471
exports.hey = hey;
72+
exports.optionMap = optionMap;
73+
exports.name = name;
74+
exports.ok = ok;
75+
exports.bad = bad;
4576
/* Not a pure module */

jscomp/test/res_debug.res

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,16 @@ let testMatch = v =>
5353
let h = '😊'
5454
let hey = "hello, 世界"
5555
// failed to type check
56+
57+
let optionMap = (x, f) =>
58+
switch x {
59+
| None => None
60+
| Some(v) => Some(f(v))
61+
}
62+
63+
type props<'name> = {key?: string, name?: string}
64+
65+
let name = None
66+
67+
let ok = {name: ?optionMap(name, x => x)}
68+
let bad = {name: ?name->optionMap(x => x)}

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269488,7 +269488,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
269488269488
| _ -> None
269489269489

269490269490
let inner_ops = [ "##"; "#@" ]
269491-
269492269491
let infix_ops = [ "|."; "#="; "##" ]
269493269492

269494269493
let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
@@ -269528,16 +269527,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
269528269527
let fn = self.expr self fn in
269529269528
match fn.pexp_desc with
269530269529
| Pexp_variant (label, None) ->
269531-
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
269530+
{
269531+
fn with
269532+
pexp_desc = Pexp_variant (label, Some new_obj_arg);
269533+
pexp_loc = e.pexp_loc;
269534+
}
269532269535
| Pexp_construct (ctor, None) ->
269533-
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
269534-
| Pexp_apply (fn, args) ->
269536+
{
269537+
fn with
269538+
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
269539+
pexp_loc = e.pexp_loc;
269540+
}
269541+
| Pexp_apply (fn1, args) ->
269535269542
Bs_ast_invariant.warn_discarded_unused_attributes
269536-
fn.pexp_attributes;
269543+
fn1.pexp_attributes;
269537269544
{
269538-
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
269539-
pexp_attributes = [];
269545+
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
269540269546
pexp_loc = e.pexp_loc;
269547+
pexp_attributes = e.pexp_attributes;
269541269548
}
269542269549
| _ -> (
269543269550
match Ast_open_cxt.destruct fn [] with

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270951,7 +270951,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
270951270951
| _ -> None
270952270952

270953270953
let inner_ops = [ "##"; "#@" ]
270954-
270955270954
let infix_ops = [ "|."; "#="; "##" ]
270956270955

270957270956
let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
@@ -270991,16 +270990,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
270991270990
let fn = self.expr self fn in
270992270991
match fn.pexp_desc with
270993270992
| Pexp_variant (label, None) ->
270994-
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
270993+
{
270994+
fn with
270995+
pexp_desc = Pexp_variant (label, Some new_obj_arg);
270996+
pexp_loc = e.pexp_loc;
270997+
}
270995270998
| Pexp_construct (ctor, None) ->
270996-
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
270997-
| Pexp_apply (fn, args) ->
270999+
{
271000+
fn with
271001+
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
271002+
pexp_loc = e.pexp_loc;
271003+
}
271004+
| Pexp_apply (fn1, args) ->
270998271005
Bs_ast_invariant.warn_discarded_unused_attributes
270999-
fn.pexp_attributes;
271006+
fn1.pexp_attributes;
271000271007
{
271001-
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
271002-
pexp_attributes = [];
271008+
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
271003271009
pexp_loc = e.pexp_loc;
271010+
pexp_attributes = e.pexp_attributes;
271004271011
}
271005271012
| _ -> (
271006271013
match Ast_open_cxt.destruct fn [] with

lib/4.06.1/whole_compiler.ml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281241,7 +281241,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
281241281241
| _ -> None
281242281242

281243281243
let inner_ops = [ "##"; "#@" ]
281244-
281245281244
let infix_ops = [ "|."; "#="; "##" ]
281246281245

281247281246
let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
@@ -281281,16 +281280,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
281281281280
let fn = self.expr self fn in
281282281281
match fn.pexp_desc with
281283281282
| Pexp_variant (label, None) ->
281284-
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
281283+
{
281284+
fn with
281285+
pexp_desc = Pexp_variant (label, Some new_obj_arg);
281286+
pexp_loc = e.pexp_loc;
281287+
}
281285281288
| Pexp_construct (ctor, None) ->
281286-
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
281287-
| Pexp_apply (fn, args) ->
281289+
{
281290+
fn with
281291+
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
281292+
pexp_loc = e.pexp_loc;
281293+
}
281294+
| Pexp_apply (fn1, args) ->
281288281295
Bs_ast_invariant.warn_discarded_unused_attributes
281289-
fn.pexp_attributes;
281296+
fn1.pexp_attributes;
281290281297
{
281291-
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
281292-
pexp_attributes = [];
281298+
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
281293281299
pexp_loc = e.pexp_loc;
281300+
pexp_attributes = e.pexp_attributes;
281294281301
}
281295281302
| _ -> (
281296281303
match Ast_open_cxt.destruct fn [] with

0 commit comments

Comments
 (0)