@jsenv/plugin-preact 1.6.25 → 1.6.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-preact",
3
- "version": "1.6.25",
3
+ "version": "1.6.27",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,8 +24,8 @@
24
24
  "babel-plugin-transform-hook-names": "1.0.2",
25
25
  "@babel/plugin-transform-react-jsx": "7.25.9",
26
26
  "@babel/plugin-transform-react-jsx-development": "7.25.9",
27
- "@jsenv/ast": "6.3.5",
28
- "@jsenv/sourcemap": "1.2.25",
27
+ "@jsenv/ast": "6.3.6",
28
+ "@jsenv/sourcemap": "1.2.26",
29
29
  "@jsenv/url-meta": "8.5.2",
30
30
  "@prefresh/babel-plugin": "0.5.1",
31
31
  "@prefresh/core": "1.5.2",
@@ -113,7 +113,7 @@ export const jsenvPluginPreact = ({
113
113
  urlInfo.content.includes("useReducer") ||
114
114
  urlInfo.content.includes("useRef") ||
115
115
  urlInfo.content.includes("useMemo"));
116
- const { code, map } = await applyBabelPlugins({
116
+ let { code, map } = await applyBabelPlugins({
117
117
  babelPlugins: [
118
118
  ...(jsxEnabled
119
119
  ? [
@@ -136,8 +136,8 @@ export const jsenvPluginPreact = ({
136
136
  inputUrl: urlInfo.url,
137
137
  outputUrl: urlInfo.generatedUrl,
138
138
  });
139
- const magicSource = createMagicSource(code);
140
139
  if (jsxEnabled) {
140
+ const magicSource = createMagicSource(code);
141
141
  // "@babel/plugin-transform-react-jsx" is injecting some of these 3 imports into the code:
142
142
  // 1. import { jsx } from "preact/jsx-runtime"
143
143
  // 2. import { jsxDev } from "preact/jsx-dev-runtime"
@@ -168,6 +168,11 @@ export const jsenvPluginPreact = ({
168
168
  index = code.indexOf(importSpecifier, index + 1);
169
169
  }
170
170
  }
171
+ const afterJsxReplace = magicSource.toContentAndSourcemap({
172
+ source: "jsenv_preact",
173
+ });
174
+ code = afterJsxReplace.content;
175
+ map = await composeTwoSourcemaps(map, afterJsxReplace.sourcemap);
171
176
  }
172
177
  if (refreshEnabled) {
173
178
  const hasReg = /\$RefreshReg\$\(/.test(code);
@@ -178,28 +183,27 @@ export const jsenvPluginPreact = ({
178
183
  expectedType: "js_module",
179
184
  specifier: "@jsenv/plugin-preact/src/client/preact_refresh.js",
180
185
  });
181
- magicSource.prepend(`import { installPreactRefresh } from ${
186
+ const prelude = `import { installPreactRefresh } from ${
182
187
  preactRefreshClientReference.generatedSpecifier
183
188
  };
184
189
  const __preact_refresh__ = installPreactRefresh(${JSON.stringify(urlInfo.url)});
185
- `);
190
+ `;
191
+ code = `${prelude.replace(/\n/g, "")}${code}`;
186
192
  if (hasReg) {
187
- magicSource.append(`
193
+ code = `${code}
194
+
188
195
  __preact_refresh__.end();
189
- import.meta.hot.accept(__preact_refresh__.acceptCallback);`);
196
+ import.meta.hot.accept(__preact_refresh__.acceptCallback);`;
190
197
  }
191
198
  }
192
199
  }
193
- const result = magicSource.toContentAndSourcemap({
194
- source: "jsenv_preact",
195
- });
196
200
  return {
197
- content: result.content,
198
- sourcemap: await composeTwoSourcemaps(map, result.sourcemap),
201
+ content: code,
202
+ sourcemap: map,
199
203
  // "no sourcemap is better than wrong sourcemap":
200
204
  // I don't know exactly what is resulting in bad sourcemaps
201
205
  // but I suspect hooknames or prefresh to be responsible
202
- sourcemapIsWrong: jsxEnabled && refreshEnabled,
206
+ // sourcemapIsWrong: jsxEnabled && refreshEnabled,
203
207
  };
204
208
  },
205
209
  },