chore: remove some unused code (#9593)

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/9598/head
Rich Harris 1 year ago committed by GitHub
parent cf9130613d
commit 1f4ae5ef45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: remove unused code

@ -58,7 +58,6 @@ export function get_comment_handlers(source) {
* @typedef {import('estree').Comment & { * @typedef {import('estree').Comment & {
* start: number; * start: number;
* end: number; * end: number;
* has_trailing_newline?: boolean
* }} CommentWithLocation * }} CommentWithLocation
*/ */
@ -91,35 +90,26 @@ export function get_comment_handlers(source) {
add_comments(ast) { add_comments(ast) {
if (comments.length === 0) return; if (comments.length === 0) return;
walk( walk(ast, null, {
ast, _(node, { next }) {
{}, let comment;
{
_(node, { next }) {
let comment;
while (comments[0] && comments[0].start < node.start) { while (comments[0] && comments[0].start < node.start) {
comment = /** @type {CommentWithLocation} */ (comments.shift()); comment = /** @type {CommentWithLocation} */ (comments.shift());
(node.leadingComments ||= []).push(comment);
const next = comments[0] || node; }
comment.has_trailing_newline =
comment.type === 'Line' || /\n/.test(source.slice(comment.end, next.start));
(node.leadingComments ||= []).push(comment);
}
next(); next();
if (comments[0]) { if (comments[0]) {
const slice = source.slice(node.end, comments[0].start); const slice = source.slice(node.end, comments[0].start);
if (/^[,) \t]*$/.test(slice)) { if (/^[,) \t]*$/.test(slice)) {
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())]; node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
}
} }
} }
} }
); });
} }
}; };
} }

@ -1087,9 +1087,7 @@ function create_block(parent, name, nodes, context) {
/** @type {import('estree').Statement} */ (update).leadingComments = [ /** @type {import('estree').Statement} */ (update).leadingComments = [
{ {
type: 'Block', type: 'Block',
value: ` Update `, value: ` Update `
// @ts-expect-error
has_trailing_newline: true
} }
]; ];
} }
@ -1107,9 +1105,7 @@ function create_block(parent, name, nodes, context) {
body[0].leadingComments = [ body[0].leadingComments = [
{ {
type: 'Block', type: 'Block',
value: ` Init `, value: ` Init `
// @ts-expect-error
has_trailing_newline: true
} }
]; ];
} }

@ -32,15 +32,11 @@ export function transform_component(analysis, source, options) {
program.body[0].leadingComments = [ program.body[0].leadingComments = [
{ {
type: 'Line', type: 'Line',
value: ` ${basename} (Svelte v${VERSION})`, value: ` ${basename} (Svelte v${VERSION})`
// @ts-ignore
has_trailing_newline: true
}, },
{ {
type: 'Line', type: 'Line',
value: ' Note: compiler output will change before 5.0 is released!', value: ' Note: compiler output will change before 5.0 is released!'
// @ts-ignore
has_trailing_newline: true
} }
]; ];
} }
@ -86,9 +82,7 @@ export function transform_module(analysis, source, options) {
program.body[0].leadingComments = [ program.body[0].leadingComments = [
{ {
type: 'Block', type: 'Block',
value: ` ${basename} generated by Svelte v${VERSION} `, value: ` ${basename} generated by Svelte v${VERSION} `
// @ts-ignore
has_trailing_newline: true
} }
]; ];
} }

@ -109,8 +109,7 @@
"type": "Block", "type": "Block",
"value": " another comment ", "value": " another comment ",
"start": 163, "start": 163,
"end": 184, "end": 184
"has_trailing_newline": true
} }
] ]
} }
@ -121,8 +120,7 @@
"type": "Line", "type": "Line",
"value": " comment", "value": " comment",
"start": 141, "start": 141,
"end": 151, "end": 151
"has_trailing_newline": true
} }
] ]
} }
@ -222,8 +220,7 @@
"type": "Line", "type": "Line",
"value": " a leading comment", "value": " a leading comment",
"start": 10, "start": 10,
"end": 30, "end": 30
"has_trailing_newline": true
} }
], ],
"trailingComments": [ "trailingComments": [
@ -290,8 +287,7 @@
"type": "Block", "type": "Block",
"value": "* a comment ", "value": "* a comment ",
"start": 72, "start": 72,
"end": 88, "end": 88
"has_trailing_newline": true
} }
] ]
} }

Loading…
Cancel
Save