@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
59 lines (57 loc) • 1.97 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
_intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
//#region src/interpreter/getContent/deepTransform.ts
/**
* Recursively traverses a node (object/array/primitive).
* Applies the *first* plugin that can transform a node, then stops descending further.
* If no plugin transforms it, it recurses into its children.
*/
const deepTransformNode = (node, props) => {
for (const plugin of props.plugins ?? []) if (plugin.canHandle(node)) return plugin.transform(node, props, (node, props) => deepTransformNode(node, props));
if (node === null || typeof node !== "object") return node;
if (node.$$typeof !== void 0 || node.__v_isVNode !== void 0 || node._isVNode !== void 0 || node.isJSX !== void 0 || typeof node === "function") return node;
if (Array.isArray(node)) return node.map((child, index) => {
return deepTransformNode(child, {
...props,
children: child,
keyPath: [...props.keyPath, {
type: _intlayer_types_nodeType.ARRAY,
key: index
}]
});
});
const result = {};
for (const key in node) {
const childProps = {
...props,
children: node[key],
keyPath: [...props.keyPath, {
type: _intlayer_types_nodeType.OBJECT,
key
}]
};
if (props.eager) {
result[key] = deepTransformNode(node[key], childProps);
continue;
}
Object.defineProperty(result, key, {
enumerable: true,
configurable: true,
get: function() {
const transformed = deepTransformNode(node[key], childProps);
Object.defineProperty(this, key, {
value: transformed,
enumerable: true,
configurable: true
});
return transformed;
}
});
}
return result;
};
//#endregion
exports.deepTransformNode = deepTransformNode;
//# sourceMappingURL=deepTransform.cjs.map