@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
41 lines (39 loc) • 1.26 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.contextToAngular = void 0;
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
const standalone_1 = require("prettier/standalone");
const contextToAngular = (options = { typescript: false }) => ({ context }) => {
let str = `
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export default class ${context.name}Context {
${(0, get_state_object_string_1.stringifyContextValue)(context.value)
.replace(/^\{/, '')
.replace(/\}$/, '')
.replaceAll(',', ';\n')
.replaceAll(':', ': any = ')}
constructor() { }
}
`;
if (options.format !== false) {
try {
str = (0, standalone_1.format)(str, {
parser: 'typescript',
plugins: [
require('prettier/parser-typescript'), // To support running in browsers
],
});
}
catch (err) {
if (process.env.NODE_ENV !== 'test') {
console.error('Format error for file:', str);
}
throw err;
}
}
return str;
};
exports.contextToAngular = contextToAngular;
;