solid-optimizer 1.0.0-next.2 → 1.0.0-next.4

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": "solid-optimizer",
3
- "version": "1.0.0-next.2",
3
+ "version": "1.0.0-next.4",
4
4
  "description": "Experimental compile-time optimizer for SolidJS",
5
5
  "keywords": [
6
6
  "compiler",
package/src/inline.ts CHANGED
@@ -1900,7 +1900,8 @@ class Inliner {
1900
1900
  }
1901
1901
  if (children !== undefined) {
1902
1902
  const opening = spread.element.openingElement;
1903
- const tag = textOf(this.context, opening.name);
1903
+ // Read the tag from the copy, which holds the renamed locals.
1904
+ const tag = copy.slice(opening.name.start, opening.name.end);
1904
1905
  const close = this.context.code.lastIndexOf('/>', opening.end);
1905
1906
  copy.overwrite(close, opening.end, `>${children}</${tag}>`);
1906
1907
  }
package/src/vite/index.ts CHANGED
@@ -744,6 +744,27 @@ export default function solidOptimizer(options: Options = {}): Plugin[] {
744
744
  return stripped.code;
745
745
  }
746
746
 
747
+ /**
748
+ * The scripts a virtual entry runs, like the server entry `start` mode
749
+ * generates: the app's modules it imports. It has no file to read, and
750
+ * the server and client builds have to see the same uses of each export.
751
+ * `undefined` when the entry has not been loaded or imports none.
752
+ */
753
+ function virtualEntryScripts(context: Rollup.PluginContext, id: string): string[] | undefined {
754
+ const info = context.getModuleInfo(id);
755
+ if (!info || info.code === null) {
756
+ return undefined;
757
+ }
758
+ const scripts: string[] = [];
759
+ for (const imported of [...info.importedIds, ...info.dynamicallyImportedIds]) {
760
+ // Packages and other virtual modules hold none of the app's components.
761
+ if (!imported.startsWith('\0') && !imported.includes('/node_modules/')) {
762
+ scripts.push(imported);
763
+ }
764
+ }
765
+ return scripts.length > 0 ? scripts : undefined;
766
+ }
767
+
747
768
  /**
748
769
  * The scripts an entry runs: the entry itself, or the module scripts of an
749
770
  * HTML entry. `undefined` when an HTML entry has an inline module script,
@@ -760,7 +781,7 @@ export default function solidOptimizer(options: Options = {}): Plugin[] {
760
781
  try {
761
782
  html = await readFile(stripQuery(id), 'utf8');
762
783
  } catch {
763
- return undefined;
784
+ return virtualEntryScripts(context, id);
764
785
  }
765
786
  const scripts: string[] = [];
766
787
  for (const [tag] of html.matchAll(/<script\b[^>]*>/gi)) {