@tanstack/start-plugin-core 1.166.12 → 1.166.13

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.
Files changed (87) hide show
  1. package/dist/esm/build-sitemap.js +94 -123
  2. package/dist/esm/build-sitemap.js.map +1 -1
  3. package/dist/esm/constants.js +15 -20
  4. package/dist/esm/constants.js.map +1 -1
  5. package/dist/esm/dev-server-plugin/dev-styles.js +137 -150
  6. package/dist/esm/dev-server-plugin/dev-styles.js.map +1 -1
  7. package/dist/esm/dev-server-plugin/extract-html-scripts.js +16 -15
  8. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
  9. package/dist/esm/dev-server-plugin/plugin.js +125 -195
  10. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  11. package/dist/esm/import-protection-plugin/ast.js +6 -5
  12. package/dist/esm/import-protection-plugin/ast.js.map +1 -1
  13. package/dist/esm/import-protection-plugin/constants.js +20 -22
  14. package/dist/esm/import-protection-plugin/constants.js.map +1 -1
  15. package/dist/esm/import-protection-plugin/defaults.js +35 -25
  16. package/dist/esm/import-protection-plugin/defaults.js.map +1 -1
  17. package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js +93 -92
  18. package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js.map +1 -1
  19. package/dist/esm/import-protection-plugin/matchers.js +23 -24
  20. package/dist/esm/import-protection-plugin/matchers.js.map +1 -1
  21. package/dist/esm/import-protection-plugin/plugin.js +1045 -1361
  22. package/dist/esm/import-protection-plugin/plugin.js.map +1 -1
  23. package/dist/esm/import-protection-plugin/postCompileUsage.js +58 -55
  24. package/dist/esm/import-protection-plugin/postCompileUsage.js.map +1 -1
  25. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +187 -259
  26. package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +1 -1
  27. package/dist/esm/import-protection-plugin/sourceLocation.js +238 -248
  28. package/dist/esm/import-protection-plugin/sourceLocation.js.map +1 -1
  29. package/dist/esm/import-protection-plugin/trace.js +173 -184
  30. package/dist/esm/import-protection-plugin/trace.js.map +1 -1
  31. package/dist/esm/import-protection-plugin/utils.js +132 -111
  32. package/dist/esm/import-protection-plugin/utils.js.map +1 -1
  33. package/dist/esm/import-protection-plugin/virtualModules.js +216 -196
  34. package/dist/esm/import-protection-plugin/virtualModules.js.map +1 -1
  35. package/dist/esm/index.js +2 -7
  36. package/dist/esm/load-env-plugin/plugin.js +12 -11
  37. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  38. package/dist/esm/output-directory.js +10 -10
  39. package/dist/esm/output-directory.js.map +1 -1
  40. package/dist/esm/plugin.js +275 -355
  41. package/dist/esm/plugin.js.map +1 -1
  42. package/dist/esm/post-server-build.js +39 -53
  43. package/dist/esm/post-server-build.js.map +1 -1
  44. package/dist/esm/prerender.js +177 -239
  45. package/dist/esm/prerender.js.map +1 -1
  46. package/dist/esm/preview-server-plugin/plugin.js +41 -44
  47. package/dist/esm/preview-server-plugin/plugin.js.map +1 -1
  48. package/dist/esm/queue.js +115 -126
  49. package/dist/esm/queue.js.map +1 -1
  50. package/dist/esm/resolve-entries.js +31 -32
  51. package/dist/esm/resolve-entries.js.map +1 -1
  52. package/dist/esm/schema.js +156 -179
  53. package/dist/esm/schema.js.map +1 -1
  54. package/dist/esm/start-compiler-plugin/compiler.js +655 -812
  55. package/dist/esm/start-compiler-plugin/compiler.js.map +1 -1
  56. package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js +25 -8
  57. package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js.map +1 -1
  58. package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js +22 -19
  59. package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js.map +1 -1
  60. package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js +20 -22
  61. package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js.map +1 -1
  62. package/dist/esm/start-compiler-plugin/handleCreateServerFn.js +187 -255
  63. package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +1 -1
  64. package/dist/esm/start-compiler-plugin/handleEnvOnly.js +23 -33
  65. package/dist/esm/start-compiler-plugin/handleEnvOnly.js.map +1 -1
  66. package/dist/esm/start-compiler-plugin/plugin.js +247 -291
  67. package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
  68. package/dist/esm/start-compiler-plugin/utils.js +27 -27
  69. package/dist/esm/start-compiler-plugin/utils.js.map +1 -1
  70. package/dist/esm/start-manifest-plugin/manifestBuilder.js +272 -378
  71. package/dist/esm/start-manifest-plugin/manifestBuilder.js.map +1 -1
  72. package/dist/esm/start-manifest-plugin/plugin.js +35 -44
  73. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  74. package/dist/esm/start-router-plugin/constants.js +6 -5
  75. package/dist/esm/start-router-plugin/constants.js.map +1 -1
  76. package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js +24 -19
  77. package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js.map +1 -1
  78. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +28 -29
  79. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  80. package/dist/esm/start-router-plugin/plugin.js +146 -199
  81. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  82. package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +32 -31
  83. package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -1
  84. package/dist/esm/utils.js +14 -14
  85. package/dist/esm/utils.js.map +1 -1
  86. package/package.json +7 -7
  87. package/dist/esm/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"postCompileUsage.js","sources":["../../../src/import-protection-plugin/postCompileUsage.ts"],"sourcesContent":["import babel from '@babel/core'\nimport * as t from '@babel/types'\nimport { parseImportProtectionAst } from './ast'\nimport type { ParsedAst } from './ast'\n\ntype UsagePos = { line: number; column0: number }\n\n/**\n * Given transformed code, returns the first \"meaningful\" usage position for an\n * import from `source` that survives compilation.\n *\n * \"Preferred\" positions (call, new, member-access) take priority over bare\n * identifier references. The returned column is 0-based (Babel loc semantics).\n */\nexport function findPostCompileUsagePos(\n code: string,\n source: string,\n): UsagePos | undefined {\n return findPostCompileUsagePosFromAst(parseImportProtectionAst(code), source)\n}\n\nfunction findPostCompileUsagePosFromAst(\n ast: ParsedAst,\n source: string,\n): UsagePos | undefined {\n // Collect local names bound from this specifier\n const imported = new Set<string>()\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node) && node.source.value === source) {\n if (node.importKind === 'type') continue\n for (const s of node.specifiers) {\n if (t.isImportSpecifier(s) && s.importKind === 'type') continue\n imported.add(s.local.name)\n }\n }\n }\n if (imported.size === 0) return undefined\n\n let preferred: UsagePos | undefined\n let anyUsage: UsagePos | undefined\n\n // babel.traverse can throw on malformed scopes (e.g. duplicate bindings from\n // import + const re-declaration) because parseAst doesn't attach a hub\n try {\n babel.traverse(ast, {\n ImportDeclaration(path) {\n path.skip()\n },\n\n Identifier(path: babel.NodePath<t.Identifier>) {\n if (preferred && anyUsage) {\n path.stop()\n return\n }\n\n const { node, parent, scope } = path\n if (!imported.has(node.name)) return\n\n // Skip binding positions (declarations, import specifiers, etc.)\n if (path.isBindingIdentifier()) return\n\n // Skip non-shorthand object property keys — they don't reference the import\n if (\n t.isObjectProperty(parent) &&\n parent.key === node &&\n !parent.computed &&\n !parent.shorthand\n )\n return\n if (t.isObjectMethod(parent) && parent.key === node && !parent.computed)\n return\n if (t.isExportSpecifier(parent) && parent.exported === node) return\n\n // Skip if shadowed by a closer binding\n const binding = scope.getBinding(node.name)\n if (binding && binding.kind !== 'module') return\n\n const loc = node.loc?.start\n if (!loc) return\n const pos: UsagePos = { line: loc.line, column0: loc.column }\n\n const isPreferred =\n (t.isCallExpression(parent) && parent.callee === node) ||\n (t.isNewExpression(parent) && parent.callee === node) ||\n (t.isMemberExpression(parent) && parent.object === node)\n\n if (isPreferred) {\n preferred ||= pos\n } else {\n anyUsage ||= pos\n }\n },\n })\n } catch {\n // Scope analysis failed — cannot determine usage positions reliably\n return undefined\n }\n\n return preferred ?? anyUsage\n}\n"],"names":[],"mappings":";;;AAcO,SAAS,wBACd,MACA,QACsB;AACtB,SAAO,+BAA+B,yBAAyB,IAAI,GAAG,MAAM;AAC9E;AAEA,SAAS,+BACP,KACA,QACsB;AAEtB,QAAM,+BAAe,IAAA;AACrB,aAAW,QAAQ,IAAI,QAAQ,MAAM;AACnC,QAAI,EAAE,oBAAoB,IAAI,KAAK,KAAK,OAAO,UAAU,QAAQ;AAC/D,UAAI,KAAK,eAAe,OAAQ;AAChC,iBAAW,KAAK,KAAK,YAAY;AAC/B,YAAI,EAAE,kBAAkB,CAAC,KAAK,EAAE,eAAe,OAAQ;AACvD,iBAAS,IAAI,EAAE,MAAM,IAAI;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACA,MAAI,SAAS,SAAS,EAAG,QAAO;AAEhC,MAAI;AACJ,MAAI;AAIJ,MAAI;AACF,UAAM,SAAS,KAAK;AAAA,MAClB,kBAAkB,MAAM;AACtB,aAAK,KAAA;AAAA,MACP;AAAA,MAEA,WAAW,MAAoC;AAC7C,YAAI,aAAa,UAAU;AACzB,eAAK,KAAA;AACL;AAAA,QACF;AAEA,cAAM,EAAE,MAAM,QAAQ,MAAA,IAAU;AAChC,YAAI,CAAC,SAAS,IAAI,KAAK,IAAI,EAAG;AAG9B,YAAI,KAAK,sBAAuB;AAGhC,YACE,EAAE,iBAAiB,MAAM,KACzB,OAAO,QAAQ,QACf,CAAC,OAAO,YACR,CAAC,OAAO;AAER;AACF,YAAI,EAAE,eAAe,MAAM,KAAK,OAAO,QAAQ,QAAQ,CAAC,OAAO;AAC7D;AACF,YAAI,EAAE,kBAAkB,MAAM,KAAK,OAAO,aAAa,KAAM;AAG7D,cAAM,UAAU,MAAM,WAAW,KAAK,IAAI;AAC1C,YAAI,WAAW,QAAQ,SAAS,SAAU;AAE1C,cAAM,MAAM,KAAK,KAAK;AACtB,YAAI,CAAC,IAAK;AACV,cAAM,MAAgB,EAAE,MAAM,IAAI,MAAM,SAAS,IAAI,OAAA;AAErD,cAAM,cACH,EAAE,iBAAiB,MAAM,KAAK,OAAO,WAAW,QAChD,EAAE,gBAAgB,MAAM,KAAK,OAAO,WAAW,QAC/C,EAAE,mBAAmB,MAAM,KAAK,OAAO,WAAW;AAErD,YAAI,aAAa;AACf,wBAAc;AAAA,QAChB,OAAO;AACL,uBAAa;AAAA,QACf;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH,QAAQ;AAEN,WAAO;AAAA,EACT;AAEA,SAAO,aAAa;AACtB;"}
