Skip to content

fix reserved words #6831

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 5 commits into from
Jun 29, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629
- Drop Node.js version <18 support, due to it reaching End-of-Life. https://github.com/rescript-lang/rescript-compiler/pull/6429
- Remove deprecated -bs-super-errors option. https://github.com/rescript-lang/rescript-compiler/pull/6814
- Some global names and old keywords are no longer prefixed. https://github.com/rescript-lang/rescript-compiler/pull/6831

#### :bug: Bug Fix

Expand Down
11 changes: 0 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,6 @@ To generate the html:
../scripts/ninja docs
```

## Update JS Reserved Keywords Map

The compiler sources include a list of reserved JS keywords in `jscomp/ext/js_reserved_map.ml` which includes all identifiers in global scope (`window`). This list should be updated from time to time for newer browser versions.

To update it, run:

```sh
npm install puppeteer
node scripts/build_reserved.js
```

## Code structure

The highlevel architecture is illustrated as below:
Expand Down
18 changes: 4 additions & 14 deletions jscomp/ext/ext_ident.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)








let js_flag = 0b1_000 (* check with ocaml compiler *)

(* let js_module_flag = 0b10_000 (\* javascript external modules *\) *)
Expand Down Expand Up @@ -172,18 +166,14 @@ let name_mangle name =
Ext_buffer.add_string buffer (convert ~op:(i=0) c)
done; Ext_buffer.contents buffer

(* TODO:
check name conflicts with javascript conventions
{[
Ext_ident.convert "^";;
- : string = "$caret"
]}
[convert name] if [name] is a js keyword,add "$$"
(**
[convert name] if [name] is a js keyword or js global, add "$$"
otherwise do the name mangling to make sure ocaml identifier it is
a valid js identifier
*)
let convert (name : string) =
if Js_reserved_map.is_reserved name then
let name = unwrap_uppercase_exotic name in
if Js_reserved_map.is_js_keyword name || Js_reserved_map.is_js_global name then
"$$" ^ name
else name_mangle name

Expand Down
Loading