@fluffjs/cli 0.0.8 → 0.1.1

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.
Files changed (142) hide show
  1. package/BabelHelpers.d.ts +26 -0
  2. package/BabelHelpers.js +65 -0
  3. package/Cli.d.ts +7 -10
  4. package/Cli.js +139 -52
  5. package/CodeGenerator.d.ts +53 -39
  6. package/CodeGenerator.js +330 -725
  7. package/ComponentCompiler.d.ts +14 -16
  8. package/ComponentCompiler.js +193 -257
  9. package/DomPreProcessor.d.ts +36 -0
  10. package/DomPreProcessor.js +645 -0
  11. package/ErrorHelpers.d.ts +5 -0
  12. package/ErrorHelpers.js +8 -0
  13. package/ExpressionTransformer.d.ts +38 -28
  14. package/ExpressionTransformer.js +558 -230
  15. package/Generator.d.ts +1 -5
  16. package/Generator.js +128 -67
  17. package/GetterDependencyExtractor.d.ts +4 -0
  18. package/GetterDependencyExtractor.js +73 -0
  19. package/IndexHtmlTransformer.d.ts +6 -7
  20. package/IndexHtmlTransformer.js +82 -88
  21. package/Parse5Helpers.d.ts +17 -0
  22. package/Parse5Helpers.js +95 -0
  23. package/TemplateParser.d.ts +39 -21
  24. package/TemplateParser.js +462 -268
  25. package/Typeguards.d.ts +24 -0
  26. package/Typeguards.js +30 -0
  27. package/babel-plugin-class-transform.d.ts +3 -18
  28. package/babel-plugin-class-transform.js +3 -11
  29. package/babel-plugin-component.d.ts +4 -13
  30. package/babel-plugin-component.js +7 -0
  31. package/babel-plugin-imports.d.ts +3 -11
  32. package/babel-plugin-imports.js +5 -31
  33. package/babel-plugin-reactive.d.ts +2 -19
  34. package/babel-plugin-reactive.js +21 -76
  35. package/bin.js +2 -2
  36. package/fluff-esbuild-plugin.d.ts +2 -5
  37. package/fluff-esbuild-plugin.js +4 -1
  38. package/index.d.ts +6 -2
  39. package/index.js +1 -1
  40. package/interfaces/BabelPluginClassTransformState.d.ts +5 -0
  41. package/interfaces/BabelPluginComponentState.d.ts +4 -0
  42. package/interfaces/BabelPluginComponentState.js +1 -0
  43. package/interfaces/BabelPluginImportsState.d.ts +5 -0
  44. package/interfaces/BabelPluginImportsState.js +1 -0
  45. package/interfaces/BabelPluginReactiveState.d.ts +13 -0
  46. package/interfaces/BabelPluginReactiveState.js +1 -0
  47. package/interfaces/BabelPluginReactiveWatchCallInfo.d.ts +7 -0
  48. package/interfaces/BabelPluginReactiveWatchCallInfo.js +1 -0
  49. package/interfaces/BabelPluginReactiveWatchInfo.d.ts +5 -0
  50. package/interfaces/BabelPluginReactiveWatchInfo.js +1 -0
  51. package/interfaces/BabelToken.d.ts +8 -0
  52. package/interfaces/BabelToken.js +1 -0
  53. package/interfaces/BindingInfo.d.ts +12 -0
  54. package/interfaces/BindingInfo.js +1 -0
  55. package/interfaces/BreakMarkerConfig.d.ts +4 -0
  56. package/interfaces/BreakMarkerConfig.js +1 -0
  57. package/interfaces/BreakNode.d.ts +4 -0
  58. package/interfaces/BreakNode.js +1 -0
  59. package/interfaces/BundleOptions.d.ts +9 -0
  60. package/interfaces/BundleOptions.js +1 -0
  61. package/interfaces/ClassTransformOptions.d.ts +10 -0
  62. package/interfaces/ClassTransformOptions.js +1 -0
  63. package/interfaces/CliOptions.d.ts +8 -0
  64. package/interfaces/CliOptions.js +1 -0
  65. package/interfaces/CommentNode.d.ts +5 -0
  66. package/interfaces/CommentNode.js +1 -0
  67. package/interfaces/CompileResult.d.ts +6 -0
  68. package/interfaces/CompileResult.js +1 -0
  69. package/interfaces/CompilerOptions.d.ts +6 -0
  70. package/interfaces/CompilerOptions.js +1 -0
  71. package/interfaces/ComponentInfo.d.ts +8 -0
  72. package/interfaces/ComponentInfo.js +1 -0
  73. package/interfaces/ComponentMetadata.d.ts +9 -0
  74. package/interfaces/ComponentMetadata.js +1 -0
  75. package/interfaces/ControlFlow.d.ts +19 -0
  76. package/interfaces/ControlFlow.js +1 -0
  77. package/interfaces/ControlFlowNode.d.ts +6 -0
  78. package/interfaces/ControlFlowNode.js +1 -0
  79. package/interfaces/ControlFlowParseResult.d.ts +10 -0
  80. package/interfaces/ControlFlowParseResult.js +1 -0
  81. package/interfaces/ElementNode.d.ts +11 -0
  82. package/interfaces/ElementNode.js +1 -0
  83. package/interfaces/FluffConfigInterface.d.ts +7 -0
  84. package/interfaces/FluffConfigInterface.js +1 -0
  85. package/interfaces/FluffPluginOptions.d.ts +9 -0
  86. package/interfaces/FluffPluginOptions.js +1 -0
  87. package/interfaces/FluffTarget.d.ts +15 -0
  88. package/interfaces/FluffTarget.js +1 -0
  89. package/interfaces/ForMarkerConfig.d.ts +9 -0
  90. package/interfaces/ForMarkerConfig.js +1 -0
  91. package/interfaces/ForNode.d.ts +13 -0
  92. package/interfaces/ForNode.js +1 -0
  93. package/interfaces/GeneratorOptions.d.ts +5 -0
  94. package/interfaces/GeneratorOptions.js +1 -0
  95. package/interfaces/HtmlTransformOptions.d.ts +10 -0
  96. package/interfaces/HtmlTransformOptions.js +1 -0
  97. package/interfaces/IfBranch.d.ts +8 -0
  98. package/interfaces/IfBranch.js +1 -0
  99. package/interfaces/IfMarkerConfig.d.ts +8 -0
  100. package/interfaces/IfMarkerConfig.js +1 -0
  101. package/interfaces/IfNode.d.ts +7 -0
  102. package/interfaces/IfNode.js +1 -0
  103. package/interfaces/ImportTransformOptions.d.ts +7 -0
  104. package/interfaces/ImportTransformOptions.js +1 -0
  105. package/interfaces/InterpolationNode.d.ts +12 -0
  106. package/interfaces/InterpolationNode.js +1 -0
  107. package/interfaces/ParsedTemplate.d.ts +6 -0
  108. package/interfaces/ParsedTemplate.js +1 -0
  109. package/interfaces/ParsedTemplateOld.d.ts +9 -0
  110. package/interfaces/ParsedTemplateOld.js +1 -0
  111. package/interfaces/PropertyChain.d.ts +2 -0
  112. package/interfaces/PropertyChain.js +1 -0
  113. package/interfaces/Scope.d.ts +5 -0
  114. package/interfaces/Scope.js +1 -0
  115. package/interfaces/ServeOptions.d.ts +5 -0
  116. package/interfaces/ServeOptions.js +1 -0
  117. package/interfaces/SwitchCase.d.ts +8 -0
  118. package/interfaces/SwitchCase.js +1 -0
  119. package/interfaces/SwitchMarkerConfig.d.ts +11 -0
  120. package/interfaces/SwitchMarkerConfig.js +1 -0
  121. package/interfaces/SwitchNode.d.ts +10 -0
  122. package/interfaces/SwitchNode.js +1 -0
  123. package/interfaces/TemplateBinding.d.ts +10 -0
  124. package/interfaces/TemplateBinding.js +1 -0
  125. package/interfaces/TemplateNode.d.ts +7 -0
  126. package/interfaces/TemplateNode.js +1 -0
  127. package/interfaces/TextMarkerConfig.d.ts +10 -0
  128. package/interfaces/TextMarkerConfig.js +1 -0
  129. package/interfaces/TextNode.d.ts +5 -0
  130. package/interfaces/TextNode.js +1 -0
  131. package/interfaces/TokenizeResult.d.ts +6 -0
  132. package/interfaces/TokenizeResult.js +1 -0
  133. package/interfaces/TransformOptions.d.ts +11 -0
  134. package/interfaces/TransformOptions.js +1 -0
  135. package/interfaces/index.d.ts +34 -0
  136. package/interfaces/index.js +1 -0
  137. package/package.json +9 -1
  138. package/types/FluffConfig.d.ts +5 -27
  139. package/ControlFlowParser.d.ts +0 -55
  140. package/ControlFlowParser.js +0 -279
  141. package/types.d.ts +0 -46
  142. /package/{types.js → interfaces/BabelPluginClassTransformState.js} +0 -0