1
+ {"version":3,"file":"postCompileUsage.js","names":[],"sources":["../../../src/import-protection-plugin/postCompileUsage.ts"],"sourcesContent":["import babel from '@babel/core'\nimport * as t from '@babel/types'\nimport { parseImportProtectionAst } from './ast'\nimport type { ParsedAst } from './ast'\n\ntype UsagePos = { line: number; column0: number }\n\n/**\n * Given transformed code, returns the first \"meaningful\" usage position for an\n * import from `source` that survives compilation.\n *\n * \"Preferred\" positions (call, new, member-access) take priority over bare\n * identifier references. The returned column is 0-based (Babel loc semantics).\n */\nexport function findPostCompileUsagePos(\n code: string,\n source: string,\n): UsagePos | undefined {\n return findPostCompileUsagePosFromAst(parseImportProtectionAst(code), source)\n}\n\nfunction findPostCompileUsagePosFromAst(\n ast: ParsedAst,\n source: string,\n): UsagePos | undefined {\n // Collect local names bound from this specifier\n const imported = new Set<string>()\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node) && node.source.value === source) {\n if (node.importKind === 'type') continue\n for (const s of node.specifiers) {\n if (t.isImportSpecifier(s) && s.importKind === 'type') continue\n imported.add(s.local.name)\n }\n }\n }\n if (imported.size === 0) return undefined\n\n let preferred: UsagePos | undefined\n let anyUsage: UsagePos | undefined\n\n // babel.traverse can throw on malformed scopes (e.g. duplicate bindings from\n // import + const re-declaration) because parseAst doesn't attach a hub\n try {\n babel.traverse(ast, {\n ImportDeclaration(path) {\n path.skip()\n },\n\n Identifier(path: babel.NodePath<t.Identifier>) {\n if (preferred && anyUsage) {\n path.stop()\n return\n }\n\n const { node, parent, scope } = path\n if (!imported.has(node.name)) return\n\n // Skip binding positions (declarations, import specifiers, etc.)\n if (path.isBindingIdentifier()) return\n\n // Skip non-shorthand object property keys — they don't reference the import\n if (\n t.isObjectProperty(parent) &&\n parent.key === node &&\n !parent.computed &&\n !parent.shorthand\n )\n return\n if (t.isObjectMethod(parent) && parent.key === node && !parent.computed)\n return\n if (t.isExportSpecifier(parent) && parent.exported === node) return\n\n // Skip if shadowed by a closer binding\n const binding = scope.getBinding(node.name)\n if (binding && binding.kind !== 'module') return\n\n const loc = node.loc?.start\n if (!loc) return\n const pos: UsagePos = { line: loc.line, column0: loc.column }\n\n const isPreferred =\n (t.isCallExpression(parent) && parent.callee === node) ||\n (t.isNewExpression(parent) && parent.callee === node) ||\n (t.isMemberExpression(parent) && parent.object === node)\n\n if (isPreferred) {\n preferred ||= pos\n } else {\n anyUsage ||= pos\n }\n },\n })\n } catch {\n // Scope analysis failed — cannot determine usage positions reliably\n return undefined\n }\n\n return preferred ?? anyUsage\n}\n"],"mappings":";;;;;;;;;;;AAcA,SAAgB,wBACd,MACA,QACsB;AACtB,QAAO,+BAA+B,yBAAyB,KAAK,EAAE,OAAO;;AAG/E,SAAS,+BACP,KACA,QACsB;CAEtB,MAAM,2BAAW,IAAI,KAAa;AAClC,MAAK,MAAM,QAAQ,IAAI,QAAQ,KAC7B,KAAI,EAAE,oBAAoB,KAAK,IAAI,KAAK,OAAO,UAAU,QAAQ;AAC/D,MAAI,KAAK,eAAe,OAAQ;AAChC,OAAK,MAAM,KAAK,KAAK,YAAY;AAC/B,OAAI,EAAE,kBAAkB,EAAE,IAAI,EAAE,eAAe,OAAQ;AACvD,YAAS,IAAI,EAAE,MAAM,KAAK;;;AAIhC,KAAI,SAAS,SAAS,EAAG,QAAO,KAAA;CAEhC,IAAI;CACJ,IAAI;AAIJ,KAAI;AACF,QAAM,SAAS,KAAK;GAClB,kBAAkB,MAAM;AACtB,SAAK,MAAM;;GAGb,WAAW,MAAoC;AAC7C,QAAI,aAAa,UAAU;AACzB,UAAK,MAAM;AACX;;IAGF,MAAM,EAAE,MAAM,QAAQ,UAAU;AAChC,QAAI,CAAC,SAAS,IAAI,KAAK,KAAK,CAAE;AAG9B,QAAI,KAAK,qBAAqB,CAAE;AAGhC,QACE,EAAE,iBAAiB,OAAO,IAC1B,OAAO,QAAQ,QACf,CAAC,OAAO,YACR,CAAC,OAAO,UAER;AACF,QAAI,EAAE,eAAe,OAAO,IAAI,OAAO,QAAQ,QAAQ,CAAC,OAAO,SAC7D;AACF,QAAI,EAAE,kBAAkB,OAAO,IAAI,OAAO,aAAa,KAAM;IAG7D,MAAM,UAAU,MAAM,WAAW,KAAK,KAAK;AAC3C,QAAI,WAAW,QAAQ,SAAS,SAAU;IAE1C,MAAM,MAAM,KAAK,KAAK;AACtB,QAAI,CAAC,IAAK;IACV,MAAM,MAAgB;KAAE,MAAM,IAAI;KAAM,SAAS,IAAI;KAAQ;AAO7D,QAJG,EAAE,iBAAiB,OAAO,IAAI,OAAO,WAAW,QAChD,EAAE,gBAAgB,OAAO,IAAI,OAAO,WAAW,QAC/C,EAAE,mBAAmB,OAAO,IAAI,OAAO,WAAW,KAGnD,eAAc;QAEd,cAAa;;GAGlB,CAAC;SACI;AAEN;;AAGF,QAAO,aAAa"}
@@ -1,277 +1,205 @@
1
- import * as t from "@babel/types";
2
- import { generateFromAst } from "@tanstack/router-utils";
3
- import { MOCK_MODULE_ID } from "./virtualModules.js";
4
1
  import { getOrCreate } from "./utils.js";
