MCPcopy
hub / github.com/rollup/rollup / renderBlock

Method renderBlock

src/ast/variables/NamespaceVariable.ts:130–184  ·  view source on GitHub ↗
(options: RenderOptions)

Source from the content-addressed store, hash-verified

128 }
129
130 renderBlock(options: RenderOptions): string {
131 const {
132 exportNamesByVariable,
133 format,
134 freeze,
135 indent: t,
136 symbols,
137 snippets: { _, cnst, getObject, getPropertyAccess, n, s }
138 } = options;
139 const memberVariables = this.module.getExportedVariablesByName();
140 const members: [key: string | null, value: string][] = [...memberVariables.entries()]
141 .filter(([name, variable]) => !name.startsWith('*') && variable.included)
142 .map(([name, variable]) => {
143 if (this.referencedEarly || variable.isReassigned || variable === this) {
144 return [
145 null,
146 `get ${stringifyObjectKeyIfNeeded(name)}${_}()${_}{${_}return ${variable.getName(
147 getPropertyAccess
148 )}${s}${_}}`
149 ];
150 }
151
152 return [name, variable.getName(getPropertyAccess)];
153 });
154 members.unshift([null, `__proto__:${_}null`]);
155
156 let output = getObject(members, { lineBreakIndent: { base: '', t } });
157 if (this.mergedNamespaces.length > 0) {
158 const assignmentArguments = this.mergedNamespaces.map(variable =>
159 variable.getName(getPropertyAccess)
160 );
161 output = `/*#__PURE__*/${MERGE_NAMESPACES_VARIABLE}(${output},${_}[${assignmentArguments.join(
162 `,${_}`
163 )}])`;
164 } else {
165 // The helper to merge namespaces will also take care of freezing and toStringTag
166 if (symbols) {
167 output = `/*#__PURE__*/Object.defineProperty(${output},${_}Symbol.toStringTag,${_}${getToStringTagValue(
168 getObject
169 )})`;
170 }
171 if (freeze) {
172 output = `/*#__PURE__*/Object.freeze(${output})`;
173 }
174 }
175
176 const name = this.getName(getPropertyAccess);
177 output = `${cnst} ${name}${_}=${_}${output};`;
178
179 if (format === 'system' && exportNamesByVariable.has(this)) {
180 output += `${n}${getSystemExportStatement([this], options)};`;
181 }
182
183 return output;
184 }
185
186 renderFirst(): boolean {
187 return this.referencedEarly;

Callers 1

renderModulesMethod · 0.80

Calls 7

getToStringTagValueFunction · 0.90
getSystemExportStatementFunction · 0.90
getObjectFunction · 0.85
hasMethod · 0.65
getNameMethod · 0.45

Tested by

no test coverage detected