@motifx/compiler 1.2.0-rc.2 → 1.2.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -2927,16 +2927,63 @@ function injectDeclaredElementTag(path) {
2927
2927
  }
2928
2928
  catch { /* enjeksiyon başarısızsa derleme bozulmasın */ }
2929
2929
  }
2930
- const elementTagPlugin = () => ({
2931
- name: 'motifjs-element-tag',
2932
- visitor: {
2933
- Class: {
2934
- enter(path) {
2935
- injectDeclaredElementTag(path);
2930
+ const isThisChilds = (e) => !!e && t.isMemberExpression(e) && !e.computed && t.isThisExpression(e.object)
2931
+ && t.isIdentifier(e.property) && e.property.name === 'childs';
2932
+ function placesChilds(path) {
2933
+ let found = false;
2934
+ path.traverse({
2935
+ Class(inner) { inner.skip(); },
2936
+ FunctionDeclaration(inner) { inner.skip(); },
2937
+ FunctionExpression(inner) { inner.skip(); },
2938
+ JSXExpressionContainer(slot) {
2939
+ if (!t.isJSXElement(slot.parent) && !t.isJSXFragment(slot.parent))
2940
+ return;
2941
+ const e = slot.node.expression;
2942
+ const value = t.isArrowFunctionExpression(e) && !t.isBlockStatement(e.body) ? e.body : e;
2943
+ if (isThisChilds(value)) {
2944
+ found = true;
2945
+ slot.stop();
2936
2946
  }
2937
2947
  }
2948
+ });
2949
+ return found;
2950
+ }
2951
+ function injectChildsSlotMarker(path) {
2952
+ try {
2953
+ const node = path.node;
2954
+ if (!node.superClass || hasStaticMember(node, '_placesChilds'))
2955
+ return;
2956
+ if (!placesChilds(path))
2957
+ return;
2958
+ node.body.body.unshift(t.classProperty(t.identifier('_placesChilds'), t.booleanLiteral(true), null, null, false, true));
2938
2959
  }
2939
- });
2960
+ catch { }
2961
+ }
2962
+ const isTypeOnlyField = (member) => t.isClassProperty(member) && (!!member.declare || !!member.abstract);
2963
+ function stripTypeOnlyFields(path) {
2964
+ const body = path.node.body.body;
2965
+ if (!body.some(isTypeOnlyField))
2966
+ return;
2967
+ path.node.body.body = body.filter(member => !isTypeOnlyField(member));
2968
+ }
2969
+ const elementTagPlugin = () => {
2970
+ const visited = new WeakSet();
2971
+ return {
2972
+ name: 'motifjs-element-tag',
2973
+ visitor: {
2974
+ Class: {
2975
+ enter(path) {
2976
+ if (visited.has(path.node))
2977
+ return;
2978
+ visited.add(path.node);
2979
+ stripTypeOnlyFields(path);
2980
+ injectDeclaredElementTag(path);
2981
+ injectChildsSlotMarker(path);
2982
+ }
2983
+ }
2984
+ }
2985
+ };
2986
+ };
2940
2987
  class Compiler {
2941
2988
  motifCompile(code, filename) {
2942
2989
  return this.start(code, filename);
@@ -3107,6 +3154,22 @@ class Compiler {
3107
3154
  path.node.body = [...setOriginal, cls];
3108
3155
  }
3109
3156
  state.set('filename', filename);
3157
+ path.traverse({
3158
+ CallExpression(call) {
3159
+ const node = call.node;
3160
+ if (!t.isIdentifier(node.callee, { name: motifComponent() }) || node.arguments.length !== 2)
3161
+ return;
3162
+ const [tag, props] = node.arguments;
3163
+ if (!t.isStringLiteral(tag) || !t.isObjectExpression(props) || props.properties.length !== 1)
3164
+ return;
3165
+ const only = props.properties[0];
3166
+ if (!t.isObjectProperty(only) || only.computed || !t.isIdentifier(only.key, { name: 'initializeComponent' }))
3167
+ return;
3168
+ if (!t.isArrowFunctionExpression(only.value) && !t.isFunctionExpression(only.value))
3169
+ return;
3170
+ node.arguments.push(t.numericLiteral(1));
3171
+ }
3172
+ });
3110
3173
  absorbGeneratedCoreImports(topLevel, coreImports);
3111
3174
  if (coreImports.size > 0) {
3112
3175
  const contractCall = t.callExpression(t.identifier(motifCompiled()), [t.numericLiteral(COMPILER_CONTRACT)]);