typescript-svelte-plugin 0.3.17 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.js +36 -3
- package/dist/src/language-service/completions.d.ts +2 -2
- package/dist/src/language-service/completions.js +99 -25
- package/dist/src/language-service/definition.d.ts +3 -1
- package/dist/src/language-service/definition.js +20 -2
- package/dist/src/language-service/diagnostics.d.ts +1 -1
- package/dist/src/language-service/diagnostics.js +53 -10
- package/dist/src/language-service/hover.d.ts +5 -0
- package/dist/src/language-service/hover.js +35 -0
- package/dist/src/language-service/index.d.ts +1 -1
- package/dist/src/language-service/index.js +8 -6
- package/dist/src/language-service/sveltekit.d.ts +135 -0
- package/dist/src/language-service/sveltekit.js +567 -0
- package/dist/src/module-loader.js +2 -2
- package/dist/src/source-mapper.js +1 -1
- package/dist/src/utils.d.ts +9 -0
- package/dist/src/utils.js +43 -1
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const project_svelte_files_1 = require("./project-svelte-files");
|
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
function init(modules) {
|
|
11
11
|
const configManager = new config_manager_1.ConfigManager();
|
|
12
|
+
let resolvedSvelteTsxFiles;
|
|
12
13
|
function create(info) {
|
|
13
14
|
var _a, _b, _c, _d;
|
|
14
15
|
const logger = new logger_1.Logger(info.project.projectService.logger);
|
|
@@ -86,7 +87,7 @@ function init(modules) {
|
|
|
86
87
|
info.project.updateGraph();
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
|
-
return decorateLanguageServiceDispose((0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger, configManager, modules.typescript), projectSvelteFilesManager !== null && projectSvelteFilesManager !== void 0 ? projectSvelteFilesManager : {
|
|
90
|
+
return decorateLanguageServiceDispose((0, language_service_1.decorateLanguageService)(info.languageService, snapshotManager, logger, configManager, info, modules.typescript), projectSvelteFilesManager !== null && projectSvelteFilesManager !== void 0 ? projectSvelteFilesManager : {
|
|
90
91
|
dispose() { }
|
|
91
92
|
});
|
|
92
93
|
}
|
|
@@ -96,14 +97,27 @@ function init(modules) {
|
|
|
96
97
|
return [];
|
|
97
98
|
}
|
|
98
99
|
// Needed so the ambient definitions are known inside the tsx files
|
|
100
|
+
const svelteTsxFiles = resolveSvelteTsxFiles();
|
|
101
|
+
if (!project.getCompilerOptions().configFilePath) {
|
|
102
|
+
svelteTsxFiles.forEach((file) => {
|
|
103
|
+
openSvelteTsxFileForInferredProject(project, file);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// let ts know project svelte files to do its optimization
|
|
107
|
+
return svelteTsxFiles.concat((_b = (_a = project_svelte_files_1.ProjectSvelteFilesManager.getInstance(project.getProjectName())) === null || _a === void 0 ? void 0 : _a.getFiles()) !== null && _b !== void 0 ? _b : []);
|
|
108
|
+
}
|
|
109
|
+
function resolveSvelteTsxFiles() {
|
|
110
|
+
if (resolvedSvelteTsxFiles) {
|
|
111
|
+
return resolvedSvelteTsxFiles;
|
|
112
|
+
}
|
|
99
113
|
const svelteTsPath = (0, path_1.dirname)(require.resolve('svelte2tsx'));
|
|
100
114
|
const svelteTsxFiles = [
|
|
101
115
|
'./svelte-shims.d.ts',
|
|
102
116
|
'./svelte-jsx.d.ts',
|
|
103
117
|
'./svelte-native-jsx.d.ts'
|
|
104
118
|
].map((f) => modules.typescript.sys.resolvePath((0, path_1.resolve)(svelteTsPath, f)));
|
|
105
|
-
|
|
106
|
-
return svelteTsxFiles
|
|
119
|
+
resolvedSvelteTsxFiles = svelteTsxFiles;
|
|
120
|
+
return svelteTsxFiles;
|
|
107
121
|
}
|
|
108
122
|
function isSvelteProject(compilerOptions) {
|
|
109
123
|
// Add more checks like "no Svelte file found" or "no config file found"?
|
|
@@ -128,6 +142,25 @@ function init(modules) {
|
|
|
128
142
|
};
|
|
129
143
|
return languageService;
|
|
130
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* TypeScript doesn't load the external files in projects without a config file. So we load it by ourselves.
|
|
147
|
+
* TypeScript also seems to expect files added to the root to be opened by the client in this situation.
|
|
148
|
+
*/
|
|
149
|
+
function openSvelteTsxFileForInferredProject(project, file) {
|
|
150
|
+
const normalizedPath = modules.typescript.server.toNormalizedPath(file);
|
|
151
|
+
if (project.containsFile(normalizedPath)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const scriptInfo = project.projectService.getOrCreateScriptInfoForNormalizedPath(normalizedPath,
|
|
155
|
+
/*openedByClient*/ true, project.readFile(file));
|
|
156
|
+
if (!scriptInfo) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!project.projectService.openFiles.has(scriptInfo.path)) {
|
|
160
|
+
project.projectService.openFiles.set(scriptInfo.path, undefined);
|
|
161
|
+
}
|
|
162
|
+
project.addRoot(scriptInfo);
|
|
163
|
+
}
|
|
131
164
|
return { create, getExternalFiles, onConfigurationChanged };
|
|
132
165
|
}
|
|
133
166
|
module.exports = init;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type ts from 'typescript';
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { Logger } from '../logger';
|
|
3
3
|
type _ts = typeof ts;
|
|
4
|
-
export declare function decorateCompletions(ls: ts.LanguageService, ts: _ts, logger: Logger): void;
|
|
4
|
+
export declare function decorateCompletions(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, ts: _ts, logger: Logger): void;
|
|
5
5
|
export {};
|
|
@@ -3,20 +3,65 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.decorateCompletions = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
7
|
const componentPostfix = '__SvelteComponent_';
|
|
7
|
-
function decorateCompletions(ls, ts, logger) {
|
|
8
|
+
function decorateCompletions(ls, info, ts, logger) {
|
|
8
9
|
const getCompletionsAtPosition = ls.getCompletionsAtPosition;
|
|
9
|
-
ls.getCompletionsAtPosition = (fileName, position, options) => {
|
|
10
|
-
var _a, _b, _c, _d;
|
|
11
|
-
|
|
10
|
+
ls.getCompletionsAtPosition = (fileName, position, options, settings) => {
|
|
11
|
+
var _a, _b, _c, _d, _e;
|
|
12
|
+
let completions;
|
|
13
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
14
|
+
if (result) {
|
|
15
|
+
const { languageService, toVirtualPos, toOriginalPos } = result;
|
|
16
|
+
completions = languageService.getCompletionsAtPosition(fileName, toVirtualPos(position), options, settings);
|
|
17
|
+
if (completions) {
|
|
18
|
+
completions.entries = completions.entries.map((c) => {
|
|
19
|
+
if (c.replacementSpan) {
|
|
20
|
+
return {
|
|
21
|
+
...c,
|
|
22
|
+
replacementSpan: {
|
|
23
|
+
...c.replacementSpan,
|
|
24
|
+
start: toOriginalPos(c.replacementSpan.start).pos
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return c;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
completions =
|
|
33
|
+
completions !== null && completions !== void 0 ? completions : getCompletionsAtPosition(fileName, position, options, settings);
|
|
12
34
|
if (!completions) {
|
|
35
|
+
// No completions hints at a top level export in the making
|
|
36
|
+
const source = (_a = ls.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
37
|
+
const node = source && (0, utils_1.findNodeAtPosition)(source, position);
|
|
38
|
+
if (node && (0, utils_1.isTopLevelExport)(ts, node, source)) {
|
|
39
|
+
return {
|
|
40
|
+
entries: Object.entries(sveltekit_1.kitExports).map(([key, value]) => ({
|
|
41
|
+
kind: ts.ScriptElementKind.constElement,
|
|
42
|
+
name: key,
|
|
43
|
+
labelDetails: {
|
|
44
|
+
description: value.documentation.map((d) => d.text).join('')
|
|
45
|
+
},
|
|
46
|
+
sortText: '0',
|
|
47
|
+
data: {
|
|
48
|
+
__sveltekit: key,
|
|
49
|
+
exportName: key // TS needs this
|
|
50
|
+
}
|
|
51
|
+
})),
|
|
52
|
+
isGlobalCompletion: false,
|
|
53
|
+
isMemberCompletion: false,
|
|
54
|
+
isNewIdentifierLocation: false,
|
|
55
|
+
isIncomplete: true
|
|
56
|
+
};
|
|
57
|
+
}
|
|
13
58
|
return completions;
|
|
14
59
|
}
|
|
15
60
|
// Add ./$types imports for SvelteKit since TypeScript is bad at it
|
|
16
61
|
if ((0, path_1.basename)(fileName).startsWith('+')) {
|
|
17
62
|
const $typeImports = new Map();
|
|
18
63
|
for (const c of completions.entries) {
|
|
19
|
-
if (((
|
|
64
|
+
if (((_b = c.source) === null || _b === void 0 ? void 0 : _b.includes('.svelte-kit/types')) && c.data) {
|
|
20
65
|
$typeImports.set(c.name, c);
|
|
21
66
|
}
|
|
22
67
|
}
|
|
@@ -24,7 +69,7 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
24
69
|
// resolve path from FileName to svelte-kit/types
|
|
25
70
|
// src/routes/foo/+page.svelte -> .svelte-kit/types/foo/$types.d.ts
|
|
26
71
|
const routesFolder = 'src/routes'; // TODO somehow get access to kit.files.routes in here
|
|
27
|
-
const relativeFileName = (
|
|
72
|
+
const relativeFileName = (_c = fileName.split(routesFolder)[1]) === null || _c === void 0 ? void 0 : _c.slice(1);
|
|
28
73
|
if (relativeFileName) {
|
|
29
74
|
const relativePath = (0, path_1.dirname)(relativeFileName) === '.' ? '' : `${(0, path_1.dirname)(relativeFileName)}/`;
|
|
30
75
|
const modifiedSource = $typeImport.source.split('.svelte-kit/types')[0] +
|
|
@@ -39,28 +84,14 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
39
84
|
source: modifiedSource,
|
|
40
85
|
data: {
|
|
41
86
|
...$typeImport.data,
|
|
42
|
-
fileName: (
|
|
43
|
-
moduleSpecifier: (
|
|
87
|
+
fileName: (_d = $typeImport.data.fileName) === null || _d === void 0 ? void 0 : _d.replace($typeImport.source, modifiedSource),
|
|
88
|
+
moduleSpecifier: (_e = $typeImport.data.moduleSpecifier) === null || _e === void 0 ? void 0 : _e.replace($typeImport.source, modifiedSource),
|
|
44
89
|
__is_sveltekit$typeImport: true
|
|
45
90
|
}
|
|
46
91
|
});
|
|
47
92
|
}
|
|
48
93
|
}
|
|
49
94
|
}
|
|
50
|
-
if ((0, path_1.basename)(fileName).startsWith('+page') || (0, path_1.basename)(fileName).startsWith('+layout')) {
|
|
51
|
-
if ((0, path_1.extname)(fileName) === '.js') {
|
|
52
|
-
completions.entries.push({
|
|
53
|
-
// TODO doesn't show up for "export" and "load" only at the bottom for "function"
|
|
54
|
-
kind: ts.ScriptElementKind.functionElement,
|
|
55
|
-
name: 'export function load() {}',
|
|
56
|
-
sortText: '-99',
|
|
57
|
-
kindModifiers: ts.ScriptElementKindModifier.exportedModifier,
|
|
58
|
-
insertText: `/** @type {import('./$types').Foo} */\nexport function load() {}`
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
95
|
return {
|
|
65
96
|
...completions,
|
|
66
97
|
entries: completions.entries.map((entry) => {
|
|
@@ -77,12 +108,46 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
77
108
|
};
|
|
78
109
|
const getCompletionEntryDetails = ls.getCompletionEntryDetails;
|
|
79
110
|
ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => {
|
|
80
|
-
var _a;
|
|
111
|
+
var _a, _b;
|
|
112
|
+
if (data === null || data === void 0 ? void 0 : data.__sveltekit) {
|
|
113
|
+
const key = data === null || data === void 0 ? void 0 : data.__sveltekit;
|
|
114
|
+
return {
|
|
115
|
+
name: key,
|
|
116
|
+
kind: ts.ScriptElementKind.constElement,
|
|
117
|
+
kindModifiers: ts.ScriptElementKindModifier.none,
|
|
118
|
+
displayParts: sveltekit_1.kitExports[key].displayParts,
|
|
119
|
+
documentation: sveltekit_1.kitExports[key].documentation
|
|
120
|
+
};
|
|
121
|
+
}
|
|
81
122
|
const is$typeImport = data === null || data === void 0 ? void 0 : data.__is_sveltekit$typeImport;
|
|
82
|
-
|
|
123
|
+
let details;
|
|
124
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
125
|
+
if (result) {
|
|
126
|
+
const { languageService, toVirtualPos, toOriginalPos } = result;
|
|
127
|
+
details = languageService.getCompletionEntryDetails(fileName, toVirtualPos(position), entryName, formatOptions, source, preferences, data);
|
|
128
|
+
if (details) {
|
|
129
|
+
details.codeActions = (_a = details.codeActions) === null || _a === void 0 ? void 0 : _a.map((codeAction) => {
|
|
130
|
+
codeAction.changes = codeAction.changes.map((change) => {
|
|
131
|
+
change.textChanges = change.textChanges.map((textChange) => {
|
|
132
|
+
return {
|
|
133
|
+
...textChange,
|
|
134
|
+
span: {
|
|
135
|
+
...textChange.span,
|
|
136
|
+
start: toOriginalPos(textChange.span.start).pos
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
return change;
|
|
141
|
+
});
|
|
142
|
+
return codeAction;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
details =
|
|
147
|
+
details !== null && details !== void 0 ? details : getCompletionEntryDetails(fileName, position, entryName, formatOptions, source, preferences, data);
|
|
83
148
|
if (details) {
|
|
84
149
|
if (is$typeImport) {
|
|
85
|
-
details.codeActions = (
|
|
150
|
+
details.codeActions = (_b = details.codeActions) === null || _b === void 0 ? void 0 : _b.map((codeAction) => {
|
|
86
151
|
codeAction.description = adjustPath(codeAction.description);
|
|
87
152
|
codeAction.changes = codeAction.changes.map((change) => {
|
|
88
153
|
change.textChanges = change.textChanges.map((textChange) => {
|
|
@@ -116,6 +181,15 @@ function decorateCompletions(ls, ts, logger) {
|
|
|
116
181
|
logger.debug('Found Svelte Component import completion details');
|
|
117
182
|
return (0, utils_1.replaceDeep)(svelteDetails, componentPostfix, '');
|
|
118
183
|
};
|
|
184
|
+
const getSignatureHelpItems = ls.getSignatureHelpItems;
|
|
185
|
+
ls.getSignatureHelpItems = (fileName, position, options) => {
|
|
186
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
187
|
+
if (result) {
|
|
188
|
+
const { languageService, toVirtualPos } = result;
|
|
189
|
+
return languageService.getSignatureHelpItems(fileName, toVirtualPos(position), options);
|
|
190
|
+
}
|
|
191
|
+
return getSignatureHelpItems(fileName, position, options);
|
|
192
|
+
};
|
|
119
193
|
}
|
|
120
194
|
exports.decorateCompletions = decorateCompletions;
|
|
121
195
|
function adjustPath(path) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { Logger } from '../logger';
|
|
3
3
|
import { SvelteSnapshotManager } from '../svelte-snapshots';
|
|
4
|
-
|
|
4
|
+
type _ts = typeof ts;
|
|
5
|
+
export declare function decorateGetDefinition(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, ts: _ts, snapshotManager: SvelteSnapshotManager, logger: Logger): void;
|
|
6
|
+
export {};
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorateGetDefinition = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
5
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
|
+
function decorateGetDefinition(ls, info, ts, snapshotManager, logger) {
|
|
6
7
|
const getDefinitionAndBoundSpan = ls.getDefinitionAndBoundSpan;
|
|
7
8
|
ls.getDefinitionAndBoundSpan = (fileName, position) => {
|
|
8
9
|
const definition = getDefinitionAndBoundSpan(fileName, position);
|
|
9
10
|
if (!(definition === null || definition === void 0 ? void 0 : definition.definitions)) {
|
|
10
|
-
return
|
|
11
|
+
return getKitDefinitions(ts, info, fileName, position);
|
|
11
12
|
}
|
|
12
13
|
return {
|
|
13
14
|
...definition,
|
|
@@ -38,4 +39,21 @@ function decorateGetDefinition(ls, snapshotManager, logger) {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
exports.decorateGetDefinition = decorateGetDefinition;
|
|
42
|
+
function getKitDefinitions(ts, info, fileName, position) {
|
|
43
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
44
|
+
if (!result)
|
|
45
|
+
return;
|
|
46
|
+
const { languageService, toOriginalPos, toVirtualPos } = result;
|
|
47
|
+
const virtualPos = toVirtualPos(position);
|
|
48
|
+
const definitions = languageService.getDefinitionAndBoundSpan(fileName, virtualPos);
|
|
49
|
+
if (!definitions)
|
|
50
|
+
return;
|
|
51
|
+
// Assumption: This is only called when the original definitions didn't turn up anything.
|
|
52
|
+
// Therefore we are called on things like export function load ({ fetch }) .
|
|
53
|
+
// This means the textSpan needs conversion but none of the definitions because they are all referencing other files.
|
|
54
|
+
return {
|
|
55
|
+
...definitions,
|
|
56
|
+
textSpan: { ...definitions.textSpan, start: toOriginalPos(definitions.textSpan.start).pos }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
41
59
|
//# sourceMappingURL=definition.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { Logger } from '../logger';
|
|
3
|
-
export declare function decorateDiagnostics(ls: ts.LanguageService, logger: Logger): void;
|
|
3
|
+
export declare function decorateDiagnostics(ls: ts.LanguageService, info: ts.server.PluginCreateInfo, typescript: typeof ts, logger: Logger): void;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decorateDiagnostics = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
|
+
function decorateDiagnostics(ls, info, typescript, logger) {
|
|
7
|
+
decorateSyntacticDiagnostics(ls, info, typescript, logger);
|
|
8
|
+
decorateSemanticDiagnostics(ls, info, typescript, logger);
|
|
9
|
+
decorateSuggestionDiagnostics(ls, info, typescript, logger);
|
|
9
10
|
}
|
|
10
11
|
exports.decorateDiagnostics = decorateDiagnostics;
|
|
11
|
-
function decorateSyntacticDiagnostics(ls) {
|
|
12
|
+
function decorateSyntacticDiagnostics(ls, info, typescript, logger) {
|
|
12
13
|
const getSyntacticDiagnostics = ls.getSyntacticDiagnostics;
|
|
13
14
|
ls.getSyntacticDiagnostics = (fileName) => {
|
|
14
15
|
// Diagnostics inside Svelte files are done
|
|
@@ -16,10 +17,11 @@ function decorateSyntacticDiagnostics(ls) {
|
|
|
16
17
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
17
18
|
return [];
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
const kitDiagnostics = getKitDiagnostics('getSyntacticDiagnostics', fileName, info, typescript, logger);
|
|
21
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSyntacticDiagnostics(fileName);
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
function decorateSemanticDiagnostics(ls) {
|
|
24
|
+
function decorateSemanticDiagnostics(ls, info, typescript, logger) {
|
|
23
25
|
const getSemanticDiagnostics = ls.getSemanticDiagnostics;
|
|
24
26
|
ls.getSemanticDiagnostics = (fileName) => {
|
|
25
27
|
// Diagnostics inside Svelte files are done
|
|
@@ -27,10 +29,11 @@ function decorateSemanticDiagnostics(ls) {
|
|
|
27
29
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
28
30
|
return [];
|
|
29
31
|
}
|
|
30
|
-
|
|
32
|
+
const kitDiagnostics = getKitDiagnostics('getSemanticDiagnostics', fileName, info, typescript, logger);
|
|
33
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSemanticDiagnostics(fileName);
|
|
31
34
|
};
|
|
32
35
|
}
|
|
33
|
-
function decorateSuggestionDiagnostics(ls) {
|
|
36
|
+
function decorateSuggestionDiagnostics(ls, info, typescript, logger) {
|
|
34
37
|
const getSuggestionDiagnostics = ls.getSuggestionDiagnostics;
|
|
35
38
|
ls.getSuggestionDiagnostics = (fileName) => {
|
|
36
39
|
// Diagnostics inside Svelte files are done
|
|
@@ -38,7 +41,47 @@ function decorateSuggestionDiagnostics(ls) {
|
|
|
38
41
|
if ((0, utils_1.isSvelteFilePath)(fileName)) {
|
|
39
42
|
return [];
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
const kitDiagnostics = getKitDiagnostics('getSuggestionDiagnostics', fileName, info, typescript, logger);
|
|
45
|
+
return kitDiagnostics !== null && kitDiagnostics !== void 0 ? kitDiagnostics : getSuggestionDiagnostics(fileName);
|
|
42
46
|
};
|
|
43
47
|
}
|
|
48
|
+
function getKitDiagnostics(methodName, fileName, info, ts, logger) {
|
|
49
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts, logger);
|
|
50
|
+
if (!result)
|
|
51
|
+
return;
|
|
52
|
+
const { languageService, toOriginalPos } = result;
|
|
53
|
+
const diagnostics = [];
|
|
54
|
+
for (let diagnostic of languageService[methodName](fileName)) {
|
|
55
|
+
if (!diagnostic.start || !diagnostic.length) {
|
|
56
|
+
diagnostics.push(diagnostic);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const mapped = toOriginalPos(diagnostic.start);
|
|
60
|
+
if (mapped.inGenerated) {
|
|
61
|
+
// If not "Cannot find module './$types' .." then filter out
|
|
62
|
+
if (diagnostic.code !== 2307) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
diagnostic = {
|
|
67
|
+
...diagnostic,
|
|
68
|
+
// adjust length so it doesn't spill over to the next line
|
|
69
|
+
length: 1,
|
|
70
|
+
messageText: typeof diagnostic.messageText === 'string' &&
|
|
71
|
+
diagnostic.messageText.includes('./$types')
|
|
72
|
+
? diagnostic.messageText +
|
|
73
|
+
` (this likely means that SvelteKit's type generation didn't run yet)`
|
|
74
|
+
: diagnostic.messageText
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
diagnostic = {
|
|
79
|
+
...diagnostic,
|
|
80
|
+
start: mapped.pos
|
|
81
|
+
};
|
|
82
|
+
diagnostics.push(diagnostic);
|
|
83
|
+
}
|
|
84
|
+
// @ts-ignore TS doesn't get the return type right
|
|
85
|
+
return diagnostics;
|
|
86
|
+
}
|
|
44
87
|
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorateHover = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const sveltekit_1 = require("./sveltekit");
|
|
6
|
+
function decorateHover(ls, info, ts, logger) {
|
|
7
|
+
const getQuickInfoAtPosition = ls.getQuickInfoAtPosition;
|
|
8
|
+
ls.getQuickInfoAtPosition = (fileName, position) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const result = (0, sveltekit_1.getVirtualLS)(fileName, info, ts);
|
|
11
|
+
if (!result)
|
|
12
|
+
return getQuickInfoAtPosition(fileName, position);
|
|
13
|
+
const { languageService, toOriginalPos, toVirtualPos } = result;
|
|
14
|
+
const virtualPos = toVirtualPos(position);
|
|
15
|
+
const quickInfo = languageService.getQuickInfoAtPosition(fileName, virtualPos);
|
|
16
|
+
if (!quickInfo)
|
|
17
|
+
return quickInfo;
|
|
18
|
+
const source = (_a = languageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
19
|
+
const node = source && (0, utils_1.findNodeAtPosition)(source, virtualPos);
|
|
20
|
+
if (node && (0, utils_1.isTopLevelExport)(ts, node, source) && ts.isIdentifier(node)) {
|
|
21
|
+
const name = node.text;
|
|
22
|
+
if (name in sveltekit_1.kitExports) {
|
|
23
|
+
quickInfo.documentation = !((_b = quickInfo.documentation) === null || _b === void 0 ? void 0 : _b.length)
|
|
24
|
+
? sveltekit_1.kitExports[name].documentation
|
|
25
|
+
: quickInfo.documentation;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
...quickInfo,
|
|
30
|
+
textSpan: { ...quickInfo.textSpan, start: toOriginalPos(quickInfo.textSpan.start).pos }
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.decorateHover = decorateHover;
|
|
35
|
+
//# sourceMappingURL=hover.js.map
|
|
@@ -3,4 +3,4 @@ import { ConfigManager } from '../config-manager';
|
|
|
3
3
|
import { Logger } from '../logger';
|
|
4
4
|
import { SvelteSnapshotManager } from '../svelte-snapshots';
|
|
5
5
|
export declare function isPatched(ls: ts.LanguageService): boolean;
|
|
6
|
-
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, typescript: typeof ts): ts.LanguageService;
|
|
6
|
+
export declare function decorateLanguageService(ls: ts.LanguageService, snapshotManager: SvelteSnapshotManager, logger: Logger, configManager: ConfigManager, info: ts.server.PluginCreateInfo, typescript: typeof ts): ts.LanguageService;
|
|
@@ -7,6 +7,7 @@ const completions_1 = require("./completions");
|
|
|
7
7
|
const definition_1 = require("./definition");
|
|
8
8
|
const diagnostics_1 = require("./diagnostics");
|
|
9
9
|
const find_references_1 = require("./find-references");
|
|
10
|
+
const hover_1 = require("./hover");
|
|
10
11
|
const implementation_1 = require("./implementation");
|
|
11
12
|
const rename_1 = require("./rename");
|
|
12
13
|
const update_imports_1 = require("./update-imports");
|
|
@@ -15,24 +16,25 @@ function isPatched(ls) {
|
|
|
15
16
|
return ls[sveltePluginPatchSymbol] === true;
|
|
16
17
|
}
|
|
17
18
|
exports.isPatched = isPatched;
|
|
18
|
-
function decorateLanguageService(ls, snapshotManager, logger, configManager, typescript) {
|
|
19
|
+
function decorateLanguageService(ls, snapshotManager, logger, configManager, info, typescript) {
|
|
19
20
|
// Decorate using a proxy so we can dynamically enable/disable method
|
|
20
21
|
// patches depending on the enabled state of our config
|
|
21
22
|
const proxy = new Proxy(ls, createProxyHandler(configManager));
|
|
22
|
-
decorateLanguageServiceInner(proxy, snapshotManager, logger, typescript);
|
|
23
|
+
decorateLanguageServiceInner(proxy, snapshotManager, logger, info, typescript);
|
|
23
24
|
return proxy;
|
|
24
25
|
}
|
|
25
26
|
exports.decorateLanguageService = decorateLanguageService;
|
|
26
|
-
function decorateLanguageServiceInner(ls, snapshotManager, logger, typescript) {
|
|
27
|
+
function decorateLanguageServiceInner(ls, snapshotManager, logger, info, typescript) {
|
|
27
28
|
patchLineColumnOffset(ls, snapshotManager);
|
|
28
29
|
(0, rename_1.decorateRename)(ls, snapshotManager, logger);
|
|
29
|
-
(0, diagnostics_1.decorateDiagnostics)(ls, logger);
|
|
30
|
+
(0, diagnostics_1.decorateDiagnostics)(ls, info, typescript, logger);
|
|
30
31
|
(0, find_references_1.decorateFindReferences)(ls, snapshotManager, logger);
|
|
31
|
-
(0, completions_1.decorateCompletions)(ls, typescript, logger);
|
|
32
|
-
(0, definition_1.decorateGetDefinition)(ls, snapshotManager, logger);
|
|
32
|
+
(0, completions_1.decorateCompletions)(ls, info, typescript, logger);
|
|
33
|
+
(0, definition_1.decorateGetDefinition)(ls, info, typescript, snapshotManager, logger);
|
|
33
34
|
(0, implementation_1.decorateGetImplementation)(ls, snapshotManager, logger);
|
|
34
35
|
(0, update_imports_1.decorateUpdateImports)(ls, snapshotManager, logger);
|
|
35
36
|
(0, call_hierarchy_1.decorateCallHierarchy)(ls, snapshotManager, typescript);
|
|
37
|
+
(0, hover_1.decorateHover)(ls, info, typescript, logger);
|
|
36
38
|
return ls;
|
|
37
39
|
}
|
|
38
40
|
function createProxyHandler(configManager) {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import { Logger } from '../logger';
|
|
3
|
+
type _ts = typeof ts;
|
|
4
|
+
interface KitSnapshot {
|
|
5
|
+
file: ts.IScriptSnapshot;
|
|
6
|
+
version: string;
|
|
7
|
+
addedCode: Array<{
|
|
8
|
+
generatedPos: number;
|
|
9
|
+
originalPos: number;
|
|
10
|
+
length: number;
|
|
11
|
+
total: number;
|
|
12
|
+
inserted: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export declare const kitExports: {
|
|
16
|
+
prerender: {
|
|
17
|
+
displayParts: {
|
|
18
|
+
text: string;
|
|
19
|
+
kind: string;
|
|
20
|
+
}[];
|
|
21
|
+
documentation: {
|
|
22
|
+
text: string;
|
|
23
|
+
kind: string;
|
|
24
|
+
}[];
|
|
25
|
+
};
|
|
26
|
+
ssr: {
|
|
27
|
+
displayParts: {
|
|
28
|
+
text: string;
|
|
29
|
+
kind: string;
|
|
30
|
+
}[];
|
|
31
|
+
documentation: {
|
|
32
|
+
text: string;
|
|
33
|
+
kind: string;
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
36
|
+
csr: {
|
|
37
|
+
displayParts: {
|
|
38
|
+
text: string;
|
|
39
|
+
kind: string;
|
|
40
|
+
}[];
|
|
41
|
+
documentation: {
|
|
42
|
+
text: string;
|
|
43
|
+
kind: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
trailingSlash: {
|
|
47
|
+
displayParts: {
|
|
48
|
+
text: string;
|
|
49
|
+
kind: string;
|
|
50
|
+
}[];
|
|
51
|
+
documentation: {
|
|
52
|
+
text: string;
|
|
53
|
+
kind: string;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
config: {
|
|
57
|
+
displayParts: {
|
|
58
|
+
text: string;
|
|
59
|
+
kind: string;
|
|
60
|
+
}[];
|
|
61
|
+
documentation: {
|
|
62
|
+
text: string;
|
|
63
|
+
kind: string;
|
|
64
|
+
}[];
|
|
65
|
+
};
|
|
66
|
+
actions: {
|
|
67
|
+
displayParts: {
|
|
68
|
+
text: string;
|
|
69
|
+
kind: string;
|
|
70
|
+
}[];
|
|
71
|
+
documentation: {
|
|
72
|
+
text: string;
|
|
73
|
+
kind: string;
|
|
74
|
+
}[];
|
|
75
|
+
};
|
|
76
|
+
load: {
|
|
77
|
+
displayParts: {
|
|
78
|
+
text: string;
|
|
79
|
+
kind: string;
|
|
80
|
+
}[];
|
|
81
|
+
documentation: {
|
|
82
|
+
text: string;
|
|
83
|
+
kind: string;
|
|
84
|
+
}[];
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export declare function getProxiedLanguageService(info: ts.server.PluginCreateInfo, ts: _ts, logger?: Logger): {
|
|
88
|
+
languageService: ts.LanguageService;
|
|
89
|
+
languageServiceHost: ts.LanguageServiceHost & {
|
|
90
|
+
getKitScriptSnapshotIfUpToDate: (fileName: string) => KitSnapshot | undefined;
|
|
91
|
+
upsertKitFile: (fileName: string) => void;
|
|
92
|
+
};
|
|
93
|
+
} | {
|
|
94
|
+
languageService: ts.LanguageService;
|
|
95
|
+
languageServiceHost: {
|
|
96
|
+
files: Record<string, KitSnapshot>;
|
|
97
|
+
log(): void;
|
|
98
|
+
trace(): void;
|
|
99
|
+
error(): void;
|
|
100
|
+
getCompilationSettings(): ts.CompilerOptions;
|
|
101
|
+
getScriptIsOpen(): boolean;
|
|
102
|
+
getCurrentDirectory(): string;
|
|
103
|
+
getDefaultLibFileName(o: any): string;
|
|
104
|
+
resolveModuleNames: ((...args: any[]) => (ts.ResolvedModule | undefined)[]) | undefined;
|
|
105
|
+
resolveModuleNameLiterals: ((...args: any[]) => readonly ts.ResolvedModuleWithFailedLookupLocations[]) | undefined;
|
|
106
|
+
getScriptVersion(fileName: string): string;
|
|
107
|
+
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined;
|
|
108
|
+
getScriptFileNames(): string[];
|
|
109
|
+
getKitScriptSnapshotIfUpToDate(fileName: string): KitSnapshot | undefined;
|
|
110
|
+
upsertKitFile(fileName: string): KitSnapshot | undefined;
|
|
111
|
+
readFile(fileName: string): string | undefined;
|
|
112
|
+
fileExists(fileName: string): boolean;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export declare function getVirtualLS(fileName: string, info: ts.server.PluginCreateInfo, ts: _ts, logger?: Logger): {
|
|
116
|
+
languageService: ts.LanguageService;
|
|
117
|
+
addedCode: {
|
|
118
|
+
generatedPos: number;
|
|
119
|
+
originalPos: number;
|
|
120
|
+
length: number;
|
|
121
|
+
total: number;
|
|
122
|
+
inserted: string;
|
|
123
|
+
}[];
|
|
124
|
+
toVirtualPos: (pos: number) => number;
|
|
125
|
+
toOriginalPos: (pos: number) => {
|
|
126
|
+
pos: number;
|
|
127
|
+
inGenerated: boolean;
|
|
128
|
+
};
|
|
129
|
+
} | undefined;
|
|
130
|
+
export declare function toVirtualPos(pos: number, addedCode: KitSnapshot['addedCode']): number;
|
|
131
|
+
export declare function toOriginalPos(pos: number, addedCode: KitSnapshot['addedCode']): {
|
|
132
|
+
pos: number;
|
|
133
|
+
inGenerated: boolean;
|
|
134
|
+
};
|
|
135
|
+
export {};
|
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toOriginalPos = exports.toVirtualPos = exports.getVirtualLS = exports.getProxiedLanguageService = exports.kitExports = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const cache = new WeakMap();
|
|
9
|
+
exports.kitExports = {
|
|
10
|
+
prerender: {
|
|
11
|
+
displayParts: [
|
|
12
|
+
{
|
|
13
|
+
text: 'const',
|
|
14
|
+
kind: 'keyword'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
text: ' ',
|
|
18
|
+
kind: 'space'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
text: 'prerender',
|
|
22
|
+
kind: 'localName'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
text: ': ',
|
|
26
|
+
kind: 'punctuation'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
text: 'boolean',
|
|
30
|
+
kind: 'keyword'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
text: ' | ',
|
|
34
|
+
kind: 'punctuation'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
text: "'auto'",
|
|
38
|
+
kind: 'stringLiteral'
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
documentation: [
|
|
42
|
+
{
|
|
43
|
+
text: 'Control whether or not this page is prerendered. More info: https://kit.svelte.dev/docs/page-options#prerender',
|
|
44
|
+
kind: 'text'
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
ssr: {
|
|
49
|
+
displayParts: [
|
|
50
|
+
{
|
|
51
|
+
text: 'const',
|
|
52
|
+
kind: 'keyword'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
text: ' ',
|
|
56
|
+
kind: 'space'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
text: 'ssr',
|
|
60
|
+
kind: 'localName'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
text: ': ',
|
|
64
|
+
kind: 'punctuation'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
text: 'boolean',
|
|
68
|
+
kind: 'keyword'
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
documentation: [
|
|
72
|
+
{
|
|
73
|
+
text: 'Control whether or not this page is server-side rendered. More info: https://kit.svelte.dev/docs/page-options#ssr',
|
|
74
|
+
kind: 'text'
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
csr: {
|
|
79
|
+
displayParts: [
|
|
80
|
+
{
|
|
81
|
+
text: 'const',
|
|
82
|
+
kind: 'keyword'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
text: ' ',
|
|
86
|
+
kind: 'space'
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
text: 'csr',
|
|
90
|
+
kind: 'localName'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
text: ': ',
|
|
94
|
+
kind: 'punctuation'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
text: 'boolean',
|
|
98
|
+
kind: 'keyword'
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
documentation: [
|
|
102
|
+
{
|
|
103
|
+
text: 'Control whether or not this page is hydrated (i.e. if JS is delivered to the client). More info: https://kit.svelte.dev/docs/page-options#csr',
|
|
104
|
+
kind: 'text'
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
trailingSlash: {
|
|
109
|
+
displayParts: [
|
|
110
|
+
{
|
|
111
|
+
text: 'const',
|
|
112
|
+
kind: 'keyword'
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
text: ' ',
|
|
116
|
+
kind: 'space'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
text: 'trailingSlash',
|
|
120
|
+
kind: 'localName'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
text: ': ',
|
|
124
|
+
kind: 'punctuation'
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
text: "'auto' | 'always' | 'never'",
|
|
128
|
+
kind: 'stringLiteral'
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
documentation: [
|
|
132
|
+
{
|
|
133
|
+
text: 'Control how SvelteKit should handle (missing) trailing slashes in the URL. More info: https://kit.svelte.dev/docs/page-options#trailingslash',
|
|
134
|
+
kind: 'text'
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
config: {
|
|
139
|
+
displayParts: [
|
|
140
|
+
{
|
|
141
|
+
text: 'const',
|
|
142
|
+
kind: 'keyword'
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
text: ' ',
|
|
146
|
+
kind: 'space'
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
text: 'config',
|
|
150
|
+
kind: 'localName'
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
text: ': ',
|
|
154
|
+
kind: 'punctuation'
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
text: 'Config',
|
|
158
|
+
kind: 'interfaceName'
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
documentation: [
|
|
162
|
+
{
|
|
163
|
+
text: `With the concept of adapters, SvelteKit is able to run on a variety of platforms. ` +
|
|
164
|
+
`Each of these might have specific configuration to further tweak the deployment, which you can configure here. ` +
|
|
165
|
+
`More info: https://kit.svelte.dev/docs/page-options#config`,
|
|
166
|
+
kind: 'text'
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
actions: {
|
|
171
|
+
displayParts: [
|
|
172
|
+
{
|
|
173
|
+
text: 'const',
|
|
174
|
+
kind: 'keyword'
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
text: ' ',
|
|
178
|
+
kind: 'space'
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
text: 'actions',
|
|
182
|
+
kind: 'localName'
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
text: ': ',
|
|
186
|
+
kind: 'punctuation'
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
text: 'Actions',
|
|
190
|
+
kind: 'interfaceName'
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
documentation: [
|
|
194
|
+
{
|
|
195
|
+
text: `An object of methods which handle form POST requests. ` +
|
|
196
|
+
`More info: https://kit.svelte.dev/docs/form-actions`,
|
|
197
|
+
kind: 'text'
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
},
|
|
201
|
+
load: {
|
|
202
|
+
displayParts: [
|
|
203
|
+
{
|
|
204
|
+
text: 'export',
|
|
205
|
+
kind: 'keyword'
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
text: ' ',
|
|
209
|
+
kind: 'space'
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
text: 'function',
|
|
213
|
+
kind: 'keyword'
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
text: ' ',
|
|
217
|
+
kind: 'space'
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
text: 'load',
|
|
221
|
+
kind: 'localName'
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
text: '(',
|
|
225
|
+
kind: 'punctuation'
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
text: 'event',
|
|
229
|
+
kind: 'parameterName'
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
text: ': ',
|
|
233
|
+
kind: 'punctuation'
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
text: 'LoadEvent',
|
|
237
|
+
kind: 'interfaceName'
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
text: ')',
|
|
241
|
+
kind: 'punctuation'
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
text: ': ',
|
|
245
|
+
kind: 'punctuation'
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
text: 'Promise',
|
|
249
|
+
kind: 'keyword'
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
text: '<',
|
|
253
|
+
kind: 'punctuation'
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
text: 'LoadOutput',
|
|
257
|
+
kind: 'interfaceName'
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
text: '>',
|
|
261
|
+
kind: 'punctuation'
|
|
262
|
+
}
|
|
263
|
+
],
|
|
264
|
+
documentation: [
|
|
265
|
+
{
|
|
266
|
+
text: 'Loads data for the given page or layout. More info: https://kit.svelte.dev/docs/load',
|
|
267
|
+
kind: 'text'
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
function getProxiedLanguageService(info, ts, logger) {
|
|
273
|
+
const cachedProxiedLanguageService = cache.get(info);
|
|
274
|
+
if (cachedProxiedLanguageService) {
|
|
275
|
+
return cachedProxiedLanguageService;
|
|
276
|
+
}
|
|
277
|
+
const originalLanguageServiceHost = info.languageServiceHost;
|
|
278
|
+
class ProxiedLanguageServiceHost {
|
|
279
|
+
constructor() {
|
|
280
|
+
this.files = {};
|
|
281
|
+
this.resolveModuleNames = originalLanguageServiceHost.resolveModuleNames
|
|
282
|
+
? (...args) => {
|
|
283
|
+
return originalLanguageServiceHost.resolveModuleNames(
|
|
284
|
+
// @ts-ignore
|
|
285
|
+
...args);
|
|
286
|
+
}
|
|
287
|
+
: undefined;
|
|
288
|
+
this.resolveModuleNameLiterals = originalLanguageServiceHost.resolveModuleNameLiterals
|
|
289
|
+
? (...args) => {
|
|
290
|
+
return originalLanguageServiceHost.resolveModuleNameLiterals(
|
|
291
|
+
// @ts-ignore
|
|
292
|
+
...args);
|
|
293
|
+
}
|
|
294
|
+
: undefined;
|
|
295
|
+
}
|
|
296
|
+
log() { }
|
|
297
|
+
trace() { }
|
|
298
|
+
error() { }
|
|
299
|
+
getCompilationSettings() {
|
|
300
|
+
return originalLanguageServiceHost.getCompilationSettings();
|
|
301
|
+
}
|
|
302
|
+
getScriptIsOpen() {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
getCurrentDirectory() {
|
|
306
|
+
return originalLanguageServiceHost.getCurrentDirectory();
|
|
307
|
+
}
|
|
308
|
+
getDefaultLibFileName(o) {
|
|
309
|
+
return originalLanguageServiceHost.getDefaultLibFileName(o);
|
|
310
|
+
}
|
|
311
|
+
getScriptVersion(fileName) {
|
|
312
|
+
const file = this.files[fileName];
|
|
313
|
+
if (!file)
|
|
314
|
+
return originalLanguageServiceHost.getScriptVersion(fileName);
|
|
315
|
+
return file.version.toString();
|
|
316
|
+
}
|
|
317
|
+
getScriptSnapshot(fileName) {
|
|
318
|
+
const file = this.files[fileName];
|
|
319
|
+
if (!file)
|
|
320
|
+
return originalLanguageServiceHost.getScriptSnapshot(fileName);
|
|
321
|
+
return file.file;
|
|
322
|
+
}
|
|
323
|
+
getScriptFileNames() {
|
|
324
|
+
const names = new Set(Object.keys(this.files));
|
|
325
|
+
const files = originalLanguageServiceHost.getScriptFileNames();
|
|
326
|
+
for (const file of files) {
|
|
327
|
+
names.add(file);
|
|
328
|
+
}
|
|
329
|
+
return [...names];
|
|
330
|
+
}
|
|
331
|
+
getKitScriptSnapshotIfUpToDate(fileName) {
|
|
332
|
+
if (!this.files[fileName] ||
|
|
333
|
+
this.getScriptVersion(fileName) !==
|
|
334
|
+
originalLanguageServiceHost.getScriptVersion(fileName)) {
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
return this.files[fileName];
|
|
338
|
+
}
|
|
339
|
+
upsertKitFile(fileName) {
|
|
340
|
+
var _a;
|
|
341
|
+
const basename = path_1.default.basename(fileName);
|
|
342
|
+
if (!kitPageFiles.has(basename))
|
|
343
|
+
return;
|
|
344
|
+
const source = (_a = info.languageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName);
|
|
345
|
+
if (!source)
|
|
346
|
+
return;
|
|
347
|
+
const addedCode = [];
|
|
348
|
+
const insert = (pos, inserted) => {
|
|
349
|
+
var _a, _b, _c, _d;
|
|
350
|
+
const insertionIdx = addedCode.findIndex((c) => c.generatedPos > pos);
|
|
351
|
+
if (insertionIdx >= 0) {
|
|
352
|
+
for (let i = insertionIdx; i < addedCode.length; i++) {
|
|
353
|
+
addedCode[i].generatedPos += inserted.length;
|
|
354
|
+
addedCode[i].total += inserted.length;
|
|
355
|
+
}
|
|
356
|
+
const prevTotal = (_b = (_a = addedCode[insertionIdx - 1]) === null || _a === void 0 ? void 0 : _a.total) !== null && _b !== void 0 ? _b : 0;
|
|
357
|
+
addedCode.splice(insertionIdx, 0, {
|
|
358
|
+
generatedPos: pos + prevTotal,
|
|
359
|
+
originalPos: pos,
|
|
360
|
+
length: inserted.length,
|
|
361
|
+
inserted,
|
|
362
|
+
total: prevTotal + inserted.length
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
const prevTotal = (_d = (_c = addedCode[addedCode.length - 1]) === null || _c === void 0 ? void 0 : _c.total) !== null && _d !== void 0 ? _d : 0;
|
|
367
|
+
addedCode.push({
|
|
368
|
+
generatedPos: pos + prevTotal,
|
|
369
|
+
originalPos: pos,
|
|
370
|
+
length: inserted.length,
|
|
371
|
+
inserted,
|
|
372
|
+
total: prevTotal + inserted.length
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const isTsFile = basename.endsWith('.ts');
|
|
377
|
+
const exports = findExports(ts, source, isTsFile);
|
|
378
|
+
// add type to load function if not explicitly typed
|
|
379
|
+
const load = exports.get('load');
|
|
380
|
+
if ((load === null || load === void 0 ? void 0 : load.type) === 'function' &&
|
|
381
|
+
load.node.parameters.length === 1 &&
|
|
382
|
+
!load.hasTypeDefinition) {
|
|
383
|
+
const pos = load.node.parameters[0].getEnd();
|
|
384
|
+
const inserted = `: import('./$types').${basename.includes('layout') ? 'Layout' : 'Page'}${basename.includes('server') ? 'Server' : ''}LoadEvent`;
|
|
385
|
+
insert(pos, inserted);
|
|
386
|
+
}
|
|
387
|
+
// add type to actions variable if not explicitly typed
|
|
388
|
+
const actions = exports.get('actions');
|
|
389
|
+
if ((actions === null || actions === void 0 ? void 0 : actions.type) === 'var' && !actions.hasTypeDefinition && actions.node.initializer) {
|
|
390
|
+
const pos = actions.node.initializer.getEnd();
|
|
391
|
+
const inserted = ` satisfies import('./$types').Actions`;
|
|
392
|
+
insert(pos, inserted);
|
|
393
|
+
}
|
|
394
|
+
// add type to prerender variable if not explicitly typed
|
|
395
|
+
const prerender = exports.get('prerender');
|
|
396
|
+
if ((prerender === null || prerender === void 0 ? void 0 : prerender.type) === 'var' &&
|
|
397
|
+
!prerender.hasTypeDefinition &&
|
|
398
|
+
prerender.node.initializer) {
|
|
399
|
+
const pos = prerender.node.name.getEnd();
|
|
400
|
+
const inserted = ` : import('@sveltejs/kit').PrerenderOption`;
|
|
401
|
+
insert(pos, inserted);
|
|
402
|
+
}
|
|
403
|
+
// add type to trailingSlash variable if not explicitly typed
|
|
404
|
+
const trailingSlash = exports.get('trailingSlash');
|
|
405
|
+
if ((trailingSlash === null || trailingSlash === void 0 ? void 0 : trailingSlash.type) === 'var' &&
|
|
406
|
+
!trailingSlash.hasTypeDefinition &&
|
|
407
|
+
trailingSlash.node.initializer) {
|
|
408
|
+
const pos = trailingSlash.node.name.getEnd();
|
|
409
|
+
const inserted = ` : 'never' | 'always' | 'ignore'`; // TODO this should be exported from kit
|
|
410
|
+
insert(pos, inserted);
|
|
411
|
+
}
|
|
412
|
+
// add type to ssr variable if not explicitly typed
|
|
413
|
+
const ssr = exports.get('ssr');
|
|
414
|
+
if ((ssr === null || ssr === void 0 ? void 0 : ssr.type) === 'var' && !ssr.hasTypeDefinition && ssr.node.initializer) {
|
|
415
|
+
const pos = ssr.node.name.getEnd();
|
|
416
|
+
const inserted = ` : boolean`;
|
|
417
|
+
insert(pos, inserted);
|
|
418
|
+
}
|
|
419
|
+
// add type to csr variable if not explicitly typed
|
|
420
|
+
const csr = exports.get('csr');
|
|
421
|
+
if ((csr === null || csr === void 0 ? void 0 : csr.type) === 'var' && !csr.hasTypeDefinition && csr.node.initializer) {
|
|
422
|
+
const pos = csr.node.name.getEnd();
|
|
423
|
+
const inserted = ` : boolean`;
|
|
424
|
+
insert(pos, inserted);
|
|
425
|
+
}
|
|
426
|
+
// construct generated text from internal text and addedCode array
|
|
427
|
+
const originalText = source.getFullText();
|
|
428
|
+
let pos = 0;
|
|
429
|
+
let text = '';
|
|
430
|
+
for (const added of addedCode) {
|
|
431
|
+
text += originalText.slice(pos, added.originalPos) + added.inserted;
|
|
432
|
+
pos = added.originalPos;
|
|
433
|
+
}
|
|
434
|
+
text += originalText.slice(pos);
|
|
435
|
+
const snap = ts.ScriptSnapshot.fromString(text);
|
|
436
|
+
snap.getChangeRange = (_) => undefined;
|
|
437
|
+
this.files[fileName] = {
|
|
438
|
+
version: originalLanguageServiceHost.getScriptVersion(fileName),
|
|
439
|
+
file: snap,
|
|
440
|
+
addedCode
|
|
441
|
+
};
|
|
442
|
+
return this.files[fileName];
|
|
443
|
+
}
|
|
444
|
+
readFile(fileName) {
|
|
445
|
+
const file = this.files[fileName];
|
|
446
|
+
return file
|
|
447
|
+
? file.file.getText(0, file.file.getLength())
|
|
448
|
+
: originalLanguageServiceHost.readFile(fileName);
|
|
449
|
+
}
|
|
450
|
+
fileExists(fileName) {
|
|
451
|
+
return (this.files[fileName] !== undefined ||
|
|
452
|
+
originalLanguageServiceHost.fileExists(fileName));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const languageServiceHost = new ProxiedLanguageServiceHost();
|
|
456
|
+
const languageService = ts.createLanguageService(languageServiceHost, ts.createDocumentRegistry());
|
|
457
|
+
cache.set(info, { languageService, languageServiceHost });
|
|
458
|
+
return {
|
|
459
|
+
languageService,
|
|
460
|
+
languageServiceHost
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
exports.getProxiedLanguageService = getProxiedLanguageService;
|
|
464
|
+
const kitPageFiles = new Set([
|
|
465
|
+
'+page.ts',
|
|
466
|
+
'+page.js',
|
|
467
|
+
'+layout.ts',
|
|
468
|
+
'+layout.js',
|
|
469
|
+
'+page.server.ts',
|
|
470
|
+
'+page.server.js',
|
|
471
|
+
'+layout.server.ts',
|
|
472
|
+
'+layout.server.js'
|
|
473
|
+
]);
|
|
474
|
+
function getVirtualLS(fileName, info, ts, logger) {
|
|
475
|
+
var _a;
|
|
476
|
+
const proxy = getProxiedLanguageService(info, ts, logger);
|
|
477
|
+
const result = (_a = proxy.languageServiceHost.getKitScriptSnapshotIfUpToDate(fileName)) !== null && _a !== void 0 ? _a : proxy.languageServiceHost.upsertKitFile(fileName);
|
|
478
|
+
if (result) {
|
|
479
|
+
return {
|
|
480
|
+
languageService: proxy.languageService,
|
|
481
|
+
addedCode: result.addedCode,
|
|
482
|
+
toVirtualPos: (pos) => toVirtualPos(pos, result.addedCode),
|
|
483
|
+
toOriginalPos: (pos) => toOriginalPos(pos, result.addedCode)
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
exports.getVirtualLS = getVirtualLS;
|
|
488
|
+
function toVirtualPos(pos, addedCode) {
|
|
489
|
+
let total = 0;
|
|
490
|
+
for (const added of addedCode) {
|
|
491
|
+
if (pos < added.originalPos)
|
|
492
|
+
break;
|
|
493
|
+
total += added.length;
|
|
494
|
+
}
|
|
495
|
+
return pos + total;
|
|
496
|
+
}
|
|
497
|
+
exports.toVirtualPos = toVirtualPos;
|
|
498
|
+
function toOriginalPos(pos, addedCode) {
|
|
499
|
+
let total = 0;
|
|
500
|
+
let idx = 0;
|
|
501
|
+
for (; idx < addedCode.length; idx++) {
|
|
502
|
+
const added = addedCode[idx];
|
|
503
|
+
if (pos < added.generatedPos)
|
|
504
|
+
break;
|
|
505
|
+
total += added.length;
|
|
506
|
+
}
|
|
507
|
+
if (idx > 0) {
|
|
508
|
+
const prev = addedCode[idx - 1];
|
|
509
|
+
// If pos is in the middle of an added range, return the start of the addition
|
|
510
|
+
if (pos > prev.generatedPos && pos < prev.generatedPos + prev.length) {
|
|
511
|
+
return { pos: prev.originalPos, inGenerated: true };
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return { pos: pos - total, inGenerated: false };
|
|
515
|
+
}
|
|
516
|
+
exports.toOriginalPos = toOriginalPos;
|
|
517
|
+
/**
|
|
518
|
+
* Finds the top level const/let/function exports of a source file.
|
|
519
|
+
*/
|
|
520
|
+
function findExports(ts, source, isTsFile) {
|
|
521
|
+
var _a, _b, _c, _d, _e;
|
|
522
|
+
const exports = new Map();
|
|
523
|
+
// TODO handle indirect exports?
|
|
524
|
+
for (const statement of source.statements) {
|
|
525
|
+
if (ts.isFunctionDeclaration(statement) &&
|
|
526
|
+
statement.name &&
|
|
527
|
+
((_b = (_a = ts.getModifiers(statement)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.kind) === ts.SyntaxKind.ExportKeyword) {
|
|
528
|
+
// export function x ...
|
|
529
|
+
exports.set(statement.name.text, {
|
|
530
|
+
type: 'function',
|
|
531
|
+
node: statement,
|
|
532
|
+
hasTypeDefinition: !!((_c = statement.parameters[0]) === null || _c === void 0 ? void 0 : _c.type) ||
|
|
533
|
+
(!isTsFile &&
|
|
534
|
+
(!!ts.getJSDocType(statement) ||
|
|
535
|
+
(statement.parameters[0] &&
|
|
536
|
+
!!ts.getJSDocParameterTags(statement.parameters[0]).length)))
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
if (ts.isVariableStatement(statement) &&
|
|
540
|
+
statement.declarationList.declarations.length === 1 &&
|
|
541
|
+
((_e = (_d = ts.getModifiers(statement)) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.kind) === ts.SyntaxKind.ExportKeyword) {
|
|
542
|
+
// export const x = ...
|
|
543
|
+
const declaration = statement.declarationList.declarations[0];
|
|
544
|
+
const hasTypeDefinition = !!declaration.type ||
|
|
545
|
+
(!isTsFile && !!ts.getJSDocType(declaration)) ||
|
|
546
|
+
(!!declaration.initializer && ts.isSatisfiesExpression(declaration.initializer));
|
|
547
|
+
if (declaration.initializer &&
|
|
548
|
+
(ts.isFunctionExpression(declaration.initializer) ||
|
|
549
|
+
ts.isArrowFunction(declaration.initializer))) {
|
|
550
|
+
exports.set(declaration.name.getText(), {
|
|
551
|
+
type: 'function',
|
|
552
|
+
node: declaration.initializer,
|
|
553
|
+
hasTypeDefinition
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
exports.set(declaration.name.getText(), {
|
|
558
|
+
type: 'var',
|
|
559
|
+
node: declaration,
|
|
560
|
+
hasTypeDefinition
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return exports;
|
|
566
|
+
}
|
|
567
|
+
//# sourceMappingURL=sveltekit.js.map
|
|
@@ -78,7 +78,7 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
78
78
|
moduleCache.clear();
|
|
79
79
|
});
|
|
80
80
|
function resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions, containingSourceFile) {
|
|
81
|
-
logger.
|
|
81
|
+
logger.debug('Resolving modules names for ' + containingFile);
|
|
82
82
|
// Try resolving all module names with the original method first.
|
|
83
83
|
// The ones that are undefined will be re-checked if they are a
|
|
84
84
|
// Svelte file and if so, are resolved, too. This way we can defer
|
|
@@ -119,7 +119,7 @@ function patchModuleLoader(logger, snapshotManager, typescript, lsHost, project,
|
|
|
119
119
|
}
|
|
120
120
|
function resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
|
|
121
121
|
var _a;
|
|
122
|
-
logger.
|
|
122
|
+
logger.debug('Resolving modules names for ' + containingFile);
|
|
123
123
|
// Try resolving all module names with the original method first.
|
|
124
124
|
// The ones that are undefined will be re-checked if they are a
|
|
125
125
|
// Svelte file and if so, are resolved, too. This way we can defer
|
|
@@ -24,7 +24,7 @@ function binarySearch(array, target, key) {
|
|
|
24
24
|
let high = array.length - 1;
|
|
25
25
|
while (low <= high) {
|
|
26
26
|
const i = low + ((high - low) >> 1);
|
|
27
|
-
const item = undefined === key ? array[i] : array[i][key];
|
|
27
|
+
const item = (undefined === key ? array[i] : array[i][key]);
|
|
28
28
|
if (item === target) {
|
|
29
29
|
return i;
|
|
30
30
|
}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type ts from 'typescript/lib/tsserverlibrary';
|
|
2
2
|
import { SvelteSnapshot } from './svelte-snapshots';
|
|
3
|
+
type _ts = typeof ts;
|
|
3
4
|
export declare function isSvelteFilePath(filePath: string): boolean;
|
|
4
5
|
export declare function isVirtualSvelteFilePath(filePath: string): boolean;
|
|
5
6
|
export declare function toRealSvelteFilePath(filePath: string): string;
|
|
@@ -31,6 +32,14 @@ export declare function findNodeAtSpan<T extends ts.Node>(node: ts.Node, span: {
|
|
|
31
32
|
start: number;
|
|
32
33
|
length: number;
|
|
33
34
|
}, predicate?: NodeTypePredicate<T>): T | void;
|
|
35
|
+
/**
|
|
36
|
+
* Finds node somewhere at position.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findNodeAtPosition<T extends ts.Node>(node: ts.Node, pos: number, predicate?: NodeTypePredicate<T>): T | void;
|
|
39
|
+
/**
|
|
40
|
+
* True if is `export const/let/function`
|
|
41
|
+
*/
|
|
42
|
+
export declare function isTopLevelExport(ts: _ts, node: ts.Node, source: ts.SourceFile): boolean;
|
|
34
43
|
export declare function isGeneratedSvelteComponentName(className: string): boolean;
|
|
35
44
|
export declare function offsetOfGeneratedComponentExport(snapshot: SvelteSnapshot): number;
|
|
36
45
|
export declare function gatherDescendants<T extends ts.Node>(node: ts.Node, predicate: NodePredicate | NodeTypePredicate<T>, dest?: T[]): T[];
|
package/dist/src/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gatherDescendants = exports.offsetOfGeneratedComponentExport = exports.isGeneratedSvelteComponentName = exports.findNodeAtSpan = exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
|
|
3
|
+
exports.gatherDescendants = exports.offsetOfGeneratedComponentExport = exports.isGeneratedSvelteComponentName = exports.isTopLevelExport = exports.findNodeAtPosition = exports.findNodeAtSpan = exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
|
|
4
4
|
function isSvelteFilePath(filePath) {
|
|
5
5
|
return filePath.endsWith('.svelte');
|
|
6
6
|
}
|
|
@@ -107,6 +107,48 @@ function findNodeAtSpan(node, span, predicate) {
|
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
exports.findNodeAtSpan = findNodeAtSpan;
|
|
110
|
+
/**
|
|
111
|
+
* Finds node somewhere at position.
|
|
112
|
+
*/
|
|
113
|
+
function findNodeAtPosition(node, pos, predicate) {
|
|
114
|
+
for (const child of node.getChildren()) {
|
|
115
|
+
const childStart = child.getStart();
|
|
116
|
+
if (pos < childStart) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const childEnd = child.getEnd();
|
|
120
|
+
if (pos > childEnd) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const foundInChildren = findNodeAtPosition(child, pos, predicate);
|
|
124
|
+
if (foundInChildren) {
|
|
125
|
+
return foundInChildren;
|
|
126
|
+
}
|
|
127
|
+
if (!predicate) {
|
|
128
|
+
return child;
|
|
129
|
+
}
|
|
130
|
+
if (predicate(child)) {
|
|
131
|
+
return child;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.findNodeAtPosition = findNodeAtPosition;
|
|
136
|
+
/**
|
|
137
|
+
* True if is `export const/let/function`
|
|
138
|
+
*/
|
|
139
|
+
function isTopLevelExport(ts, node, source) {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
return ((ts.isVariableStatement(node) && source.statements.includes(node)) ||
|
|
142
|
+
(ts.isIdentifier(node) &&
|
|
143
|
+
node.parent &&
|
|
144
|
+
ts.isVariableDeclaration(node.parent) &&
|
|
145
|
+
source.statements.includes((_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent)) ||
|
|
146
|
+
(ts.isIdentifier(node) &&
|
|
147
|
+
node.parent &&
|
|
148
|
+
ts.isFunctionDeclaration(node.parent) &&
|
|
149
|
+
source.statements.includes(node.parent)));
|
|
150
|
+
}
|
|
151
|
+
exports.isTopLevelExport = isTopLevelExport;
|
|
110
152
|
const COMPONENT_SUFFIX = '__SvelteComponent_';
|
|
111
153
|
function isGeneratedSvelteComponentName(className) {
|
|
112
154
|
return className.endsWith(COMPONENT_SUFFIX);
|