2
+ import { MOCK_MODULE_ID } from "./virtualModules.js";
5
3
  import { parseImportProtectionAst } from "./ast.js";
4
+ import * as t from "@babel/types";
5
+ import { generateFromAst } from "@tanstack/router-utils";
6
+ //#region src/import-protection-plugin/rewriteDeniedImports.ts
6
7
  function isValidExportName(name) {
7
- if (name === "default" || name.length === 0) return false;
8
- const first = name.charCodeAt(0);
9
- if (!(first >= 65 && first <= 90 || first >= 97 && first <= 122 || first === 95 || first === 36))
10
- return false;
11
- for (let i = 1; i < name.length; i++) {
12
- const ch = name.charCodeAt(i);
13
- if (!(ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 48 && ch <= 57 || ch === 95 || ch === 36))
14
- return false;
15
- }
16
- return true;
8
+ if (name === "default" || name.length === 0) return false;
9
+ const first = name.charCodeAt(0);
10
+ if (!(first >= 65 && first <= 90 || first >= 97 && first <= 122 || first === 95 || first === 36)) return false;
11
+ for (let i = 1; i < name.length; i++) {
12
+ const ch = name.charCodeAt(i);
13
+ if (!(ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || ch >= 48 && ch <= 57 || ch === 95 || ch === 36)) return false;
14
+ }
15
+ return true;
17
16
  }
18
17
  function collectMockExportNamesBySource(code) {
19
- return collectMockExportNamesBySourceFromAst(parseImportProtectionAst(code));
18
+ return collectMockExportNamesBySourceFromAst(parseImportProtectionAst(code));
20
19
  }
21
20
  function collectMockExportNamesBySourceFromAst(ast) {
22
- const namesBySource = /* @__PURE__ */ new Map();
23
- const memberBindingToSource = /* @__PURE__ */ new Map();
24
- const add = (source, name) => {
25
- if (name === "default" || name.length === 0) return;
26
- getOrCreate(namesBySource, source, () => /* @__PURE__ */ new Set()).add(name);
27
- };
28
- for (const node of ast.program.body) {
29
- if (t.isImportDeclaration(node)) {
30
- if (node.importKind === "type") continue;
31
- const source = node.source.value;
32
- for (const s of node.specifiers) {
33
- if (t.isImportNamespaceSpecifier(s)) {
34
- memberBindingToSource.set(s.local.name, source);
35
- continue;
36
- }
37
- if (t.isImportDefaultSpecifier(s)) {
38
- memberBindingToSource.set(s.local.name, source);
39
- continue;
40
- }
41
- if (!t.isImportSpecifier(s)) continue;
42
- if (s.importKind === "type") continue;
43
- const importedName = t.isIdentifier(s.imported) ? s.imported.name : s.imported.value;
44
- if (importedName === "default") continue;
45
- add(source, importedName);
46
- }
47
- }
48
- if (t.isExportNamedDeclaration(node) && node.source?.value) {
49
- if (node.exportKind === "type") continue;
50
- const source = node.source.value;
51
- for (const s of node.specifiers) {
52
- if (!t.isExportSpecifier(s)) continue;
53
- if (s.exportKind === "type") continue;
54
- add(source, s.local.name);
55
- }
56
- }
57
- }
58
- if (memberBindingToSource.size > 0) {
59
- const visit = (node) => {
60
- if (t.isMemberExpression(node)) {
61
- const object = node.object;
62
- if (t.isIdentifier(object)) {
63
- const source = memberBindingToSource.get(object.name);
64
- if (source) {
65
- const property = node.property;
66
- if (!node.computed && t.isIdentifier(property)) {
67
- add(source, property.name);
68
- } else if (node.computed && t.isStringLiteral(property)) {
69
- add(source, property.value);
70
- }
71
- }
72
- }
73
- }
74
- const keys = t.VISITOR_KEYS[node.type];
75
- if (!keys) return;
76
- for (const key of keys) {
77
- const child = node[key];
78
- if (Array.isArray(child)) {
79
- for (const item of child) {
80
- if (item && typeof item === "object" && "type" in item) {
81
- visit(item);
82
- }
83
- }
84
- } else if (child && typeof child === "object" && "type" in child) {
85
- visit(child);
86
- }
87
- }
88
- };
89
- visit(ast.program);
90
- }
91
- const out = /* @__PURE__ */ new Map();
92
- for (const [source, set] of namesBySource) {
93
- out.set(source, Array.from(set).sort());
94
- }
95
- return out;
21
+ const namesBySource = /* @__PURE__ */ new Map();
22
+ const memberBindingToSource = /* @__PURE__ */ new Map();
23
+ const add = (source, name) => {
24
+ if (name === "default" || name.length === 0) return;
25
+ getOrCreate(namesBySource, source, () => /* @__PURE__ */ new Set()).add(name);
26
+ };
27
+ for (const node of ast.program.body) {
28
+ if (t.isImportDeclaration(node)) {
29
+ if (node.importKind === "type") continue;
30
+ const source = node.source.value;
31
+ for (const s of node.specifiers) {
32
+ if (t.isImportNamespaceSpecifier(s)) {
33
+ memberBindingToSource.set(s.local.name, source);
34
+ continue;
35
+ }
36
+ if (t.isImportDefaultSpecifier(s)) {
37
+ memberBindingToSource.set(s.local.name, source);
38
+ continue;
39
+ }
40
+ if (!t.isImportSpecifier(s)) continue;
41
+ if (s.importKind === "type") continue;
42
+ const importedName = t.isIdentifier(s.imported) ? s.imported.name : s.imported.value;
43
+ if (importedName === "default") continue;
44
+ add(source, importedName);
45
+ }
46
+ }
47
+ if (t.isExportNamedDeclaration(node) && node.source?.value) {
48
+ if (node.exportKind === "type") continue;
49
+ const source = node.source.value;
50
+ for (const s of node.specifiers) {
51
+ if (!t.isExportSpecifier(s)) continue;
52
+ if (s.exportKind === "type") continue;
53
+ add(source, s.local.name);
54
+ }
55
+ }
56
+ }
57
+ if (memberBindingToSource.size > 0) {
58
+ const visit = (node) => {
59
+ if (t.isMemberExpression(node)) {
60
+ const object = node.object;
61
+ if (t.isIdentifier(object)) {
62
+ const source = memberBindingToSource.get(object.name);
63
+ if (source) {
64
+ const property = node.property;
65
+ if (!node.computed && t.isIdentifier(property)) add(source, property.name);
66
+ else if (node.computed && t.isStringLiteral(property)) add(source, property.value);
67
+ }
68
+ }
69
+ }
70
+ const keys = t.VISITOR_KEYS[node.type];
71
+ if (!keys) return;
72
+ for (const key of keys) {
73
+ const child = node[key];
74
+ if (Array.isArray(child)) {
75
+ for (const item of child) if (item && typeof item === "object" && "type" in item) visit(item);
76
+ } else if (child && typeof child === "object" && "type" in child) visit(child);
77
+ }
78
+ };
79
+ visit(ast.program);
80
+ }
81
+ const out = /* @__PURE__ */ new Map();
82
+ for (const [source, set] of namesBySource) out.set(source, Array.from(set).sort());
83
+ return out;
96
84
  }
