MCPcopy
hub / github.com/BuilderIO/mitosis / componentToMarko

Function componentToMarko

packages/core/src/generators/marko/generate.ts:154–312  ·  view source on GitHub ↗
(userOptions = {})

Source from the content-addressed store, hash-verified

152
153export const componentToMarko: TranspilerGenerator<ToMarkoOptions> =
154 (userOptions = {}) =>
155 ({ component }) => {
156 let json = fastClone(component);
157 const options = initializeOptions<InternalToMarkoOptions>({
158 target: 'marko',
159 component,
160 defaults: {
161 ...userOptions,
162 component: json,
163 },
164 });
165
166 if (options.plugins) {
167 json = runPreJsonPlugins({ json, plugins: options.plugins });
168 }
169 let css = collectCss(json, {
170 prefix: hash(json),
171 });
172
173 const domRefs = getRefs(json);
174 mapRefs(json, (refName) => `this.${camelCase(refName)}`);
175
176 if (options.plugins) {
177 json = runPostJsonPlugins({ json, plugins: options.plugins });
178 }
179 stripMetaProperties(json);
180
181 const dataString = getStateObjectStringFromComponent(json, {
182 format: 'object',
183 data: true,
184 functions: false,
185 getters: false,
186 valueMapper: (code) => processBinding(json, code, 'state'),
187 });
188
189 const thisHasProps = hasProps(json);
190
191 const methodsString = getStateObjectStringFromComponent(json, {
192 format: 'class',
193 data: false,
194 functions: true,
195 getters: true,
196 valueMapper: (code) => processBinding(json, code, 'class'),
197 });
198
199 const hasState = dataString.trim().length > 5;
200
201 if (options.prettier !== false) {
202 try {
203 css = format(css, {
204 parser: 'css',
205 plugins: [require('prettier/parser-postcss')],
206 });
207 } catch (err) {
208 console.warn('Could not format css', err);
209 }
210 }
211

Callers 2

generateCodeFunction · 0.85
getOutputGeneratorFunction · 0.85

Calls 15

fastCloneFunction · 0.90
initializeOptionsFunction · 0.90
runPreJsonPluginsFunction · 0.90
collectCssFunction · 0.90
getRefsFunction · 0.90
mapRefsFunction · 0.90
runPostJsonPluginsFunction · 0.90
stripMetaPropertiesFunction · 0.90
hasPropsFunction · 0.90
dedentFunction · 0.90
renderPreComponentFunction · 0.90

Tested by

no test coverage detected