Skip to content

Commit a5515ac

Browse files
committed
fix(scripts): the leaf's header is line comments, so the bundled .d.ts carries none of it
The bundler keeps a JSDoc block that leads a module's first statement, and the leaf is bundled first, so its /** */ header was published as 14 lines the base dist/index.d.ts did not carry. The header is // lines now; the self-test holds that. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2gLghEqeDKTbDTC7Zd
1 parent 20f49a9 commit a5515ac

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

‎scripts/codemod-split-sql-driver.mjs‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,21 +1075,23 @@ function moduleText(moduleFile, title, movers, scope, leafNames) {
10751075
* export and something outside the leaf now imports.
10761076
*/
10771077
function leafText(scope, top, leafExports) {
1078+
// The header is `//` lines, not a `/** */` docblock: the bundled `.d.ts`
1079+
// keeps a JSDoc block that leads a module's first statement, and this module
1080+
// is bundled FIRST, so a docblock here would be published text the base did
1081+
// not carry (measured: 14 added lines in dist/index.d.ts).
10781082
const out = [];
10791083
out.push('// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.');
10801084
out.push('');
1081-
out.push('/**');
10821085
out.push(...wrapComment([MARK, 'The', 'top-level', 'declarations', 'ahead', 'of', '`SqlDriver`', 'in', '`sql-driver.ts`',
10831086
'that', 'moved', 'out', 'whole', 'by', '`scripts/codemod-split-sql-driver.mjs`', '(lever', '(b)', 'of', 'ruling',
1084-
'6591753301).']));
1085-
out.push(' *');
1086-
out.push(' * A MOVE, not a redesign: each declaration below is its `sql-driver.ts` text');
1087-
out.push(' * exactly, with the comments above it, in the order it stood there. A LEAF:');
1088-
out.push(' * it imports neither `sql-driver.ts` nor any `sql-driver-*` module, so it is');
1089-
out.push(' * evaluated before the class and forms no cycle with it. `sql-driver.ts`');
1090-
out.push(' * re-exports, by name, every declaration here it exported before, so every');
1091-
out.push(' * importer of `./sql-driver.js` reads what it read.');
1092-
out.push(' */');
1087+
'6591753301).']).map((l) => l.replace(/^ \*/, '//')));
1088+
out.push('//');
1089+
out.push('// A MOVE, not a redesign: each declaration below is its `sql-driver.ts` text');
1090+
out.push('// exactly, with the comments above it, in the order it stood there. A LEAF:');
1091+
out.push('// it imports neither `sql-driver.ts` nor any `sql-driver-*` module, so it is');
1092+
out.push('// evaluated before the class and forms no cycle with it. `sql-driver.ts`');
1093+
out.push('// re-exports, by name, every declaration here it exported before, so every');
1094+
out.push('// importer of `./sql-driver.js` reads what it read.');
10931095
out.push('');
10941096
out.push(...importLines(scope, top.movers));
10951097
let text = out.join('\n');
@@ -1236,7 +1238,7 @@ function verify(tm, baseText, headText, moduleTexts, { readSibling = null } = {}
12361238
const stmts = sf.getStatements();
12371239
// The generated header is leading trivia of the first statement when no
12381240
// import precedes it; a moved statement's text starts after it.
1239-
const headerEnd = text.indexOf(' */\n', text.indexOf(MARK)) + ' */\n'.length;
1241+
const headerEnd = text.indexOf('\n\n', text.indexOf(MARK)) + 1;
12401242
stmts.forEach((st, i) => {
12411243
if (Node.isImportDeclaration(st)) {
12421244
if (/^\.\/sql-driver/.test(st.getModuleSpecifierValue())) {
@@ -1627,7 +1629,7 @@ let selfTestReachedVerdict = false;
16271629
const SELF_TEST_BATTERIES = Object.freeze({
16281630
'declaration bar': 6,
16291631
'stay rules': 11,
1630-
'top-level moves': 9,
1632+
'top-level moves': 10,
16311633
'byte-identity proof': 10,
16321634
'refusals': 3,
16331635
});
@@ -1823,6 +1825,8 @@ async function selfTest() {
18231825
check('a declaration after the class is not in the region', !top('needleInMethod'));
18241826
const out = generate(tm, input, planned);
18251827
const leaf = out.modules.get(LEAF_MODULE) ?? '';
1828+
check('the leaf header is line comments, never a docblock the bundled .d.ts would publish',
1829+
leaf.includes(MARK) && !leaf.slice(0, leaf.indexOf('\n\n', leaf.indexOf(MARK))).includes('/*'));
18261830
check('the leaf imports neither sql-driver.ts nor a seam module', leaf.length > 0 && !/from '\.\/sql-driver/.test(leaf), leaf.slice(0, 200));
18271831
check('sql-driver.ts re-exports the exported movers by name, the interface as a type',
18281832
/export \{ DERIVED, type ExportedShape \} from '\.\/sql-driver-top-level\.js';/.test(out.host));

0 commit comments

Comments
 (0)