Skip to content

Commit

Permalink
Fix unicode imports, unicode-escaped variable names, and printClauseA…
Browse files Browse the repository at this point in the history
…lias not working for utf-8 (#15009)
  • Loading branch information
pfgithub authored Nov 11, 2024
1 parent 62cabe9 commit 56f7c88
Show file tree
Hide file tree
Showing 28 changed files with 642 additions and 991 deletions.
10 changes: 8 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ If you see this error when compiling, run:
$ xcode-select --install
```

## Cannot find `libatomic.a`
### Cannot find `libatomic.a`

Bun defaults to linking `libatomic` statically, as not all systems have it. If you are building on a distro that does not have a static libatomic available, you can run the following command to enable dynamic linking:

Expand All @@ -295,11 +295,17 @@ $ bun run build -DUSE_STATIC_LIBATOMIC=OFF

The built version of Bun may not work on other systems if compiled this way.

## ccache conflicts with building TinyCC on macOS
### ccache conflicts with building TinyCC on macOS

If you run into issues with `ccache` when building TinyCC, try reinstalling ccache

```bash
brew uninstall ccache
brew install ccache
```

## Using bun-debug

- Disable logging: `BUN_DEBUG_QUIET_LOGS=1 bun-debug ...` (to disable all debug logging)
- Enable logging for a specific zig scope: `BUN_DEBUG_EventLoop=1 bun-debug ...` (to allow `std.log.scoped(.EventLoop)`)
- Bun transpiles every file it runs, to see the actual executed source in a debug build find it in `/tmp/bun-debug-src/...path/to/file`, for example the transpiled version of `/home/bun/index.ts` would be in `/tmp/bun-debug-src/home/bun/index.ts`
4 changes: 2 additions & 2 deletions src/StandaloneModuleGraph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ pub const StandaloneModuleGraph = struct {
if (item.data != .e_string)
return error.InvalidSourceMap;

const decoded = try item.data.e_string.stringDecodedUTF8(arena);
const decoded = try item.data.e_string.stringCloned(arena);

const offset = string_payload.items.len;
try string_payload.appendSlice(decoded);
Expand All @@ -1089,7 +1089,7 @@ pub const StandaloneModuleGraph = struct {
if (item.data != .e_string)
return error.InvalidSourceMap;

const utf8 = try item.data.e_string.stringDecodedUTF8(arena);
const utf8 = try item.data.e_string.stringCloned(arena);
defer arena.free(utf8);

const offset = string_payload.items.len;
Expand Down
2 changes: 1 addition & 1 deletion src/api/schema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2816,7 +2816,7 @@ pub const Api = struct {

fn expectString(this: *Parser, expr: js_ast.Expr) !void {
switch (expr.data) {
.e_string, .e_utf8_string => {},
.e_string => {},
else => {
this.log.addErrorFmt(this.source, expr.loc, this.allocator, "expected string but received {}", .{
@as(js_ast.Expr.Tag, expr.data),
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/module_loader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ pub const ModuleLoader = struct {
.specifier = input_specifier,
.source_url = input_specifier.createIfDifferent(path.text),
.hash = 0,
.jsvalue_for_export = parse_result.ast.parts.@"[0]"().stmts[0].data.s_expr.value.toJS(allocator, globalObject orelse jsc_vm.global, .{}) catch @panic("Unexpected JS error"),
.jsvalue_for_export = parse_result.ast.parts.@"[0]"().stmts[0].data.s_expr.value.toJS(allocator, globalObject orelse jsc_vm.global) catch @panic("Unexpected JS error"),
.tag = .exports_object,
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/bundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ pub const Bundler = struct {
},
// TODO: use lazy export AST
.text => {
const expr = js_ast.Expr.init(js_ast.E.UTF8String, js_ast.E.UTF8String{
const expr = js_ast.Expr.init(js_ast.E.String, js_ast.E.String{
.data = source.contents,
}, logger.Loc.Empty);
const stmt = js_ast.Stmt.alloc(js_ast.S.ExportDefault, js_ast.S.ExportDefault{
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/bundle_v2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3504,7 +3504,7 @@ pub const ParseTask = struct {
return JSAst.init((try js_parser.newLazyExportAST(allocator, bundler.options.define, opts, log, root, &source, "")).?);
},
.text => {
const root = Expr.init(E.UTF8String, E.UTF8String{
const root = Expr.init(E.String, E.String{
.data = source.contents,
}, Logger.Loc{ .start = 0 });
var ast = JSAst.init((try js_parser.newLazyExportAST(allocator, bundler.options.define, opts, log, root, &source, "")).?);
Expand Down
2 changes: 1 addition & 1 deletion src/bunfig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ pub const Bunfig = struct {

pub fn expectString(this: *Parser, expr: js_ast.Expr) !void {
switch (expr.data) {
.e_string, .e_utf8_string => {},
.e_string => {},
else => {
this.log.addErrorFmtOpts(
this.allocator,
Expand Down
19 changes: 0 additions & 19 deletions src/cli/run_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ pub const RunCommand = struct {
delimiter = 0;
},

// do we need to escape?
' ' => {
delimiter = ' ';
},
Expand Down Expand Up @@ -236,24 +235,6 @@ pub const RunCommand = struct {

delimiter = 0;
},
// TODO: handle escape sequences properly
// https://github.com/oven-sh/bun/issues/53
'\\' => {
delimiter = 0;

if (entry_i + 1 < script.len) {
switch (script[entry_i + 1]) {
'"', '\'' => {
entry_i += 1;
continue;
},
'\\' => {
entry_i += 1;
},
else => {},
}
}
},
else => {
delimiter = 0;
},
Expand Down
3 changes: 0 additions & 3 deletions src/feature_flags.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ pub const jsx_runtime_is_cjs = true;

pub const tracing = true;

/// Disabled due to bugs
pub const minify_javascript_string_length = false;

// TODO: remove this flag, it should use bun.Output.scoped
pub const verbose_watcher = false;

Expand Down
5 changes: 2 additions & 3 deletions src/ini.zig
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub const Parser = struct {
const c = val[i];
if (esc) {
switch (c) {
'\\' => try unesc.appendSlice(&[_]u8{ '\\', '\\' }),
'\\' => try unesc.appendSlice(&[_]u8{'\\'}),
';', '#', '$' => try unesc.append(c),
'.' => {
if (comptime usage == .section) {
Expand Down Expand Up @@ -636,7 +636,7 @@ pub const IniTestingAPIs = struct {
}
};

return parser.out.toJS(bun.default_allocator, globalThis, .{ .decode_escape_sequences = true }) catch |e| {
return parser.out.toJS(bun.default_allocator, globalThis) catch |e| {
globalThis.throwError(e, "failed to turn AST into JS");
return .undefined;
};
Expand All @@ -660,7 +660,6 @@ pub const ToStringFormatter = struct {
.e_number => try writer.print("{d}", .{this.d.e_number.value}),
.e_string => try writer.print("{s}", .{this.d.e_string.data}),
.e_null => try writer.print("null", .{}),
.e_utf8_string => try writer.print("{s}", .{this.d.e_utf8_string.data}),

else => |tag| if (bun.Environment.isDebug) {
Output.panic("Unexpected AST node: {s}", .{@tagName(tag)});
Expand Down
4 changes: 0 additions & 4 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,6 @@ pub const PackageManager = struct {

pub const GetJSONOptions = struct {
init_reset_store: bool = true,
always_decode_escape_sequences: bool = true,
guess_indentation: bool = false,
};

Expand Down Expand Up @@ -2840,7 +2839,6 @@ pub const PackageManager = struct {
.is_json = true,
.allow_comments = true,
.allow_trailing_commas = true,
.always_decode_escape_sequences = opts.always_decode_escape_sequences,
.guess_indentation = opts.guess_indentation,
},
) catch |err| {
Expand Down Expand Up @@ -2894,7 +2892,6 @@ pub const PackageManager = struct {
.is_json = true,
.allow_comments = true,
.allow_trailing_commas = true,
.always_decode_escape_sequences = opts.always_decode_escape_sequences,
.guess_indentation = opts.guess_indentation,
},
);
Expand Down Expand Up @@ -10412,7 +10409,6 @@ pub const PackageManager = struct {
manager.log,
manager.original_package_json_path,
.{
.always_decode_escape_sequences = false,
.guess_indentation = true,
},
)) {
Expand Down
Loading

0 comments on commit 56f7c88

Please sign in to comment.