85
+ /** Collect all valid named export identifiers from the given code. */
97
86
  function collectNamedExports(code) {
98
- return collectNamedExportsFromAst(parseImportProtectionAst(code));
87
+ return collectNamedExportsFromAst(parseImportProtectionAst(code));
99
88
  }
100
89
  function collectIdentifiersFromPattern(pattern, add) {
101
- if (t.isIdentifier(pattern)) {
102
- add(pattern.name);
103
- } else if (t.isObjectPattern(pattern)) {
104
- for (const prop of pattern.properties) {
105
- if (t.isRestElement(prop)) {
106
- collectIdentifiersFromPattern(prop.argument, add);
107
- } else {
108
- collectIdentifiersFromPattern(prop.value, add);
109
- }
110
- }
111
- } else if (t.isArrayPattern(pattern)) {
112
- for (const elem of pattern.elements) {
113
- if (elem) collectIdentifiersFromPattern(elem, add);
114
- }
115
- } else if (t.isAssignmentPattern(pattern)) {
116
- collectIdentifiersFromPattern(pattern.left, add);
117
- } else if (t.isRestElement(pattern)) {
118
- collectIdentifiersFromPattern(pattern.argument, add);
119
- }
90
+ if (t.isIdentifier(pattern)) add(pattern.name);
91
+ else if (t.isObjectPattern(pattern)) for (const prop of pattern.properties) if (t.isRestElement(prop)) collectIdentifiersFromPattern(prop.argument, add);
92
+ else collectIdentifiersFromPattern(prop.value, add);
93
+ else if (t.isArrayPattern(pattern)) {
94
+ for (const elem of pattern.elements) if (elem) collectIdentifiersFromPattern(elem, add);
95
+ } else if (t.isAssignmentPattern(pattern)) collectIdentifiersFromPattern(pattern.left, add);
96
+ else if (t.isRestElement(pattern)) collectIdentifiersFromPattern(pattern.argument, add);
120
97
  }
121
98
  function collectNamedExportsFromAst(ast) {
122
- const names = /* @__PURE__ */ new Set();
123
- const add = (name) => {
124
- if (isValidExportName(name)) names.add(name);
125
- };
126
- for (const node of ast.program.body) {
127
- if (t.isExportNamedDeclaration(node)) {
128
- if (node.exportKind === "type") continue;
129
- if (node.declaration) {
130
- const decl = node.declaration;
131
- if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {
132
- if (decl.id?.name) add(decl.id.name);
133
- } else if (t.isVariableDeclaration(decl)) {
134
- for (const d of decl.declarations) {
135
- collectIdentifiersFromPattern(d.id, add);
136
- }
137
- }
138
- }
139
- for (const s of node.specifiers) {
140
- if (!t.isExportSpecifier(s)) continue;
141
- if (s.exportKind === "type") continue;
142
- const exportedName = t.isIdentifier(s.exported) ? s.exported.name : s.exported.value;
143
- add(exportedName);
144
- }
145
- }
146
- }
147
- return Array.from(names).sort();
99
+ const names = /* @__PURE__ */ new Set();
100
+ const add = (name) => {
101
+ if (isValidExportName(name)) names.add(name);
102
+ };
103
+ for (const node of ast.program.body) if (t.isExportNamedDeclaration(node)) {
104
+ if (node.exportKind === "type") continue;
105
+ if (node.declaration) {
106
+ const decl = node.declaration;
107
+ if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {
108
+ if (decl.id?.name) add(decl.id.name);
109
+ } else if (t.isVariableDeclaration(decl)) for (const d of decl.declarations) collectIdentifiersFromPattern(d.id, add);
110
+ }
111
+ for (const s of node.specifiers) {
112
+ if (!t.isExportSpecifier(s)) continue;
113
+ if (s.exportKind === "type") continue;
114
+ add(t.isIdentifier(s.exported) ? s.exported.name : s.exported.value);
115
+ }
116
+ }
117
+ return Array.from(names).sort();
148
118
  }
119
+ /**
120
+ * Rewrite static imports/re-exports from denied sources using Babel AST transforms.
121
+ *
122
+ * Transforms:
123
+ * import { a as b, c } from 'denied'
124
+ * Into:
125
+ * import __tss_deny_0 from 'tanstack-start-import-protection:mock'
126
+ * const b = __tss_deny_0.a
127
+ * const c = __tss_deny_0.c
128
+ *
129
+ * Also handles:
130
+ * import def from 'denied' -> import def from mock
131
+ * import * as ns from 'denied' -> import ns from mock
132
+ * export { x } from 'denied' -> export const x = mock.x
133
+ * export * from 'denied' -> removed
134
+ * export { x as y } from 'denied' -> export const y = mock.x
135
+ */
149
136
  function rewriteDeniedImports(code, id, deniedSources, getMockModuleId = () => MOCK_MODULE_ID) {
150
- return rewriteDeniedImportsFromAst(
151
- parseImportProtectionAst(code),
152
- id,
153
- deniedSources,
154
- getMockModuleId
155
- );
137
+ return rewriteDeniedImportsFromAst(parseImportProtectionAst(code), id, deniedSources, getMockModuleId);
156
138
  }
