solid-optimizer 1.0.0-next.9 → 1.0.0

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.
@@ -1,5 +1,4 @@
1
1
  import { SourceMap } from "@jridgewell/remapping";
2
- import MagicString from "magic-string";
3
2
  import "oxc-parser";
4
3
  //#region src/value.d.ts
5
4
  type Primitive = string | number | boolean | null | undefined;
@@ -203,4 +202,4 @@ interface ModuleConstants {
203
202
  declare function readModuleConstants(code: string, options?: Pick<CompileOptions, 'filename' | 'importedConstants' | 'globalConstants'>): ModuleConstants;
204
203
  //#endregion
205
204
  export { readModuleConstants as a, SkipPass as c, compile as i, Primitive as l, CompileResult as n, ImportedConstants as o, ModuleConstants as r, Skip as s, CompileOptions as t };
206
- //# sourceMappingURL=compile-X_SMDFr2.d.mts.map
205
+ //# sourceMappingURL=compile-ioIkBKzR.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-ioIkBKzR.d.mts","names":[],"sources":["../src/value.ts","../src/context.ts","../src/constants.ts","../src/compile.ts"],"mappings":";;;KAUY;;;;KC4DA;;;;;UAMK;WACN,MAAM;;WAEN;;WAEA;;;;;;;;KC9DC,oBAAoB,SAAS,eAAe,SAAS,eAAe;;;UCC/D;;;;;;;EAOf;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;;EAOA;;;;;;;;EAQA;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA,iBAAiB,SAAS;;;;;;;EAO1B;;;;;;EAMA,oBAAoB;;;;;;EAMpB,kBAAkB,SAAS,eAAe;;;;;;EAM1C,mBAAmB,SAAS;;;;;;;;EAQ5B,mBAAmB,SAAS;;;;;;;;EAQ5B;;;;;;EAMA;;;;;;;;EAQA;;;;;;EAMA;;;;;;;EAOA;;UAGe;EACf;;EAEA,KAAK;;;;;EAKL,UAAU;;;;;;;;;;;;;iBAmGI,QAAQ,cAAc,UAAS,iBAAsB;UAwHpD;;;;;EAKf;;;;;;EAMA,SAAS,eAAe;;;;;;;;iBASV,oBACd,cACA,UAAS,KAAK,wEACb"}
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as readModuleConstants, c as SkipPass, i as compile, l as Primitive, n as CompileResult, o as ImportedConstants, r as ModuleConstants, s as Skip, t as CompileOptions } from "./compile-X_SMDFr2.mjs";
1
+ import { a as readModuleConstants, c as SkipPass, i as compile, l as Primitive, n as CompileResult, o as ImportedConstants, r as ModuleConstants, s as Skip, t as CompileOptions } from "./compile-ioIkBKzR.mjs";
2
2
  export { type CompileOptions, type CompileResult, type ImportedConstants, type ModuleConstants, type Primitive, type Skip, type SkipPass, compile, readModuleConstants };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as readModuleConstants, t as compile } from "./compile-DptOANJi.mjs";
1
+ import { n as readModuleConstants, t as compile } from "./compile-Cvjy2e11.mjs";
2
2
  export { compile, readModuleConstants };
package/dist/vite.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { s as Skip, t as CompileOptions } from "./compile-X_SMDFr2.mjs";
1
+ import { s as Skip, t as CompileOptions } from "./compile-ioIkBKzR.mjs";
2
2
  import { Options as Options$1 } from "@solidjs/vite-plugin";
3
3
  import { Plugin } from "vite";
4
4
  //#region src/vite/report.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.mts","names":["SolidPluginOptions"],"sources":["../src/vite/report.ts","../src/vite/index.ts"],"mappings":";;;;;UAUiB;;WAEN;WACA,gBAAgB;;;;iBC0CV,yBAAyB,KACxC;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;;EASA,qBAAqB,QAAQ;;;;;;;;;;EAU7B;;iBAKe,gBAAgB,QAAQA;;EAEvC,YAAY;;wBAiNU,eAAe,UAAS,UAAe"}
