svelte-shaker 0.9.1 → 0.9.2

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/dist/analyze.js CHANGED
@@ -567,6 +567,9 @@ function collectEscapedComponents(ast, imports, importedLocals, namespaceLocals)
567
567
  };
568
568
  walk(ast.fragment, { parent: null }, {
569
569
  _(node, { state, next }) {
570
+ // Type-only subtrees are erased at compile — never a runtime escape.
571
+ if (isTypeOnlyNode(node))
572
+ return;
570
573
  if (node.type === 'Identifier' &&
571
574
  node.name &&
572
575
  importedLocals.has(node.name) &&
@@ -581,6 +584,11 @@ function collectEscapedComponents(ast, imports, importedLocals, namespaceLocals)
581
584
  if (ast.instance) {
582
585
  walk(ast.instance, { parent: null }, {
583
586
  _(node, { state, next }) {
587
+ // Skip TS type positions: an identifier in `ComponentProps<typeof X>`
588
+ // or `: Props` is type-level (erased at compile), not a value read, so
589
+ // descending would falsely flag the component as escaped.
590
+ if (isTypeOnlyNode(node))
591
+ return;
584
592
  if (node.type === 'Identifier' &&
585
593
  node.name &&
586
594
  (imports.has(node.name) || namespaceLocals.has(node.name)) &&
@@ -594,6 +602,23 @@ function collectEscapedComponents(ast, imports, importedLocals, namespaceLocals)
594
602
  }
595
603
  return escaped;
596
604
  }
605
+ /**
606
+ * A TS type-only subtree the escape walk must NOT descend into: every `TSType*`
607
+ * node (type annotations, type references/queries, type-argument and
608
+ * type-parameter lists, …) plus `interface` declarations. Identifiers inside
609
+ * them — e.g. `Button` in `ComponentProps<typeof Button>['pattern']`, or `Props`
610
+ * in `: Props` — are type-level, erased at compile, never runtime value reads, so
611
+ * descending would falsely flag the component as escaped and bail it whole.
612
+ *
613
+ * `TSAsExpression` / `TSSatisfiesExpression` / `TSNonNullExpression` /
614
+ * `TSInstantiationExpression` are deliberately NOT pruned: they wrap a real
615
+ * runtime expression (`Button as T` IS a value use of `Button`), and their own
616
+ * type child is itself a `TSType*` node this prunes.
617
+ */
618
+ function isTypeOnlyNode(node) {
619
+ return (typeof node.type === 'string' &&
620
+ (node.type.startsWith('TSType') || node.type === 'TSInterfaceDeclaration'));
621
+ }
597
622
  /**
598
623
  * Is this Identifier used as a runtime *value* (so a component name here would
599
624
  * escape)? Property keys, member names and import/export specifier slots are
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-shaker",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Tree shaking for Svelte components",
5
5
  "keywords": [
6
6
  "dead-code-elimination",