@vesk/compiler 0.2.50 → 0.2.52
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/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +33 -0
- package/dist/ir-generator.d.ts.map +1 -1
- package/dist/ir-generator.js +456 -69
- package/dist/module-imports.d.ts +6 -2
- package/dist/module-imports.d.ts.map +1 -1
- package/dist/module-imports.js +96 -7
- package/dist/parser.d.ts +29 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +221 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +15 -0
- package/dist/server-jsgen.d.ts.map +1 -1
- package/dist/server-jsgen.js +32 -6
- package/dist/server-utils.d.ts +1 -0
- package/dist/server-utils.d.ts.map +1 -1
- package/dist/server-utils.js +1 -1
- package/dist/strip-ts.d.ts.map +1 -1
- package/dist/strip-ts.js +48 -6
- package/package.json +2 -2
package/dist/strip-ts.js
CHANGED
|
@@ -189,17 +189,59 @@ export function stripTsTypes(ast) {
|
|
|
189
189
|
},
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Drop TS syntax from ONE function parameter.
|
|
194
|
+
*
|
|
195
|
+
* A parameter is not always a bare `Identifier`: with a default value it is an
|
|
196
|
+
* `AssignmentPattern` (`a: T = {}`), and then the annotation and the `?` live
|
|
197
|
+
* on `left`, NOT on the pattern node. Clearing only `p.typeAnnotation` handled
|
|
198
|
+
* `(a: string)` and left every defaulted parameter's annotation in place, so the
|
|
199
|
+
* emitted module kept a literal `: Partial<Record<string, number>>` and the SSR
|
|
200
|
+
* module loader died on `Unexpected token ':'` — one shape that only appeared
|
|
201
|
+
* when a parameter also had an initializer, which is why every non-defaulted
|
|
202
|
+
* case tested clean.
|
|
203
|
+
*
|
|
204
|
+
* Descending through the pattern covers the defaulted forms AND the destructured
|
|
205
|
+
* ones (`({ a }: Opts = {})`), and `RestElement` (`...rest: string[]`), so no
|
|
206
|
+
* parameter shape can keep type syntax.
|
|
207
|
+
*/
|
|
208
|
+
function stripParamTypes(p) {
|
|
209
|
+
if (!p)
|
|
210
|
+
return;
|
|
211
|
+
if (p.typeAnnotation)
|
|
212
|
+
p.typeAnnotation = null;
|
|
213
|
+
if (p.optional)
|
|
214
|
+
p.optional = false;
|
|
215
|
+
switch (p.type) {
|
|
216
|
+
case 'AssignmentPattern':
|
|
217
|
+
// `a: T = dflt` — the binding is `left`; the default (right) is real JS.
|
|
218
|
+
stripParamTypes(p.left);
|
|
219
|
+
break;
|
|
220
|
+
case 'RestElement':
|
|
221
|
+
stripParamTypes(p.argument);
|
|
222
|
+
break;
|
|
223
|
+
case 'ObjectPattern':
|
|
224
|
+
for (const prop of p.properties || []) {
|
|
225
|
+
// Shorthand `{ a }` has `value === shorthand`; `value` is always the binding.
|
|
226
|
+
stripParamTypes(prop.value || prop.argument || prop);
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
case 'ArrayPattern':
|
|
230
|
+
for (const el of p.elements || [])
|
|
231
|
+
if (el)
|
|
232
|
+
stripParamTypes(el);
|
|
233
|
+
break;
|
|
234
|
+
default:
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
192
238
|
function stripFunctionTypes(node) {
|
|
193
239
|
if (node.returnType)
|
|
194
240
|
node.returnType = null;
|
|
195
241
|
if (node.typeParameters)
|
|
196
242
|
node.typeParameters = null;
|
|
197
|
-
for (const p of node.params || [])
|
|
198
|
-
|
|
199
|
-
p.typeAnnotation = null;
|
|
200
|
-
if (p.optional)
|
|
201
|
-
p.optional = false;
|
|
202
|
-
}
|
|
243
|
+
for (const p of node.params || [])
|
|
244
|
+
stripParamTypes(p);
|
|
203
245
|
}
|
|
204
246
|
/**
|
|
205
247
|
* Strips TypeScript-only syntax from a plain-JS source snippet (a top-level
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesk/compiler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vesk compiler — lexer, parser, semantic analysis, IR, codegen",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@sveltejs/acorn-typescript": "^1.0.0",
|
|
23
|
-
"@vesk/types": "^0.2.
|
|
23
|
+
"@vesk/types": "^0.2.52",
|
|
24
24
|
"acorn": "^8.15.0",
|
|
25
25
|
"esrap": "^2.3.0",
|
|
26
26
|
"is-reference": "^3.0.0",
|