Skip to content

Commit

Permalink
chore: replace deprecated property access in preparation for TS 5.0 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Mar 8, 2023
1 parent 66b2f4e commit 18d7e81
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-goats-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

chore: replace deprecated property access in preparation for TS 5.0
5 changes: 4 additions & 1 deletion packages/kit/src/core/sync/write_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ export function tweak_types(content, is_server) {
});
}

if (node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
if (
ts.canHaveModifiers(node) &&
ts.getModifiers(node)?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)
) {
if (ts.isFunctionDeclaration(node) && node.name?.text && names.has(node.name?.text)) {
exports.set(node.name.text, node.name.text);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/migrate/migrations/routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ export function get_exports(node) {
} else if (
ts.isFunctionDeclaration(statement) &&
statement.name &&
statement.modifiers?.[0]?.kind === ts.SyntaxKind.ExportKeyword
ts.getModifiers(statement)?.[0]?.kind === ts.SyntaxKind.ExportKeyword
) {
// export function x ...
map.set(statement.name.text, statement.name.text);
} else if (
ts.isVariableStatement(statement) &&
statement.modifiers?.[0]?.kind === ts.SyntaxKind.ExportKeyword
ts.getModifiers(statement)?.[0]?.kind === ts.SyntaxKind.ExportKeyword
) {
// export const x = ..., y = ...
for (const declaration of statement.declarationList.declarations) {
Expand Down
20 changes: 12 additions & 8 deletions sites/kit.svelte.dev/src/lib/docs/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,18 @@ function convert_to_ts(js_code, indent = '', offset = '') {
const [name, generics] = get_type_info(tag);

if (ts.isFunctionDeclaration(node)) {
const is_export = node.modifiers?.some(
(modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword
)
? 'export '
: '';
const is_async = node.modifiers?.some(
(modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword
);
const is_export =
ts.canHaveModifiers(node) &&
ts
.getModifiers(node)
?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)
? 'export '
: '';
const is_async =
ts.canHaveModifiers(node) &&
ts
.getModifiers(node)
?.some((modifier) => modifier.kind === ts.SyntaxKind.AsyncKeyword);
code.overwrite(
node.getStart(),
node.name.getEnd(),
Expand Down

0 comments on commit 18d7e81

Please sign in to comment.