forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
89 lines (84 loc) · 2.22 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { HtmlParser } from "../../compiler/src/ml_parser/html_parser.js";
import { TagContentType } from '../../compiler/src/ml_parser/tags.js';
import { ParseTreeResult } from "../../compiler/src/ml_parser/parser.js";
let parser: HtmlParser | null = null;
const getParser = () => {
if (!parser) {
parser = new HtmlParser();
}
return parser;
};
export interface ParseOptions {
/**
* any element can self close
*
* defaults to false
*/
canSelfClose?: boolean,
/**
* support [`htm`](https://github.com/developit/htm) component closing tags (`<//>`)
*
* defaults to false
*/
allowHtmComponentClosingTags?: boolean,
/**
* do not lowercase tag names before querying their tag definitions
*
* defaults to false
*/
isTagNameCaseSensitive?: boolean,
/**
* customize tag content type
*
* defaults to the content type defined in the HTML spec
*/
getTagContentType?: (
tagName: string,
prefix: string,
hasParent: boolean,
attrs: Array<{prefix: string, name: string, value?: string}>
) => void | TagContentType,
/**
* tokenize angular control flow block syntax
*/
tokenizeAngularBlocks?: boolean,
}
export function parse(
input: string,
options: ParseOptions = {}
): ParseTreeResult {
const {
canSelfClose = false,
allowHtmComponentClosingTags = false,
isTagNameCaseSensitive = false,
getTagContentType,
tokenizeAngularBlocks = false,
} = options;
return getParser().parse(
input,
"angular-html-parser",
{
tokenizeExpansionForms: false,
interpolationConfig: undefined,
canSelfClose,
allowHtmComponentClosingTags,
tokenizeBlocks: tokenizeAngularBlocks,
},
isTagNameCaseSensitive,
getTagContentType,
);
}
// For prettier
export { TagContentType };
export {
RecursiveVisitor,
visitAll,
} from "../../compiler/src/ml_parser/ast.js";
export {
ParseSourceSpan,
ParseLocation,
ParseSourceFile,
} from "../../compiler/src/parse_util.js";
export { getHtmlTagDefinition } from "../../compiler/src/ml_parser/html_tags.js";
export { htmlAstToRender3Ast } from '../../compiler/src/render3/r3_template_transform.js';
export { makeBindingParser } from '../../compiler/src/render3/view/template';