@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
31 lines (29 loc) • 1.03 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.contextToSolid = void 0;
const get_state_object_string_1 = require("../../helpers/get-state-object-string");
const standalone_1 = require("prettier/standalone");
const contextToSolid = (options = {}) => ({ context }) => {
let str = `
import { createContext } from 'solid-js';
export default createContext(${(0, get_state_object_string_1.stringifyContextValue)(context.value)})
`;
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.contextToSolid = contextToSolid;
;