Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sveltejs/language-tools i…
Browse files Browse the repository at this point in the history
…nto ts-5_7
  • Loading branch information
jasonlyu123 committed Nov 30, 2024
2 parents 7f5cd38 + 89cc22b commit c3457c9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1755,20 +1755,9 @@ describe('CodeActionsProvider', function () {
line: 1
}
}
},
{
newText: "import { } from './somepng.png';\n",
range: {
end: {
character: 0,
line: 4
},
start: {
character: 4,
line: 3
}
}
}
// Because the generated code adds a ; after the last import, the
// second import is not appearing in the edits here
],
textDocument: {
uri: getUri('organize-imports-leading-comment.svelte'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export function handleFirstInstanceImport(
hasModuleScript: boolean,
str: MagicString
) {
const firstImport = tsAst.statements
.filter(ts.isImportDeclaration)
.sort((a, b) => a.end - b.end)[0];
const imports = tsAst.statements.filter(ts.isImportDeclaration).sort((a, b) => a.end - b.end);
const firstImport = imports[0];
if (!firstImport) {
return;
}
Expand All @@ -42,4 +41,12 @@ export function handleFirstInstanceImport(
: firstImport.getStart();

str.appendRight(start + astOffset, '\n' + (hasModuleScript ? '\n' : ''));

// Add a semi-colon to the last import if it doesn't have one, to prevent auto completion
// and imports from being added at the wrong position
const lastImport = imports[imports.length - 1];
const end = lastImport.end + astOffset - 1;
if (str.original[end] !== ';') {
str.overwrite(end, lastImport.end + astOffset, str.original[end] + ';\n');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
;
import { a as b } from "./test.svelte"

import * as c from "b.ts"
import * as c from "b.ts";
function render() {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
;// non-leading comment
/**@typedef {{ a: string }} Foo */

import ''
import '';
function render() {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
interface Dependency {
a: number;
b: typeof value;
};;type $$ComponentProps = { a: Dependency, b: string };function render() {
};
;type $$ComponentProps = { a: Dependency, b: string };function render() {



Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
///<reference types="svelte" />
;;type $$ComponentProps = { a: number, b: string };function render() {
;
;type $$ComponentProps = { a: number, b: string };function render() {

let { a, b }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props();
let x = $state(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
///<reference types="svelte" />
;;type $$ComponentProps = {form: boolean, data: true };function render() {
;
;type $$ComponentProps = {form: boolean, data: true };function render() {

const snapshot: any = {};
let { form, data }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props();
Expand Down

0 comments on commit c3457c9

Please sign in to comment.