@fluixi/compiler 1.0.0-alpha.92 → 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.
- package/dist/analyze/intrinsics.cjs +31 -1
- package/dist/analyze/intrinsics.d.cts +14 -0
- package/dist/analyze/intrinsics.d.ts +14 -0
- package/dist/analyze/intrinsics.d.ts.map +1 -1
- package/dist/analyze/intrinsics.js +35 -0
- package/dist/analyze/intrinsics.mjs +31 -1
- package/dist/analyze/reactive-bindings.cjs +18 -0
- package/dist/analyze/reactive-bindings.mjs +18 -0
- package/dist/analyze/static-graph.cjs +22 -4
- package/dist/analyze/static-graph.d.ts.map +1 -1
- package/dist/analyze/static-graph.js +6 -4
- package/dist/analyze/static-graph.mjs +22 -4
- package/dist/{babel-GI375YZ2.mjs → babel-RJFQVFJW.mjs} +4 -4
- package/dist/{chunk-QZ4CJPYP.mjs → chunk-DP2QDWWH.mjs} +1 -1
- package/dist/{chunk-DWNWN5RH.mjs → chunk-E2RWTIYE.mjs} +21 -15
- package/dist/{chunk-XJ5H2MXY.mjs → chunk-HCCBEJEZ.mjs} +31 -1
- package/dist/{chunk-VOUI6XPV.mjs → chunk-HIZU7WI2.mjs} +1 -1
- package/dist/{chunk-VC6X44FS.mjs → chunk-ZR2QHTEX.mjs} +505 -68
- package/dist/codegen/backends/imperative.cjs +24 -6
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +20 -4
- package/dist/codegen/backends/imperative.mjs +24 -6
- package/dist/frontend/babel/build-ir-lit.cjs +470 -63
- package/dist/frontend/babel/build-ir-lit.mjs +470 -63
- package/dist/frontend/babel/build-ir.cjs +470 -63
- package/dist/frontend/babel/build-ir.mjs +470 -63
- package/dist/frontend/babel/index.cjs +471 -64
- package/dist/frontend/babel/index.mjs +471 -64
- package/dist/frontend/babel/lower-template.cjs +470 -63
- package/dist/frontend/babel/lower-template.mjs +470 -63
- package/dist/frontend/babel/plugin.cjs +470 -63
- package/dist/frontend/babel/plugin.mjs +470 -63
- package/dist/index.cjs +360 -58
- package/dist/index.mjs +372 -58
- package/dist/integrations.cjs +1347 -98
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +44 -2
- package/dist/integrations.mjs +205 -19
- package/dist/lower/compile-template.cjs +354 -57
- package/dist/lower/compile-template.d.cts +13 -0
- package/dist/lower/compile-template.d.ts +13 -0
- package/dist/lower/compile-template.d.ts.map +1 -1
- package/dist/lower/compile-template.js +3 -0
- package/dist/lower/compile-template.mjs +366 -57
- package/dist/lower/entities.cjs +288 -0
- package/dist/lower/entities.d.cts +1 -0
- package/dist/lower/entities.d.ts +2 -0
- package/dist/lower/entities.d.ts.map +1 -0
- package/dist/lower/entities.js +54 -0
- package/dist/lower/entities.mjs +267 -0
- package/dist/lower/jsx.cjs +567 -7
- package/dist/lower/jsx.d.cts +8 -0
- package/dist/lower/jsx.d.ts +8 -0
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +205 -7
- package/dist/lower/jsx.mjs +567 -7
- package/dist/lower/template.cjs +332 -56
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +57 -49
- package/dist/lower/template.mjs +332 -56
- package/dist/resolve/builtins.cjs +1 -1
- package/dist/resolve/builtins.mjs +1 -1
- package/dist/resolve/component-globals.cjs +20 -1
- package/dist/resolve/component-globals.js +2 -2
- package/dist/resolve/component-globals.mjs +20 -1
- package/dist/resolve/write-globals.cjs +20 -1
- package/dist/resolve/write-globals.mjs +20 -1
- package/dist/{server-fns-BBZRZUPP.mjs → server-fns-JLSTKWPS.mjs} +4 -4
- package/dist/{server-functions-VEGLIFCE.mjs → server-functions-BGY3RD4R.mjs} +3 -3
- package/dist/transform/index.cjs +1123 -77
- package/dist/transform/index.mjs +1141 -91
- package/dist/transform/intrinsics.cjs +18 -0
- package/dist/transform/intrinsics.mjs +18 -0
- package/dist/transform/props.mjs +19 -14
- package/dist/transform/server-fns.mjs +19 -14
- package/dist/transform/source-locations.cjs +64 -3
- package/dist/transform/source-locations.d.cts +7 -2
- package/dist/transform/source-locations.d.ts +7 -2
- package/dist/transform/source-locations.d.ts.map +1 -1
- package/dist/transform/source-locations.js +68 -3
- package/dist/transform/source-locations.mjs +64 -3
- package/dist/transform/styles.cjs +588 -0
- package/dist/transform/styles.d.cts +211 -0
- package/dist/transform/styles.d.ts +212 -0
- package/dist/transform/styles.d.ts.map +1 -0
- package/dist/transform/styles.js +714 -0
- package/dist/transform/styles.mjs +653 -0
- package/dist/transform/templates.cjs +1122 -76
- package/dist/transform/templates.d.cts +13 -0
- package/dist/transform/templates.d.ts +13 -0
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +51 -14
- package/dist/transform/templates.mjs +1140 -90
- package/dist/{transform-UWZ7ZGJ2.mjs → transform-GBP6Y4UI.mjs} +603 -19
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/vite-styles.cjs +180 -0
- package/dist/vite-styles.d.cts +59 -0
- package/dist/vite-styles.d.ts +60 -0
- package/dist/vite-styles.d.ts.map +1 -0
- package/dist/vite-styles.js +198 -0
- package/dist/vite-styles.mjs +159 -0
- package/package.json +10 -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;
|
|
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;AAEzH,OAAO,EAAqC,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAkB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAmBrL,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;IACrB;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;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,CAAC;IACb,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5C,yEAAyE;IACzE,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,wEAAwE;IACxE,oBAAoB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC7C,8DAA8D;IAC9D,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;IACnC,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAC/C,+FAA+F;IAC/F,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IACzB,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;IACrC,6FAA6F;IAC7F,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B,8EAA8E;IAC9E,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;CACpC;AAoTD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,gBAAqB,GAC7B,eAAe,GAAG,IAAI,CAuPxB"}
|
|
@@ -21,8 +21,9 @@ import { imperativeBackend } from '../codegen/backends/imperative.js';
|
|
|
21
21
|
import { moduleBindings } from './bindings.js';
|
|
22
22
|
import { collectPropsEdits } from './props.js';
|
|
23
23
|
import { avoidBindingClashes, collectIntrinsicEdits, intrinsicImports } from './intrinsics.js';
|
|
24
|
-
import { collectSourceEdits,
|
|
25
|
-
import {
|
|
24
|
+
import { collectSourceEdits, mayHaveSourceMarks } from './source-locations.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,
|
|
71
|
-
return
|
|
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) {
|
|
@@ -303,20 +302,29 @@ export function transformTemplates(code, id, options = {}) {
|
|
|
303
302
|
const wantsIntrinsics = options.intrinsics !== false && mayHaveIntrinsic(code);
|
|
304
303
|
// A module can be nothing but reactive calls and still need marking, so the skip check
|
|
305
304
|
// has to look for those too when source locations are wanted.
|
|
306
|
-
const wantsSources = options.sourceLocations === true &&
|
|
305
|
+
const wantsSources = options.sourceLocations === true && mayHaveSourceMarks(code);
|
|
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
|
-
|
|
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,
|
|
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);
|