(userOptions = {})
| 152 | |
| 153 | export 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 |
no test coverage detected