diff options
author | 2021-08-17 15:25:36 -0700 | |
---|---|---|
committer | 2021-08-17 15:25:36 -0700 | |
commit | 3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a (patch) | |
tree | 48a0aa9e2d8c099e381332e3be5d23da61e7e371 /src | |
parent | ae01e9b98d481332236976344fa0386bafa82f53 (diff) | |
download | bun-3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a.tar.gz bun-3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a.tar.zst bun-3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a.zip |
fix jsx
Former-commit-id: a9bfcbce261798cdd0c3f8cb09076dc246920b48
Diffstat (limited to 'src')
-rw-r--r-- | src/js_parser/js_parser.zig | 30 | ||||
-rw-r--r-- | src/resolver/package_json.zig | 25 | ||||
-rw-r--r-- | src/runtime.version | 2 | ||||
-rw-r--r-- | src/runtime/hmr.ts | 1 |
4 files changed, 41 insertions, 17 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index 4d6189cbc..78ab4feb3 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -10484,7 +10484,7 @@ pub fn NewParser( } } - const runtime = if (p.options.jsx.runtime == .automatic and !e_.flags.is_key_before_rest) options.JSX.Runtime.automatic else options.JSX.Runtime.classic; + const runtime = if (e_.tag != null and p.options.jsx.runtime == .automatic and !e_.flags.is_key_before_rest) options.JSX.Runtime.automatic else options.JSX.Runtime.classic; var children_count = e_.children.len; const is_childless_tag = FeatureFlags.react_specific_warnings and children_count > 0 and tag.data == .e_string and tag.data.e_string.isUTF8() and js_lexer.ChildlessJSXTags.has(tag.data.e_string.utf8); @@ -10546,18 +10546,22 @@ pub fn NewParser( // children: [] // } - if (children_count > 0) { - for (e_.children[0..children_count]) |child, i| { - e_.children[i] = p.visitExpr(child); - } - const children_key = Expr{ .data = jsxChildrenKeyData, .loc = expr.loc }; - props.append(G.Property{ - .key = children_key, - .value = p.e(E.Array{ - .items = e_.children, - .is_single_line = e_.children.len < 2, - }, expr.loc), - }) catch unreachable; + switch (children_count) { + 0 => {}, + + else => { + for (e_.children[0..children_count]) |child, i| { + e_.children[i] = p.visitExpr(child); + } + const children_key = Expr{ .data = jsxChildrenKeyData, .loc = expr.loc }; + props.append(G.Property{ + .key = children_key, + .value = p.e(E.Array{ + .items = e_.children, + .is_single_line = e_.children.len < 2, + }, expr.loc), + }) catch unreachable; + }, } args[1] = p.e(E.Object{ diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 5a6c2f5b0..f2a569de5 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -21,6 +21,25 @@ pub const PackageJSON = struct { production, }; + const node_modules_path = std.fs.path.sep_str ++ "node_modules" ++ std.fs.path.sep_str; + pub fn nameForImport(this: *const PackageJSON, allocator: *std.mem.Allocator) !string { + if (strings.indexOf(this.source.path.text, node_modules_path)) |_| { + return this.name; + } else { + const parent = this.source.path.name.dirWithTrailingSlash(); + if (strings.indexOf(parent, fs.FileSystem.instance.top_level_dir)) |i| { + const relative_dir = parent[i + fs.FileSystem.instance.top_level_dir.len ..]; + var out_dir = try allocator.alloc(u8, relative_dir.len + 2); + std.mem.copy(u8, out_dir[2..], relative_dir); + out_dir[0] = '.'; + out_dir[1] = '/'; + return out_dir; + } + + return this.name; + } + } + pub const FrameworkRouterPair = struct { framework: *options.Framework, router: *options.RouteConfig, @@ -284,7 +303,7 @@ pub const PackageJSON = struct { .development => { if (framework_object.expr.asProperty("development")) |env| { if (loadFrameworkExpression(pair.framework, env.expr, allocator, read_defines)) { - pair.framework.package = package_json.name; + pair.framework.package = package_json.nameForImport(allocator) catch unreachable; pair.framework.development = true; if (env.expr.asProperty("static")) |static_prop| { if (static_prop.expr.asString(allocator)) |str| { @@ -302,7 +321,7 @@ pub const PackageJSON = struct { .production => { if (framework_object.expr.asProperty("production")) |env| { if (loadFrameworkExpression(pair.framework, env.expr, allocator, read_defines)) { - pair.framework.package = package_json.name; + pair.framework.package = package_json.nameForImport(allocator) catch unreachable; pair.framework.development = false; if (env.expr.asProperty("static")) |static_prop| { @@ -322,7 +341,7 @@ pub const PackageJSON = struct { } if (loadFrameworkExpression(pair.framework, framework_object.expr, allocator, read_defines)) { - pair.framework.package = package_json.name; + pair.framework.package = package_json.nameForImport(allocator) catch unreachable; pair.framework.development = false; } } diff --git a/src/runtime.version b/src/runtime.version index fac0eba4e..dd9a0085a 100644 --- a/src/runtime.version +++ b/src/runtime.version @@ -1 +1 @@ -def44909172594cf
\ No newline at end of file +ef1f71fecb089b94
\ No newline at end of file diff --git a/src/runtime/hmr.ts b/src/runtime/hmr.ts index 99cdf634a..10f7e4a5d 100644 --- a/src/runtime/hmr.ts +++ b/src/runtime/hmr.ts @@ -629,6 +629,7 @@ if (typeof window !== "undefined") { // If so, it will use it. // Else, it will fall back to live reloading. case API.Loader.js: + case API.Loader.jsx: case API.Loader.json: case API.Loader.ts: case API.Loader.tsx: { |