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