MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / removeNamedImports

Function removeNamedImports

packages/vite/hmr/server/websocket.ts:656–679  ·  view source on GitHub ↗
(code: string, names: string[])

Source from the content-addressed store, hash-verified

654// (legacy wrapSfcWithStableDefault removed; full SFCs now delegate to /ns/asm)
655
656function removeNamedImports(code: string, names: string[]): string {
657 const regex = /^(\s*import\s*\{)([^}]*)(\}\s*from\s*['"][^'"]+['"];?)/gm;
658 return code.replace(regex, (_m, p1, specList, p3) => {
659 // Only strip for known globalized framework sources (Vue/Nativescript-Vue).
660 // Keep imports from all other packages (Pinia, third-party libs, app modules) intact.
661 const srcMatch = /from\s*['"]\s*([^'"\s]+)\s*['"]/i.exec(_m);
662 const src = (srcMatch?.[1] || '').toLowerCase();
663 const isVueSource = /^(?:vue|nativescript-vue)(?:\b|\/)/i.test(src);
664 if (!isVueSource) {
665 return _m;
666 }
667 const remaining = specList
668 .split(',')
669 .map((s: string) => s.trim())
670 .filter(Boolean)
671 .filter((entry: string) => {
672 const base = entry.split(/\s+as\s+/i)[0].trim();
673 return !names.includes(base);
674 });
675
676 if (!remaining.length) return '';
677 return `${p1} ${remaining.join(', ')} ${p3}`;
678 });
679}
680
681/**
682 * Inject global bindings for given names

Callers 1

processCodeForDeviceFunction · 0.85

Calls 6

replaceMethod · 0.80
includesMethod · 0.80
joinMethod · 0.80
mapMethod · 0.65
testMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected