@vesk/compiler 0.1.1 → 0.2.8
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/api-routes.d.ts +6 -1
- package/dist/api-routes.d.ts.map +1 -1
- package/dist/api-routes.js +52 -7
- package/dist/client-codegen.d.ts +15 -0
- package/dist/client-codegen.d.ts.map +1 -1
- package/dist/client-codegen.js +73 -10
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +25 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +33 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/ir-generator.d.ts.map +1 -1
- package/dist/ir-generator.js +109 -1
- package/dist/md-inline.d.ts +17 -0
- package/dist/md-inline.d.ts.map +1 -0
- package/dist/md-inline.js +149 -0
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +42 -7
- package/dist/router.d.ts +2 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +48 -3
- package/dist/server-codegen.d.ts +1 -1
- package/dist/server-codegen.d.ts.map +1 -1
- package/dist/server-codegen.js +1 -1
- package/dist/server-jsgen.d.ts.map +1 -1
- package/dist/server-jsgen.js +4 -3
- package/dist/server-render.d.ts.map +1 -1
- package/dist/server-render.js +16 -8
- package/dist/server-utils.d.ts +31 -0
- package/dist/server-utils.d.ts.map +1 -1
- package/dist/server-utils.js +478 -52
- package/dist/ssr-store.d.ts +1 -1
- package/dist/ssr-store.d.ts.map +1 -1
- package/dist/ssr-store.js +3 -0
- package/dist/typecheck.d.ts +2 -0
- package/dist/typecheck.d.ts.map +1 -1
- package/dist/typecheck.js +452 -29
- package/dist/types.d.ts +4 -129
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/vesk-plugin.d.ts +2 -0
- package/dist/vesk-plugin.d.ts.map +1 -1
- package/dist/vesk-plugin.js +152 -0
- package/dist/vsk-tsx.d.ts +62 -0
- package/dist/vsk-tsx.d.ts.map +1 -1
- package/dist/vsk-tsx.js +844 -362
- package/package.json +2 -1
- package/dist/package.json +0 -15
package/dist/types.d.ts
CHANGED
|
@@ -1,147 +1,22 @@
|
|
|
1
1
|
import type { IRRoot } from '@vesk/compiler/src/ir';
|
|
2
|
-
export
|
|
3
|
-
path: string;
|
|
4
|
-
fullPath: string;
|
|
5
|
-
isGroup: boolean;
|
|
6
|
-
isDynamic: boolean;
|
|
7
|
-
isCatchAll: boolean;
|
|
8
|
-
page: string | null;
|
|
9
|
-
layout: string | null;
|
|
10
|
-
loading: string | null;
|
|
11
|
-
error: string | null;
|
|
12
|
-
notFound: string | null;
|
|
13
|
-
hasMiddleware: boolean;
|
|
14
|
-
children: RouteNode[];
|
|
15
|
-
sourceDir: string;
|
|
16
|
-
segmentCount: number;
|
|
17
|
-
}
|
|
18
|
-
export interface ApiRouteNode {
|
|
19
|
-
path: string;
|
|
20
|
-
fullPath: string;
|
|
21
|
-
isDynamic: boolean;
|
|
22
|
-
isCatchAll: boolean;
|
|
23
|
-
filePath: string | null;
|
|
24
|
-
children: ApiRouteNode[];
|
|
25
|
-
}
|
|
26
|
-
export interface MiddlewareContext {
|
|
27
|
-
request: Request;
|
|
28
|
-
params: Record<string, string>;
|
|
29
|
-
url: URL;
|
|
30
|
-
locals: Record<string, unknown>;
|
|
31
|
-
cookies: Record<string, string>;
|
|
32
|
-
set(key: string, value: unknown): void;
|
|
33
|
-
get(key: string): unknown;
|
|
34
|
-
[key: string]: unknown;
|
|
35
|
-
}
|
|
36
|
-
export interface VeskPlugin {
|
|
37
|
-
name: string;
|
|
38
|
-
provides?: Record<string, (() => unknown | Promise<unknown>) | unknown>;
|
|
39
|
-
onRequest?: (ctx: MiddlewareContext) => void | Promise<void>;
|
|
40
|
-
onCSS?: (content: string, filePath: string) => string | null | Promise<string | null>;
|
|
41
|
-
onFileWatch?: (filePath: string) => {
|
|
42
|
-
handled: boolean;
|
|
43
|
-
} | Promise<{
|
|
44
|
-
handled: boolean;
|
|
45
|
-
}>;
|
|
46
|
-
onTransformJS?: (code: string, filePath: string) => string | null | Promise<string | null>;
|
|
47
|
-
onBuildStart?: () => void | Promise<void>;
|
|
48
|
-
onBuildEnd?: () => void | Promise<void>;
|
|
49
|
-
}
|
|
50
|
-
export interface VeskCors {
|
|
51
|
-
origin: string | string[];
|
|
52
|
-
methods?: string;
|
|
53
|
-
headers?: string;
|
|
54
|
-
credentials?: boolean;
|
|
55
|
-
maxAge?: number;
|
|
56
|
-
}
|
|
57
|
-
export interface VeskRateLimit {
|
|
58
|
-
windowMs?: number;
|
|
59
|
-
max?: number;
|
|
60
|
-
}
|
|
61
|
-
export type VeskSecurityPreset = 'strict' | 'default' | 'minimal' | 'off';
|
|
62
|
-
export interface VeskSecurity {
|
|
63
|
-
xFrameOptions?: string | false;
|
|
64
|
-
hsts?: string | false;
|
|
65
|
-
referrerPolicy?: string | false;
|
|
66
|
-
contentSecurityPolicy?: boolean | string;
|
|
67
|
-
autoEscape?: boolean;
|
|
68
|
-
csrf?: boolean;
|
|
69
|
-
cors?: VeskCors;
|
|
70
|
-
trustProxy?: boolean | string;
|
|
71
|
-
rateLimit?: VeskRateLimit;
|
|
72
|
-
redactLogs?: boolean;
|
|
73
|
-
}
|
|
74
|
-
export interface VeskConfig {
|
|
75
|
-
appDir?: string;
|
|
76
|
-
outDir?: string;
|
|
77
|
-
publicDir?: string;
|
|
78
|
-
ssg?: {
|
|
79
|
-
getStaticPaths?: () => Promise<{
|
|
80
|
-
paths: Array<{
|
|
81
|
-
params: Record<string, string>;
|
|
82
|
-
}>;
|
|
83
|
-
}>;
|
|
84
|
-
};
|
|
85
|
-
plugins?: VeskPlugin[];
|
|
86
|
-
security?: VeskSecurity | VeskSecurityPreset | false | ((preset: (name: string, overrides?: VeskSecurity) => VeskSecurity) => VeskSecurity);
|
|
87
|
-
/** Client router route-data freshness TTL in milliseconds. The SPA router
|
|
88
|
-
* refetches a route's server data when it is older than this. Default 0 =
|
|
89
|
-
* always fetch fresh data on every SPA visit. */
|
|
90
|
-
routeDataCache?: number;
|
|
91
|
-
}
|
|
92
|
-
export interface MiddlewareEntry {
|
|
93
|
-
sourcePath: string;
|
|
94
|
-
node: RouteNode;
|
|
95
|
-
}
|
|
96
|
-
export interface MiddlewareChainOptions {
|
|
97
|
-
onLast?: (rewriteUrl: string | null) => Response | Promise<Response>;
|
|
98
|
-
plugins?: VeskPlugin[];
|
|
99
|
-
}
|
|
2
|
+
export type { RouteNode, ApiRouteNode, MiddlewareContext, VeskPlugin, VeskCors, VeskRateLimit, VeskSecurityPreset, VeskSecurity, VeskConfig, MdConfig, MdHtmlMode, MiddlewareEntry, MiddlewareChainOptions, RenderPageResult, SSGResult, DataScriptPayload, ExternalDataScript, } from '@vesk/types';
|
|
100
3
|
export interface CompileFileResult {
|
|
101
4
|
ir: IRRoot;
|
|
102
5
|
componentMap: Map<string, Function>;
|
|
103
6
|
__vesk: Record<string, unknown>;
|
|
104
7
|
}
|
|
105
|
-
export interface RenderPageResult {
|
|
106
|
-
body: string;
|
|
107
|
-
head: string;
|
|
108
|
-
props: Record<string, unknown>;
|
|
109
|
-
}
|
|
110
|
-
export interface SSGResult {
|
|
111
|
-
html: string;
|
|
112
|
-
body: string;
|
|
113
|
-
head: string;
|
|
114
|
-
props: string;
|
|
115
|
-
clientCode: string;
|
|
116
|
-
static: boolean;
|
|
117
|
-
staticLists: boolean;
|
|
118
|
-
}
|
|
119
|
-
export interface DataScriptPayload {
|
|
120
|
-
props?: Record<string, unknown>;
|
|
121
|
-
ssrData?: Record<string, unknown>;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* When provided, hydration data (serialized props + useFetch SSR data) is
|
|
125
|
-
* served as an external classic script (`<script src="...">`) instead of an
|
|
126
|
-
* inline `<script>globalThis.__vsk_ssr_data = ...</script>`. Inline data
|
|
127
|
-
* scripts are blocked by strict Content-Security-Policy headers
|
|
128
|
-
* (`script-src 'self'` without `'unsafe-inline'`), so servers must deliver
|
|
129
|
-
* the payload through an origin-served file. The callback stores the payload
|
|
130
|
-
* server-side and returns the script src URL (or null to fall back to inline).
|
|
131
|
-
*/
|
|
132
|
-
export type ExternalDataScript = (payload: DataScriptPayload) => string | null;
|
|
133
8
|
export interface FullPageOptions {
|
|
134
9
|
cssUrl?: string;
|
|
135
10
|
cssUrls?: string[];
|
|
136
11
|
clientScriptUrl?: string;
|
|
137
12
|
pageHead?: string;
|
|
138
|
-
security?: VeskSecurity;
|
|
13
|
+
security?: import('@vesk/types').VeskSecurity;
|
|
139
14
|
__vesk?: Record<string, unknown>;
|
|
140
15
|
hydrate?: boolean;
|
|
141
16
|
sourcePath?: string;
|
|
142
|
-
externalDataScript?: ExternalDataScript;
|
|
17
|
+
externalDataScript?: import('@vesk/types').ExternalDataScript;
|
|
143
18
|
cached?: CompileFileResult;
|
|
144
19
|
}
|
|
145
|
-
export declare const VESK_BUILTINS: readonly ["useFetch", "useRouter", "useParams", "usePathname", "useSearchParams", "useNavigate", "useHead", "useTitle", "Form", "Field", "Link", "NavLink", "Outlet", "Image", "Portal", "Experiment", "defineAction", "required", "email", "minLength", "maxLength", "pattern", "custom", "track", "get", "set", "derived", "effect", "batch", "untrack", "cookies", "headers", "locals", "VeskResponse", "VeskRequest", "ServerRequest", "ServerResponse", "redirect", "permanentRedirect", "notFound"];
|
|
20
|
+
export declare const VESK_BUILTINS: readonly ["useFetch", "useRouter", "useParams", "usePathname", "useSearchParams", "useNavigate", "useHead", "useTitle", "Form", "Field", "Link", "NavLink", "Outlet", "Image", "Portal", "Experiment", "LoadingIndicator", "useLoadingIndicator", "defineAction", "required", "email", "minLength", "maxLength", "pattern", "custom", "track", "get", "set", "derived", "effect", "batch", "untrack", "cookies", "headers", "locals", "VeskResponse", "VeskRequest", "ServerRequest", "ServerResponse", "redirect", "permanentRedirect", "notFound"];
|
|
146
21
|
export type VeskBuiltin = typeof VESK_BUILTINS[number];
|
|
147
22
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIpD,YAAY,EACV,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,aAAa,EAAE,YAAY,CAAC;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,aAAa,EAAE,kBAAkB,CAAC;IAC9D,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED,eAAO,MAAM,aAAa,shBAahB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/types.js
CHANGED
|
@@ -4,6 +4,7 @@ export const VESK_BUILTINS = [
|
|
|
4
4
|
'Form', 'Field', 'Link', 'NavLink', 'Outlet',
|
|
5
5
|
'Image', 'Portal',
|
|
6
6
|
'Experiment',
|
|
7
|
+
'LoadingIndicator', 'useLoadingIndicator',
|
|
7
8
|
'defineAction',
|
|
8
9
|
'required', 'email', 'minLength', 'maxLength', 'pattern', 'custom',
|
|
9
10
|
'track', 'get', 'set', 'derived', 'effect', 'batch', 'untrack',
|
package/dist/vesk-plugin.d.ts
CHANGED
|
@@ -23,11 +23,13 @@ declare module 'acorn' {
|
|
|
23
23
|
exitScope(): void;
|
|
24
24
|
semicolon(): void;
|
|
25
25
|
raise(pos: number, message: string): void;
|
|
26
|
+
unexpected(pos?: number): void;
|
|
26
27
|
next(): void;
|
|
27
28
|
eat(token: any): boolean;
|
|
28
29
|
jsx_parseElementAt(startPos: number, startLoc?: any): any;
|
|
29
30
|
jsx_parseElement(): any;
|
|
30
31
|
jsx_parseExpressionContainer(): any;
|
|
32
|
+
jsx_parseOpeningElementAt(startPos: number, startLoc?: any): any;
|
|
31
33
|
jsx_parseClosingElementAt(pos: number, loc: any): any;
|
|
32
34
|
jsx_parseElementName(): any;
|
|
33
35
|
parseIdent(allowBinding?: boolean): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vesk-plugin.d.ts","sourceRoot":"","sources":["../src/vesk-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,QAAQ,OAAO,CAAC;IACrB,UAAU,MAAM;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,GAAG,CAAC;QACV,KAAK,EAAE,GAAG,CAAC;QAC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EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC;QACtD,oBAAoB,IAAI,GAAG,CAAC;QAC5B,UAAU,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,GAAG,CAAC;QACxC,mBAAmB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;QACrC,aAAa,IAAI,GAAG,CAAC;QACrB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QACpC,QAAQ,EAAE,GAAG,CAAC;QACd,MAAM,EAAE,GAAG,CAAC;QACZ,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,GAAG,CAAC;QACnB,eAAe,EAAE,GAAG,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;QACzC,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC;KAChC;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAqHD,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,gBAAqB,IACpD,QAAQ,OAAO,KAAK,CAAC,MAAM,KAAG,OAAO,KAAK,CAAC,MAAM,CAud1D"}
|
package/dist/vesk-plugin.js
CHANGED
|
@@ -1,4 +1,116 @@
|
|
|
1
1
|
import * as acorn from 'acorn';
|
|
2
|
+
const VOID_ELEMENTS = new Set([
|
|
3
|
+
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
4
|
+
'link', 'meta', 'param', 'source', 'track', 'wbr',
|
|
5
|
+
]);
|
|
6
|
+
function getJSXElementName(node) {
|
|
7
|
+
if (!node)
|
|
8
|
+
return null;
|
|
9
|
+
if (node.type === 'JSXIdentifier')
|
|
10
|
+
return node.name;
|
|
11
|
+
if (node.type === 'JSXNamespacedName' && node.namespace && node.name) {
|
|
12
|
+
return `${node.namespace.name}:${node.name.name}`;
|
|
13
|
+
}
|
|
14
|
+
if (node.type === 'JSXMemberExpression') {
|
|
15
|
+
const parts = [];
|
|
16
|
+
let cur = node;
|
|
17
|
+
while (cur && cur.type === 'JSXMemberExpression') {
|
|
18
|
+
if (cur.property && cur.property.name)
|
|
19
|
+
parts.unshift(cur.property.name);
|
|
20
|
+
cur = cur.object;
|
|
21
|
+
}
|
|
22
|
+
if (cur && cur.type === 'JSXIdentifier' && cur.name)
|
|
23
|
+
parts.unshift(cur.name);
|
|
24
|
+
return parts.join('.') || null;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function isIdentStartCode(code) {
|
|
29
|
+
return (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code === 95 || code === 36;
|
|
30
|
+
}
|
|
31
|
+
function isIdentCharCode(code) {
|
|
32
|
+
return isIdentStartCode(code) || (code >= 48 && code <= 57);
|
|
33
|
+
}
|
|
34
|
+
function looksLikeGenericArrowAt(input, pos) {
|
|
35
|
+
let i = pos + 1;
|
|
36
|
+
while (i < input.length && isWsChar(input.charCodeAt(i)))
|
|
37
|
+
i++;
|
|
38
|
+
if (i >= input.length || !isIdentStartCode(input.charCodeAt(i)))
|
|
39
|
+
return false;
|
|
40
|
+
while (i < input.length && isIdentCharCode(input.charCodeAt(i)))
|
|
41
|
+
i++;
|
|
42
|
+
while (i < input.length && isWsChar(input.charCodeAt(i)))
|
|
43
|
+
i++;
|
|
44
|
+
if (input.charCodeAt(i) !== 44)
|
|
45
|
+
return false; // ','
|
|
46
|
+
i++;
|
|
47
|
+
while (i < input.length && isWsChar(input.charCodeAt(i)))
|
|
48
|
+
i++;
|
|
49
|
+
if (input.charCodeAt(i) !== 62)
|
|
50
|
+
return false; // '>'
|
|
51
|
+
i++;
|
|
52
|
+
while (i < input.length && isWsChar(input.charCodeAt(i)))
|
|
53
|
+
i++;
|
|
54
|
+
if (input.charCodeAt(i) !== 40)
|
|
55
|
+
return false; // '('
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
const TS_PRIMITIVE_TYPES = new Set(['number', 'string', 'boolean', 'any', 'unknown', 'never', 'void', 'object', 'symbol', 'bigint', 'undefined', 'null']);
|
|
59
|
+
const HTML_TAGS = new Set(['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'menu', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'slot', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr']);
|
|
60
|
+
function looksLikeTypeAssertionAt(input, pos) {
|
|
61
|
+
let i = pos + 1;
|
|
62
|
+
while (i < input.length && isWsChar(input.charCodeAt(i)))
|
|
63
|
+
i++;
|
|
64
|
+
const nameStart = i;
|
|
65
|
+
if (i >= input.length || !isIdentStartCode(input.charCodeAt(i)))
|
|
66
|
+
return false;
|
|
67
|
+
while (i < input.length && isIdentCharCode(input.charCodeAt(i)))
|
|
68
|
+
i++;
|
|
69
|
+
const name = input.slice(nameStart, i);
|
|
70
|
+
// If it's a known HTML tag (lowercase), it's JSX, not a type assertion
|
|
71
|
+
if (HTML_TAGS.has(name) || VOID_ELEMENTS.has(name))
|
|
72
|
+
return false;
|
|
73
|
+
// Only treat as type assertion if name is a TS primitive or capitalized type
|
|
74
|
+
const isPrimitive = TS_PRIMITIVE_TYPES.has(name);
|
|
75
|
+
const isCapitalized = name[0] >= 'A' && name[0] <= 'Z';
|
|
76
|
+
if (!isPrimitive && !isCapitalized)
|
|
77
|
+
return false;
|
|
78
|
+
// allow qualified type like `ns.Type` or `Array<string>`? For now only single identifier, skip generics check
|
|
79
|
+
// If next is '<', skip balanced <...>
|
|
80
|
+
if (input.charCodeAt(i) === 60) {
|
|
81
|
+
let depth = 0;
|
|
82
|
+
let j = i;
|
|
83
|
+
while (j < input.length) {
|
|
84
|
+
const c = input.charCodeAt(j);
|
|
85
|
+
if (c === 60)
|
|
86
|
+
depth++;
|
|
87
|
+
else if (c === 62) {
|
|
88
|
+
depth--;
|
|
89
|
+
if (depth === 0) {
|
|
90
|
+
i = j + 1;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
j++;
|
|
95
|
+
if (j - i > 100)
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
while (i < input.length && isWsChar(input.charCodeAt(i)))
|
|
100
|
+
i++;
|
|
101
|
+
if (input.charCodeAt(i) !== 62)
|
|
102
|
+
return false; // '>'
|
|
103
|
+
i++;
|
|
104
|
+
while (i < input.length && isWsChar(input.charCodeAt(i)))
|
|
105
|
+
i++;
|
|
106
|
+
if (i >= input.length)
|
|
107
|
+
return false;
|
|
108
|
+
const c = input.charCodeAt(i);
|
|
109
|
+
// expression start: identifier, (, [, {, ", ', `, !, ~, +, -, number, this/super etc.
|
|
110
|
+
if (isIdentStartCode(c) || c === 40 || c === 91 || c === 123 || c === 34 || c === 39 || c === 96 || c === 33 || c === 126 || c === 43 || c === 45 || (c >= 48 && c <= 57))
|
|
111
|
+
return true;
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
2
114
|
function isWsChar(code) {
|
|
3
115
|
return code === 32 || code === 9 || code === 10 || code === 13 || code === 12;
|
|
4
116
|
}
|
|
@@ -58,6 +170,10 @@ export function VeskParserPlugin(config = {}) {
|
|
|
58
170
|
};
|
|
59
171
|
if (inType) {
|
|
60
172
|
if (startsNewStatement) {
|
|
173
|
+
if (looksLikeGenericArrowAt(this.input, this.pos) || looksLikeTypeAssertionAt(this.input, this.pos)) {
|
|
174
|
+
this.#jsxStartsStatement = false;
|
|
175
|
+
return super.readToken(code);
|
|
176
|
+
}
|
|
61
177
|
this.#jsxStartsStatement = true;
|
|
62
178
|
++this.pos;
|
|
63
179
|
return this.finishToken(tstt.jsxTagStart);
|
|
@@ -70,6 +186,10 @@ export function VeskParserPlugin(config = {}) {
|
|
|
70
186
|
prev === tt._this || prev === tt._super || prev === tt._true || prev === tt._false ||
|
|
71
187
|
prev === tt._null || prev === tt.jsxTagEnd;
|
|
72
188
|
if (!canEndExpr || startsNewStatement) {
|
|
189
|
+
if (looksLikeGenericArrowAt(this.input, this.pos) || looksLikeTypeAssertionAt(this.input, this.pos)) {
|
|
190
|
+
this.#jsxStartsStatement = false;
|
|
191
|
+
return super.readToken(code);
|
|
192
|
+
}
|
|
73
193
|
this.#jsxStartsStatement = true;
|
|
74
194
|
return forceJsx();
|
|
75
195
|
}
|
|
@@ -379,6 +499,38 @@ export function VeskParserPlugin(config = {}) {
|
|
|
379
499
|
}
|
|
380
500
|
return super.jsx_parseElementAt(startPos, startLoc);
|
|
381
501
|
}
|
|
502
|
+
jsx_parseOpeningElementAt(startPos, startLoc) {
|
|
503
|
+
// Manual implementation that treats HTML void elements as
|
|
504
|
+
// self-closing even without `/>`. Delegating to super would leave
|
|
505
|
+
// a stale tc_expr context (the `>` updateContext only pops the
|
|
506
|
+
// extra level when a `/` was present), so the following `}` is
|
|
507
|
+
// mis-read as JSX text: "Unexpected token `}`".
|
|
508
|
+
const node = this.startNodeAt(startPos, startLoc);
|
|
509
|
+
node.attributes = [];
|
|
510
|
+
const nodeName = this.jsx_parseElementName();
|
|
511
|
+
if (nodeName)
|
|
512
|
+
node.name = nodeName;
|
|
513
|
+
const nameStr = getJSXElementName(nodeName);
|
|
514
|
+
const isVoid = !!(nameStr && VOID_ELEMENTS.has(nameStr));
|
|
515
|
+
while (this.type !== tt.slash && this.type !== tstt.jsxTagEnd) {
|
|
516
|
+
node.attributes.push(this.jsx_parseAttribute());
|
|
517
|
+
}
|
|
518
|
+
const hasSlash = this.eat(tt.slash);
|
|
519
|
+
node.selfClosing = hasSlash || isVoid;
|
|
520
|
+
if (this.type !== tstt.jsxTagEnd)
|
|
521
|
+
this.unexpected();
|
|
522
|
+
if (isVoid && !hasSlash) {
|
|
523
|
+
const stack = this.context;
|
|
524
|
+
if (stack.length > 0 && stack[stack.length - 1].token === '<tag>...</tag>') {
|
|
525
|
+
stack.pop();
|
|
526
|
+
this.exprAllowed = true;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
// Consume `>`. For void `>` we already popped tc_expr above so the
|
|
530
|
+
// following `}` is read as a normal JS token, not JSX text.
|
|
531
|
+
this.next();
|
|
532
|
+
return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
|
|
533
|
+
}
|
|
382
534
|
parseStyleElement(startPos, startLoc) {
|
|
383
535
|
const el = this.startNodeAt(startPos, startLoc);
|
|
384
536
|
const openNode = this.startNodeAt(startPos, startLoc);
|
package/dist/vsk-tsx.d.ts
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Segment-based TSX codegen. `vskToTsx` remains the byte-identical string
|
|
3
|
+
* transform used by the typechecker; `compileVskCodegen` additionally
|
|
4
|
+
* records `CodeMapping`s (source offset -> generated offset) so the
|
|
5
|
+
* Volar-based LSP can map positions, hover, completions and diagnostics
|
|
6
|
+
* between the user's `.vsk` source and the virtual TSX file TS actually
|
|
7
|
+
* analyzes. Synthetic text (braces, semicolons, `.map` scaffolding) is
|
|
8
|
+
* emitted without a mapping; verbatim user text is mapped 1:1.
|
|
9
|
+
*/
|
|
10
|
+
export interface CodeInfo {
|
|
11
|
+
verification?: boolean;
|
|
12
|
+
completion?: boolean | {
|
|
13
|
+
isAdditional?: boolean;
|
|
14
|
+
};
|
|
15
|
+
semantic?: boolean | {
|
|
16
|
+
shouldHighlight?: boolean;
|
|
17
|
+
shouldRename?: boolean;
|
|
18
|
+
};
|
|
19
|
+
navigation?: boolean | {
|
|
20
|
+
shouldRename?: boolean;
|
|
21
|
+
resolveRenameNewName?: (newName: string) => string;
|
|
22
|
+
};
|
|
23
|
+
structure?: boolean;
|
|
24
|
+
format?: boolean;
|
|
25
|
+
customData?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface CodeMapping {
|
|
28
|
+
sourceOffsets: number[];
|
|
29
|
+
generatedOffsets: number[];
|
|
30
|
+
lengths: number[];
|
|
31
|
+
generatedLengths?: number[];
|
|
32
|
+
data: CodeInfo;
|
|
33
|
+
}
|
|
34
|
+
export interface StyleRegion {
|
|
35
|
+
/** Source range of the whole `<style>` element. */
|
|
36
|
+
start: number;
|
|
37
|
+
end: number;
|
|
38
|
+
/** The CSS text between the opening and closing tags. */
|
|
39
|
+
content: string;
|
|
40
|
+
}
|
|
41
|
+
export interface VskCodegenError {
|
|
42
|
+
message: string;
|
|
43
|
+
start: number;
|
|
44
|
+
end: number;
|
|
45
|
+
}
|
|
46
|
+
export interface VskCodegenOptions {
|
|
47
|
+
/**
|
|
48
|
+
* When set, `&[count] = track(...)` declarations rewrite to
|
|
49
|
+
* `const __cell = track(...); let count = __cell.get(); let rawCell =
|
|
50
|
+
* __cell;` so TypeScript infers the cell's value type (hover shows
|
|
51
|
+
* `number`, not `any`). Only used by the LSP — `vskToTsx` keeps the
|
|
52
|
+
* plain `let count: any = ...` form.
|
|
53
|
+
*/
|
|
54
|
+
typedCells?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface VskCodegenResult {
|
|
57
|
+
code: string;
|
|
58
|
+
mappings: CodeMapping[];
|
|
59
|
+
styleRegions: StyleRegion[];
|
|
60
|
+
errors: VskCodegenError[];
|
|
61
|
+
}
|
|
62
|
+
export declare function compileVskCodegen(source: string, opts?: VskCodegenOptions): VskCodegenResult;
|
|
1
63
|
export declare function vskToTsx(source: string): string;
|
|
2
64
|
export declare function generateVskDts(source: string): string;
|
|
3
65
|
//# sourceMappingURL=vsk-tsx.d.ts.map
|
package/dist/vsk-tsx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vsk-tsx.d.ts","sourceRoot":"","sources":["../src/vsk-tsx.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vsk-tsx.d.ts","sourceRoot":"","sources":["../src/vsk-tsx.ts"],"names":[],"mappings":"AAiBA;;;;;;;;GAQG;AAEH,MAAM,WAAW,QAAQ;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,GAAG;QAAE,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAClD,QAAQ,CAAC,EAAE,OAAO,GAAG;QAAE,eAAe,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC3E,UAAU,CAAC,EAAE,OAAO,GAAG;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE,CAAC;IACtG,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC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