@fink/loxia
Version:
A fink to JavaScript compiler.
235 lines (201 loc) • 6.76 kB
JavaScript
import babel_types_0 from "@babel/types";
const jsxIdentifier_0 = babel_types_0.jsxIdentifier;
const jsxExpressionContainer_0 = babel_types_0.jsxExpressionContainer;
import { length as length_0 } from "@fink/std-lib/iter.js";
import { add as add_0 } from "../context.js";
import { set_js2 as set_js2_0 } from "../context.js";
import { get_js as get_js_0 } from "../context.js";
import { get_js_literal as get_js_literal_0 } from "../context.js";
import { with_loc as with_loc_0 } from "../context.js";
const transform_prop_id_0 = key_18 => {
/* istanbul ignore else */
if (null != key_18) {
/* istanbul ignore else */
if (key_18.type === `Identifier`) {
const arg_4 = jsxIdentifier_0(key_18.name);
const result_2 = with_loc_0(key_18, arg_4);
return result_2;
}
}
/* istanbul ignore else */
if (null != key_18) {
/* istanbul ignore else */
if (key_18.type === `StringLiteral`) {
const arg_1 = jsxIdentifier_0(key_18.value);
const result_1 = with_loc_0(key_18, arg_1);
return result_1;
}
}
/* istanbul ignore next */
return;
};
const transform_prop_val_0 = value_1 => {
/* istanbul ignore else */
if (null != value_1) {
/* istanbul ignore else */
if (value_1.type === `TemplateLiteral`) {
const right_0 = length_0(value_1.quasis);
/* istanbul ignore else */
if (true === (1 === right_0)) {
const arg_10 = babel_types_0.stringLiteral(value_1.quasis[0].value.raw);
const result_6 = with_loc_0(value_1, arg_10);
return result_6;
}
}
}
const arg_7 = jsxExpressionContainer_0(value_1);
const result_4 = with_loc_0(value_1, arg_7);
return result_4;
};
const transform_props_0 = (...args_2) => {
transform_props_0: do {
const dlst_0 = args_2[0];
const hdm_0 = dlst_0[0];
const prop_0 = undefined === hdm_0 ? false : hdm_0;
const tail_4 = dlst_0.slice(1);
const hdm_1 = args_2[1];
const out_0 = undefined === hdm_1 ? [] : hdm_1;
/* istanbul ignore else */
if (prop_0 === false) {
return out_0;
}
/* istanbul ignore else */
if (null != prop_0) {
/* istanbul ignore else */
if (prop_0.type === `ObjectProperty`) {
const arg_15 = transform_prop_id_0(prop_0.key);
const arg_17 = transform_prop_val_0(prop_0.value);
const attr_1 = babel_types_0.jsxAttribute(arg_15, arg_17);
args_2 = [tail_4, [...out_0, attr_1]];
continue transform_props_0;
}
}
/* istanbul ignore else */
if (null != prop_0) {
/* istanbul ignore else */
if (prop_0.type === `SpreadElement`) {
const attr_0 = babel_types_0.jsxSpreadAttribute(prop_0.argument);
args_2 = [tail_4, [...out_0, attr_0]];
continue transform_props_0;
}
}
/* istanbul ignore next */
return;
} while (true);
};
const transform_children_0 = (...args_3) => {
transform_children_0: do {
const dlst_1 = args_3[0];
const hdm_2 = dlst_1[0];
const chld_0 = undefined === hdm_2 ? false : hdm_2;
const tail_7 = dlst_1.slice(1);
const hdm_3 = args_3[1];
const out_1 = undefined === hdm_3 ? [] : hdm_3;
/* istanbul ignore else */
if (chld_0 === false) {
return out_1;
}
/* istanbul ignore else */
if (null != chld_0) {
/* istanbul ignore else */
if (chld_0.type === `TemplateLiteral`) {
const right_1 = length_0(chld_0.quasis);
/* istanbul ignore else */
if (true === (1 === right_1)) {
const arg_29 = babel_types_0.jsxText(chld_0.quasis[0].value.raw);
const js_1 = with_loc_0(chld_0, arg_29);
args_3 = [tail_7, [...out_1, js_1]];
continue transform_children_0;
}
}
}
/* istanbul ignore else */
if (null != chld_0) {
/* istanbul ignore else */
if (chld_0.type === `JSXElement`) {
args_3 = [tail_7, [...out_1, chld_0]];
continue transform_children_0;
}
}
const arg_22 = jsxExpressionContainer_0(chld_0);
const js_0 = with_loc_0(chld_0, arg_22);
args_3 = [tail_7, [...out_1, js_0]];
continue transform_children_0;
} while (true);
};
const transform_jxe_0 = (expr_0, ctx_0) => {
const val_15 = expr_0[0].args;
const name_id_0 = val_15[0];
const id_v_0 = get_js_literal_0(name_id_0, ctx_0);
let ret_8;
ret_8: {
/* istanbul ignore else */
if (null != id_v_0) {
/* istanbul ignore else */
if (id_v_0.type === `TemplateLiteral`) {
const arg_39 = jsxIdentifier_0(id_v_0.quasis[0].value.raw);
const result_26 = with_loc_0(name_id_0, arg_39);
ret_8 = result_26;
/* istanbul ignore next */
break ret_8;
}
}
const left_7 = get_js_0(name_id_0, ctx_0);
const result_24 = jsxIdentifier_0(left_7.name);
ret_8 = result_24;
/* istanbul ignore next */
break ret_8;
}
const id_0 = ret_8;
const ppr_0 = (prtl_0 => {
const pfn_1 = get_js_literal_0(prtl_0, ctx_0);
return pfn_1;
})(val_15[1]);
const ppr_1 = (prtl_1 => {
return prtl_1.properties;
})(ppr_0);
const ppr_2 = transform_props_0(ppr_1);
const ppr_3 = (prtl_2 => {
const pfn_6 = get_js_literal_0(prtl_2, ctx_0);
return pfn_6;
})(val_15[2]);
const ppr_4 = (prtl_3 => {
return prtl_3.elements;
})(ppr_3);
const ppr_5 = transform_children_0(ppr_4);
const right_2 = length_0(ppr_5);
const arg_43 = babel_types_0.jsxOpeningElement(id_0, ppr_2, 0 === right_2);
const arg_48 = babel_types_0.jsxClosingElement(id_0);
const js_2 = babel_types_0.jsxElement(arg_43, arg_48, ppr_5);
const result_30 = set_js2_0(expr_0, js_2, ctx_0);
return result_30;
};
const transform_jxf_0 = (expr_1, ctx_1) => {
const ppr_6 = (prtl_4 => {
const pfn_11 = get_js_literal_0(prtl_4, ctx_1);
return pfn_11;
})(expr_1[0].args[0]);
const ppr_7 = (prtl_5 => {
return prtl_5.elements;
})(ppr_6);
const ppr_8 = transform_children_0(ppr_7);
const arg_55 = babel_types_0.jsxOpeningFragment();
const arg_56 = babel_types_0.jsxClosingFragment();
const js_3 = babel_types_0.jsxFragment(arg_55, arg_56, ppr_8);
const result_34 = set_js2_0(expr_1, js_3, ctx_1);
return result_34;
};
const add_jsx_0 = ctx_2 => {
const pfn_15 = add_0(`jxe`, transform_jxe_0);
const ppr_9 = pfn_15(ctx_2);
const pfn_16 = add_0(`jxf`, transform_jxf_0);
const ppr_10 = pfn_16(ppr_9);
return ppr_10;
};
export const transform_prop_id = transform_prop_id_0,
transform_prop_val = transform_prop_val_0,
transform_props = transform_props_0,
transform_children = transform_children_0,
transform_jxe = transform_jxe_0,
transform_jxf = transform_jxf_0,
add_jsx = add_jsx_0;