diff options
author | 2021-12-15 15:15:54 -0800 | |
---|---|---|
committer | 2021-12-15 17:08:04 -0800 | |
commit | e10fe8aaad81e7bd958244adb8584107d7aef18e (patch) | |
tree | d92fad573ff98e6a60c379cf5040626ee88cbc63 /src | |
parent | feb45edf6d9e33d55e89f5dbca9758bce010b14a (diff) | |
download | bun-e10fe8aaad81e7bd958244adb8584107d7aef18e.tar.gz bun-e10fe8aaad81e7bd958244adb8584107d7aef18e.tar.zst bun-e10fe8aaad81e7bd958244adb8584107d7aef18e.zip |
[JS transpiler] Ensure reserved words don't end up in nonUniqueIdentifier()
Diffstat (limited to 'src')
-rw-r--r-- | src/js_lexer_tables.zig | 12 | ||||
-rw-r--r-- | src/string_mutable.zig | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/js_lexer_tables.zig b/src/js_lexer_tables.zig index 78dd2cf15..b594fbc2e 100644 --- a/src/js_lexer_tables.zig +++ b/src/js_lexer_tables.zig @@ -203,6 +203,18 @@ pub const StrictModeReservedWords = std.ComptimeStringMap(bool, .{ .{ "yield", true }, }); +pub const StrictModeReservedWordsRemap = std.ComptimeStringMap(string, .{ + .{ "implements", "_implements" }, + .{ "interface", "_interface" }, + .{ "let", "_let" }, + .{ "package", "_package" }, + .{ "private", "_private" }, + .{ "protected", "_protected" }, + .{ "public", "_public" }, + .{ "static", "_static" }, + .{ "yield", "_yield" }, +}); + pub const PropertyModifierKeyword = enum { p_abstract, p_async, diff --git a/src/string_mutable.zig b/src/string_mutable.zig index b8084dd50..5dc153c99 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -63,6 +63,8 @@ pub const MutableString = struct { if (!iterator.next(&cursor)) return "_"; + const JSLexerTables = @import("./js_lexer_tables.zig"); + // Common case: no gap necessary. No allocation necessary. needs_gap = !js_lexer.isIdentifierStart(cursor.c); if (!needs_gap) { @@ -76,6 +78,10 @@ pub const MutableString = struct { } } + if (!needs_gap and str.len >= 3 and str.len <= 10) { + return JSLexerTables.StrictModeReservedWordsRemap.get(str) orelse str; + } + if (needs_gap) { var mutable = try MutableString.initCopy(allocator, str[0..start_i]); needs_gap = false; |