(
input: string,
options: {
preserveWhitespaces?: boolean;
leadingTriviaChars?: string[];
ignoreError?: boolean;
selectorlessEnabled?: boolean;
} = {},
)
| 144 | |
| 145 | // Parse an html string to IVY specific info |
| 146 | export function parseR3( |
| 147 | input: string, |
| 148 | options: { |
| 149 | preserveWhitespaces?: boolean; |
| 150 | leadingTriviaChars?: string[]; |
| 151 | ignoreError?: boolean; |
| 152 | selectorlessEnabled?: boolean; |
| 153 | } = {}, |
| 154 | ): Render3ParseResult { |
| 155 | const htmlParser = new HtmlParser(); |
| 156 | const parseResult = htmlParser.parse(input, 'path:://to/template', { |
| 157 | tokenizeExpansionForms: true, |
| 158 | leadingTriviaChars: options.leadingTriviaChars ?? LEADING_TRIVIA_CHARS, |
| 159 | selectorlessEnabled: options.selectorlessEnabled, |
| 160 | }); |
| 161 | |
| 162 | if (parseResult.errors.length > 0 && !options.ignoreError) { |
| 163 | const msg = parseResult.errors.map((e) => e.toString()).join('\n'); |
| 164 | throw new Error(msg); |
| 165 | } |
| 166 | |
| 167 | let htmlNodes = processI18nMeta(parseResult).rootNodes; |
| 168 | |
| 169 | if (!options.preserveWhitespaces) { |
| 170 | htmlNodes = visitAllWithSiblings( |
| 171 | new WhitespaceVisitor(true /* preserveSignificantWhitespace */), |
| 172 | htmlNodes, |
| 173 | ); |
| 174 | } |
| 175 | |
| 176 | const expressionParser = new Parser(new Lexer()); |
| 177 | const schemaRegistry = new MockSchemaRegistry( |
| 178 | {'invalidProp': false}, |
| 179 | {'mappedAttr': 'mappedProp'}, |
| 180 | {'unknown': false, 'un-known': false}, |
| 181 | ['onEvent'], |
| 182 | ['onEvent'], |
| 183 | ); |
| 184 | const bindingParser = new BindingParser(expressionParser, schemaRegistry, []); |
| 185 | const r3Result = htmlAstToRender3Ast(htmlNodes, bindingParser, {collectCommentNodes: false}); |
| 186 | |
| 187 | if (r3Result.errors.length > 0 && !options.ignoreError) { |
| 188 | const msg = r3Result.errors.map((e) => e.toString()).join('\n'); |
| 189 | throw new Error(msg); |
| 190 | } |
| 191 | |
| 192 | return r3Result; |
| 193 | } |
| 194 | |
| 195 | export function processI18nMeta(htmlAstWithErrors: ParseTreeResult): ParseTreeResult { |
| 196 | return new ParseTreeResult( |
nothing calls this directly
no test coverage detected
searching dependent graphs…