aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-17 15:25:36 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-17 15:25:36 -0700
commit3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a (patch)
tree48a0aa9e2d8c099e381332e3be5d23da61e7e371
parentae01e9b98d481332236976344fa0386bafa82f53 (diff)
downloadbun-3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a.tar.gz
bun-3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a.tar.zst
bun-3b6259edf33933be61ed0e8cdb2ff3dc2ae3a56a.zip
fix jsx
Former-commit-id: a9bfcbce261798cdd0c3f8cb09076dc246920b48
-rw-r--r--demos/hello-next/pages/index.js18
-rw-r--r--src/js_parser/js_parser.zig30
-rw-r--r--src/resolver/package_json.zig25
-rw-r--r--src/runtime.version2
-rw-r--r--src/runtime/hmr.ts1
5 files changed, 49 insertions, 27 deletions
diff --git a/demos/hello-next/pages/index.js b/demos/hello-next/pages/index.js
index 4db0d5ae6..209701990 100644
--- a/demos/hello-next/pages/index.js
+++ b/demos/hello-next/pages/index.js
@@ -1,12 +1,13 @@
import Head from "next/head";
import Image from "next/image";
import styles from "../styles/Home.module.css";
+import Link from "next/link";
export default function Home() {
return (
<div className={styles.container}>
<Head>
- <title>Create Next App</title>
+ <title>Create Next Ap123p</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
@@ -31,15 +32,12 @@ export default function Home() {
<h2>Learn &rarr;</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
-
- <a
- href="https://github.com/vercel/next.js/tree/master/examples"
- className={styles.card}
- >
- <h2>Examples &rarr;</h2>
- <p>Discover and deploy boilerplate example Next.js projects.</p>
- </a>
-
+ <Link href="/hi">
+ <a className={styles.card}>
+ <h2>Examples &rarr;</h2>
+ <p>Discover and deploy boilerplate example Next.js projects.</p>
+ </a>
+ </Link>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
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: {