aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js_ast.zig8
-rw-r--r--src/js_parser.zig24
2 files changed, 32 insertions, 0 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 9ec14e158..8ae652bb9 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -2140,6 +2140,14 @@ pub const E = struct {
rope_len: u32 = 0,
is_utf16: bool = false,
+ pub fn isIdentifier(this: *String, allocator: std.mem.Allocator) bool {
+ if (!this.isUTF8()) {
+ return bun.js_lexer.isIdentifierUTF16(this.slice16());
+ }
+
+ return bun.js_lexer.isIdentifier(this.slice(allocator));
+ }
+
pub var class = E.String{ .data = "class" };
pub fn push(this: *String, other: *String) void {
std.debug.assert(this.isUTF8());
diff --git a/src/js_parser.zig b/src/js_parser.zig
index 2d84fc0c0..5729efa39 100644
--- a/src/js_parser.zig
+++ b/src/js_parser.zig
@@ -15900,6 +15900,30 @@ fn NewParser_(
const is_call_target = std.meta.activeTag(p.call_target) == .e_index and expr.data.e_index == p.call_target.e_index;
const is_delete_target = std.meta.activeTag(p.delete_target) == .e_index and expr.data.e_index == p.delete_target.e_index;
+ if (p.options.features.minify_syntax) {
+ if (e_.index.data == .e_string and e_.index.data.e_string.isUTF8() and e_.index.data.e_string.isIdentifier(p.allocator)) {
+ const dot = p.newExpr(
+ E.Dot{
+ .name = e_.index.data.e_string.slice(p.allocator),
+ .name_loc = e_.index.loc,
+ .target = e_.target,
+ .optional_chain = e_.optional_chain,
+ },
+ expr.loc,
+ );
+
+ if (is_call_target) {
+ p.call_target = dot.data;
+ }
+
+ if (is_delete_target) {
+ p.delete_target = dot.data;
+ }
+
+ return p.visitExprInOut(dot, in);
+ }
+ }
+
const target = p.visitExprInOut(e_.target, ExprIn{
// this is awkward due to a zig compiler bug
.has_chain_parent = (e_.optional_chain orelse js_ast.OptionalChain.start) == js_ast.OptionalChain.ccontinue,