Skip to content

Commit 9b451f4

Browse files
Brooooooklynclaude
andcommitted
fix(cli): handle default+named imports in external dts type-only fix
`externalDtsTypeOnlyPlugin` blindly prepended `import type ` to every import line in postcss/lightningcss `.d.ts` files. For the `import D, { N } from 'x'` shape that produced `import type D, { N }`, which is invalid — a type-only import statement cannot mix a default binding with named bindings. The dts bundler then failed with `[PARSE_ERROR]` (surfaced by the `vp-config` ecosystem-ci project, whose dependency graph routes postcss's `.d.ts` through this plugin). Fold the default binding into the named clause as `{ default as D, N }` before the generic prepend, in both the internal-file and consumer-file branches. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 62c3d5e commit 9b451f4

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

packages/cli/src/pack-bin.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,24 @@ function externalDtsTypeOnlyPlugin() {
4242
const id = rawId.replaceAll('\\', '/');
4343
if (EXTERNAL_DTS_INTERNAL_RE.test(id)) {
4444
// postcss/lightningcss internal files: transform imports only
45-
// (exports may include value re-exports like `export const Features`)
46-
return code.replace(/^(import\s+)(?!type\s)/gm, 'import type ');
45+
// (exports may include value re-exports like `export const Features`).
46+
// A type-only import statement cannot mix a default binding with named
47+
// bindings, so fold `import D, { N } from 'x'` into a single named
48+
// clause (`{ default as D, N }`) before the generic prepend runs.
49+
return code
50+
.replace(/^import\s+(\w+)\s*,\s*\{/gm, 'import type { default as $1,')
51+
.replace(/^(import\s+)(?!type\s)/gm, 'import type ');
4752
}
4853
// Consumer files: only transform imports from postcss/lightningcss
49-
return code.replace(
50-
/^(import\s+)(?!type\s)(.+from\s+['"](?:postcss|lightningcss)['"])/gm,
51-
'import type $2',
52-
);
54+
return code
55+
.replace(
56+
/^import\s+(\w+)\s*,\s*\{([^}]*)\}\s*from\s+(['"](?:postcss|lightningcss)['"])/gm,
57+
'import type { default as $1,$2} from $3',
58+
)
59+
.replace(
60+
/^(import\s+)(?!type\s)(.+from\s+['"](?:postcss|lightningcss)['"])/gm,
61+
'import type $2',
62+
);
5363
},
5464
},
5565
};

0 commit comments

Comments
 (0)