@fluffjs/cli 0.4.2 → 0.4.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.
@@ -57,6 +57,7 @@ export declare class CodeGenerator {
57
57
  private readonly bindingsMap;
58
58
  private rootFragment;
59
59
  private readonly collectedTemplates;
60
+ private readonly namespaceStack;
60
61
  constructor(componentSelectors?: Set<string>, componentSelector?: string);
61
62
  static resetGlobalState(): void;
62
63
  static internString(str: string): number;
@@ -80,6 +81,8 @@ export declare class CodeGenerator {
80
81
  private renderNodesToParent;
81
82
  private renderNodeToParent;
82
83
  private renderElementToParent;
84
+ private getCurrentNamespace;
85
+ private renderToTemplateWithNamespace;
83
86
  private renderTextToParent;
84
87
  private isComponentTag;
85
88
  private serializeBinding;
package/CodeGenerator.js CHANGED
@@ -35,6 +35,7 @@ export class CodeGenerator {
35
35
  bindingsMap = new Map();
36
36
  rootFragment = null;
37
37
  collectedTemplates = [];
38
+ namespaceStack = [Parse5Helpers.NS_HTML];
38
39
  constructor(componentSelectors = new Set(), componentSelector = '') {
39
40
  this.componentSelectors = componentSelectors;
40
41
  this.componentSelector = componentSelector;
@@ -70,6 +71,8 @@ export class CodeGenerator {
70
71
  generateHtml(template) {
71
72
  this.rootFragment = parse5.parseFragment('');
72
73
  this.collectedTemplates.length = 0;
74
+ this.namespaceStack.length = 0;
75
+ this.namespaceStack.push(Parse5Helpers.NS_HTML);
73
76
  this.renderNodesToParent(template.root, this.rootFragment);
74
77
  for (const tpl of this.collectedTemplates) {
75
78
  tpl.parentNode = this.rootFragment;
@@ -314,9 +317,36 @@ export class CodeGenerator {
314
317
  if (tagName.startsWith(RESTRICTED_ELEMENT_PREFIX)) {
315
318
  tagName = tagName.slice(RESTRICTED_ELEMENT_PREFIX.length);
316
319
  }
317
- const el = Parse5Helpers.createElement(tagName, attrs);
320
+ const currentNamespace = this.namespaceStack[this.namespaceStack.length - 1];
321
+ const elementNamespace = node.namespaceURI ?? currentNamespace;
322
+ const el = Parse5Helpers.createElement(tagName, attrs, elementNamespace);
318
323
  Parse5Helpers.appendChild(parent, el);
324
+ if (elementNamespace !== currentNamespace) {
325
+ this.namespaceStack.push(elementNamespace);
326
+ }
319
327
  this.renderNodesToParent(node.children, el);
328
+ if (elementNamespace !== currentNamespace) {
329
+ this.namespaceStack.pop();
330
+ }
331
+ }
332
+ getCurrentNamespace() {
333
+ return this.namespaceStack[this.namespaceStack.length - 1];
334
+ }
335
+ renderToTemplateWithNamespace(nodes, attrName, attrValue) {
336
+ const tpl = Parse5Helpers.createElement('template', [{ name: attrName, value: attrValue }]);
337
+ const tplContent = Parse5Helpers.getTemplateContent(tpl);
338
+ const currentNs = this.getCurrentNamespace();
339
+ if (currentNs !== Parse5Helpers.NS_HTML) {
340
+ const wrapperTag = currentNs === Parse5Helpers.NS_SVG ? 'svg' : 'math';
341
+ const wrapper = Parse5Helpers.createElement(wrapperTag, [{ name: 'data-fluff-ns-wrapper', value: '' }], currentNs);
342
+ Parse5Helpers.appendChild(tplContent, wrapper);
343
+ this.renderNodesToParent(nodes, wrapper);
344
+ }
345
+ else {
346
+ this.renderNodesToParent(nodes, tplContent);
347
+ }
348
+ this.collectedTemplates.push(tpl);
349
+ return tpl;
320
350
  }
321
351
  renderTextToParent(node, parent) {
322
352
  Parse5Helpers.appendText(parent, node.content);
@@ -435,9 +465,7 @@ export class CodeGenerator {
435
465
  for (let i = 0; i < node.branches.length; i++) {
436
466
  const branch = node.branches[i];
437
467
  const templateId = `${this.componentSelector}-${id}-${i}`;
438
- const tpl = Parse5Helpers.createElement('template', [{ name: 'data-fluff-branch', value: templateId }]);
439
- this.renderNodesToParent(branch.children, Parse5Helpers.getTemplateContent(tpl));
440
- this.collectedTemplates.push(tpl);
468
+ this.renderToTemplateWithNamespace(branch.children, 'data-fluff-branch', templateId);
441
469
  }
442
470
  Parse5Helpers.appendComment(parent, `/fluff:if:${id}`);
443
471
  }
@@ -454,13 +482,9 @@ export class CodeGenerator {
454
482
  this.markerConfigs.set(id, config);
455
483
  Parse5Helpers.appendComment(parent, `fluff:for:${id}`);
456
484
  const templateId = `${this.componentSelector}-${id}`;
457
- const tpl = Parse5Helpers.createElement('template', [{ name: 'data-fluff-tpl', value: templateId }]);
458
- this.renderNodesToParent(node.children, Parse5Helpers.getTemplateContent(tpl));
459
- this.collectedTemplates.push(tpl);
485
+ this.renderToTemplateWithNamespace(node.children, 'data-fluff-tpl', templateId);
460
486
  if (node.emptyContent) {
461
- const emptyTpl = Parse5Helpers.createElement('template', [{ name: 'data-fluff-empty', value: templateId }]);
462
- this.renderNodesToParent(node.emptyContent, Parse5Helpers.getTemplateContent(emptyTpl));
463
- this.collectedTemplates.push(emptyTpl);
487
+ this.renderToTemplateWithNamespace(node.emptyContent, 'data-fluff-empty', templateId);
464
488
  }
465
489
  Parse5Helpers.appendComment(parent, `/fluff:for:${id}`);
466
490
  }
@@ -481,9 +505,7 @@ export class CodeGenerator {
481
505
  for (let i = 0; i < node.cases.length; i++) {
482
506
  const caseNode = node.cases[i];
483
507
  const templateId = `${this.componentSelector}-${id}-${i}`;
484
- const tpl = Parse5Helpers.createElement('template', [{ name: 'data-fluff-case', value: templateId }]);
485
- this.renderNodesToParent(caseNode.children, Parse5Helpers.getTemplateContent(tpl));
486
- this.collectedTemplates.push(tpl);
508
+ this.renderToTemplateWithNamespace(caseNode.children, 'data-fluff-case', templateId);
487
509
  }
488
510
  Parse5Helpers.appendComment(parent, `/fluff:switch:${id}`);
489
511
  }
package/Generator.js CHANGED
@@ -102,8 +102,8 @@ export class Generator {
102
102
  private: true,
103
103
  type: 'module',
104
104
  scripts: {
105
- build: 'npx @fluffjs/cli build',
106
- serve: 'npx @fluffjs/cli serve'
105
+ build: 'fluff build',
106
+ serve: 'fluff serve'
107
107
  },
108
108
  dependencies: {
109
109
  '@fluffjs/fluff': `^${cliVersion}`
@@ -1,10 +1,16 @@
1
+ import type * as parse5 from 'parse5';
2
+ import { type html } from 'parse5';
3
+ export type Parse5NS = html.NS;
1
4
  import type { Parse5ChildNode, Parse5Document, Parse5DocumentFragment, Parse5Element, Parse5Node, Parse5ParentNode } from './Typeguards.js';
2
5
  export type Parse5NodeVisitor = (node: Parse5Node) => boolean | undefined;
3
6
  export declare class Parse5Helpers {
7
+ static readonly NS_HTML = parse5.html.NS.HTML;
8
+ static readonly NS_SVG = parse5.html.NS.SVG;
9
+ static readonly NS_MATHML = parse5.html.NS.MATHML;
4
10
  static createElement(tagName: string, attrs: {
5
11
  name: string;
6
12
  value: string;
7
- }[]): Parse5Element;
13
+ }[], namespaceURI?: Parse5NS): Parse5Element;
8
14
  static appendChild(parent: Parse5ParentNode, child: Parse5ChildNode): void;
9
15
  static appendText(parent: Parse5ParentNode, value: string): void;
10
16
  static appendComment(parent: Parse5ParentNode, data: string): void;
package/Parse5Helpers.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import { html as parse5Html } from 'parse5';
2
2
  import { Typeguards } from './Typeguards.js';
3
3
  export class Parse5Helpers {
4
- static createElement(tagName, attrs) {
4
+ static NS_HTML = parse5Html.NS.HTML;
5
+ static NS_SVG = parse5Html.NS.SVG;
6
+ static NS_MATHML = parse5Html.NS.MATHML;
7
+ static createElement(tagName, attrs, namespaceURI) {
5
8
  const el = {
6
9
  nodeName: tagName,
7
10
  tagName,
8
11
  attrs,
9
12
  childNodes: [],
10
- namespaceURI: parse5Html.NS.HTML,
13
+ namespaceURI: namespaceURI ?? Parse5Helpers.NS_HTML,
11
14
  parentNode: null
12
15
  };
13
16
  if (tagName === 'template') {
@@ -0,0 +1,6 @@
1
+ export interface PeerDependency {
2
+ name: string;
3
+ version: string;
4
+ }
5
+ export declare function getCliPeerDependencies(): PeerDependency[];
6
+ //# sourceMappingURL=PeerDependencies.d.ts.map
@@ -0,0 +1,7 @@
1
+ export function getCliPeerDependencies() {
2
+ return [
3
+ { name: 'cssnano', version: '^7.1.2' },
4
+ { name: 'postcss', version: '^8.5.6' },
5
+ { name: 'jsesc', version: '^3.1.0' }
6
+ ];
7
+ }
package/TemplateParser.js CHANGED
@@ -327,7 +327,8 @@ export class TemplateParser {
327
327
  tagName: element.tagName,
328
328
  attributes,
329
329
  bindings,
330
- children
330
+ children,
331
+ namespaceURI: element.namespaceURI
331
332
  };
332
333
  if (hasBindings) {
333
334
  node.id = `l${this.bindingId++}`;
@@ -137,7 +137,7 @@ export function fluffPlugin(options) {
137
137
  plugins: ['typescript', 'decorators']
138
138
  });
139
139
  const exprTableImport = t.importDeclaration([], t.stringLiteral(VIRTUAL_EXPR_TABLE_ID));
140
- ast.program.body.push(exprTableImport);
140
+ ast.program.body.unshift(exprTableImport);
141
141
  const output = generate(ast, { compact: false });
142
142
  return {
143
143
  contents: output.code,
@@ -1,5 +1,6 @@
1
1
  import type { BindingInfo } from './BindingInfo.js';
2
2
  import type { TemplateNode } from './TemplateNode.js';
3
+ import type { Parse5NS } from '../Parse5Helpers.js';
3
4
  export interface ElementNode {
4
5
  type: 'element';
5
6
  tagName: string;
@@ -7,5 +8,6 @@ export interface ElementNode {
7
8
  bindings: BindingInfo[];
8
9
  children: TemplateNode[];
9
10
  id?: string;
11
+ namespaceURI?: Parse5NS;
10
12
  }
11
13
  //# sourceMappingURL=ElementNode.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluffjs/cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -29,23 +29,23 @@
29
29
  "@babel/preset-typescript": "^7.28.5",
30
30
  "@babel/traverse": "^7.28.6",
31
31
  "@babel/types": "^7.28.6",
32
+ "cssnano": "^7.1.2",
32
33
  "esbuild": "^0.27.2",
33
34
  "he": "^1.2.0",
34
35
  "html-minifier-terser": "^7.2.0",
35
36
  "http-proxy": "^1.18.1",
37
+ "jsesc": "^3.1.0",
36
38
  "parse5": "^8.0.0",
37
39
  "parse5-sax-parser": "^8.0.0",
38
40
  "picomatch": "^4.0.2",
41
+ "postcss": "^8.5.6",
39
42
  "source-map": "^0.7.6",
40
43
  "tslib": "^2.3.0"
41
44
  },
42
45
  "devDependencies": {
43
46
  "@types/he": "^1.2.3",
44
47
  "@types/http-proxy": "^1.17.16",
45
- "@types/jsesc": "^3.0.3",
46
- "cssnano": "^7.1.2",
47
- "jsesc": "^3.1.0",
48
- "postcss": "^8.5.6"
48
+ "@types/jsesc": "^3.0.3"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"