1
+ {"version":3,"file":"vite.d.mts","names":["SolidPluginOptions"],"sources":["../src/vite/report.ts","../src/vite/index.ts"],"mappings":";;;;;UAUiB;;WAEN;WACA,gBAAgB;;;;iBC0CV,yBAAyB,KACxC;;;;;;;;;EAWA;;;;;;EAMA;;;;;;;;;EASA,qBAAqB,QAAQ;;;;;;;;;;EAU7B;;iBAKe,gBAAgB,QAAQA;;EAEvC,YAAY;;wBAoPU,eAAe,UAAS,UAAe"}
package/dist/vite.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { a as analyzeScopes, c as collectParents, d as parse, f as unwrap, i as runtimeImportSources, l as forEachChild, n as readModuleConstants, o as lookup, r as CONTEXT_SAFE_PRIMITIVES, s as scopeAt, t as compile, u as isIntrinsicTag } from "./compile-DptOANJi.mjs";
1
+ import { a as analyzeScopes, c as collectParents, d as parse, f as unwrap, i as runtimeImportSources, l as forEachChild, n as readModuleConstants, o as lookup, r as CONTEXT_SAFE_PRIMITIVES, s as scopeAt, t as compile, u as isIntrinsicTag } from "./compile-Cvjy2e11.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import remapping from "@jridgewell/remapping";
4
- import MagicString from "magic-string";
5
4
  import { parseSync } from "oxc-parser";
5
+ import MagicString from "magic-string";
6
6
  import { readFile } from "node:fs/promises";
7
7
  import path from "node:path";
8
8
  import { gzipSync } from "node:zlib";
@@ -1077,6 +1077,32 @@ function stripQuery(id) {
1077
1077
  return id.replace(/\?.*$/, "");
1078
1078
  }
1079
1079
  /**
1080
+ * The extensions `options.extensions` registers, and whether each holds
1081
+ * TypeScript, read the way `@solidjs/vite-plugin` reads them. A string
1082
+ * that contains `tsx` makes every registered extension TypeScript, as it does there.
1083
+ * `.tsrx` is left out: the official plugin compiles it on its own path, and
1084
+ * the parser here does not read it.
1085
+ */
1086
+ function readExtensions(extensions) {
1087
+ const list = extensions ?? [];
1088
+ let anyTSX = false;
1089
+ for (const extension of list) if (typeof extension === "string" && extension.includes("tsx")) anyTSX = true;
1090
+ const registered = /* @__PURE__ */ new Map();
1091
+ for (const extension of list) {
1092
+ const [name, extensionOptions] = typeof extension === "string" ? [extension, void 0] : extension;
1093
+ if (name === ".tsrx") continue;
1094
+ const typescript = anyTSX || extensionOptions?.typescript === true;
1095
+ registered.set(name, (registered.get(name) ?? false) || typescript);
1096
+ }
1097
+ return registered;
1098
+ }
1099
+ /** The extension of an id, with its leading dot, as the official plugin reads it. */
1100
+ function readExtension(id) {
1101
+ const file = stripQuery(id);
1102
+ const index = file.lastIndexOf(".");
1103
+ return index < 0 ? "" : file.slice(index);
1104
+ }
1105
+ /**
1080
1106
  * Chains the maps of each step into one, or `null` when the build writes no
1081
1107
  * source maps, since chaining the maps of a large chunk takes a while.
1082
1108
  */
@@ -1225,9 +1251,23 @@ function solidOptimizer(options = {}) {
1225
1251
  const client = jsxOptions(false);
1226
1252
  return client.generate === "dom" && client.hydratable !== true;
1227
1253
  };
1254
+ /** The extensions the official plugin lowers besides the JSX ones. */
1255
+ const extensions = readExtensions(solidOptions.extensions);
1256
+ /** Whether the official plugin lowers the module, so this plugin optimizes it. */
1228
1257
  const isJSXModule = (id) => {
1229
1258
  filter ??= createFilter(solidOptions.include, solidOptions.exclude, { resolve: config?.root });
1230
- return filter(id) && JSX_MODULE.test(stripQuery(id));
1259
+ return filter(id) && (JSX_MODULE.test(stripQuery(id)) || extensions.has(readExtension(id)));
1260
+ };
1261
+ /**
1262
+ * The file name the parser reads a module's code under. The parser picks
1263
+ * its dialect from the extension, so a registered one borrows `.tsx` or
1264
+ * `.jsx`, like the official plugin does when it lowers the module.
1265
+ */
1266
+ const parserFilename = (id) => {
1267
+ const file = stripQuery(id);
1268
+ const typescript = extensions.get(readExtension(id));
1269
+ if (typescript === void 0 || JSX_MODULE.test(file)) return file;
1270
+ return `${file}${typescript ? ".tsx" : ".jsx"}`;
1231
1271
  };
1232
1272
  /** Modules that keep their JSX, which the bundler must parse as JSX. */
1233
1273
  const preserved = /* @__PURE__ */ new Set();
