rooklang 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +177 -2
- package/README.ru.md +178 -0
- package/dist/ast/declarations.d.ts +185 -0
- package/dist/ast/declarations.js +1 -0
- package/dist/ast/expressions.d.ts +201 -0
- package/dist/ast/expressions.js +1 -0
- package/dist/ast/markup.d.ts +141 -0
- package/dist/ast/markup.js +1 -0
- package/dist/ast/statements.d.ts +173 -0
- package/dist/ast/statements.js +1 -0
- package/dist/ast.d.ts +18 -0
- package/dist/ast.js +18 -0
- package/dist/attrs.d.ts +8 -0
- package/dist/attrs.js +23 -0
- package/dist/browser.d.ts +30 -0
- package/dist/browser.js +36 -0
- package/dist/build.d.ts +48 -0
- package/dist/build.js +112 -0
- package/dist/checker/assignments.d.ts +14 -0
- package/dist/checker/assignments.js +197 -0
- package/dist/checker/base.d.ts +124 -0
- package/dist/checker/base.js +180 -0
- package/dist/checker/bigint.d.ts +15 -0
- package/dist/checker/bigint.js +85 -0
- package/dist/checker/builtins.d.ts +9 -0
- package/dist/checker/builtins.js +307 -0
- package/dist/checker/bytes.d.ts +11 -0
- package/dist/checker/bytes.js +72 -0
- package/dist/checker/calls.d.ts +23 -0
- package/dist/checker/calls.js +210 -0
- package/dist/checker/channel.d.ts +14 -0
- package/dist/checker/channel.js +44 -0
- package/dist/checker/channels.d.ts +9 -0
- package/dist/checker/channels.js +95 -0
- package/dist/checker/checker.d.ts +4 -0
- package/dist/checker/checker.js +22 -0
- package/dist/checker/classes.d.ts +24 -0
- package/dist/checker/classes.js +223 -0
- package/dist/checker/completion-names.d.ts +11 -0
- package/dist/checker/completion-names.js +100 -0
- package/dist/checker/completion.d.ts +25 -0
- package/dist/checker/completion.js +222 -0
- package/dist/checker/component-values.d.ts +11 -0
- package/dist/checker/component-values.js +88 -0
- package/dist/checker/components.d.ts +37 -0
- package/dist/checker/components.js +287 -0
- package/dist/checker/context.d.ts +196 -0
- package/dist/checker/context.js +35 -0
- package/dist/checker/control-flow.d.ts +24 -0
- package/dist/checker/control-flow.js +237 -0
- package/dist/checker/declarations.d.ts +26 -0
- package/dist/checker/declarations.js +259 -0
- package/dist/checker/decorator-exports.d.ts +5 -0
- package/dist/checker/decorator-exports.js +40 -0
- package/dist/checker/decorator-members.d.ts +28 -0
- package/dist/checker/decorator-members.js +140 -0
- package/dist/checker/decorator-wrappers.d.ts +20 -0
- package/dist/checker/decorator-wrappers.js +132 -0
- package/dist/checker/decorators.d.ts +28 -0
- package/dist/checker/decorators.js +265 -0
- package/dist/checker/dom-svg.d.ts +7 -0
- package/dist/checker/dom-svg.js +19 -0
- package/dist/checker/dom.d.ts +22 -0
- package/dist/checker/dom.js +361 -0
- package/dist/checker/expressions.d.ts +32 -0
- package/dist/checker/expressions.js +244 -0
- package/dist/checker/flow.d.ts +18 -0
- package/dist/checker/flow.js +134 -0
- package/dist/checker/forwarding.d.ts +15 -0
- package/dist/checker/forwarding.js +78 -0
- package/dist/checker/functions.d.ts +24 -0
- package/dist/checker/functions.js +154 -0
- package/dist/checker/go-for.d.ts +12 -0
- package/dist/checker/go-for.js +93 -0
- package/dist/checker/goroutines.d.ts +19 -0
- package/dist/checker/goroutines.js +110 -0
- package/dist/checker/helpers.d.ts +35 -0
- package/dist/checker/helpers.js +162 -0
- package/dist/checker/imports.d.ts +7 -0
- package/dist/checker/imports.js +83 -0
- package/dist/checker/initializers.d.ts +22 -0
- package/dist/checker/initializers.js +104 -0
- package/dist/checker/iterables.d.ts +5 -0
- package/dist/checker/iterables.js +17 -0
- package/dist/checker/iterators.d.ts +13 -0
- package/dist/checker/iterators.js +95 -0
- package/dist/checker/loops.d.ts +10 -0
- package/dist/checker/loops.js +82 -0
- package/dist/checker/markup.d.ts +28 -0
- package/dist/checker/markup.js +220 -0
- package/dist/checker/members.d.ts +29 -0
- package/dist/checker/members.js +233 -0
- package/dist/checker/operators.d.ts +13 -0
- package/dist/checker/operators.js +177 -0
- package/dist/checker/promise.d.ts +17 -0
- package/dist/checker/promise.js +49 -0
- package/dist/checker/refs.d.ts +26 -0
- package/dist/checker/refs.js +136 -0
- package/dist/checker/resolution.d.ts +23 -0
- package/dist/checker/resolution.js +173 -0
- package/dist/checker/statements.d.ts +28 -0
- package/dist/checker/statements.js +212 -0
- package/dist/checker/styles.d.ts +14 -0
- package/dist/checker/styles.js +49 -0
- package/dist/checker/transfer.d.ts +5 -0
- package/dist/checker/transfer.js +83 -0
- package/dist/checker/types/bytes.d.ts +4 -0
- package/dist/checker/types/bytes.js +51 -0
- package/dist/checker/types/classes.d.ts +22 -0
- package/dist/checker/types/classes.js +93 -0
- package/dist/checker/types/constructors.d.ts +27 -0
- package/dist/checker/types/constructors.js +129 -0
- package/dist/checker/types/generics.d.ts +20 -0
- package/dist/checker/types/generics.js +75 -0
- package/dist/checker/types/lazy.d.ts +30 -0
- package/dist/checker/types/lazy.js +92 -0
- package/dist/checker/types/model.d.ts +149 -0
- package/dist/checker/types/model.js +15 -0
- package/dist/checker/types/params.d.ts +7 -0
- package/dist/checker/types/params.js +220 -0
- package/dist/checker/types/printing.d.ts +6 -0
- package/dist/checker/types/printing.js +109 -0
- package/dist/checker/types/relations.d.ts +16 -0
- package/dist/checker/types/relations.js +294 -0
- package/dist/checker/types.d.ts +9 -0
- package/dist/checker/types.js +10 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +193 -0
- package/dist/codegen/analysis.d.ts +18 -0
- package/dist/codegen/analysis.js +144 -0
- package/dist/codegen/attributes.d.ts +40 -0
- package/dist/codegen/attributes.js +227 -0
- package/dist/codegen/calls.d.ts +22 -0
- package/dist/codegen/calls.js +106 -0
- package/dist/codegen/chan-helpers.d.ts +2 -0
- package/dist/codegen/chan-helpers.js +253 -0
- package/dist/codegen/component-helpers.d.ts +33 -0
- package/dist/codegen/component-helpers.js +18 -0
- package/dist/codegen/component-props.d.ts +42 -0
- package/dist/codegen/component-props.js +173 -0
- package/dist/codegen/component-values.d.ts +27 -0
- package/dist/codegen/component-values.js +146 -0
- package/dist/codegen/components.d.ts +53 -0
- package/dist/codegen/components.js +268 -0
- package/dist/codegen/control-flow.d.ts +25 -0
- package/dist/codegen/control-flow.js +152 -0
- package/dist/codegen/control-statements.d.ts +28 -0
- package/dist/codegen/control-statements.js +226 -0
- package/dist/codegen/creation.d.ts +31 -0
- package/dist/codegen/creation.js +113 -0
- package/dist/codegen/early-returns.d.ts +59 -0
- package/dist/codegen/early-returns.js +244 -0
- package/dist/codegen/element-helpers.d.ts +12 -0
- package/dist/codegen/element-helpers.js +54 -0
- package/dist/codegen/elements.d.ts +71 -0
- package/dist/codegen/elements.js +293 -0
- package/dist/codegen/emitter.d.ts +135 -0
- package/dist/codegen/emitter.js +296 -0
- package/dist/codegen/expressions.d.ts +49 -0
- package/dist/codegen/expressions.js +262 -0
- package/dist/codegen/functions.d.ts +28 -0
- package/dist/codegen/functions.js +170 -0
- package/dist/codegen/go-helpers.d.ts +9 -0
- package/dist/codegen/go-helpers.js +307 -0
- package/dist/codegen/helpers.d.ts +10 -0
- package/dist/codegen/helpers.js +356 -0
- package/dist/codegen/imported.d.ts +38 -0
- package/dist/codegen/imported.js +71 -0
- package/dist/codegen/js.d.ts +20 -0
- package/dist/codegen/js.js +113 -0
- package/dist/codegen/mutations.d.ts +10 -0
- package/dist/codegen/mutations.js +102 -0
- package/dist/codegen/parallel.d.ts +7 -0
- package/dist/codegen/parallel.js +63 -0
- package/dist/codegen/reactive.d.ts +95 -0
- package/dist/codegen/reactive.js +280 -0
- package/dist/codegen/refs.d.ts +62 -0
- package/dist/codegen/refs.js +160 -0
- package/dist/codegen/select-helpers.d.ts +2 -0
- package/dist/codegen/select-helpers.js +135 -0
- package/dist/codegen/simple-statements.d.ts +42 -0
- package/dist/codegen/simple-statements.js +253 -0
- package/dist/codegen/statements.d.ts +22 -0
- package/dist/codegen/statements.js +142 -0
- package/dist/codegen/styles.d.ts +54 -0
- package/dist/codegen/styles.js +157 -0
- package/dist/codegen/syntax.d.ts +18 -0
- package/dist/codegen/syntax.js +70 -0
- package/dist/codegen/thread-helpers.d.ts +2 -0
- package/dist/codegen/thread-helpers.js +198 -0
- package/dist/codegen/updates.d.ts +51 -0
- package/dist/codegen/updates.js +201 -0
- package/dist/codegen/web-components.d.ts +20 -0
- package/dist/codegen/web-components.js +149 -0
- package/dist/compile-file.d.ts +11 -0
- package/dist/compile-file.js +24 -0
- package/dist/compile.d.ts +53 -0
- package/dist/compile.js +187 -0
- package/dist/completion.d.ts +10 -0
- package/dist/completion.js +134 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +44 -0
- package/dist/css/hash.d.ts +1 -0
- package/dist/css/hash.js +10 -0
- package/dist/css/parse.d.ts +42 -0
- package/dist/css/parse.js +138 -0
- package/dist/css/print.d.ts +9 -0
- package/dist/css/print.js +35 -0
- package/dist/css/selectors.d.ts +29 -0
- package/dist/css/selectors.js +168 -0
- package/dist/declarations.d.ts +3 -0
- package/dist/declarations.js +207 -0
- package/dist/decorator-copy.d.ts +18 -0
- package/dist/decorator-copy.js +158 -0
- package/dist/decorators.d.ts +61 -0
- package/dist/decorators.js +241 -0
- package/dist/diagnostics.d.ts +17 -0
- package/dist/diagnostics.js +22 -0
- package/dist/go-for.d.ts +26 -0
- package/dist/go-for.js +155 -0
- package/dist/goroutines.d.ts +37 -0
- package/dist/goroutines.js +253 -0
- package/dist/html-tag.d.ts +21 -0
- package/dist/html-tag.js +103 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +55 -0
- package/dist/inline-packages.d.ts +32 -0
- package/dist/inline-packages.js +129 -0
- package/dist/iterators.d.ts +10 -0
- package/dist/iterators.js +33 -0
- package/dist/lexer/base.d.ts +24 -0
- package/dist/lexer/base.js +87 -0
- package/dist/lexer/lexer.d.ts +8 -0
- package/dist/lexer/lexer.js +134 -0
- package/dist/lexer/literals.d.ts +18 -0
- package/dist/lexer/literals.js +203 -0
- package/dist/lexer/markup.d.ts +10 -0
- package/dist/lexer/markup.js +93 -0
- package/dist/lexer/style.d.ts +17 -0
- package/dist/lexer/style.js +97 -0
- package/dist/lexer/tables.d.ts +53 -0
- package/dist/lexer/tables.js +101 -0
- package/dist/lexer/token.d.ts +42 -0
- package/dist/lexer/token.js +108 -0
- package/dist/loader.d.ts +1 -0
- package/dist/loader.js +50 -0
- package/dist/methods.d.ts +5 -0
- package/dist/methods.js +81 -0
- package/dist/modules.d.ts +3 -0
- package/dist/modules.js +49 -0
- package/dist/names.d.ts +23 -0
- package/dist/names.js +267 -0
- package/dist/parser/base.d.ts +96 -0
- package/dist/parser/base.js +202 -0
- package/dist/parser/classes.d.ts +8 -0
- package/dist/parser/classes.js +164 -0
- package/dist/parser/control-flow.d.ts +29 -0
- package/dist/parser/control-flow.js +232 -0
- package/dist/parser/declarations.d.ts +27 -0
- package/dist/parser/declarations.js +238 -0
- package/dist/parser/decorators.d.ts +30 -0
- package/dist/parser/decorators.js +176 -0
- package/dist/parser/expressions.d.ts +15 -0
- package/dist/parser/expressions.js +255 -0
- package/dist/parser/literals.d.ts +27 -0
- package/dist/parser/literals.js +206 -0
- package/dist/parser/markup.d.ts +22 -0
- package/dist/parser/markup.js +193 -0
- package/dist/parser/parser.d.ts +14 -0
- package/dist/parser/parser.js +22 -0
- package/dist/parser/simple-statements.d.ts +22 -0
- package/dist/parser/simple-statements.js +156 -0
- package/dist/parser/statements.d.ts +37 -0
- package/dist/parser/statements.js +267 -0
- package/dist/parser/syntax.d.ts +51 -0
- package/dist/parser/syntax.js +173 -0
- package/dist/parser/types.d.ts +23 -0
- package/dist/parser/types.js +218 -0
- package/dist/recursion.d.ts +25 -0
- package/dist/recursion.js +170 -0
- package/dist/refs.d.ts +49 -0
- package/dist/refs.js +210 -0
- package/dist/run.d.ts +1 -0
- package/dist/run.js +21 -0
- package/dist/source.d.ts +15 -0
- package/dist/source.js +34 -0
- package/dist/style-modules.d.ts +17 -0
- package/dist/style-modules.js +49 -0
- package/dist/styles.d.ts +36 -0
- package/dist/styles.js +160 -0
- package/dist/svg.d.ts +8 -0
- package/dist/svg.js +77 -0
- package/dist/ts-types.d.ts +11 -0
- package/dist/ts-types.js +133 -0
- package/dist/typed-arrays.d.ts +8 -0
- package/dist/typed-arrays.js +43 -0
- package/dist/typescript/convert-base.d.ts +42 -0
- package/dist/typescript/convert-base.js +135 -0
- package/dist/typescript/convert-objects.d.ts +28 -0
- package/dist/typescript/convert-objects.js +245 -0
- package/dist/typescript/convert.d.ts +14 -0
- package/dist/typescript/convert.js +67 -0
- package/dist/typescript/importer.d.ts +37 -0
- package/dist/typescript/importer.js +152 -0
- package/dist/typescript/library.d.ts +23 -0
- package/dist/typescript/library.js +81 -0
- package/dist/vite.d.ts +11 -0
- package/dist/vite.js +86 -0
- package/dist/walk-types.d.ts +4 -0
- package/dist/walk-types.js +56 -0
- package/dist/walk.d.ts +5 -0
- package/dist/walk.js +315 -0
- package/package.json +104 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type * as TS from 'typescript';
|
|
2
|
+
import type { Library } from '../checker/checker.ts';
|
|
3
|
+
import { type Type } from '../checker/types.ts';
|
|
4
|
+
import type { TypeConverter } from './convert.ts';
|
|
5
|
+
export declare class LibraryTypes implements Library {
|
|
6
|
+
private readonly checker;
|
|
7
|
+
private readonly converter;
|
|
8
|
+
private readonly values;
|
|
9
|
+
private readonly types;
|
|
10
|
+
private readonly converted;
|
|
11
|
+
constructor(ts: typeof TS, program: TS.Program, converter: TypeConverter);
|
|
12
|
+
value(name: string): Type | undefined;
|
|
13
|
+
type(name: string): Type | undefined;
|
|
14
|
+
primitive(kind: 'string' | 'number' | 'bigint' | 'bool'): Type | undefined;
|
|
15
|
+
array(element: Type): Type | undefined;
|
|
16
|
+
/** The element of a tag; custom elements like `<app-card>` are HTMLElement. */
|
|
17
|
+
element(tag: string, svg?: boolean): Type | undefined;
|
|
18
|
+
event(name: string): Type | undefined;
|
|
19
|
+
names(of: 'value' | 'type' | 'tag'): Iterable<string>;
|
|
20
|
+
/** `Map[key]` of an interface that maps names to types. */
|
|
21
|
+
private entry;
|
|
22
|
+
private cached;
|
|
23
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { instantiate } from "../checker/types.js";
|
|
2
|
+
/** The interfaces of the lib files with the members of the primitive types. */
|
|
3
|
+
const PRIMITIVE_TYPES = { string: 'String', number: 'Number', bigint: 'BigInt', bool: 'Boolean' };
|
|
4
|
+
// Globals of TypeScript's lib files (the standard library and the DOM) and of the `@types`
|
|
5
|
+
// packages, such as `process` from @types/node. Each name is converted when it is first used.
|
|
6
|
+
export class LibraryTypes {
|
|
7
|
+
checker;
|
|
8
|
+
converter;
|
|
9
|
+
values = new Map();
|
|
10
|
+
types = new Map();
|
|
11
|
+
converted = new Map();
|
|
12
|
+
constructor(ts, program, converter) {
|
|
13
|
+
this.checker = program.getTypeChecker();
|
|
14
|
+
this.converter = converter;
|
|
15
|
+
// The scope of a script file is the global scope.
|
|
16
|
+
const lib = program.getSourceFile(ts.getDefaultLibFilePath(program.getCompilerOptions()));
|
|
17
|
+
if (!lib)
|
|
18
|
+
return;
|
|
19
|
+
for (const symbol of this.checker.getSymbolsInScope(lib, ts.SymbolFlags.Value)) {
|
|
20
|
+
this.values.set(symbol.name, symbol);
|
|
21
|
+
}
|
|
22
|
+
for (const symbol of this.checker.getSymbolsInScope(lib, ts.SymbolFlags.Type)) {
|
|
23
|
+
this.types.set(symbol.name, symbol);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
value(name) {
|
|
27
|
+
return this.cached(`value ${name}`, () => {
|
|
28
|
+
const symbol = this.values.get(name);
|
|
29
|
+
return symbol && this.converter.valueType(symbol);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
type(name) {
|
|
33
|
+
return this.cached(`type ${name}`, () => {
|
|
34
|
+
const symbol = this.types.get(name);
|
|
35
|
+
return symbol && this.converter.typeOf(symbol);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
primitive(kind) {
|
|
39
|
+
return this.type(PRIMITIVE_TYPES[kind]);
|
|
40
|
+
}
|
|
41
|
+
array(element) {
|
|
42
|
+
const symbol = this.types.get('Array');
|
|
43
|
+
return symbol && instantiate(this.converter.arrayTemplate(symbol), [element]);
|
|
44
|
+
}
|
|
45
|
+
/** The element of a tag; custom elements like `<app-card>` are HTMLElement. */
|
|
46
|
+
element(tag, svg = false) {
|
|
47
|
+
if (svg) {
|
|
48
|
+
return this.cached(`svg ${tag}`, () => this.entry('SVGElementTagNameMap', tag) ?? this.type('SVGElement'));
|
|
49
|
+
}
|
|
50
|
+
return this.cached(`element ${tag}`, () => this.entry('HTMLElementTagNameMap', tag) ??
|
|
51
|
+
(tag.includes('-') ? this.type('HTMLElement') : undefined));
|
|
52
|
+
}
|
|
53
|
+
event(name) {
|
|
54
|
+
return this.cached(`event ${name}`, () => this.entry('HTMLElementEventMap', name));
|
|
55
|
+
}
|
|
56
|
+
names(of) {
|
|
57
|
+
if (of === 'value')
|
|
58
|
+
return this.values.keys();
|
|
59
|
+
if (of === 'type')
|
|
60
|
+
return this.types.keys();
|
|
61
|
+
const symbol = this.types.get('HTMLElementTagNameMap');
|
|
62
|
+
return symbol
|
|
63
|
+
? this.checker
|
|
64
|
+
.getPropertiesOfType(this.checker.getDeclaredTypeOfSymbol(symbol))
|
|
65
|
+
.map((property) => property.name)
|
|
66
|
+
: [];
|
|
67
|
+
}
|
|
68
|
+
/** `Map[key]` of an interface that maps names to types. */
|
|
69
|
+
entry(map, key) {
|
|
70
|
+
const symbol = this.types.get(map);
|
|
71
|
+
if (!symbol)
|
|
72
|
+
return undefined;
|
|
73
|
+
const property = this.checker.getPropertyOfType(this.checker.getDeclaredTypeOfSymbol(symbol), key);
|
|
74
|
+
return property && this.converter.convert(this.checker.getTypeOfSymbol(property));
|
|
75
|
+
}
|
|
76
|
+
cached(key, compute) {
|
|
77
|
+
if (!this.converted.has(key))
|
|
78
|
+
this.converted.set(key, compute());
|
|
79
|
+
return this.converted.get(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface RookPluginOptions {
|
|
3
|
+
/** Check types before generating code. Defaults to `true`. */
|
|
4
|
+
typeCheck?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Markup and components, for every `.rk` file; by default as the package.json of the file
|
|
7
|
+
* says, `"rook": { "markup": true }`.
|
|
8
|
+
*/
|
|
9
|
+
markup?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function rook(options?: RookPluginOptions): Plugin;
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { formatDiagnostic } from "./diagnostics.js";
|
|
4
|
+
import { compile } from "./index.js";
|
|
5
|
+
import { SourceFile } from "./source.js";
|
|
6
|
+
// A Vite plugin for Rook: `.rk` modules are compiled when Vite loads them, with type
|
|
7
|
+
// checking, so `import { App } from "./app.rk"` works in a Vite project. Type errors stop the
|
|
8
|
+
// build and show up in the browser overlay of the dev server. `app.rk.goroutines.js` is the
|
|
9
|
+
// worker module of `go` in app.rk, which Vite bundles as a worker: it is not a file, and its
|
|
10
|
+
// path has no query, since Vite drops the query of a worker's URL.
|
|
11
|
+
const GOROUTINES = '.goroutines.js';
|
|
12
|
+
export function rook(options = {}) {
|
|
13
|
+
const typeCheck = options.typeCheck ?? true;
|
|
14
|
+
let root = process.cwd();
|
|
15
|
+
return {
|
|
16
|
+
name: 'rooklang',
|
|
17
|
+
// Vite bundles workers with plugins of their own: the worker modules of `go` need this one too,
|
|
18
|
+
// and they are ES modules.
|
|
19
|
+
config(config) {
|
|
20
|
+
const plugins = config.worker?.plugins;
|
|
21
|
+
return {
|
|
22
|
+
worker: { format: 'es', plugins: () => [...(plugins?.() ?? []), rook(options)] },
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
configResolved(config) {
|
|
26
|
+
root = config.root;
|
|
27
|
+
},
|
|
28
|
+
resolveId(source, importer) {
|
|
29
|
+
const [path = source] = source.split('?');
|
|
30
|
+
if (!path.endsWith(`.rk${GOROUTINES}`))
|
|
31
|
+
return null;
|
|
32
|
+
if (!isAbsolute(path))
|
|
33
|
+
return resolve(dirname(importer ?? join(root, 'index.html')), path);
|
|
34
|
+
// `/app.rk.goroutines.js` from the dev server is a path in the root.
|
|
35
|
+
return path.startsWith(root) ? path : join(root, path);
|
|
36
|
+
},
|
|
37
|
+
load(id) {
|
|
38
|
+
const [path = id] = id.split('?');
|
|
39
|
+
if (!path.endsWith(`.rk${GOROUTINES}`))
|
|
40
|
+
return null;
|
|
41
|
+
return readFileSync(path.slice(0, -GOROUTINES.length), 'utf8');
|
|
42
|
+
},
|
|
43
|
+
transform(source, id) {
|
|
44
|
+
const [name = id, query] = id.split('?');
|
|
45
|
+
const worker = name.endsWith(`.rk${GOROUTINES}`);
|
|
46
|
+
const path = worker ? name.slice(0, -GOROUTINES.length) : name;
|
|
47
|
+
// `app.rk?raw` and the like are left to Vite; it adds queries of its own to workers.
|
|
48
|
+
if (!path.endsWith('.rk') || (query !== undefined && !worker))
|
|
49
|
+
return null;
|
|
50
|
+
// Imports keep `.rk`: Vite resolves them and gives them to this plugin again.
|
|
51
|
+
const result = compile(source, {
|
|
52
|
+
filename: path,
|
|
53
|
+
rewriteImports: false,
|
|
54
|
+
typeCheck,
|
|
55
|
+
markup: options.markup,
|
|
56
|
+
workerUrl: `./${basename(path)}${GOROUTINES}`,
|
|
57
|
+
});
|
|
58
|
+
const file = new SourceFile(relative(root, path), source);
|
|
59
|
+
// Vite counts columns from 0.
|
|
60
|
+
const loc = (start) => {
|
|
61
|
+
const { line, column } = file.position(start);
|
|
62
|
+
return { line, column: column - 1 };
|
|
63
|
+
};
|
|
64
|
+
for (const warning of result.warnings) {
|
|
65
|
+
this.warn({
|
|
66
|
+
message: formatDiagnostic(file, warning, 'warning'),
|
|
67
|
+
id,
|
|
68
|
+
loc: loc(warning.start),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (result.diagnostics.length > 0) {
|
|
72
|
+
this.error({
|
|
73
|
+
message: result.diagnostics.map((d) => formatDiagnostic(file, d)).join('\n\n'),
|
|
74
|
+
id,
|
|
75
|
+
loc: loc(result.diagnostics[0].start),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// The code of imported decorators is inlined here, and their types are used: when an
|
|
79
|
+
// imported module changes, this one is compiled again.
|
|
80
|
+
for (const dependency of result.dependencies) {
|
|
81
|
+
this.addWatchFile(resolve(dirname(path), dependency));
|
|
82
|
+
}
|
|
83
|
+
return { code: worker ? (result.worker ?? '') : result.code, map: null };
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export function forEachTypeChild(node, visit) {
|
|
2
|
+
const each = (nodes) => {
|
|
3
|
+
for (const child of nodes)
|
|
4
|
+
visit(child);
|
|
5
|
+
};
|
|
6
|
+
const optional = (child) => {
|
|
7
|
+
if (child)
|
|
8
|
+
visit(child);
|
|
9
|
+
};
|
|
10
|
+
switch (node.kind) {
|
|
11
|
+
case 'TypeReference':
|
|
12
|
+
visit(node.name);
|
|
13
|
+
each(node.typeArgs);
|
|
14
|
+
break;
|
|
15
|
+
case 'TypeParameter':
|
|
16
|
+
visit(node.name);
|
|
17
|
+
optional(node.constraint);
|
|
18
|
+
break;
|
|
19
|
+
case 'ArrayType':
|
|
20
|
+
case 'ChanType':
|
|
21
|
+
visit(node.element);
|
|
22
|
+
break;
|
|
23
|
+
case 'NullableType':
|
|
24
|
+
visit(node.type);
|
|
25
|
+
break;
|
|
26
|
+
case 'FuncType':
|
|
27
|
+
each(node.params);
|
|
28
|
+
each(node.results);
|
|
29
|
+
break;
|
|
30
|
+
case 'ComponentType':
|
|
31
|
+
each(node.params);
|
|
32
|
+
break;
|
|
33
|
+
case 'ObjectType':
|
|
34
|
+
each(node.members);
|
|
35
|
+
break;
|
|
36
|
+
case 'UnionType':
|
|
37
|
+
each(node.types);
|
|
38
|
+
break;
|
|
39
|
+
case 'LiteralType':
|
|
40
|
+
visit(node.value);
|
|
41
|
+
break;
|
|
42
|
+
case 'PropertySignature':
|
|
43
|
+
visit(node.name);
|
|
44
|
+
visit(node.type);
|
|
45
|
+
break;
|
|
46
|
+
case 'IndexSignature':
|
|
47
|
+
visit(node.key);
|
|
48
|
+
visit(node.type);
|
|
49
|
+
break;
|
|
50
|
+
case 'MethodSignature':
|
|
51
|
+
visit(node.name);
|
|
52
|
+
each(node.params);
|
|
53
|
+
each(node.results);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
package/dist/walk.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as ast from './ast.ts';
|
|
2
|
+
/** Calls `visit` for each direct child of `node`, in source order. */
|
|
3
|
+
export declare function forEachChild(node: ast.Node, visit: (child: ast.Node) => void): void;
|
|
4
|
+
/** Whether a `break` in these statements leaves the enclosing loop or switch. */
|
|
5
|
+
export declare function containsBreak(statements: readonly ast.Statement[]): boolean;
|
package/dist/walk.js
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { forEachTypeChild } from "./walk-types.js";
|
|
2
|
+
/** Calls `visit` for each direct child of `node`, in source order. */
|
|
3
|
+
export function forEachChild(node, visit) {
|
|
4
|
+
const each = (nodes) => {
|
|
5
|
+
for (const child of nodes)
|
|
6
|
+
visit(child);
|
|
7
|
+
};
|
|
8
|
+
const optional = (child) => {
|
|
9
|
+
if (child)
|
|
10
|
+
visit(child);
|
|
11
|
+
};
|
|
12
|
+
switch (node.kind) {
|
|
13
|
+
case 'Program':
|
|
14
|
+
case 'BlockStatement':
|
|
15
|
+
each(node.body);
|
|
16
|
+
break;
|
|
17
|
+
case 'ImportDeclaration':
|
|
18
|
+
optional(node.defaultImport);
|
|
19
|
+
optional(node.namespaceImport);
|
|
20
|
+
each(node.namedImports);
|
|
21
|
+
visit(node.source);
|
|
22
|
+
break;
|
|
23
|
+
case 'ImportSpecifier':
|
|
24
|
+
visit(node.imported);
|
|
25
|
+
if (node.local !== node.imported)
|
|
26
|
+
visit(node.local);
|
|
27
|
+
break;
|
|
28
|
+
case 'FuncDeclaration':
|
|
29
|
+
case 'MethodDeclaration':
|
|
30
|
+
visit(node.name);
|
|
31
|
+
each(node.params);
|
|
32
|
+
each(node.results);
|
|
33
|
+
visit(node.body);
|
|
34
|
+
break;
|
|
35
|
+
case 'Parameter':
|
|
36
|
+
visit(node.name);
|
|
37
|
+
optional(node.type);
|
|
38
|
+
optional(node.defaultValue);
|
|
39
|
+
break;
|
|
40
|
+
case 'ComponentDeclaration':
|
|
41
|
+
visit(node.name);
|
|
42
|
+
each(node.decorators);
|
|
43
|
+
each(node.params);
|
|
44
|
+
visit(node.body);
|
|
45
|
+
break;
|
|
46
|
+
case 'DecoratorDeclaration':
|
|
47
|
+
// The names after `needs` are other decorators', not values in scope.
|
|
48
|
+
visit(node.name);
|
|
49
|
+
each(node.params);
|
|
50
|
+
visit(node.body);
|
|
51
|
+
break;
|
|
52
|
+
case 'DecoratorUse':
|
|
53
|
+
// The name is the decorator's, not a value in scope.
|
|
54
|
+
each(node.arguments);
|
|
55
|
+
break;
|
|
56
|
+
case 'DecoratorGet':
|
|
57
|
+
visit(node.target);
|
|
58
|
+
break;
|
|
59
|
+
case 'VariableDeclaration':
|
|
60
|
+
each(node.names);
|
|
61
|
+
optional(node.type);
|
|
62
|
+
each(node.values);
|
|
63
|
+
break;
|
|
64
|
+
case 'ClassDeclaration':
|
|
65
|
+
visit(node.name);
|
|
66
|
+
optional(node.superClass);
|
|
67
|
+
each(node.implements);
|
|
68
|
+
each(node.members);
|
|
69
|
+
break;
|
|
70
|
+
case 'FieldDeclaration':
|
|
71
|
+
visit(node.name);
|
|
72
|
+
optional(node.type);
|
|
73
|
+
optional(node.value);
|
|
74
|
+
break;
|
|
75
|
+
case 'ConstructorDeclaration':
|
|
76
|
+
each(node.params);
|
|
77
|
+
visit(node.body);
|
|
78
|
+
break;
|
|
79
|
+
case 'InterfaceDeclaration':
|
|
80
|
+
visit(node.name);
|
|
81
|
+
each(node.members);
|
|
82
|
+
break;
|
|
83
|
+
case 'TypeAliasDeclaration':
|
|
84
|
+
visit(node.name);
|
|
85
|
+
visit(node.type);
|
|
86
|
+
break;
|
|
87
|
+
case 'ExpressionStatement':
|
|
88
|
+
visit(node.expression);
|
|
89
|
+
break;
|
|
90
|
+
case 'AssignmentStatement':
|
|
91
|
+
each(node.targets);
|
|
92
|
+
each(node.values);
|
|
93
|
+
break;
|
|
94
|
+
case 'IncDecStatement':
|
|
95
|
+
case 'DeleteStatement':
|
|
96
|
+
visit(node.target);
|
|
97
|
+
break;
|
|
98
|
+
case 'SendStatement':
|
|
99
|
+
visit(node.channel);
|
|
100
|
+
visit(node.value);
|
|
101
|
+
break;
|
|
102
|
+
case 'ChanExpression':
|
|
103
|
+
visit(node.element);
|
|
104
|
+
optional(node.size);
|
|
105
|
+
break;
|
|
106
|
+
case 'MakeExpression':
|
|
107
|
+
visit(node.type);
|
|
108
|
+
visit(node.length);
|
|
109
|
+
break;
|
|
110
|
+
case 'ConversionExpression':
|
|
111
|
+
visit(node.type);
|
|
112
|
+
visit(node.argument);
|
|
113
|
+
break;
|
|
114
|
+
case 'ReturnStatement':
|
|
115
|
+
each(node.values);
|
|
116
|
+
break;
|
|
117
|
+
case 'IfStatement':
|
|
118
|
+
visit(node.condition);
|
|
119
|
+
visit(node.consequent);
|
|
120
|
+
optional(node.alternate);
|
|
121
|
+
break;
|
|
122
|
+
case 'ForStatement':
|
|
123
|
+
optional(node.init);
|
|
124
|
+
optional(node.condition);
|
|
125
|
+
optional(node.update);
|
|
126
|
+
visit(node.body);
|
|
127
|
+
break;
|
|
128
|
+
case 'ForInStatement':
|
|
129
|
+
optional(node.key);
|
|
130
|
+
visit(node.value);
|
|
131
|
+
visit(node.iterable);
|
|
132
|
+
visit(node.body);
|
|
133
|
+
break;
|
|
134
|
+
case 'SwitchStatement':
|
|
135
|
+
optional(node.discriminant);
|
|
136
|
+
each(node.cases);
|
|
137
|
+
break;
|
|
138
|
+
case 'SwitchCase':
|
|
139
|
+
each(node.tests);
|
|
140
|
+
each(node.body);
|
|
141
|
+
break;
|
|
142
|
+
case 'SelectStatement':
|
|
143
|
+
each(node.cases);
|
|
144
|
+
break;
|
|
145
|
+
case 'SelectCase':
|
|
146
|
+
each(node.names);
|
|
147
|
+
optional(node.operation);
|
|
148
|
+
each(node.body);
|
|
149
|
+
break;
|
|
150
|
+
case 'ThrowStatement':
|
|
151
|
+
visit(node.argument);
|
|
152
|
+
break;
|
|
153
|
+
case 'TryStatement':
|
|
154
|
+
visit(node.block);
|
|
155
|
+
optional(node.handler);
|
|
156
|
+
optional(node.finalizer);
|
|
157
|
+
break;
|
|
158
|
+
case 'CatchClause':
|
|
159
|
+
optional(node.param);
|
|
160
|
+
visit(node.body);
|
|
161
|
+
break;
|
|
162
|
+
case 'DeferStatement':
|
|
163
|
+
case 'MountStatement':
|
|
164
|
+
case 'EffectStatement':
|
|
165
|
+
visit(node.body);
|
|
166
|
+
break;
|
|
167
|
+
case 'StyleStatement':
|
|
168
|
+
each(node.parts);
|
|
169
|
+
break;
|
|
170
|
+
case 'TemplateLiteral':
|
|
171
|
+
node.quasis.forEach((quasi, i) => {
|
|
172
|
+
visit(quasi);
|
|
173
|
+
optional(node.expressions[i] ?? null);
|
|
174
|
+
});
|
|
175
|
+
break;
|
|
176
|
+
case 'ArrayLiteral':
|
|
177
|
+
each(node.elements);
|
|
178
|
+
break;
|
|
179
|
+
case 'ObjectLiteral':
|
|
180
|
+
each(node.properties);
|
|
181
|
+
break;
|
|
182
|
+
case 'Property':
|
|
183
|
+
visit(node.key);
|
|
184
|
+
visit(node.value);
|
|
185
|
+
break;
|
|
186
|
+
case 'SpreadElement':
|
|
187
|
+
visit(node.argument);
|
|
188
|
+
break;
|
|
189
|
+
case 'FuncExpression':
|
|
190
|
+
each(node.params);
|
|
191
|
+
each(node.results);
|
|
192
|
+
visit(node.body);
|
|
193
|
+
break;
|
|
194
|
+
case 'ArrowFunction':
|
|
195
|
+
each(node.params);
|
|
196
|
+
visit(node.body);
|
|
197
|
+
break;
|
|
198
|
+
case 'UnaryExpression':
|
|
199
|
+
visit(node.argument);
|
|
200
|
+
break;
|
|
201
|
+
case 'GoExpression':
|
|
202
|
+
visit(node.call);
|
|
203
|
+
break;
|
|
204
|
+
case 'BinaryExpression':
|
|
205
|
+
visit(node.left);
|
|
206
|
+
visit(node.right);
|
|
207
|
+
break;
|
|
208
|
+
case 'AsExpression':
|
|
209
|
+
visit(node.expression);
|
|
210
|
+
visit(node.type);
|
|
211
|
+
break;
|
|
212
|
+
case 'ConditionalExpression':
|
|
213
|
+
visit(node.test);
|
|
214
|
+
visit(node.consequent);
|
|
215
|
+
visit(node.alternate);
|
|
216
|
+
break;
|
|
217
|
+
case 'CallExpression':
|
|
218
|
+
case 'NewExpression':
|
|
219
|
+
visit(node.callee);
|
|
220
|
+
each(node.arguments);
|
|
221
|
+
break;
|
|
222
|
+
case 'MemberExpression':
|
|
223
|
+
visit(node.object);
|
|
224
|
+
visit(node.property);
|
|
225
|
+
break;
|
|
226
|
+
case 'IndexExpression':
|
|
227
|
+
visit(node.object);
|
|
228
|
+
visit(node.index);
|
|
229
|
+
break;
|
|
230
|
+
case 'ElementExpression':
|
|
231
|
+
optional(node.tag);
|
|
232
|
+
optional(node.value);
|
|
233
|
+
each(node.attributes);
|
|
234
|
+
each(node.children);
|
|
235
|
+
break;
|
|
236
|
+
case 'JsxExpressionContainer':
|
|
237
|
+
visit(node.expression);
|
|
238
|
+
break;
|
|
239
|
+
case 'JsxStatementContainer':
|
|
240
|
+
visit(node.statement);
|
|
241
|
+
break;
|
|
242
|
+
case 'JsxElementStatement':
|
|
243
|
+
visit(node.element);
|
|
244
|
+
break;
|
|
245
|
+
case 'JsxAttribute':
|
|
246
|
+
visit(node.name);
|
|
247
|
+
optional(node.value);
|
|
248
|
+
break;
|
|
249
|
+
case 'JsxSpreadAttribute':
|
|
250
|
+
visit(node.argument);
|
|
251
|
+
break;
|
|
252
|
+
case 'EventHandler':
|
|
253
|
+
each(node.body);
|
|
254
|
+
break;
|
|
255
|
+
case 'TypeReference':
|
|
256
|
+
case 'TypeParameter':
|
|
257
|
+
case 'ArrayType':
|
|
258
|
+
case 'ChanType':
|
|
259
|
+
case 'NullableType':
|
|
260
|
+
case 'FuncType':
|
|
261
|
+
case 'ComponentType':
|
|
262
|
+
case 'ObjectType':
|
|
263
|
+
case 'UnionType':
|
|
264
|
+
case 'LiteralType':
|
|
265
|
+
case 'PropertySignature':
|
|
266
|
+
case 'IndexSignature':
|
|
267
|
+
case 'MethodSignature':
|
|
268
|
+
forEachTypeChild(node, visit);
|
|
269
|
+
break;
|
|
270
|
+
// Its names belong to the decorator, not to any scope.
|
|
271
|
+
case 'DecoratorMember':
|
|
272
|
+
break;
|
|
273
|
+
case 'BreakStatement':
|
|
274
|
+
case 'ContinueStatement':
|
|
275
|
+
case 'JsxText':
|
|
276
|
+
case 'CssText':
|
|
277
|
+
case 'Identifier':
|
|
278
|
+
case 'NumberLiteral':
|
|
279
|
+
case 'BigIntLiteral':
|
|
280
|
+
case 'StringLiteral':
|
|
281
|
+
case 'TemplateElement':
|
|
282
|
+
case 'BooleanLiteral':
|
|
283
|
+
case 'NullLiteral':
|
|
284
|
+
case 'ThisExpression':
|
|
285
|
+
case 'SuperExpression':
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** Whether a `break` in these statements leaves the enclosing loop or switch. */
|
|
290
|
+
export function containsBreak(statements) {
|
|
291
|
+
let found = false;
|
|
292
|
+
const visit = (node) => {
|
|
293
|
+
switch (node.kind) {
|
|
294
|
+
case 'BreakStatement':
|
|
295
|
+
found = true;
|
|
296
|
+
return;
|
|
297
|
+
// A `break` inside these belongs to them.
|
|
298
|
+
case 'ForStatement':
|
|
299
|
+
case 'ForInStatement':
|
|
300
|
+
case 'SwitchStatement':
|
|
301
|
+
case 'SelectStatement':
|
|
302
|
+
case 'FuncDeclaration':
|
|
303
|
+
case 'FuncExpression':
|
|
304
|
+
case 'ArrowFunction':
|
|
305
|
+
case 'ClassDeclaration':
|
|
306
|
+
case 'MountStatement':
|
|
307
|
+
case 'EffectStatement':
|
|
308
|
+
return;
|
|
309
|
+
default:
|
|
310
|
+
forEachChild(node, visit);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
statements.forEach(visit);
|
|
314
|
+
return found;
|
|
315
|
+
}
|