diff options
author | 2022-02-27 04:14:55 -0800 | |
---|---|---|
committer | 2022-02-27 04:14:55 -0800 | |
commit | 0a86a4ea80f9cab08c78ef24c932a4f366943a87 (patch) | |
tree | 6f10fe79f6014edd8657c3c545deab040858160a | |
parent | d91e8974130735fd43cd9c37d6147fe20f6b3290 (diff) | |
download | bun-0a86a4ea80f9cab08c78ef24c932a4f366943a87.tar.gz bun-0a86a4ea80f9cab08c78ef24c932a4f366943a87.tar.zst bun-0a86a4ea80f9cab08c78ef24c932a4f366943a87.zip |
Fix https://github.com/Jarred-Sumner/bun/issues/115
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | integration/apps/bun-install-utf8.sh | 14 | ||||
-rw-r--r-- | src/js_lexer.zig | 5 | ||||
-rw-r--r-- | src/json_parser.zig | 28 |
4 files changed, 34 insertions, 17 deletions
@@ -639,7 +639,7 @@ release-bin-dir: echo $(PACKAGE_DIR) dev-obj: - $(ZIG) build obj + $(ZIG) build obj --prominent-compile-errors dev-obj-linux: $(ZIG) build obj -Dtarget=x86_64-linux-gnu @@ -682,12 +682,14 @@ test-bun-run: test-bun-install: test-bun-install-git-status cd integration/apps && JS_RUNTIME=$(RELEASE_BUN) NPM_CLIENT=$(RELEASE_BUN) bash ./bun-install.sh + cd integration/apps && BUN_BIN=$(RELEASE_BUN) bash ./bun-install-utf8.sh test-bun-install-git-status: cd integration/apps && JS_RUNTIME=$(RELEASE_BUN) BUN_BIN=$(RELEASE_BUN) bash ./bun-install-lockfile-status.sh test-dev-bun-install: test-dev-bun-install-git-status cd integration/apps && JS_RUNTIME=$(DEBUG_BUN) NPM_CLIENT=$(DEBUG_BUN) bash ./bun-install.sh + cd integration/apps && BUN_BIN=$(DEBUG_BUN) bash ./bun-install-utf8.sh test-dev-bun-install-git-status: cd integration/apps && BUN_BIN=$(DEBUG_BUN) bash ./bun-install-lockfile-status.sh diff --git a/integration/apps/bun-install-utf8.sh b/integration/apps/bun-install-utf8.sh new file mode 100644 index 000000000..6a00af817 --- /dev/null +++ b/integration/apps/bun-install-utf8.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -euo pipefail + +killall -9 $(basename $BUN_BIN) || echo "" + +dir=$(mktemp -d --suffix=bun-ADD) + +cd $dir + +# https://github.com/Jarred-Sumner/bun/issues/115 +echo '{ "author": "Arnuad Barré (https://github.com/ArnaudBarre)" }' >package.json + +$BUN_BIN add react diff --git a/src/js_lexer.zig b/src/js_lexer.zig index 4febdfdfa..f0c997e67 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -401,11 +401,6 @@ fn NewLexer_( }, // 2-digit hexadecimal 'x' => { - if (comptime is_json) { - lexer.end = start + iter.i - width2; - try lexer.syntaxError(); - } - var value: CodePoint = 0; var c3: CodePoint = 0; var width3: u3 = 0; diff --git a/src/json_parser.zig b/src/json_parser.zig index be304d8fd..e9ec0226b 100644 --- a/src/json_parser.zig +++ b/src/json_parser.zig @@ -114,7 +114,7 @@ fn JSONLikeParser(opts: js_lexer.JSONOptions) type { return Expr.init(Type, t, loc); } } - pub fn parseExpr(p: *Parser, comptime maybe_auto_quote: bool) anyerror!Expr { + pub fn parseExpr(p: *Parser, comptime maybe_auto_quote: bool, force_utf8: bool) anyerror!Expr { const loc = p.lexer.loc(); switch (p.lexer.token) { @@ -136,6 +136,12 @@ fn JSONLikeParser(opts: js_lexer.JSONOptions) type { }, .t_string_literal => { var str: E.String = p.lexer.toEString(); + if (comptime force_utf8) { + if (str.value.len > 0) { + str.utf8 = p.lexer.utf16ToString(str.value); + str.value = &[_]u16{}; + } + } try p.lexer.next(); return p.e(str, loc); @@ -171,7 +177,7 @@ fn JSONLikeParser(opts: js_lexer.JSONOptions) type { } } - exprs.append(try p.parseExpr(false)) catch unreachable; + exprs.append(try p.parseExpr(false, force_utf8)) catch unreachable; } if (p.lexer.has_newline_before) { @@ -240,7 +246,7 @@ fn JSONLikeParser(opts: js_lexer.JSONOptions) type { try p.lexer.expect(.t_string_literal); try p.lexer.expect(.t_colon); - const value = try p.parseExpr(false); + const value = try p.parseExpr(false, force_utf8); properties.append(G.Property{ .key = key, .value = value }) catch unreachable; } @@ -258,7 +264,7 @@ fn JSONLikeParser(opts: js_lexer.JSONOptions) type { if (comptime maybe_auto_quote) { p.lexer = try Lexer.initJSON(p.log, p.source().*, p.allocator); try p.lexer.parseStringLiteral(0); - return p.parseExpr(false); + return p.parseExpr(false, force_utf8); } try p.lexer.unexpected(); @@ -679,7 +685,7 @@ pub fn ParseJSON(source: *const logger.Source, log: *logger.Log, allocator: std. else => {}, } - return try parser.parseExpr(false); + return try parser.parseExpr(false, true); } pub fn ParseJSONForMacro(source: *const logger.Source, log: *logger.Log, allocator: std.mem.Allocator) !Expr { @@ -702,7 +708,7 @@ pub fn ParseJSONForMacro(source: *const logger.Source, log: *logger.Log, allocat else => {}, } - return try parser.parseExpr(false); + return try parser.parseExpr(false, true); } pub const JSONParseResult = struct { @@ -736,7 +742,7 @@ pub fn ParseJSONForBundling(source: *const logger.Source, log: *logger.Log, allo else => {}, } - const result = try parser.parseExpr(false); + const result = try parser.parseExpr(false, true); return JSONParseResult{ .tag = if (!LEXER_DEBUGGER_WORKAROUND and parser.lexer.is_ascii_only) JSONParseResult.Tag.ascii else JSONParseResult.Tag.expr, .expr = result, @@ -767,7 +773,7 @@ pub fn ParseEnvJSON(source: *const logger.Source, log: *logger.Log, allocator: s switch (source.contents[0]) { '{', '[', '0'...'9', '"', '\'' => { - return try parser.parseExpr(false); + return try parser.parseExpr(false, false); }, else => { switch (parser.lexer.token) { @@ -785,10 +791,10 @@ pub fn ParseEnvJSON(source: *const logger.Source, log: *logger.Log, allocator: s return Expr{ .loc = logger.Loc{ .start = 0 }, .data = .{ .e_undefined = E.Undefined{} } }; } - return try parser.parseExpr(true); + return try parser.parseExpr(true, false); }, else => { - return try parser.parseExpr(true); + return try parser.parseExpr(true, false); }, } }, @@ -816,7 +822,7 @@ pub fn ParseTSConfig(source: *const logger.Source, log: *logger.Log, allocator: var parser = try TSConfigParser.init(allocator, source.*, log); - return parser.parseExpr(false); + return parser.parseExpr(false, true); } const duplicateKeyJson = "{ \"name\": \"valid\", \"name\": \"invalid\" }"; |