( ...[head, ...tail]: Params )
| 802 | * @since 3.10.0 |
| 803 | */ |
| 804 | export const TemplateLiteral = <Params extends array_.NonEmptyReadonlyArray<TemplateLiteralParameter>>( |
| 805 | ...[head, ...tail]: Params |
| 806 | ): TemplateLiteral<GetTemplateLiteralType<Params>> => { |
| 807 | const spans: Array<AST.TemplateLiteralSpan> = [] |
| 808 | let h = "" |
| 809 | let ts = tail |
| 810 | |
| 811 | if (isSchema(head)) { |
| 812 | if (AST.isLiteral(head.ast)) { |
| 813 | h = String(head.ast.literal) |
| 814 | } else { |
| 815 | ts = [head, ...ts] |
| 816 | } |
| 817 | } else { |
| 818 | h = String(head) |
| 819 | } |
| 820 | |
| 821 | for (let i = 0; i < ts.length; i++) { |
| 822 | const item = ts[i] |
| 823 | if (isSchema(item)) { |
| 824 | if (i < ts.length - 1) { |
| 825 | const next = ts[i + 1] |
| 826 | if (isSchema(next)) { |
| 827 | if (AST.isLiteral(next.ast)) { |
| 828 | spans.push(new AST.TemplateLiteralSpan(item.ast, String(next.ast.literal))) |
| 829 | i++ |
| 830 | continue |
| 831 | } |
| 832 | } else { |
| 833 | spans.push(new AST.TemplateLiteralSpan(item.ast, String(next))) |
| 834 | i++ |
| 835 | continue |
| 836 | } |
| 837 | } |
| 838 | spans.push(new AST.TemplateLiteralSpan(item.ast, "")) |
| 839 | } else { |
| 840 | spans.push(new AST.TemplateLiteralSpan(new AST.Literal(item), "")) |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if (array_.isNonEmptyArray(spans)) { |
| 845 | return make(new AST.TemplateLiteral(h, spans)) |
| 846 | } else { |
| 847 | return make(new AST.TemplateLiteral("", [new AST.TemplateLiteralSpan(new AST.Literal(h), "")])) |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | type TemplateLiteralParserParameters = Schema.Any | AST.LiteralValue |
| 852 |
no test coverage detected
searching dependent graphs…