Skip to content

Commit b8014e1

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/project-thread-x1ore2-hydrate-reask
2 parents 7ce4011 + 55c7329 commit b8014e1

26 files changed

Lines changed: 583 additions & 61 deletions

File tree

‎.changeset/babel-plugin-babel-8.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/babel-plugin": patch
3+
---
4+
5+
Support `@babel/core` 8 alongside 7: the peer range is now `^7.20.12 || ^8.0.0`. SSR no longer reads `Scope#uids` (removed in Babel 8), evaluated negative or non-finite numbers are built with `valueToNode`, `import()` parsed as `ImportExpression` stays dynamic, and TSRX emits the AST shape of the running Babel major (type arguments, type parameter names, `import()`, enums, heritage). TSRX also keeps `import()` options and class method type parameters, which it dropped before.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
`latest()` of an optimistic value now shows the guess beside the held screen however reads are grouped into render effects (#4284). When a guess's lane is held on a downstream async derivation, a render effect that reads the guess and `latest(guess)` together no longer parks with the lane and freezes the `latest()` read: like split effects, it shows `1 x1 / 5` (the committed value and its derivation beside the guess) and `5 x5 / 5` when the derivation lands. The lane still holds the guess until its derivation lands; an unblocked lane costs no extra pass.

‎.github/workflows/main-ci.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,31 @@ jobs:
6363
path: |
6464
'*/dist'
6565
'*/types'
66+
67+
# @solidjs/babel-plugin peers @babel/core ^7 || ^8 and keeps its own 7.x
68+
# helpers, so this runs its suite against the core a Babel 8 user installs.
69+
babel-8:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- uses: actions/checkout@v4
73+
- uses: pnpm/action-setup@v4
74+
- uses: actions/setup-node@v4
75+
with:
76+
node-version-file: ".nvmrc"
77+
cache: "pnpm"
78+
79+
- name: Installing deps
80+
run: pnpm install
81+
82+
- name: Building babel plugin
83+
run: pnpm --filter @solidjs/babel-plugin run build
84+
85+
- name: Swapping in @babel/core 8
86+
run: |
87+
npm install --prefix "$RUNNER_TEMP/babel8" --no-save --no-package-lock @babel/core@^8
88+
ln -sfn "$RUNNER_TEMP/babel8/node_modules/@babel/core" packages/babel-plugin/node_modules/@babel/core
89+
node -p "'@babel/core ' + require('./packages/babel-plugin/node_modules/@babel/core/package.json').version"
90+
91+
- name: Testing on Babel 8
92+
working-directory: packages/babel-plugin
93+
run: pnpm exec vitest run

‎packages/babel-plugin/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"parse5": "^7.1.2"
2828
},
2929
"peerDependencies": {
30-
"@babel/core": "^7.20.12",
30+
"@babel/core": "^7.20.12 || ^8.0.0",
3131
"@tsrx/core": "0.1.63"
3232
},
3333
"peerDependenciesMeta": {

‎packages/babel-plugin/src/dom/element.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export function transformElement(
245245
}
246246
if (value)
247247
a.get("value").replaceWith(
248-
t.jSXExpressionContainer(t.callExpression(t.arrowFunctionExpression([], value), []))
248+
t.jsxExpressionContainer(t.callExpression(t.arrowFunctionExpression([], value), []))
249249
);
250250
}
251251
});
@@ -997,7 +997,7 @@ function transformAttributes(
997997
((type = typeof evaluated) === "string" || type === "number" || type === "boolean")
998998
) {
999999
if (type === "number" && key.startsWith("prop:")) {
1000-
value = t.jsxExpressionContainer(t.numericLiteral(evaluated));
1000+
value = t.jsxExpressionContainer(t.valueToNode(evaluated) as babelTypes.Expression);
10011001
} else if (type === "boolean") {
10021002
value = t.jsxExpressionContainer(t.booleanLiteral(evaluated));
10031003
} else value = t.stringLiteral(String(evaluated));

‎packages/babel-plugin/src/index.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@ type ParserOptions = { sourceFileName?: string };
1515
type ParseFn = (code: string, parserOpts: ParserOptions) => t.File;
1616

1717
export default (
18-
_api?: unknown,
18+
api?: { version?: string },
1919
options: { syntax?: SyntaxOption } = {}
2020
): {
2121
name: string;
2222
inherits: () => JSXPluginSyntax;
2323
parserOverride: (code: string, parserOpts: ParserOptions, parse: ParseFn) => t.File;
2424
visitor: Visitor<PluginPass>;
2525
} => {
26+
// TSRX builds its own AST, so it has to match the running core's shape.
27+
const babelMajor = parseInt(api?.version ?? "7", 10) || 7;
2628
return {
2729
name: "@solidjs/babel-plugin",
2830
inherits: SyntaxJSX.default,
2931
parserOverride(code, parserOpts, parse) {
3032
if (isTsrxSource(options.syntax, parserOpts?.sourceFileName)) {
31-
return parseTsrx(code, parserOpts?.sourceFileName);
33+
return parseTsrx(code, parserOpts?.sourceFileName, babelMajor);
3234
}
3335
return parse(code, parserOpts);
3436
},

‎packages/babel-plugin/src/shared/utils.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ export function hasStaticMarker(
130130
return hasStaticMarker(object.expression as StaticMarkerNode, path);
131131
}
132132

133+
/** `import()`: an `ImportExpression` on Babel 8 (and 7 with
134+
* `createImportExpressions`), a `CallExpression` with an `Import` callee
135+
* otherwise. Checked by type so older `@babel/types` builds still match. */
136+
export function isImportExpression(node: t.Node): boolean {
137+
return node.type === ("ImportExpression" as t.Node["type"]);
138+
}
139+
133140
export function isDynamic(
134141
path: NodePath,
135142
{ checkMember, checkTags, checkCallExpressions = true }: DynamicOptions
@@ -149,7 +156,8 @@ export function isDynamic(
149156
checkCallExpressions &&
150157
(t.isCallExpression(expr) ||
151158
t.isOptionalCallExpression(expr) ||
152-
t.isTaggedTemplateExpression(expr))
159+
t.isTaggedTemplateExpression(expr) ||
160+
isImportExpression(expr))
153161
) {
154162
return true;
155163
}
@@ -192,6 +200,11 @@ export function isDynamic(
192200

193201
let dynamic: boolean | undefined;
194202
const visitor: Visitor = {
203+
// `ImportExpression` is matched by type rather than visitor key: a Babel
204+
// core older than 7.23 rejects visitors for node types it doesn't know.
205+
enter(p) {
206+
checkCallExpressions && isImportExpression(p.node) && (dynamic = true) && p.stop();
207+
},
195208
Function(p) {
196209
if (t.isObjectMethod(p.node) && p.node.computed) {
197210
dynamic = isDynamic(p.get("key"), { checkMember, checkTags, checkCallExpressions });
@@ -773,7 +786,7 @@ export function evaluateAndInline(
773786
if (typeof r.value === "string") {
774787
valueNode.replaceWith(t.stringLiteral(r.value));
775788
} else if (typeof r.value === "number") {
776-
valueNode.replaceWith(t.numericLiteral(r.value));
789+
valueNode.replaceWith(t.valueToNode(r.value));
777790
} else if (typeof r.value === "boolean") {
778791
valueNode.replaceWith(t.booleanLiteral(r.value));
779792
}

‎packages/babel-plugin/src/ssr/element.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
inlineCallExpression,
2121
canChildSlotAllocateIds,
2222
isFunctionShapedHole,
23-
isEventName
23+
isEventName,
24+
isImportExpression
2425
} from "../shared/utils";
2526
import { transformNode, getCreateTemplate } from "../shared/transform";
2627
import { decodedAttrValue } from "../universal/element";
@@ -1309,7 +1310,8 @@ function callsOutsideFunctions(node: babelTypes.Node): boolean {
13091310
t.isCallExpression(node) ||
13101311
t.isOptionalCallExpression(node) ||
13111312
t.isNewExpression(node) ||
1312-
t.isTaggedTemplateExpression(node)
1313+
t.isTaggedTemplateExpression(node) ||
1314+
isImportExpression(node)
13131315
)
13141316
return true;
13151317
if (t.isFunction(node)) return false;

‎packages/babel-plugin/src/ssr/props.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ export function hoistProps(program: NodePath<t.Program>, config: PluginConfig):
8484
// program scope's `uids` (the names generateUid handed out — `hasUid` is
8585
// how a compiler temp is told from user code below) and `data` (imports,
8686
// templates, events — what postprocess is about to place); both survive.
87-
const uids = program.scope.uids;
87+
const scope = program.scope as typeof program.scope & { uidsSet?: Set<string> };
88+
const uids = scope.uidsSet ? new Set(scope.uidsSet) : scope.uids;
8889
program.scope.crawl();
89-
Object.assign(program.scope.uids, uids);
90+
if (uids instanceof Set) for (const name of uids) scope.uidsSet!.add(name);
91+
else Object.assign(program.scope.uids, uids);
9092
program.scope.data = data as Record<string | symbol, unknown>;
9193

9294
const state: HoistState = {

‎packages/babel-plugin/src/tsrx/estree-to-babel.ts‎

Lines changed: 119 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ const STRIP_KEYS = new Set([
3131
"directive"
3232
]);
3333

34+
/** Which Babel AST shape to emit. Babel 8 keeps `typeArguments`,
35+
* `ImportExpression`, Identifier type-parameter names and `TSEnumBody`;
36+
* Babel 7 wants the older forms. Set for the length of one `toBabelFile`. */
37+
let babel8 = false;
38+
39+
/** The key Babel expects for a node's type arguments. */
40+
function typeArgsKey(): string {
41+
return babel8 ? "typeArguments" : "typeParameters";
42+
}
43+
3444
function isNode(value: unknown): value is EsNode {
3545
return (
3646
typeof value === "object" &&
@@ -57,19 +67,32 @@ function convertValue(value: unknown): unknown {
5767
}
5868

5969
/** Shallow-map every kept key, renaming typescript-eslint's `typeArguments`
60-
* to Babel 7's `typeParameters` along the way. */
70+
* to Babel 7's `typeParameters` along the way (Babel 8 keeps the name). */
6171
function convertGeneric(node: EsNode, overrideType?: string): EsNode {
6272
const out: Record<string, unknown> = { type: overrideType ?? node.type };
6373
copyLoc(node, out);
6474
for (const key of Object.keys(node)) {
6575
if (STRIP_KEYS.has(key)) continue;
6676
const outKey =
67-
key === "typeArguments" && node.typeParameters === undefined ? "typeParameters" : key;
77+
!babel8 && key === "typeArguments" && node.typeParameters === undefined
78+
? "typeParameters"
79+
: key;
6880
out[outKey] = convertValue(node[key]);
6981
}
7082
return out as EsNode;
7183
}
7284

85+
/** Convert a node whose type arguments typescript-eslint spells
86+
* `typeParameters`, moving them to the key the target Babel expects. */
87+
function convertTypeArgsHolder(node: EsNode, type: string): EsNode {
88+
const out = convertGeneric(node, type) as Record<string, unknown>;
89+
const args = out.typeParameters ?? out.typeArguments;
90+
delete out.typeParameters;
91+
delete out.typeArguments;
92+
if (args !== undefined) out[typeArgsKey()] = args;
93+
return out as EsNode;
94+
}
95+
7396
function convertLiteral(node: EsNode): EsNode {
7497
const out: Record<string, unknown> = {};
7598
copyLoc(node, out);
@@ -162,7 +185,7 @@ function convertChainLink(node: EsNode): EsNode {
162185
};
163186
copyLoc(node, out);
164187
if (node.typeParameters !== undefined || node.typeArguments !== undefined) {
165-
out.typeParameters = convertValue(node.typeParameters ?? node.typeArguments);
188+
out[typeArgsKey()] = convertValue(node.typeParameters ?? node.typeArguments);
166189
}
167190
return out as EsNode;
168191
}
@@ -245,6 +268,9 @@ function convertNode(node: EsNode): EsNode {
245268
};
246269
copyLoc(node, out);
247270
convertFunctionParts(fn, out);
271+
if (node.typeParameters != null && out.typeParameters === undefined) {
272+
out.typeParameters = convertValue(node.typeParameters);
273+
}
248274
if (node.accessibility !== undefined) out.accessibility = node.accessibility;
249275
if (node.override !== undefined) out.override = node.override;
250276
if (node.optional !== undefined) out.optional = node.optional;
@@ -287,10 +313,22 @@ function convertNode(node: EsNode): EsNode {
287313
return convertChainLink(node.expression as EsNode);
288314

289315
case "ImportExpression": {
316+
// `@tsrx/core` puts the options object in `arguments[0]`; acorn uses `options`.
317+
const options = node.options ?? (node.arguments as EsNode[] | undefined)?.[0];
318+
if (babel8) {
319+
const out: Record<string, unknown> = {
320+
type: "ImportExpression",
321+
source: convertValue(node.source),
322+
options: options != null ? convertValue(options) : null
323+
};
324+
if (node.phase != null) out.phase = node.phase;
325+
copyLoc(node, out);
326+
return out as EsNode;
327+
}
290328
const importCallee: Record<string, unknown> = { type: "Import" };
291329
copyLoc(node, importCallee);
292330
const args: unknown[] = [convertValue(node.source)];
293-
if (node.options != null) args.push(convertValue(node.options));
331+
if (options != null) args.push(convertValue(options));
294332
const out: Record<string, unknown> = {
295333
type: "CallExpression",
296334
callee: importCallee,
@@ -308,13 +346,72 @@ function convertNode(node: EsNode): EsNode {
308346
}
309347

310348
case "TSTypeParameter": {
311-
const out = convertGeneric(node);
312-
if (isNode(out.name)) out.name = (out.name as unknown as { name: string }).name;
313-
return out;
349+
const out = convertGeneric(node) as Record<string, unknown>;
350+
if (babel8) {
351+
if (typeof out.name === "string") {
352+
const id: Record<string, unknown> = { type: "Identifier", name: out.name };
353+
copyLoc(node, id);
354+
out.name = id;
355+
}
356+
} else if (isNode(out.name)) out.name = (out.name as unknown as { name: string }).name;
357+
return out as EsNode;
314358
}
315359

316360
case "TSInterfaceHeritage":
317-
return convertGeneric(node, "TSExpressionWithTypeArguments");
361+
return convertTypeArgsHolder(
362+
node,
363+
babel8 ? "TSInterfaceHeritage" : "TSExpressionWithTypeArguments"
364+
);
365+
366+
// `implements` entries arrive in the pre-split typescript-eslint shape.
367+
case "TSExpressionWithTypeArguments":
368+
case "TSClassImplements":
369+
return convertTypeArgsHolder(
370+
node,
371+
babel8 ? "TSClassImplements" : "TSExpressionWithTypeArguments"
372+
);
373+
374+
case "ClassDeclaration":
375+
case "ClassExpression": {
376+
const out = convertGeneric(node) as Record<string, unknown>;
377+
const superArgs = out.superTypeParameters ?? out.superTypeArguments;
378+
delete out.superTypeParameters;
379+
delete out.superTypeArguments;
380+
if (superArgs !== undefined) {
381+
out[babel8 ? "superTypeArguments" : "superTypeParameters"] = superArgs;
382+
}
383+
return out as EsNode;
384+
}
385+
386+
case "TSInterfaceDeclaration": {
387+
const out = convertGeneric(node) as Record<string, unknown>;
388+
// Interface heritage can arrive in the class-implements shape.
389+
if (babel8 && Array.isArray(out.extends)) {
390+
for (const heritage of out.extends as Record<string, unknown>[]) {
391+
heritage.type = "TSInterfaceHeritage";
392+
}
393+
}
394+
return out as EsNode;
395+
}
396+
397+
case "TSImportType": {
398+
const out = convertGeneric(node) as Record<string, unknown>;
399+
if (babel8 && out.argument !== undefined) {
400+
out.source = out.argument;
401+
delete out.argument;
402+
}
403+
return out as EsNode;
404+
}
405+
406+
case "TSEnumDeclaration": {
407+
const out = convertGeneric(node) as Record<string, unknown>;
408+
if (babel8 && out.body === undefined) {
409+
const body: Record<string, unknown> = { type: "TSEnumBody", members: out.members };
410+
delete out.members;
411+
out.body = body;
412+
}
413+
return out as EsNode;
414+
}
318415

319416
case "TSAbstractMethodDefinition":
320417
case "TSAbstractPropertyDefinition":
@@ -337,13 +434,18 @@ function convertNode(node: EsNode): EsNode {
337434
}
338435
}
339436

340-
export function toBabelFile(program: EsNode): t.File {
341-
const file: Record<string, unknown> = {
342-
type: "File",
343-
program: convertNode(program),
344-
comments: [],
345-
tokens: []
346-
};
347-
copyLoc(program, file);
348-
return file as unknown as t.File;
437+
export function toBabelFile(program: EsNode, babelMajor = 7): t.File {
438+
babel8 = babelMajor >= 8;
439+
try {
440+
const file: Record<string, unknown> = {
441+
type: "File",
442+
program: convertNode(program),
443+
comments: [],
444+
tokens: []
445+
};
446+
copyLoc(program, file);
447+
return file as unknown as t.File;
448+
} finally {
449+
babel8 = false;
450+
}
349451
}

0 commit comments

Comments
 (0)