irisout 0.2.1
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/CHANGELOG.md +24 -0
- package/README.md +25 -0
- package/dist/LICENSE +190 -0
- package/dist/compiler/analyze.d.ts +61 -0
- package/dist/compiler/ast-codegen.d.ts +8 -0
- package/dist/compiler/decl-graph.d.ts +7 -0
- package/dist/compiler/inline-components.d.ts +4 -0
- package/dist/compiler/module-linker.d.ts +13 -0
- package/dist/compiler/render.d.ts +27 -0
- package/dist/compiler/state.d.ts +221 -0
- package/dist/diagnostics.d.ts +26 -0
- package/dist/diagnostics.js +83 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +28519 -0
- package/dist/jsx.d.ts +132 -0
- package/dist/runtime.d.ts +77 -0
- package/dist/runtime.js +286 -0
- package/dist/state.js +46 -0
- package/dist/vite.d.ts +18 -0
- package/dist/vite.js +67 -0
- package/package.json +37 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# 変更履歴
|
|
2
|
+
|
|
3
|
+
## 0.2.1 - 未公開
|
|
4
|
+
|
|
5
|
+
- `signal((previous) => next)`による関数形式の更新を追加した。
|
|
6
|
+
- `signal(initial, keyOf)`と`.update(key, updater)`を削除した。
|
|
7
|
+
- 配列signalの一覧更新をJSXの`key`による全体再調整へ統一した。
|
|
8
|
+
- Webアプリの依存を単一の`irisout`パッケージへ統一した。
|
|
9
|
+
|
|
10
|
+
### 移行
|
|
11
|
+
|
|
12
|
+
`collection(initial, keyOf)`または`signal(initial, keyOf)`を`signal(initial)`へ置き換える。項目更新は`items((previous) => previous.map(...))`、削除は`items((previous) => previous.filter(...))`と記述する。
|
|
13
|
+
|
|
14
|
+
## 0.1.1 - 2026-09-10
|
|
15
|
+
|
|
16
|
+
- イベント処理、`use=`、`onMount`、`effect`の作者記述を元のJSXへ対応付ける実行時ソースマップを追加した。
|
|
17
|
+
- 別ファイルの部品で未対応構文を拒否したとき、原因となるファイル、行、列を示すよう診断を修正した。
|
|
18
|
+
- npm公開版から始める手順、JSX型検査の設定、初期HTMLと破棄の範囲を利用文書へ追加した。
|
|
19
|
+
|
|
20
|
+
公開入口の削除と既存記法の変更はない。共有実行時処理、DOM探索、一覧照合、条件分岐管理、自動生成した更新関数は、対応する元構文が一つに定まらないためソースマップの対象外である。
|
|
21
|
+
|
|
22
|
+
## 0.1.0 - 2026-09-09
|
|
23
|
+
|
|
24
|
+
- コンパイラ、実行時処理、Vite連携、診断、JSX型定義を単一の`irisout`パッケージとして初めて公開した。
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# irisout
|
|
2
|
+
|
|
3
|
+
JSXから静的HTMLと直接DOM更新コードを生成する開発基盤です。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install irisout vite-plus
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Vite連携は`irisout/vite`、JSX型定義は`irisout/jsx`から参照します。
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { irisout } from 'irisout/vite'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"compilerOptions": {
|
|
18
|
+
"types": ["irisout/jsx"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
コンパイラは`irisout`、診断型は`irisout/diagnostics`から参照できます。
|
|
24
|
+
|
|
25
|
+
版ごとの差分は[`CHANGELOG.md`](./CHANGELOG.md)を参照してください。
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 irisout contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { NodePath } from '@babel/traverse';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import type { CompilerState, DeclId, ResolveUpdateCall } from './state.ts';
|
|
4
|
+
export interface AnalyzeResult {
|
|
5
|
+
deps: Set<DeclId>;
|
|
6
|
+
/** 本番出力向け(read call を裸の識別子へ書き換え済み)。 */
|
|
7
|
+
rendered: string;
|
|
8
|
+
/** ビルド時実行向け(hygienic rename のみ、read call はそのまま)。 */
|
|
9
|
+
sourceRendered: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function analyzeExpr(ctx: CompilerState, path: NodePath<t.Expression>, instanceId: number): AnalyzeResult;
|
|
12
|
+
export interface HandlerAnalysis {
|
|
13
|
+
/** 出力向け(書き込み呼び出しを代入文へ書き換え済み)。 */
|
|
14
|
+
rendered: string;
|
|
15
|
+
/** signalToMarkers確定後に本体と入れ子関数の更新文を挿入する。 */
|
|
16
|
+
finalize: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
17
|
+
/** このハンドラが書き込む root signal の declId 集合(推移解決済み)。 */
|
|
18
|
+
writeDeclIds: Set<DeclId>;
|
|
19
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
20
|
+
/** 連結済み入力ソースにおける本体先頭。 */
|
|
21
|
+
sourceStart: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function analyzeHandlerExpr(ctx: CompilerState, exprPath: NodePath<t.Expression>, instanceId: number): HandlerAnalysis;
|
|
24
|
+
export declare function analyzeHandlerBody(ctx: CompilerState, stmts: NodePath<t.Statement>[], instanceId: number): HandlerAnalysis;
|
|
25
|
+
export interface ActionBodyAnalysis {
|
|
26
|
+
finalizeBody: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
27
|
+
/** action/effect本体が直接読み取る宣言。返り値cleanupのreadは含めない。 */
|
|
28
|
+
readDeclIds: Set<DeclId>;
|
|
29
|
+
/** 返り値(function または { update?, destroy? })。無ければ null。 */
|
|
30
|
+
result: {
|
|
31
|
+
finalize: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
32
|
+
/** update が直接読む signal/derived(推移解決前 -- ctx.markerDeps と
|
|
33
|
+
* 同じ形、resolveToSignals による展開は compiler.ts の
|
|
34
|
+
* buildSignalToMarkers に任せる)。destroy の読み取りはここへ含めない。 */
|
|
35
|
+
deps: Set<DeclId>;
|
|
36
|
+
/** update/destroy の本体が書く宣言。字句範囲検証に使う。 */
|
|
37
|
+
writeDeclIds: Set<DeclId>;
|
|
38
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
39
|
+
} | null;
|
|
40
|
+
/** action本体が書く宣言。 */
|
|
41
|
+
writeDeclIds: Set<DeclId>;
|
|
42
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
43
|
+
}
|
|
44
|
+
export declare function analyzeActionBody(ctx: CompilerState, body: NodePath<t.Expression> | NodePath<t.Statement>[], instanceId: number): ActionBodyAnalysis;
|
|
45
|
+
export interface MountBodyAnalysis {
|
|
46
|
+
finalizeBody: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
47
|
+
readDeclIds: Set<DeclId>;
|
|
48
|
+
writeDeclIds: Set<DeclId>;
|
|
49
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
50
|
+
/** `onMount` callbackが返す、unmount時だけ呼ぶcleanup。 */
|
|
51
|
+
finalizeCleanup: (() => string) | null;
|
|
52
|
+
}
|
|
53
|
+
export declare function analyzeMountBody(ctx: CompilerState, callbackPath: NodePath<t.ArrowFunctionExpression>, instanceId: number): MountBodyAnalysis;
|
|
54
|
+
export interface EffectBodyAnalysis {
|
|
55
|
+
finalizeBody: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
56
|
+
/** effect callback本体が直接読み取る宣言。cleanupのreadは除外する。 */
|
|
57
|
+
readDeclIds: Set<DeclId>;
|
|
58
|
+
finalizeCleanup: (() => string) | null;
|
|
59
|
+
}
|
|
60
|
+
export declare function analyzeEffectBody(ctx: CompilerState, callbackPath: NodePath<t.ArrowFunctionExpression>, instanceId: number): EffectBodyAnalysis;
|
|
61
|
+
export declare function bareTrackedDeclId(ctx: CompilerState, exprPath: NodePath<t.Expression>, instanceId: number): DeclId | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
export type AstNodeGetter = <T extends t.Node>(original: T) => T;
|
|
3
|
+
export interface AstRewriteSession {
|
|
4
|
+
rename(original: t.Identifier, name: string): void;
|
|
5
|
+
replace(target: t.Node, parent: t.Node | null, depth: number, build: (get: AstNodeGetter) => t.Node): void;
|
|
6
|
+
generate(): string;
|
|
7
|
+
}
|
|
8
|
+
export declare function createAstRewrite(root: t.Node): AstRewriteSession;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CompilerState, DeclId } from './state.ts';
|
|
2
|
+
/**
|
|
3
|
+
* derived の依存先だけを辿り、循環を検出する。`resolveToSignals` は呼び出し
|
|
4
|
+
* 側ごとに新しい集合を渡すため、ここではコンパイル済み宣言を一度に検査する。
|
|
5
|
+
*/
|
|
6
|
+
export declare function assertAcyclicDerivedGraph(ctx: CompilerState): void;
|
|
7
|
+
export declare function resolveToSignals(ctx: CompilerState, declId: DeclId, visited: Set<DeclId>): Set<DeclId>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NodePath } from '@babel/traverse';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
export declare function collectTopLevelComponents(ast: t.File, renderOnly?: boolean): Map<string, NodePath<t.FunctionDeclaration>>;
|
|
4
|
+
export declare function inlineComponents(ast: t.File, transformedNodes?: Set<t.Node>): Set<t.Node>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DiagnosticOrigin } from '../diagnostics.ts';
|
|
2
|
+
export interface LinkedProject {
|
|
3
|
+
source: string;
|
|
4
|
+
supportStatements: string[];
|
|
5
|
+
supportNames: Set<string>;
|
|
6
|
+
/** 外部moduleとViteの資源import。compilerのAST解析へ入れず生成moduleへ残す。 */
|
|
7
|
+
externalImports: string[];
|
|
8
|
+
/** compileProject()の利用側が相対moduleを監視できる絶対pathの一覧。 */
|
|
9
|
+
dependencies: string[];
|
|
10
|
+
/** 連結後ソースの範囲と元モジュールの対応。診断位置の復元に使う。 */
|
|
11
|
+
origins: DiagnosticOrigin[];
|
|
12
|
+
}
|
|
13
|
+
export declare function linkProject(entryPath: string): LinkedProject;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { NodePath } from '@babel/traverse';
|
|
2
|
+
import type * as t from '@babel/types';
|
|
3
|
+
import type { CompilerState, ContextId, LocalDecl } from './state.ts';
|
|
4
|
+
export interface RenderOutput {
|
|
5
|
+
declStatements: string[];
|
|
6
|
+
instrumentedDeclStatements: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface ContextProvider {
|
|
9
|
+
key: ContextId;
|
|
10
|
+
valuePath: NodePath<t.Expression>;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveContextProvider(ctx: CompilerState, stmt: NodePath<t.Statement>): ContextProvider | null;
|
|
13
|
+
export type HandlerFns = Map<string, NodePath<t.FunctionDeclaration>>;
|
|
14
|
+
export type MountHooks = NodePath<t.ArrowFunctionExpression>[];
|
|
15
|
+
export type EffectHooks = NodePath<t.ArrowFunctionExpression>[];
|
|
16
|
+
export declare function processLocalDeclarationStatement(ctx: CompilerState, stmt: NodePath<t.Statement>, instanceId: number): LocalDecl;
|
|
17
|
+
export declare function renderCallJsx(stmt: NodePath<t.Statement>): NodePath<t.JSXElement> | null;
|
|
18
|
+
export interface ComponentZones {
|
|
19
|
+
varZoneStmts: NodePath<t.Statement>[];
|
|
20
|
+
renderJsxPath: NodePath<t.JSXElement>;
|
|
21
|
+
movementZoneFns: HandlerFns;
|
|
22
|
+
mountHooks: MountHooks;
|
|
23
|
+
effectHooks: EffectHooks;
|
|
24
|
+
}
|
|
25
|
+
export declare function resolveOnMountHook(stmt: NodePath<t.Statement>): NodePath<t.ArrowFunctionExpression> | null;
|
|
26
|
+
export declare function splitComponentZones(componentPath: NodePath<t.FunctionDeclaration>): ComponentZones;
|
|
27
|
+
export declare function compileComponent(ctx: CompilerState, componentPath: NodePath<t.FunctionDeclaration>, instanceId: number, out: RenderOutput): string;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type { NodePath } from '@babel/traverse';
|
|
2
|
+
import type * as t from '@babel/types';
|
|
3
|
+
export type DeclId = string & {
|
|
4
|
+
readonly __brand: 'DeclId';
|
|
5
|
+
};
|
|
6
|
+
export type MarkerId = string & {
|
|
7
|
+
readonly __brand: 'MarkerId';
|
|
8
|
+
};
|
|
9
|
+
export type ContextId = string & {
|
|
10
|
+
readonly __brand: 'ContextId';
|
|
11
|
+
};
|
|
12
|
+
export declare const toDeclId: (s: string) => DeclId;
|
|
13
|
+
export declare const toMarkerId: (s: string) => MarkerId;
|
|
14
|
+
export declare const toContextId: (s: string) => ContextId;
|
|
15
|
+
export type DeclKind = 'signal' | 'derived' | 'collection';
|
|
16
|
+
export interface ResolvedUpdateCall {
|
|
17
|
+
code: string;
|
|
18
|
+
needsCollectionBatch: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type ResolveUpdateCall = (ids: Set<DeclId>, directCollectionWriteDeclIds?: Set<DeclId>) => ResolvedUpdateCall;
|
|
21
|
+
export interface TextContentPart {
|
|
22
|
+
type: 'text';
|
|
23
|
+
value: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ExprContentPart {
|
|
26
|
+
type: 'expr';
|
|
27
|
+
code: string;
|
|
28
|
+
}
|
|
29
|
+
export type ContentPart = TextContentPart | ExprContentPart;
|
|
30
|
+
export interface TextMarker {
|
|
31
|
+
id: MarkerId;
|
|
32
|
+
kind: 'text';
|
|
33
|
+
contentParts: ContentPart[];
|
|
34
|
+
}
|
|
35
|
+
export interface HandlerDecl {
|
|
36
|
+
markerId: MarkerId;
|
|
37
|
+
eventName: string;
|
|
38
|
+
rendered: string;
|
|
39
|
+
/** 本体と入れ子関数の更新文をsignalToMarkers確定後に挿入する。 */
|
|
40
|
+
finalize?: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
41
|
+
writeDeclIds: Set<DeclId>;
|
|
42
|
+
/** collection.update() の直接通知経路で書き込むcollection。通常の
|
|
43
|
+
* keyed signal(next) setterとは異なり、同一スコープのbatch時だけ遅延する。 */
|
|
44
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
45
|
+
/** ADR-0009: 第1仮引数(イベントオブジェクト)の authored 名。なければ null。 */
|
|
46
|
+
param: string | null;
|
|
47
|
+
/** authored handlerがasync関数またはasync arrowか。 */
|
|
48
|
+
async: boolean;
|
|
49
|
+
sourceStart: number;
|
|
50
|
+
}
|
|
51
|
+
export interface AttrBinding {
|
|
52
|
+
markerId: MarkerId;
|
|
53
|
+
name: string;
|
|
54
|
+
/** 出力向け(update 用、read call を裸の識別子へ書き換え済み)。 */
|
|
55
|
+
rendered: string;
|
|
56
|
+
deps: Set<DeclId>;
|
|
57
|
+
}
|
|
58
|
+
export interface LocalDecl {
|
|
59
|
+
id: DeclId;
|
|
60
|
+
kind: DeclKind;
|
|
61
|
+
/** 出力向けの変数名(この unit の factory 内でのみ有効)。 */
|
|
62
|
+
outputName: string;
|
|
63
|
+
/** 初期化式(出力向け、read call を裸の識別子へ書き換え済み)。 */
|
|
64
|
+
rendered: string;
|
|
65
|
+
}
|
|
66
|
+
export interface StructuralUnitBody {
|
|
67
|
+
template: string;
|
|
68
|
+
localMarkers: (TextMarker | ListMarker | ConditionalMarker)[];
|
|
69
|
+
localHandlers: HandlerDecl[];
|
|
70
|
+
/** 構造unit内の`use=`。factory instanceが初期化と破棄を所有する。 */
|
|
71
|
+
localActions: ActionDecl[];
|
|
72
|
+
/** 構造unit内の`onMount`。factory instanceが初期化と破棄を所有する。 */
|
|
73
|
+
localMounts: MountDecl[];
|
|
74
|
+
/** 構造unit内の`effect`。factory instanceが再実行と破棄を所有する。 */
|
|
75
|
+
localEffects: EffectDecl[];
|
|
76
|
+
/** ADR-0012: このユニット専有の動的属性バインディング。 */
|
|
77
|
+
localAttrBindings: AttrBinding[];
|
|
78
|
+
/** same-file-component-composition: このユニット直下のローカルsignal宣言。 */
|
|
79
|
+
localDecls: LocalDecl[];
|
|
80
|
+
/** 親のsignal/derivedに依存する本文・属性・入れ子unitの依存。 */
|
|
81
|
+
rootDeps: Set<DeclId>;
|
|
82
|
+
}
|
|
83
|
+
export interface ListMarker {
|
|
84
|
+
id: MarkerId;
|
|
85
|
+
kind: 'list';
|
|
86
|
+
/** `.map((item) => ...)` の item 仮引数の authored 名。 */
|
|
87
|
+
itemParam: string;
|
|
88
|
+
/** `.map()` を呼ぶ対象配列の出力向けレンダー結果(裸の識別子または式)。 */
|
|
89
|
+
arrayRendered: string;
|
|
90
|
+
/** `key={...}` の出力向けレンダー結果(item 仮引数を参照する式)。 */
|
|
91
|
+
keyRendered: string;
|
|
92
|
+
/** 配列式が直接、キー付き`signal()`を読んでいる場合の宣言ID。それ以外はnull。 */
|
|
93
|
+
collectionDeclId: DeclId | null;
|
|
94
|
+
body: StructuralUnitBody;
|
|
95
|
+
}
|
|
96
|
+
export interface ConditionalBranch {
|
|
97
|
+
/** `&&`: 真のときのみ描画。三項: consequent/alternate それぞれに対応。 */
|
|
98
|
+
body: StructuralUnitBody | null;
|
|
99
|
+
}
|
|
100
|
+
export interface ConditionalMarker {
|
|
101
|
+
id: MarkerId;
|
|
102
|
+
kind: 'conditional';
|
|
103
|
+
/** 条件式の出力向けレンダー結果。 */
|
|
104
|
+
condRendered: string;
|
|
105
|
+
/** true: branches[0]=真, false=なし(`&&`)。false: branches[0]=consequent, branches[1]=alternate(三項)。 */
|
|
106
|
+
isLogical: boolean;
|
|
107
|
+
branches: ConditionalBranch[];
|
|
108
|
+
}
|
|
109
|
+
export interface ActionMarker {
|
|
110
|
+
id: MarkerId;
|
|
111
|
+
kind: 'action';
|
|
112
|
+
}
|
|
113
|
+
export type Marker = TextMarker | ListMarker | ConditionalMarker | ActionMarker;
|
|
114
|
+
export interface ActionDecl {
|
|
115
|
+
markerId: MarkerId;
|
|
116
|
+
/** action本体の第1仮引数(要素自身)の authored 名。0引数なら null。 */
|
|
117
|
+
elParam: string | null;
|
|
118
|
+
finalizeBody: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
119
|
+
/** 返り値(function または { update?, destroy? })。無ければ null。 */
|
|
120
|
+
finalizeResult: ((resolveUpdateCall: ResolveUpdateCall) => string) | null;
|
|
121
|
+
/** 返り値のupdateが読むsignal/derived。構造unitの親依存へ合流する。 */
|
|
122
|
+
resultDeps: Set<DeclId>;
|
|
123
|
+
/** action本体・返り値のupdateが書く宣言。字句範囲検証に使う。 */
|
|
124
|
+
writeDeclIds: Set<DeclId>;
|
|
125
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
126
|
+
bodySourceStart: number;
|
|
127
|
+
resultSourceStart: number | null;
|
|
128
|
+
}
|
|
129
|
+
export interface MountDecl {
|
|
130
|
+
finalizeBody: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
131
|
+
finalizeCleanup: (() => string) | null;
|
|
132
|
+
writeDeclIds: Set<DeclId>;
|
|
133
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
134
|
+
bodySourceStart: number;
|
|
135
|
+
cleanupSourceStart: number | null;
|
|
136
|
+
}
|
|
137
|
+
export interface EffectDecl {
|
|
138
|
+
finalizeBody: (resolveUpdateCall: ResolveUpdateCall) => string;
|
|
139
|
+
finalizeCleanup: (() => string) | null;
|
|
140
|
+
readDeclIds: Set<DeclId>;
|
|
141
|
+
bodySourceStart: number;
|
|
142
|
+
cleanupSourceStart: number | null;
|
|
143
|
+
}
|
|
144
|
+
export interface ContextDecl {
|
|
145
|
+
id: ContextId;
|
|
146
|
+
/** createAsyncContext()の値を扱うcontextか。runtime awaitは生成しない。 */
|
|
147
|
+
async: boolean;
|
|
148
|
+
/** createContext()のdefaultValue。build時と生成時で同じ式を使う。 */
|
|
149
|
+
defaultRendered: string;
|
|
150
|
+
defaultSourceRendered: string;
|
|
151
|
+
}
|
|
152
|
+
export interface ContextValue {
|
|
153
|
+
rendered: string;
|
|
154
|
+
sourceRendered: string;
|
|
155
|
+
deps: Set<DeclId>;
|
|
156
|
+
}
|
|
157
|
+
export interface SharedDecl {
|
|
158
|
+
id: DeclId;
|
|
159
|
+
kind: 'signal' | 'derived' | 'collection';
|
|
160
|
+
outputName: string;
|
|
161
|
+
/** signal/collectionの初期値、またはderivedの関数式。 */
|
|
162
|
+
rendered: string;
|
|
163
|
+
/** build時実行向けの初期値、またはderivedの関数式。 */
|
|
164
|
+
sourceRendered: string;
|
|
165
|
+
/** collectionのkey selector。collection以外では未設定。 */
|
|
166
|
+
keyRendered?: string;
|
|
167
|
+
/** build時実行向けcollectionのkey selector。collection以外では未設定。 */
|
|
168
|
+
keySourceRendered?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface TrackedFn {
|
|
171
|
+
name: string;
|
|
172
|
+
/** authored の仮引数テキスト(括弧なし。0引数なら空文字列)。 */
|
|
173
|
+
paramSource: string;
|
|
174
|
+
/** 書き換え済み本体(中括弧の中身、update_*() なし)。 */
|
|
175
|
+
rendered: string;
|
|
176
|
+
/** authored movement-zone functionがasyncか。 */
|
|
177
|
+
async: boolean;
|
|
178
|
+
writeDeclIds: Set<DeclId>;
|
|
179
|
+
directCollectionWriteDeclIds: Set<DeclId>;
|
|
180
|
+
calleeNames: Set<string>;
|
|
181
|
+
}
|
|
182
|
+
export interface CompilerState {
|
|
183
|
+
source: string;
|
|
184
|
+
supportNames: Set<string>;
|
|
185
|
+
transformedNodes: Set<t.Node>;
|
|
186
|
+
declIdByKey: Map<string, DeclId>;
|
|
187
|
+
declKind: Map<DeclId, DeclKind>;
|
|
188
|
+
declOutputName: Map<DeclId, string>;
|
|
189
|
+
derivedDeps: Map<DeclId, Set<DeclId>>;
|
|
190
|
+
derivedRecompute: Map<DeclId, string>;
|
|
191
|
+
collectionKeyRendered: Map<DeclId, string>;
|
|
192
|
+
usedOutputNames: Set<string>;
|
|
193
|
+
markers: Marker[];
|
|
194
|
+
markerDeps: Map<MarkerId, Set<DeclId>>;
|
|
195
|
+
handlers: HandlerDecl[];
|
|
196
|
+
actions: ActionDecl[];
|
|
197
|
+
/** ルートcomponentの`onMount`。構造unit内では収集しない。 */
|
|
198
|
+
mounts: MountDecl[];
|
|
199
|
+
/** ルートcomponentの`effect`。構造unit内では収集しない。 */
|
|
200
|
+
effects: EffectDecl[];
|
|
201
|
+
/** top-level createContext() declarations keyed by lexical binding. */
|
|
202
|
+
contexts: Map<ContextId, ContextDecl>;
|
|
203
|
+
contextIdByKey: Map<string, ContextId>;
|
|
204
|
+
/** render/analyze中の現在unitへ見えるprovider値。終了時に復元する。 */
|
|
205
|
+
contextValues: Map<ContextId, ContextValue>;
|
|
206
|
+
attrBindings: AttrBinding[];
|
|
207
|
+
markerCounter: number;
|
|
208
|
+
instanceCounter: number;
|
|
209
|
+
movementFns: Map<string, NodePath<t.FunctionDeclaration>>;
|
|
210
|
+
trackedFns: Map<string, TrackedFn>;
|
|
211
|
+
localDeclIds: Set<DeclId>;
|
|
212
|
+
/** compileProjectで収集したmodule共有signal/derived。 */
|
|
213
|
+
sharedDecls: SharedDecl[];
|
|
214
|
+
sharedDeclIdByBindingKey: Map<string, DeclId>;
|
|
215
|
+
sharedDeclIds: Set<DeclId>;
|
|
216
|
+
usedSharedDeclIds: Set<DeclId>;
|
|
217
|
+
}
|
|
218
|
+
export declare function createCompilerState(source: string, transformedNodes?: Set<t.Node>, supportNames?: Set<string>): CompilerState;
|
|
219
|
+
export declare const declKey: (instanceId: number, start: number, bindingName: string) => string;
|
|
220
|
+
export declare function nextMarkerId(ctx: CompilerState): MarkerId;
|
|
221
|
+
export declare function assignOutputName(ctx: CompilerState, naturalName: string, id: DeclId): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface DiagnosticOptions {
|
|
2
|
+
filePath: string;
|
|
3
|
+
source: string;
|
|
4
|
+
offset?: number;
|
|
5
|
+
/** compileProject()の連結後ソースを元モジュールへ戻す範囲。 */
|
|
6
|
+
origins?: DiagnosticOrigin[];
|
|
7
|
+
}
|
|
8
|
+
export interface DiagnosticOrigin {
|
|
9
|
+
generatedStart: number;
|
|
10
|
+
generatedEnd: number;
|
|
11
|
+
filePath: string;
|
|
12
|
+
source: string;
|
|
13
|
+
}
|
|
14
|
+
export interface DiagnosticPosition {
|
|
15
|
+
filePath: string;
|
|
16
|
+
line: number;
|
|
17
|
+
column: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function diagnosticPosition(error: unknown, options: DiagnosticOptions): DiagnosticPosition;
|
|
20
|
+
export declare class CompileDiagnostic extends Error {
|
|
21
|
+
readonly filePath: string;
|
|
22
|
+
readonly line: number;
|
|
23
|
+
readonly column: number;
|
|
24
|
+
constructor(message: string, options: DiagnosticOptions, cause?: unknown);
|
|
25
|
+
}
|
|
26
|
+
export declare function withCompileDiagnostic(error: unknown, options: DiagnosticOptions): CompileDiagnostic;
|