@@ -0,0 +1,26 @@
1
+ import _generate from '@babel/generator';
2
+ import _traverse from '@babel/traverse';
3
+ import * as t from '@babel/types';
4
+ export declare const generate: typeof _generate.generate;
5
+ export declare const traverse: {
6
+ <S>(parent: _traverse.Node, opts: _traverse.TraverseOptions<S>, scope: _traverse.Scope | undefined, state: S, parentPath?: _traverse.NodePath): void;
7
+ (parent: _traverse.Node, opts?: _traverse.TraverseOptions, scope?: _traverse.Scope, state?: any, parentPath?: _traverse.NodePath): void;
8
+ visitors: typeof _traverse.visitors;
9
+ verify: typeof _traverse.visitors.verify;
10
+ explode: typeof _traverse.visitors.explode;
11
+ cheap: (node: _traverse.Node, enter: (node: _traverse.Node) => void) => void;
12
+ node: (node: _traverse.Node, opts: _traverse.TraverseOptions, scope?: _traverse.Scope, state?: any, path?: _traverse.NodePath, skipKeys?: Record<string, boolean>) => void;
13
+ clearNode: (node: _traverse.Node, opts?: _traverse.RemovePropertiesOptions) => void;
14
+ removeProperties: (tree: _traverse.Node, opts?: _traverse.RemovePropertiesOptions) => _traverse.Node;
15
+ hasType: (tree: _traverse.Node, type: _traverse.Node["type"], denylistTypes?: string[]) => boolean;
16
+ cache: typeof _traverse.cache;
17
+ };
18
+ export declare function findDecoratorIndex(decorators: t.Decorator[], name: string): number;
19
+ export declare function getDecoratorName(decorator: t.Decorator): string | null;
20
+ export interface DecoratedNode {
21
+ decorators?: t.Decorator[] | null;
22
+ }
23
+ export declare function filterDecoratorsFromNode(node: DecoratedNode, removeDecorators: string[]): void;
24
+ export declare function parseMethodBody(body: string): t.Statement[];
25
+ export declare function buildHostBindingUpdateStatement(hostProperty: string): t.Statement;
26
+ //# sourceMappingURL=BabelHelpers.d.ts.map
@@ -0,0 +1,65 @@
1
+ import _generate from '@babel/generator';
2
+ import { parse } from '@babel/parser';
3
+ import _traverse from '@babel/traverse';
4
+ import * as t from '@babel/types';
5
+ export const generate = _generate.default ?? _generate;
6
+ export const traverse = _traverse.default ?? _traverse;
7
+ export function findDecoratorIndex(decorators, name) {
8
+ return decorators.findIndex(dec => {
9
+ if (t.isCallExpression(dec.expression) && t.isIdentifier(dec.expression.callee)) {
10
+ return dec.expression.callee.name === name;
11
+ }
12
+ return false;
13
+ });
14
+ }
15
+ export function getDecoratorName(decorator) {
16
+ const expr = decorator.expression;
17
+ if (t.isCallExpression(expr) && t.isIdentifier(expr.callee)) {
18
+ return expr.callee.name;
19
+ }
20
+ if (t.isIdentifier(expr)) {
21
+ return expr.name;
22
+ }
23
+ return null;
24
+ }
25
+ export function filterDecoratorsFromNode(node, removeDecorators) {
26
+ const { decorators } = node;
27
+ if (!decorators)
28
+ return;
29
+ node.decorators = decorators.filter(dec => {
30
+ const name = getDecoratorName(dec);
31
+ return !name || !removeDecorators.includes(name);
32
+ });
33
+ }
34
+ export function parseMethodBody(body) {
35
+ const wrappedCode = `class __Temp__ { __temp__() { ${body} } }`;
36
+ const ast = parse(wrappedCode, { sourceType: 'module' });
37
+ const [classDecl] = ast.program.body;
38
+ if (t.isClassDeclaration(classDecl)) {
39
+ const [method] = classDecl.body.body;
40
+ if (t.isClassMethod(method)) {
41
+ return method.body.body;
42
+ }
43
+ }
44
+ return [];
45
+ }
46
+ export function buildHostBindingUpdateStatement(hostProperty) {
47
+ if (hostProperty.startsWith('class.')) {
48
+ const className = hostProperty.slice(6);
49
+ return t.ifStatement(t.identifier('__v'), t.expressionStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('classList')), t.identifier('add')), [t.stringLiteral(className)])), t.expressionStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('classList')), t.identifier('remove')), [t.stringLiteral(className)])));
50
+ }
51
+ else if (hostProperty.startsWith('attr.')) {
52
+ const attrName = hostProperty.slice(5);
53
+ return t.ifStatement(t.binaryExpression('!=', t.identifier('__v'), t.nullLiteral()), t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('setAttribute')), [
54
+ t.stringLiteral(attrName),
55
+ t.callExpression(t.identifier('String'), [t.identifier('__v')])
56
+ ])), t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('removeAttribute')), [t.stringLiteral(attrName)])));
57
+ }
58
+ else if (hostProperty.startsWith('style.')) {
59
+ const styleProp = hostProperty.slice(6);
60
+ return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('style')), t.identifier(styleProp)), t.logicalExpression('||', t.identifier('__v'), t.stringLiteral(''))));
61
+ }
62
+ else {
63
+ return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(hostProperty)), t.identifier('__v')));
64
+ }
65
+ }
package/Cli.d.ts CHANGED
@@ -1,12 +1,10 @@
1
- interface CliOptions {
2
- cwd?: string;
3
- nxPackage?: string;
4
- noGzip?: boolean;
5
- }
1
+ import type { CliOptions } from './interfaces/CliOptions.js';
6
2
  export declare class Cli {
7
3
  private readonly cwd;
8
4
  private readonly nxPackage;
9
5
  private readonly noGzip;
6
+ private readonly noMinify;
7
+ private readonly gzScriptTag;
10
8
  constructor(options?: CliOptions);
11
9
  run(args: string[]): Promise<void>;
12
10
  private showHelp;
@@ -28,10 +26,9 @@ export declare class Cli {
28
26
  private findFiles;
29
27
  private matchesPatterns;
30
28
  private matchGlob;
29
+ static parseArgs(argv: string[]): {
30
+ options: CliOptions;
31
+ args: string[];
32
+ };
31
33
  }
32
- export declare function parseArgs(argv: string[]): {
33
- options: CliOptions;
34
- args: string[];
35
- };
36
- export {};
37
34
  //# sourceMappingURL=Cli.d.ts.map
package/Cli.js CHANGED
@@ -1,20 +1,28 @@
1
+ import * as t from '@babel/types';
2
+ import { randomUUID } from 'crypto';
1
3
  import * as esbuild from 'esbuild';
2
4
  import * as fs from 'fs';
3
5
  import * as path from 'path';
6
+ import picomatch from 'picomatch';
4
7
  import { gzipSync } from 'zlib';
8
+ import { generate } from './BabelHelpers.js';
5
9
  import { ComponentCompiler } from './ComponentCompiler.js';
6
10
  import { fluffPlugin } from './fluff-esbuild-plugin.js';
7
- import { transformIndexHtml } from './IndexHtmlTransformer.js';
8
- import { DEFAULT_CONFIG } from './types/FluffConfig.js';
9
11
  import { Generator } from './Generator.js';
12
+ import { IndexHtmlTransformer } from './IndexHtmlTransformer.js';
13
+ import { DEFAULT_CONFIG } from './types/FluffConfig.js';
10
14
  export class Cli {
11
15
  cwd;
12
16
  nxPackage;
13
17
  noGzip;
18
+ noMinify;
19
+ gzScriptTag;
14
20
  constructor(options = {}) {
15
21
  this.cwd = options.cwd ?? process.env.INIT_CWD ?? process.cwd();
16
22
  this.nxPackage = options.nxPackage;
17
23
  this.noGzip = options.noGzip ?? false;
24
+ this.noMinify = options.noMinify ?? false;
25
+ this.gzScriptTag = options.gzScriptTag ?? false;
18
26
  }
19
27
  async run(args) {
20
28
  const [command, ...commandArgs] = args;
@@ -292,9 +300,33 @@ Examples:
292
300
  if (this.noGzip) {
293
301
  bundleOptions.gzip = false;
294
302
  }
303
+ if (this.noMinify) {
304
+ bundleOptions.minify = false;
305
+ }
295
306
  const entryPoint = target.entryPoint
296
307
  ? path.join(srcDir, target.entryPoint)
297
308
  : this.generateEntryPoint(srcDir, target.components);
309
+ let inlineStyles = '';
310
+ if (target.styles && target.styles.length > 0) {
311
+ const styleContents = [];
312
+ for (const styleGlob of target.styles) {
313
+ const styleFiles = this.findFiles(srcDir, [styleGlob]);
314
+ for (const styleFile of styleFiles) {
315
+ styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
316
+ }
317
+ }
318
+ if (styleContents.length > 0) {
319
+ inlineStyles = styleContents.join('\n');
320
+ if (bundleOptions.minify) {
321
+ const cssResult = await esbuild.transform(inlineStyles, {
322
+ loader: 'css',
323
+ minify: true
324
+ });
325
+ inlineStyles = cssResult.code;
326
+ }
327
+ console.log(' ✓ Bundled global styles');
328
+ }
329
+ }
298
330
  console.log(' Building with esbuild...');
299
331
  const result = await esbuild.build({
300
332
  entryPoints: [entryPoint],
@@ -307,7 +339,15 @@ Examples:
307
339
  splitting: bundleOptions.splitting ?? false,
308
340
  treeShaking: true,
309
341
  metafile: true,
310
- plugins: [fluffPlugin({ srcDir: appDir, minify: bundleOptions.minify ?? true })],
342
+ plugins: [
343
+ fluffPlugin({
344
+ srcDir: appDir,
345
+ outDir,
346
+ minify: bundleOptions.minify ?? true,
347
+ skipDefine: false,
348
+ production: true
349
+ })
350
+ ],
311
351
  external: bundleOptions.external ?? [],
312
352
  logLevel: 'warning',
313
353
  tsconfigRaw: '{}'
@@ -319,8 +359,8 @@ Examples:
319
359
  const jsBundleName = path.basename(jsBundle);
320
360
  const jsPath = path.join(outDir, jsBundleName);
321
361
  if (bundleOptions.gzip) {
322
- const jsContent = fs.readFileSync(jsPath);
323
- const gzipped = gzipSync(jsContent, { level: 9 });
362
+ const gzipContent = fs.readFileSync(jsPath);
363
+ const gzipped = gzipSync(gzipContent, { level: 9 });
324
364
  fs.writeFileSync(`${jsPath}.gz`, gzipped);
325
365
  fs.unlinkSync(jsPath);
326
366
  console.log(` ✓ Created ${jsBundleName}.gz (${gzipped.length} bytes)`);
@@ -347,10 +387,12 @@ Examples:
347
387
  const indexHtmlPath = path.join(srcDir, target.indexHtml);
348
388
  if (fs.existsSync(indexHtmlPath)) {
349
389
  const indexHtml = fs.readFileSync(indexHtmlPath, 'utf-8');
350
- const transformed = await transformIndexHtml(indexHtml, {
390
+ const transformed = await IndexHtmlTransformer.transform(indexHtml, {
351
391
  jsBundle: jsBundle ? path.basename(jsBundle) : 'main.js',
352
392
  cssBundle: cssBundle ? path.basename(cssBundle) : undefined,
393
+ inlineStyles: inlineStyles || undefined,
353
394
  gzip: bundleOptions.gzip,
395
+ gzScriptTag: bundleOptions.gzScriptTag ?? this.gzScriptTag,
354
396
  minify: bundleOptions.minify
355
397
  });
356
398
  fs.writeFileSync(path.join(outDir, 'index.html'), transformed);
@@ -436,26 +478,58 @@ Examples:
436
478
  async serveTarget(target, projectRoot, workspaceRoot, projectRelativePath) {
437
479
  const srcDir = path.resolve(projectRoot, target.srcDir);
438
480
  const appDir = path.join(srcDir, 'app');
439
- const outDir = (workspaceRoot && projectRelativePath)
440
- ? path.join(workspaceRoot, 'dist', projectRelativePath)
441
- : path.resolve(projectRoot, target.outDir);
481
+ const fluffDir = path.join(this.cwd, '.fluff');
482
+ const serveId = randomUUID();
483
+ const outDir = path.join(fluffDir, serveId);
442
484
  if (!fs.existsSync(outDir)) {
443
485
  fs.mkdirSync(outDir, { recursive: true });
444
486
  }
487
+ const cleanup = () => {
488
+ try {
489
+ if (fs.existsSync(outDir)) {
490
+ fs.rmSync(outDir, { recursive: true, force: true });
491
+ }
492
+ }
493
+ catch {
494
+ }
495
+ };
496
+ process.on('exit', cleanup);
497
+ process.on('SIGINT', () => {
498
+ cleanup();
499
+ process.exit(0);
500
+ });
501
+ process.on('SIGTERM', () => {
502
+ cleanup();
503
+ process.exit(0);
504
+ });
445
505
  const serveOptions = target.serve ?? {};
446
506
  const port = serveOptions.port ?? 3000;
447
507
  const host = serveOptions.host ?? 'localhost';
448
508
  const entryPoint = target.entryPoint
449
509
  ? path.join(srcDir, target.entryPoint)
450
510
  : this.generateEntryPoint(srcDir, target.components);
511
+ let inlineStyles = '';
512
+ if (target.styles && target.styles.length > 0) {
513
+ const styleContents = [];
514
+ for (const styleGlob of target.styles) {
515
+ const styleFiles = this.findFiles(srcDir, [styleGlob]);
516
+ for (const styleFile of styleFiles) {
517
+ styleContents.push(fs.readFileSync(styleFile, 'utf-8'));
518
+ }
519
+ }
520
+ if (styleContents.length > 0) {
521
+ inlineStyles = styleContents.join('\n');
522
+ }
523
+ }
451
524
  if (target.indexHtml) {
452
525
  const indexHtmlPath = path.join(srcDir, target.indexHtml);
453
526
  if (fs.existsSync(indexHtmlPath)) {
454
527
  const indexHtml = fs.readFileSync(indexHtmlPath, 'utf-8');
455
- const transformed = await transformIndexHtml(indexHtml, {
528
+ const transformed = await IndexHtmlTransformer.transform(indexHtml, {
456
529
  jsBundle: path.basename(entryPoint)
457
530
  .replace('.ts', '.js'),
458
531
  cssBundle: undefined,
532
+ inlineStyles: inlineStyles || undefined,
459
533
  gzip: false,
460
534
  minify: false,
461
535
  liveReload: true
@@ -496,7 +570,16 @@ Examples:
496
570
  minify: false,
497
571
  treeShaking: true,
498
572
  sourcemap: true,
499
- plugins: [fluffPlugin({ srcDir: appDir, minify: false, sourcemap: true })],
573
+ plugins: [
574
+ fluffPlugin({
575
+ srcDir: appDir,
576
+ outDir,
577
+ minify: false,
578
+ sourcemap: true,
579
+ skipDefine: false,
580
+ production: false
581
+ })
582
+ ],
500
583
  logLevel: 'info'
501
584
  });
502
585
  await ctx.watch();
@@ -511,12 +594,13 @@ Examples:
511
594
  }
512
595
  generateEntryPoint(srcDir, componentPatterns) {
513
596
  const componentFiles = this.findFiles(srcDir, componentPatterns);
514
- const imports = componentFiles.map(f => {
597
+ const importDecls = componentFiles.map(f => {
515
598
  const relativePath = './' + path.relative(srcDir, f)
516
599
  .replace(/\\/g, '/');
517
- return `import '${relativePath}';`;
600
+ return t.importDeclaration([], t.stringLiteral(relativePath));
518
601
  });
519
- const entryContent = imports.join('\n');
602
+ const program = t.program(importDecls);
603
+ const entryContent = generate(program, { compact: false }).code;
520
604
  const entryPath = path.join(srcDir, '__generated_entry.ts');
521
605
  fs.writeFileSync(entryPath, entryContent);
522
606
  return entryPath;
@@ -550,45 +634,48 @@ Examples:
550
634
  return false;
551
635
  }
552
636
  matchGlob(filePath, pattern) {
553
- const regexPattern = pattern
554
- .replace(/\./g, '\\.')
555
- .replace(/\*\*/g, '{{GLOBSTAR}}')
556
- .replace(/\*/g, '[^/]*')
557
- .replace(/\{\{GLOBSTAR}}\//g, '(.*\\/)?')
558
- .replace(/\{\{GLOBSTAR}}/g, '.*');
559
- const regex = new RegExp(`^${regexPattern}$`);
560
- return regex.test(filePath);
637
+ const normalizedPath = filePath.replace(/\\/g, '/');
638
+ const isMatch = picomatch(pattern, { dot: false });
639
+ return isMatch(normalizedPath);
561
640
  }
562
- }
563
- export function parseArgs(argv) {
564
- const options = {};
565
- const args = [];
566
- let i = 0;
567
- while (i < argv.length) {
568
- const arg = argv[i];
569
- if (arg === '--nx' && argv[i + 1]) {
570
- options.nxPackage = argv[i + 1];
571
- i += 2;
572
- }
573
- else if (arg === '--cwd' && argv[i + 1]) {
574
- options.cwd = argv[i + 1];
575
- i += 2;
576
- }
577
- else if (arg === '--no-gzip') {
578
- options.noGzip = true;
579
- i++;
580
- }
581
- else if (arg?.startsWith('--')) {
582
- console.error(`Unknown option: ${arg}`);
583
- process.exit(1);
584
- }
585
- else if (arg) {
586
- args.push(arg);
587
- i++;
588
- }
589
- else {
590
- i++;
641
+ static parseArgs(argv) {
642
+ const options = {};
643
+ const args = [];
644
+ let i = 0;
645
+ while (i < argv.length) {
646
+ const arg = argv[i];
647
+ if (arg === '--nx' && argv[i + 1]) {
648
+ options.nxPackage = argv[i + 1];
649
+ i += 2;
650
+ }
651
+ else if (arg === '--cwd' && argv[i + 1]) {
652
+ options.cwd = argv[i + 1];
653
+ i += 2;
654
+ }
655
+ else if (arg === '--no-gzip') {
656
+ options.noGzip = true;
657
+ i++;
658
+ }
659
+ else if (arg === '--no-minify') {
660
+ options.noMinify = true;
661
+ i++;
662
+ }
663
+ else if (arg === '--gz-script-tag') {
664
+ options.gzScriptTag = true;
665
+ i++;
666
+ }
667
+ else if (arg?.startsWith('--')) {
668
+ console.error(`Unknown option: ${arg}`);
669
+ process.exit(1);
670
+ }
671
+ else if (arg) {
672
+ args.push(arg);
673
+ i++;
674
+ }
675
+ else {
676
+ i++;
677
+ }
591
678
  }
679
+ return { options, args };
592
680
  }
593
- return { options, args };
594
681
  }
@@ -1,42 +1,56 @@
1
- import type { ControlFlow, TemplateBinding } from './types.js';
1
+ import type { BreakMarkerConfig } from './interfaces/BreakMarkerConfig.js';
2
+ import type { ForMarkerConfig } from './interfaces/ForMarkerConfig.js';
3
+ import type { IfMarkerConfig } from './interfaces/IfMarkerConfig.js';
4
+ import type { SwitchMarkerConfig } from './interfaces/SwitchMarkerConfig.js';
5
+ import type { TextMarkerConfig } from './interfaces/TextMarkerConfig.js';
6
+ import type { ParsedTemplate } from './TemplateParser.js';
7
+ export type { BreakMarkerConfig } from './interfaces/BreakMarkerConfig.js';
8
+ export type { ForMarkerConfig } from './interfaces/ForMarkerConfig.js';
9
+ export type { IfMarkerConfig } from './interfaces/IfMarkerConfig.js';
10
+ export type { SwitchMarkerConfig } from './interfaces/SwitchMarkerConfig.js';
11
+ export type { TextMarkerConfig } from './interfaces/TextMarkerConfig.js';
12
+ export type MarkerConfig = IfMarkerConfig | ForMarkerConfig | SwitchMarkerConfig | TextMarkerConfig | BreakMarkerConfig;
2
13
  export declare class CodeGenerator {
3
- private reactiveProperties;
4
- private templateRefs;
5
- setReactiveProperties(props: Set<string>): void;
6
- setTemplateRefs(refs: string[]): void;
7
- generateRenderMethod(html: string, styles?: string): string;
8
- generateBindingsSetup(bindings: TemplateBinding[], controlFlows: ControlFlow[]): string;
9
- private getPropertyRef;
10
- private extractBaseProp;
11
- private escapeForTemplateLiteral;
12
- private escapeForTemplateLiteralPreservingExpressions;
13
- private dotsToDashes;
14
- private removeIndexSuffix;
15
- private generateBindingCode;
16
- private generateTextBinding;
17
- private generatePropertyBinding;
18
- private generateEventBinding;
19
- private generateRefLookups;
20
- private generateClassBinding;
21
- private generateStyleBinding;
22
- private generateControlFlowCode;
23
- private processContentBindings;
24
- private walkAndTransformBindings;
25
- private isParse5Element;
26
- private processAndGenerateBindings;
27
- private transformInterpolationsInContent;
28
- private generateBindingSetupCode;
29
- private extractPropertyBindings;
30
- private generateUnifiedRender;
31
- private generateIfCode;
32
- private generateForCode;
33
- private generateForBindingSetup;
34
- private extractEventBindings;
35
- private walkAndExtractEventBindings;
36
- private generateSwitchCode;
37
- private kebabToCamel;
38
- private extractTextBindings;
39
- private walkAndExtractTextBindings;
40
- private walkAndExtractPropertyBindings;
14
+ private readonly componentSelectors;
15
+ private readonly componentSelector;
16
+ private static readonly globalExprIdsByExpr;
17
+ private static globalExprs;
18
+ private static readonly globalHandlerIdsByExpr;
19
+ private static globalHandlers;
20
+ private markerId;
21
+ private readonly markerConfigs;
22
+ private readonly usedExprIds;
23
+ private readonly usedHandlerIds;
24
+ private readonly bindingsMap;
25
+ private rootFragment;
26
+ private readonly collectedTemplates;
27
+ constructor(componentSelectors?: Set<string>, componentSelector?: string);
28
+ static resetGlobalState(): void;
29
+ generateRenderMethod(template: ParsedTemplate, styles?: string): string;
30
+ generateHtml(template: ParsedTemplate): string;
31
+ generateRenderMethodFromHtml(html: string, styles?: string, markerConfigJson?: string): string;
32
+ getMarkerConfigJson(): string;
33
+ generateBindingsSetup(): string;
34
+ getBindingsMap(): Record<string, Record<string, unknown>[]>;
35
+ generateExpressionAssignments(): string;
36
+ static generateGlobalExprTable(): string;
37
+ private static buildExpressionArrowFunction;
38
+ private static buildHandlerArrowFunction;
39
+ private static normalizeCompiledExpr;
40
+ private nextMarkerId;
41
+ private renderNodesToParent;
42
+ private renderNodeToParent;
43
+ private renderElementToParent;
44
+ private renderTextToParent;
45
+ private isComponentTag;
46
+ private serializeBinding;
47
+ private internExpression;
48
+ private internHandler;
49
+ private renderInterpolationToParent;
50
+ private renderCommentToParent;
51
+ private renderIfToParent;
52
+ private renderForToParent;
53
+ private renderSwitchToParent;
54
+ private renderBreakToParent;
41
55
  }
42
56
  //# sourceMappingURL=CodeGenerator.d.ts.map