(path)
| 82 | Object.keys(path.scope.bindings).forEach((b) => declared.add(b)); |
| 83 | }, |
| 84 | ImportDeclaration(path) { |
| 85 | const src = path.node.source?.value as string; |
| 86 | if (src === '@') { |
| 87 | path.node.source = t.stringLiteral('/ns/m/__invalid_at__.mjs'); |
| 88 | } |
| 89 | if (isVueLike(src)) { |
| 90 | path.node.source = t.stringLiteral('/ns/rt'); |
| 91 | } else if (isNsCorePackage(src)) { |
| 92 | // Rewrite any @nativescript/core[/*] to the HTTP-ESM bridge |
| 93 | path.node.source = t.stringLiteral('/ns/core'); |
| 94 | } else if (isVitePrebundle(src)) { |
| 95 | const id = vitePrebundleId(src); |
| 96 | if (id && /^(?:pinia)(?:$|[_\.-])/.test(id)) { |
| 97 | // Rewrite pinia prebundles to bare 'pinia' so vendor binding can handle it later |
| 98 | path.node.source = t.stringLiteral('pinia'); |
| 99 | } else if (isVuePrebundle(src)) { |
| 100 | // Route vue prebundles to runtime bridge |
| 101 | path.node.source = t.stringLiteral('/ns/rt'); |
| 102 | } else { |
| 103 | // Keep other prebundles as-is; they may be fetchable directly from the dev server |
| 104 | } |
| 105 | } else if (isViteVirtual(src) || src === '@vite/client' || src === '/@vite/client') { |
| 106 | path.remove(); |
| 107 | return; |
| 108 | } |
| 109 | const isRt = isRtLike(path.node.source?.value as string); |
| 110 | const isCore = isCoreLike(path.node.source?.value as string); |
| 111 | // Ensure any generated binding names are valid identifiers and not reserved like 'this' |
| 112 | const isValidLocal = (n: string) => { |
| 113 | try { |
| 114 | return t.isValidIdentifier(n) && n !== 'this'; |
| 115 | } catch { |
| 116 | return /^[A-Za-z_$][\w$]*$/.test(n) && n !== 'this'; |
| 117 | } |
| 118 | }; |
| 119 | const makeUniqueLocal = (base: string) => { |
| 120 | let name = base; |
| 121 | if (!isValidLocal(name)) { |
| 122 | name = `__ns_${name.replace(/[^A-Za-z0-9_$]+/g, '_') || 'id'}`; |
| 123 | } |
| 124 | let i = 1; |
| 125 | let cand = name; |
| 126 | while (declared.has(cand)) { |
| 127 | cand = `${name}_${i++}`; |
| 128 | } |
| 129 | declared.add(cand); |
| 130 | return cand; |
| 131 | }; |
| 132 | if (isRt || isCore) { |
| 133 | let named = (path.node.specifiers || []).filter((s) => t.isImportSpecifier(s)) as t.ImportSpecifier[]; |
| 134 | if (isRt && named.length) { |
| 135 | named = named.filter((s) => { |
| 136 | const imp = s.imported as any; |
| 137 | const name = (imp && (imp.name || String(imp))) as string; |
| 138 | return name !== '$navigateTo' && name !== '$navigateBack'; |
| 139 | }); |
| 140 | } |
| 141 | const hasDefault = path.node.specifiers.some((s) => t.isImportDefaultSpecifier(s)); |
nothing calls this directly
no test coverage detected