@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
50 lines (49 loc) • 1.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.stableInject = void 0;
/**
* Similar to our `stableJSONSerialize` function, except that it does not stringify the values: it injects them as-is.
* This is needed for our `MitosisState` values which are JS expressions stored as strings.
*/
function stableInject(obj) {
const output = [];
_serialize(output, obj);
return output.join('');
}
exports.stableInject = stableInject;
function _serialize(output, obj) {
if (obj == null) {
output.push('null');
}
else if (typeof obj === 'object') {
if (Array.isArray(obj)) {
output.push('[');
let sep = '';
for (let i = 0; i < obj.length; i++) {
output.push(sep);
_serialize(output, obj[i]);
sep = ',';
}
output.push(']');
}
else {
const keys = Object.keys(obj).sort();
output.push('{');
let sep = '';
for (const key of keys) {
const value = obj[key];
if (value !== undefined) {
output.push(sep);
output.push(JSON.stringify(key));
output.push(':');
_serialize(output, value);
sep = ',';
}
}
output.push('}');
}
}
else {
output.push(obj);
}
}
;