@@ -1344,16 +1384,17 @@ function solidOptimizer(options = {}) {
1344
1384
  */
1345
1385
  async function moduleOptions(context, code, id) {
1346
1386
  const filename = stripQuery(id);
1387
+ const parsedAs = parserFilename(id);
1347
1388
  if (optimizer.fold === false || !isBuild()) return {
1348
1389
  ...compileOptions,
1349
- filename,
1390
+ filename: parsedAs,
1350
1391
  sourceMap: wantsMaps()
1351
1392
  };
1352
- const { imports } = readModuleConstants(code, { filename });
1393
+ const { imports } = readModuleConstants(code, { filename: parsedAs });
1353
1394
  const imported = await importedConstants(context, imports, filename, /* @__PURE__ */ new Set([filename]), id);
1354
1395
  return {
1355
1396
  ...compileOptions,
1356
- filename,
1397
+ filename: parsedAs,
1357
1398
  sourceMap: wantsMaps(),
1358
1399
  importedConstants: imported.constants,
1359
1400
  globalConstants: globals
@@ -1507,7 +1548,7 @@ function solidOptimizer(options = {}) {
1507
1548
  await context.load({ id: target });
1508
1549
  const code = recorded.get(environmentKey(context, target));
1509
1550
  if (code === void 0) return;
1510
- return (await transformWithOxc(code, stripQuery(target), {
1551
+ return (await transformWithOxc(code, parserFilename(target), {
1511
1552
  jsx: "preserve",
1512
1553
  sourcemap: false
1513
1554
  })).code;
@@ -1641,7 +1682,7 @@ function solidOptimizer(options = {}) {
1641
1682
  }
1642
1683
  for (let depth = 0; depth < 8 && isJSXModule(resolved.id); depth += 1) {
1643
1684
  const code = await state.load(resolved.id);
1644
- const reexport = code === void 0 ? void 0 : readReexport(code, stripQuery(resolved.id), imported);
1685
+ const reexport = code === void 0 ? void 0 : readReexport(code, parserFilename(resolved.id), imported);
1645
1686
  if (!reexport) break;
1646
1687
  const next = await context.resolve(reexport.source, resolved.id);
1647
1688
  if (!next || next.external || !isCopyable(next.id)) {
@@ -1664,7 +1705,7 @@ function solidOptimizer(options = {}) {
1664
1705
  skip("copy-cycle");
1665
1706
  return;
1666
1707
  }
1667
- const component = readExportedComponent(loaded, stripQuery(resolved.id), imported, moduleSources);
1708
+ const component = readExportedComponent(loaded, parserFilename(resolved.id), imported, moduleSources);
1668
1709
  if (!component) {
1669
1710
  state.excluded.add(key);
1670
1711
  skip("copy-shape");
@@ -1720,7 +1761,7 @@ function solidOptimizer(options = {}) {
1720
1761
  * can import components in turn, which a few more rounds take in.
1721
1762
  */
1722
1763
  async function inlineImports(context, source, id, compileOptionsOfModule, load, copySkips) {
1723
- const filename = stripQuery(id);
1764
+ const filename = parserFilename(id);
1724
1765
  const maps = [];
1725
1766
  let skipped;
1726
1767
  const excluded = /* @__PURE__ */ new Set();
@@ -1855,7 +1896,7 @@ function solidOptimizer(options = {}) {
1855
1896
  * lowering.
1856
1897
  */
1857
1898
  async function keepJSX(context, source, id) {
1858
- const filename = stripQuery(id);
1899
+ const filename = parserFilename(id);
1859
1900
  const solidCompiler = getCompiler();
1860
1901
  const maps = [];
1861
1902
  let code = source;
@@ -1928,7 +1969,7 @@ function solidOptimizer(options = {}) {
1928
1969
  code = protectedRefs.code;
1929
1970
  maps.push(protectedRefs.map);
1930
1971
  }
1931
- code = await resolveLazyModuleUrls(context, code, filename);
1972
+ code = await resolveLazyModuleUrls(context, code, stripQuery(id));
1932
1973
  preserved.add(id);
1933
1974
  return {
1934
1975
  code,
@@ -1967,7 +2008,7 @@ function solidOptimizer(options = {}) {
1967
2008
  async transform(source, id) {
1968
2009
  if (!isBuild() && optimizer.dev !== true) return null;
1969
2010
  if (chunkMode() && isClient(this) || !isJSXModule(id)) return null;
1970
- const filename = stripQuery(id);
2011
+ const filename = parserFilename(id);
1971
2012
  const sourceOptions = await moduleOptions(this, source, id);
1972
2013
  const result = compile(source, sourceOptions);
1973
2014
  let code = result.code;
@@ -2105,7 +2146,7 @@ function solidOptimizer(options = {}) {
2105
2146
  name: "solid-optimizer:module-type",
2106
2147
  transform(code, id) {
2107
2148
  if (!preserved.has(id)) return null;
2108
- const repaired = repairJSXSequences(code, stripQuery(id));
2149
+ const repaired = repairJSXSequences(code, parserFilename(id));
2109
2150
  return repaired ? {
2110
2151
  code: repaired.code,
2111
2152
  map: repaired.map,