Skip to content

Fix issue where pipe "->" processing eats up attributes. #5581

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

Merged
merged 2 commits into from
Jul 23, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
- Initial support for JSX V4, still work in progress.
- :boom: when V4 is activated, at most one component is allowed for each module.

#### :bug: Bug Fix

- Fix issue where pipe `->` processing eats up attributes https://github.com/rescript-lang/rescript-compiler/pull/5581

#### :nail_care: Polish

- Print patterns in warnings using rescript printer https://github.com/rescript-lang/rescript-compiler/pull/5492
Expand Down
21 changes: 14 additions & 7 deletions jscomp/frontend/ast_exp_apply.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
| _ -> None

let inner_ops = [ "##"; "#@" ]

let infix_ops = [ "|."; "#="; "##" ]

let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
Expand Down Expand Up @@ -110,16 +109,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
let fn = self.expr self fn in
match fn.pexp_desc with
| Pexp_variant (label, None) ->
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
{
fn with
pexp_desc = Pexp_variant (label, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_construct (ctor, None) ->
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
| Pexp_apply (fn, args) ->
{
fn with
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_apply (fn1, args) ->
Bs_ast_invariant.warn_discarded_unused_attributes
fn.pexp_attributes;
fn1.pexp_attributes;
{
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
pexp_attributes = [];
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
pexp_loc = e.pexp_loc;
pexp_attributes = e.pexp_attributes;
}
| _ -> (
match Ast_open_cxt.destruct fn [] with
Expand Down
31 changes: 31 additions & 0 deletions jscomp/test/res_debug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var Curry = require("../../lib/js/curry.js");
var Caml_obj = require("../../lib/js/caml_obj.js");
var Caml_option = require("../../lib/js/caml_option.js");

function f($$window, a, b) {
return $$window.location(a, b);
Expand All @@ -24,6 +26,29 @@ function testMatch(v) {
}
}

function optionMap(x, f) {
if (x !== undefined) {
return Caml_option.some(Curry._1(f, Caml_option.valFromOption(x)));
}

}

var ok_name = optionMap(undefined, (function (x) {
return x;
}));

var ok = {
name: ok_name
};

var bad_name = optionMap(undefined, (function (x) {
return x;
}));

var bad = {
name: bad_name
};

var v2 = newrecord;

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

var hey = "hello, 世界";

var name;

exports.f = f;
exports.v0 = v0;
exports.v2 = v2;
exports.v1 = v1;
exports.testMatch = testMatch;
exports.h = h;
exports.hey = hey;
exports.optionMap = optionMap;
exports.name = name;
exports.ok = ok;
exports.bad = bad;
/* Not a pure module */
13 changes: 13 additions & 0 deletions jscomp/test/res_debug.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,16 @@ let testMatch = v =>
let h = '😊'
let hey = "hello, 世界"
// failed to type check

let optionMap = (x, f) =>
switch x {
| None => None
| Some(v) => Some(f(v))
}

type props<'name> = {key?: string, name?: string}

let name = None

let ok = {name: ?optionMap(name, x => x)}
let bad = {name: ?name->optionMap(x => x)}
21 changes: 14 additions & 7 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -269488,7 +269488,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
| _ -> None

let inner_ops = [ "##"; "#@" ]

let infix_ops = [ "|."; "#="; "##" ]

let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
Expand Down Expand Up @@ -269528,16 +269527,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
let fn = self.expr self fn in
match fn.pexp_desc with
| Pexp_variant (label, None) ->
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
{
fn with
pexp_desc = Pexp_variant (label, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_construct (ctor, None) ->
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
| Pexp_apply (fn, args) ->
{
fn with
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_apply (fn1, args) ->
Bs_ast_invariant.warn_discarded_unused_attributes
fn.pexp_attributes;
fn1.pexp_attributes;
{
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
pexp_attributes = [];
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
pexp_loc = e.pexp_loc;
pexp_attributes = e.pexp_attributes;
}
| _ -> (
match Ast_open_cxt.destruct fn [] with
Expand Down
21 changes: 14 additions & 7 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -270951,7 +270951,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
| _ -> None

let inner_ops = [ "##"; "#@" ]

let infix_ops = [ "|."; "#="; "##" ]

let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
Expand Down Expand Up @@ -270991,16 +270990,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
let fn = self.expr self fn in
match fn.pexp_desc with
| Pexp_variant (label, None) ->
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
{
fn with
pexp_desc = Pexp_variant (label, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_construct (ctor, None) ->
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
| Pexp_apply (fn, args) ->
{
fn with
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_apply (fn1, args) ->
Bs_ast_invariant.warn_discarded_unused_attributes
fn.pexp_attributes;
fn1.pexp_attributes;
{
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
pexp_attributes = [];
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
pexp_loc = e.pexp_loc;
pexp_attributes = e.pexp_attributes;
}
| _ -> (
match Ast_open_cxt.destruct fn [] with
Expand Down
21 changes: 14 additions & 7 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -281241,7 +281241,6 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
| _ -> None

let inner_ops = [ "##"; "#@" ]

let infix_ops = [ "|."; "#="; "##" ]

let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
Expand Down Expand Up @@ -281281,16 +281280,24 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
let fn = self.expr self fn in
match fn.pexp_desc with
| Pexp_variant (label, None) ->
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
{
fn with
pexp_desc = Pexp_variant (label, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_construct (ctor, None) ->
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
| Pexp_apply (fn, args) ->
{
fn with
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
pexp_loc = e.pexp_loc;
}
| Pexp_apply (fn1, args) ->
Bs_ast_invariant.warn_discarded_unused_attributes
fn.pexp_attributes;
fn1.pexp_attributes;
{
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
pexp_attributes = [];
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
pexp_loc = e.pexp_loc;
pexp_attributes = e.pexp_attributes;
}
| _ -> (
match Ast_open_cxt.destruct fn [] with
Expand Down