Skip to content

Commit 4ef6668

Browse files
authored
fix reserved words (#6831)
* fix reserved words * allow more names that isn't related to CommonJS * add changelog * remove codegen script completely * use Hashtbl instead of Set
1 parent 63f3cd2 commit 4ef6668

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+412
-1961
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629
2727
- Drop Node.js version <18 support, due to it reaching End-of-Life. https://github.com/rescript-lang/rescript-compiler/pull/6429
2828
- Remove deprecated -bs-super-errors option. https://github.com/rescript-lang/rescript-compiler/pull/6814
29+
- Some global names and old keywords are no longer prefixed. https://github.com/rescript-lang/rescript-compiler/pull/6831
2930

3031
#### :bug: Bug Fix
3132

Diff for: CONTRIBUTING.md

-11
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,6 @@ To generate the html:
300300
../scripts/ninja docs
301301
```
302302

303-
## Update JS Reserved Keywords Map
304-
305-
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.
306-
307-
To update it, run:
308-
309-
```sh
310-
npm install puppeteer
311-
node scripts/build_reserved.js
312-
```
313-
314303
## Code structure
315304

316305
The highlevel architecture is illustrated as below:

Diff for: jscomp/ext/ext_ident.ml

+4-14
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
27-
28-
29-
30-
31-
3226
let js_flag = 0b1_000 (* check with ocaml compiler *)
3327

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

175-
(* TODO:
176-
check name conflicts with javascript conventions
177-
{[
178-
Ext_ident.convert "^";;
179-
- : string = "$caret"
180-
]}
181-
[convert name] if [name] is a js keyword,add "$$"
169+
(**
170+
[convert name] if [name] is a js keyword or js global, add "$$"
182171
otherwise do the name mangling to make sure ocaml identifier it is
183172
a valid js identifier
184173
*)
185174
let convert (name : string) =
186-
if Js_reserved_map.is_reserved name then
175+
let name = unwrap_uppercase_exotic name in
176+
if Js_reserved_map.is_js_keyword name || Js_reserved_map.is_js_global name then
187177
"$$" ^ name
188178
else name_mangle name
189179

0 commit comments

Comments
 (0)