157
139
  function rewriteDeniedImportsFromAst(ast, id, deniedSources, getMockModuleId = () => MOCK_MODULE_ID) {
158
- let modified = false;
159
- let mockCounter = 0;
160
- for (let i = ast.program.body.length - 1; i >= 0; i--) {
161
- const node = ast.program.body[i];
162
- if (t.isImportDeclaration(node)) {
163
- if (node.importKind === "type") continue;
164
- if (!deniedSources.has(node.source.value)) continue;
165
- const mockVar = `__tss_deny_${mockCounter++}`;
166
- const replacements = [];
167
- replacements.push(
168
- t.importDeclaration(
169
- [t.importDefaultSpecifier(t.identifier(mockVar))],
170
- t.stringLiteral(getMockModuleId(node.source.value))
171
- )
172
- );
173
- for (const specifier of node.specifiers) {
174
- if (t.isImportDefaultSpecifier(specifier) || t.isImportNamespaceSpecifier(specifier)) {
175
- replacements.push(
176
- t.variableDeclaration("const", [
177
- t.variableDeclarator(
178
- t.identifier(specifier.local.name),
179
- t.identifier(mockVar)
180
- )
181
- ])
182
- );
183
- } else if (t.isImportSpecifier(specifier)) {
184
- if (specifier.importKind === "type") continue;
185
- const importedName = t.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value;
186
- replacements.push(
187
- t.variableDeclaration("const", [
188
- t.variableDeclarator(
189
- t.identifier(specifier.local.name),
190
- t.memberExpression(
191
- t.identifier(mockVar),
192
- t.identifier(importedName)
193
- )
194
- )
195
- ])
196
- );
197
- }
198
- }
199
- ast.program.body.splice(i, 1, ...replacements);
200
- modified = true;
201
- continue;
202
- }
203
- if (t.isExportNamedDeclaration(node) && node.source) {
204
- if (node.exportKind === "type") continue;
205
- if (!deniedSources.has(node.source.value)) continue;
206
- const mockVar = `__tss_deny_${mockCounter++}`;
207
- const replacements = [];
208
- replacements.push(
209
- t.importDeclaration(
210
- [t.importDefaultSpecifier(t.identifier(mockVar))],
211
- t.stringLiteral(getMockModuleId(node.source.value))
212
- )
213
- );
214
- const exportSpecifiers = [];
215
- for (const specifier of node.specifiers) {
216
- if (t.isExportSpecifier(specifier)) {
217
- if (specifier.exportKind === "type") continue;
218
- const localName = specifier.local.name;
219
- const exportedName = t.isIdentifier(specifier.exported) ? specifier.exported.name : specifier.exported.value;
220
- const internalVar = `__tss_reexport_${localName}`;
221
- replacements.push(
222
- t.variableDeclaration("const", [
223
- t.variableDeclarator(
224
- t.identifier(internalVar),
225
- t.memberExpression(
226
- t.identifier(mockVar),
227
- t.identifier(localName)
228
- )
229
- )
230
- ])
231
- );
232
- exportSpecifiers.push({ localName: internalVar, exportedName });
233
- }
234
- }
235
- if (exportSpecifiers.length > 0) {
236
- replacements.push(
237
- t.exportNamedDeclaration(
238
- null,
239
- exportSpecifiers.map(
240
- (s) => t.exportSpecifier(
241
- t.identifier(s.localName),
242
- t.identifier(s.exportedName)
243
- )
244
- )
245
- )
246
- );
247
- }
248
- ast.program.body.splice(i, 1, ...replacements);
249
- modified = true;
250
- continue;
251
- }
252
- if (t.isExportAllDeclaration(node)) {
253
- if (node.exportKind === "type") continue;
254
- if (!deniedSources.has(node.source.value)) continue;
255
- ast.program.body.splice(i, 1);
256
- modified = true;
257
- continue;
258
- }
259
- }
260
- if (!modified) return void 0;
261
- const result = generateFromAst(ast, {
262
- sourceMaps: true,
263
- sourceFileName: id,
264
- filename: id
265
- });
266
- return {
267
- code: result.code,
268
- ...result.map ? { map: result.map } : {}
269
- };
140
+ let modified = false;
141
+ let mockCounter = 0;
142
+ for (let i = ast.program.body.length - 1; i >= 0; i--) {
143
+ const node = ast.program.body[i];
144
+ if (t.isImportDeclaration(node)) {
145
+ if (node.importKind === "type") continue;
146
+ if (!deniedSources.has(node.source.value)) continue;
147
+ const mockVar = `__tss_deny_${mockCounter++}`;
148
+ const replacements = [];
149
+ replacements.push(t.importDeclaration([t.importDefaultSpecifier(t.identifier(mockVar))], t.stringLiteral(getMockModuleId(node.source.value))));
150
+ for (const specifier of node.specifiers) if (t.isImportDefaultSpecifier(specifier) || t.isImportNamespaceSpecifier(specifier)) replacements.push(t.variableDeclaration("const", [t.variableDeclarator(t.identifier(specifier.local.name), t.identifier(mockVar))]));
151
+ else if (t.isImportSpecifier(specifier)) {
152
+ if (specifier.importKind === "type") continue;
153
+ const importedName = t.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value;
154
+ replacements.push(t.variableDeclaration("const", [t.variableDeclarator(t.identifier(specifier.local.name), t.memberExpression(t.identifier(mockVar), t.identifier(importedName)))]));
155
+ }
156
+ ast.program.body.splice(i, 1, ...replacements);
157
+ modified = true;
158
+ continue;
159
+ }
160
+ if (t.isExportNamedDeclaration(node) && node.source) {
161
+ if (node.exportKind === "type") continue;
162
+ if (!deniedSources.has(node.source.value)) continue;
163
+ const mockVar = `__tss_deny_${mockCounter++}`;
164
+ const replacements = [];
165
+ replacements.push(t.importDeclaration([t.importDefaultSpecifier(t.identifier(mockVar))], t.stringLiteral(getMockModuleId(node.source.value))));
166
+ const exportSpecifiers = [];
167
+ for (const specifier of node.specifiers) if (t.isExportSpecifier(specifier)) {
168
+ if (specifier.exportKind === "type") continue;
169
+ const localName = specifier.local.name;
170
+ const exportedName = t.isIdentifier(specifier.exported) ? specifier.exported.name : specifier.exported.value;
171
+ const internalVar = `__tss_reexport_${localName}`;
172
+ replacements.push(t.variableDeclaration("const", [t.variableDeclarator(t.identifier(internalVar), t.memberExpression(t.identifier(mockVar), t.identifier(localName)))]));
173
+ exportSpecifiers.push({
174
+ localName: internalVar,
175
+ exportedName
176
+ });
177
+ }
178
+ if (exportSpecifiers.length > 0) replacements.push(t.exportNamedDeclaration(null, exportSpecifiers.map((s) => t.exportSpecifier(t.identifier(s.localName), t.identifier(s.exportedName)))));
179
+ ast.program.body.splice(i, 1, ...replacements);
180
+ modified = true;
181
+ continue;
182
+ }
183
+ if (t.isExportAllDeclaration(node)) {
184
+ if (node.exportKind === "type") continue;
185
+ if (!deniedSources.has(node.source.value)) continue;
186
+ ast.program.body.splice(i, 1);
187
+ modified = true;
188
+ continue;
189
+ }
190
+ }
191
+ if (!modified) return void 0;
192
+ const result = generateFromAst(ast, {
193
+ sourceMaps: true,
194
+ sourceFileName: id,
195
+ filename: id
196
+ });
197
+ return {
198
+ code: result.code,
199
+ ...result.map ? { map: result.map } : {}
200
+ };
270
201
  }
