update svelte2tsx

We can now use the typings from the Svelte library instead of the
svelte2tsx shims
This commit is contained in:
Damien Elmes 2021-09-25 10:06:37 +10:00
parent dc20300794
commit e660e0a3e5
3 changed files with 13 additions and 15 deletions

View File

@ -45,7 +45,7 @@
"svelte": "^3.25.0", "svelte": "^3.25.0",
"svelte-check": "^1.0.61", "svelte-check": "^1.0.61",
"svelte-preprocess": "^4.6.9", "svelte-preprocess": "^4.6.9",
"svelte2tsx": "^0.1.133", "svelte2tsx": "^0.4.6",
"tmp": "^0.2.1", "tmp": "^0.2.1",
"tslib": "^2.0.3", "tslib": "^2.0.3",
"typescript": "^4.4.0", "typescript": "^4.4.0",

View File

@ -2,10 +2,10 @@
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
// languageServerHost taken from MIT sources - see below. // languageServerHost taken from MIT sources - see below.
const fs = require("fs"); import * as fs from "fs";
const worker = require("@bazel/worker"); import * as worker from "@bazel/worker";
const svelte2tsx = require("svelte2tsx"); import { svelte2tsx } from "svelte2tsx";
const preprocess = require("svelte-preprocess"); import preprocess from "svelte-preprocess";
import { basename } from "path"; import { basename } from "path";
import * as ts from "typescript"; import * as ts from "typescript";
import * as svelte from "svelte/compiler.js"; import * as svelte from "svelte/compiler.js";
@ -132,13 +132,10 @@ async function writeDts(tsPath, dtsPath, tsLibs) {
function writeTs(svelteSource, sveltePath, tsPath): void { function writeTs(svelteSource, sveltePath, tsPath): void {
let tsSource = svelte2tsx(svelteSource, { let tsSource = svelte2tsx(svelteSource, {
filename: sveltePath, filename: sveltePath,
strictMode: true,
isTsFile: true, isTsFile: true,
mode: "dts",
}); });
let codeLines = tsSource.code.split("\n"); let codeLines = tsSource.code.split("\n");
// replace the "///<reference types="svelte" />" with a line
// turning off checking, as we'll use svelte-check for that
codeLines[0] = "// @ts-nocheck";
updateFileContent(tsPath, codeLines.join("\n")); updateFileContent(tsPath, codeLines.join("\n"));
} }
@ -164,10 +161,11 @@ async function writeJs(
], ],
}, },
}); });
preprocessOptions.filename = inputFilename;
try { try {
const processed = await svelte.preprocess(source, preprocessOptions); const processed = await svelte.preprocess(source, preprocessOptions, {
filename: inputFilename,
});
const result = svelte.compile(processed.toString!(), { const result = svelte.compile(processed.toString!(), {
format: "esm", format: "esm",
css: false, css: false,

View File

@ -4306,10 +4306,10 @@ svelte-preprocess@^4.0.0, svelte-preprocess@^4.6.9:
sorcery "^0.10.0" sorcery "^0.10.0"
strip-indent "^3.0.0" strip-indent "^3.0.0"
svelte2tsx@^0.1.133: svelte2tsx@^0.4.6:
version "0.1.193" version "0.4.6"
resolved "https://registry.yarnpkg.com/svelte2tsx/-/svelte2tsx-0.1.193.tgz#16fe594898ef455e4f715ac317d219c9c757656b" resolved "https://registry.yarnpkg.com/svelte2tsx/-/svelte2tsx-0.4.6.tgz#3435064962c910c0a075b4a1c04e91eaf568f5e5"
integrity sha512-vzy4YQNYDnoqp2iZPnJy7kpPAY6y121L0HKrSBjU/IWW7DQ6T7RMJed2VVHFmVYm0zAGYMDl9urPc6R4DDUyhg== integrity sha512-flljgh/MbJDijo6Z1HhCfyzdRgn1Nd7QTuuxk9Oq5CzyBXZl/NJYh4otZZwUHnx5poy8k7Oxr2CBE3IBh89tmQ==
dependencies: dependencies:
dedent-js "^1.0.1" dedent-js "^1.0.1"
pascal-case "^3.1.1" pascal-case "^3.1.1"