@fluffjs/cli 0.1.11 → 0.1.13

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.
@@ -6,6 +6,7 @@ export declare class DomPreProcessor {
6
6
  process(html: string): Promise<string>;
7
7
  private handleStartTag;
8
8
  private transformAttribute;
9
+ private buildBindingObject;
9
10
  private convertInterpolationToExpression;
10
11
  private handleEndTag;
11
12
  private handleText;
@@ -103,54 +103,30 @@ export class DomPreProcessor {
103
103
  transformAttribute(name, value, subscribeMap) {
104
104
  if (name.startsWith('[(') && name.endsWith(')]')) {
105
105
  const propName = name.slice(2, -2);
106
- const bindingObj = {
107
- name: propName, binding: 'two-way', expression: value
108
- };
109
- const subscribeTo = subscribeMap.get(propName);
110
- if (subscribeTo)
111
- bindingObj.subscribe = subscribeTo;
112
- const json = JSON.stringify(bindingObj);
106
+ const bindingObj = this.buildBindingObject(propName, 'two-way', value, subscribeMap.get(propName));
113
107
  return {
114
- name: `x-fluff-attrib-${propName.toLowerCase()}`, value: json
108
+ name: `x-fluff-attrib-${propName.toLowerCase()}`, value: JSON.stringify(bindingObj)
115
109
  };
116
110
  }
117
111
  if (name.startsWith('[') && name.endsWith(']')) {
118
112
  const propName = name.slice(1, -1);
119
113
  if (propName.startsWith('class.')) {
120
114
  const className = propName.slice(6);
121
- const bindingObj = {
122
- name: className, binding: 'class', expression: value
123
- };
124
- const subscribeTo = subscribeMap.get(propName);
125
- if (subscribeTo)
126
- bindingObj.subscribe = subscribeTo;
127
- const json = JSON.stringify(bindingObj);
115
+ const bindingObj = this.buildBindingObject(className, 'class', value, subscribeMap.get(propName));
128
116
  return {
129
- name: `x-fluff-attrib-class-${className.toLowerCase()}`, value: json
117
+ name: `x-fluff-attrib-class-${className.toLowerCase()}`, value: JSON.stringify(bindingObj)
130
118
  };
131
119
  }
132
120
  if (propName.startsWith('style.')) {
133
121
  const styleName = propName.slice(6);
134
- const bindingObj = {
135
- name: styleName, binding: 'style', expression: value
136
- };
137
- const subscribeTo = subscribeMap.get(propName);
138
- if (subscribeTo)
139
- bindingObj.subscribe = subscribeTo;
140
- const json = JSON.stringify(bindingObj);
122
+ const bindingObj = this.buildBindingObject(styleName, 'style', value, subscribeMap.get(propName));
141
123
  return {
142
- name: `x-fluff-attrib-style-${styleName.toLowerCase()}`, value: json
124
+ name: `x-fluff-attrib-style-${styleName.toLowerCase()}`, value: JSON.stringify(bindingObj)
143
125
  };
144
126
  }
145
- const bindingObj = {
146
- name: propName, binding: 'property', expression: value
147
- };
148
- const subscribeTo = subscribeMap.get(propName);
149
- if (subscribeTo)
150
- bindingObj.subscribe = subscribeTo;
151
- const json = JSON.stringify(bindingObj);
127
+ const bindingObj = this.buildBindingObject(propName, 'property', value, subscribeMap.get(propName));
152
128
  return {
153
- name: `x-fluff-attrib-${propName.toLowerCase()}`, value: json
129
+ name: `x-fluff-attrib-${propName.toLowerCase()}`, value: JSON.stringify(bindingObj)
154
130
  };
155
131
  }
156
132
  if (name.startsWith('(') && name.endsWith(')')) {
@@ -182,6 +158,21 @@ export class DomPreProcessor {
182
158
  }
183
159
  return null;
184
160
  }
161
+ buildBindingObject(name, binding, value, subscribeTo) {
162
+ const parsed = ExpressionTransformer.parsePrimaryExpression(value);
163
+ const bindingObj = {
164
+ name,
165
+ binding,
166
+ expression: parsed.expression
167
+ };
168
+ if (parsed.pipes.length > 0) {
169
+ bindingObj.pipes = parsed.pipes;
170
+ }
171
+ if (subscribeTo) {
172
+ bindingObj.subscribe = subscribeTo;
173
+ }
174
+ return bindingObj;
175
+ }
185
176
  convertInterpolationToExpression(value) {
186
177
  const parts = [];
187
178
  let pos = 0;
@@ -190,7 +190,7 @@ export class ExpressionTransformer {
190
190
  const { loc } = e;
191
191
  return loc !== null && typeof loc === 'object' && 'index' in loc && typeof loc.index === 'number';
192
192
  }
193
- static tokenizeExpression(code, startPos = 0) {
193
+ static tokenizeExpression(code, delimiters, startPos = 0) {
194
194
  const substring = code.slice(startPos);
195
195
  let tokens = [];
196
196
  try {
@@ -237,7 +237,7 @@ export class ExpressionTransformer {
237
237
  tokenCount = i;
238
238
  break;
239
239
  }
240
- if (depth === 0 && (token.type.label === '|' || token.type.label === ';' || token.type.label === ':')) {
240
+ if (depth === 0 && delimiters.includes(token.type.label)) {
241
241
  stopIndex = token.start;
242
242
  stopReason = 'delimiter';
243
243
  tokenCount = i;
@@ -305,7 +305,7 @@ export class ExpressionTransformer {
305
305
  static parsePrimaryExpression(text, startPos) {
306
306
  const offset = startPos ?? 0;
307
307
  const pipes = [];
308
- const tokenResult = ExpressionTransformer.tokenizeExpression(text, offset);
308
+ const tokenResult = ExpressionTransformer.tokenizeExpression(text, ['|', ';'], offset);
309
309
  if (tokenResult.tokenCount === 0) {
310
310
  return {
311
311
  expression: text.slice(offset)
@@ -344,7 +344,7 @@ export class ExpressionTransformer {
344
344
  }
345
345
  const prefix = `_arg${args.length + 1}=`;
346
346
  const argText = prefix + text.slice(pos);
347
- const argTokenResult = ExpressionTransformer.tokenizeExpression(argText, 0);
347
+ const argTokenResult = ExpressionTransformer.tokenizeExpression(argText, ['|', ':', ';'], 0);
348
348
  const argEndPos = argTokenResult.index - prefix.length;
349
349
  if (argTokenResult.tokenCount > 0) {
350
350
  const argCandidate = text.slice(pos, pos + argEndPos)
@@ -37,6 +37,7 @@ export declare class TemplateParser {
37
37
  private parseBindingAttribute;
38
38
  private getAttr;
39
39
  private transformWithLocals;
40
+ private transformPipes;
40
41
  private pushScope;
41
42
  private popScope;
42
43
  private getCurrentLocalVariables;
package/TemplateParser.js CHANGED
@@ -294,21 +294,7 @@ export class TemplateParser {
294
294
  try {
295
295
  const parsed = JSON.parse(pipesAttr);
296
296
  if (Array.isArray(parsed)) {
297
- result.pipes = parsed.map(pipe => {
298
- if (!Typeguards.isRecord(pipe)) {
299
- return null;
300
- }
301
- if (typeof pipe.name !== 'string' || !Array.isArray(pipe.args)) {
302
- return null;
303
- }
304
- const args = pipe.args.filter((arg) => typeof arg === 'string')
305
- .map(arg => this.transformWithLocals(arg));
306
- return {
307
- name: pipe.name,
308
- args
309
- };
310
- })
311
- .filter((pipe) => pipe !== null);
297
+ result.pipes = this.transformPipes(parsed);
312
298
  }
313
299
  }
314
300
  catch {
@@ -377,6 +363,9 @@ export class TemplateParser {
377
363
  if (typeof parsed.subscribe === 'string') {
378
364
  result.subscribe = parsed.subscribe;
379
365
  }
366
+ if (Array.isArray(parsed.pipes)) {
367
+ result.pipes = this.transformPipes(parsed.pipes);
368
+ }
380
369
  return result;
381
370
  }
382
371
  catch {
@@ -397,6 +386,23 @@ export class TemplateParser {
397
386
  templateRefs: options?.templateRefs
398
387
  });
399
388
  }
389
+ transformPipes(pipes) {
390
+ return pipes.map(pipe => {
391
+ if (!Typeguards.isRecord(pipe)) {
392
+ return null;
393
+ }
394
+ if (typeof pipe.name !== 'string' || !Array.isArray(pipe.args)) {
395
+ return null;
396
+ }
397
+ const args = pipe.args.filter((arg) => typeof arg === 'string')
398
+ .map(arg => this.transformWithLocals(arg));
399
+ return {
400
+ name: pipe.name,
401
+ args
402
+ };
403
+ })
404
+ .filter((pipe) => pipe !== null);
405
+ }
400
406
  pushScope(variables) {
401
407
  const parent = this.scopeStack[this.scopeStack.length - 1];
402
408
  this.scopeStack.push({
@@ -8,5 +8,9 @@ export interface BindingInfo {
8
8
  targetProp?: string;
9
9
  deps?: PropertyChain[];
10
10
  subscribe?: string;
11
+ pipes?: {
12
+ name: string;
13
+ args: string[];
14
+ }[];
11
15
  }
12
16
  //# sourceMappingURL=BindingInfo.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluffjs/cli",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",