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

Function stripRtCoreSentinel

packages/vite/hmr/helpers/sanitize.ts:5–24  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

3// Remove any ns_core_ns_1 mapping from destructuring off the runtime default (__ns_rt_ns_*),
4// which would otherwise create a local like __ns_core_ns_1 that can collide with explicit core imports.
5export function stripRtCoreSentinel(code: string): string {
6 try {
7 let out = code;
8 // Remove the standalone form: const { ns_core_ns_1: __ns_core_ns_1 } = __ns_rt_ns_<n|re>;
9 out = out.replace(/(^|\n)\s*const\s*\{\s*ns_core_ns_1\s*:\s*__ns_core_ns_1\s*\}\s*=\s*__ns_rt_ns_(?:\d+|re)\s*;\s*/g, '$1');
10 // Remove leading property in a multi-prop destructure
11 out = out.replace(/(\{\s*)ns_core_ns_1\s*:\s*__ns_core_ns_1\s*,\s*([^}]*\}\s*=\s*__ns_rt_ns_(?:\d+|re)\s*;)/g, '{$2');
12 // Remove trailing property in a multi-prop destructure
13 out = out.replace(/(\{[^}]*?,)\s*ns_core_ns_1\s*:\s*__ns_core_ns_1\s*(\}\s*=\s*__ns_rt_ns_(?:\d+|re)\s*;)/g, '$1$2');
14 // Remove middle property in a multi-prop destructure
15 out = out.replace(/(\{[^}]*?,)\s*ns_core_ns_1\s*:\s*__ns_core_ns_1\s*,\s*([^}]*\}\s*=\s*__ns_rt_ns_(?:\d+|re)\s*;)/g, '$1$2');
16 // Ultra-conservative fallback: strip any occurrence of mapping and clean up dangling commas
17 out = out.replace(/ns_core_ns_1\s*:\s*__ns_core_ns_1\s*,?\s*/g, (m) => '');
18 // Remove empty destructures: const { } = __ns_rt_ns_<n|re>;
19 out = out.replace(/(^|\n)\s*const\s*\{\s*\}\s*=\s*__ns_rt_ns_(?:\d+|re)\s*;\s*/g, '$1');
20 return out;
21 } catch {
22 return code;
23 }
24}
25
26// Neutralize dangling Vite CJS import helper usages like:
27// const foo = __vite__cjsImport4__pkg_flat["prop"];

Callers 2

sanitize.spec.tsFile · 0.90
configureServerFunction · 0.85

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected