From 1f4ae5ef451fc369a80dc784ea62ced0a83c34ce Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 22 Nov 2023 14:10:12 -0500 Subject: [PATCH] chore: remove some unused code (#9593) Co-authored-by: Rich Harris --- .changeset/two-falcons-buy.md | 5 +++ .../src/compiler/phases/1-parse/acorn.js | 36 +++++++------------ .../3-transform/client/visitors/template.js | 8 ++--- .../src/compiler/phases/3-transform/index.js | 12 ++----- .../samples/javascript-comments/output.json | 12 +++---- 5 files changed, 27 insertions(+), 46 deletions(-) create mode 100644 .changeset/two-falcons-buy.md diff --git a/.changeset/two-falcons-buy.md b/.changeset/two-falcons-buy.md new file mode 100644 index 0000000000..c1a8e069f6 --- /dev/null +++ b/.changeset/two-falcons-buy.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +chore: remove unused code diff --git a/packages/svelte/src/compiler/phases/1-parse/acorn.js b/packages/svelte/src/compiler/phases/1-parse/acorn.js index dfc87d90af..ad23d47d6b 100644 --- a/packages/svelte/src/compiler/phases/1-parse/acorn.js +++ b/packages/svelte/src/compiler/phases/1-parse/acorn.js @@ -58,7 +58,6 @@ export function get_comment_handlers(source) { * @typedef {import('estree').Comment & { * start: number; * end: number; - * has_trailing_newline?: boolean * }} CommentWithLocation */ @@ -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())]; } } } - ); + }); } }; } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index 8bea4b1d24..207bc6faf0 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -1087,9 +1087,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 ` } ]; } @@ -1107,9 +1105,7 @@ function create_block(parent, name, nodes, context) { body[0].leadingComments = [ { type: 'Block', - value: ` Init `, - // @ts-expect-error - has_trailing_newline: true + value: ` Init ` } ]; } diff --git a/packages/svelte/src/compiler/phases/3-transform/index.js b/packages/svelte/src/compiler/phases/3-transform/index.js index 66459d60d6..af8de96d70 100644 --- a/packages/svelte/src/compiler/phases/3-transform/index.js +++ b/packages/svelte/src/compiler/phases/3-transform/index.js @@ -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!' } ]; } @@ -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} ` } ]; } diff --git a/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json b/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json index 9ec95cfaae..951cf05ff8 100644 --- a/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json +++ b/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json @@ -109,8 +109,7 @@ "type": "Block", "value": " another comment ", "start": 163, - "end": 184, - "has_trailing_newline": true + "end": 184 } ] } @@ -121,8 +120,7 @@ "type": "Line", "value": " comment", "start": 141, - "end": 151, - "has_trailing_newline": true + "end": 151 } ] } @@ -222,8 +220,7 @@ "type": "Line", "value": " a leading comment", "start": 10, - "end": 30, - "has_trailing_newline": true + "end": 30 } ], "trailingComments": [ @@ -290,8 +287,7 @@ "type": "Block", "value": "* a comment ", "start": 72, - "end": 88, - "has_trailing_newline": true + "end": 88 } ] }