ember-vite-hmr 2.2.2 → 2.2.3
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/lib/hmr.js +36 -11
- package/package.json +1 -1
package/dist/lib/hmr.js
CHANGED
|
@@ -15,26 +15,51 @@ const traverse = traverseModule.default || traverseModule;
|
|
|
15
15
|
import { readFile } from 'fs/promises';
|
|
16
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
17
17
|
const __dirname = path.dirname(__filename);
|
|
18
|
+
// Above this many distinct named blocks, fall back to forwarding all of them
|
|
19
|
+
// unconditionally rather than generating an exponential number of branches
|
|
20
|
+
// (see generateInvocations below for why branching is needed at all).
|
|
21
|
+
const MAX_COMBINATORIAL_YIELDS = 8;
|
|
22
|
+
function blockTag(y) {
|
|
23
|
+
return `<:${y} as |a b c d e f g h i j k l|>{{yield a b c d e f g h i j k l to='${y}'}}</:${y}>`;
|
|
24
|
+
}
|
|
25
|
+
function invocation(selected) {
|
|
26
|
+
if (!selected.length) {
|
|
27
|
+
return `<this.curried @__hot__={{this.hot}} ...attributes />`;
|
|
28
|
+
}
|
|
29
|
+
return `<this.curried @__hot__={{this.hot}} ...attributes>${selected.map(blockTag).join('\n')}</this.curried>`;
|
|
30
|
+
}
|
|
31
|
+
// Glimmer determines a target component's `(has-block "y")` purely from
|
|
32
|
+
// whether a `<:y>` named block tag is structurally present on the
|
|
33
|
+
// invocation, not from whether that block's content renders anything, and
|
|
34
|
+
// named block tags cannot be nested inside `{{#if}}` (a "named block nested
|
|
35
|
+
// in a normal block" compile error). So a per-block `{{#if (has-block 'y')}}
|
|
36
|
+
// <:y>...</:y>{{/if}}` inside a single invocation can't work — instead this
|
|
37
|
+
// recursively branches on `(has-block y)` for each known named block to
|
|
38
|
+
// build one fully static invocation per combination of blocks the caller
|
|
39
|
+
// actually passed, so blocks not passed are truly absent rather than merely
|
|
40
|
+
// empty (see #531).
|
|
41
|
+
function generateInvocations(remaining, selected) {
|
|
42
|
+
if (!remaining.length) {
|
|
43
|
+
return invocation(selected);
|
|
44
|
+
}
|
|
45
|
+
const [y, ...rest] = remaining;
|
|
46
|
+
return `{{#if (has-block '${y}')}}${generateInvocations(rest, [...selected, y])}{{else}}${generateInvocations(rest, selected)}{{/if}}`;
|
|
47
|
+
}
|
|
18
48
|
function generateContent(yields) {
|
|
19
49
|
if (!yields.includes('default')) {
|
|
20
50
|
yields.push('default');
|
|
21
51
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
str += `
|
|
26
|
-
<:${y} as |a b c d e f g h i j k l|>{{yield a b c d e f g h i j k l to='${y}'}}</:${y}>
|
|
27
|
-
`;
|
|
28
|
-
}
|
|
29
|
-
return `
|
|
52
|
+
if (yields.length > MAX_COMBINATORIAL_YIELDS) {
|
|
53
|
+
let all = yields.map((y) => `(has-block '${y}')`).join(' ');
|
|
54
|
+
return `
|
|
30
55
|
{{#if (notAny ${all})}}
|
|
31
56
|
<this.curried @__hot__={{this.hot}} ...attributes />
|
|
32
57
|
{{else}}
|
|
33
|
-
|
|
34
|
-
${str}
|
|
35
|
-
</this.curried>
|
|
58
|
+
${invocation(yields)}
|
|
36
59
|
{{/if}}
|
|
37
60
|
`;
|
|
61
|
+
}
|
|
62
|
+
return generateInvocations(yields, []);
|
|
38
63
|
}
|
|
39
64
|
const getHotComponent = (imp, specifier, yields) => `
|
|
40
65
|
import { ${specifier} as TargetComponent } from "${imp}";
|