Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove some unused code #9593

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-falcons-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: remove unused code
36 changes: 13 additions & 23 deletions packages/svelte/src/compiler/phases/1-parse/acorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function get_comment_handlers(source) {
* @typedef {import('estree').Comment & {
* start: number;
* end: number;
* has_trailing_newline?: boolean
* }} CommentWithLocation
*/

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

walk(
ast,
{},
{
_(node, { next }) {
let comment;
walk(ast, null, {
_(node, { next }) {
let comment;

while (comments[0] && comments[0].start < node.start) {
comment = /** @type {CommentWithLocation} */ (comments.shift());

const next = comments[0] || node;
comment.has_trailing_newline =
comment.type === 'Line' || /\n/.test(source.slice(comment.end, next.start));

(node.leadingComments ||= []).push(comment);
}
while (comments[0] && comments[0].start < node.start) {
comment = /** @type {CommentWithLocation} */ (comments.shift());
(node.leadingComments ||= []).push(comment);
}

next();
next();

if (comments[0]) {
const slice = source.slice(node.end, comments[0].start);
if (comments[0]) {
const slice = source.slice(node.end, comments[0].start);

if (/^[,) \t]*$/.test(slice)) {
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
}
if (/^[,) \t]*$/.test(slice)) {
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
}
}
}
);
});
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,7 @@ function create_block(parent, name, nodes, context) {
/** @type {import('estree').Statement} */ (update).leadingComments = [
{
type: 'Block',
value: ` Update `,
// @ts-expect-error
has_trailing_newline: true
value: ` Update `
}
];
}
Expand All @@ -1106,9 +1104,7 @@ function create_block(parent, name, nodes, context) {
body[0].leadingComments = [
{
type: 'Block',
value: ` Init `,
// @ts-expect-error
has_trailing_newline: true
value: ` Init `
}
];
}
Expand Down
12 changes: 3 additions & 9 deletions packages/svelte/src/compiler/phases/3-transform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ export function transform_component(analysis, source, options) {
program.body[0].leadingComments = [
{
type: 'Line',
value: ` ${basename} (Svelte v${VERSION})`,
// @ts-ignore
has_trailing_newline: true
value: ` ${basename} (Svelte v${VERSION})`
},
{
type: 'Line',
value: ' Note: compiler output will change before 5.0 is released!',
// @ts-ignore
has_trailing_newline: true
value: ' Note: compiler output will change before 5.0 is released!'
}
];
}
Expand Down Expand Up @@ -86,9 +82,7 @@ export function transform_module(analysis, source, options) {
program.body[0].leadingComments = [
{
type: 'Block',
value: ` ${basename} generated by Svelte v${VERSION} `,
// @ts-ignore
has_trailing_newline: true
value: ` ${basename} generated by Svelte v${VERSION} `
}
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@
"type": "Block",
"value": " another comment ",
"start": 163,
"end": 184,
"has_trailing_newline": true
"end": 184
}
]
}
Expand All @@ -121,8 +120,7 @@
"type": "Line",
"value": " comment",
"start": 141,
"end": 151,
"has_trailing_newline": true
"end": 151
}
]
}
Expand Down Expand Up @@ -222,8 +220,7 @@
"type": "Line",
"value": " a leading comment",
"start": 10,
"end": 30,
"has_trailing_newline": true
"end": 30
}
],
"trailingComments": [
Expand Down Expand Up @@ -290,8 +287,7 @@
"type": "Block",
"value": "* a comment ",
"start": 72,
"end": 88,
"has_trailing_newline": true
"end": 88
}
]
}
Expand Down