Skip to content

Commit 0531bfc

Browse files
committed
Add splitInterpolation
1 parent 4762d60 commit 0531bfc

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎packages/angular-html-parser/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export {
109109
} from "../../compiler/src/parse_util.ts";
110110
export { getHtmlTagDefinition } from "../../compiler/src/ml_parser/html_tags.ts";
111111
export { SUPPORTED_BLOCKS as SUPPORTED_ANGULAR_BLOCKS } from "../../compiler/src/ml_parser/lexer.ts";
112+
export { splitInterpolation } from "./utilities.ts";
112113

113114
// Types
114115
export type { ParseTreeResult } from "../../compiler/src/ml_parser/parser.ts";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getFakeSpan } from "../../compiler/test/expression_parser/utils/span.ts";
2+
import { Lexer } from "../../compiler/src/expression_parser/lexer.ts";
3+
import {
4+
Parser,
5+
SplitInterpolation,
6+
} from "../../compiler/src/expression_parser/parser.ts";
7+
8+
function createParser(supportsDirectPipeReferences = false) {
9+
return new Parser(new Lexer(), supportsDirectPipeReferences);
10+
}
11+
12+
function splitInterpolation(text: string): SplitInterpolation | null {
13+
return createParser().splitInterpolation(text, getFakeSpan(), [], null);
14+
}
15+
16+
export { splitInterpolation };
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { splitInterpolation } from "../src/index.ts";
2+
3+
test("splitInterpolation", () => {
4+
expect(splitInterpolation('before {{ "}}" }}')).toMatchInlineSnapshot(`
5+
SplitInterpolation {
6+
"expressions": [
7+
{
8+
"end": 19,
9+
"start": 7,
10+
"text": " "}}" ",
11+
},
12+
],
13+
"offsets": [
14+
9,
15+
],
16+
"strings": [
17+
{
18+
"end": 7,
19+
"start": 0,
20+
"text": "before ",
21+
},
22+
{
23+
"end": 19,
24+
"start": 19,
25+
"text": "",
26+
},
27+
],
28+
}
29+
`);
30+
});

0 commit comments

Comments
 (0)