@fluffjs/cli 0.2.0 → 0.2.2

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.
@@ -71,6 +71,29 @@ export default function reactivePlugin() {
71
71
  const propertyHostBindingInits = [];
72
72
  const pipeMethods = [];
73
73
  const hostListeners = [];
74
+ const linkedPropertyMethods = [];
75
+ for (const memberPath of path.get('body')) {
76
+ if (!memberPath.isClassMethod())
77
+ continue;
78
+ const methodNode = memberPath.node;
79
+ const decorators = methodNode.decorators ?? [];
80
+ const linkedPropertyIndex = findDecoratorIndex(decorators, 'LinkedProperty');
81
+ if (linkedPropertyIndex >= 0) {
82
+ const linkedPropertyDecorator = decorators[linkedPropertyIndex];
83
+ if (t.isCallExpression(linkedPropertyDecorator.expression)) {
84
+ const args = linkedPropertyDecorator.expression.arguments;
85
+ if (args.length > 0 && t.isStringLiteral(args[0])) {
86
+ const propertyName = args[0].value;
87
+ if (t.isIdentifier(methodNode.key)) {
88
+ linkedPropertyMethods.push({
89
+ methodName: methodNode.key.name, propertyName
90
+ });
91
+ }
92
+ }
93
+ }
94
+ decorators.splice(linkedPropertyIndex, 1);
95
+ }
96
+ }
74
97
  for (const memberPath of path.get('body')) {
75
98
  if (memberPath.isClassMethod()) {
76
99
  const methodNode = memberPath.node;
@@ -123,6 +146,22 @@ export default function reactivePlugin() {
123
146
  }
124
147
  decorators.splice(watchDecoratorIndex, 1);
125
148
  }
149
+ const linkedPropertyIndex = findDecoratorIndex(decorators, 'LinkedProperty');
150
+ if (linkedPropertyIndex >= 0) {
151
+ const linkedPropertyDecorator = decorators[linkedPropertyIndex];
152
+ if (t.isCallExpression(linkedPropertyDecorator.expression)) {
153
+ const args = linkedPropertyDecorator.expression.arguments;
154
+ if (args.length > 0 && t.isStringLiteral(args[0])) {
155
+ const propertyName = args[0].value;
156
+ if (t.isIdentifier(methodNode.key)) {
157
+ linkedPropertyMethods.push({
158
+ methodName: methodNode.key.name, propertyName
159
+ });
160
+ }
161
+ }
162
+ }
163
+ decorators.splice(linkedPropertyIndex, 1);
164
+ }
126
165
  if (methodNode.kind === 'get') {
127
166
  const hostBindingIndex = findDecoratorIndex(decorators, 'HostBinding');
128
167
  if (hostBindingIndex >= 0) {
@@ -226,9 +265,14 @@ export default function reactivePlugin() {
226
265
  const getter = t.classMethod('get', t.identifier(propName), [], t.blockStatement([
227
266
  t.returnStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(privateName)), t.identifier('getValue')), []))
228
267
  ]));
229
- const setter = t.classMethod('set', t.identifier(propName), [t.identifier('__v')], t.blockStatement([
268
+ const linkedMethod = linkedPropertyMethods.find(lp => lp.propertyName === propName);
269
+ const setterStatements = [
230
270
  t.expressionStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(privateName)), t.identifier('setValue')), [t.identifier('__v')]))
231
- ]));
271
+ ];
272
+ if (linkedMethod) {
273
+ setterStatements.push(t.ifStatement(t.binaryExpression('instanceof', t.identifier('__v'), t.identifier('Property')), t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier(linkedMethod.methodName)), [t.identifier('__v')]))));
274
+ }
275
+ const setter = t.classMethod('set', t.identifier(propName), [t.identifier('__v')], t.blockStatement(setterStatements));
232
276
  propsToRemove.push(memberPath);
233
277
  newMembers.push(getter, setter);
234
278
  privateFields.push(privateField);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluffjs/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",