aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--integration/snapshots/array-args-with-default-values.hmr.js6
-rw-r--r--integration/snapshots/bundled-entry-point.hmr.js10
-rw-r--r--integration/snapshots/caught-require.hmr.debug.js6
-rw-r--r--integration/snapshots/caught-require.hmr.js8
-rw-r--r--integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js16
-rw-r--r--integration/snapshots/code-simplification-neql-define.hmr.js6
-rw-r--r--integration/snapshots/custom-emotion-jsx/file.hmr.debug.jsx9
-rw-r--r--integration/snapshots/custom-emotion-jsx/file.hmr.jsx12
-rw-r--r--integration/snapshots/export.hmr.js18
-rw-r--r--integration/snapshots/forbid-in-is-correct.hmr.js6
-rw-r--r--integration/snapshots/global-is-remapped-to-globalThis.hmr.js6
-rw-r--r--integration/snapshots/jsx-entities.hmr.debug.jsx9
-rw-r--r--integration/snapshots/jsx-entities.hmr.jsx14
-rw-r--r--integration/snapshots/jsx-spacing.hmr.debug.jsx9
-rw-r--r--integration/snapshots/jsx-spacing.hmr.jsx12
-rw-r--r--integration/snapshots/latin1-chars-in-regexp.hmr.debug.js4
-rw-r--r--integration/snapshots/latin1-chars-in-regexp.hmr.js6
-rw-r--r--integration/snapshots/lodash-regexp.hmr.js10
-rw-r--r--integration/snapshots/multiple-imports.hmr.js12
-rw-r--r--integration/snapshots/number-literal-bug.hmr.debug.js4
-rw-r--r--integration/snapshots/number-literal-bug.hmr.js6
-rw-r--r--integration/snapshots/optional-chain-with-function.hmr.debug.js4
-rw-r--r--integration/snapshots/optional-chain-with-function.hmr.js6
-rw-r--r--integration/snapshots/package-json-exports/index.hmr.js16
-rw-r--r--integration/snapshots/react-context-value-func.hmr.debug.tsx9
-rw-r--r--integration/snapshots/react-context-value-func.hmr.tsx12
-rw-r--r--integration/snapshots/spread_with_key.hmr.tsx12
-rw-r--r--integration/snapshots/string-escapes.hmr.js12
-rw-r--r--integration/snapshots/styledcomponents-output.hmr.debug.js9
-rw-r--r--integration/snapshots/styledcomponents-output.hmr.js16
-rw-r--r--integration/snapshots/template-literal.hmr.debug.js4
-rw-r--r--integration/snapshots/template-literal.hmr.js6
-rw-r--r--integration/snapshots/ts-fallback-rewrite-works.hmr.js6
-rw-r--r--integration/snapshots/tsx-fallback-rewrite-works.hmr.js6
-rw-r--r--integration/snapshots/type-only-imports.hmr.ts6
-rw-r--r--integration/snapshots/unicode-identifiers.hmr.js6
-rw-r--r--integration/snapshots/void-shouldnt-delete-call-expressions.hmr.debug.js4
-rw-r--r--integration/snapshots/void-shouldnt-delete-call-expressions.hmr.js6
-rw-r--r--src/bundler.zig6
-rw-r--r--src/bunfig.zig14
-rw-r--r--src/cli/create_command.zig65
-rw-r--r--src/install/install.zig27
-rw-r--r--src/install/npm.zig34
-rw-r--r--src/js_ast.zig219
-rw-r--r--src/js_parser/js_parser.zig137
-rw-r--r--src/js_printer.zig31
-rw-r--r--src/json_parser.zig6
-rw-r--r--src/resolver/package_json.zig31
-rw-r--r--src/resolver/tsconfig_json.zig10
49 files changed, 513 insertions, 396 deletions
diff --git a/integration/snapshots/array-args-with-default-values.hmr.js b/integration/snapshots/array-args-with-default-values.hmr.js
index 7cf643b9d..467ccd733 100644
--- a/integration/snapshots/array-args-with-default-values.hmr.js
+++ b/integration/snapshots/array-args-with-default-values.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(3474597122, "array-args-with-default-values.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/bundled-entry-point.hmr.js b/integration/snapshots/bundled-entry-point.hmr.js
index 45e9f0dba..30a619535 100644
--- a/integration/snapshots/bundled-entry-point.hmr.js
+++ b/integration/snapshots/bundled-entry-point.hmr.js
@@ -1,14 +1,14 @@
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+import * as $bbcd215f from "http://localhost:3000/node_modules/react/index.js";
+Bun.activate(true);
var hmr = new HMR(3012834585, "bundled-entry-point.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/caught-require.hmr.debug.js b/integration/snapshots/caught-require.hmr.debug.js
index 2cd9f386d..7144220d8 100644
--- a/integration/snapshots/caught-require.hmr.debug.js
+++ b/integration/snapshots/caught-require.hmr.debug.js
@@ -1,12 +1,12 @@
import {
__require as require
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
Bun.activate(true);
var hmr = new HMR(2398506918, "caught-require.js"), exports = hmr.exports;
diff --git a/integration/snapshots/caught-require.hmr.js b/integration/snapshots/caught-require.hmr.js
index 3c604d74d..57f98636c 100644
--- a/integration/snapshots/caught-require.hmr.js
+++ b/integration/snapshots/caught-require.hmr.js
@@ -1,13 +1,13 @@
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(2398506918, "caught-require.js"), exports = hmr.exports;
await (hmr._load = async function() {
diff --git a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js
index 4934b46b9..289262c1e 100644
--- a/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js
+++ b/integration/snapshots/cjs-transform-shouldnt-have-static-imports-in-cjs-function.hmr.js
@@ -1,15 +1,15 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-import _login from "http://localhost:8080/_login.js";
-import _auth from "http://localhost:8080/_auth.js";
-import * as _loginReally from "http://localhost:8080/_login.js";
-import * as _loginReally2 from "http://localhost:8080/_login.js";
-import * as _authReally from "http://localhost:8080/_auth.js";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+import _login from "http://localhost:3000/_login.js";
+import _auth from "http://localhost:3000/_auth.js";
+import * as _loginReally from "http://localhost:3000/_login.js";
+import * as _loginReally2 from "http://localhost:3000/_login.js";
+import * as _authReally from "http://localhost:3000/_auth.js";
+Bun.activate(true);
var hmr = new HMR(3878252498, "cjs-transform-shouldnt-have-static-imports-in-cjs-function.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/code-simplification-neql-define.hmr.js b/integration/snapshots/code-simplification-neql-define.hmr.js
index 64a03dda4..c1523ee6e 100644
--- a/integration/snapshots/code-simplification-neql-define.hmr.js
+++ b/integration/snapshots/code-simplification-neql-define.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(726376257, "code-simplification-neql-define.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/custom-emotion-jsx/file.hmr.debug.jsx b/integration/snapshots/custom-emotion-jsx/file.hmr.debug.jsx
index bd299b2a8..896bd2e93 100644
--- a/integration/snapshots/custom-emotion-jsx/file.hmr.debug.jsx
+++ b/integration/snapshots/custom-emotion-jsx/file.hmr.debug.jsx
@@ -1,13 +1,14 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
-import * as JSX from "http://localhost:8080/node_modules/@emotion/react/jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.browser.esm.js";
+} from "http://localhost:8080/bun:wrap";
+import * as $72625799 from "http://localhost:8080/node_modules/@emotion/react/jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.browser.esm.js";
+var JSX = require($72625799);
var jsx = require(JSX).jsxDEV;
import * as $5b3cea55 from "http://localhost:8080/node_modules/react-dom/index.js";
diff --git a/integration/snapshots/custom-emotion-jsx/file.hmr.jsx b/integration/snapshots/custom-emotion-jsx/file.hmr.jsx
index aae7c50c0..398690a7e 100644
--- a/integration/snapshots/custom-emotion-jsx/file.hmr.jsx
+++ b/integration/snapshots/custom-emotion-jsx/file.hmr.jsx
@@ -1,19 +1,19 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $72625799 from "http://localhost:8080/node_modules/@emotion/react/jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.browser.esm.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $72625799 from "http://localhost:3000/node_modules/@emotion/react/jsx-dev-runtime/dist/emotion-react-jsx-dev-runtime.browser.esm.js";
var JSX = require($72625799);
var jsx = require(JSX).jsxDEV;
-import * as $5b3cea55 from "http://localhost:8080/node_modules/react-dom/index.js";
+import * as $5b3cea55 from "http://localhost:3000/node_modules/react-dom/index.js";
var ReactDOM = require($5b3cea55);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(2497996991, "custom-emotion-jsx/file.jsx"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/export.hmr.js b/integration/snapshots/export.hmr.js
index b0c14bbc6..ef1963323 100644
--- a/integration/snapshots/export.hmr.js
+++ b/integration/snapshots/export.hmr.js
@@ -1,12 +1,12 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-import what from "http://localhost:8080/_auth.js";
-import * as where from "http://localhost:8080/_auth.js";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+import what from "http://localhost:3000/_auth.js";
+import * as where from "http://localhost:3000/_auth.js";
+Bun.activate(true);
var hmr = new HMR(1879780259, "export.js"), exports = hmr.exports;
(hmr._load = function() {
@@ -68,7 +68,7 @@ export {
$$hmr_booop as booop,
$$hmr_test as test
};
-export {default as auth} from "http://localhost:8080/_auth.js";
-export {default as login} from "http://localhost:8080/_login.js";
-export * from "http://localhost:8080/_bacon.js";
-export {} from "http://localhost:8080/_bacon.js";
+export {default as auth} from "http://localhost:3000/_auth.js";
+export {default as login} from "http://localhost:3000/_login.js";
+export * from "http://localhost:3000/_bacon.js";
+export {} from "http://localhost:3000/_bacon.js";
diff --git a/integration/snapshots/forbid-in-is-correct.hmr.js b/integration/snapshots/forbid-in-is-correct.hmr.js
index 7ecffa276..2b55a976a 100644
--- a/integration/snapshots/forbid-in-is-correct.hmr.js
+++ b/integration/snapshots/forbid-in-is-correct.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(346837007, "forbid-in-is-correct.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/global-is-remapped-to-globalThis.hmr.js b/integration/snapshots/global-is-remapped-to-globalThis.hmr.js
index 1abe6edd6..6872df8ca 100644
--- a/integration/snapshots/global-is-remapped-to-globalThis.hmr.js
+++ b/integration/snapshots/global-is-remapped-to-globalThis.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(713665787, "global-is-remapped-to-globalThis.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/jsx-entities.hmr.debug.jsx b/integration/snapshots/jsx-entities.hmr.debug.jsx
index 5427483d3..4c4e6ac85 100644
--- a/integration/snapshots/jsx-entities.hmr.debug.jsx
+++ b/integration/snapshots/jsx-entities.hmr.debug.jsx
@@ -1,13 +1,14 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
-import * as JSX from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:8080/bun:wrap";
+import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+var JSX = require($2f488e5b);
import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
var JSXClassic = require($bbcd215f);
var jsx = require(JSX).jsxDEV, JSXFrag = require(JSXClassic).Fragment;
diff --git a/integration/snapshots/jsx-entities.hmr.jsx b/integration/snapshots/jsx-entities.hmr.jsx
index 6a8e19e2c..f7e3df0b0 100644
--- a/integration/snapshots/jsx-entities.hmr.jsx
+++ b/integration/snapshots/jsx-entities.hmr.jsx
@@ -1,21 +1,21 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $2f488e5b from "http://localhost:3000/node_modules/react/jsx-dev-runtime.js";
var JSX = require($2f488e5b);
-import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
+import * as $bbcd215f from "http://localhost:3000/node_modules/react/index.js";
var JSXClassic = require($bbcd215f);
var jsx = require(JSX).jsxDEV, JSXFrag = require(JSXClassic).Fragment;
-import * as $1f6f0e67 from "http://localhost:8080/node_modules/react-dom/server.browser.js";
+import * as $1f6f0e67 from "http://localhost:3000/node_modules/react-dom/server.browser.js";
var ReactDOM = require($1f6f0e67);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(817082122, "jsx-entities.jsx"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/jsx-spacing.hmr.debug.jsx b/integration/snapshots/jsx-spacing.hmr.debug.jsx
index 462469ba5..d82957a7a 100644
--- a/integration/snapshots/jsx-spacing.hmr.debug.jsx
+++ b/integration/snapshots/jsx-spacing.hmr.debug.jsx
@@ -1,13 +1,14 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
-import * as JSX from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:8080/bun:wrap";
+import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+var JSX = require($2f488e5b);
var jsx = require(JSX).jsxDEV;
import * as $1f6f0e67 from "http://localhost:8080/node_modules/react-dom/server.browser.js";
diff --git a/integration/snapshots/jsx-spacing.hmr.jsx b/integration/snapshots/jsx-spacing.hmr.jsx
index 41cf523a3..c6eb4b979 100644
--- a/integration/snapshots/jsx-spacing.hmr.jsx
+++ b/integration/snapshots/jsx-spacing.hmr.jsx
@@ -1,19 +1,19 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $2f488e5b from "http://localhost:3000/node_modules/react/jsx-dev-runtime.js";
var JSX = require($2f488e5b);
var jsx = require(JSX).jsxDEV;
-import * as $1f6f0e67 from "http://localhost:8080/node_modules/react-dom/server.browser.js";
+import * as $1f6f0e67 from "http://localhost:3000/node_modules/react-dom/server.browser.js";
var ReactDOM = require($1f6f0e67);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(3614189736, "jsx-spacing.jsx"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/latin1-chars-in-regexp.hmr.debug.js b/integration/snapshots/latin1-chars-in-regexp.hmr.debug.js
index db7f60ee3..29ce11711 100644
--- a/integration/snapshots/latin1-chars-in-regexp.hmr.debug.js
+++ b/integration/snapshots/latin1-chars-in-regexp.hmr.debug.js
@@ -1,9 +1,9 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
Bun.activate(true);
var hmr = new HMR(1430071586, "latin1-chars-in-regexp.js"), exports = hmr.exports;
diff --git a/integration/snapshots/latin1-chars-in-regexp.hmr.js b/integration/snapshots/latin1-chars-in-regexp.hmr.js
index b223df7b3..5baf94817 100644
--- a/integration/snapshots/latin1-chars-in-regexp.hmr.js
+++ b/integration/snapshots/latin1-chars-in-regexp.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(1430071586, "latin1-chars-in-regexp.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/lodash-regexp.hmr.js b/integration/snapshots/lodash-regexp.hmr.js
index 04db31a93..78e5609af 100644
--- a/integration/snapshots/lodash-regexp.hmr.js
+++ b/integration/snapshots/lodash-regexp.hmr.js
@@ -1,15 +1,15 @@
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-import * as $60f52dc2 from "http://localhost:8080/node_modules/lodash/lodash.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $60f52dc2 from "http://localhost:3000/node_modules/lodash/lodash.js";
var { shuffle} = require($60f52dc2);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(2158065009, "lodash-regexp.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/multiple-imports.hmr.js b/integration/snapshots/multiple-imports.hmr.js
index 90fa24453..8945c5424 100644
--- a/integration/snapshots/multiple-imports.hmr.js
+++ b/integration/snapshots/multiple-imports.hmr.js
@@ -1,21 +1,21 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $2f488e5b from "http://localhost:3000/node_modules/react/jsx-dev-runtime.js";
var JSX = require($2f488e5b);
-import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
+import * as $bbcd215f from "http://localhost:3000/node_modules/react/index.js";
var JSXClassic = require($bbcd215f);
var jsx = require(JSX).jsxDEV, JSXFrag = require(JSXClassic).Fragment;
var { default: React} = require($bbcd215f);
var { default: React2} = require($bbcd215f);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(2165509932, "multiple-imports.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/number-literal-bug.hmr.debug.js b/integration/snapshots/number-literal-bug.hmr.debug.js
index 96e0dc96c..81dd56694 100644
--- a/integration/snapshots/number-literal-bug.hmr.debug.js
+++ b/integration/snapshots/number-literal-bug.hmr.debug.js
@@ -1,9 +1,9 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
Bun.activate(true);
var hmr = new HMR(583570002, "number-literal-bug.js"), exports = hmr.exports;
diff --git a/integration/snapshots/number-literal-bug.hmr.js b/integration/snapshots/number-literal-bug.hmr.js
index ce74e60a0..f83254c0d 100644
--- a/integration/snapshots/number-literal-bug.hmr.js
+++ b/integration/snapshots/number-literal-bug.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(583570002, "number-literal-bug.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/optional-chain-with-function.hmr.debug.js b/integration/snapshots/optional-chain-with-function.hmr.debug.js
index f4c7a3641..68b71ddcc 100644
--- a/integration/snapshots/optional-chain-with-function.hmr.debug.js
+++ b/integration/snapshots/optional-chain-with-function.hmr.debug.js
@@ -1,9 +1,9 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
Bun.activate(true);
var hmr = new HMR(3608848620, "optional-chain-with-function.js"), exports = hmr.exports;
diff --git a/integration/snapshots/optional-chain-with-function.hmr.js b/integration/snapshots/optional-chain-with-function.hmr.js
index 784ef9b55..b75166c90 100644
--- a/integration/snapshots/optional-chain-with-function.hmr.js
+++ b/integration/snapshots/optional-chain-with-function.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(3608848620, "optional-chain-with-function.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/package-json-exports/index.hmr.js b/integration/snapshots/package-json-exports/index.hmr.js
index 040004980..e70ea1868 100644
--- a/integration/snapshots/package-json-exports/index.hmr.js
+++ b/integration/snapshots/package-json-exports/index.hmr.js
@@ -1,21 +1,21 @@
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-import * as $4068f25b from "http://localhost:8080/package-json-exports/node_modules/inexact/browser/index.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $4068f25b from "http://localhost:3000/package-json-exports/node_modules/inexact/browser/index.js";
var InexactRoot = require($4068f25b);
-import * as $d2a171d2 from "http://localhost:8080/package-json-exports/node_modules/inexact/browser/dir/file.js";
+import * as $d2a171d2 from "http://localhost:3000/package-json-exports/node_modules/inexact/browser/dir/file.js";
var InexactFile = require($d2a171d2);
-import * as $522c6d1f from "http://localhost:8080/package-json-exports/node_modules/inexact/browser/foo.js";
+import * as $522c6d1f from "http://localhost:3000/package-json-exports/node_modules/inexact/browser/foo.js";
var ExactFile = require($522c6d1f);
-import * as $fce83cd7 from "http://localhost:8080/package-json-exports/node_modules/js-only-exports/browser/js-file.js";
+import * as $fce83cd7 from "http://localhost:3000/package-json-exports/node_modules/js-only-exports/browser/js-file.js";
var JSFileExtensionOnly = require($fce83cd7);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(1953708113, "package-json-exports/index.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/react-context-value-func.hmr.debug.tsx b/integration/snapshots/react-context-value-func.hmr.debug.tsx
index 4632802d4..cfaca0723 100644
--- a/integration/snapshots/react-context-value-func.hmr.debug.tsx
+++ b/integration/snapshots/react-context-value-func.hmr.debug.tsx
@@ -1,13 +1,14 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
-import * as JSX from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:8080/bun:wrap";
+import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+var JSX = require($2f488e5b);
var jsx = require(JSX).jsxDEV;
import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
diff --git a/integration/snapshots/react-context-value-func.hmr.tsx b/integration/snapshots/react-context-value-func.hmr.tsx
index 66bcfb36c..42eee99fc 100644
--- a/integration/snapshots/react-context-value-func.hmr.tsx
+++ b/integration/snapshots/react-context-value-func.hmr.tsx
@@ -1,19 +1,19 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $2f488e5b from "http://localhost:3000/node_modules/react/jsx-dev-runtime.js";
var JSX = require($2f488e5b);
var jsx = require(JSX).jsxDEV;
-import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
+import * as $bbcd215f from "http://localhost:3000/node_modules/react/index.js";
var { default: React} = require($bbcd215f);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(3514348331, "react-context-value-func.tsx"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/spread_with_key.hmr.tsx b/integration/snapshots/spread_with_key.hmr.tsx
index 0e36097a4..596ba8700 100644
--- a/integration/snapshots/spread_with_key.hmr.tsx
+++ b/integration/snapshots/spread_with_key.hmr.tsx
@@ -1,20 +1,20 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $2f488e5b from "http://localhost:3000/node_modules/react/jsx-dev-runtime.js";
var JSX = require($2f488e5b);
-import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
+import * as $bbcd215f from "http://localhost:3000/node_modules/react/index.js";
var JSXClassic = require($bbcd215f);
var jsx = require(JSX).jsxDEV, jsxEl = require(JSXClassic).createElement;
var { default: React} = require($bbcd215f);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(2717584935, "spread_with_key.tsx"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/string-escapes.hmr.js b/integration/snapshots/string-escapes.hmr.js
index 1b341528c..4c95ef6f3 100644
--- a/integration/snapshots/string-escapes.hmr.js
+++ b/integration/snapshots/string-escapes.hmr.js
@@ -1,19 +1,19 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $2f488e5b from "http://localhost:3000/node_modules/react/jsx-dev-runtime.js";
var JSX = require($2f488e5b);
-import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
+import * as $bbcd215f from "http://localhost:3000/node_modules/react/index.js";
var JSXClassic = require($bbcd215f);
var jsx = require(JSX).jsxDEV, JSXFrag = require(JSXClassic).Fragment;
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(2482749838, "string-escapes.js"), exports = hmr.exports;
(hmr._load = function() {
var tab = "\t";
diff --git a/integration/snapshots/styledcomponents-output.hmr.debug.js b/integration/snapshots/styledcomponents-output.hmr.debug.js
index cecb4780e..2c93c0c08 100644
--- a/integration/snapshots/styledcomponents-output.hmr.debug.js
+++ b/integration/snapshots/styledcomponents-output.hmr.debug.js
@@ -1,13 +1,14 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
-import * as JSX from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:8080/bun:wrap";
+import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+var JSX = require($2f488e5b);
var jsx = require(JSX).jsxDEV;
import * as $d4051a2e from "http://localhost:8080/node_modules/styled-components/dist/styled-components.browser.esm.js";
diff --git a/integration/snapshots/styledcomponents-output.hmr.js b/integration/snapshots/styledcomponents-output.hmr.js
index 6cf42fffd..8967d17e5 100644
--- a/integration/snapshots/styledcomponents-output.hmr.js
+++ b/integration/snapshots/styledcomponents-output.hmr.js
@@ -1,23 +1,23 @@
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__require as require
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
-import * as $2f488e5b from "http://localhost:8080/node_modules/react/jsx-dev-runtime.js";
+} from "http://localhost:3000/bun:wrap";
+import * as $2f488e5b from "http://localhost:3000/node_modules/react/jsx-dev-runtime.js";
var JSX = require($2f488e5b);
var jsx = require(JSX).jsxDEV;
-import * as $d4051a2e from "http://localhost:8080/node_modules/styled-components/dist/styled-components.browser.esm.js";
+import * as $d4051a2e from "http://localhost:3000/node_modules/styled-components/dist/styled-components.browser.esm.js";
var { default: styled} = require($d4051a2e);
-import * as $bbcd215f from "http://localhost:8080/node_modules/react/index.js";
+import * as $bbcd215f from "http://localhost:3000/node_modules/react/index.js";
var { default: React} = require($bbcd215f);
-import * as $5b3cea55 from "http://localhost:8080/node_modules/react-dom/index.js";
+import * as $5b3cea55 from "http://localhost:3000/node_modules/react-dom/index.js";
var { default: ReactDOM} = require($5b3cea55);
-Bun.activate(false);
+Bun.activate(true);
var hmr = new HMR(1290604342, "styledcomponents-output.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/template-literal.hmr.debug.js b/integration/snapshots/template-literal.hmr.debug.js
index a603ab705..b3397e7a5 100644
--- a/integration/snapshots/template-literal.hmr.debug.js
+++ b/integration/snapshots/template-literal.hmr.debug.js
@@ -1,9 +1,9 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
Bun.activate(true);
var hmr = new HMR(2201713056, "template-literal.js"), exports = hmr.exports;
diff --git a/integration/snapshots/template-literal.hmr.js b/integration/snapshots/template-literal.hmr.js
index 8097787c4..e464c4ee0 100644
--- a/integration/snapshots/template-literal.hmr.js
+++ b/integration/snapshots/template-literal.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(2201713056, "template-literal.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/ts-fallback-rewrite-works.hmr.js b/integration/snapshots/ts-fallback-rewrite-works.hmr.js
index 4f19ee3c6..d4156081f 100644
--- a/integration/snapshots/ts-fallback-rewrite-works.hmr.js
+++ b/integration/snapshots/ts-fallback-rewrite-works.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(421762902, "ts-fallback-rewrite-works.ts"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/tsx-fallback-rewrite-works.hmr.js b/integration/snapshots/tsx-fallback-rewrite-works.hmr.js
index 3bdda9320..5d5212e12 100644
--- a/integration/snapshots/tsx-fallback-rewrite-works.hmr.js
+++ b/integration/snapshots/tsx-fallback-rewrite-works.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(2117426367, "tsx-fallback-rewrite-works.tsx"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/type-only-imports.hmr.ts b/integration/snapshots/type-only-imports.hmr.ts
index b58f0cb4a..384dffc50 100644
--- a/integration/snapshots/type-only-imports.hmr.ts
+++ b/integration/snapshots/type-only-imports.hmr.ts
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(650094581, "type-only-imports.ts"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/unicode-identifiers.hmr.js b/integration/snapshots/unicode-identifiers.hmr.js
index 386f79bb2..40b339582 100644
--- a/integration/snapshots/unicode-identifiers.hmr.js
+++ b/integration/snapshots/unicode-identifiers.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(1398361736, "unicode-identifiers.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.debug.js b/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.debug.js
index fa25488ec..cef7a9290 100644
--- a/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.debug.js
+++ b/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.debug.js
@@ -1,9 +1,9 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:runtime";
+} from "http://localhost:8080/bun:wrap";
Bun.activate(true);
var hmr = new HMR(635901064, "void-shouldnt-delete-call-expressions.js"), exports = hmr.exports;
diff --git a/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.js b/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.js
index d59a41bf6..fc53d5258 100644
--- a/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.js
+++ b/integration/snapshots/void-shouldnt-delete-call-expressions.hmr.js
@@ -1,10 +1,10 @@
import {
__HMRModule as HMR
-} from "http://localhost:8080/bun:wrap";
+} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
-} from "http://localhost:8080/bun:wrap";
-Bun.activate(false);
+} from "http://localhost:3000/bun:wrap";
+Bun.activate(true);
var hmr = new HMR(635901064, "void-shouldnt-delete-call-expressions.js"), exports = hmr.exports;
(hmr._load = function() {
diff --git a/src/bundler.zig b/src/bundler.zig
index bcbcf910e..f453f7b89 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -1790,7 +1790,7 @@ pub const Bundler = struct {
json_e_call = js_ast.E.Call{
.target = js_ast.Expr{ .data = .{ .e_identifier = json_e_identifier }, .loc = logger.Loc{ .start = 0 } },
- .args = std.mem.span(&json_call_args),
+ .args = js_ast.ExprNodeList.init(std.mem.span(&json_call_args)),
};
break :brk js_ast.Expr{ .data = .{ .e_call = &json_e_call }, .loc = logger.Loc{ .start = 0 } };
// If we're going to have to convert it to a UTF16, just make it an object actually
@@ -1885,7 +1885,7 @@ pub const Bundler = struct {
var properties: [1]js_ast.G.Property = undefined;
var e_object = E.Object{
- .properties = &properties,
+ .properties = js_ast.G.Property.List.init(&properties),
};
const module_path_str = js_ast.Expr{ .data = .{ .e_string = &package_path }, .loc = logger.Loc.Empty };
properties[0] = js_ast.G.Property{
@@ -1912,7 +1912,7 @@ pub const Bundler = struct {
.data = .{ .e_identifier = target_identifier },
.loc = logger.Loc{ .start = 0 },
},
- .args = &register_args,
+ .args = js_ast.ExprNodeList.init(&register_args),
};
var register_expr = Expr{ .loc = call_register.target.loc, .data = .{ .e_call = &call_register } };
var decls: [1]js_ast.G.Decl = undefined;
diff --git a/src/bunfig.zig b/src/bunfig.zig
index 0dd9a7d3f..9af59976f 100644
--- a/src/bunfig.zig
+++ b/src/bunfig.zig
@@ -29,6 +29,7 @@ const Analytics = @import("./analytics.zig");
const JSONParser = @import("./json_parser.zig");
const Command = @import("cli.zig").Command;
+// TODO: replace Api.TransformOptions with Bunfig
pub const Bunfig = struct {
const Parser = struct {
json: js_ast.Expr,
@@ -54,7 +55,7 @@ pub const Bunfig = struct {
if (json.get("define")) |expr| {
try this.expect(expr, .e_object);
var valid_count: usize = 0;
- const properties = expr.data.e_object.properties;
+ const properties = expr.data.e_object.properties.slice();
for (properties) |prop| {
if (prop.value.?.data != .e_string) continue;
valid_count += 1;
@@ -116,7 +117,7 @@ pub const Bunfig = struct {
if (comptime cmd == .BunCommand) {
if (bun.get("entryPoints")) |entryPoints| {
try this.expect(entryPoints, .e_array);
- const items = entryPoints.data.e_array.items;
+ const items = entryPoints.data.e_array.items.slice();
var names = try this.allocator.alloc(string, items.len);
for (items) |item, i| {
try this.expect(item, .e_string);
@@ -131,14 +132,15 @@ pub const Bunfig = struct {
Analytics.Features.always_bundle = true;
const object = expr.data.e_object;
- for (object.properties) |prop| {
+ const properties = object.properties.slice();
+ for (properties) |prop| {
if (prop.value.?.data != .e_boolean) continue;
valid_count += 1;
}
try this.ctx.debug.package_bundle_map.ensureTotalCapacity(allocator, valid_count);
- for (object.properties) |prop| {
+ for (properties) |prop| {
if (prop.value.?.data != .e_boolean) continue;
const path = try prop.key.?.data.e_string.string(allocator);
@@ -182,7 +184,7 @@ pub const Bunfig = struct {
.e_array => |array| {
var externals = try allocator.alloc(string, array.items.len);
- for (array.items) |item, i| {
+ for (array.items.slice()) |item, i| {
try this.expect(item, .e_string);
externals[i] = try item.data.e_string.string(allocator);
}
@@ -202,7 +204,7 @@ pub const Bunfig = struct {
if (json.get("loader")) |expr| {
try this.expect(expr, .e_object);
- const properties = expr.data.e_object.properties;
+ const properties = expr.data.e_object.properties.slice();
var loader_names = try this.allocator.alloc(string, properties.len);
var loader_values = try this.allocator.alloc(Api.Loader, properties.len);
diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig
index 7e3ea96eb..7abea971b 100644
--- a/src/cli/create_command.zig
+++ b/src/cli/create_command.zig
@@ -74,7 +74,7 @@ const UnsupportedPackages = struct {
@"styled-jsx": bool = false,
pub fn update(this: *UnsupportedPackages, expr: js_ast.Expr) void {
- for (expr.data.e_object.properties) |prop| {
+ for (expr.data.e_object.properties.slice()) |prop| {
inline for (comptime std.meta.fieldNames(UnsupportedPackages)) |field_name| {
if (strings.eqlComptime(prop.key.?.data.e_string.utf8, comptime field_name)) {
@field(this, field_name) = true;
@@ -727,7 +727,7 @@ pub const CreateCommand = struct {
break :process_package_json;
}
- var properties_list = std.ArrayList(js_ast.G.Property).fromOwnedSlice(default_allocator, package_json_expr.data.e_object.properties);
+ var properties_list = std.ArrayList(js_ast.G.Property).fromOwnedSlice(default_allocator, package_json_expr.data.e_object.properties.slice());
if (ctx.log.errors > 0) {
if (Output.enable_ansi_colors) {
@@ -809,7 +809,7 @@ pub const CreateCommand = struct {
has_react_scripts = has_react_scripts or property.hasAnyPropertyNamed(&.{"react-scripts"});
has_relay = has_relay or property.hasAnyPropertyNamed(&.{ "react-relay", "relay-runtime", "babel-plugin-relay" });
- property.data.e_object.properties = Prune.prune(property.data.e_object.properties);
+ property.data.e_object.properties = js_ast.G.Property.List.init(Prune.prune(property.data.e_object.properties.slice()));
if (property.data.e_object.properties.len > 0) {
has_dependencies = true;
dev_dependencies = q.expr;
@@ -830,7 +830,7 @@ pub const CreateCommand = struct {
has_react_scripts = has_react_scripts or property.hasAnyPropertyNamed(&.{"react-scripts"});
has_relay = has_relay or property.hasAnyPropertyNamed(&.{ "react-relay", "relay-runtime", "babel-plugin-relay" });
- property.data.e_object.properties = Prune.prune(property.data.e_object.properties);
+ property.data.e_object.properties = js_ast.G.Property.List.init(Prune.prune(property.data.e_object.properties.slice()));
if (property.data.e_object.properties.len > 0) {
has_dependencies = true;
@@ -963,7 +963,7 @@ pub const CreateCommand = struct {
};
var bun_macro_relay_object = js_ast.E.Object{
- .properties = std.mem.span(&bun_macro_relay_properties),
+ .properties = undefined,
};
var bun_macros_relay_object_properties = [_]js_ast.G.Property{
@@ -1012,11 +1012,11 @@ pub const CreateCommand = struct {
};
pub var bun_macros_relay_object = E.Object{
- .properties = &bun_macros_relay_object_properties,
+ .properties = undefined,
};
var bun_macros_relay_only_object_string = js_ast.E.String{ .utf8 = "macros" };
- var bun_macros_relay_only_object_properties = [_]js_ast.G.Property{
+ pub var bun_macros_relay_only_object_properties = [_]js_ast.G.Property{
js_ast.G.Property{
.key = js_ast.Expr{
.data = .{
@@ -1032,9 +1032,7 @@ pub const CreateCommand = struct {
},
},
};
- pub var bun_macros_relay_only_object = E.Object{
- .properties = &bun_macros_relay_only_object_properties,
- };
+ pub var bun_macros_relay_only_object = E.Object{ .properties = undefined };
var bun_only_macros_string = js_ast.E.String{ .utf8 = "bun" };
pub var bun_only_macros_relay_property = js_ast.G.Property{
@@ -1118,12 +1116,14 @@ pub const CreateCommand = struct {
pub const bun_bun_for_nextjs_task: string = "bun bun --use next";
};
+ InjectionPrefill.bun_macro_relay_object.properties = js_ast.G.Property.List.init(std.mem.span(&InjectionPrefill.bun_macro_relay_properties));
+ InjectionPrefill.bun_macros_relay_object.properties = js_ast.G.Property.List.init(&InjectionPrefill.bun_macros_relay_object_properties);
+ InjectionPrefill.bun_macros_relay_only_object.properties = js_ast.G.Property.List.init(&InjectionPrefill.bun_macros_relay_only_object_properties);
+
if (needs_to_inject_dev_dependency and dev_dependencies == null) {
var e_object = try ctx.allocator.create(E.Object);
- e_object.* = E.Object{
- .properties = &.{},
- };
+ e_object.* = E.Object{};
const value = js_ast.Expr{ .data = .{ .e_object = e_object }, .loc = logger.Loc.Empty };
properties_list.appendAssumeCapacity(js_ast.G.Property{
@@ -1136,9 +1136,7 @@ pub const CreateCommand = struct {
if (needs_to_inject_dependency and dependencies == null) {
var e_object = try ctx.allocator.create(E.Object);
- e_object.* = E.Object{
- .properties = &.{},
- };
+ e_object.* = E.Object{};
const value = js_ast.Expr{ .data = .{ .e_object = e_object }, .loc = logger.Loc.Empty };
properties_list.appendAssumeCapacity(js_ast.G.Property{
@@ -1163,7 +1161,7 @@ pub const CreateCommand = struct {
// "bun.macros.react-relay.graphql"
if (needs.bun_macro_relay and !needs_bun_prop and !needs_bun_macros_prop) {
// "graphql" is the only valid one for now, so anything else in this object is invalid.
- bun_relay_prop.?.data.e_object = InjectionPrefill.bun_macros_relay_object.properties[0].value.?.data.e_object;
+ bun_relay_prop.?.data.e_object = InjectionPrefill.bun_macros_relay_object.properties.ptr[0].value.?.data.e_object;
needs_bun_macros_prop = false;
needs_bun_prop = false;
needs.bun_macro_relay = false;
@@ -1177,10 +1175,10 @@ pub const CreateCommand = struct {
ctx.allocator,
obj.properties.len + InjectionPrefill.bun_macros_relay_object.properties.len,
);
- defer obj.properties = properties.toOwnedSlice();
+ defer obj.properties.update(properties);
- try properties.insertSlice(0, obj.properties);
- try properties.insertSlice(0, InjectionPrefill.bun_macros_relay_object.properties);
+ try properties.insertSlice(0, obj.properties.slice());
+ try properties.insertSlice(0, InjectionPrefill.bun_macros_relay_object.properties.slice());
needs_bun_macros_prop = false;
needs_bun_prop = false;
@@ -1205,8 +1203,8 @@ pub const CreateCommand = struct {
ctx.allocator,
obj.properties.len + dependencies_to_inject_count,
);
- try properties.insertSlice(0, obj.properties);
- defer obj.properties = properties.toOwnedSlice();
+ try properties.insertSlice(0, obj.properties.slice());
+ defer obj.properties.update(properties);
if (needs.bun_framework_next) {
properties.appendAssumeCapacity(InjectionPrefill.bun_framework_next_property);
needs.bun_framework_next = false;
@@ -1220,8 +1218,8 @@ pub const CreateCommand = struct {
ctx.allocator,
obj.properties.len + dev_dependencies_to_inject_count,
);
- try properties.insertSlice(0, obj.properties);
- defer obj.properties = properties.toOwnedSlice();
+ try properties.insertSlice(0, obj.properties.slice());
+ defer obj.properties.update(properties);
if (needs.bun_macro_relay_dependency) {
properties.appendAssumeCapacity(InjectionPrefill.bun_macro_relay_dependency);
needs.bun_macro_relay_dependency = false;
@@ -1330,17 +1328,17 @@ pub const CreateCommand = struct {
package_json_expr.data.e_object.is_single_line = false;
- package_json_expr.data.e_object.properties = properties_list.items;
+ package_json_expr.data.e_object.properties = js_ast.G.Property.List.fromList(properties_list);
{
var i: usize = 0;
var property_i: usize = 0;
while (i < package_json_expr.data.e_object.properties.len) : (i += 1) {
- const property = package_json_expr.data.e_object.properties[i];
+ const property = package_json_expr.data.e_object.properties.ptr[i];
const key = property.key.?.asString(ctx.allocator).?;
if (strings.eqlComptime(key, "scripts")) {
if (property.value.?.data == .e_object) {
- var scripts_properties = property.value.?.data.e_object.properties;
+ var scripts_properties = property.value.?.data.e_object.properties.slice();
// if they're starting the app with "react-scripts start" or "next dev", that won't make sense
// if they launch with npm run start it will just be slower
@@ -1369,12 +1367,12 @@ pub const CreateCommand = struct {
script_property_out_i += 1;
}
- property.value.?.data.e_object.properties = scripts_properties[0..script_property_out_i];
+ property.value.?.data.e_object.properties = js_ast.G.Property.List.init(scripts_properties[0..script_property_out_i]);
}
}
if (key.len == 0 or !strings.eqlComptime(key, "bun-create")) {
- package_json_expr.data.e_object.properties[property_i] = property;
+ package_json_expr.data.e_object.properties.ptr[property_i] = property;
property_i += 1;
continue;
}
@@ -1389,7 +1387,8 @@ pub const CreateCommand = struct {
);
},
.e_array => |tasks| {
- for (tasks.items) |task| {
+ const items = tasks.slice();
+ for (items) |task| {
if (task.asString(ctx.allocator)) |task_entry| {
if (needs.bun_bun_for_nextjs or bun_bun_for_react_scripts) {
var iter = std.mem.split(u8, task_entry, " ");
@@ -1426,7 +1425,7 @@ pub const CreateCommand = struct {
);
},
.e_array => |tasks| {
- for (tasks.items) |task| {
+ for (tasks.items.slice()) |task| {
if (task.asString(ctx.allocator)) |task_entry| {
try preinstall_tasks.append(
ctx.allocator,
@@ -1439,7 +1438,7 @@ pub const CreateCommand = struct {
}
}
}
- package_json_expr.data.e_object.properties = package_json_expr.data.e_object.properties[0..property_i];
+ package_json_expr.data.e_object.properties = js_ast.G.Property.List.init(package_json_expr.data.e_object.properties.ptr[0..property_i]);
}
var package_json_writer = JSPrinter.NewFileWriter(package_json_file.?);
@@ -2077,7 +2076,7 @@ pub const Example = struct {
const count = q.expr.data.e_object.properties.len;
var list = try ctx.allocator.alloc(Example, count);
- for (q.expr.data.e_object.properties) |property, i| {
+ for (q.expr.data.e_object.properties.slice()) |property, i| {
const name = property.key.?.data.e_string.utf8;
list[i] = Example{
.name = if (std.mem.indexOfScalar(u8, name, '/')) |slash|
diff --git a/src/install/install.zig b/src/install/install.zig
index 7620356b6..3065a6f72 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -2332,7 +2332,7 @@ pub const Lockfile = struct {
inline for (dependency_groups) |group| {
if (json.asProperty(group.prop)) |dependencies_q| {
if (dependencies_q.expr.data == .e_object) {
- for (dependencies_q.expr.data.e_object.properties) |item| {
+ for (dependencies_q.expr.data.e_object.properties.slice()) |item| {
string_builder.count(item.key.?.asString(allocator) orelse "");
string_builder.count(item.value.?.asString(allocator) orelse "");
}
@@ -2381,7 +2381,7 @@ pub const Lockfile = struct {
inline for (dependency_groups) |group| {
if (json.asProperty(group.prop)) |dependencies_q| {
if (dependencies_q.expr.data == .e_object) {
- const dependency_props: []const JSAst.G.Property = dependencies_q.expr.data.e_object.properties;
+ const dependency_props: []const JSAst.G.Property = dependencies_q.expr.data.e_object.properties.slice();
var i: usize = 0;
outer: while (i < dependency_props.len) {
const item = dependency_props[i];
@@ -5170,7 +5170,7 @@ pub const PackageManager = struct {
var dependencies: []G.Property = &[_]G.Property{};
if (current_package_json.asProperty(dependency_list)) |query| {
if (query.expr.data == .e_object) {
- dependencies = query.expr.data.e_object.properties;
+ dependencies = query.expr.data.e_object.properties.slice();
}
}
@@ -5233,7 +5233,7 @@ pub const PackageManager = struct {
dependencies_object = JSAst.Expr.init(
JSAst.E.Object,
JSAst.E.Object{
- .properties = new_dependencies,
+ .properties = JSAst.G.Property.List.init(new_dependencies),
},
logger.Loc.Empty,
);
@@ -5251,10 +5251,10 @@ pub const PackageManager = struct {
),
.value = dependencies_object,
};
- current_package_json.* = JSAst.Expr.init(JSAst.E.Object, JSAst.E.Object{ .properties = root_properties }, logger.Loc.Empty);
+ current_package_json.* = JSAst.Expr.init(JSAst.E.Object, JSAst.E.Object{ .properties = JSAst.G.Property.List.init(root_properties) }, logger.Loc.Empty);
} else if (needs_new_dependency_list) {
var root_properties = try allocator.alloc(JSAst.G.Property, current_package_json.data.e_object.properties.len + 1);
- std.mem.copy(JSAst.G.Property, root_properties, current_package_json.data.e_object.properties);
+ std.mem.copy(JSAst.G.Property, root_properties, current_package_json.data.e_object.properties.slice());
root_properties[root_properties.len - 1].key = JSAst.Expr.init(
JSAst.E.String,
JSAst.E.String{
@@ -5263,10 +5263,10 @@ pub const PackageManager = struct {
logger.Loc.Empty,
);
root_properties[root_properties.len - 1].value = dependencies_object;
- current_package_json.* = JSAst.Expr.init(JSAst.E.Object, JSAst.E.Object{ .properties = root_properties }, logger.Loc.Empty);
+ current_package_json.* = JSAst.Expr.init(JSAst.E.Object, JSAst.E.Object{ .properties = JSAst.G.Property.List.init(root_properties) }, logger.Loc.Empty);
}
- dependencies_object.data.e_object.properties = new_dependencies;
+ dependencies_object.data.e_object.properties = JSAst.G.Property.List.init(new_dependencies);
dependencies_object.data.e_object.packageJSONSort();
}
@@ -5935,7 +5935,7 @@ pub const PackageManager = struct {
inline for (dependency_lists_to_check) |list| {
if (current_package_json.asProperty(list)) |query| {
if (query.expr.data == .e_object) {
- var dependencies = query.expr.data.e_object.properties;
+ var dependencies = query.expr.data.e_object.properties.slice();
var i: usize = 0;
var new_len = dependencies.len;
while (i < dependencies.len) : (i += 1) {
@@ -5955,17 +5955,14 @@ pub const PackageManager = struct {
const changed = new_len != dependencies.len;
if (changed) {
- query.expr.data.e_object.properties = query.expr.data.e_object.properties[0..new_len];
+ query.expr.data.e_object.properties.len = @truncate(u32, new_len);
// If the dependencies list is now empty, remove it from the package.json
// since we're swapRemove, we have to re-sort it
if (query.expr.data.e_object.properties.len == 0) {
- var arraylist = std.ArrayListUnmanaged(JSAst.G.Property){
- .items = current_package_json.data.e_object.properties,
- .capacity = current_package_json.data.e_object.properties.len,
- };
+ var arraylist = current_package_json.data.e_object.properties.list();
_ = arraylist.swapRemove(query.i);
- current_package_json.data.e_object.properties = arraylist.items;
+ current_package_json.data.e_object.properties.update(arraylist);
current_package_json.data.e_object.packageJSONSort();
} else {
var obj = query.expr.data.e_object;
diff --git a/src/install/npm.zig b/src/install/npm.zig
index 8ca08fc4b..3f3f8596a 100644
--- a/src/install/npm.zig
+++ b/src/install/npm.zig
@@ -745,7 +745,7 @@ pub const PackageManifest = struct {
if (json.asProperty("versions")) |versions_q| {
if (versions_q.expr.data != .e_object) break :get_versions;
- const versions = versions_q.expr.data.e_object.properties;
+ const versions = versions_q.expr.data.e_object.properties.slice();
for (versions) |prop| {
const version_name = prop.key.?.asString(allocator) orelse continue;
@@ -764,8 +764,8 @@ pub const PackageManifest = struct {
switch (bin.expr.data) {
.e_object => |obj| {
if (obj.properties.len > 0) {
- string_builder.count(obj.properties[0].key.?.asString(allocator) orelse break :bin);
- string_builder.count(obj.properties[0].value.?.asString(allocator) orelse break :bin);
+ string_builder.count(obj.properties.ptr[0].key.?.asString(allocator) orelse break :bin);
+ string_builder.count(obj.properties.ptr[0].value.?.asString(allocator) orelse break :bin);
}
},
.e_string => {
@@ -792,7 +792,7 @@ pub const PackageManifest = struct {
if (prop.value.?.asProperty(pair.prop)) |versioned_deps| {
if (versioned_deps.expr.data == .e_object) {
dependency_sum += versioned_deps.expr.data.e_object.properties.len;
- const properties = versioned_deps.expr.data.e_object.properties;
+ const properties = versioned_deps.expr.data.e_object.properties.slice();
for (properties) |property| {
if (property.key.?.asString(allocator)) |key| {
string_builder.count(key);
@@ -811,7 +811,7 @@ pub const PackageManifest = struct {
var dist_tags_count: usize = 0;
if (json.asProperty("dist-tags")) |dist| {
if (dist.expr.data == .e_object) {
- const tags = dist.expr.data.e_object.properties;
+ const tags = dist.expr.data.e_object.properties.slice();
for (tags) |tag| {
if (tag.key.?.asString(allocator)) |key| {
string_builder.count(key);
@@ -890,7 +890,7 @@ pub const PackageManifest = struct {
if (json.asProperty("versions")) |versions_q| {
if (versions_q.expr.data != .e_object) break :get_versions;
- const versions = versions_q.expr.data.e_object.properties;
+ const versions = versions_q.expr.data.e_object.properties.slice();
var all_dependency_names_and_values = all_extern_strings[0..dependency_sum];
@@ -926,9 +926,10 @@ pub const PackageManifest = struct {
switch (cpu.expr.data) {
.e_array => |arr| {
- if (arr.items.len > 0) {
+ const items = arr.slice();
+ if (items.len > 0) {
package_version.cpu = Architecture.none;
- for (arr.items) |item| {
+ for (items) |item| {
if (item.asString(allocator)) |cpu_str_| {
package_version.cpu = package_version.cpu.apply(cpu_str_);
}
@@ -947,9 +948,10 @@ pub const PackageManifest = struct {
switch (os.expr.data) {
.e_array => |arr| {
- if (arr.items.len > 0) {
+ const items = arr.slice();
+ if (items.len > 0) {
package_version.os = OperatingSystem.none;
- for (arr.items) |item| {
+ for (items) |item| {
if (item.asString(allocator)) |cpu_str_| {
package_version.os = package_version.os.apply(cpu_str_);
}
@@ -967,9 +969,9 @@ pub const PackageManifest = struct {
if (prop.value.?.asProperty("bin")) |bin| {
switch (bin.expr.data) {
.e_object => |obj| {
- if (obj.properties.len > 0) {
- const bin_name = obj.properties[0].key.?.asString(allocator) orelse break :bin;
- const value = obj.properties[0].value.?.asString(allocator) orelse break :bin;
+ if (obj.properties.slice().len > 0) {
+ const bin_name = obj.properties.ptr[0].key.?.asString(allocator) orelse break :bin;
+ const value = obj.properties.ptr[0].value.?.asString(allocator) orelse break :bin;
// For now, we're only supporting the first bin
// We'll fix that later
package_version.bin = Bin{
@@ -1057,7 +1059,7 @@ pub const PackageManifest = struct {
inline for (dependency_groups) |pair| {
if (prop.value.?.asProperty(comptime pair.prop)) |versioned_deps| {
- const items = versioned_deps.expr.data.e_object.properties;
+ const items = versioned_deps.expr.data.e_object.properties.slice();
var count = items.len;
var this_names = dependency_names[0..count];
@@ -1073,7 +1075,7 @@ pub const PackageManifest = struct {
if (prop.value.?.asProperty("peerDependenciesMeta")) |meta| {
if (meta.expr.data == .e_object) {
- const meta_props = meta.expr.data.e_object.properties;
+ const meta_props = meta.expr.data.e_object.properties.slice();
try optional_peer_dep_names.ensureUnusedCapacity(meta_props.len);
for (meta_props) |meta_prop| {
if (meta_prop.value.?.asProperty("optional")) |optional| {
@@ -1246,7 +1248,7 @@ pub const PackageManifest = struct {
if (json.asProperty("dist-tags")) |dist| {
if (dist.expr.data == .e_object) {
- const tags = dist.expr.data.e_object.properties;
+ const tags = dist.expr.data.e_object.properties.slice();
var extern_strings_slice = extern_strings[0..dist_tags_count];
var dist_tag_i: usize = 0;
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 28f0dad85..a78650266 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -184,7 +184,94 @@ pub const BindingNodeIndex = Binding;
pub const StmtNodeIndex = Stmt;
pub const ExprNodeIndex = Expr;
-pub const ExprNodeList = []Expr;
+pub fn BabyList(comptime Type: type) type {
+ return struct {
+ const ListType = @This();
+ ptr: [*]Type = undefined,
+ len: u32 = 0,
+ cap: u32 = 0,
+
+ pub inline fn init(items: []const Type) ListType {
+ @setRuntimeSafety(false);
+ return ListType{
+ // Remove the const qualifier from the items
+ .ptr = @intToPtr([*]Type, @ptrToInt(items.ptr)),
+
+ .len = @truncate(u32, items.len),
+ .cap = @truncate(u32, items.len),
+ };
+ }
+
+ pub inline fn fromList(list_: anytype) ListType {
+ @setRuntimeSafety(false);
+
+ if (comptime Environment.allow_assert) {
+ std.debug.assert(list_.items.len <= list_.capacity);
+ }
+
+ return ListType{
+ .ptr = list_.items.ptr,
+ .len = @truncate(u32, list_.items.len),
+ .cap = @truncate(u32, list_.capacity),
+ };
+ }
+
+ pub fn update(this: *ListType, list_: anytype) void {
+ @setRuntimeSafety(false);
+ this.ptr = list_.items.ptr;
+ this.len = @truncate(u32, list_.items.len);
+ this.cap = @truncate(u32, list_.capacity);
+
+ if (comptime Environment.allow_assert) {
+ std.debug.assert(this.len <= this.cap);
+ }
+ }
+
+ pub fn list(this: ListType) std.ArrayListUnmanaged(Type) {
+ return std.ArrayListUnmanaged(Type){
+ .items = this.ptr[0..this.len],
+ .capacity = this.cap,
+ };
+ }
+
+ pub inline fn first(this: ListType) ?*Type {
+ return if (this.len > 0) this.ptr[0] else @as(?*Type, null);
+ }
+
+ pub inline fn first_(this: ListType) Type {
+ return this.ptr[0];
+ }
+
+ pub fn one(allocator: std.mem.Allocator, value: Type) !ListType {
+ var items = try allocator.alloc(Type, 1);
+ items[0] = value;
+ return ListType{
+ .ptr = @ptrCast([*]Type, items.ptr),
+ .len = 1,
+ .cap = 1,
+ };
+ }
+
+ pub inline fn @"[0]"(this: ListType) Type {
+ return this.ptr[0];
+ }
+
+ pub fn push(this: *ListType, allocator: std.mem.Allocator, value: Type) !void {
+ var list_ = this.list();
+ try list_.append(allocator, value);
+ this.update(list_);
+ }
+
+ pub inline fn slice(this: ListType) []Type {
+ @setRuntimeSafety(false);
+ return this.ptr[0..this.len];
+ }
+ };
+}
+
+/// Slice that stores capacity and length in the same space as a regular slice.
+pub const ExprNodeList = BabyList(Expr);
+
pub const StmtNodeList = []Stmt;
pub const BindingNodeList = []Binding;
@@ -309,7 +396,7 @@ pub const Binding = struct {
};
}
- return Expr.init(E.Array, E.Array{ .items = exprs, .is_single_line = b.is_single_line }, loc);
+ return Expr.init(E.Array, E.Array{ .items = ExprNodeList.init(exprs), .is_single_line = b.is_single_line }, loc);
},
.b_object => |b| {
var properties = wrapper.allocator.alloc(G.Property, b.properties.len) catch unreachable;
@@ -323,7 +410,7 @@ pub const Binding = struct {
.initializer = item.default_value,
};
}
- return Expr.init(E.Object, E.Object{ .properties = properties, .is_single_line = b.is_single_line }, loc);
+ return Expr.init(E.Object, E.Object{ .properties = G.Property.List.init(properties), .is_single_line = b.is_single_line }, loc);
},
else => {
Global.panic("Interanl error", .{});
@@ -475,7 +562,7 @@ pub const G = struct {
pub const Class = struct {
class_keyword: logger.Range = logger.Range.None,
- ts_decorators: ExprNodeList = &([_]Expr{}),
+ ts_decorators: ExprNodeList = ExprNodeList{},
class_name: ?LocRef = null,
extends: ?ExprNodeIndex = null,
body_loc: logger.Loc = logger.Loc.Empty,
@@ -486,7 +573,7 @@ pub const G = struct {
pub const Comment = struct { loc: logger.Loc, text: string };
pub const Property = struct {
- ts_decorators: ExprNodeList = &([_]ExprNodeIndex{}),
+ ts_decorators: ExprNodeList = ExprNodeList{},
// Key is optional for spread
key: ?ExprNodeIndex = null,
@@ -506,6 +593,8 @@ pub const G = struct {
kind: Kind = Kind.normal,
flags: Flags.Property = Flags.Property.None,
+ pub const List = BabyList(Property);
+
pub const Kind = enum(u2) {
normal,
get,
@@ -534,7 +623,7 @@ pub const G = struct {
flags: Flags.Function = Flags.Function.None,
};
pub const Arg = struct {
- ts_decorators: ExprNodeList = &([_]Expr{}),
+ ts_decorators: ExprNodeList = ExprNodeList{},
binding: BindingNodeIndex,
default: ?ExprNodeIndex = null,
@@ -868,10 +957,14 @@ pub const OptionalChain = enum(u2) {
pub const E = struct {
pub const Array = struct {
- items: ExprNodeList,
+ items: ExprNodeList = ExprNodeList{},
comma_after_spread: ?logger.Loc = null,
is_single_line: bool = false,
is_parenthesized: bool = false,
+
+ pub inline fn slice(this: Array) []Expr {
+ return this.items.slice();
+ }
};
pub const Unary = struct {
@@ -892,7 +985,7 @@ pub const E = struct {
pub const Undefined = struct {};
pub const New = struct {
target: ExprNodeIndex,
- args: ExprNodeList,
+ args: ExprNodeList = ExprNodeList{},
// True if there is a comment containing "@__PURE__" or "#__PURE__" preceding
// this call expression. See the comment inside ECall for more details.
@@ -904,7 +997,7 @@ pub const E = struct {
pub const Call = struct {
// Node:
target: ExprNodeIndex,
- args: ExprNodeList = &([_]ExprNodeIndex{}),
+ args: ExprNodeList = ExprNodeList{},
optional_chain: ?OptionalChain = null,
is_direct_eval: bool = false,
@@ -1063,11 +1156,11 @@ pub const E = struct {
/// null represents a fragment
tag: ?ExprNodeIndex = null,
- /// props
- properties: []G.Property = &([_]G.Property{}),
+ /// JSX props
+ properties: G.Property.List = G.Property.List{},
- /// element children
- children: ExprNodeList = &([_]ExprNodeIndex{}),
+ /// JSX element children <div>{this_is_a_child_element}</div>
+ children: ExprNodeList = ExprNodeList{},
/// key is the key prop like <ListItem key="foo">
key: ?ExprNodeIndex = null,
@@ -1128,17 +1221,35 @@ pub const E = struct {
};
pub const Object = struct {
- properties: []G.Property = &[_]G.Property{},
+ properties: G.Property.List = G.Property.List{},
comma_after_spread: ?logger.Loc = null,
is_single_line: bool = false,
is_parenthesized: bool = false,
+ pub fn asProperty(obj: *const Object, name: string) ?Expr.Query {
+ for (obj.properties.slice()) |prop, i| {
+ const value = prop.value orelse continue;
+ const key = prop.key orelse continue;
+ if (std.meta.activeTag(key.data) != .e_string) continue;
+ const key_str = key.data.e_string;
+ if (key_str.eql(string, name)) {
+ return Expr.Query{
+ .expr = value,
+ .loc = key.loc,
+ .i = @truncate(u32, i),
+ };
+ }
+ }
+
+ return null;
+ }
+
pub fn alphabetizeProperties(this: *Object) void {
- std.sort.sort(G.Property, this.properties, void{}, Sorter.isLessThan);
+ std.sort.sort(G.Property, this.properties.slice(), void{}, Sorter.isLessThan);
}
pub fn packageJSONSort(this: *Object) void {
- std.sort.sort(G.Property, this.properties, void{}, PackageJSONSort.Fields.isLessThan);
+ std.sort.sort(G.Property, this.properties.slice(), void{}, PackageJSONSort.Fields.isLessThan);
}
const PackageJSONSort = struct {
@@ -1721,7 +1832,7 @@ pub const Expr = struct {
const obj = expr.data.e_object;
if (@ptrToInt(obj.properties.ptr) == 0) return false;
- for (obj.properties) |prop| {
+ for (obj.properties.slice()) |prop| {
if (prop.value == null) continue;
const key = prop.key orelse continue;
if (std.meta.activeTag(key.data) != .e_string) continue;
@@ -1742,21 +1853,7 @@ pub const Expr = struct {
const obj = expr.data.e_object;
if (@ptrToInt(obj.properties.ptr) == 0) return null;
- for (obj.properties) |prop, i| {
- const value = prop.value orelse continue;
- const key = prop.key orelse continue;
- if (std.meta.activeTag(key.data) != .e_string) continue;
- const key_str = key.data.e_string;
- if (key_str.eql(string, name)) {
- return Query{
- .expr = value,
- .loc = key.loc,
- .i = @truncate(u32, i),
- };
- }
- }
-
- return null;
+ return obj.asProperty(name);
}
pub const ArrayIterator = struct {
@@ -1768,7 +1865,7 @@ pub const Expr = struct {
return null;
}
defer this.index += 1;
- return this.array.items[this.index];
+ return this.array.items.ptr[this.index];
}
};
@@ -4099,7 +4196,7 @@ pub const Macro = struct {
var slice = temporary_call_args_array[0..args.len];
for (slice) |_, i| {
var node = JSCBase.getAllocator(ctx).create(JSNode) catch unreachable;
- node.* = JSNode.initExpr(args[i]);
+ node.* = JSNode.initExpr(args.ptr[i]);
slice[i] = JSNode.Class.make(ctx, node);
}
return js.JSObjectMakeArray(ctx, args.len, slice.ptr, exception);
@@ -4135,7 +4232,7 @@ pub const Macro = struct {
_: js.JSStringRef,
exception: js.ExceptionRef,
) js.JSObjectRef {
- const args = if (this.data == .e_object) this.data.e_object.properties else &[_]G.Property{};
+ const args = if (this.data == .e_object) this.data.e_object.properties.slice() else &[_]G.Property{};
switch (args.len) {
0 => return js.JSObjectMakeArray(ctx, 0, null, exception),
@@ -4198,31 +4295,34 @@ pub const Macro = struct {
}
fn toArrayValue(_: *JSNode, ctx: js.JSContextRef, array: E.Array, exception: js.ExceptionRef) js.JSObjectRef {
- if (array.items.len == 0) {
+ const items = array.slice();
+
+ if (items.len == 0) {
return js.JSObjectMakeArray(ctx, 0, null, exception);
}
- for (array.items) |expr, i| {
+ for (items) |expr, i| {
var node = JSCBase.getAllocator(ctx).create(JSNode) catch unreachable;
node.* = JSNode.initExpr(expr);
temporary_call_args_array[i] = JSNode.Class.make(ctx, node);
}
- return js.JSObjectMakeArray(ctx, array.items.len, &temporary_call_args_array, exception);
+ return js.JSObjectMakeArray(ctx, items.len, &temporary_call_args_array, exception);
}
fn toArrayPrimitive(_: *JSNode, ctx: js.JSContextRef, array: E.Array, exception: js.ExceptionRef) js.JSObjectRef {
- if (array.items.len == 0) {
+ const items = array.slice();
+ if (items.len == 0) {
return js.JSObjectMakeArray(ctx, 0, null, exception);
}
var node: JSNode = undefined;
- for (array.items) |expr, i| {
+ for (items) |expr, i| {
node = JSNode.initExpr(expr);
temporary_call_args_array[i] = toPrimitive(&node, ctx, exception);
}
- return js.JSObjectMakeArray(ctx, array.items.len, temporary_call_args_array[0..array.items.len].ptr, exception);
+ return js.JSObjectMakeArray(ctx, items.len, temporary_call_args_array[0..items.len].ptr, exception);
}
fn toObjectValue(this: *JSNode, ctx: js.JSContextRef, obj: E.Object, exception: js.ExceptionRef) js.JSObjectRef {
@@ -4242,11 +4342,11 @@ pub const Macro = struct {
defer if (did_allocate) getAllocator(ctx).free(properties_list);
- for (obj.properties) |_, i| {
+ for (obj.properties.slice()) |_, i| {
var node = JSCBase.getAllocator(ctx).create(JSNode) catch unreachable;
node.* = JSNode{
.data = .{
- .g_property = &obj.properties[i],
+ .g_property = &obj.properties.ptr[i],
},
.loc = this.loc,
};
@@ -4781,7 +4881,7 @@ pub const Macro = struct {
if (this == .e_call)
return this.e_call.args
else
- return &[_]Expr{};
+ return ExprNodeList{};
}
pub fn booleanValue(this: Data) bool {
@@ -5750,8 +5850,14 @@ pub const Macro = struct {
.e_string => {
self.p.recordUsage(self.bun_jsx_ref);
_ = self.writeElement(element);
- var call_args = self.p.allocator.alloc(Expr, 1) catch unreachable;
- call_args[0] = Expr.init(E.Array, E.Array{ .items = self.args.items }, tag_expr.loc);
+ var call_args = ExprNodeList.one(
+ self.allocator,
+ Expr.init(
+ E.Array,
+ E.Array{ .items = ExprNodeList.fromList(self.args) },
+ tag_expr.loc,
+ ),
+ ) catch unreachable;
return Expr.init(
E.Call,
@@ -5773,9 +5879,11 @@ pub const Macro = struct {
} else {
const loc = logger.Loc.Empty;
self.p.recordUsage(self.bun_jsx_ref);
- _ = self.writeNodeType(JSNode.Tag.fragment, element.properties, element.children, loc);
- var call_args = self.p.allocator.alloc(Expr, 1) catch unreachable;
- call_args[0] = Expr.init(E.Array, E.Array{ .items = self.args.items }, loc);
+ _ = self.writeNodeType(JSNode.Tag.fragment, element.properties.slice(), element.children.slice(), loc);
+ var call_args = ExprNodeList.one(
+ self.allocator,
+ Expr.init(E.Array, E.Array{ .items = ExprNodeList.init(self.args.items) }, loc),
+ ) catch unreachable;
return Expr.init(
E.Call,
@@ -5815,7 +5923,7 @@ pub const Macro = struct {
self.log.addErrorFmt(p.source, tag_expr.loc, p.allocator, "Tag \"{s}\" is invalid here", .{str.utf8}) catch unreachable;
}
- return self.writeNodeType(node_type, element.properties, element.children, tag_expr.loc);
+ return self.writeNodeType(node_type, element.properties.slice(), element.children.slice(), tag_expr.loc);
}
pub fn writeElement(self: *JSXWriter, element: E.JSXElement) bool {
@@ -5833,7 +5941,7 @@ pub const Macro = struct {
return false;
};
- return self.writeNodeType(node_type, element.properties, element.children, tag_expr.loc);
+ return self.writeNodeType(node_type, element.properties.slice(), element.children.slice(), tag_expr.loc);
}
};
}
@@ -6210,7 +6318,8 @@ pub const Macro = struct {
}
}
}
- expr.* = Expr.init(E.Array, E.Array{ .items = items.items[0..i] }, writer.loc);
+ items.items = items.items[0..i];
+ expr.* = Expr.init(E.Array, E.Array{ .items = ExprNodeList.fromList(items) }, writer.loc);
return true;
},
.e_boolean => {
@@ -6587,7 +6696,7 @@ pub const Macro = struct {
var this: *LazyPropertiesObject = JSCBase.GetJSPrivateData(LazyPropertiesObject, thisObject) orelse return null;
const len = js.JSStringGetLength(propertyName);
- const properties = this.node.data.e_object.properties;
+ const properties = this.node.data.e_object.properties.slice();
var ptr = js.JSStringGetCharacters8Ptr(propertyName);
var property_slice = ptr[0..len];
var value_node: JSNode = undefined;
@@ -6615,7 +6724,7 @@ pub const Macro = struct {
var this: *LazyPropertiesObject = JSCBase.GetJSPrivateData(LazyPropertiesObject, thisObject) orelse return false;
const len = js.JSStringGetLength(propertyName);
- const properties = this.node.data.e_object.properties;
+ const properties = this.node.data.e_object.properties.slice();
var ptr = js.JSStringGetCharacters8Ptr(propertyName);
var property_slice = ptr[0..len];
@@ -6637,7 +6746,7 @@ pub const Macro = struct {
) callconv(.C) void {
var this: *LazyPropertiesObject = JSCBase.GetJSPrivateData(LazyPropertiesObject, thisObject) orelse return;
- const properties = this.node.data.e_object.properties;
+ const properties = this.node.data.e_object.properties.slice();
for (properties) |property| {
const key = property.key orelse continue;
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig
index 0921c5970..290c48ce1 100644
--- a/src/js_parser/js_parser.zig
+++ b/src/js_parser/js_parser.zig
@@ -1016,7 +1016,7 @@ pub const SideEffects = enum(u2) {
// can be removed. The annotation causes us to ignore the target.
if (call.can_be_unwrapped_if_unused) {
if (call.args.len > 0) {
- return Expr.joinAllWithCommaCallback(call.args, @TypeOf(p), p, simpifyUnusedExpr, p.allocator);
+ return Expr.joinAllWithCommaCallback(call.args.slice(), @TypeOf(p), p, simpifyUnusedExpr, p.allocator);
}
}
},
@@ -1065,7 +1065,7 @@ pub const SideEffects = enum(u2) {
// can be removed. The annotation causes us to ignore the target.
if (call.can_be_unwrapped_if_unused) {
if (call.args.len > 0) {
- return Expr.joinAllWithComma(call.args, p.allocator);
+ return Expr.joinAllWithComma(call.args.slice(), p.allocator);
}
}
},
@@ -3315,8 +3315,8 @@ pub fn NewParser(
switch (call.target.data) {
.e_identifier => |ident| {
// is this a require("something")
- if (strings.eqlComptime(p.loadNameFromRef(ident.ref), "require") and call.args.len == 1 and std.meta.activeTag(call.args[0].data) == .e_string) {
- _ = p.addImportRecord(.require, loc, call.args[0].data.e_string.string(p.allocator) catch unreachable);
+ if (strings.eqlComptime(p.loadNameFromRef(ident.ref), "require") and call.args.len == 1 and std.meta.activeTag(call.args.ptr[0].data) == .e_string) {
+ _ = p.addImportRecord(.require, loc, call.args.@"[0]"().data.e_string.string(p.allocator) catch unreachable);
}
},
else => {},
@@ -3331,8 +3331,8 @@ pub fn NewParser(
switch (call.target.data) {
.e_identifier => |ident| {
// is this a require("something")
- if (strings.eqlComptime(p.loadNameFromRef(ident.ref), "require") and call.args.len == 1 and std.meta.activeTag(call.args[0].data) == .e_string) {
- _ = p.addImportRecord(.require, loc, call.args[0].data.e_string.string(p.allocator) catch unreachable);
+ if (strings.eqlComptime(p.loadNameFromRef(ident.ref), "require") and call.args.len == 1 and std.meta.activeTag(call.args.ptr[0].data) == .e_string) {
+ _ = p.addImportRecord(.require, loc, call.args.@"[0]"().data.e_string.string(p.allocator) catch unreachable);
}
},
else => {},
@@ -4029,8 +4029,8 @@ pub fn NewParser(
// p.markSyntaxFeature(Destructing)
var items = List(js_ast.ArrayBinding).initCapacity(p.allocator, ex.items.len) catch unreachable;
var is_spread = false;
- for (ex.items) |_, i| {
- var item = ex.items[i];
+ for (ex.items.slice()) |_, i| {
+ var item = ex.items.ptr[i];
if (item.data == .e_spread) {
is_spread = true;
item = item.data.e_spread.value;
@@ -4064,7 +4064,7 @@ pub fn NewParser(
// p.markSyntaxFeature(compat.Destructuring, p.source.RangeOfOperatorAfter(expr.Loc, "{"))
var properties = List(B.Property).initCapacity(p.allocator, ex.properties.len) catch unreachable;
- for (ex.properties) |item| {
+ for (ex.properties.slice()) |item| {
if (item.flags.is_method or item.kind == .get or item.kind == .set) {
invalid_loc.append(item.key.?.loc) catch unreachable;
continue;
@@ -4388,7 +4388,7 @@ pub fn NewParser(
}
args.append(p.allocator, G.Arg{
- .ts_decorators = ts_decorators,
+ .ts_decorators = ExprNodeList.init(ts_decorators),
.binding = arg,
.default = default_value,
@@ -6801,8 +6801,7 @@ pub fn NewParser(
const path = p.e(p.lexer.toEString(), p.lexer.loc());
try p.lexer.expect(.t_string_literal);
try p.lexer.expect(.t_close_paren);
- const args = p.allocator.alloc(ExprNodeIndex, 1) catch unreachable;
- args[0] = path;
+ const args = try ExprNodeList.one(p.allocator, path);
value.data = .{ .e_call = Expr.Data.Store.All.append(E.Call, E.Call{ .target = value, .args = args }) };
} else {
// "import Foo = Bar"
@@ -8521,7 +8520,7 @@ pub fn NewParser(
try p.lexer.expectOrInsertSemicolon();
return G.Property{
- .ts_decorators = opts.ts_decorators,
+ .ts_decorators = ExprNodeList.init(opts.ts_decorators),
.kind = kind,
.flags = Flags.Property{
.is_computed = is_computed,
@@ -8652,7 +8651,7 @@ pub fn NewParser(
}
return G.Property{
- .ts_decorators = opts.ts_decorators,
+ .ts_decorators = ExprNodeList.init(opts.ts_decorators),
.kind = kind,
.flags = Flags.Property{
.is_computed = is_computed,
@@ -8669,7 +8668,6 @@ pub fn NewParser(
const value = try p.parseExprOrBindings(.comma, errors);
return G.Property{
- .ts_decorators = &[_]Expr{},
.kind = kind,
.flags = Flags.Property{
.is_computed = is_computed,
@@ -8774,7 +8772,7 @@ pub fn NewParser(
return G.Class{
.class_name = name,
.extends = extends,
- .ts_decorators = class_opts.ts_decorators,
+ .ts_decorators = ExprNodeList.init(class_opts.ts_decorators),
.class_keyword = class_keyword,
.body_loc = body_loc,
.properties = properties.toOwnedSlice(),
@@ -8847,7 +8845,7 @@ pub fn NewParser(
return expr;
}
- pub fn parseCallArgs(p: *P) anyerror![]Expr {
+ pub fn parseCallArgs(p: *P) anyerror!ExprNodeList {
// Allow "in" inside call arguments
const old_allow_in = p.allow_in;
p.allow_in = true;
@@ -8875,7 +8873,7 @@ pub fn NewParser(
}
try p.lexer.expect(.t_close_paren);
- return args.toOwnedSlice();
+ return ExprNodeList.fromList(args);
}
pub fn parseSuffix(p: *P, left: Expr, level: Level, errors: ?*DeferredErrors, flags: Expr.EFlags) anyerror!Expr {
@@ -10042,7 +10040,7 @@ pub fn NewParser(
}
const target = try p.parseExprWithFlags(.member, flags);
- var args: []Expr = &([_]Expr{});
+ var args = ExprNodeList{};
if (is_typescript_enabled) {
// Skip over TypeScript non-null assertions
@@ -10131,7 +10129,7 @@ pub fn NewParser(
self_errors.mergeInto(errors);
}
return p.e(E.Array{
- .items = items.toOwnedSlice(),
+ .items = ExprNodeList.fromList(items),
.comma_after_spread = comma_after_spread.toNullable(),
.is_single_line = is_single_line,
}, loc);
@@ -10194,7 +10192,7 @@ pub fn NewParser(
self_errors.mergeInto(errors);
}
return p.e(E.Object{
- .properties = properties.toOwnedSlice(),
+ .properties = G.Property.List.fromList(properties),
.comma_after_spread = comma_after_spread.toNullable(),
.is_single_line = is_single_line,
}, loc);
@@ -10477,7 +10475,7 @@ pub fn NewParser(
}
var previous_string_with_backslash_loc = logger.Loc{};
- var properties: []G.Property = &([_]G.Property{});
+ var properties = G.Property.List{};
var key_prop: ?ExprNodeIndex = null;
var flags = Flags.JSXElement{};
var start_tag: ?ExprNodeIndex = null;
@@ -10551,7 +10549,7 @@ pub fn NewParser(
try p.log.addWarning(p.source, spread_loc, "\"key\" prop before a {...spread} is deprecated in JSX. Falling back to classic runtime.");
p.has_classic_runtime_warned = true;
}
- properties = props.toOwnedSlice();
+ properties = G.Property.List.fromList(props);
}
// People sometimes try to use the output of "JSON.stringify()" as a JSX
@@ -10650,7 +10648,7 @@ pub fn NewParser(
return p.e(E.JSXElement{
.tag = end_tag.data.asExpr(),
- .children = children.toOwnedSlice(),
+ .children = ExprNodeList.fromList(children),
.properties = properties,
.key = key_prop,
.flags = flags,
@@ -11103,17 +11101,17 @@ pub fn NewParser(
}
};
- for (e_.properties) |property, i| {
+ for (e_.properties.slice()) |property, i| {
if (property.kind != .spread) {
- e_.properties[i].key = p.visitExpr(e_.properties[i].key.?);
+ e_.properties.ptr[i].key = p.visitExpr(e_.properties.ptr[i].key.?);
}
if (property.value != null) {
- e_.properties[i].value = p.visitExpr(e_.properties[i].value.?);
+ e_.properties.ptr[i].value = p.visitExpr(e_.properties.ptr[i].value.?);
}
if (property.initializer != null) {
- e_.properties[i].initializer = p.visitExpr(e_.properties[i].initializer.?);
+ e_.properties.ptr[i].initializer = p.visitExpr(e_.properties.ptr[i].initializer.?);
}
}
@@ -11148,9 +11146,9 @@ pub fn NewParser(
if (e_.properties.len > 0) {
if (e_.key) |key| {
var props = p.allocator.alloc(G.Property, e_.properties.len + 1) catch unreachable;
- std.mem.copy(G.Property, props, e_.properties);
+ std.mem.copy(G.Property, props, e_.properties.slice());
props[props.len - 1] = G.Property{ .key = Expr{ .loc = key.loc, .data = keyExprData }, .value = key };
- args[1] = p.e(E.Object{ .properties = props }, expr.loc);
+ args[1] = p.e(E.Object{ .properties = G.Property.List.init(props) }, expr.loc);
} else {
args[1] = p.e(E.Object{ .properties = e_.properties }, expr.loc);
}
@@ -11160,7 +11158,7 @@ pub fn NewParser(
i = 2;
}
- for (e_.children[0..children_count]) |child| {
+ for (e_.children.slice()[0..children_count]) |child| {
args[i] = p.visitExpr(child);
i += @intCast(usize, @boolToInt(args[i].data != .e_missing));
}
@@ -11168,7 +11166,7 @@ pub fn NewParser(
// Call createElement()
return p.e(E.Call{
.target = p.jsxStringsToMemberExpression(expr.loc, p.jsx_factory.ref),
- .args = args[0..i],
+ .args = ExprNodeList.init(args[0..i]),
// Enable tree shaking
.can_be_unwrapped_if_unused = !p.options.ignore_dce_annotations,
}, expr.loc);
@@ -11181,7 +11179,8 @@ pub fn NewParser(
const include_filename = FeatureFlags.include_filename_in_jsx and p.options.jsx.development;
const args = p.allocator.alloc(Expr, if (p.options.jsx.development) @as(usize, 6) else @as(usize, 4)) catch unreachable;
args[0] = tag;
- var props = ListManaged(G.Property).fromOwnedSlice(p.allocator, e_.properties);
+ const allocator = p.allocator;
+ var props = e_.properties.list();
// arguments needs to be like
// {
// ...props,
@@ -11189,13 +11188,13 @@ pub fn NewParser(
// }
{
- var last_child: usize = 0;
- for (e_.children[0..children_count]) |child| {
- e_.children[last_child] = p.visitExpr(child);
+ var last_child: u32 = 0;
+ for (e_.children.ptr[0..children_count]) |child| {
+ e_.children.ptr[last_child] = p.visitExpr(child);
// if tree-shaking removes the element, we must also remove it here.
- last_child += @intCast(usize, @boolToInt(e_.children[last_child].data != .e_missing));
+ last_child += @intCast(u32, @boolToInt(e_.children.ptr[last_child].data != .e_missing));
}
- e_.children = e_.children[0..last_child];
+ e_.children.len = last_child;
}
const children_key = Expr{ .data = jsxChildrenKeyData, .loc = expr.loc };
@@ -11207,13 +11206,13 @@ pub fn NewParser(
switch (e_.children.len) {
0 => {},
1 => {
- props.append(G.Property{
+ props.append(allocator, G.Property{
.key = children_key,
- .value = e_.children[0],
+ .value = e_.children.ptr[0],
}) catch unreachable;
},
else => {
- props.append(G.Property{
+ props.append(allocator, G.Property{
.key = children_key,
.value = p.e(E.Array{
.items = e_.children,
@@ -11224,7 +11223,7 @@ pub fn NewParser(
}
args[1] = p.e(E.Object{
- .properties = props.toOwnedSlice(),
+ .properties = G.Property.List.fromList(props),
}, expr.loc);
if (e_.key) |key| {
@@ -11274,7 +11273,7 @@ pub fn NewParser(
// .value = p.e(E.Number{ .value = @intToFloat(f64, expr.loc.start) }, expr.loc),
// };
args[4] = p.e(E.Object{
- .properties = source,
+ .properties = G.Property.List.init(source),
}, expr.loc);
// When disabled, this must specifically be undefined
@@ -11294,7 +11293,7 @@ pub fn NewParser(
return p.e(E.Call{
.target = p.jsxStringsToMemberExpressionAutomatic(expr.loc, is_static_jsx),
- .args = args,
+ .args = ExprNodeList.init(args),
// Enable tree shaking
.can_be_unwrapped_if_unused = !p.options.ignore_dce_annotations,
.was_jsx_element = true,
@@ -11465,7 +11464,7 @@ pub fn NewParser(
},
expr.loc,
),
- .args = call_args,
+ .args = ExprNodeList.init(call_args),
.can_be_unwrapped_if_unused = true,
},
expr.loc,
@@ -12061,8 +12060,8 @@ pub fn NewParser(
p.log.addRangeError(p.source, logger.Range{ .loc = spread, .len = 1 }, "Unexpected \",\" after rest pattern") catch unreachable;
}
}
-
- for (e_.items) |*item| {
+ var items = e_.items.slice();
+ for (items) |*item| {
switch (item.data) {
.e_missing => {},
.e_spread => |spread| {
@@ -12100,7 +12099,7 @@ pub fn NewParser(
var has_proto = false;
var i: usize = 0;
while (i < e_.properties.len) : (i += 1) {
- var property = &e_.properties[i];
+ var property = e_.properties.ptr[i];
if (property.kind != .spread) {
property.key = p.visitExpr(property.key orelse Global.panic("Expected property key", .{}));
@@ -12216,9 +12215,9 @@ pub fn NewParser(
if (is_macro_ref)
p.options.ignore_dce_annotations = true;
- for (e_.args) |_, i| {
- const arg = e_.args[i];
- e_.args[i] = p.visitExpr(arg);
+ for (e_.args.slice()) |_, i| {
+ const arg = e_.args.ptr[i];
+ e_.args.ptr[i] = p.visitExpr(arg);
}
}
@@ -12227,7 +12226,7 @@ pub fn NewParser(
// the try/catch statement is there to handle the potential run-time
// error from the unbundled require() call failing.
if (e_.args.len == 1) {
- return p.require_transposer.maybeTransposeIf(e_.args[0], null);
+ return p.require_transposer.maybeTransposeIf(e_.args.first_(), null);
} else if (p.options.warn_about_unbundled_modules) {
const r = js_lexer.rangeOfIdentifier(p.source, e_.target.loc);
p.log.addRangeDebug(p.source, r, "This call to \"require\" will not be bundled because it has multiple arguments") catch unreachable;
@@ -12274,7 +12273,7 @@ pub fn NewParser(
e_.target = p.visitExpr(e_.target);
// p.warnA
- for (e_.args) |*arg| {
+ for (e_.args.slice()) |*arg| {
arg.* = p.visitExpr(arg.*);
}
},
@@ -12375,7 +12374,7 @@ pub fn NewParser(
pub fn visitTSDecorators(p: *P, decs: ExprNodeList) ExprNodeList {
var i: usize = 0;
while (i < decs.len) : (i += 1) {
- decs[i] = p.visitExpr(decs[i]);
+ decs.ptr[i] = p.visitExpr(decs.ptr[i]);
}
return decs;
@@ -12535,7 +12534,7 @@ pub fn NewParser(
return p.exprCanBeRemovedIfUnused(&ex.test_) and p.exprCanBeRemovedIfUnused(&ex.yes) and p.exprCanBeRemovedIfUnused(&ex.no);
},
.e_array => |ex| {
- for (ex.items) |*item| {
+ for (ex.items.slice()) |*item| {
if (!p.exprCanBeRemovedIfUnused(item)) {
return false;
}
@@ -12544,7 +12543,7 @@ pub fn NewParser(
return true;
},
.e_object => |ex| {
- for (ex.properties) |*property| {
+ for (ex.properties.slice()) |*property| {
// The key must still be evaluated if it's computed or a spread
if (property.kind == .spread or property.flags.is_computed or property.flags.is_spread) {
@@ -12564,7 +12563,7 @@ pub fn NewParser(
// A call that has been marked "__PURE__" can be removed if all arguments
// can be removed. The annotation causes us to ignore the target.
if (ex.can_be_unwrapped_if_unused) {
- for (ex.args) |*arg| {
+ for (ex.args.slice()) |*arg| {
if (!p.exprCanBeRemovedIfUnused(arg)) {
return false;
}
@@ -12577,7 +12576,7 @@ pub fn NewParser(
// A call that has been marked "__PURE__" can be removed if all arguments
// can be removed. The annotation causes us to ignore the target.
if (ex.can_be_unwrapped_if_unused) {
- for (ex.args) |*arg| {
+ for (ex.args.slice()) |*arg| {
if (!p.exprCanBeRemovedIfUnused(arg)) {
return false;
}
@@ -13705,7 +13704,7 @@ pub fn NewParser(
},
name_loc,
),
- p.e(E.Object{ .properties = &[_]G.Property{} }, name_loc),
+ p.e(E.Object{}, name_loc),
allocator,
),
},
@@ -13724,7 +13723,7 @@ pub fn NewParser(
.right = Expr.assign(
Expr.initIdentifier(name_ref, name_loc),
p.e(
- E.Object{ .properties = &[_]G.Property{} },
+ E.Object{},
name_loc,
),
allocator,
@@ -13757,7 +13756,7 @@ pub fn NewParser(
const call = p.e(
E.Call{
.target = target,
- .args = args_list,
+ .args = ExprNodeList.init(args_list),
},
stmt_loc,
);
@@ -14258,7 +14257,7 @@ pub fn NewParser(
.target = p.e(E.Identifier{
.ref = ref,
}, loc),
- .args = args,
+ .args = ExprNodeList.init(args),
}, loc);
}
@@ -14535,7 +14534,7 @@ pub fn NewParser(
if (opts.is_async) {
p.logExprErrors(&errors);
const async_expr = p.e(E.Identifier{ .ref = try p.storeNameInRef("async") }, loc);
- return p.e(E.Call{ .target = async_expr, .args = items }, loc);
+ return p.e(E.Call{ .target = async_expr, .args = ExprNodeList.init(items) }, loc);
}
// Is this a chain of expressions and comma operators?
@@ -14709,7 +14708,7 @@ pub fn NewParser(
}
}
- commonjs_wrapper.data.e_call.args[0] = p.e(
+ commonjs_wrapper.data.e_call.args.ptr[0] = p.e(
E.Function{ .func = G.Fn{
.name = null,
.open_parens_loc = logger.Loc.Empty,
@@ -14728,7 +14727,7 @@ pub fn NewParser(
sourcefile_name = sourcefile_name[end..];
}
}
- commonjs_wrapper.data.e_call.args[1] = p.e(E.String{ .utf8 = sourcefile_name }, logger.Loc.Empty);
+ commonjs_wrapper.data.e_call.args.ptr[1] = p.e(E.String{ .utf8 = sourcefile_name }, logger.Loc.Empty);
new_stmts_list[imports_list.len] = p.s(
S.ExportDefault{
@@ -14874,7 +14873,7 @@ pub fn NewParser(
.name_loc = logger.Loc.Empty,
}, logger.Loc.Empty),
- .args = args_list,
+ .args = ExprNodeList.init(args_list),
}, logger.Loc.Empty),
},
logger.Loc.Empty,
@@ -14892,7 +14891,7 @@ pub fn NewParser(
first_decl[0] = G.Decl{
.binding = p.b(B.Identifier{ .ref = p.hmr_module.ref }, logger.Loc.Empty),
.value = p.e(E.New{
- .args = new_call_args,
+ .args = ExprNodeList.init(new_call_args),
.target = p.e(
E.Identifier{
.ref = hmr_import_ref,
@@ -15015,7 +15014,7 @@ pub fn NewParser(
}
var export_all_args = call_args[new_call_args.len..];
export_all_args[0] = p.e(
- E.Object{ .properties = export_properties[0..named_export_i] },
+ E.Object{ .properties = Property.List.init(export_properties[0..named_export_i]) },
logger.Loc.Empty,
);
@@ -15031,7 +15030,7 @@ pub fn NewParser(
},
logger.Loc.Empty,
),
- .args = export_all_args,
+ .args = ExprNodeList.init(export_all_args),
},
logger.Loc.Empty,
),
diff --git a/src/js_printer.zig b/src/js_printer.zig
index b3310eeeb..dd7ec98e5 100644
--- a/src/js_printer.zig
+++ b/src/js_printer.zig
@@ -1152,14 +1152,14 @@ pub fn NewPrinter(
p.print("new");
p.printSpace();
p.printExpr(e.target, .new, ExprFlag.ForbidCall());
-
- if (e.args.len > 0 or level.gte(.postfix)) {
+ const args = e.args.slice();
+ if (args.len > 0 or level.gte(.postfix)) {
p.print("(");
- if (e.args.len > 0) {
- p.printExpr(e.args[0], .comma, ExprFlag.None());
+ if (args.len > 0) {
+ p.printExpr(args[0], .comma, ExprFlag.None());
- for (e.args[1..]) |arg| {
+ for (args[1..]) |arg| {
p.print(",");
p.printSpace();
p.printExpr(arg, .comma, ExprFlag.None());
@@ -1212,10 +1212,11 @@ pub fn NewPrinter(
p.print("?.");
}
p.print("(");
+ const args = e.args.slice();
- if (e.args.len > 0) {
- p.printExpr(e.args[0], .comma, ExprFlag.None());
- for (e.args[1..]) |arg| {
+ if (args.len > 0) {
+ p.printExpr(args[0], .comma, ExprFlag.None());
+ for (args[1..]) |arg| {
p.print(",");
p.printSpace();
p.printExpr(arg, .comma, ExprFlag.None());
@@ -1500,12 +1501,13 @@ pub fn NewPrinter(
},
.e_array => |e| {
p.print("[");
- if (e.items.len > 0) {
+ const items = e.items.slice();
+ if (items.len > 0) {
if (!e.is_single_line) {
p.options.indent += 1;
}
- for (e.items) |item, i| {
+ for (items) |item, i| {
if (i != 0) {
p.print(",");
if (e.is_single_line) {
@@ -1518,7 +1520,7 @@ pub fn NewPrinter(
}
p.printExpr(item, .comma, ExprFlag.None());
- if (i == e.items.len - 1) {
+ if (i == items.len - 1) {
// Make sure there's a comma after trailing missing items
switch (item.data) {
.e_missing => {
@@ -1549,12 +1551,13 @@ pub fn NewPrinter(
p.print("(");
}
p.print("{");
- if (e.properties.len > 0) {
+ const props = e.properties.slice();
+ if (props.len > 0) {
if (!e.is_single_line) {
p.options.indent += 1;
}
- for (e.properties) |property, i| {
+ for (props) |property, i| {
if (i != 0) {
p.print(",");
if (e.is_single_line) {
@@ -1573,7 +1576,7 @@ pub fn NewPrinter(
p.options.unindent();
p.printNewline();
p.printIndent();
- } else if (e.properties.len > 0) {
+ } else if (props.len > 0) {
p.printSpace();
}
}
diff --git a/src/json_parser.zig b/src/json_parser.zig
index ed5e42d85..e8fbde12c 100644
--- a/src/json_parser.zig
+++ b/src/json_parser.zig
@@ -178,7 +178,7 @@ fn JSONLikeParser(opts: js_lexer.JSONOptions) type {
is_single_line = false;
}
try p.lexer.expect(.t_close_bracket);
- return p.e(E.Array{ .items = exprs.items }, loc);
+ return p.e(E.Array{ .items = ExprNodeList.fromList(exprs), .is_single_line = is_single_line }, loc);
},
.t_open_brace => {
try p.lexer.next();
@@ -245,7 +245,7 @@ fn JSONLikeParser(opts: js_lexer.JSONOptions) type {
}
try p.lexer.expect(.t_close_brace);
return p.e(E.Object{
- .properties = properties.items,
+ .properties = G.Property.List.fromList(properties),
.is_single_line = is_single_line,
}, loc);
},
@@ -484,7 +484,7 @@ const DotEnvJSONParser = JSONLikeParser(js_lexer.JSONOptions{
var empty_string = E.String{ .utf8 = "" };
const TSConfigParser = JSONLikeParser(js_lexer.JSONOptions{ .allow_comments = true, .is_json = true, .allow_trailing_commas = true });
var empty_object = E.Object{};
-var empty_array = E.Array{ .items = &[_]ExprNodeIndex{} };
+var empty_array = E.Array{};
var empty_string_data = Expr.Data{ .e_string = &empty_string };
var empty_object_data = Expr.Data{ .e_object = &empty_object };
var empty_array_data = Expr.Data{ .e_array = &empty_array };
diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig
index 1ac221998..bac9c8790 100644
--- a/src/resolver/package_json.zig
+++ b/src/resolver/package_json.zig
@@ -110,7 +110,7 @@ pub const PackageJSON = struct {
allocator: std.mem.Allocator,
) !void {
var valid_count: usize = 0;
- for (json.properties) |prop| {
+ for (json.properties.slice()) |prop| {
if (prop.value.?.data != .e_string) continue;
valid_count += 1;
}
@@ -118,7 +118,7 @@ pub const PackageJSON = struct {
env.defaults.shrinkRetainingCapacity(0);
env.defaults.ensureTotalCapacity(allocator, valid_count) catch {};
- for (json.properties) |prop| {
+ for (json.properties.slice()) |prop| {
if (prop.value.?.data != .e_string) continue;
env.defaults.appendAssumeCapacity(.{
.key = prop.key.?.data.e_string.string(allocator) catch unreachable,
@@ -133,7 +133,7 @@ pub const PackageJSON = struct {
allocator: std.mem.Allocator,
) void {
var valid_count: usize = 0;
- for (json.properties) |prop| {
+ for (json.properties.slice()) |prop| {
if (prop.value.?.data != .e_string) continue;
valid_count += 1;
}
@@ -142,7 +142,7 @@ pub const PackageJSON = struct {
var keys = buffer[0..valid_count];
var values = buffer[valid_count..];
var i: usize = 0;
- for (json.properties) |prop| {
+ for (json.properties.slice()) |prop| {
if (prop.value.?.data != .e_string) continue;
keys[i] = prop.key.?.data.e_string.string(allocator) catch unreachable;
values[i] = prop.value.?.data.e_string.string(allocator) catch unreachable;
@@ -156,7 +156,7 @@ pub const PackageJSON = struct {
json: *const js_ast.E.Object,
allocator: std.mem.Allocator,
) anyerror!void {
- for (json.properties) |prop| {
+ for (json.properties.slice()) |prop| {
switch (prop.key.?.data) {
.e_string => |e_str| {
const str = e_str.string(allocator) catch "";
@@ -332,13 +332,14 @@ pub const PackageJSON = struct {
},
.e_array => |array| {
var count: usize = 0;
- for (array.items) |item| {
+ const items = array.items.slice();
+ for (items) |item| {
count += @boolToInt(item.data == .e_string and item.data.e_string.utf8.len > 0);
}
switch (count) {
0 => {},
1 => {
- const str = array.items[0].data.e_string.string(allocator) catch unreachable;
+ const str = items[0].data.e_string.string(allocator) catch unreachable;
if (str.len > 0) {
pair.router.dir = str;
pair.router.possible_dirs = &[_]string{};
@@ -350,7 +351,7 @@ pub const PackageJSON = struct {
const list = allocator.alloc(string, count) catch unreachable;
var list_i: usize = 0;
- for (array.items) |item| {
+ for (items) |item| {
if (item.data == .e_string and item.data.e_string.utf8.len > 0) {
list[list_i] = item.data.e_string.string(allocator) catch unreachable;
list_i += 1;
@@ -454,7 +455,7 @@ pub const PackageJSON = struct {
var macro_map = MacroMap{};
if (macros.data != .e_object) return macro_map;
- const properties = macros.data.e_object.properties;
+ const properties = macros.data.e_object.properties.slice();
for (properties) |property| {
const key = property.key.?.asString(allocator) orelse continue;
@@ -481,7 +482,7 @@ pub const PackageJSON = struct {
continue;
}
- const remap_properties = value.data.e_object.properties;
+ const remap_properties = value.data.e_object.properties.slice();
if (remap_properties.len == 0) continue;
var map = MacroImportReplacementMap.init(allocator);
@@ -644,7 +645,7 @@ pub const PackageJSON = struct {
// The value is an object
// Remap all files in the browser field
- for (obj.properties) |*prop| {
+ for (obj.properties.slice()) |*prop| {
var _key_str = (prop.key orelse continue).asString(r.allocator) orelse continue;
const value: js_ast.Expr = prop.value orelse continue;
@@ -694,7 +695,7 @@ pub const PackageJSON = struct {
const scripts_obj = scripts_prop.expr.data.e_object;
var count: usize = 0;
- for (scripts_obj.properties) |prop| {
+ for (scripts_obj.properties.slice()) |prop| {
const key = prop.key.?.asString(r.allocator) orelse continue;
const value = prop.value.?.asString(r.allocator) orelse continue;
@@ -705,7 +706,7 @@ pub const PackageJSON = struct {
var scripts = ScriptsMap.init(r.allocator);
scripts.ensureUnusedCapacity(count) catch break :read_scripts;
- for (scripts_obj.properties) |prop| {
+ for (scripts_obj.properties.slice()) |prop| {
const key = prop.key.?.asString(r.allocator) orelse continue;
const value = prop.value.?.asString(r.allocator) orelse continue;
@@ -792,7 +793,7 @@ pub const ExportsMap = struct {
},
.e_array => |e_array| {
var array = this.allocator.alloc(Entry, e_array.items.len) catch unreachable;
- for (e_array.items) |item, i| {
+ for (e_array.items.slice()) |item, i| {
array[i] = this.visit(item);
}
return Entry{
@@ -815,7 +816,7 @@ pub const ExportsMap = struct {
var is_conditional_sugar = false;
first_token.loc = expr.loc;
first_token.len = 1;
- for (e_obj.properties) |prop, i| {
+ for (e_obj.properties.slice()) |prop, i| {
const key: string = prop.key.?.data.e_string.string(this.allocator) catch unreachable;
const key_range: logger.Range = this.source.rangeOfString(prop.key.?.loc);
diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig
index 9c457682c..82b658d69 100644
--- a/src/resolver/tsconfig_json.zig
+++ b/src/resolver/tsconfig_json.zig
@@ -192,7 +192,7 @@ pub const TSConfigJSON = struct {
var paths = paths_prop.expr.data.e_object;
result.base_url_for_paths = if (result.base_url.len > 0) result.base_url else ".";
result.paths = PathsMap.init(allocator);
- for (paths.properties) |property| {
+ for (paths.properties.slice()) |property| {
const key_prop = property.key orelse continue;
const key = (key_prop.asString(allocator)) orelse continue;
@@ -225,13 +225,13 @@ pub const TSConfigJSON = struct {
// and then, if that didn't work, also check "projectRoot/generated/folder1/file2".
switch (value_prop.data) {
.e_array => {
- const array = value_prop.data.e_array;
+ const array = value_prop.data.e_array.slice();
- if (array.items.len > 0) {
- var values = allocator.alloc(string, array.items.len) catch unreachable;
+ if (array.len > 0) {
+ var values = allocator.alloc(string, array.len) catch unreachable;
errdefer allocator.free(values);
var count: usize = 0;
- for (array.items) |expr| {
+ for (array) |expr| {
if ((expr.asString(allocator))) |str| {
if (TSConfigJSON.isValidTSConfigPathPattern(
str,