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: replace deprecated property access in preparation for TS 5.0 #9361

Merged
merged 1 commit into from
Mar 8, 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/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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why you checked ts.canHaveModifiers in the other two files but not this one

Copy link
Member Author

@dummdidumm dummdidumm Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the statement node already is marked as being able to have modifiers through its type.

) {
// 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