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

Function ImportDeclaration

packages/vite/configuration/vue.ts:124–157  ·  view source on GitHub ↗
(path: any)

Source from the content-addressed store, hash-verified

122 },
123 },
124 ImportDeclaration(path: any) {
125 const node: t.ImportDeclaration = path.node;
126 const src = node.source.value;
127 if (src !== 'nativescript-vue') return;
128 const named = node.specifiers?.filter((s) => s.type === 'ImportSpecifier') as t.ImportSpecifier[];
129 if (!named?.length) return;
130 mutated = true;
131 // Ensure our helpers are available
132 hasNSVNamespace = true;
133 hasNSVDefaultVar = true;
134
135 // Gather new variable declarations for each named specifier
136 const decls: t.VariableDeclarator[] = [];
137 for (const spec of named) {
138 const imported = (spec.imported as t.Identifier).name;
139 const local = (spec.local as t.Identifier).name;
140 const pickExpr = t.logicalExpression('||', t.memberExpression(t.identifier(nsVarName), t.identifier(imported), false), t.memberExpression(t.identifier(defVarName), t.identifier(imported), false));
141 const bindHelper = t.callExpression(t.arrowFunctionExpression([t.identifier('v')], t.conditionalExpression(t.binaryExpression('===', t.unaryExpression('typeof', t.identifier('v')), t.stringLiteral('function')), t.callExpression(t.memberExpression(t.identifier('v'), t.identifier('bind')), [t.identifier(defVarName)]), t.identifier('v'))), [pickExpr]);
142 decls.push(t.variableDeclarator(t.identifier(local), bindHelper));
143 }
144
145 // Build replacement: remove named specifiers from original import
146 const remaining = node.specifiers.filter((s) => s.type !== 'ImportSpecifier');
147 const newStmts: t.Statement[] = [];
148 if (remaining.length) {
149 // Keep any default/namespace import as-is
150 newStmts.push(t.importDeclaration(remaining as any, t.stringLiteral('nativescript-vue')));
151 }
152 // Always ensure namespace/default helpers are present by prepending in Program.exit
153 newStmts.push(t.variableDeclaration('const', decls));
154
155 nodesToRemove.push(node);
156 newNodes.push(...newStmts);
157 },
158 });
159
160 if (!mutated) return null;

Callers

nothing calls this directly

Calls 2

filterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected