@fluixi/compiler 1.0.0-alpha.93 → 1.0.0-alpha.94

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 (90) hide show
  1. package/dist/analyze/intrinsics.cjs +13 -1
  2. package/dist/analyze/intrinsics.d.cts +14 -0
  3. package/dist/analyze/intrinsics.d.ts +14 -0
  4. package/dist/analyze/intrinsics.d.ts.map +1 -1
  5. package/dist/analyze/intrinsics.js +17 -0
  6. package/dist/analyze/intrinsics.mjs +13 -1
  7. package/dist/analyze/static-graph.cjs +1 -1
  8. package/dist/analyze/static-graph.mjs +1 -1
  9. package/dist/{babel-RJHJQVEM.mjs → babel-RJFQVFJW.mjs} +4 -4
  10. package/dist/{chunk-56QSOVVL.mjs → chunk-DP2QDWWH.mjs} +1 -1
  11. package/dist/{chunk-R7PPFBCL.mjs → chunk-E2RWTIYE.mjs} +21 -15
  12. package/dist/{chunk-OD53TMER.mjs → chunk-HCCBEJEZ.mjs} +13 -1
  13. package/dist/{chunk-TJIH7TLX.mjs → chunk-HIZU7WI2.mjs} +1 -1
  14. package/dist/{chunk-U7HCFLZ2.mjs → chunk-ZR2QHTEX.mjs} +356 -24
  15. package/dist/codegen/backends/imperative.cjs +1 -1
  16. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  17. package/dist/codegen/backends/imperative.js +2 -1
  18. package/dist/codegen/backends/imperative.mjs +1 -1
  19. package/dist/frontend/babel/build-ir-lit.cjs +352 -22
  20. package/dist/frontend/babel/build-ir-lit.mjs +352 -22
  21. package/dist/frontend/babel/build-ir.cjs +352 -22
  22. package/dist/frontend/babel/build-ir.mjs +352 -22
  23. package/dist/frontend/babel/index.cjs +353 -23
  24. package/dist/frontend/babel/index.mjs +353 -23
  25. package/dist/frontend/babel/lower-template.cjs +352 -22
  26. package/dist/frontend/babel/lower-template.mjs +352 -22
  27. package/dist/frontend/babel/plugin.cjs +352 -22
  28. package/dist/frontend/babel/plugin.mjs +352 -22
  29. package/dist/index.cjs +321 -22
  30. package/dist/index.mjs +333 -22
  31. package/dist/integrations.cjs +1174 -49
  32. package/dist/integrations.d.ts.map +1 -1
  33. package/dist/integrations.js +44 -2
  34. package/dist/integrations.mjs +205 -19
  35. package/dist/lower/compile-template.cjs +315 -21
  36. package/dist/lower/compile-template.d.cts +13 -0
  37. package/dist/lower/compile-template.d.ts +13 -0
  38. package/dist/lower/compile-template.d.ts.map +1 -1
  39. package/dist/lower/compile-template.js +3 -0
  40. package/dist/lower/compile-template.mjs +327 -21
  41. package/dist/lower/entities.cjs +288 -0
  42. package/dist/lower/entities.d.cts +1 -0
  43. package/dist/lower/entities.d.ts +2 -0
  44. package/dist/lower/entities.d.ts.map +1 -0
  45. package/dist/lower/entities.js +54 -0
  46. package/dist/lower/entities.mjs +267 -0
  47. package/dist/lower/jsx.cjs +104 -47
  48. package/dist/lower/jsx.d.cts +8 -0
  49. package/dist/lower/jsx.d.ts +8 -0
  50. package/dist/lower/jsx.d.ts.map +1 -1
  51. package/dist/lower/jsx.js +92 -2
  52. package/dist/lower/jsx.mjs +104 -47
  53. package/dist/lower/template.cjs +293 -20
  54. package/dist/lower/template.d.ts.map +1 -1
  55. package/dist/lower/template.js +35 -19
  56. package/dist/lower/template.mjs +293 -20
  57. package/dist/resolve/builtins.cjs +1 -1
  58. package/dist/resolve/builtins.mjs +1 -1
  59. package/dist/resolve/component-globals.cjs +6 -1
  60. package/dist/resolve/component-globals.js +2 -2
  61. package/dist/resolve/component-globals.mjs +6 -1
  62. package/dist/resolve/write-globals.cjs +6 -1
  63. package/dist/resolve/write-globals.mjs +6 -1
  64. package/dist/{server-fns-ZFRDIQ2X.mjs → server-fns-JLSTKWPS.mjs} +4 -4
  65. package/dist/{server-functions-CTDXX67X.mjs → server-functions-BGY3RD4R.mjs} +3 -3
  66. package/dist/transform/index.cjs +956 -33
  67. package/dist/transform/index.mjs +974 -47
  68. package/dist/transform/props.mjs +19 -14
  69. package/dist/transform/server-fns.mjs +19 -14
  70. package/dist/transform/styles.cjs +588 -0
  71. package/dist/transform/styles.d.cts +211 -0
  72. package/dist/transform/styles.d.ts +212 -0
  73. package/dist/transform/styles.d.ts.map +1 -0
  74. package/dist/transform/styles.js +714 -0
  75. package/dist/transform/styles.mjs +653 -0
  76. package/dist/transform/templates.cjs +955 -32
  77. package/dist/transform/templates.d.cts +13 -0
  78. package/dist/transform/templates.d.ts +13 -0
  79. package/dist/transform/templates.d.ts.map +1 -1
  80. package/dist/transform/templates.js +49 -12
  81. package/dist/transform/templates.mjs +973 -46
  82. package/dist/{transform-QWWQDCXE.mjs → transform-GBP6Y4UI.mjs} +601 -17
  83. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  84. package/dist/vite-styles.cjs +180 -0
  85. package/dist/vite-styles.d.cts +59 -0
  86. package/dist/vite-styles.d.ts +60 -0
  87. package/dist/vite-styles.d.ts.map +1 -0
  88. package/dist/vite-styles.js +198 -0
  89. package/dist/vite-styles.mjs +159 -0
  90. package/package.json +4 -3
