Skip to content

Commit 1f4ae5e

Browse files
authored
chore: remove some unused code (#9593)
Co-authored-by: Rich Harris <[email protected]>
1 parent cf91306 commit 1f4ae5e

File tree

5 files changed

+27
-46
lines changed

5 files changed

+27
-46
lines changed

.changeset/two-falcons-buy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: remove unused code

packages/svelte/src/compiler/phases/1-parse/acorn.js

+13-23
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export function get_comment_handlers(source) {
5858
* @typedef {import('estree').Comment & {
5959
* start: number;
6060
* end: number;
61-
* has_trailing_newline?: boolean
6261
* }} CommentWithLocation
6362
*/
6463

@@ -91,35 +90,26 @@ export function get_comment_handlers(source) {
9190
add_comments(ast) {
9291
if (comments.length === 0) return;
9392

94-
walk(
95-
ast,
96-
{},
97-
{
98-
_(node, { next }) {
99-
let comment;
93+
walk(ast, null, {
94+
_(node, { next }) {
95+
let comment;
10096

101-
while (comments[0] && comments[0].start < node.start) {
102-
comment = /** @type {CommentWithLocation} */ (comments.shift());
103-
104-
const next = comments[0] || node;
105-
comment.has_trailing_newline =
106-
comment.type === 'Line' || /\n/.test(source.slice(comment.end, next.start));
107-
108-
(node.leadingComments ||= []).push(comment);
109-
}
97+
while (comments[0] && comments[0].start < node.start) {
98+
comment = /** @type {CommentWithLocation} */ (comments.shift());
99+
(node.leadingComments ||= []).push(comment);
100+
}
110101

111-
next();
102+
next();
112103

113-
if (comments[0]) {
114-
const slice = source.slice(node.end, comments[0].start);
104+
if (comments[0]) {
105+
const slice = source.slice(node.end, comments[0].start);
115106

116-
if (/^[,) \t]*$/.test(slice)) {
117-
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
118-
}
107+
if (/^[,) \t]*$/.test(slice)) {
108+
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
119109
}
120110
}
121111
}
122-
);
112+
});
123113
}
124114
};
125115
}

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,7 @@ function create_block(parent, name, nodes, context) {
10871087
/** @type {import('estree').Statement} */ (update).leadingComments = [
10881088
{
10891089
type: 'Block',
1090-
value: ` Update `,
1091-
// @ts-expect-error
1092-
has_trailing_newline: true
1090+
value: ` Update `
10931091
}
10941092
];
10951093
}
@@ -1107,9 +1105,7 @@ function create_block(parent, name, nodes, context) {
11071105
body[0].leadingComments = [
11081106
{
11091107
type: 'Block',
1110-
value: ` Init `,
1111-
// @ts-expect-error
1112-
has_trailing_newline: true
1108+
value: ` Init `
11131109
}
11141110
];
11151111
}

packages/svelte/src/compiler/phases/3-transform/index.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@ export function transform_component(analysis, source, options) {
3232
program.body[0].leadingComments = [
3333
{
3434
type: 'Line',
35-
value: ` ${basename} (Svelte v${VERSION})`,
36-
// @ts-ignore
37-
has_trailing_newline: true
35+
value: ` ${basename} (Svelte v${VERSION})`
3836
},
3937
{
4038
type: 'Line',
41-
value: ' Note: compiler output will change before 5.0 is released!',
42-
// @ts-ignore
43-
has_trailing_newline: true
39+
value: ' Note: compiler output will change before 5.0 is released!'
4440
}
4541
];
4642
}
@@ -86,9 +82,7 @@ export function transform_module(analysis, source, options) {
8682
program.body[0].leadingComments = [
8783
{
8884
type: 'Block',
89-
value: ` ${basename} generated by Svelte v${VERSION} `,
90-
// @ts-ignore
91-
has_trailing_newline: true
85+
value: ` ${basename} generated by Svelte v${VERSION} `
9286
}
9387
];
9488
}

packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@
109109
"type": "Block",
110110
"value": " another comment ",
111111
"start": 163,
112-
"end": 184,
113-
"has_trailing_newline": true
112+
"end": 184
114113
}
115114
]
116115
}
@@ -121,8 +120,7 @@
121120
"type": "Line",
122121
"value": " comment",
123122
"start": 141,
124-
"end": 151,
125-
"has_trailing_newline": true
123+
"end": 151
126124
}
127125
]
128126
}
@@ -222,8 +220,7 @@
222220
"type": "Line",
223221
"value": " a leading comment",
224222
"start": 10,
225-
"end": 30,
226-
"has_trailing_newline": true
223+
"end": 30
227224
}
228225
],
229226
"trailingComments": [
@@ -290,8 +287,7 @@
290287
"type": "Block",
291288
"value": "* a comment ",
292289
"start": 72,
293-
"end": 88,
294-
"has_trailing_newline": true
290+
"end": 88
295291
}
296292
]
297293
}

0 commit comments

Comments
 (0)