@ttsc/wasm 0.11.0-dev.20260517
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 +125 -0
- package/build/build-wasm.cjs +240 -0
- package/build/pack-prepare.cjs +68 -0
- package/cmd/ttsc-wasm/main.go +130 -0
- package/cmd/ttsc-wasm/main_wasm.go +17 -0
- package/dist/go.mod +54 -0
- package/dist/ttsc.wasm +0 -0
- package/dist/wasm_exec.js +575 -0
- package/go.mod +54 -0
- package/go.sum +26 -0
- package/host/api.go +205 -0
- package/host/doc.go +31 -0
- package/host/host.go +317 -0
- package/host/host_native.go +12 -0
- package/host/plugin.go +59 -0
- package/lib/src/MemFS.d.ts +68 -0
- package/lib/src/MemFS.js +384 -0
- package/lib/src/MemFS.js.map +1 -0
- package/lib/src/api.d.ts +87 -0
- package/lib/src/api.js +20 -0
- package/lib/src/api.js.map +1 -0
- package/lib/src/index.d.ts +6 -0
- package/lib/src/index.js +10 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/instantiate.d.ts +27 -0
- package/lib/src/instantiate.js +71 -0
- package/lib/src/instantiate.js.map +1 -0
- package/package.json +49 -0
- package/src/MemFS.ts +566 -0
- package/src/api.ts +112 -0
- package/src/index.ts +28 -0
- package/src/instantiate.ts +114 -0
- package/vendor/shim/ast/extra-shim.json +4 -0
- package/vendor/shim/ast/go.mod +5 -0
- package/vendor/shim/ast/lint.go +328 -0
- package/vendor/shim/ast/shim.go +220 -0
- package/vendor/shim/ast/surface.go +685 -0
- package/vendor/shim/bundled/extra-shim.json +1 -0
- package/vendor/shim/bundled/go.mod +5 -0
- package/vendor/shim/bundled/shim.go +23 -0
- package/vendor/shim/checker/extra-shim.json +31 -0
- package/vendor/shim/checker/go.mod +5 -0
- package/vendor/shim/checker/shim.go +174 -0
- package/vendor/shim/compiler/extra-shim.json +4 -0
- package/vendor/shim/compiler/go.mod +5 -0
- package/vendor/shim/compiler/shim.go +65 -0
- package/vendor/shim/core/extra-shim.json +4 -0
- package/vendor/shim/core/go.mod +5 -0
- package/vendor/shim/core/shim.go +29 -0
- package/vendor/shim/diagnosticwriter/go.mod +5 -0
- package/vendor/shim/diagnosticwriter/lint.go +145 -0
- package/vendor/shim/diagnosticwriter/shim.go +29 -0
- package/vendor/shim/lsp/extra-shim.json +4 -0
- package/vendor/shim/lsp/go.mod +16 -0
- package/vendor/shim/lsp/go.sum +26 -0
- package/vendor/shim/lsp/shim.go +42 -0
- package/vendor/shim/parser/extra-shim.json +4 -0
- package/vendor/shim/parser/go.mod +5 -0
- package/vendor/shim/parser/shim.go +61 -0
- package/vendor/shim/printer/go.mod +5 -0
- package/vendor/shim/printer/shim.go +23 -0
- package/vendor/shim/scanner/extra-shim.json +4 -0
- package/vendor/shim/scanner/go.mod +5 -0
- package/vendor/shim/scanner/shim.go +134 -0
- package/vendor/shim/tsoptions/extra-shim.json +4 -0
- package/vendor/shim/tsoptions/go.mod +5 -0
- package/vendor/shim/tsoptions/shim.go +173 -0
- package/vendor/shim/tspath/extra-shim.json +4 -0
- package/vendor/shim/tspath/go.mod +5 -0
- package/vendor/shim/tspath/shim.go +236 -0
- package/vendor/shim/vfs/cachedvfs/extra-shim.json +4 -0
- package/vendor/shim/vfs/cachedvfs/go.mod +5 -0
- package/vendor/shim/vfs/cachedvfs/shim.go +12 -0
- package/vendor/shim/vfs/extra-shim.json +4 -0
- package/vendor/shim/vfs/go.mod +5 -0
- package/vendor/shim/vfs/osvfs/extra-shim.json +4 -0
- package/vendor/shim/vfs/osvfs/go.mod +5 -0
- package/vendor/shim/vfs/osvfs/shim.go +13 -0
- package/vendor/shim/vfs/shim.go +22 -0
package/src/api.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Type-safe wrapper around the `globalThis[apiName]` object a host-built wasm
|
|
2
|
+
// installs. Every consumer wasm (the base `ttsc.wasm`, the website's
|
|
3
|
+
// `playground.wasm`, typia's `ttsc-typia.wasm`) exposes the same surface, so
|
|
4
|
+
// one set of types covers them all.
|
|
5
|
+
|
|
6
|
+
export interface ITtscApi {
|
|
7
|
+
/** Build metadata reported by the wasm. Useful for diagnostics. */
|
|
8
|
+
version(): ITtscVersion;
|
|
9
|
+
|
|
10
|
+
/** Compile a project: typecheck + emit. `result` is JSON; `parseResult<ITtscCompileResult>` deserializes it. */
|
|
11
|
+
build(opts: ITtscBuildOpts): Promise<ITtscResult>;
|
|
12
|
+
|
|
13
|
+
/** Typecheck without emit. `result` is JSON; `parseResult<ITtscCompileResult>` deserializes it. */
|
|
14
|
+
check(opts: ITtscBuildOpts): Promise<ITtscResult>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Return every source file the program saw, keyed by project-relative
|
|
18
|
+
* path. Used by playgrounds that want to render the TypeScript view after
|
|
19
|
+
* a source rewriter (e.g. paths) has run. `result` is JSON; use
|
|
20
|
+
* `parseResult<ITtscTransformResult>` to deserialize.
|
|
21
|
+
*/
|
|
22
|
+
transform(opts: ITtscBuildOpts): Promise<ITtscResult>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Dispatch a registered plugin's subcommand. Returns the captured stdout /
|
|
26
|
+
* stderr (the same streams the native sidecar binary would write to)
|
|
27
|
+
* together with the exit code.
|
|
28
|
+
*/
|
|
29
|
+
plugin(opts: ITtscPluginOpts): Promise<ITtscResult>;
|
|
30
|
+
|
|
31
|
+
/** Names of the plugins this wasm was built with. */
|
|
32
|
+
plugins(): string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ITtscVersion {
|
|
36
|
+
version: string;
|
|
37
|
+
commit: string;
|
|
38
|
+
date: string;
|
|
39
|
+
go: string;
|
|
40
|
+
goos: string;
|
|
41
|
+
goarch: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ITtscBuildOpts {
|
|
45
|
+
/** Absolute virtual path the project lives at inside the MemFS. */
|
|
46
|
+
cwd: string;
|
|
47
|
+
/** tsconfig path, relative to `cwd`. Defaults to `tsconfig.json`. */
|
|
48
|
+
tsconfig?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ITtscPluginOpts {
|
|
52
|
+
/** Plugin id registered with `host.Expose` (e.g. `@ttsc/banner`). */
|
|
53
|
+
name: string;
|
|
54
|
+
/** Subcommand the plugin's Run will receive (e.g. `build`). */
|
|
55
|
+
command: string;
|
|
56
|
+
/** Forwarded as `--cwd=<value>`. */
|
|
57
|
+
cwd?: string;
|
|
58
|
+
/** Forwarded as `--tsconfig=<value>`. Defaults to `tsconfig.json`. */
|
|
59
|
+
tsconfig?: string;
|
|
60
|
+
/** Any extra key/value pairs map to `--key=value` argv entries. */
|
|
61
|
+
[key: string]: string | boolean | number | undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ITtscResult {
|
|
65
|
+
/** Exit code. 0 = success, 2 = usage error, 3 = runtime error. */
|
|
66
|
+
code: number;
|
|
67
|
+
/** Anything the wasm wrote to its stdout stream. */
|
|
68
|
+
stdout: string;
|
|
69
|
+
/** Anything the wasm wrote to its stderr stream. */
|
|
70
|
+
stderr: string;
|
|
71
|
+
/**
|
|
72
|
+
* For the base endpoints, the JSON-encoded compile/transform result. For
|
|
73
|
+
* the plugin endpoint, this is empty — the plugin's own output sits in
|
|
74
|
+
* stdout/stderr. Use `parseResult<T>` to deserialize.
|
|
75
|
+
*/
|
|
76
|
+
result: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ITtscCompileResult {
|
|
80
|
+
diagnostics?: ITtscDiagnostic[];
|
|
81
|
+
output: Record<string, string>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ITtscTransformResult {
|
|
85
|
+
diagnostics?: ITtscDiagnostic[];
|
|
86
|
+
typescript: Record<string, string>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface ITtscDiagnostic {
|
|
90
|
+
file: string | null;
|
|
91
|
+
category: "error" | "warning";
|
|
92
|
+
code: number;
|
|
93
|
+
start?: number;
|
|
94
|
+
length?: number;
|
|
95
|
+
line?: number;
|
|
96
|
+
character?: number;
|
|
97
|
+
messageText: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Parse the `result` field of an ITtscResult into the structured payload.
|
|
102
|
+
* The wasm returns JSON as a string because js.ValueOf does not handle large
|
|
103
|
+
* nested maps efficiently. Callers JSON.parse exactly once at the boundary.
|
|
104
|
+
*/
|
|
105
|
+
export function parseResult<T>(result: ITtscResult): T | null {
|
|
106
|
+
if (!result.result) return null;
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(result.result) as T;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Public entry point for `@ttsc/wasm`.
|
|
2
|
+
//
|
|
3
|
+
// Re-exports the boot helper, MemFS bridge, and typed API surface. Plugin
|
|
4
|
+
// authors and playground builders consume these. The Go-side scaffolding
|
|
5
|
+
// (`host/`) is shipped alongside on disk but loaded via `go build`, not
|
|
6
|
+
// imported from JS.
|
|
7
|
+
|
|
8
|
+
export { bootTtsc } from "./instantiate";
|
|
9
|
+
export type { IBootTtscOptions, IBootResult } from "./instantiate";
|
|
10
|
+
|
|
11
|
+
export { createMemFS, MemFSError } from "./MemFS";
|
|
12
|
+
export type {
|
|
13
|
+
IMemFSHost,
|
|
14
|
+
IWasmExecFS,
|
|
15
|
+
IFileStats,
|
|
16
|
+
} from "./MemFS";
|
|
17
|
+
|
|
18
|
+
export type {
|
|
19
|
+
ITtscApi,
|
|
20
|
+
ITtscVersion,
|
|
21
|
+
ITtscBuildOpts,
|
|
22
|
+
ITtscPluginOpts,
|
|
23
|
+
ITtscResult,
|
|
24
|
+
ITtscCompileResult,
|
|
25
|
+
ITtscTransformResult,
|
|
26
|
+
ITtscDiagnostic,
|
|
27
|
+
} from "./api";
|
|
28
|
+
export { parseResult } from "./api";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// Boots a host-built wasm and returns the JS-side handle.
|
|
2
|
+
//
|
|
3
|
+
// Order of operations matters: wasm_exec.js installs default no-op fs/process
|
|
4
|
+
// shims if `globalThis.fs` is missing at load time, so we must install our
|
|
5
|
+
// MemFS BEFORE importing wasm_exec.js.
|
|
6
|
+
//
|
|
7
|
+
// The boot helper is parameterized by `apiName` so any wasm built with
|
|
8
|
+
// `host.Expose(...)` can be loaded the same way. The base wasm uses "ttsc";
|
|
9
|
+
// downstream consumers pick their own (e.g. "ttscPlayground", "ttscTypia").
|
|
10
|
+
|
|
11
|
+
import { createMemFS, type IMemFSHost } from "./MemFS";
|
|
12
|
+
import type { ITtscApi } from "./api";
|
|
13
|
+
|
|
14
|
+
declare const importScripts: (...urls: string[]) => void;
|
|
15
|
+
|
|
16
|
+
export interface IBootTtscOptions {
|
|
17
|
+
/** URL of the .wasm to fetch. */
|
|
18
|
+
wasmUrl: string;
|
|
19
|
+
/** URL of wasm_exec.js. Defaults to the same directory as wasmUrl. */
|
|
20
|
+
wasmExecUrl?: string;
|
|
21
|
+
/**
|
|
22
|
+
* globalThis property name the wasm binds. Must match the value the wasm
|
|
23
|
+
* was built with (the `apiName` passed to `host.Expose`). Defaults to
|
|
24
|
+
* "ttsc".
|
|
25
|
+
*/
|
|
26
|
+
apiName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Optional pre-existing MemFS host. When omitted, a fresh one is created
|
|
29
|
+
* and stored on the returned BootResult. Pass an existing host when you
|
|
30
|
+
* want to boot multiple wasms over the same filesystem (e.g. base ttsc +
|
|
31
|
+
* a typia wasm) so they share project sources.
|
|
32
|
+
*/
|
|
33
|
+
host?: IMemFSHost;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IBootResult {
|
|
37
|
+
api: ITtscApi;
|
|
38
|
+
host: IMemFSHost;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Boot a host-built wasm. Re-entrant only if you reuse the same `host`. */
|
|
42
|
+
export async function bootTtsc(options: IBootTtscOptions): Promise<IBootResult> {
|
|
43
|
+
const wasmUrl = options.wasmUrl;
|
|
44
|
+
const wasmExecUrl = options.wasmExecUrl ?? defaultWasmExecUrl(wasmUrl);
|
|
45
|
+
const apiName = options.apiName ?? "ttsc";
|
|
46
|
+
|
|
47
|
+
const host = options.host ?? createMemFS();
|
|
48
|
+
const globalAny = globalThis as Record<string, unknown>;
|
|
49
|
+
// Only install fs / process if they aren't already in place. A caller
|
|
50
|
+
// booting a second wasm over the same MemFS reuses the same shims.
|
|
51
|
+
if (!globalAny.fs) globalAny.fs = host.fs;
|
|
52
|
+
if (!globalAny.process) globalAny.process = createProcessShim();
|
|
53
|
+
|
|
54
|
+
// wasm_exec.js installs `globalThis.Go`. It also reads globalThis.fs at
|
|
55
|
+
// module-eval time, so this import must follow the assignment above.
|
|
56
|
+
importScripts(wasmExecUrl);
|
|
57
|
+
|
|
58
|
+
const ready = new Promise<void>((resolve) => {
|
|
59
|
+
globalAny[apiName + "Ready"] = resolve;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const goCtor = (globalAny as { Go: new () => IGoInstance }).Go;
|
|
63
|
+
const go = new goCtor();
|
|
64
|
+
|
|
65
|
+
const response = await fetch(wasmUrl);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`bootTtsc: failed to fetch ${wasmUrl}: ${response.status}`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const wasm = await WebAssembly.instantiateStreaming(response, go.importObject);
|
|
72
|
+
// go.run never resolves until the wasm exits; we don't await it.
|
|
73
|
+
void go.run(wasm.instance);
|
|
74
|
+
await ready;
|
|
75
|
+
|
|
76
|
+
const api = (globalAny as Record<string, ITtscApi | undefined>)[apiName];
|
|
77
|
+
if (!api)
|
|
78
|
+
throw new Error(
|
|
79
|
+
`bootTtsc: ${apiName} global was not set — was the wasm built with host.Expose(${JSON.stringify(apiName)}, ...)?`,
|
|
80
|
+
);
|
|
81
|
+
return { api, host };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function defaultWasmExecUrl(wasmUrl: string): string {
|
|
85
|
+
const slash = wasmUrl.lastIndexOf("/");
|
|
86
|
+
if (slash < 0) return "wasm_exec.js";
|
|
87
|
+
return wasmUrl.slice(0, slash + 1) + "wasm_exec.js";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface IGoInstance {
|
|
91
|
+
importObject: WebAssembly.Imports;
|
|
92
|
+
run(instance: WebAssembly.Instance): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function createProcessShim(): Record<string, unknown> {
|
|
96
|
+
return {
|
|
97
|
+
getuid: () => -1,
|
|
98
|
+
getgid: () => -1,
|
|
99
|
+
geteuid: () => -1,
|
|
100
|
+
getegid: () => -1,
|
|
101
|
+
getgroups: () => {
|
|
102
|
+
throw new Error("not implemented");
|
|
103
|
+
},
|
|
104
|
+
pid: -1,
|
|
105
|
+
ppid: -1,
|
|
106
|
+
umask: () => {
|
|
107
|
+
throw new Error("not implemented");
|
|
108
|
+
},
|
|
109
|
+
cwd: () => "/",
|
|
110
|
+
chdir: () => {
|
|
111
|
+
/* no-op; the workspace lives inside the MemFS */
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
// Lint-oriented additions to the AST shim.
|
|
2
|
+
//
|
|
3
|
+
// This file groups the helpers and node-flag constants the `@ttsc/lint`
|
|
4
|
+
// plugin needs to navigate the tree.
|
|
5
|
+
//
|
|
6
|
+
// Everything here is a pure re-export of `internal/ast` symbols — there is
|
|
7
|
+
// no behavior, no copy of upstream logic. Adding a new node type is
|
|
8
|
+
// mechanical: add a `type X = innerast.X` line and the matching
|
|
9
|
+
// `KindX = innerast.KindX` entry.
|
|
10
|
+
package ast
|
|
11
|
+
|
|
12
|
+
import (
|
|
13
|
+
innerast "github.com/microsoft/typescript-go/internal/ast"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// ---- Node-list / visitor primitives ----
|
|
17
|
+
|
|
18
|
+
type Visitor = innerast.Visitor
|
|
19
|
+
type NodeFlags = innerast.NodeFlags
|
|
20
|
+
type ModifierFlags = innerast.ModifierFlags
|
|
21
|
+
|
|
22
|
+
// ---- Statement-shaped node types ----
|
|
23
|
+
|
|
24
|
+
type Block = innerast.Block
|
|
25
|
+
type BreakStatement = innerast.BreakStatement
|
|
26
|
+
type CaseBlock = innerast.CaseBlock
|
|
27
|
+
type CaseOrDefaultClause = innerast.CaseOrDefaultClause
|
|
28
|
+
type CatchClause = innerast.CatchClause
|
|
29
|
+
type ContinueStatement = innerast.ContinueStatement
|
|
30
|
+
type DebuggerStatement = innerast.DebuggerStatement
|
|
31
|
+
type DoStatement = innerast.DoStatement
|
|
32
|
+
type EmptyStatement = innerast.EmptyStatement
|
|
33
|
+
type ExpressionStatement = innerast.ExpressionStatement
|
|
34
|
+
type ForInOrOfStatement = innerast.ForInOrOfStatement
|
|
35
|
+
type ForStatement = innerast.ForStatement
|
|
36
|
+
type FunctionDeclaration = innerast.FunctionDeclaration
|
|
37
|
+
type IfStatement = innerast.IfStatement
|
|
38
|
+
type LabeledStatement = innerast.LabeledStatement
|
|
39
|
+
type ModuleDeclaration = innerast.ModuleDeclaration
|
|
40
|
+
type ModuleBlock = innerast.ModuleBlock
|
|
41
|
+
type ReturnStatement = innerast.ReturnStatement
|
|
42
|
+
type SwitchStatement = innerast.SwitchStatement
|
|
43
|
+
type ThrowStatement = innerast.ThrowStatement
|
|
44
|
+
type TryStatement = innerast.TryStatement
|
|
45
|
+
type VariableDeclaration = innerast.VariableDeclaration
|
|
46
|
+
type VariableDeclarationList = innerast.VariableDeclarationList
|
|
47
|
+
type VariableStatement = innerast.VariableStatement
|
|
48
|
+
type WhileStatement = innerast.WhileStatement
|
|
49
|
+
type WithStatement = innerast.WithStatement
|
|
50
|
+
|
|
51
|
+
// ---- Class / module / enum shapes ----
|
|
52
|
+
|
|
53
|
+
type ClassDeclaration = innerast.ClassDeclaration
|
|
54
|
+
type ClassExpression = innerast.ClassExpression
|
|
55
|
+
type ClassStaticBlockDeclaration = innerast.ClassStaticBlockDeclaration
|
|
56
|
+
type ConstructorDeclaration = innerast.ConstructorDeclaration
|
|
57
|
+
type EnumDeclaration = innerast.EnumDeclaration
|
|
58
|
+
type EnumMember = innerast.EnumMember
|
|
59
|
+
type GetAccessorDeclaration = innerast.GetAccessorDeclaration
|
|
60
|
+
type SetAccessorDeclaration = innerast.SetAccessorDeclaration
|
|
61
|
+
type HeritageClause = innerast.HeritageClause
|
|
62
|
+
type PropertyDeclaration = innerast.PropertyDeclaration
|
|
63
|
+
|
|
64
|
+
// ---- Module syntax ----
|
|
65
|
+
|
|
66
|
+
type ImportDeclaration = innerast.ImportDeclaration
|
|
67
|
+
type ImportSpecifier = innerast.ImportSpecifier
|
|
68
|
+
type ImportEqualsDeclaration = innerast.ImportEqualsDeclaration
|
|
69
|
+
type ExternalModuleReference = innerast.ExternalModuleReference
|
|
70
|
+
type NamedImports = innerast.NamedImports
|
|
71
|
+
type NamespaceImport = innerast.NamespaceImport
|
|
72
|
+
type ExportDeclaration = innerast.ExportDeclaration
|
|
73
|
+
type ExportSpecifier = innerast.ExportSpecifier
|
|
74
|
+
type ExportAssignment = innerast.ExportAssignment
|
|
75
|
+
type ImportTypeNode = innerast.ImportTypeNode
|
|
76
|
+
|
|
77
|
+
// ---- Binding patterns ----
|
|
78
|
+
|
|
79
|
+
type BindingElement = innerast.BindingElement
|
|
80
|
+
type BindingPattern = innerast.BindingPattern
|
|
81
|
+
|
|
82
|
+
// ---- Expressions ----
|
|
83
|
+
|
|
84
|
+
type ArrayLiteralExpression = innerast.ArrayLiteralExpression
|
|
85
|
+
type ArrowFunction = innerast.ArrowFunction
|
|
86
|
+
type AsExpression = innerast.AsExpression
|
|
87
|
+
type AwaitExpression = innerast.AwaitExpression
|
|
88
|
+
type BinaryExpression = innerast.BinaryExpression
|
|
89
|
+
type ConditionalExpression = innerast.ConditionalExpression
|
|
90
|
+
type DeleteExpression = innerast.DeleteExpression
|
|
91
|
+
type ElementAccessExpression = innerast.ElementAccessExpression
|
|
92
|
+
type FunctionExpression = innerast.FunctionExpression
|
|
93
|
+
type NewExpression = innerast.NewExpression
|
|
94
|
+
type NonNullExpression = innerast.NonNullExpression
|
|
95
|
+
type ObjectLiteralExpression = innerast.ObjectLiteralExpression
|
|
96
|
+
type ParenthesizedExpression = innerast.ParenthesizedExpression
|
|
97
|
+
type PostfixUnaryExpression = innerast.PostfixUnaryExpression
|
|
98
|
+
type PropertyAccessExpression = innerast.PropertyAccessExpression
|
|
99
|
+
type PropertyAssignment = innerast.PropertyAssignment
|
|
100
|
+
type ShorthandPropertyAssignment = innerast.ShorthandPropertyAssignment
|
|
101
|
+
type SpreadAssignment = innerast.SpreadAssignment
|
|
102
|
+
type SpreadElement = innerast.SpreadElement
|
|
103
|
+
type TaggedTemplateExpression = innerast.TaggedTemplateExpression
|
|
104
|
+
type TemplateExpression = innerast.TemplateExpression
|
|
105
|
+
type TemplateSpan = innerast.TemplateSpan
|
|
106
|
+
type TypeAssertion = innerast.TypeAssertion
|
|
107
|
+
type TypeOperatorNode = innerast.TypeOperatorNode
|
|
108
|
+
type TypeOfExpression = innerast.TypeOfExpression
|
|
109
|
+
type VoidExpression = innerast.VoidExpression
|
|
110
|
+
type YieldExpression = innerast.YieldExpression
|
|
111
|
+
type RegularExpressionLiteral = innerast.RegularExpressionLiteral
|
|
112
|
+
type SatisfiesExpression = innerast.SatisfiesExpression
|
|
113
|
+
|
|
114
|
+
// ---- Comment directives (ban-ts-comment) ----
|
|
115
|
+
|
|
116
|
+
type CommentDirective = innerast.CommentDirective
|
|
117
|
+
type CommentDirectiveKind = innerast.CommentDirectiveKind
|
|
118
|
+
|
|
119
|
+
// ---- Source file parse options (test harness) ----
|
|
120
|
+
|
|
121
|
+
type SourceFileParseOptions = innerast.SourceFileParseOptions
|
|
122
|
+
type ExternalModuleIndicatorOptions = innerast.ExternalModuleIndicatorOptions
|
|
123
|
+
|
|
124
|
+
// ---- Node-flag constants ----
|
|
125
|
+
|
|
126
|
+
const (
|
|
127
|
+
NodeFlagsNone = innerast.NodeFlagsNone
|
|
128
|
+
NodeFlagsSynthesized = innerast.NodeFlagsSynthesized
|
|
129
|
+
NodeFlagsLet = innerast.NodeFlagsLet
|
|
130
|
+
NodeFlagsConst = innerast.NodeFlagsConst
|
|
131
|
+
NodeFlagsBlockScoped = innerast.NodeFlagsBlockScoped
|
|
132
|
+
NodeFlagsAwaitContext = innerast.NodeFlagsAwaitContext
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
// ---- Statement / declaration / expression kinds ----
|
|
136
|
+
|
|
137
|
+
const (
|
|
138
|
+
KindSourceFile = innerast.KindSourceFile
|
|
139
|
+
|
|
140
|
+
// Statements
|
|
141
|
+
KindBlock = innerast.KindBlock
|
|
142
|
+
KindBreakStatement = innerast.KindBreakStatement
|
|
143
|
+
KindCaseBlock = innerast.KindCaseBlock
|
|
144
|
+
KindCaseClause = innerast.KindCaseClause
|
|
145
|
+
KindCatchClause = innerast.KindCatchClause
|
|
146
|
+
KindContinueStatement = innerast.KindContinueStatement
|
|
147
|
+
KindDebuggerStatement = innerast.KindDebuggerStatement
|
|
148
|
+
KindDefaultClause = innerast.KindDefaultClause
|
|
149
|
+
KindDoStatement = innerast.KindDoStatement
|
|
150
|
+
KindEmptyStatement = innerast.KindEmptyStatement
|
|
151
|
+
KindExpressionStatement = innerast.KindExpressionStatement
|
|
152
|
+
KindForInStatement = innerast.KindForInStatement
|
|
153
|
+
KindForOfStatement = innerast.KindForOfStatement
|
|
154
|
+
KindForStatement = innerast.KindForStatement
|
|
155
|
+
KindIfStatement = innerast.KindIfStatement
|
|
156
|
+
KindLabeledStatement = innerast.KindLabeledStatement
|
|
157
|
+
KindReturnStatement = innerast.KindReturnStatement
|
|
158
|
+
KindSwitchStatement = innerast.KindSwitchStatement
|
|
159
|
+
KindThrowStatement = innerast.KindThrowStatement
|
|
160
|
+
KindTryStatement = innerast.KindTryStatement
|
|
161
|
+
KindVariableDeclaration = innerast.KindVariableDeclaration
|
|
162
|
+
KindVariableDeclarationList = innerast.KindVariableDeclarationList
|
|
163
|
+
KindVariableStatement = innerast.KindVariableStatement
|
|
164
|
+
KindWhileStatement = innerast.KindWhileStatement
|
|
165
|
+
KindWithStatement = innerast.KindWithStatement
|
|
166
|
+
|
|
167
|
+
// Class / enum / module
|
|
168
|
+
KindClassDeclaration = innerast.KindClassDeclaration
|
|
169
|
+
KindClassExpression = innerast.KindClassExpression
|
|
170
|
+
KindConstructor = innerast.KindConstructor
|
|
171
|
+
KindEnumDeclaration = innerast.KindEnumDeclaration
|
|
172
|
+
KindEnumMember = innerast.KindEnumMember
|
|
173
|
+
KindGetAccessor = innerast.KindGetAccessor
|
|
174
|
+
KindSetAccessor = innerast.KindSetAccessor
|
|
175
|
+
KindHeritageClause = innerast.KindHeritageClause
|
|
176
|
+
KindPropertyDeclaration = innerast.KindPropertyDeclaration
|
|
177
|
+
|
|
178
|
+
// Module syntax
|
|
179
|
+
KindExportAssignment = innerast.KindExportAssignment
|
|
180
|
+
KindExportDeclaration = innerast.KindExportDeclaration
|
|
181
|
+
KindImportEqualsDeclaration = innerast.KindImportEqualsDeclaration
|
|
182
|
+
KindExternalModuleReference = innerast.KindExternalModuleReference
|
|
183
|
+
KindImportType = innerast.KindImportType
|
|
184
|
+
KindImportKeyword = innerast.KindImportKeyword
|
|
185
|
+
|
|
186
|
+
// Binding
|
|
187
|
+
KindBindingElement = innerast.KindBindingElement
|
|
188
|
+
KindObjectBindingPattern = innerast.KindObjectBindingPattern
|
|
189
|
+
KindArrayBindingPattern = innerast.KindArrayBindingPattern
|
|
190
|
+
KindOmittedExpression = innerast.KindOmittedExpression
|
|
191
|
+
|
|
192
|
+
// Expressions
|
|
193
|
+
KindArrayLiteralExpression = innerast.KindArrayLiteralExpression
|
|
194
|
+
KindArrowFunction = innerast.KindArrowFunction
|
|
195
|
+
KindAsExpression = innerast.KindAsExpression
|
|
196
|
+
KindAwaitExpression = innerast.KindAwaitExpression
|
|
197
|
+
KindBinaryExpression = innerast.KindBinaryExpression
|
|
198
|
+
KindConditionalExpression = innerast.KindConditionalExpression
|
|
199
|
+
KindDeleteExpression = innerast.KindDeleteExpression
|
|
200
|
+
KindElementAccessExpression = innerast.KindElementAccessExpression
|
|
201
|
+
KindFunctionExpression = innerast.KindFunctionExpression
|
|
202
|
+
KindNewExpression = innerast.KindNewExpression
|
|
203
|
+
KindNonNullExpression = innerast.KindNonNullExpression
|
|
204
|
+
KindObjectLiteralExpression = innerast.KindObjectLiteralExpression
|
|
205
|
+
KindParenthesizedExpression = innerast.KindParenthesizedExpression
|
|
206
|
+
KindPostfixUnaryExpression = innerast.KindPostfixUnaryExpression
|
|
207
|
+
KindPropertyAssignment = innerast.KindPropertyAssignment
|
|
208
|
+
KindShorthandPropertyAssignment = innerast.KindShorthandPropertyAssignment
|
|
209
|
+
KindSpreadAssignment = innerast.KindSpreadAssignment
|
|
210
|
+
KindSpreadElement = innerast.KindSpreadElement
|
|
211
|
+
KindTaggedTemplateExpression = innerast.KindTaggedTemplateExpression
|
|
212
|
+
KindTemplateExpression = innerast.KindTemplateExpression
|
|
213
|
+
KindTemplateSpan = innerast.KindTemplateSpan
|
|
214
|
+
KindTypeAssertionExpression = innerast.KindTypeAssertionExpression
|
|
215
|
+
KindTypeOfExpression = innerast.KindTypeOfExpression
|
|
216
|
+
KindVoidExpression = innerast.KindVoidExpression
|
|
217
|
+
KindYieldExpression = innerast.KindYieldExpression
|
|
218
|
+
KindRegularExpressionLiteral = innerast.KindRegularExpressionLiteral
|
|
219
|
+
KindSatisfiesExpression = innerast.KindSatisfiesExpression
|
|
220
|
+
|
|
221
|
+
// Keywords / tokens used by rules
|
|
222
|
+
KindThisKeyword = innerast.KindThisKeyword
|
|
223
|
+
KindSuperKeyword = innerast.KindSuperKeyword
|
|
224
|
+
KindEqualsToken = innerast.KindEqualsToken
|
|
225
|
+
KindEqualsEqualsToken = innerast.KindEqualsEqualsToken
|
|
226
|
+
KindEqualsEqualsEqualsToken = innerast.KindEqualsEqualsEqualsToken
|
|
227
|
+
KindExclamationEqualsToken = innerast.KindExclamationEqualsToken
|
|
228
|
+
KindExclamationEqualsEqualsToken = innerast.KindExclamationEqualsEqualsToken
|
|
229
|
+
KindLessThanToken = innerast.KindLessThanToken
|
|
230
|
+
KindGreaterThanToken = innerast.KindGreaterThanToken
|
|
231
|
+
KindLessThanEqualsToken = innerast.KindLessThanEqualsToken
|
|
232
|
+
KindGreaterThanEqualsToken = innerast.KindGreaterThanEqualsToken
|
|
233
|
+
KindPlusToken = innerast.KindPlusToken
|
|
234
|
+
KindPlusEqualsToken = innerast.KindPlusEqualsToken
|
|
235
|
+
KindMinusEqualsToken = innerast.KindMinusEqualsToken
|
|
236
|
+
KindAsteriskToken = innerast.KindAsteriskToken
|
|
237
|
+
KindSlashToken = innerast.KindSlashToken
|
|
238
|
+
KindAmpersandAmpersandToken = innerast.KindAmpersandAmpersandToken
|
|
239
|
+
KindBarBarToken = innerast.KindBarBarToken
|
|
240
|
+
KindQuestionQuestionToken = innerast.KindQuestionQuestionToken
|
|
241
|
+
KindExclamationToken = innerast.KindExclamationToken
|
|
242
|
+
KindTildeToken = innerast.KindTildeToken
|
|
243
|
+
KindInKeyword = innerast.KindInKeyword
|
|
244
|
+
KindInstanceOfKeyword = innerast.KindInstanceOfKeyword
|
|
245
|
+
KindAsKeyword = innerast.KindAsKeyword
|
|
246
|
+
KindPlusPlusToken = innerast.KindPlusPlusToken
|
|
247
|
+
KindMinusMinusToken = innerast.KindMinusMinusToken
|
|
248
|
+
KindDotToken = innerast.KindDotToken
|
|
249
|
+
|
|
250
|
+
// Bitwise / shift / exponent operator tokens — needed by
|
|
251
|
+
// no-bitwise, prefer-exponentiation-operator, etc.
|
|
252
|
+
KindAmpersandToken = innerast.KindAmpersandToken
|
|
253
|
+
KindBarToken = innerast.KindBarToken
|
|
254
|
+
KindCaretToken = innerast.KindCaretToken
|
|
255
|
+
KindLessThanLessThanToken = innerast.KindLessThanLessThanToken
|
|
256
|
+
KindGreaterThanGreaterThanToken = innerast.KindGreaterThanGreaterThanToken
|
|
257
|
+
KindGreaterThanGreaterThanGreaterThanToken = innerast.KindGreaterThanGreaterThanGreaterThanToken
|
|
258
|
+
KindAsteriskAsteriskToken = innerast.KindAsteriskAsteriskToken
|
|
259
|
+
KindAmpersandAmpersandEqualsToken = innerast.KindAmpersandAmpersandEqualsToken
|
|
260
|
+
KindBarBarEqualsToken = innerast.KindBarBarEqualsToken
|
|
261
|
+
KindQuestionQuestionEqualsToken = innerast.KindQuestionQuestionEqualsToken
|
|
262
|
+
KindAsteriskEqualsToken = innerast.KindAsteriskEqualsToken
|
|
263
|
+
KindSlashEqualsToken = innerast.KindSlashEqualsToken
|
|
264
|
+
KindPercentEqualsToken = innerast.KindPercentEqualsToken
|
|
265
|
+
KindAsteriskAsteriskEqualsToken = innerast.KindAsteriskAsteriskEqualsToken
|
|
266
|
+
KindAmpersandEqualsToken = innerast.KindAmpersandEqualsToken
|
|
267
|
+
KindBarEqualsToken = innerast.KindBarEqualsToken
|
|
268
|
+
KindCaretEqualsToken = innerast.KindCaretEqualsToken
|
|
269
|
+
KindLessThanLessThanEqualsToken = innerast.KindLessThanLessThanEqualsToken
|
|
270
|
+
KindGreaterThanGreaterThanEqualsToken = innerast.KindGreaterThanGreaterThanEqualsToken
|
|
271
|
+
KindGreaterThanGreaterThanGreaterThanEqualsToken = innerast.KindGreaterThanGreaterThanGreaterThanEqualsToken
|
|
272
|
+
KindCommaToken = innerast.KindCommaToken
|
|
273
|
+
KindQuestionToken = innerast.KindQuestionToken
|
|
274
|
+
|
|
275
|
+
// Metaprogramming / privacy / async syntax
|
|
276
|
+
KindMetaProperty = innerast.KindMetaProperty
|
|
277
|
+
KindPrivateIdentifier = innerast.KindPrivateIdentifier
|
|
278
|
+
KindClassStaticBlockDeclaration = innerast.KindClassStaticBlockDeclaration
|
|
279
|
+
|
|
280
|
+
// Misc syntax used by suggestion rules
|
|
281
|
+
KindSymbolKeyword = innerast.KindSymbolKeyword
|
|
282
|
+
KindObjectKeyword = innerast.KindObjectKeyword
|
|
283
|
+
|
|
284
|
+
// Modifier-style keywords
|
|
285
|
+
KindAsyncKeyword = innerast.KindAsyncKeyword
|
|
286
|
+
KindAwaitKeyword = innerast.KindAwaitKeyword
|
|
287
|
+
KindReadonlyKeyword = innerast.KindReadonlyKeyword
|
|
288
|
+
KindStaticKeyword = innerast.KindStaticKeyword
|
|
289
|
+
KindAbstractKeyword = innerast.KindAbstractKeyword
|
|
290
|
+
KindExportKeyword = innerast.KindExportKeyword
|
|
291
|
+
KindDeclareKeyword = innerast.KindDeclareKeyword
|
|
292
|
+
KindModuleKeyword = innerast.KindModuleKeyword
|
|
293
|
+
KindTypeKeyword = innerast.KindTypeKeyword
|
|
294
|
+
|
|
295
|
+
// TypeScript-specific kinds used by ts rules
|
|
296
|
+
KindCallSignature = innerast.KindCallSignature
|
|
297
|
+
KindConstructSignature = innerast.KindConstructSignature
|
|
298
|
+
KindTypeQuery = innerast.KindTypeQuery
|
|
299
|
+
KindTypeOperator = innerast.KindTypeOperator
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
// ---- Comment-directive kind constants ----
|
|
303
|
+
|
|
304
|
+
const (
|
|
305
|
+
CommentDirectiveKindIgnore = innerast.CommentDirectiveKindIgnore
|
|
306
|
+
CommentDirectiveKindExpectError = innerast.CommentDirectiveKindExpectError
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
// ---- Helpers ----
|
|
310
|
+
|
|
311
|
+
// GetCombinedNodeFlags returns the combined node flags for a declaration,
|
|
312
|
+
// consulting parents where applicable. This is what `IsLet` / `IsConst` use
|
|
313
|
+
// internally; lint rules need it to detect `var` declarations whose flag
|
|
314
|
+
// lives on the VariableDeclarationList rather than the declaration itself.
|
|
315
|
+
func GetCombinedNodeFlags(node *Node) NodeFlags {
|
|
316
|
+
return innerast.GetCombinedNodeFlags(node)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// IsLet reports whether the declaration was introduced by `let` / `using`.
|
|
320
|
+
func IsLet(node *Node) bool { return GetCombinedNodeFlags(node)&NodeFlagsLet != 0 }
|
|
321
|
+
|
|
322
|
+
// IsConst reports whether the declaration was introduced by `const` /
|
|
323
|
+
// `await using` / `using`.
|
|
324
|
+
func IsConst(node *Node) bool { return GetCombinedNodeFlags(node)&NodeFlagsConst != 0 }
|
|
325
|
+
|
|
326
|
+
// IsVar reports whether the declaration was introduced by `var`. The block
|
|
327
|
+
// scoped flag bits are clear when the keyword is plain `var`.
|
|
328
|
+
func IsVar(node *Node) bool { return GetCombinedNodeFlags(node)&NodeFlagsBlockScoped == 0 }
|