MCPcopy Create free account
hub / github.com/BuilderIO/mitosis / updateReferencesInCode

Function updateReferencesInCode

packages/core/src/generators/html/generator.ts:239–269  ·  view source on GitHub ↗
(
  code: string,
  options: InternalToHtmlOptions,
  blockOptions: BlockOptions = {},
)

Source from the content-addressed store, hash-verified

237
238// TODO: overloaded function
239const updateReferencesInCode = (
240 code: string,
241 options: InternalToHtmlOptions,
242 blockOptions: BlockOptions = {},
243): string => {
244 const contextVars = blockOptions.contextVars || [];
245 const context = blockOptions?.context || 'this.';
246 if (options?.experimental?.updateReferencesInCode) {
247 return options?.experimental?.updateReferencesInCode(code, options, {
248 stripStateAndPropsRefs: deprecatedStripStateAndPropsRefs,
249 });
250 }
251 if (options.format === 'class') {
252 return pipe(
253 stripStateAndPropsRefs(code, {
254 includeProps: false,
255 includeState: true,
256 replaceWith: context + 'state.',
257 }),
258 (newCode) =>
259 stripStateAndPropsRefs(newCode, {
260 // TODO: replace with `this.` and add setters that call this.update()
261 includeProps: true,
262 includeState: false,
263 replaceWith: context + 'props.',
264 }),
265 (newCode) => DO_NOT_USE_CONTEXT_VARS_TRANSFORMS({ code: newCode, context, contextVars }),
266 );
267 }
268 return code;
269};
270
271const addOnChangeJs = (id: string, options: InternalToHtmlOptions, code: string) => {
272 if (!options.onChangeJsById[id]) {

Callers 3

blockToHtmlFunction · 0.85
componentToHtmlFunction · 0.85
componentToCustomElementFunction · 0.85

Calls 2

stripStateAndPropsRefsFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…