@@ -3,6 +3,7 @@ import { type CompileTemplateOptions } from '../lower/compile-template.cjs';
3
3
  import type { IRLoadStrategy } from '../ir/nodes.cjs';
4
4
  import { type PropsDiagnostic } from './props.cjs';
5
5
  import { type IntrinsicDiagnostic } from './intrinsics.cjs';
6
+ import { type CompiledStyle, type StyleDiagnostic, type StyleLiteral, type StyleOptions, type StyleReference } from './styles.cjs';
6
7
  export interface TransformOptions extends CompileTemplateOptions {
7
8
  /**
8
9
  * Which authoring syntaxes to compile. Both lower to the same IR, so this is
@@ -42,6 +43,11 @@ export interface TransformOptions extends CompileTemplateOptions {
42
43
  * @default true
43
44
  */
44
45
  intrinsics?: boolean;
46
+ /**
47
+ * Compile `<style>` / `<style scoped>` blocks with this CSS processor (the project's
48
+ * @fluixi-css context). Without it, `<style>` is an ordinary element.
49
+ */
50
+ styles?: StyleOptions;
45
51
  }
46
52
  export interface UnresolvedDiagnostic {
47
53
  /** The tag nothing supplies. */
@@ -65,5 +71,12 @@ export interface TransformResult {
65
71
  loadDiagnostics?: LoadDiagnostic[];
66
72
  /** Capitalised tags nothing supplies: they compile to an undefined reference. */
67
73
  unresolvedDiagnostics?: UnresolvedDiagnostic[];
74
+ /** `<style>` blocks taken out of the templates, processed and scoped, for the host to emit. */
75
+ styles?: CompiledStyle[];
76
+ styleDiagnostics?: StyleDiagnostic[];
77
+ /** `css`` values of the module, processed and unscoped, by handle id: emitted where used. */
78
+ styleLiterals?: StyleLiteral[];
79
+ /** Style values interpolated from other modules, for the build to resolve. */
80
+ styleReferences?: StyleReference[];
68
81
  }
69
82
  export declare function transformTemplates(code: string, id: string, options?: TransformOptions): TransformResult | null;
@@ -3,6 +3,7 @@ import { type CompileTemplateOptions } from '../lower/compile-template.js';
3
3
  import type { IRLoadStrategy } from '../ir/nodes.js';
4
4
  import { type PropsDiagnostic } from './props.js';
5
5
  import { type IntrinsicDiagnostic } from './intrinsics.js';
6
+ import { type CompiledStyle, type StyleDiagnostic, type StyleLiteral, type StyleOptions, type StyleReference } from './styles.js';
6
7
  export interface TransformOptions extends CompileTemplateOptions {
7
8
  /**
8
9
  * Which authoring syntaxes to compile. Both lower to the same IR, so this is
@@ -42,6 +43,11 @@ export interface TransformOptions extends CompileTemplateOptions {
42
43
  * @default true
43
44
  */
44
45
  intrinsics?: boolean;
46
+ /**
47
+ * Compile `<style>` / `<style scoped>` blocks with this CSS processor (the project's
48
+ * @fluixi-css context). Without it, `<style>` is an ordinary element.
49
+ */
50
+ styles?: StyleOptions;
45
51
  }
46
52
  export interface UnresolvedDiagnostic {
47
53
  /** The tag nothing supplies. */
@@ -65,6 +71,13 @@ export interface TransformResult {
65
71
  loadDiagnostics?: LoadDiagnostic[];
66
72
  /** Capitalised tags nothing supplies: they compile to an undefined reference. */
67
73
  unresolvedDiagnostics?: UnresolvedDiagnostic[];
74
+ /** `<style>` blocks taken out of the templates, processed and scoped, for the host to emit. */
75
+ styles?: CompiledStyle[];
76
+ styleDiagnostics?: StyleDiagnostic[];
77
+ /** `css`` values of the module, processed and unscoped, by handle id: emitted where used. */
78
+ styleLiterals?: StyleLiteral[];
79
+ /** Style values interpolated from other modules, for the build to resolve. */
80
+ styleReferences?: StyleReference[];
68
81
  }
69
82
  export declare function transformTemplates(code: string, id: string, options?: TransformOptions): TransformResult | null;
70
83
  //# sourceMappingURL=templates.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/transform/templates.ts"],"names":[],"mappings":"AASA,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAG1F,OAAO,KAAK,EAAqB,cAAc,EAAU,MAAM,gBAAgB,CAAC;AAWhF,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAgE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAoBzH,MAAM,WAAW,gBAAiB,SAAQ,sBAAsB;IAC9D;;;;OAIG;IACH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAChC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,IAAI,EAAE,MAAM,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Z,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,gBAAqB,GAC7B,eAAe,GAAG,IAAI,CAuPxB"}
@@ -22,7 +22,8 @@ import { moduleBindings } from './bindings.js';
22
22
  import { collectPropsEdits } from './props.js';
23
23
  import { avoidBindingClashes, collectIntrinsicEdits, intrinsicImports } from './intrinsics.js';
24
24
  import { collectSourceEdits, mayHaveSourceMarks } from './source-locations.js';
25
- import { mayHaveIntrinsic } from '../analyze/intrinsics.js';
25
+ import { collectStyles, finishShadowStyles } from './styles.js';
26
+ import { mayHaveIntrinsic, tagIntrinsics } from '../analyze/intrinsics.js';
26
27
  import { declaredNames } from '../analyze/reactive-bindings.js';
27
28
  import { DOM_CONTROL_FLOW, CORE_CONTROL_FLOW, ROUTER_COMPONENTS } from '../resolve/builtins.js';
28
29
  // Which builtin comes from which module is published by resolve/builtins.ts ,
@@ -67,10 +68,8 @@ function isJsxRoot(node, parent, key) {
67
68
  return false;
68
69
  return !(parent && isJsx(parent) && key === 'children');
69
70
  }
70
- function isTemplateTag(node, litTag) {
71
- return (node.type === 'TaggedTemplateExpression' &&
72
- node.tag?.type === 'Identifier' &&
73
- (node.tag.name === litTag || node.tag.name === 'svg'));
71
+ function isTemplateTag(node, tags) {
72
+ return node.type === 'TaggedTemplateExpression' && node.tag?.type === 'Identifier' && tags.has(node.tag.name);
74
73
  }
75
74
  /** The edits in `list` that no other edit in `list` contains. */
76
75
  function outermost(list) {
@@ -307,16 +306,25 @@ export function transformTemplates(code, id, options = {}) {
307
306
  // What a mark calls this file. The declaration marks and the usage marks are read back by
308
307
  // name, so both passes have to spell it the same way.
309
308
  const sourceName = relativeToRoot(id, options.sourceRoot);
310
- if (!mayHaveTemplate && !(wantsJsx && code.includes('<')) && !wantsIntrinsics && !wantsSources)
309
+ // A module of nothing but css`` values still has literals to compile.
310
+ const wantsStyles = options.styles !== undefined && (code.includes('<style') || code.includes('css`'));
311
+ if (!mayHaveTemplate && !(wantsJsx && code.includes('<')) && !wantsIntrinsics && !wantsSources && !wantsStyles)
311
312
  return null;
312
313
  const ast = parse(code, {
313
314
  sourceType: 'module',
314
315
  plugins: ['jsx', 'typescript'],
315
316
  errorRecovery: true,
316
317
  });
318
+ // `html`, `svg`, and in an app `$html`/`$svg`/`$css`, which need no import.
319
+ const intrinsicTags = options.intrinsics === false ? new Map() : tagIntrinsics(moduleBindings(ast.program));
320
+ const templateTags = new Map([[litTag, 'html'], ['svg', 'svg']]);
321
+ for (const [name, tag] of intrinsicTags)
322
+ if (tag !== 'css')
323
+ templateTags.set(name, tag);
324
+ const cssTags = [...intrinsicTags].filter(([, tag]) => tag === 'css').map(([name]) => name);
317
325
  const found = [];
318
326
  walk(ast.program, (n, parent, key) => {
319
- if (wantsLit && isTemplateTag(n, litTag))
327
+ if (wantsLit && isTemplateTag(n, templateTags))
320
328
  found.push(n);
321
329
  else if (wantsJsx && isJsxRoot(n, parent, key))
322
330
  found.push(n);
@@ -340,6 +348,9 @@ export function transformTemplates(code, id, options = {}) {
340
348
  const sources = options.sourceLocations === true
341
349
  ? collectSourceEdits(ast.program, sourceName)
342
350
  : { edits: [], marked: 0 };
351
+ // `<style>` blocks, processed by the host's CSS engine and scoped. Only when the host asked:
352
+ // without a processor a `<style>` stays an ordinary element.
353
+ const styles = wantsStyles ? collectStyles(ast.program, sourceName, options.styles, { html: templateTags, css: cssTags }, { id, code }) : undefined;
343
354
  // Nothing to emit still returns a result when there's something to say, a shadowed
344
355
  // intrinsic is a diagnostic even though the code comes back untouched.
345
356
  const silent = found.length === 0 &&
@@ -347,7 +358,9 @@ export function transformTemplates(code, id, options = {}) {
347
358
  sources.edits.length === 0 &&
348
359
  intrinsics.edits.length === 0 &&
349
360
  intrinsics.diagnostics.length === 0 &&
350
- props.diagnostics.length === 0;
361
+ props.diagnostics.length === 0 &&
362
+ !styles?.edits.length &&
363
+ !styles?.diagnostics.length;
351
364
  if (silent)
352
365
  return null;
353
366
  // Innermost first, so a nested template is already compiled by the time the
@@ -362,19 +375,33 @@ export function transformTemplates(code, id, options = {}) {
362
375
  declared: declaredNames(ast.program),
363
376
  };
364
377
  const hoisted = new Map();
365
- const edits = [...props.edits, ...intrinsics.edits, ...sources.edits];
378
+ const edits = [...props.edits, ...intrinsics.edits, ...sources.edits, ...(styles?.edits ?? [])];
366
379
  for (const node of found) {
367
380
  // A root inside another root's hole is emitted without partial templates,
368
381
  // matching what the plugin does for nested emits. Marker layout has to agree
369
382
  // between server and client, so this is not the place to change it.
370
383
  const nested = found.some((o) => o !== node && o.start <= node.start && o.end >= node.end && o.end - o.start > node.end - node.start);
371
384
  if (isJsx(node)) {
372
- edits.push({ start: node.start, end: node.end, code: compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceName) });
385
+ edits.push({ start: node.start, end: node.end, code: compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceName, styles) });
373
386
  continue;
374
387
  }
375
388
  const holes = node.quasi.expressions.map((e) => bindHole(code, e, edits, options.sourceLocations === true));
389
+ const scope = styles?.scopes.find((s) => node.start >= s.start && node.end <= s.end)?.value;
390
+ const owner = styles?.templateOwners.get(node.start);
391
+ const templateStyles = options.styles && styles && (scope || owner)
392
+ ? {
393
+ options: options.styles,
394
+ ...(scope ? { scope } : {}),
395
+ ...(owner ? { owner } : {}),
396
+ line: node.loc?.start.line ?? 0,
397
+ column: node.loc?.start.column ?? 0,
398
+ styles: styles.styles,
399
+ diagnostics: styles.diagnostics,
400
+ }
401
+ : undefined;
376
402
  const result = compilePieces(toPieces(node), holes, {
377
403
  ...options,
404
+ ...(templateStyles ? { templateStyles } : {}),
378
405
  hoistTemplates: true,
379
406
  // A tag inside a template gets the same mark a JSX tag does. Without one, the nodes it
380
407
  // makes are the only ones in the module carrying no mark, and they take whichever was
@@ -385,13 +412,17 @@ export function transformTemplates(code, id, options = {}) {
385
412
  // Same defaults as the plugin, so moving a build over is not a rendering change.
386
413
  templateClone: options.templateClone ?? true,
387
414
  partialTemplates: nested ? false : options.partialTemplates ?? true,
388
- svg: node.tag.name === 'svg',
415
+ svg: templateTags.get(node.tag.name) === 'svg',
389
416
  });
390
417
  for (const symbol of result.imports)
391
418
  used.add(symbol);
392
419
  collectNeeds(result.ir, needs);
393
420
  edits.push({ start: node.start, end: node.end, code: adoptTemplates(result.code, result.templates, hoisted) });
394
421
  }
422
+ // A shadow-DOM element's blocks and css`` values go into its `static styles`, once every
423
+ // template has been compiled and its blocks numbered.
424
+ if (styles && options.styles)
425
+ edits.push(...finishShadowStyles(styles, code, id));
395
426
  const out = new MagicString(code);
396
427
  // Same reason as in `slice`: a nested edit is already inside its parent's code.
397
428
  for (const e of outermost(edits)) {
@@ -476,6 +507,10 @@ export function transformTemplates(code, id, options = {}) {
476
507
  ...(unresolvedDiagnostics.length ? { unresolvedDiagnostics } : {}),
477
508
  ...(props.diagnostics.length ? { propsDiagnostics: props.diagnostics } : {}),
478
509
  ...(intrinsics.diagnostics.length ? { intrinsicDiagnostics: intrinsics.diagnostics } : {}),
510
+ ...(styles?.styles.length ? { styles: styles.styles } : {}),
511
+ ...(styles?.diagnostics.length ? { styleDiagnostics: styles.diagnostics } : {}),
512
+ ...(styles?.literals.length ? { styleLiterals: styles.literals } : {}),
513
+ ...(styles?.references.length ? { styleReferences: styles.references } : {}),
479
514
  };
480
515
  }
481
516
  /**
@@ -483,10 +518,12 @@ export function transformTemplates(code, id, options = {}) {
483
518
  * with anything already compiled inside them folded in, so nested JSX and nested
484
519
  * `` html`` `` both come along for free.
485
520
  */
486
- function compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceFile) {
521
+ function compileJsx(code, node, edits, nested, used, needs, hoisted, options, sourceFile, styles) {
487
522
  const ir = buildJsxIR(node, {
488
523
  code: (n) => slice(code, n.start, n.end, edits),
489
524
  used,
525
+ ...(styles?.scopes.length ? { scopes: styles.scopes } : {}),
526
+ ...(styles?.drop.size ? { dropStyles: styles.drop } : {}),
490
527
  ...(options.sourceLocations === true && sourceFile ? { sourceFile } : {}),
491
528
  });
492
529
  analyzeStatic(ir);