@weapp-vite/wxml 0.0.0-stage → 0.0.1-dev.20261112.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/LICENSE +21 -0
- package/README.md +199 -2
- package/dist/core/index.d.mts +2 -0
- package/dist/core/index.mjs +1 -0
- package/dist/core-BEEC2yjm.mjs +2392 -0
- package/dist/core-DBjwtLEd.d.mts +249 -0
- package/dist/index-eR1Owa_a.d.mts +71 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.mjs +140 -0
- package/dist/presets/index.d.mts +2 -0
- package/dist/presets/index.mjs +1 -0
- package/dist/presets-Ez_Kg5w3.mjs +179 -0
- package/package.json +92 -4
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
interface SourceRange {
|
|
2
|
+
readonly start: number;
|
|
3
|
+
readonly end: number;
|
|
4
|
+
}
|
|
5
|
+
type Platform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs' | 'qq' | 'ks' | 'ty';
|
|
6
|
+
type Syntax = 'legacy' | 'xml';
|
|
7
|
+
/** 与平台无关的模板方言声明。 */
|
|
8
|
+
interface DialectDefinition {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly syntax: Syntax;
|
|
11
|
+
readonly rawTags: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
declare const compiledDialectBrand: unique symbol;
|
|
14
|
+
/** 已校验的不可变方言,供词法核心绑定使用。 */
|
|
15
|
+
interface CompiledDialect extends DialectDefinition {
|
|
16
|
+
readonly [compiledDialectBrand]: true;
|
|
17
|
+
}
|
|
18
|
+
/** 仅在结束边界已确定时提供完整插值的 UTF-16 半开范围,属性外层引号不在范围内。 */
|
|
19
|
+
interface InterpolationRecovery extends SourceRange {
|
|
20
|
+
readonly kind: 'interpolation';
|
|
21
|
+
}
|
|
22
|
+
interface Diagnostic extends SourceRange {
|
|
23
|
+
readonly code: string;
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly severity: 'error' | 'warning' | 'info';
|
|
26
|
+
readonly recovery?: InterpolationRecovery;
|
|
27
|
+
}
|
|
28
|
+
interface Attribute extends SourceRange {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly nameStart: number;
|
|
31
|
+
readonly nameEnd: number;
|
|
32
|
+
readonly value?: string;
|
|
33
|
+
readonly valueStart?: number;
|
|
34
|
+
readonly valueEnd?: number;
|
|
35
|
+
readonly rawValue?: string;
|
|
36
|
+
readonly quote?: '"' | '\'';
|
|
37
|
+
}
|
|
38
|
+
interface TagToken extends SourceRange {
|
|
39
|
+
readonly kind: 'tag';
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly nameStart: number;
|
|
42
|
+
readonly nameEnd: number;
|
|
43
|
+
readonly closing: boolean;
|
|
44
|
+
readonly selfClosing: boolean;
|
|
45
|
+
readonly attributes: readonly Attribute[];
|
|
46
|
+
readonly matching?: number;
|
|
47
|
+
readonly parent?: number;
|
|
48
|
+
}
|
|
49
|
+
interface RawToken extends SourceRange {
|
|
50
|
+
readonly kind: 'text' | 'comment' | 'cdata' | 'declaration' | 'script';
|
|
51
|
+
readonly tagName?: string;
|
|
52
|
+
}
|
|
53
|
+
type Token = TagToken | RawToken;
|
|
54
|
+
interface ScriptBoundaryCandidates {
|
|
55
|
+
readonly closingTag?: SourceRange;
|
|
56
|
+
readonly trailingComment?: number;
|
|
57
|
+
readonly commentClosings?: readonly (SourceRange & {
|
|
58
|
+
readonly block: boolean;
|
|
59
|
+
})[];
|
|
60
|
+
}
|
|
61
|
+
interface ParseOptions {
|
|
62
|
+
readonly platform?: Platform;
|
|
63
|
+
readonly syntax?: Syntax;
|
|
64
|
+
readonly rawTags?: readonly string[];
|
|
65
|
+
readonly resolveScriptBoundary?: (source: string, start: number, tagName: string, candidates: ScriptBoundaryCandidates) => SourceRange | undefined;
|
|
66
|
+
}
|
|
67
|
+
interface ScanResult {
|
|
68
|
+
readonly tokens: readonly Token[];
|
|
69
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
70
|
+
}
|
|
71
|
+
interface ElementNode extends SourceRange {
|
|
72
|
+
readonly kind: 'element';
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly attributes: readonly Attribute[];
|
|
75
|
+
readonly children: readonly Node[];
|
|
76
|
+
readonly opening: TagToken;
|
|
77
|
+
readonly closing?: TagToken;
|
|
78
|
+
readonly selfClosing: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface RawNode extends RawToken {
|
|
81
|
+
readonly data: string;
|
|
82
|
+
}
|
|
83
|
+
type Node = ElementNode | RawNode;
|
|
84
|
+
interface Document extends TemplateDocument {
|
|
85
|
+
readonly platform: Platform;
|
|
86
|
+
readonly options: ParseOptions;
|
|
87
|
+
}
|
|
88
|
+
/** 核心入口使用的平台无关文档基型。 */
|
|
89
|
+
interface TemplateDocument extends ScanResult {
|
|
90
|
+
readonly source: string;
|
|
91
|
+
readonly syntax: Syntax;
|
|
92
|
+
readonly children: readonly Node[];
|
|
93
|
+
}
|
|
94
|
+
interface TemplateParser {
|
|
95
|
+
readonly dialect: CompiledDialect;
|
|
96
|
+
readonly scan: (source: string) => ScanResult;
|
|
97
|
+
readonly scanComments: (source: string) => ScanResult;
|
|
98
|
+
readonly parse: (source: string) => TemplateDocument;
|
|
99
|
+
}
|
|
100
|
+
interface Visitor {
|
|
101
|
+
enter?: (node: Node, parent: ElementNode | undefined) => void | false;
|
|
102
|
+
leave?: (node: Node, parent: ElementNode | undefined) => void;
|
|
103
|
+
}
|
|
104
|
+
type AttributeValue = string | number | boolean | {
|
|
105
|
+
readonly expression: string;
|
|
106
|
+
};
|
|
107
|
+
interface EditableNode {
|
|
108
|
+
readonly node: Node;
|
|
109
|
+
rename: (name: string) => void;
|
|
110
|
+
setAttribute: (name: string, value: AttributeValue) => void;
|
|
111
|
+
setBooleanAttribute: (name: string) => void;
|
|
112
|
+
removeAttribute: (name: string) => void;
|
|
113
|
+
replaceText: (value: string | {
|
|
114
|
+
readonly expression: string;
|
|
115
|
+
}) => void;
|
|
116
|
+
remove: () => void;
|
|
117
|
+
replaceWith: (source: string) => void;
|
|
118
|
+
insertBefore: (source: string) => void;
|
|
119
|
+
insertAfter: (source: string) => void;
|
|
120
|
+
prepend: (source: string) => void;
|
|
121
|
+
append: (source: string) => void;
|
|
122
|
+
}
|
|
123
|
+
type EditVisitor = (node: EditableNode) => void | false;
|
|
124
|
+
/** 编辑会话中的逻辑属性;源码坐标仅由提交后的文档提供。 */
|
|
125
|
+
interface EditAttribute {
|
|
126
|
+
readonly name: string;
|
|
127
|
+
readonly value?: string;
|
|
128
|
+
readonly quote?: '"' | '\'';
|
|
129
|
+
}
|
|
130
|
+
interface EditElement {
|
|
131
|
+
readonly kind: 'element';
|
|
132
|
+
readonly name: string;
|
|
133
|
+
readonly attributes: readonly EditAttribute[];
|
|
134
|
+
readonly children: readonly EditNode[];
|
|
135
|
+
readonly selfClosing: boolean;
|
|
136
|
+
}
|
|
137
|
+
interface EditRawNode {
|
|
138
|
+
readonly kind: RawNode['kind'];
|
|
139
|
+
readonly data: string;
|
|
140
|
+
}
|
|
141
|
+
type EditNode = EditElement | EditRawNode;
|
|
142
|
+
type EditCallback<State = undefined, Current extends EditNode = EditNode> = (path: EditPath<Current>, state: State) => void | false;
|
|
143
|
+
type EditNodeVisitor<State = undefined, Current extends EditNode = EditNode> = EditCallback<State, Current> | {
|
|
144
|
+
enter?: EditCallback<State, Current>;
|
|
145
|
+
exit?: EditCallback<State, Current>;
|
|
146
|
+
};
|
|
147
|
+
interface EditVisitors<State = undefined> {
|
|
148
|
+
enter?: EditCallback<State>;
|
|
149
|
+
exit?: EditCallback<State>;
|
|
150
|
+
Element?: EditNodeVisitor<State, EditElement>;
|
|
151
|
+
Text?: EditNodeVisitor<State, EditRawNode & {
|
|
152
|
+
readonly kind: 'text';
|
|
153
|
+
}>;
|
|
154
|
+
Comment?: EditNodeVisitor<State, EditRawNode & {
|
|
155
|
+
readonly kind: 'comment';
|
|
156
|
+
}>;
|
|
157
|
+
Cdata?: EditNodeVisitor<State, EditRawNode & {
|
|
158
|
+
readonly kind: 'cdata';
|
|
159
|
+
}>;
|
|
160
|
+
Declaration?: EditNodeVisitor<State, EditRawNode & {
|
|
161
|
+
readonly kind: 'declaration';
|
|
162
|
+
}>;
|
|
163
|
+
Script?: EditNodeVisitor<State, EditRawNode & {
|
|
164
|
+
readonly kind: 'script';
|
|
165
|
+
}>;
|
|
166
|
+
}
|
|
167
|
+
/** 路径身份属于单个编辑会话,所有修改在会话结束后失效。 */
|
|
168
|
+
interface EditPath<Current extends EditNode = EditNode> {
|
|
169
|
+
readonly node: Current;
|
|
170
|
+
readonly originalNode: Node | undefined;
|
|
171
|
+
readonly originalRange: SourceRange | undefined;
|
|
172
|
+
readonly parentPath: EditPath | undefined;
|
|
173
|
+
readonly key: number;
|
|
174
|
+
readonly removed: boolean;
|
|
175
|
+
get: (key: 'children') => readonly EditPath[];
|
|
176
|
+
getSibling: (index: number) => EditPath | undefined;
|
|
177
|
+
findParent: (predicate: (path: EditPath) => boolean) => EditPath | undefined;
|
|
178
|
+
isElement: {
|
|
179
|
+
(): this is EditPath<EditElement>;
|
|
180
|
+
<Name extends string>(name: Name): this is EditPath<EditElement & {
|
|
181
|
+
readonly name: Name;
|
|
182
|
+
}>;
|
|
183
|
+
};
|
|
184
|
+
isText: () => this is EditPath<EditRawNode & {
|
|
185
|
+
readonly kind: 'text';
|
|
186
|
+
}>;
|
|
187
|
+
hasAttribute: (name: string) => boolean;
|
|
188
|
+
getAttribute: (name: string) => EditAttribute | undefined;
|
|
189
|
+
rename: (name: string) => void;
|
|
190
|
+
renameAttribute: (name: string, nextName: string) => void;
|
|
191
|
+
setAttribute: (name: string, value: AttributeValue) => void;
|
|
192
|
+
setBooleanAttribute: (name: string) => void;
|
|
193
|
+
removeAttribute: (name: string) => void;
|
|
194
|
+
replaceText: (value: string | {
|
|
195
|
+
readonly expression: string;
|
|
196
|
+
}) => void;
|
|
197
|
+
remove: () => void;
|
|
198
|
+
replaceWith: (source: string) => readonly EditPath[];
|
|
199
|
+
insertBefore: (source: string) => readonly EditPath[];
|
|
200
|
+
insertAfter: (source: string) => readonly EditPath[];
|
|
201
|
+
prepend: (source: string) => readonly EditPath[];
|
|
202
|
+
append: (source: string) => readonly EditPath[];
|
|
203
|
+
traverse: {
|
|
204
|
+
(visitors: EditVisitors): void;
|
|
205
|
+
<State>(visitors: EditVisitors<State>, state: State): void;
|
|
206
|
+
};
|
|
207
|
+
skip: () => void;
|
|
208
|
+
stop: () => void;
|
|
209
|
+
requeue: () => void;
|
|
210
|
+
}
|
|
211
|
+
interface SerializeOptions {
|
|
212
|
+
readonly mode?: 'preserve' | 'canonical';
|
|
213
|
+
}
|
|
214
|
+
/** 解码不含外层引号的词法属性值;表达式内部保留 JS 字符串的转义层。 */
|
|
215
|
+
declare function decodeAttribute(value: string, syntax?: Syntax, decodeEntities?: boolean, quote?: string): string;
|
|
216
|
+
/** 校验并冻结方言声明,匹配结构不通过公开对象暴露。 */
|
|
217
|
+
declare function compileDialect(definition: DialectDefinition): CompiledDialect;
|
|
218
|
+
/** 同步编辑会话验证变更词法后发布新文档,原始文档保持不变。 */
|
|
219
|
+
declare function edit(document: Document, visitor: EditVisitor): Document;
|
|
220
|
+
declare function edit(document: TemplateDocument, visitor: EditVisitor): TemplateDocument;
|
|
221
|
+
declare function edit(document: Document, visitors: EditVisitors): Document;
|
|
222
|
+
declare function edit(document: TemplateDocument, visitors: EditVisitors): TemplateDocument;
|
|
223
|
+
declare function edit<State>(document: Document, visitors: EditVisitors<State>, state: State): Document;
|
|
224
|
+
declare function edit<State>(document: TemplateDocument, visitors: EditVisitors<State>, state: State): TemplateDocument;
|
|
225
|
+
/** 定位插值末尾;跳过字符串、注释、正则和嵌套括号,保留原文编码。 */
|
|
226
|
+
declare function expressionEnd(source: string, start: number, mustache?: boolean, syntax?: Syntax, outerQuote?: string): number;
|
|
227
|
+
/** 返回完整插值的半开范围,保留属性层的编码规则。 */
|
|
228
|
+
declare function interpolations(source: string, syntax?: Syntax, outerQuote?: string): SourceRange[];
|
|
229
|
+
/** 词法错误携带原文偏移,由调用方选择报告或抛出。 */
|
|
230
|
+
declare class TemplateLexicalError extends Error {
|
|
231
|
+
readonly offset: number;
|
|
232
|
+
readonly recovery?: InterpolationRecovery | undefined;
|
|
233
|
+
constructor(offset: number, message: string, recovery?: InterpolationRecovery | undefined);
|
|
234
|
+
}
|
|
235
|
+
/** 只收集词法候选,不加载 JS AST;歧义由调用方注入的 resolver 处理。 */
|
|
236
|
+
declare function scanScriptBoundaryCandidates(source: string, start: number, tagName: string): ScriptBoundaryCandidates;
|
|
237
|
+
/** 返回明确位于脚本代码层的结束标签,不擅自采用注释内的候选。 */
|
|
238
|
+
declare function findScriptClosingTag(source: string, start: number, tagName: string): SourceRange | undefined;
|
|
239
|
+
/** 查找词法确认的未闭合尾部块注释。 */
|
|
240
|
+
declare function findTrailingScriptComment(source: string): number | undefined;
|
|
241
|
+
/** 保留模式输出当前文档源码;规范模式逐节点输出并保留所有文本。 */
|
|
242
|
+
declare function serialize(document: TemplateDocument, options?: SerializeOptions): string;
|
|
243
|
+
/** 读取标签与属性范围;属性值始终保留未解码的原文。 */
|
|
244
|
+
declare function readTag(source: string, start: number, syntax?: Syntax, collectAttributes?: boolean): TagToken;
|
|
245
|
+
/** 迭代遍历文档,enter 返回 false 时跳过子树,避免深模板递归溢出。 */
|
|
246
|
+
declare function walk(document: TemplateDocument | readonly Node[], visitor: Visitor): void;
|
|
247
|
+
/** 将编译方言绑定一次,同一解析器复用不可变配置和 matcher。 */
|
|
248
|
+
declare function createParser(dialect: CompiledDialect, options?: Pick<ParseOptions, 'resolveScriptBoundary'>): TemplateParser;
|
|
249
|
+
export { ElementNode as A, SourceRange as B, EditNode as C, EditVisitor as D, EditRawNode as E, RawNode as F, Token as G, TagToken as H, RawToken as I, Visitor as K, ScanResult as L, Node as M, ParseOptions as N, EditVisitors as O, Platform as P, ScriptBoundaryCandidates as R, EditElement as S, EditPath as T, TemplateDocument as U, Syntax as V, TemplateParser as W, Diagnostic as _, findScriptClosingTag as a, EditAttribute as b, TemplateLexicalError as c, edit as d, compileDialect as f, CompiledDialect as g, AttributeValue as h, serialize as i, InterpolationRecovery as j, EditableNode as k, expressionEnd as l, Attribute as m, walk as n, findTrailingScriptComment as o, decodeAttribute as p, readTag as r, scanScriptBoundaryCandidates as s, createParser as t, interpolations as u, DialectDefinition as v, EditNodeVisitor as w, EditCallback as x, Document as y, SerializeOptions as z };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** 模板方言的最小定义;不包含构建器、IDE 或宿主 runtime 能力。 */
|
|
2
|
+
interface TemplateDialectDefinition {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly syntax: 'legacy' | 'xml';
|
|
5
|
+
readonly rawTags: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
interface TemplateScriptModule {
|
|
8
|
+
readonly extension: string;
|
|
9
|
+
readonly tag: string;
|
|
10
|
+
readonly format: 'commonjs' | 'esm';
|
|
11
|
+
readonly sourceAttribute: 'src' | 'from';
|
|
12
|
+
readonly moduleAttribute: 'module' | 'name';
|
|
13
|
+
}
|
|
14
|
+
/** 可移植兼容输入的引用属性,不为 filter 等标签推断模块制式。 */
|
|
15
|
+
interface TemplateScriptReferenceRecipe {
|
|
16
|
+
readonly tag: string;
|
|
17
|
+
readonly sourceAttributes: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
interface TemplateScriptModuleRecipe {
|
|
20
|
+
readonly defaultScriptModule: TemplateScriptModule;
|
|
21
|
+
readonly scriptModules: readonly TemplateScriptModule[];
|
|
22
|
+
}
|
|
23
|
+
/** 历史构建输入的默认脚本约定;与某个平台的原生方言分开。 */
|
|
24
|
+
interface TemplateInputRecipe extends TemplateScriptModuleRecipe {
|
|
25
|
+
readonly scriptReferences: readonly TemplateScriptReferenceRecipe[];
|
|
26
|
+
readonly rawTags: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
interface TemplateDirectives {
|
|
29
|
+
readonly if: string;
|
|
30
|
+
readonly elif: string;
|
|
31
|
+
readonly else: string;
|
|
32
|
+
readonly for: string;
|
|
33
|
+
readonly forItem: string;
|
|
34
|
+
readonly forIndex: string;
|
|
35
|
+
readonly key: string;
|
|
36
|
+
}
|
|
37
|
+
interface TemplatePreset {
|
|
38
|
+
readonly id: PlatformPresetId;
|
|
39
|
+
readonly templateExtension: string;
|
|
40
|
+
readonly styleExtension: string;
|
|
41
|
+
readonly dialect: TemplateDialectDefinition;
|
|
42
|
+
readonly nativeDialect: TemplateDialectDefinition;
|
|
43
|
+
readonly compatibilityDialect: TemplateDialectDefinition;
|
|
44
|
+
readonly portableScriptModule: TemplateScriptModule;
|
|
45
|
+
readonly nativeScriptModules: readonly TemplateScriptModule[];
|
|
46
|
+
readonly directives: TemplateDirectives;
|
|
47
|
+
readonly directivePrefix: string;
|
|
48
|
+
readonly directiveSeparator: ':' | '-';
|
|
49
|
+
readonly eventStyle: 'default' | 'alipay';
|
|
50
|
+
}
|
|
51
|
+
type PlatformPresetId = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs' | 'qq' | 'ks' | 'ty';
|
|
52
|
+
/** 纯模板语言预设;不会暗示对应平台具备构建或宿主 runtime 支持。 */
|
|
53
|
+
declare const weapp: TemplatePreset;
|
|
54
|
+
declare const alipay: TemplatePreset;
|
|
55
|
+
declare const tt: TemplatePreset;
|
|
56
|
+
declare const swan: TemplatePreset;
|
|
57
|
+
declare const jd: TemplatePreset;
|
|
58
|
+
declare const xhs: TemplatePreset;
|
|
59
|
+
declare const qq: TemplatePreset;
|
|
60
|
+
declare const ks: TemplatePreset;
|
|
61
|
+
declare const ty: TemplatePreset;
|
|
62
|
+
/** 兼容构建输入保留原有标签次序;平台原生别名由各自预设追加。 */
|
|
63
|
+
declare const portableCompatibilityScriptRecipes: readonly TemplateScriptReferenceRecipe[];
|
|
64
|
+
/** 无平台构建入口的历史默认,不暗示微信或其他宿主能力。 */
|
|
65
|
+
declare const defaultTemplateInputRecipe: TemplateInputRecipe;
|
|
66
|
+
/** 旧共享 helper 在无平台时将 SJS 视为 ESM;有平台的缺省回退仍为 CommonJS。 */
|
|
67
|
+
declare const legacyScriptModuleRecipes: Readonly<Record<'unprofiled' | 'platform', TemplateScriptModuleRecipe>>;
|
|
68
|
+
declare const presets: readonly TemplatePreset[];
|
|
69
|
+
/** 获取已登记的平台模板预设;平台输入校验和错误兼容由根入口负责。 */
|
|
70
|
+
declare function getTemplatePreset(id: PlatformPresetId): TemplatePreset;
|
|
71
|
+
export { TemplateScriptReferenceRecipe as S, TemplateDirectives as _, ks as a, TemplateScriptModule as b, presets as c, tt as d, ty as f, TemplateDialectDefinition as g, PlatformPresetId as h, jd as i, qq as l, xhs as m, defaultTemplateInputRecipe as n, legacyScriptModuleRecipes as o, weapp as p, getTemplatePreset as r, portableCompatibilityScriptRecipes as s, alipay as t, swan as u, TemplateInputRecipe as v, TemplateScriptModuleRecipe as x, TemplatePreset as y };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { A as ElementNode, B as SourceRange, C as EditNode, D as EditVisitor, E as EditRawNode, F as RawNode, G as Token, H as TagToken, I as RawToken, K as Visitor, L as ScanResult, M as Node, N as ParseOptions, O as EditVisitors, P as Platform, R as ScriptBoundaryCandidates, S as EditElement, T as EditPath, U as TemplateDocument, V as Syntax, W as TemplateParser, _ as Diagnostic, a as findScriptClosingTag, b as EditAttribute, c as TemplateLexicalError, f as compileDialect, g as CompiledDialect, h as AttributeValue, i as serialize, j as InterpolationRecovery, k as EditableNode, l as expressionEnd, m as Attribute, n as walk, o as findTrailingScriptComment, p as decodeAttribute, r as readTag, s as scanScriptBoundaryCandidates, t as createParser, u as interpolations, v as DialectDefinition, w as EditNodeVisitor, x as EditCallback, y as Document, z as SerializeOptions } from "./core-DBjwtLEd.mjs";
|
|
2
|
+
import { _ as TemplateDirectives, a as ks, b as TemplateScriptModule, c as presets, d as tt, f as ty, g as TemplateDialectDefinition, h as PlatformPresetId, i as jd, l as qq, m as xhs, p as weapp, r as getTemplatePreset, t as alipay, u as swan, y as TemplatePreset } from "./index-eR1Owa_a.mjs";
|
|
3
|
+
/** 旧结构化文档按原选项恢复上下文,核心文档须保留所属解析器关联。 */
|
|
4
|
+
export declare function edit(document: Document, visitor: EditVisitor): Document;
|
|
5
|
+
export declare function edit(document: TemplateDocument, visitor: EditVisitor): TemplateDocument;
|
|
6
|
+
export declare function edit(document: Document, visitors: EditVisitors): Document;
|
|
7
|
+
export declare function edit(document: TemplateDocument, visitors: EditVisitors): TemplateDocument;
|
|
8
|
+
export declare function edit<State>(document: Document, visitors: EditVisitors<State>, state: State): Document;
|
|
9
|
+
export declare function edit<State>(document: TemplateDocument, visitors: EditVisitors<State>, state: State): TemplateDocument;
|
|
10
|
+
/** 使用兼容平台选项建立保留完整源码的文档,核心扫描不承担平台归一化。 */
|
|
11
|
+
export declare function parse(source: string, options?: ParseOptions): Document;
|
|
12
|
+
/** 兼容根入口,扫描前解析平台预设。 */
|
|
13
|
+
export declare function scan(source: string, options?: ParseOptions): ScanResult;
|
|
14
|
+
/** 只收集普通模板注释,复用同一词法核心。 */
|
|
15
|
+
export declare function scanComments(source: string, options?: ParseOptions): ScanResult;
|
|
16
|
+
export { type Attribute, type AttributeValue, type CompiledDialect, type Diagnostic, type DialectDefinition, type Document, type EditAttribute, type EditCallback, type EditElement, type EditNode, type EditNodeVisitor, type EditPath, type EditRawNode, type EditVisitor, type EditVisitors, type EditableNode, type ElementNode, type InterpolationRecovery, type Node, type ParseOptions, type Platform, type PlatformPresetId, type RawNode, type RawToken, type ScanResult, type ScriptBoundaryCandidates, type SerializeOptions, type SourceRange, type Syntax, type TagToken, type TemplateDialectDefinition, type TemplateDirectives, type TemplateDocument, TemplateLexicalError, type TemplateParser, type TemplatePreset, type TemplateScriptModule, type Token, type Visitor, alipay, compileDialect, createParser, decodeAttribute, expressionEnd, findScriptClosingTag, findTrailingScriptComment, getTemplatePreset, interpolations, jd, ks, presets, qq, readTag, scanScriptBoundaryCandidates, serialize, swan, tt, ty, walk, weapp, xhs };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { _ as scanScriptBoundaryCandidates, a as compiledState, b as TemplateLexicalError, c as decodeAttribute, d as parseContext, f as requireContext, g as findTrailingScriptComment, h as findScriptClosingTag, i as compileDialect, l as bindDocument, m as readTag, n as walk, p as scanCompiledDocument, r as serialize, s as editWithContext, t as createParser, u as contextFor, v as expressionEnd, y as interpolations } from "./core-BEEC2yjm.mjs";
|
|
2
|
+
import { a as ks, c as presets, d as tt, f as ty, i as jd, l as qq, m as xhs, p as weapp, r as getTemplatePreset, t as alipay, u as swan } from "./presets-Ez_Kg5w3.mjs";
|
|
3
|
+
// src/options.ts
|
|
4
|
+
const compiled = /* @__PURE__ */ new Map();
|
|
5
|
+
const customDialects = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
const customContexts = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const resolvedContexts = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function createContext(platform, syntax, dialect, explicitRawTags = false, resolver) {
|
|
9
|
+
const snapshot = Object.freeze({
|
|
10
|
+
platform,
|
|
11
|
+
syntax,
|
|
12
|
+
rawTags: explicitRawTags ? dialect.rawTags : void 0,
|
|
13
|
+
resolveScriptBoundary: resolver
|
|
14
|
+
});
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
dialect,
|
|
17
|
+
state: compiledState(dialect),
|
|
18
|
+
resolveScriptBoundary: resolver,
|
|
19
|
+
metadata: Object.freeze({
|
|
20
|
+
platform,
|
|
21
|
+
options: snapshot
|
|
22
|
+
}),
|
|
23
|
+
createDocument: (source, fields) => ({
|
|
24
|
+
source,
|
|
25
|
+
platform,
|
|
26
|
+
syntax: fields.syntax,
|
|
27
|
+
tokens: fields.tokens,
|
|
28
|
+
diagnostics: fields.diagnostics,
|
|
29
|
+
children: fields.children,
|
|
30
|
+
options: snapshot
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
for (const preset of presets) {
|
|
35
|
+
const legacy = compileDialect({
|
|
36
|
+
...preset.compatibilityDialect,
|
|
37
|
+
syntax: "legacy"
|
|
38
|
+
});
|
|
39
|
+
const xml = compileDialect({
|
|
40
|
+
...preset.compatibilityDialect,
|
|
41
|
+
syntax: "xml"
|
|
42
|
+
});
|
|
43
|
+
compiled.set(preset.id, {
|
|
44
|
+
syntax: preset.compatibilityDialect.syntax,
|
|
45
|
+
legacy,
|
|
46
|
+
xml,
|
|
47
|
+
contexts: Object.freeze({
|
|
48
|
+
legacy: createContext(preset.id, "legacy", legacy),
|
|
49
|
+
xml: createContext(preset.id, "xml", xml)
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function readResolver(options) {
|
|
54
|
+
const resolver = options.resolveScriptBoundary;
|
|
55
|
+
if (resolver !== void 0 && typeof resolver !== "function") throw new TypeError("Expected resolveScriptBoundary to be a function.");
|
|
56
|
+
return resolver;
|
|
57
|
+
}
|
|
58
|
+
function cachedContext(platform, syntax, dialect, explicitRawTags, resolver) {
|
|
59
|
+
let contexts = customContexts;
|
|
60
|
+
if (resolver) {
|
|
61
|
+
const existing = resolvedContexts.get(resolver);
|
|
62
|
+
if (existing) contexts = existing;
|
|
63
|
+
else {
|
|
64
|
+
contexts = /* @__PURE__ */ new WeakMap();
|
|
65
|
+
resolvedContexts.set(resolver, contexts);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const previous = contexts.get(dialect);
|
|
69
|
+
if (previous) return previous;
|
|
70
|
+
const context = createContext(platform, syntax, dialect, explicitRawTags, resolver);
|
|
71
|
+
contexts.set(dialect, context);
|
|
72
|
+
return context;
|
|
73
|
+
}
|
|
74
|
+
/** 自定义数组保持内容观测,校验与快照比较共用一轮遍历。 */
|
|
75
|
+
function customContext(options, platform, syntax, base, rawTags) {
|
|
76
|
+
if (!Array.isArray(rawTags)) throw new TypeError("Expected rawTags to be an array of nonempty names.");
|
|
77
|
+
let variants = customDialects.get(rawTags);
|
|
78
|
+
const previous = variants?.get(base);
|
|
79
|
+
let unchanged = previous !== void 0 && previous.rawTags.length === rawTags.length;
|
|
80
|
+
for (let index = 0; index < rawTags.length; index++) {
|
|
81
|
+
const name = rawTags[index];
|
|
82
|
+
if (typeof name !== "string" || !name) throw new TypeError("Expected rawTags to be an array of nonempty names.");
|
|
83
|
+
if (unchanged && name !== previous.rawTags[index]) unchanged = false;
|
|
84
|
+
}
|
|
85
|
+
const resolver = readResolver(options);
|
|
86
|
+
const dialect = unchanged ? previous : compileDialect({
|
|
87
|
+
id: `${platform}-custom`,
|
|
88
|
+
syntax,
|
|
89
|
+
rawTags
|
|
90
|
+
});
|
|
91
|
+
if (!unchanged) {
|
|
92
|
+
if (!variants) {
|
|
93
|
+
variants = /* @__PURE__ */ new Map();
|
|
94
|
+
customDialects.set(rawTags, variants);
|
|
95
|
+
}
|
|
96
|
+
variants.set(base, dialect);
|
|
97
|
+
}
|
|
98
|
+
return cachedContext(platform, syntax, dialect, true, resolver);
|
|
99
|
+
}
|
|
100
|
+
/** 默认配置直接选取预编译上下文,自定义与 resolver 路径独立维护弱缓存。 */
|
|
101
|
+
function normalizeOptions(options) {
|
|
102
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) throw new TypeError("Expected a parse options object.");
|
|
103
|
+
const platform = options.platform ?? "weapp";
|
|
104
|
+
const preset = compiled.get(platform);
|
|
105
|
+
if (!preset) throw new TypeError(`Unsupported template platform: ${String(platform)}.`);
|
|
106
|
+
const syntax = options.syntax ?? preset.syntax;
|
|
107
|
+
if (syntax !== "legacy" && syntax !== "xml") throw new TypeError(`Unsupported template syntax: ${String(syntax)}.`);
|
|
108
|
+
const rawTags = options.rawTags;
|
|
109
|
+
if (rawTags !== void 0) return customContext(options, platform, syntax, preset[syntax], rawTags);
|
|
110
|
+
const resolver = readResolver(options);
|
|
111
|
+
return resolver ? cachedContext(platform, syntax, preset[syntax], false, resolver) : preset.contexts[syntax];
|
|
112
|
+
}
|
|
113
|
+
/** 扫描、解析和兼容文档恢复共用不可变快照;缓存不捕获源码或保活用户 resolver。 */
|
|
114
|
+
const compatibilityContext = normalizeOptions;
|
|
115
|
+
// src/compatibilityEdit.ts
|
|
116
|
+
function edit(document, visitor, state) {
|
|
117
|
+
let context = contextFor(document);
|
|
118
|
+
if (!context && "platform" in document && "options" in document) {
|
|
119
|
+
context = compatibilityContext(document.options);
|
|
120
|
+
bindDocument(document, context);
|
|
121
|
+
}
|
|
122
|
+
return editWithContext(document, visitor, context ?? requireContext(document), state);
|
|
123
|
+
}
|
|
124
|
+
// src/parser.ts
|
|
125
|
+
/** 使用兼容平台选项建立保留完整源码的文档,核心扫描不承担平台归一化。 */
|
|
126
|
+
function parse(source, options = {}) {
|
|
127
|
+
return parseContext(source, compatibilityContext(options));
|
|
128
|
+
}
|
|
129
|
+
// src/scanner.ts
|
|
130
|
+
/** 兼容根入口,扫描前解析平台预设。 */
|
|
131
|
+
function scan(source, options = {}) {
|
|
132
|
+
const { state, resolveScriptBoundary } = normalizeOptions(options);
|
|
133
|
+
return scanCompiledDocument(source, state, resolveScriptBoundary, false);
|
|
134
|
+
}
|
|
135
|
+
/** 只收集普通模板注释,复用同一词法核心。 */
|
|
136
|
+
function scanComments(source, options = {}) {
|
|
137
|
+
const { state, resolveScriptBoundary } = normalizeOptions(options);
|
|
138
|
+
return scanCompiledDocument(source, state, resolveScriptBoundary, false, true);
|
|
139
|
+
}
|
|
140
|
+
export { TemplateLexicalError, alipay, compileDialect, createParser, decodeAttribute, edit, expressionEnd, findScriptClosingTag, findTrailingScriptComment, getTemplatePreset, interpolations, jd, ks, parse, presets, qq, readTag, scan, scanComments, scanScriptBoundaryCandidates, serialize, swan, tt, ty, walk, weapp, xhs };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { S as TemplateScriptReferenceRecipe, _ as TemplateDirectives, a as ks, b as TemplateScriptModule, c as presets, d as tt, f as ty, g as TemplateDialectDefinition, h as PlatformPresetId, i as jd, l as qq, m as xhs, n as defaultTemplateInputRecipe, o as legacyScriptModuleRecipes, p as weapp, r as getTemplatePreset, s as portableCompatibilityScriptRecipes, t as alipay, u as swan, v as TemplateInputRecipe, x as TemplateScriptModuleRecipe, y as TemplatePreset } from "../index-eR1Owa_a.mjs";
|
|
2
|
+
export { type PlatformPresetId, type TemplateDialectDefinition, type TemplateDirectives, type TemplateInputRecipe, type TemplatePreset, type TemplateScriptModule, type TemplateScriptModuleRecipe, type TemplateScriptReferenceRecipe, alipay, defaultTemplateInputRecipe, getTemplatePreset, jd, ks, legacyScriptModuleRecipes, portableCompatibilityScriptRecipes, presets, qq, swan, tt, ty, weapp, xhs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as alipay, n as defaultTemplateInputRecipe, r as getTemplatePreset, i as jd, a as ks, o as legacyScriptModuleRecipes, s as portableCompatibilityScriptRecipes, c as presets, l as qq, u as swan, d as tt, f as ty, p as weapp, m as xhs } from "../presets-Ez_Kg5w3.mjs";
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// src/presets/definitions.ts
|
|
2
|
+
const compatibilityRawTags = Object.freeze([
|
|
3
|
+
"wxs",
|
|
4
|
+
"sjs",
|
|
5
|
+
"ks",
|
|
6
|
+
"filter",
|
|
7
|
+
"script",
|
|
8
|
+
"import-sjs"
|
|
9
|
+
]);
|
|
10
|
+
const filterScriptReference = Object.freeze({
|
|
11
|
+
tag: "filter",
|
|
12
|
+
sourceAttribute: "src"
|
|
13
|
+
});
|
|
14
|
+
function dialect(id, syntax, rawTags) {
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
id,
|
|
17
|
+
syntax,
|
|
18
|
+
rawTags: Object.freeze([...rawTags])
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function module(extension, tag, format = "commonjs", sourceAttribute = "src", moduleAttribute = "module") {
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
extension,
|
|
24
|
+
tag,
|
|
25
|
+
format,
|
|
26
|
+
sourceAttribute,
|
|
27
|
+
moduleAttribute
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function directives(prefix, separator = ":") {
|
|
31
|
+
const name = (suffix) => `${prefix}${separator}${suffix}`;
|
|
32
|
+
return Object.freeze({
|
|
33
|
+
if: name("if"),
|
|
34
|
+
elif: name("elif"),
|
|
35
|
+
else: name("else"),
|
|
36
|
+
for: name("for"),
|
|
37
|
+
forItem: name("for-item"),
|
|
38
|
+
forIndex: name("for-index"),
|
|
39
|
+
key: name("key")
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function createPreset(input) {
|
|
43
|
+
const nativeModules = Object.freeze([...input.nativeScriptModules ?? []]);
|
|
44
|
+
const nativeRawTags = [
|
|
45
|
+
input.portableScriptModule.tag,
|
|
46
|
+
...nativeModules.map((module) => module.tag),
|
|
47
|
+
...input.extraRawTags ?? []
|
|
48
|
+
];
|
|
49
|
+
const compatibilityDialect = dialect(`${input.id}-compatibility`, input.id === "weapp" ? "legacy" : "xml", [.../* @__PURE__ */ new Set([...compatibilityRawTags, ...nativeModules.map((module) => module.tag)])]);
|
|
50
|
+
const nativeDialect = dialect(`${input.id}-native`, compatibilityDialect.syntax, [...new Set(nativeRawTags)]);
|
|
51
|
+
return Object.freeze({
|
|
52
|
+
id: input.id,
|
|
53
|
+
templateExtension: input.templateExtension,
|
|
54
|
+
styleExtension: input.styleExtension,
|
|
55
|
+
dialect: nativeDialect,
|
|
56
|
+
nativeDialect,
|
|
57
|
+
compatibilityDialect,
|
|
58
|
+
portableScriptModule: input.portableScriptModule,
|
|
59
|
+
nativeScriptModules: nativeModules,
|
|
60
|
+
directives: directives(input.directivePrefix, input.directiveSeparator),
|
|
61
|
+
directivePrefix: input.directivePrefix,
|
|
62
|
+
directiveSeparator: input.directiveSeparator ?? ":",
|
|
63
|
+
eventStyle: input.eventStyle ?? "default"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** 纯模板语言预设;不会暗示对应平台具备构建或宿主 runtime 支持。 */
|
|
67
|
+
const weapp = createPreset({
|
|
68
|
+
id: "weapp",
|
|
69
|
+
templateExtension: ".wxml",
|
|
70
|
+
styleExtension: ".wxss",
|
|
71
|
+
directivePrefix: "wx",
|
|
72
|
+
portableScriptModule: module("wxs", "wxs")
|
|
73
|
+
});
|
|
74
|
+
const alipay = createPreset({
|
|
75
|
+
id: "alipay",
|
|
76
|
+
templateExtension: ".axml",
|
|
77
|
+
styleExtension: ".acss",
|
|
78
|
+
directivePrefix: "a",
|
|
79
|
+
eventStyle: "alipay",
|
|
80
|
+
portableScriptModule: module("sjs", "import-sjs", "esm", "from", "name")
|
|
81
|
+
});
|
|
82
|
+
const tt = createPreset({
|
|
83
|
+
id: "tt",
|
|
84
|
+
templateExtension: ".ttml",
|
|
85
|
+
styleExtension: ".ttss",
|
|
86
|
+
directivePrefix: "tt",
|
|
87
|
+
portableScriptModule: module("sjs", "sjs")
|
|
88
|
+
});
|
|
89
|
+
const swan = createPreset({
|
|
90
|
+
id: "swan",
|
|
91
|
+
templateExtension: ".swan",
|
|
92
|
+
styleExtension: ".css",
|
|
93
|
+
directivePrefix: "s",
|
|
94
|
+
directiveSeparator: "-",
|
|
95
|
+
extraRawTags: [filterScriptReference.tag],
|
|
96
|
+
portableScriptModule: module("sjs", "import-sjs", "esm")
|
|
97
|
+
});
|
|
98
|
+
const jd = createPreset({
|
|
99
|
+
id: "jd",
|
|
100
|
+
templateExtension: ".jxml",
|
|
101
|
+
styleExtension: ".jxss",
|
|
102
|
+
directivePrefix: "wx",
|
|
103
|
+
portableScriptModule: module("wxs", "wxs"),
|
|
104
|
+
nativeScriptModules: [module("jds", "jds")]
|
|
105
|
+
});
|
|
106
|
+
const xhs = createPreset({
|
|
107
|
+
id: "xhs",
|
|
108
|
+
templateExtension: ".xhsml",
|
|
109
|
+
styleExtension: ".css",
|
|
110
|
+
directivePrefix: "wx",
|
|
111
|
+
portableScriptModule: module("wxs", "wxs")
|
|
112
|
+
});
|
|
113
|
+
const qq = createPreset({
|
|
114
|
+
id: "qq",
|
|
115
|
+
templateExtension: ".qml",
|
|
116
|
+
styleExtension: ".qss",
|
|
117
|
+
directivePrefix: "qq",
|
|
118
|
+
portableScriptModule: module("wxs", "wxs"),
|
|
119
|
+
nativeScriptModules: [module("qs", "qs")]
|
|
120
|
+
});
|
|
121
|
+
const ks = createPreset({
|
|
122
|
+
id: "ks",
|
|
123
|
+
templateExtension: ".ksml",
|
|
124
|
+
styleExtension: ".css",
|
|
125
|
+
directivePrefix: "ks",
|
|
126
|
+
portableScriptModule: module("ks", "ks")
|
|
127
|
+
});
|
|
128
|
+
const ty = createPreset({
|
|
129
|
+
id: "ty",
|
|
130
|
+
templateExtension: ".tyml",
|
|
131
|
+
styleExtension: ".tyss",
|
|
132
|
+
directivePrefix: "ty",
|
|
133
|
+
portableScriptModule: module("sjs", "sjs")
|
|
134
|
+
});
|
|
135
|
+
function referenceRecipe(script) {
|
|
136
|
+
return Object.freeze({
|
|
137
|
+
tag: script.tag,
|
|
138
|
+
sourceAttributes: Object.freeze([script.sourceAttribute])
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** 兼容构建输入保留原有标签次序;平台原生别名由各自预设追加。 */
|
|
142
|
+
const portableCompatibilityScriptRecipes = Object.freeze([
|
|
143
|
+
referenceRecipe(weapp.portableScriptModule),
|
|
144
|
+
referenceRecipe(tt.portableScriptModule),
|
|
145
|
+
referenceRecipe(filterScriptReference),
|
|
146
|
+
referenceRecipe(alipay.portableScriptModule)
|
|
147
|
+
]);
|
|
148
|
+
/** 无平台构建入口的历史默认,不暗示微信或其他宿主能力。 */
|
|
149
|
+
const defaultTemplateInputRecipe = Object.freeze({
|
|
150
|
+
defaultScriptModule: weapp.portableScriptModule,
|
|
151
|
+
scriptModules: Object.freeze([weapp.portableScriptModule, tt.portableScriptModule]),
|
|
152
|
+
scriptReferences: portableCompatibilityScriptRecipes,
|
|
153
|
+
rawTags: Object.freeze(portableCompatibilityScriptRecipes.map((recipe) => recipe.tag))
|
|
154
|
+
});
|
|
155
|
+
/** 旧共享 helper 在无平台时将 SJS 视为 ESM;有平台的缺省回退仍为 CommonJS。 */
|
|
156
|
+
const legacyScriptModuleRecipes = Object.freeze({
|
|
157
|
+
unprofiled: Object.freeze({
|
|
158
|
+
defaultScriptModule: weapp.portableScriptModule,
|
|
159
|
+
scriptModules: Object.freeze([weapp.portableScriptModule, module(tt.portableScriptModule.extension, tt.portableScriptModule.tag, "esm")])
|
|
160
|
+
}),
|
|
161
|
+
platform: defaultTemplateInputRecipe
|
|
162
|
+
});
|
|
163
|
+
const presets = Object.freeze([
|
|
164
|
+
weapp,
|
|
165
|
+
alipay,
|
|
166
|
+
tt,
|
|
167
|
+
swan,
|
|
168
|
+
jd,
|
|
169
|
+
xhs,
|
|
170
|
+
qq,
|
|
171
|
+
ks,
|
|
172
|
+
ty
|
|
173
|
+
]);
|
|
174
|
+
const presetById = new Map(presets.map((preset) => [preset.id, preset]));
|
|
175
|
+
/** 获取已登记的平台模板预设;平台输入校验和错误兼容由根入口负责。 */
|
|
176
|
+
function getTemplatePreset(id) {
|
|
177
|
+
return presetById.get(id);
|
|
178
|
+
}
|
|
179
|
+
export { ks as a, presets as c, tt as d, ty as f, jd as i, qq as l, xhs as m, defaultTemplateInputRecipe as n, legacyScriptModuleRecipes as o, weapp as p, getTemplatePreset as r, portableCompatibilityScriptRecipes as s, alipay as t, swan as u };
|