Skip to content

Commit 3e04636

Browse files
committed
fix
1 parent 1bd50a8 commit 3e04636

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

packages/svelte/scripts/check-treeshakeability.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ import virtual from '@rollup/plugin-virtual';
55

66
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
77

8+
let failed = false;
9+
10+
console.group('checking treeshakeability');
11+
812
for (const key in pkg.exports) {
13+
// special cases
14+
if (key === './compiler') continue;
15+
if (key === './internal/disclose-version') continue;
16+
917
for (const type of ['browser', 'default']) {
1018
if (!pkg.exports[key][type]) continue;
1119

20+
const subpackage = path.join(pkg.name, key);
21+
1222
const resolved = path.resolve(pkg.exports[key][type]);
1323

1424
const bundle = await rollup({
@@ -29,10 +39,19 @@ for (const key in pkg.exports) {
2939
throw new Error('errr what');
3040
}
3141

32-
const { code } = output[0];
42+
const code = output[0].code.replace(/import\s+([^'"]+from\s+)?(['"])[^'"]+\2\s*;?/, '');
3343
if (code.trim()) {
3444
console.error(code);
35-
throw new Error(`${path.join(pkg.name, key)} ${type} export is not tree-shakeable`);
45+
console.error(`❌ ${subpackage} (${type})`);
46+
failed = true;
47+
} else {
48+
console.error(`✅ ${subpackage} (${type})`);
3649
}
3750
}
3851
}
52+
53+
console.groupEnd();
54+
55+
if (failed) {
56+
process.exit(1);
57+
}

packages/svelte/src/internal/server/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const INVALID_ATTR_NAME_CHAR_REGEX =
3232
/[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;
3333

3434
// This is duplicated from the compiler, but we need it at runtime too.
35-
const DOMBooleans = [
35+
export const DOMBooleanAttributes = [
3636
'allowfullscreen',
3737
'async',
3838
'autofocus',
@@ -59,9 +59,6 @@ const DOMBooleans = [
5959
'selected'
6060
];
6161

62-
/** @type {Set<string>} */
63-
export const DOMBooleanAttributes = new Set(DOMBooleans);
64-
6562
export const VoidElements = new Set([
6663
'area',
6764
'base',
@@ -280,7 +277,7 @@ export function spread_attributes(attrs, class_hash, additional) {
280277

281278
for (name in merged_attrs) {
282279
if (INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;
283-
const is_boolean = DOMBooleanAttributes.has(name);
280+
const is_boolean = DOMBooleanAttributes.includes(name);
284281
attr_str += attr(name, merged_attrs[name], is_boolean);
285282
}
286283

0 commit comments

Comments
 (0)