Skip to content

Handle escape sequences correctly in @as. #5402

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

Closed
cristianoc opened this issue May 31, 2022 · 1 comment
Closed

Handle escape sequences correctly in @as. #5402

cristianoc opened this issue May 31, 2022 · 1 comment
Milestone

Comments

@cristianoc
Copy link
Collaborator

Context: #5401

@cknitt
Copy link
Member

cknitt commented May 31, 2022

See the difference in the way the string "\h\e\l\lo" is compiled:

external f: (@as("\h\e\l\lo") _, int) => unit = "f"

let x = "\h\e\l\lo"
let y = f(42)

compiles to

// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';


f("\\h\\e\\l\\lo", 42);

var x = "\h\e\l\lo";

var y;

exports.x = x;
exports.y = y;
/*  Not a pure module */

I.e. when used in an attribute, the backslashes are duplicated.

(see also #5391)

@cristianoc cristianoc changed the title Figure out whatfigure out what "but there was still an unresolved issue when the string contained an escape character" means.. Handle escape sequences correctly in @as. Jun 1, 2022
@cknitt cknitt added this to the v10.0 milestone Jun 9, 2022
cristianoc added a commit that referenced this issue Jun 19, 2022
mununki pushed a commit to mununki/rescript-compiler that referenced this issue Jul 15, 2022
…ang#5446)

* emit str

* Hack timestamps to get around tree-sitter failing on M1.

1) change files by hand
2) touch js_fold.ml js_record_iter.ml js_record_map.ml js_record_fold.ml

* Do not escape strings in @bs.as on externals.

Fixes rescript-lang#5402

* Hack the timestamp by doing a dummy modification.

* Comments in code.

* An alternative solution that requires fewer changes.

* Remove changes to Str.

* Restore original files.

* More restore files.

* Comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants