@react-router/dev 0.0.0-experimental-2d5e406e4 → 0.0.0-experimental-7de693505
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/cli/commands.js +1 -1
- package/dist/cli/detectPackageManager.js +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/run.js +1 -1
- package/dist/cli/useJavascript.js +1 -1
- package/dist/colors.js +1 -1
- package/dist/config/format.js +1 -1
- package/dist/config/routes.js +1 -1
- package/dist/invariant.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/typescript/plugin.js +2 -13
- package/dist/typescript/typegen.d.ts +8 -4
- package/dist/typescript/typegen.js +23 -23
- package/dist/vite/babel.js +1 -1
- package/dist/vite/build.js +1 -1
- package/dist/vite/cloudflare-dev-proxy.js +1 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite/combine-urls.js +1 -1
- package/dist/vite/config.js +1 -1
- package/dist/vite/dev.js +1 -1
- package/dist/vite/import-vite-esm-sync.js +1 -1
- package/dist/vite/node-adapter.js +1 -1
- package/dist/vite/plugin.js +1 -1
- package/dist/vite/profiler.js +1 -1
- package/dist/vite/remove-exports.js +1 -1
- package/dist/vite/resolve-file-url.js +1 -1
- package/dist/vite/styles.js +1 -1
- package/dist/vite/vite-node.js +1 -1
- package/dist/vite/vmod.js +1 -1
- package/dist/vite/with-props.js +1 -1
- package/dist/vite.js +1 -1
- package/package.json +6 -7
- package/dist/typescript/ast.d.ts +0 -8
- package/dist/typescript/ast.js +0 -98
- package/dist/typescript/autotype/api.completions.d.ts +0 -5
- package/dist/typescript/autotype/api.completions.js +0 -75
- package/dist/typescript/autotype/api.definitions.d.ts +0 -4
- package/dist/typescript/autotype/api.definitions.js +0 -55
- package/dist/typescript/autotype/api.diagnostics.d.ts +0 -5
- package/dist/typescript/autotype/api.diagnostics.js +0 -60
- package/dist/typescript/autotype/api.hover.d.ts +0 -3
- package/dist/typescript/autotype/api.hover.js +0 -33
- package/dist/typescript/autotype/api.inlay-hints.d.ts +0 -3
- package/dist/typescript/autotype/api.inlay-hints.js +0 -31
- package/dist/typescript/autotype/index.d.ts +0 -5
- package/dist/typescript/autotype/language-service.d.ts +0 -35
- package/dist/typescript/autotype/language-service.js +0 -290
- package/dist/typescript/context.d.ts +0 -15
- package/dist/typescript/decorate.d.ts +0 -2
- package/dist/typescript/decorate.js +0 -233
- package/dist/typescript/routes.d.ts +0 -10
- package/dist/typescript/routes.js +0 -102
- package/dist/typescript/typecheck.d.ts +0 -1
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-2d5e406e4
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Remix Software Inc.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var languageService = require('./language-service.js');
|
|
16
|
-
|
|
17
|
-
const getDefinitionAndBoundSpan = ctx => (fileName, position) => {
|
|
18
|
-
var _result$definitions;
|
|
19
|
-
const autotype = languageService.getAutotypeLanguageService(ctx);
|
|
20
|
-
const route = autotype.getRoute(fileName);
|
|
21
|
-
if (!route) return;
|
|
22
|
-
const splicedIndex = route.autotyped.toSplicedIndex(position);
|
|
23
|
-
const result = autotype.getDefinitionAndBoundSpan(fileName, splicedIndex);
|
|
24
|
-
if (!result) return;
|
|
25
|
-
return {
|
|
26
|
-
definitions: (_result$definitions = result.definitions) === null || _result$definitions === void 0 ? void 0 : _result$definitions.map(remapSpans(autotype)),
|
|
27
|
-
textSpan: {
|
|
28
|
-
...result.textSpan,
|
|
29
|
-
start: route.autotyped.toOriginalIndex(result.textSpan.start).index
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const getTypeDefinitionAtPosition = ctx => (fileName, position) => {
|
|
34
|
-
const autotype = languageService.getAutotypeLanguageService(ctx);
|
|
35
|
-
const route = autotype.getRoute(fileName);
|
|
36
|
-
if (!route) return;
|
|
37
|
-
const splicedIndex = route.autotyped.toSplicedIndex(position);
|
|
38
|
-
const definitions = autotype.getTypeDefinitionAtPosition(fileName, splicedIndex);
|
|
39
|
-
if (!definitions) return;
|
|
40
|
-
return definitions.map(remapSpans(autotype));
|
|
41
|
-
};
|
|
42
|
-
const remapSpans = autotype => definition => {
|
|
43
|
-
const definitionRoute = autotype.getRoute(definition.fileName);
|
|
44
|
-
if (!definitionRoute) return definition;
|
|
45
|
-
return {
|
|
46
|
-
...definition,
|
|
47
|
-
textSpan: {
|
|
48
|
-
...definition.textSpan,
|
|
49
|
-
start: definitionRoute.autotyped.toOriginalIndex(definition.textSpan.start).index
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
exports.getDefinitionAndBoundSpan = getDefinitionAndBoundSpan;
|
|
55
|
-
exports.getTypeDefinitionAtPosition = getTypeDefinitionAtPosition;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type ts from "typescript/lib/tsserverlibrary";
|
|
2
|
-
import { type Context } from "../context";
|
|
3
|
-
export declare const getSyntacticDiagnostics: (ctx: Context) => ts.LanguageService["getSyntacticDiagnostics"];
|
|
4
|
-
export declare const getSemanticDiagnostics: (ctx: Context) => ts.LanguageService["getSemanticDiagnostics"];
|
|
5
|
-
export declare const getSuggestionDiagnostics: (ctx: Context) => ts.LanguageService["getSuggestionDiagnostics"];
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-2d5e406e4
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Remix Software Inc.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var languageService = require('./language-service.js');
|
|
16
|
-
|
|
17
|
-
const getSyntacticDiagnostics = ctx => fileName => {
|
|
18
|
-
var _ctx$languageService$;
|
|
19
|
-
const autotype = languageService.getAutotypeLanguageService(ctx);
|
|
20
|
-
const route = autotype.getRoute(fileName);
|
|
21
|
-
if (!route) return [];
|
|
22
|
-
const sourceFile = (_ctx$languageService$ = ctx.languageService.getProgram()) === null || _ctx$languageService$ === void 0 ? void 0 : _ctx$languageService$.getSourceFile(fileName);
|
|
23
|
-
if (!sourceFile) return [];
|
|
24
|
-
return autotype.getSyntacticDiagnostics(fileName).map(remapSpans(sourceFile, route.autotyped));
|
|
25
|
-
};
|
|
26
|
-
const getSemanticDiagnostics = ctx => fileName => {
|
|
27
|
-
var _ctx$languageService$2;
|
|
28
|
-
const autotype = languageService.getAutotypeLanguageService(ctx);
|
|
29
|
-
const route = autotype.getRoute(fileName);
|
|
30
|
-
if (!route) return [];
|
|
31
|
-
const sourceFile = (_ctx$languageService$2 = ctx.languageService.getProgram()) === null || _ctx$languageService$2 === void 0 ? void 0 : _ctx$languageService$2.getSourceFile(fileName);
|
|
32
|
-
if (!sourceFile) return [];
|
|
33
|
-
return autotype.getSemanticDiagnostics(fileName).map(remapSpans(sourceFile, route.autotyped));
|
|
34
|
-
};
|
|
35
|
-
const getSuggestionDiagnostics = ctx => fileName => {
|
|
36
|
-
var _ctx$languageService$3;
|
|
37
|
-
const autotype = languageService.getAutotypeLanguageService(ctx);
|
|
38
|
-
const route = autotype.getRoute(fileName);
|
|
39
|
-
if (!route) return [];
|
|
40
|
-
const sourceFile = (_ctx$languageService$3 = ctx.languageService.getProgram()) === null || _ctx$languageService$3 === void 0 ? void 0 : _ctx$languageService$3.getSourceFile(fileName);
|
|
41
|
-
if (!sourceFile) return [];
|
|
42
|
-
return autotype.getSuggestionDiagnostics(fileName).map(remapSpans(sourceFile, route.autotyped));
|
|
43
|
-
};
|
|
44
|
-
const remapSpans = (sourceFile, route) => diagnostic => {
|
|
45
|
-
if (!diagnostic.start) return diagnostic;
|
|
46
|
-
const {
|
|
47
|
-
index,
|
|
48
|
-
remapDiagnostics
|
|
49
|
-
} = route.toOriginalIndex(diagnostic.start);
|
|
50
|
-
return {
|
|
51
|
-
...diagnostic,
|
|
52
|
-
start: (remapDiagnostics === null || remapDiagnostics === void 0 ? void 0 : remapDiagnostics.start) ?? index,
|
|
53
|
-
length: (remapDiagnostics === null || remapDiagnostics === void 0 ? void 0 : remapDiagnostics.length) ?? diagnostic.length,
|
|
54
|
-
file: sourceFile
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
exports.getSemanticDiagnostics = getSemanticDiagnostics;
|
|
59
|
-
exports.getSuggestionDiagnostics = getSuggestionDiagnostics;
|
|
60
|
-
exports.getSyntacticDiagnostics = getSyntacticDiagnostics;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-2d5e406e4
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Remix Software Inc.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var languageService = require('./language-service.js');
|
|
16
|
-
|
|
17
|
-
const getQuickInfoAtPosition = ctx => (fileName, position) => {
|
|
18
|
-
const autotype = languageService.getAutotypeLanguageService(ctx);
|
|
19
|
-
const route = autotype.getRoute(fileName);
|
|
20
|
-
if (!route) return;
|
|
21
|
-
const splicedIndex = route.autotyped.toSplicedIndex(position);
|
|
22
|
-
const quickinfo = autotype.getQuickInfoAtPosition(fileName, splicedIndex);
|
|
23
|
-
if (!quickinfo) return;
|
|
24
|
-
return {
|
|
25
|
-
...quickinfo,
|
|
26
|
-
textSpan: {
|
|
27
|
-
...quickinfo.textSpan,
|
|
28
|
-
start: route.autotyped.toOriginalIndex(quickinfo.textSpan.start).index
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
exports.getQuickInfoAtPosition = getQuickInfoAtPosition;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-2d5e406e4
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Remix Software Inc.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var languageService = require('./language-service.js');
|
|
16
|
-
|
|
17
|
-
const provideInlayHints = ctx => (fileName, span, preferences) => {
|
|
18
|
-
const autotype = languageService.getAutotypeLanguageService(ctx);
|
|
19
|
-
const route = autotype.getRoute(fileName);
|
|
20
|
-
if (!route) return [];
|
|
21
|
-
const start = route.autotyped.toSplicedIndex(span.start);
|
|
22
|
-
return autotype.provideInlayHints(fileName, {
|
|
23
|
-
start,
|
|
24
|
-
length: route.autotyped.toSplicedIndex(span.start + span.length) - start
|
|
25
|
-
}, preferences).map(hint => ({
|
|
26
|
-
...hint,
|
|
27
|
-
position: route.autotyped.toOriginalIndex(hint.position).index
|
|
28
|
-
}));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
exports.provideInlayHints = provideInlayHints;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type ts from "typescript/lib/tsserverlibrary";
|
|
2
|
-
import type { Context } from "../context";
|
|
3
|
-
type RouteModule = {
|
|
4
|
-
snapshot: ts.IScriptSnapshot;
|
|
5
|
-
version: string;
|
|
6
|
-
autotyped: AutotypedRoute;
|
|
7
|
-
};
|
|
8
|
-
type AutotypeLanguageService = ts.LanguageService & {
|
|
9
|
-
getRoute: (fileName: string) => RouteModule | undefined;
|
|
10
|
-
};
|
|
11
|
-
export declare function getAutotypeLanguageService(ctx: Context): AutotypeLanguageService;
|
|
12
|
-
type Splice = {
|
|
13
|
-
index: number;
|
|
14
|
-
content: string;
|
|
15
|
-
remapDiagnostics: {
|
|
16
|
-
start: number;
|
|
17
|
-
length: number;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export declare class AutotypedRoute {
|
|
21
|
-
private _originalCode;
|
|
22
|
-
private _splices;
|
|
23
|
-
private _code;
|
|
24
|
-
constructor(code: string, splices: Splice[]);
|
|
25
|
-
code(): string;
|
|
26
|
-
toSplicedIndex(originalIndex: number): number;
|
|
27
|
-
toOriginalIndex(splicedIndex: number): {
|
|
28
|
-
index: number;
|
|
29
|
-
remapDiagnostics?: {
|
|
30
|
-
start: number;
|
|
31
|
-
length: number;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export {};
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-2d5e406e4
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Remix Software Inc.
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var path = require('node:path');
|
|
16
|
-
var typegen = require('../typegen.js');
|
|
17
|
-
var ast = require('../ast.js');
|
|
18
|
-
var routes = require('../routes.js');
|
|
19
|
-
|
|
20
|
-
function _interopNamespace(e) {
|
|
21
|
-
if (e && e.__esModule) return e;
|
|
22
|
-
var n = Object.create(null);
|
|
23
|
-
if (e) {
|
|
24
|
-
Object.keys(e).forEach(function (k) {
|
|
25
|
-
if (k !== 'default') {
|
|
26
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () { return e[k]; }
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
n["default"] = e;
|
|
35
|
-
return Object.freeze(n);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
39
|
-
|
|
40
|
-
// Adapted from https://github.com/sveltejs/language-tools/blob/master/packages/typescript-plugin/src/language-service/sveltekit.ts
|
|
41
|
-
const FORCE_UPDATE_VERSION = "FORCE_UPDATE_VERSION";
|
|
42
|
-
// TODO: cache by rootDirectory!
|
|
43
|
-
let CACHED;
|
|
44
|
-
function getAutotypeLanguageService(ctx) {
|
|
45
|
-
if (CACHED) return CACHED;
|
|
46
|
-
const host = ctx.languageServiceHost;
|
|
47
|
-
class AutotypeLanguageServiceHost {
|
|
48
|
-
routes = {};
|
|
49
|
-
// TODO: Q: are these needed? do they just "silence" the autotype host?
|
|
50
|
-
// log() {}
|
|
51
|
-
// trace() {}
|
|
52
|
-
// error() {}
|
|
53
|
-
getCompilationSettings() {
|
|
54
|
-
return host.getCompilationSettings();
|
|
55
|
-
}
|
|
56
|
-
getCurrentDirectory() {
|
|
57
|
-
return host.getCurrentDirectory();
|
|
58
|
-
}
|
|
59
|
-
getDefaultLibFileName(o) {
|
|
60
|
-
return host.getDefaultLibFileName(o);
|
|
61
|
-
}
|
|
62
|
-
getScriptFileNames() {
|
|
63
|
-
const names = new Set(Object.keys(this.routes));
|
|
64
|
-
const files = host.getScriptFileNames();
|
|
65
|
-
for (const file of files) {
|
|
66
|
-
names.add(file);
|
|
67
|
-
}
|
|
68
|
-
return [...names];
|
|
69
|
-
}
|
|
70
|
-
getScriptVersion(fileName) {
|
|
71
|
-
const route = this.routes[fileName];
|
|
72
|
-
if (!route) return host.getScriptVersion(fileName);
|
|
73
|
-
return route.version.toString();
|
|
74
|
-
}
|
|
75
|
-
getScriptSnapshot(fileName) {
|
|
76
|
-
const route = this.routes[fileName];
|
|
77
|
-
if (!route) return host.getScriptSnapshot(fileName);
|
|
78
|
-
return route.snapshot;
|
|
79
|
-
}
|
|
80
|
-
readFile(fileName) {
|
|
81
|
-
const route = this.routes[fileName];
|
|
82
|
-
return route ? route.snapshot.getText(0, route.snapshot.getLength()) : host.readFile(fileName);
|
|
83
|
-
}
|
|
84
|
-
fileExists(fileName) {
|
|
85
|
-
return this.routes[fileName] !== undefined || host.fileExists(fileName);
|
|
86
|
-
}
|
|
87
|
-
getRouteIfUpToDate(fileName) {
|
|
88
|
-
const scriptVersion = this.getScriptVersion(fileName);
|
|
89
|
-
const route = this.routes[fileName];
|
|
90
|
-
if (!route || scriptVersion !== host.getScriptVersion(fileName) || scriptVersion === FORCE_UPDATE_VERSION) {
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
return route;
|
|
94
|
-
}
|
|
95
|
-
upsertRouteFile(fileName) {
|
|
96
|
-
var _ctx$languageService$;
|
|
97
|
-
const route = routes.get(ctx, fileName);
|
|
98
|
-
if (!route) return;
|
|
99
|
-
const sourceFile = (_ctx$languageService$ = ctx.languageService.getProgram()) === null || _ctx$languageService$ === void 0 ? void 0 : _ctx$languageService$.getSourceFile(fileName);
|
|
100
|
-
if (!sourceFile) return;
|
|
101
|
-
const {
|
|
102
|
-
text: code
|
|
103
|
-
} = sourceFile;
|
|
104
|
-
const autotyped = autotypeRoute(ctx, fileName, code);
|
|
105
|
-
const snapshot = ctx.ts.ScriptSnapshot.fromString(autotyped.code());
|
|
106
|
-
snapshot.getChangeRange = _ => undefined;
|
|
107
|
-
this.routes[fileName] = {
|
|
108
|
-
version: this.routes[fileName] === undefined ? FORCE_UPDATE_VERSION : host.getScriptVersion(fileName),
|
|
109
|
-
snapshot,
|
|
110
|
-
autotyped
|
|
111
|
-
};
|
|
112
|
-
return this.routes[fileName];
|
|
113
|
-
}
|
|
114
|
-
// needed for path auto completions
|
|
115
|
-
readDirectory = host.readDirectory ? (...args) => {
|
|
116
|
-
return host.readDirectory(...args);
|
|
117
|
-
} : undefined;
|
|
118
|
-
}
|
|
119
|
-
const autotypeHost = new AutotypeLanguageServiceHost();
|
|
120
|
-
function getRoute(fileName) {
|
|
121
|
-
const route = autotypeHost.getRouteIfUpToDate(fileName) ?? autotypeHost.upsertRouteFile(fileName);
|
|
122
|
-
return route;
|
|
123
|
-
}
|
|
124
|
-
const languageService = ctx.ts.createLanguageService(autotypeHost);
|
|
125
|
-
CACHED = {
|
|
126
|
-
...languageService,
|
|
127
|
-
getRoute
|
|
128
|
-
};
|
|
129
|
-
return CACHED;
|
|
130
|
-
}
|
|
131
|
-
function autotypeRoute(ctx, filepath, code) {
|
|
132
|
-
const sourceFile = ctx.ts.createSourceFile(filepath, code, ctx.ts.ScriptTarget.Latest, true);
|
|
133
|
-
const route = {
|
|
134
|
-
file: path__namespace.relative(ctx.config.appDirectory, filepath)
|
|
135
|
-
};
|
|
136
|
-
const typesSource = "./" + path__namespace.parse(typegen.getPath(ctx, route)).name;
|
|
137
|
-
const splices = [...sourceFile.statements.flatMap(stmt => [...annotateDefaultExportFunctionDeclaration(ctx, stmt, typesSource), ...annotateDefaultExportExpression(ctx, stmt, typesSource), ...annotateNamedExportFunctionDeclaration(ctx, stmt, typesSource), ...annotateNamedExportVariableStatement(ctx, stmt, typesSource)])];
|
|
138
|
-
return new AutotypedRoute(code, splices);
|
|
139
|
-
}
|
|
140
|
-
function annotateDefaultExportFunctionDeclaration(ctx, stmt, typesSource) {
|
|
141
|
-
var _stmt$name, _stmt$name2;
|
|
142
|
-
if (!ctx.ts.isFunctionDeclaration(stmt)) return [];
|
|
143
|
-
if (!ast.exported(ctx.ts, stmt)) return [];
|
|
144
|
-
const _default = ast.defaulted(ctx.ts, stmt);
|
|
145
|
-
if (!_default) return [];
|
|
146
|
-
return annotateFunction(ctx, stmt, {
|
|
147
|
-
typesSource,
|
|
148
|
-
name: "default",
|
|
149
|
-
remapDiagnostics: {
|
|
150
|
-
start: ((_stmt$name = stmt.name) === null || _stmt$name === void 0 ? void 0 : _stmt$name.getStart()) ?? _default.getStart(),
|
|
151
|
-
length: ((_stmt$name2 = stmt.name) === null || _stmt$name2 === void 0 ? void 0 : _stmt$name2.getWidth()) ?? _default.getWidth()
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
function annotateDefaultExportExpression(ctx, stmt, typesSource) {
|
|
156
|
-
if (!ctx.ts.isExportAssignment(stmt)) return [];
|
|
157
|
-
if (stmt.isExportEquals) return [];
|
|
158
|
-
if (!ctx.ts.isArrowFunction(stmt.expression)) return [];
|
|
159
|
-
const regex = /^export\s+/;
|
|
160
|
-
const matches = stmt.getText().match(regex);
|
|
161
|
-
if (!matches) {
|
|
162
|
-
throw Error(`expected ${regex} at ${stmt.getSourceFile().fileName}:${stmt.getStart()}`);
|
|
163
|
-
}
|
|
164
|
-
return annotateFunction(ctx, stmt.expression, {
|
|
165
|
-
typesSource,
|
|
166
|
-
name: "default",
|
|
167
|
-
remapDiagnostics: {
|
|
168
|
-
start: stmt.getStart() + matches[0].length,
|
|
169
|
-
length: 7
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
function annotateNamedExportFunctionDeclaration(ctx, stmt, typesSource) {
|
|
174
|
-
if (!ctx.ts.isFunctionDeclaration(stmt)) return [];
|
|
175
|
-
if (!ast.exported(ctx.ts, stmt)) return [];
|
|
176
|
-
if (ast.defaulted(ctx.ts, stmt)) return [];
|
|
177
|
-
if (!stmt.name) return [];
|
|
178
|
-
return annotateFunction(ctx, stmt, {
|
|
179
|
-
typesSource,
|
|
180
|
-
name: stmt.name.text,
|
|
181
|
-
remapDiagnostics: {
|
|
182
|
-
start: stmt.name.getStart(),
|
|
183
|
-
length: stmt.name.getWidth()
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
function annotateNamedExportVariableStatement(ctx, stmt, typesSource) {
|
|
188
|
-
if (!ctx.ts.isVariableStatement(stmt)) return [];
|
|
189
|
-
if (!ast.exported(ctx.ts, stmt)) return [];
|
|
190
|
-
return stmt.declarationList.declarations.flatMap(decl => {
|
|
191
|
-
if (!ctx.ts.isIdentifier(decl.name)) return [];
|
|
192
|
-
if (decl.initializer === undefined) return [];
|
|
193
|
-
if (ctx.ts.isFunctionExpression(decl.initializer) || ctx.ts.isArrowFunction(decl.initializer)) {
|
|
194
|
-
return annotateFunction(ctx, decl.initializer, {
|
|
195
|
-
typesSource,
|
|
196
|
-
name: decl.name.text,
|
|
197
|
-
remapDiagnostics: {
|
|
198
|
-
start: decl.name.getStart(),
|
|
199
|
-
length: decl.name.getWidth()
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
return [];
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
function annotateFunction(ctx, fn, {
|
|
207
|
-
typesSource,
|
|
208
|
-
name,
|
|
209
|
-
remapDiagnostics
|
|
210
|
-
}) {
|
|
211
|
-
var _fn$body, _Route$exports$name;
|
|
212
|
-
const param = fn.parameters[0];
|
|
213
|
-
const returnTypeIndex = ctx.ts.isArrowFunction(fn) ? fn.equalsGreaterThanToken.getStart() : (_fn$body = fn.body) === null || _fn$body === void 0 ? void 0 : _fn$body.getStart();
|
|
214
|
-
const annotateReturnType = (_Route$exports$name = routes.exports[name]) === null || _Route$exports$name === void 0 ? void 0 : _Route$exports$name.annotateReturnType;
|
|
215
|
-
name = name === "default" ? "Default" : name;
|
|
216
|
-
return [param && param.type === undefined ? {
|
|
217
|
-
index: param.getEnd(),
|
|
218
|
-
content: `: import("${typesSource}").${name}["args"]`,
|
|
219
|
-
remapDiagnostics
|
|
220
|
-
} : null, returnTypeIndex && annotateReturnType && fn.type === undefined ? {
|
|
221
|
-
index: returnTypeIndex,
|
|
222
|
-
content: `: import("${typesSource}").${name}["return"]`,
|
|
223
|
-
remapDiagnostics
|
|
224
|
-
} : null].filter(x => x !== null);
|
|
225
|
-
}
|
|
226
|
-
class AutotypedRoute {
|
|
227
|
-
_code = undefined;
|
|
228
|
-
constructor(code, splices) {
|
|
229
|
-
this._originalCode = code;
|
|
230
|
-
this._splices = splices;
|
|
231
|
-
}
|
|
232
|
-
code() {
|
|
233
|
-
if (!this._code) {
|
|
234
|
-
const chars = Array.from(this._originalCode);
|
|
235
|
-
// iterate over splices in reverse so that splicing doesn't mess up other indices
|
|
236
|
-
for (let {
|
|
237
|
-
index,
|
|
238
|
-
content
|
|
239
|
-
} of reverse(this._splices)) {
|
|
240
|
-
chars.splice(index, 0, content);
|
|
241
|
-
}
|
|
242
|
-
this._code = chars.join("");
|
|
243
|
-
}
|
|
244
|
-
return this._code;
|
|
245
|
-
}
|
|
246
|
-
toSplicedIndex(originalIndex) {
|
|
247
|
-
let spliceOffset = 0;
|
|
248
|
-
for (let {
|
|
249
|
-
index,
|
|
250
|
-
content
|
|
251
|
-
} of this._splices) {
|
|
252
|
-
if (index > originalIndex) break;
|
|
253
|
-
spliceOffset += content.length;
|
|
254
|
-
}
|
|
255
|
-
return originalIndex + spliceOffset;
|
|
256
|
-
}
|
|
257
|
-
toOriginalIndex(splicedIndex) {
|
|
258
|
-
let spliceOffset = 0;
|
|
259
|
-
for (let {
|
|
260
|
-
index,
|
|
261
|
-
content,
|
|
262
|
-
remapDiagnostics
|
|
263
|
-
} of this._splices) {
|
|
264
|
-
// before this splice
|
|
265
|
-
if (splicedIndex < index + spliceOffset) break;
|
|
266
|
-
// within this splice
|
|
267
|
-
if (splicedIndex < index + spliceOffset + content.length) {
|
|
268
|
-
return {
|
|
269
|
-
index,
|
|
270
|
-
remapDiagnostics
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
// after this splice
|
|
274
|
-
spliceOffset += content.length;
|
|
275
|
-
}
|
|
276
|
-
return {
|
|
277
|
-
index: Math.max(0, splicedIndex - spliceOffset)
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
function* reverse(array) {
|
|
282
|
-
let i = array.length - 1;
|
|
283
|
-
while (i >= 0) {
|
|
284
|
-
yield array[i];
|
|
285
|
-
i--;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
exports.AutotypedRoute = AutotypedRoute;
|
|
290
|
-
exports.getAutotypeLanguageService = getAutotypeLanguageService;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type ts from "typescript/lib/tsserverlibrary";
|
|
2
|
-
import type { RouteManifest } from "../config/routes";
|
|
3
|
-
export type Context = {
|
|
4
|
-
config: {
|
|
5
|
-
rootDirectory: string;
|
|
6
|
-
appDirectory: string;
|
|
7
|
-
};
|
|
8
|
-
routes: RouteManifest;
|
|
9
|
-
languageService: ts.LanguageService;
|
|
10
|
-
languageServiceHost: ts.LanguageServiceHost;
|
|
11
|
-
ts: typeof ts;
|
|
12
|
-
logger?: {
|
|
13
|
-
info: (message: string) => void;
|
|
14
|
-
};
|
|
15
|
-
};
|