271
- export {
272
- collectMockExportNamesBySource,
273
- collectNamedExports,
274
- isValidExportName,
275
- rewriteDeniedImports
276
- };
277
- //# sourceMappingURL=rewriteDeniedImports.js.map
202
+ //#endregion
203
+ export { collectMockExportNamesBySource, collectNamedExports, isValidExportName, rewriteDeniedImports };
204
+
205
+ //# sourceMappingURL=rewriteDeniedImports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rewriteDeniedImports.js","sources":["../../../src/import-protection-plugin/rewriteDeniedImports.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { generateFromAst } from '@tanstack/router-utils'\n\nimport { MOCK_MODULE_ID } from './virtualModules'\nimport { getOrCreate } from './utils'\nimport { parseImportProtectionAst } from './ast'\nimport type { SourceMapLike } from './sourceLocation'\nimport type { ParsedAst } from './ast'\n\nexport function isValidExportName(name: string): boolean {\n if (name === 'default' || name.length === 0) return false\n const first = name.charCodeAt(0)\n // First char: A-Z (65-90), a-z (97-122), _ (95), $ (36)\n if (\n !(\n (first >= 65 && first <= 90) ||\n (first >= 97 && first <= 122) ||\n first === 95 ||\n first === 36\n )\n )\n return false\n for (let i = 1; i < name.length; i++) {\n const ch = name.charCodeAt(i)\n // Subsequent: A-Z, a-z, 0-9 (48-57), _, $\n if (\n !(\n (ch >= 65 && ch <= 90) ||\n (ch >= 97 && ch <= 122) ||\n (ch >= 48 && ch <= 57) ||\n ch === 95 ||\n ch === 36\n )\n )\n return false\n }\n return true\n}\n\nexport function collectMockExportNamesBySource(\n code: string,\n): Map<string, Array<string>> {\n return collectMockExportNamesBySourceFromAst(parseImportProtectionAst(code))\n}\n\nfunction collectMockExportNamesBySourceFromAst(\n ast: ParsedAst,\n): Map<string, Array<string>> {\n const namesBySource = new Map<string, Set<string>>()\n const memberBindingToSource = new Map<string, string>()\n const add = (source: string, name: string) => {\n if (name === 'default' || name.length === 0) return\n getOrCreate(namesBySource, source, () => new Set<string>()).add(name)\n }\n\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node)) {\n if (node.importKind === 'type') continue\n const source = node.source.value\n for (const s of node.specifiers) {\n if (t.isImportNamespaceSpecifier(s)) {\n memberBindingToSource.set(s.local.name, source)\n continue\n }\n if (t.isImportDefaultSpecifier(s)) {\n memberBindingToSource.set(s.local.name, source)\n continue\n }\n if (!t.isImportSpecifier(s)) continue\n if (s.importKind === 'type') continue\n const importedName = t.isIdentifier(s.imported)\n ? s.imported.name\n : s.imported.value\n // `import { default as x } from 'm'` only requires a default export.\n if (importedName === 'default') continue\n add(source, importedName)\n }\n }\n\n if (t.isExportNamedDeclaration(node) && node.source?.value) {\n if (node.exportKind === 'type') continue\n const source = node.source.value\n for (const s of node.specifiers) {\n if (!t.isExportSpecifier(s)) continue\n if (s.exportKind === 'type') continue\n add(source, s.local.name)\n }\n }\n }\n\n // For namespace/default imports, collect property names used as\n // `binding.foo`/`binding?.foo` so mock-edge modules can expose explicit ESM\n // named exports required by Rolldown/native ESM.\n if (memberBindingToSource.size > 0) {\n const visit = (node: t.Node): void => {\n if (t.isMemberExpression(node)) {\n const object = node.object\n if (t.isIdentifier(object)) {\n const source = memberBindingToSource.get(object.name)\n if (source) {\n const property = node.property\n if (!node.computed && t.isIdentifier(property)) {\n add(source, property.name)\n } else if (node.computed && t.isStringLiteral(property)) {\n add(source, property.value)\n }\n }\n }\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n visit(item as t.Node)\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n visit(child as t.Node)\n }\n }\n }\n\n visit(ast.program)\n }\n\n const out = new Map<string, Array<string>>()\n for (const [source, set] of namesBySource) {\n out.set(source, Array.from(set).sort())\n }\n return out\n}\n\n/** Collect all valid named export identifiers from the given code. */\nexport function collectNamedExports(code: string): Array<string> {\n return collectNamedExportsFromAst(parseImportProtectionAst(code))\n}\n\nfunction collectIdentifiersFromPattern(\n pattern: t.LVal,\n add: (name: string) => void,\n): void {\n if (t.isIdentifier(pattern)) {\n add(pattern.name)\n } else if (t.isObjectPattern(pattern)) {\n for (const prop of pattern.properties) {\n if (t.isRestElement(prop)) {\n collectIdentifiersFromPattern(prop.argument as t.LVal, add)\n } else {\n collectIdentifiersFromPattern(prop.value as t.LVal, add)\n }\n }\n } else if (t.isArrayPattern(pattern)) {\n for (const elem of pattern.elements) {\n if (elem) collectIdentifiersFromPattern(elem as t.LVal, add)\n }\n } else if (t.isAssignmentPattern(pattern)) {\n collectIdentifiersFromPattern(pattern.left, add)\n } else if (t.isRestElement(pattern)) {\n collectIdentifiersFromPattern(pattern.argument as t.LVal, add)\n }\n}\n\nfunction collectNamedExportsFromAst(ast: ParsedAst): Array<string> {\n const names = new Set<string>()\n const add = (name: string) => {\n if (isValidExportName(name)) names.add(name)\n }\n\n for (const node of ast.program.body) {\n if (t.isExportNamedDeclaration(node)) {\n if (node.exportKind === 'type') continue\n\n if (node.declaration) {\n const decl = node.declaration\n if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {\n if (decl.id?.name) add(decl.id.name)\n } else if (t.isVariableDeclaration(decl)) {\n for (const d of decl.declarations) {\n collectIdentifiersFromPattern(d.id as t.LVal, add)\n }\n }\n }\n\n for (const s of node.specifiers) {\n if (!t.isExportSpecifier(s)) continue\n if (s.exportKind === 'type') continue\n const exportedName = t.isIdentifier(s.exported)\n ? s.exported.name\n : s.exported.value\n add(exportedName)\n }\n }\n }\n\n return Array.from(names).sort()\n}\n\n/**\n * Rewrite static imports/re-exports from denied sources using Babel AST transforms.\n *\n * Transforms:\n * import { a as b, c } from 'denied'\n * Into:\n * import __tss_deny_0 from 'tanstack-start-import-protection:mock'\n * const b = __tss_deny_0.a\n * const c = __tss_deny_0.c\n *\n * Also handles:\n * import def from 'denied' -> import def from mock\n * import * as ns from 'denied' -> import ns from mock\n * export { x } from 'denied' -> export const x = mock.x\n * export * from 'denied' -> removed\n * export { x as y } from 'denied' -> export const y = mock.x\n */\nexport function rewriteDeniedImports(\n code: string,\n id: string,\n deniedSources: Set<string>,\n getMockModuleId: (source: string) => string = () => MOCK_MODULE_ID,\n): { code: string; map?: SourceMapLike } | undefined {\n return rewriteDeniedImportsFromAst(\n parseImportProtectionAst(code),\n id,\n deniedSources,\n getMockModuleId,\n )\n}\n\nfunction rewriteDeniedImportsFromAst(\n ast: ParsedAst,\n id: string,\n deniedSources: Set<string>,\n getMockModuleId: (source: string) => string = () => MOCK_MODULE_ID,\n): { code: string; map?: SourceMapLike } | undefined {\n let modified = false\n let mockCounter = 0\n\n // Walk program body in reverse so splice indices stay valid\n for (let i = ast.program.body.length - 1; i >= 0; i--) {\n const node = ast.program.body[i]!\n\n if (t.isImportDeclaration(node)) {\n if (node.importKind === 'type') continue\n if (!deniedSources.has(node.source.value)) continue\n\n const mockVar = `__tss_deny_${mockCounter++}`\n const replacements: Array<t.Statement> = []\n\n replacements.push(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(mockVar))],\n t.stringLiteral(getMockModuleId(node.source.value)),\n ),\n )\n\n for (const specifier of node.specifiers) {\n if (\n t.isImportDefaultSpecifier(specifier) ||\n t.isImportNamespaceSpecifier(specifier)\n ) {\n replacements.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(specifier.local.name),\n t.identifier(mockVar),\n ),\n ]),\n )\n } else if (t.isImportSpecifier(specifier)) {\n if (specifier.importKind === 'type') continue\n const importedName = t.isIdentifier(specifier.imported)\n ? specifier.imported.name\n : specifier.imported.value\n replacements.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(specifier.local.name),\n t.memberExpression(\n t.identifier(mockVar),\n t.identifier(importedName),\n ),\n ),\n ]),\n )\n }\n }\n\n ast.program.body.splice(i, 1, ...replacements)\n modified = true\n continue\n }\n\n if (t.isExportNamedDeclaration(node) && node.source) {\n if (node.exportKind === 'type') continue\n if (!deniedSources.has(node.source.value)) continue\n\n const mockVar = `__tss_deny_${mockCounter++}`\n const replacements: Array<t.Statement> = []\n\n replacements.push(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(mockVar))],\n t.stringLiteral(getMockModuleId(node.source.value)),\n ),\n )\n const exportSpecifiers: Array<{\n localName: string\n exportedName: string\n }> = []\n for (const specifier of node.specifiers) {\n if (t.isExportSpecifier(specifier)) {\n if (specifier.exportKind === 'type') continue\n const localName = specifier.local.name\n const exportedName = t.isIdentifier(specifier.exported)\n ? specifier.exported.name\n : specifier.exported.value\n\n const internalVar = `__tss_reexport_${localName}`\n replacements.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(internalVar),\n t.memberExpression(\n t.identifier(mockVar),\n t.identifier(localName),\n ),\n ),\n ]),\n )\n exportSpecifiers.push({ localName: internalVar, exportedName })\n }\n }\n\n if (exportSpecifiers.length > 0) {\n replacements.push(\n t.exportNamedDeclaration(\n null,\n exportSpecifiers.map((s) =>\n t.exportSpecifier(\n t.identifier(s.localName),\n t.identifier(s.exportedName),\n ),\n ),\n ),\n )\n }\n\n ast.program.body.splice(i, 1, ...replacements)\n modified = true\n continue\n }\n\n if (t.isExportAllDeclaration(node)) {\n if (node.exportKind === 'type') continue\n if (!deniedSources.has(node.source.value)) continue\n\n ast.program.body.splice(i, 1)\n modified = true\n continue\n }\n }\n\n if (!modified) return undefined\n\n const result = generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n\n return {\n code: result.code,\n ...(result.map ? { map: result.map as SourceMapLike } : {}),\n }\n}\n"],"names":[],"mappings":";;;;;AASO,SAAS,kBAAkB,MAAuB;AACvD,MAAI,SAAS,aAAa,KAAK,WAAW,EAAG,QAAO;AACpD,QAAM,QAAQ,KAAK,WAAW,CAAC;AAE/B,MACE,EACG,SAAS,MAAM,SAAS,MACxB,SAAS,MAAM,SAAS,OACzB,UAAU,MACV,UAAU;AAGZ,WAAO;AACT,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,KAAK,KAAK,WAAW,CAAC;AAE5B,QACE,EACG,MAAM,MAAM,MAAM,MAClB,MAAM,MAAM,MAAM,OAClB,M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OAAO;AAAA,kBACpB,EAAE,WAAW,SAAS;AAAA,gBAAA;AAAA,cACxB;AAAA,YACF,CACD;AAAA,UAAA;AAEH,2BAAiB,KAAK,EAAE,WAAW,aAAa,cAAc;AAAA,QAChE;AAAA,MACF;AAEA,UAAI,iBAAiB,SAAS,GAAG;AAC/B,qBAAa;AAAA,UACX,EAAE;AAAA,YACA;AAAA,YACA,iBAAiB;AAAA,cAAI,CAAC,MACpB,EAAE;AAAA,gBACA,EAAE,WAAW,EAAE,SAAS;AAAA,gBACxB,EAAE,WAAW,EAAE,YAAY;AAAA,cAAA;AAAA,YAC7B;AAAA,UACF;AAAA,QACF;AAAA,MAEJ;AAEA,UAAI,QAAQ,KAAK,OAAO,GAAG,GAAG,GAAG,YAAY;AAC7C,iBAAW;AACX;AAAA,IACF;AAEA,QAAI,EAAE,uBAAuB,IAAI,GAAG;AAClC,UAAI,KAAK,eAAe,OAAQ;AAChC,UAAI,CAAC,cAAc,IAAI,KAAK,OAAO,KAAK,EAAG;AAE3C,UAAI,QAAQ,KAAK,OAAO,GAAG,CAAC;AAC5B,iBAAW;AACX;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,SAAU,QAAO;AAEtB,QAAM,SAAS,gBAAgB,KAAK;AAAA,IAClC,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,UAAU;AAAA,EAAA,CACX;AAED,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,GAAI,OAAO,MAAM,EAAE,KAAK,OAAO,IAAA,IAAyB,CAAA;AAAA,EAAC;AAE7D;"}
1
+ {"version":3,"file":"rewriteDeniedImports.js","names":[],"sources":["../../../src/import-protection-plugin/rewriteDeniedImports.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { generateFromAst } from '@tanstack/router-utils'\n\nimport { MOCK_MODULE_ID } from './virtualModules'\nimport { getOrCreate } from './utils'\nimport { parseImportProtectionAst } from './ast'\nimport type { SourceMapLike } from './sourceLocation'\nimport type { ParsedAst } from './ast'\n\nexport function isValidExportName(name: string): boolean {\n if (name === 'default' || name.length === 0) return false\n const first = name.charCodeAt(0)\n // First char: A-Z (65-90), a-z (97-122), _ (95), $ (36)\n if (\n !(\n (first >= 65 && first <= 90) ||\n (first >= 97 && first <= 122) ||\n first === 95 ||\n first === 36\n )\n )\n return false\n for (let i = 1; i < name.length; i++) {\n const ch = name.charCodeAt(i)\n // Subsequent: A-Z, a-z, 0-9 (48-57), _, $\n if (\n !(\n (ch >= 65 && ch <= 90) ||\n (ch >= 97 && ch <= 122) ||\n (ch >= 48 && ch <= 57) ||\n ch === 95 ||\n ch === 36\n )\n )\n return false\n }\n return true\n}\n\nexport function collectMockExportNamesBySource(\n code: string,\n): Map<string, Array<string>> {\n return collectMockExportNamesBySourceFromAst(parseImportProtectionAst(code))\n}\n\nfunction collectMockExportNamesBySourceFromAst(\n ast: ParsedAst,\n): Map<string, Array<string>> {\n const namesBySource = new Map<string, Set<string>>()\n const memberBindingToSource = new Map<string, string>()\n const add = (source: string, name: string) => {\n if (name === 'default' || name.length === 0) return\n getOrCreate(namesBySource, source, () => new Set<string>()).add(name)\n }\n\n for (const node of ast.program.body) {\n if (t.isImportDeclaration(node)) {\n if (node.importKind === 'type') continue\n const source = node.source.value\n for (const s of node.specifiers) {\n if (t.isImportNamespaceSpecifier(s)) {\n memberBindingToSource.set(s.local.name, source)\n continue\n }\n if (t.isImportDefaultSpecifier(s)) {\n memberBindingToSource.set(s.local.name, source)\n continue\n }\n if (!t.isImportSpecifier(s)) continue\n if (s.importKind === 'type') continue\n const importedName = t.isIdentifier(s.imported)\n ? s.imported.name\n : s.imported.value\n // `import { default as x } from 'm'` only requires a default export.\n if (importedName === 'default') continue\n add(source, importedName)\n }\n }\n\n if (t.isExportNamedDeclaration(node) && node.source?.value) {\n if (node.exportKind === 'type') continue\n const source = node.source.value\n for (const s of node.specifiers) {\n if (!t.isExportSpecifier(s)) continue\n if (s.exportKind === 'type') continue\n add(source, s.local.name)\n }\n }\n }\n\n // For namespace/default imports, collect property names used as\n // `binding.foo`/`binding?.foo` so mock-edge modules can expose explicit ESM\n // named exports required by Rolldown/native ESM.\n if (memberBindingToSource.size > 0) {\n const visit = (node: t.Node): void => {\n if (t.isMemberExpression(node)) {\n const object = node.object\n if (t.isIdentifier(object)) {\n const source = memberBindingToSource.get(object.name)\n if (source) {\n const property = node.property\n if (!node.computed && t.isIdentifier(property)) {\n add(source, property.name)\n } else if (node.computed && t.isStringLiteral(property)) {\n add(source, property.value)\n }\n }\n }\n }\n\n const keys = t.VISITOR_KEYS[node.type]\n if (!keys) return\n for (const key of keys) {\n const child = (node as unknown as Record<string, unknown>)[key]\n if (Array.isArray(child)) {\n for (const item of child) {\n if (item && typeof item === 'object' && 'type' in item) {\n visit(item as t.Node)\n }\n }\n } else if (child && typeof child === 'object' && 'type' in child) {\n visit(child as t.Node)\n }\n }\n }\n\n visit(ast.program)\n }\n\n const out = new Map<string, Array<string>>()\n for (const [source, set] of namesBySource) {\n out.set(source, Array.from(set).sort())\n }\n return out\n}\n\n/** Collect all valid named export identifiers from the given code. */\nexport function collectNamedExports(code: string): Array<string> {\n return collectNamedExportsFromAst(parseImportProtectionAst(code))\n}\n\nfunction collectIdentifiersFromPattern(\n pattern: t.LVal,\n add: (name: string) => void,\n): void {\n if (t.isIdentifier(pattern)) {\n add(pattern.name)\n } else if (t.isObjectPattern(pattern)) {\n for (const prop of pattern.properties) {\n if (t.isRestElement(prop)) {\n collectIdentifiersFromPattern(prop.argument as t.LVal, add)\n } else {\n collectIdentifiersFromPattern(prop.value as t.LVal, add)\n }\n }\n } else if (t.isArrayPattern(pattern)) {\n for (const elem of pattern.elements) {\n if (elem) collectIdentifiersFromPattern(elem as t.LVal, add)\n }\n } else if (t.isAssignmentPattern(pattern)) {\n collectIdentifiersFromPattern(pattern.left, add)\n } else if (t.isRestElement(pattern)) {\n collectIdentifiersFromPattern(pattern.argument as t.LVal, add)\n }\n}\n\nfunction collectNamedExportsFromAst(ast: ParsedAst): Array<string> {\n const names = new Set<string>()\n const add = (name: string) => {\n if (isValidExportName(name)) names.add(name)\n }\n\n for (const node of ast.program.body) {\n if (t.isExportNamedDeclaration(node)) {\n if (node.exportKind === 'type') continue\n\n if (node.declaration) {\n const decl = node.declaration\n if (t.isFunctionDeclaration(decl) || t.isClassDeclaration(decl)) {\n if (decl.id?.name) add(decl.id.name)\n } else if (t.isVariableDeclaration(decl)) {\n for (const d of decl.declarations) {\n collectIdentifiersFromPattern(d.id as t.LVal, add)\n }\n }\n }\n\n for (const s of node.specifiers) {\n if (!t.isExportSpecifier(s)) continue\n if (s.exportKind === 'type') continue\n const exportedName = t.isIdentifier(s.exported)\n ? s.exported.name\n : s.exported.value\n add(exportedName)\n }\n }\n }\n\n return Array.from(names).sort()\n}\n\n/**\n * Rewrite static imports/re-exports from denied sources using Babel AST transforms.\n *\n * Transforms:\n * import { a as b, c } from 'denied'\n * Into:\n * import __tss_deny_0 from 'tanstack-start-import-protection:mock'\n * const b = __tss_deny_0.a\n * const c = __tss_deny_0.c\n *\n * Also handles:\n * import def from 'denied' -> import def from mock\n * import * as ns from 'denied' -> import ns from mock\n * export { x } from 'denied' -> export const x = mock.x\n * export * from 'denied' -> removed\n * export { x as y } from 'denied' -> export const y = mock.x\n */\nexport function rewriteDeniedImports(\n code: string,\n id: string,\n deniedSources: Set<string>,\n getMockModuleId: (source: string) => string = () => MOCK_MODULE_ID,\n): { code: string; map?: SourceMapLike } | undefined {\n return rewriteDeniedImportsFromAst(\n parseImportProtectionAst(code),\n id,\n deniedSources,\n getMockModuleId,\n )\n}\n\nfunction rewriteDeniedImportsFromAst(\n ast: ParsedAst,\n id: string,\n deniedSources: Set<string>,\n getMockModuleId: (source: string) => string = () => MOCK_MODULE_ID,\n): { code: string; map?: SourceMapLike } | undefined {\n let modified = false\n let mockCounter = 0\n\n // Walk program body in reverse so splice indices stay valid\n for (let i = ast.program.body.length - 1; i >= 0; i--) {\n const node = ast.program.body[i]!\n\n if (t.isImportDeclaration(node)) {\n if (node.importKind === 'type') continue\n if (!deniedSources.has(node.source.value)) continue\n\n const mockVar = `__tss_deny_${mockCounter++}`\n const replacements: Array<t.Statement> = []\n\n replacements.push(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(mockVar))],\n t.stringLiteral(getMockModuleId(node.source.value)),\n ),\n )\n\n for (const specifier of node.specifiers) {\n if (\n t.isImportDefaultSpecifier(specifier) ||\n t.isImportNamespaceSpecifier(specifier)\n ) {\n replacements.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(specifier.local.name),\n t.identifier(mockVar),\n ),\n ]),\n )\n } else if (t.isImportSpecifier(specifier)) {\n if (specifier.importKind === 'type') continue\n const importedName = t.isIdentifier(specifier.imported)\n ? specifier.imported.name\n : specifier.imported.value\n replacements.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(specifier.local.name),\n t.memberExpression(\n t.identifier(mockVar),\n t.identifier(importedName),\n ),\n ),\n ]),\n )\n }\n }\n\n ast.program.body.splice(i, 1, ...replacements)\n modified = true\n continue\n }\n\n if (t.isExportNamedDeclaration(node) && node.source) {\n if (node.exportKind === 'type') continue\n if (!deniedSources.has(node.source.value)) continue\n\n const mockVar = `__tss_deny_${mockCounter++}`\n const replacements: Array<t.Statement> = []\n\n replacements.push(\n t.importDeclaration(\n [t.importDefaultSpecifier(t.identifier(mockVar))],\n t.stringLiteral(getMockModuleId(node.source.value)),\n ),\n )\n const exportSpecifiers: Array<{\n localName: string\n exportedName: string\n }> = []\n for (const specifier of node.specifiers) {\n if (t.isExportSpecifier(specifier)) {\n if (specifier.exportKind === 'type') continue\n const localName = specifier.local.name\n const exportedName = t.isIdentifier(specifier.exported)\n ? specifier.exported.name\n : specifier.exported.value\n\n const internalVar = `__tss_reexport_${localName}`\n replacements.push(\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(internalVar),\n t.memberExpression(\n t.identifier(mockVar),\n t.identifier(localName),\n ),\n ),\n ]),\n )\n exportSpecifiers.push({ localName: internalVar, exportedName })\n }\n }\n\n if (exportSpecifiers.length > 0) {\n replacements.push(\n t.exportNamedDeclaration(\n null,\n exportSpecifiers.map((s) =>\n t.exportSpecifier(\n t.identifier(s.localName),\n t.identifier(s.exportedName),\n ),\n ),\n ),\n )\n }\n\n ast.program.body.splice(i, 1, ...replacements)\n modified = true\n continue\n }\n\n if (t.isExportAllDeclaration(node)) {\n if (node.exportKind === 'type') continue\n if (!deniedSources.has(node.source.value)) continue\n\n ast.program.body.splice(i, 1)\n modified = true\n continue\n }\n }\n\n if (!modified) return undefined\n\n const result = generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n\n return {\n code: result.code,\n ...(result.map ? { map: result.map as SourceMapLike } : {}),\n }\n}\n"],"mappings":";;;;;;AASA,SAAgB,kBAAkB,MAAuB;AACvD,KAAI,SAAS,aAAa,KAAK,WAAW,EAAG,QAAO;CACpD,MAAM,QAAQ,KAAK,WAAW,EAAE;AAEhC,KACE,EACG,SAAS,MAAM,SAAS,MACxB,SAAS,MAAM,SAAS,OACzB,UAAU,MACV,UAAU,IAGZ,QAAO;AACT,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,KAAK,KAAK,WAAW,EAAE;AAE7B,MACE,EACG,MAAM,MAAM,MAAM,MAClB,MAAM,MAAM,MAAM,OAClB,MAAM,MAAM,MAAM,MACnB,OAAO,MACP,OAAO,IAGT,QAAO;;AAEX,QAAO;;AAGT,SAAgB,+BACd,MAC4B;AAC5B,QAAO,sCAAsC,yBAAyB,KAAK,CAAC;;AAG9E,SAAS,sCACP,KAC4B;CAC5B,MAAM,gCAAgB,IAAI,KAA0B;CACpD,MAAM,wCAAwB,IAAI,KAAqB;CACvD,MAAM,OAAO,QAAgB,SAAiB;AAC5C,MAAI,SAAS,aAAa,KAAK,WAAW,EAAG;AAC7C,cAAY,eAAe,8BAAc,IAAI,KAAa,CAAC,CAAC,IAAI,KAAK;;AAGv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