-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
684 additions
and
658 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ errorShots/ | |
/test/unpack-anode.spec.js | ||
/test/pref/tti.html | ||
*.vscode | ||
types/test/san-test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* ANode 的类型文件 | ||
*/ | ||
import { ExprNode, ExprAccessorNode } from "./expr.d"; | ||
|
||
export interface ANode { | ||
isText?: boolean; | ||
text?: string; | ||
textExpr?: ExprNode; | ||
children?: ANode[]; | ||
props: ANodeProperty[]; | ||
events: SanIndexedList<ExprNode>; | ||
directives: { [k: string]: Directive<any> }; | ||
tagName: string; | ||
vars?: [{ | ||
name: string; | ||
expr: ExprNode | ||
}]; | ||
} | ||
|
||
export interface ATextNode extends ANode { | ||
textExpr: ExprNode; | ||
} | ||
|
||
export interface ATemplateNode extends ANode { | ||
tagName: 'template'; | ||
children: ANode[]; | ||
} | ||
|
||
export interface AFragmentNode extends ANode { | ||
tagName: 'fragment'; | ||
children: ANode[]; | ||
} | ||
|
||
export interface AForNode extends ANode { | ||
directives: { | ||
for: Directive<any>; | ||
}; | ||
} | ||
|
||
export interface AIfNode extends ANode { | ||
ifRinsed: ANode; | ||
elses?: ANode[]; | ||
directives: { | ||
if: Directive<any>; | ||
}; | ||
} | ||
|
||
export interface ASlotNode extends ANode { | ||
children: ANode[]; | ||
tagName: 'slot'; | ||
} | ||
|
||
export interface SanIndexedList<T> { | ||
raw: T[]; | ||
index: { [name: string]: T }; | ||
|
||
get(bindName: string): T; | ||
each(handler: (bindItem: T) => any, thisArg: any): void; | ||
push(item: { name: string } & {}): void; | ||
remove(name: string): any; | ||
concat(other: SanIndexedList<T>): SanIndexedList<T>; | ||
} | ||
|
||
export enum NodeType { | ||
TEXT = 1, | ||
IF = 2, | ||
FOR = 3, | ||
ELEM = 4, | ||
CMPT = 5, | ||
SLOT = 6, | ||
TPL = 7 | ||
} | ||
|
||
export interface Directive<T extends ExprNode> { | ||
item?: string; | ||
index?: number; | ||
trackBy?: ExprAccessorNode; | ||
value: T; | ||
} | ||
|
||
export interface ANodeProperty { | ||
name: string; | ||
expr: ExprNode; | ||
noValue?: 1; | ||
x?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
export enum ExprType { | ||
STRING = 1, | ||
NUMBER = 2, | ||
BOOL = 3, | ||
ACCESSOR = 4, | ||
INTERP = 5, | ||
CALL = 6, | ||
TEXT = 7, | ||
BINARY = 8, | ||
UNARY = 9, | ||
TERTIARY = 10, | ||
OBJECT = 11, | ||
ARRAY = 12, | ||
NULL = 13 | ||
} | ||
|
||
export interface ExprNodeTpl<T extends ExprType> { | ||
type: T; // 如果只有这一个属性,去掉泛型更可读 | ||
value?: any; // 在 eval 会统一处理,事实上作用于 null, string, number | ||
parenthesized?: boolean; // 在 read parenthesized expr 会统一设置 | ||
} | ||
export type ExprNode = ExprNodeTpl<any>; | ||
export interface ExprStringNode extends ExprNodeTpl<ExprType.STRING> { | ||
value: string; | ||
} | ||
export interface ExprNumberNode extends ExprNodeTpl<ExprType.NUMBER> { | ||
value: number; | ||
} | ||
export interface ExprBoolNode extends ExprNodeTpl<ExprType.BOOL> { | ||
value: boolean; | ||
} | ||
export interface ExprAccessorNode extends ExprNodeTpl<ExprType.ACCESSOR> { | ||
paths: ExprNode[]; | ||
} | ||
export interface ExprInterpNode extends ExprNodeTpl<ExprType.INTERP> { | ||
expr: ExprNode; | ||
filters: ExprCallNode[]; | ||
original: boolean; | ||
} | ||
export interface ExprCallNode extends ExprNodeTpl<ExprType.CALL> { | ||
name: ExprAccessorNode; | ||
args: ExprNode[]; | ||
} | ||
export interface ExprTextNode extends ExprNodeTpl<ExprType.TEXT> { | ||
segs: ExprNode[]; | ||
original?: number; | ||
value?: string; // segs 由一个 STRING 构成时存在 | ||
} | ||
export interface ExprBinaryNode extends ExprNodeTpl<ExprType.BINARY> { | ||
segs: [ExprNode, ExprNode]; | ||
operator: number; | ||
} | ||
export interface ExprUnaryNode extends ExprNodeTpl<ExprType.UNARY> { | ||
operator: number; | ||
expr: ExprNode; | ||
} | ||
export interface ExprTertiaryNode extends ExprNodeTpl<ExprType.TERTIARY> { | ||
segs: ExprNode[]; | ||
} | ||
export interface ExprObjectNode extends ExprNodeTpl<ExprType.OBJECT> { | ||
items: [{ | ||
spread: boolean; | ||
expr: ExprNode; | ||
name: ExprNode; | ||
}]; | ||
} | ||
export interface ExprArrayNode extends ExprNodeTpl<ExprType.ARRAY> { | ||
items: [{ | ||
spread: boolean; | ||
expr: ExprNode; | ||
}]; | ||
} | ||
export interface ExprNullNode extends ExprNodeTpl<ExprType.NULL> {} |
Oops, something went wrong.