diff --git a/src/constants/node-types.ts b/src/constants/node-types.ts index c644faa..216672b 100644 --- a/src/constants/node-types.ts +++ b/src/constants/node-types.ts @@ -36,4 +36,9 @@ export enum NodeTypes { DoctypeAttributeValue = "DoctypeAttributeValue", DoctypeAttributeWrapperStart = "DoctypeAttributeWrapperStart", DoctypeAttributeWrapperEnd = "DoctypeAttributeWrapperEnd", + + OpenTemplate = "OpenTemplate", + Template = "Template", + CloseTemplate = "CloseTemplate", + Part = "Part", } diff --git a/src/constants/token-types.ts b/src/constants/token-types.ts index 94230a9..c5e090d 100644 --- a/src/constants/token-types.ts +++ b/src/constants/token-types.ts @@ -24,4 +24,8 @@ export enum TokenTypes { OpenStyleTagEnd = "OpenStyleTagEnd", StyleTagContent = "StyleTagContent", CloseStyleTag = "CloseStyleTag", + Part = "Part", + OpenTemplate = "OpenTemplate", + Template = "Template", + CloseTemplate = "CloseTemplate", } diff --git a/src/parser/__tests__/__snapshots__/token-adapter.spec.ts.snap b/src/parser/__tests__/__snapshots__/token-adapter.spec.ts.snap index 7846e62..338d69f 100644 --- a/src/parser/__tests__/__snapshots__/token-adapter.spec.ts.snap +++ b/src/parser/__tests__/__snapshots__/token-adapter.spec.ts.snap @@ -18,11 +18,11 @@ exports[`parse basic 1`] = ` "line": 1, }, }, + "parts": [], "range": [ 5, 12, ], - "templates": [], "type": "Text", "value": "content", }, @@ -164,11 +164,11 @@ exports[`parse basic 1`] = ` "line": 1, }, }, + "parts": [], "range": [ 5, 12, ], - "templates": [], "type": "Text", "value": "content", }, @@ -212,11 +212,11 @@ exports[`parse token adapter 1`] = ` "line": 2, }, }, + "parts": [], "range": [ 6, 13, ], - "templates": [], "type": "Text", "value": "content", }, @@ -358,11 +358,11 @@ exports[`parse token adapter 1`] = ` "line": 2, }, }, + "parts": [], "range": [ 6, 13, ], - "templates": [], "type": "Text", "value": "content", }, diff --git a/src/parser/parse.ts b/src/parser/parse.ts index 8c70525..35b9491 100644 --- a/src/parser/parse.ts +++ b/src/parser/parse.ts @@ -7,7 +7,7 @@ import { Options } from "../types/parse"; export function parse(html: string, options?: Options): ParseResult { const tokenAdapter = (options && options.tokenAdapter) || defaultTokenAdapter; - const { tokens } = tokenize(html, tokenAdapter, options?.templateRanges); + const { tokens } = tokenize(html, tokenAdapter, options?.templateInfos); const { ast } = constructTree(tokens); return { ast: clearParent(ast), diff --git a/src/tokenizer/__tests__/__output__/attributes-apostrophe.ts b/src/tokenizer/__tests__/__output__/attributes-apostrophe.ts index ad22efb..fe5ea7c 100644 --- a/src/tokenizer/__tests__/__output__/attributes-apostrophe.ts +++ b/src/tokenizer/__tests__/__output__/attributes-apostrophe.ts @@ -45,7 +45,7 @@ export default [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -76,7 +76,7 @@ export default [ column: 13, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -122,7 +122,7 @@ export default [ column: 25, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -153,7 +153,7 @@ export default [ column: 36, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -199,7 +199,7 @@ export default [ column: 48, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -245,7 +245,7 @@ export default [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -291,7 +291,7 @@ export default [ column: 6, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -322,7 +322,7 @@ export default [ column: 19, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -368,7 +368,7 @@ export default [ column: 33, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -399,7 +399,7 @@ export default [ column: 19, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -445,7 +445,7 @@ export default [ line: 10, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -491,7 +491,7 @@ export default [ line: 14, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -522,7 +522,7 @@ export default [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -553,7 +553,7 @@ export default [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -584,7 +584,7 @@ export default [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -615,6 +615,6 @@ export default [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/attributes-bare-wrong-quote.ts b/src/tokenizer/__tests__/__output__/attributes-bare-wrong-quote.ts index 29d9a99..a31d235 100644 --- a/src/tokenizer/__tests__/__output__/attributes-bare-wrong-quote.ts +++ b/src/tokenizer/__tests__/__output__/attributes-bare-wrong-quote.ts @@ -31,7 +31,7 @@ const OUTPUT: AnyToken[] = [ column: 9, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -62,7 +62,7 @@ const OUTPUT: AnyToken[] = [ column: 18, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagEnd, diff --git a/src/tokenizer/__tests__/__output__/attributes-bare.ts b/src/tokenizer/__tests__/__output__/attributes-bare.ts index 042e23e..17a7261 100644 --- a/src/tokenizer/__tests__/__output__/attributes-bare.ts +++ b/src/tokenizer/__tests__/__output__/attributes-bare.ts @@ -30,7 +30,7 @@ export default [ column: 8, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -61,7 +61,7 @@ export default [ column: 16, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeKey, @@ -77,7 +77,7 @@ export default [ column: 29, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -108,7 +108,7 @@ export default [ column: 37, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagEnd, @@ -154,7 +154,7 @@ export default [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -185,7 +185,7 @@ export default [ column: 10, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -216,7 +216,7 @@ export default [ column: 27, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagEnd, @@ -247,7 +247,7 @@ export default [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -278,7 +278,7 @@ export default [ column: 21, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -309,7 +309,7 @@ export default [ column: 26, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeKey, @@ -325,7 +325,7 @@ export default [ column: 12, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -356,7 +356,7 @@ export default [ column: 19, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagEnd, @@ -387,7 +387,7 @@ export default [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -418,7 +418,7 @@ export default [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -449,6 +449,6 @@ export default [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/attributes-empty.ts b/src/tokenizer/__tests__/__output__/attributes-empty.ts index 678f427..b764c72 100644 --- a/src/tokenizer/__tests__/__output__/attributes-empty.ts +++ b/src/tokenizer/__tests__/__output__/attributes-empty.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -92,7 +92,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -123,7 +123,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -154,7 +154,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/attributes-multiline-crlf.ts b/src/tokenizer/__tests__/__output__/attributes-multiline-crlf.ts index 0307ebd..0420c8c 100644 --- a/src/tokenizer/__tests__/__output__/attributes-multiline-crlf.ts +++ b/src/tokenizer/__tests__/__output__/attributes-multiline-crlf.ts @@ -31,7 +31,7 @@ const OUTPUT: AnyToken[] = [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -77,7 +77,7 @@ const OUTPUT: AnyToken[] = [ column: 9, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -108,7 +108,7 @@ const OUTPUT: AnyToken[] = [ column: 7, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -154,7 +154,7 @@ const OUTPUT: AnyToken[] = [ column: 12, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -185,7 +185,7 @@ const OUTPUT: AnyToken[] = [ column: 6, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagEnd, @@ -216,7 +216,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -247,7 +247,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/attributes-quote.ts b/src/tokenizer/__tests__/__output__/attributes-quote.ts index 2c5d6d4..b00812e 100644 --- a/src/tokenizer/__tests__/__output__/attributes-quote.ts +++ b/src/tokenizer/__tests__/__output__/attributes-quote.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -77,7 +77,7 @@ const OUTPUT: AnyToken[] = [ column: 13, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -123,7 +123,7 @@ const OUTPUT: AnyToken[] = [ column: 25, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -154,7 +154,7 @@ const OUTPUT: AnyToken[] = [ column: 36, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -200,7 +200,7 @@ const OUTPUT: AnyToken[] = [ column: 48, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -246,7 +246,7 @@ const OUTPUT: AnyToken[] = [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -292,7 +292,7 @@ const OUTPUT: AnyToken[] = [ column: 6, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -323,7 +323,7 @@ const OUTPUT: AnyToken[] = [ column: 19, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -369,7 +369,7 @@ const OUTPUT: AnyToken[] = [ column: 33, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -400,7 +400,7 @@ const OUTPUT: AnyToken[] = [ column: 19, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -446,7 +446,7 @@ const OUTPUT: AnyToken[] = [ column: 37, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -492,7 +492,7 @@ const OUTPUT: AnyToken[] = [ column: 6, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -523,7 +523,7 @@ const OUTPUT: AnyToken[] = [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -554,7 +554,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -585,7 +585,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -616,7 +616,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/comments.ts b/src/tokenizer/__tests__/__output__/comments.ts index f49401e..ddb1131 100644 --- a/src/tokenizer/__tests__/__output__/comments.ts +++ b/src/tokenizer/__tests__/__output__/comments.ts @@ -31,7 +31,7 @@ const OUTPUT: AnyToken[] = [ column: 18, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentClose, @@ -62,7 +62,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -108,7 +108,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -154,7 +154,7 @@ const OUTPUT: AnyToken[] = [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentOpen, @@ -185,7 +185,7 @@ const OUTPUT: AnyToken[] = [ column: 19, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentClose, @@ -216,7 +216,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -247,7 +247,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentOpen, @@ -278,7 +278,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentClose, @@ -309,7 +309,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -340,7 +340,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentOpen, @@ -371,7 +371,7 @@ const OUTPUT: AnyToken[] = [ column: 8, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentClose, @@ -402,7 +402,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentOpen, @@ -433,7 +433,7 @@ const OUTPUT: AnyToken[] = [ column: 34, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CommentClose, @@ -464,7 +464,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/custom-elements.ts b/src/tokenizer/__tests__/__output__/custom-elements.ts index f522dc1..30adf5a 100644 --- a/src/tokenizer/__tests__/__output__/custom-elements.ts +++ b/src/tokenizer/__tests__/__output__/custom-elements.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -92,7 +92,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -123,7 +123,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -154,7 +154,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/doctypes.ts b/src/tokenizer/__tests__/__output__/doctypes.ts index b2013aa..2c0d6fe 100644 --- a/src/tokenizer/__tests__/__output__/doctypes.ts +++ b/src/tokenizer/__tests__/__output__/doctypes.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.DoctypeOpen, @@ -92,7 +92,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.DoctypeOpen, @@ -228,7 +228,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.DoctypeOpen, @@ -304,7 +304,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.DoctypeOpen, @@ -470,7 +470,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.DoctypeOpen, @@ -636,7 +636,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/nested-tags.ts b/src/tokenizer/__tests__/__output__/nested-tags.ts index a5fe5a5..ca92fd7 100644 --- a/src/tokenizer/__tests__/__output__/nested-tags.ts +++ b/src/tokenizer/__tests__/__output__/nested-tags.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -92,7 +92,7 @@ const OUTPUT: AnyToken[] = [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -138,7 +138,7 @@ const OUTPUT: AnyToken[] = [ column: 4, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -169,7 +169,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -200,7 +200,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -231,7 +231,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/opening-closing-text.ts b/src/tokenizer/__tests__/__output__/opening-closing-text.ts index b8bf0ed..993d998 100644 --- a/src/tokenizer/__tests__/__output__/opening-closing-text.ts +++ b/src/tokenizer/__tests__/__output__/opening-closing-text.ts @@ -16,7 +16,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -77,7 +77,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/script-elements-attributes.ts b/src/tokenizer/__tests__/__output__/script-elements-attributes.ts index 9e02c43..340e095 100644 --- a/src/tokenizer/__tests__/__output__/script-elements-attributes.ts +++ b/src/tokenizer/__tests__/__output__/script-elements-attributes.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -77,7 +77,7 @@ const OUTPUT: AnyToken[] = [ column: 14, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -123,7 +123,7 @@ const OUTPUT: AnyToken[] = [ column: 31, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -154,7 +154,7 @@ const OUTPUT: AnyToken[] = [ column: 44, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -200,7 +200,7 @@ const OUTPUT: AnyToken[] = [ column: 54, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -246,7 +246,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseScriptTag, @@ -277,7 +277,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -308,7 +308,7 @@ const OUTPUT: AnyToken[] = [ column: 8, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -354,7 +354,7 @@ const OUTPUT: AnyToken[] = [ column: 25, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -385,7 +385,7 @@ const OUTPUT: AnyToken[] = [ column: 9, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagEnd, @@ -416,7 +416,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseScriptTag, @@ -447,7 +447,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -478,7 +478,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -509,7 +509,7 @@ const OUTPUT: AnyToken[] = [ column: 13, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeKey, @@ -525,7 +525,7 @@ const OUTPUT: AnyToken[] = [ column: 18, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -571,7 +571,7 @@ const OUTPUT: AnyToken[] = [ column: 35, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -617,7 +617,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseScriptTag, @@ -648,7 +648,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/script-elements.ts b/src/tokenizer/__tests__/__output__/script-elements.ts index 10afe9f..2103153 100644 --- a/src/tokenizer/__tests__/__output__/script-elements.ts +++ b/src/tokenizer/__tests__/__output__/script-elements.ts @@ -16,7 +16,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -62,7 +62,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -108,7 +108,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseScriptTag, @@ -139,7 +139,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -170,7 +170,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/style-elements-attributes.ts b/src/tokenizer/__tests__/__output__/style-elements-attributes.ts index 99813b8..fc02295 100644 --- a/src/tokenizer/__tests__/__output__/style-elements-attributes.ts +++ b/src/tokenizer/__tests__/__output__/style-elements-attributes.ts @@ -31,7 +31,7 @@ const OUTPUT: AnyToken[] = [ column: 11, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -77,7 +77,7 @@ const OUTPUT: AnyToken[] = [ column: 21, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -108,7 +108,7 @@ const OUTPUT: AnyToken[] = [ column: 29, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -154,7 +154,7 @@ const OUTPUT: AnyToken[] = [ column: 40, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -200,7 +200,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseStyleTag, @@ -231,7 +231,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -277,7 +277,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagStart, @@ -308,7 +308,7 @@ const OUTPUT: AnyToken[] = [ line: 9, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeKey, @@ -324,7 +324,7 @@ const OUTPUT: AnyToken[] = [ line: 10, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -370,7 +370,7 @@ const OUTPUT: AnyToken[] = [ column: 18, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, @@ -401,7 +401,7 @@ const OUTPUT: AnyToken[] = [ column: 18, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagEnd, @@ -432,7 +432,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseStyleTag, @@ -463,7 +463,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -494,7 +494,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/style-elements.ts b/src/tokenizer/__tests__/__output__/style-elements.ts index b8b9663..c68f288 100644 --- a/src/tokenizer/__tests__/__output__/style-elements.ts +++ b/src/tokenizer/__tests__/__output__/style-elements.ts @@ -16,7 +16,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagStart, @@ -62,7 +62,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseStyleTag, @@ -93,7 +93,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -139,7 +139,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagStart, @@ -185,7 +185,7 @@ const OUTPUT: AnyToken[] = [ column: 2, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseStyleTag, @@ -216,7 +216,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -247,7 +247,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; diff --git a/src/tokenizer/__tests__/__output__/svg.ts b/src/tokenizer/__tests__/__output__/svg.ts index 36b3e34..734ca24 100644 --- a/src/tokenizer/__tests__/__output__/svg.ts +++ b/src/tokenizer/__tests__/__output__/svg.ts @@ -31,7 +31,7 @@ const OUTPUT: AnyToken[] = [ line: 1, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -77,7 +77,7 @@ const OUTPUT: AnyToken[] = [ line: 1, }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeValueWrapperEnd, diff --git a/src/tokenizer/__tests__/__output__/tags-register.ts b/src/tokenizer/__tests__/__output__/tags-register.ts index 16edc5b..c720254 100644 --- a/src/tokenizer/__tests__/__output__/tags-register.ts +++ b/src/tokenizer/__tests__/__output__/tags-register.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -77,7 +77,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -138,7 +138,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -184,7 +184,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseTag, @@ -215,7 +215,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, @@ -276,7 +276,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -337,7 +337,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -383,7 +383,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseScriptTag, @@ -414,7 +414,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -475,7 +475,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenScriptTagStart, @@ -521,7 +521,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseScriptTag, @@ -552,7 +552,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagStart, @@ -613,7 +613,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagStart, @@ -659,7 +659,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.CloseStyleTag, @@ -690,7 +690,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagStart, @@ -751,7 +751,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenStyleTagStart, @@ -812,7 +812,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, ]; export default OUTPUT; diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-key-wrapper.ts b/src/tokenizer/__tests__/__output__/templates-attributes-key-wrapper.ts new file mode 100644 index 0000000..3be53ae --- /dev/null +++ b/src/tokenizer/__tests__/__output__/templates-attributes-key-wrapper.ts @@ -0,0 +1,110 @@ +export default [ + { + loc: { + end: { + column: 4, + line: 1, + }, + start: { + column: 0, + line: 1, + }, + }, + range: [0, 4], + type: "OpenTagStart", + value: "", + }, + { + loc: { + end: { + column: 18, + line: 1, + }, + start: { + column: 12, + line: 1, + }, + }, + range: [12, 18], + type: "CloseTag", + value: "", + }, +]; diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-key.ts b/src/tokenizer/__tests__/__output__/templates-attributes-key.ts index a881f68..ab6b819 100644 --- a/src/tokenizer/__tests__/__output__/templates-attributes-key.ts +++ b/src/tokenizer/__tests__/__output__/templates-attributes-key.ts @@ -28,7 +28,7 @@ export default [ range: [5, 11], type: "AttributeKey", value: "${key}", - templates: [ + parts: [ { loc: { end: { @@ -41,9 +41,11 @@ export default [ }, }, range: [5, 11], - type: "AttributeKey", + type: "Template", value: "${key}", - isTemplate: true, + open: undefined, + close: undefined, + partOf: "AttributeKey", }, ], }, diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-value-bare.ts b/src/tokenizer/__tests__/__output__/templates-attributes-value-bare.ts index 34d8d80..729b1d4 100644 --- a/src/tokenizer/__tests__/__output__/templates-attributes-value-bare.ts +++ b/src/tokenizer/__tests__/__output__/templates-attributes-value-bare.ts @@ -19,7 +19,7 @@ const OUTPUT: AnyToken[] = [ start: { line: 1, column: 5 }, end: { line: 1, column: 7 }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -38,15 +38,15 @@ const OUTPUT: AnyToken[] = [ end: { line: 1, column: 13 }, }, value: "${id}", - templates: [ + parts: [ { - type: TokenTypes.AttributeValue, + type: TokenTypes.Template, + partOf: TokenTypes.AttributeValue, range: [8, 13], loc: { start: { line: 1, column: 8 }, end: { line: 1, column: 13 }, }, - isTemplate: true, value: "${id}", }, ], diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2.ts b/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2.ts index 858d577..5a41b4a 100644 --- a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2.ts +++ b/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped-2.ts @@ -19,7 +19,7 @@ const OUTPUT: AnyToken[] = [ start: { line: 1, column: 5 }, end: { line: 1, column: 10 }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -47,45 +47,45 @@ const OUTPUT: AnyToken[] = [ end: { line: 1, column: 31 }, }, value: "one ${two} ${three}", - templates: [ + parts: [ { - type: TokenTypes.AttributeValue, + type: TokenTypes.Part, range: [12, 16], loc: { start: { line: 1, column: 12 }, end: { line: 1, column: 16 }, }, - isTemplate: false, + partOf: TokenTypes.AttributeValue, value: "one ", }, { - type: TokenTypes.AttributeValue, + partOf: TokenTypes.AttributeValue, + type: TokenTypes.Template, range: [16, 22], loc: { start: { line: 1, column: 16 }, end: { line: 1, column: 22 }, }, - isTemplate: true, value: "${two}", }, { - type: TokenTypes.AttributeValue, + type: TokenTypes.Part, range: [22, 23], loc: { start: { line: 1, column: 22 }, end: { line: 1, column: 23 }, }, - isTemplate: false, + partOf: TokenTypes.AttributeValue, value: " ", }, { - type: TokenTypes.AttributeValue, + partOf: TokenTypes.AttributeValue, + type: TokenTypes.Template, range: [23, 31], loc: { start: { line: 1, column: 23 }, end: { line: 1, column: 31 }, }, - isTemplate: true, value: "${three}", }, ], diff --git a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped.ts b/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped.ts index 30380de..200fda3 100644 --- a/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped.ts +++ b/src/tokenizer/__tests__/__output__/templates-attributes-value-wrapped.ts @@ -19,7 +19,7 @@ const OUTPUT: AnyToken[] = [ start: { line: 1, column: 5 }, end: { line: 1, column: 7 }, }, - templates: [], + parts: [], }, { type: TokenTypes.AttributeAssignment, @@ -47,15 +47,15 @@ const OUTPUT: AnyToken[] = [ end: { line: 1, column: 14 }, }, value: "${id}", - templates: [ + parts: [ { - type: TokenTypes.AttributeValue, + type: TokenTypes.Template, + partOf: TokenTypes.AttributeValue, range: [9, 14], loc: { start: { line: 1, column: 9 }, end: { line: 1, column: 14 }, }, - isTemplate: true, value: "${id}", }, ], diff --git a/src/tokenizer/__tests__/__output__/templates-comment.ts b/src/tokenizer/__tests__/__output__/templates-comment.ts index 7b69702..2863acc 100644 --- a/src/tokenizer/__tests__/__output__/templates-comment.ts +++ b/src/tokenizer/__tests__/__output__/templates-comment.ts @@ -19,16 +19,18 @@ const OUTPUT: AnyToken[] = [ start: { line: 1, column: 4 }, end: { line: 1, column: 14 }, }, - templates: [ + parts: [ { - type: TokenTypes.CommentContent, + type: TokenTypes.Template, + partOf: TokenTypes.CommentContent, value: "${comment}", range: [4, 14], loc: { start: { line: 1, column: 4 }, end: { line: 1, column: 14 }, }, - isTemplate: true, + open: undefined, + close: undefined, }, ], }, diff --git a/src/tokenizer/__tests__/__output__/templates-content-end.ts b/src/tokenizer/__tests__/__output__/templates-content-end.ts index b194ba0..4e3272c 100644 --- a/src/tokenizer/__tests__/__output__/templates-content-end.ts +++ b/src/tokenizer/__tests__/__output__/templates-content-end.ts @@ -16,7 +16,7 @@ const OUTPUT: AnyToken[] = [ range: [0, 10], type: TokenTypes.Text, value: "${content}", - templates: [ + parts: [ { loc: { end: { @@ -29,9 +29,11 @@ const OUTPUT: AnyToken[] = [ }, }, range: [0, 10], - type: TokenTypes.Text, + type: TokenTypes.Template, value: "${content}", - isTemplate: true, + partOf: TokenTypes.Text, + open: undefined, + close: undefined, }, ], }, diff --git a/src/tokenizer/__tests__/__output__/templates-data.ts b/src/tokenizer/__tests__/__output__/templates-data.ts index e61ff7f..37a1307 100644 --- a/src/tokenizer/__tests__/__output__/templates-data.ts +++ b/src/tokenizer/__tests__/__output__/templates-data.ts @@ -28,16 +28,16 @@ const OUTPUT: AnyToken[] = [ start: { line: 1, column: 5 }, end: { line: 1, column: 16 }, }, - templates: [ + parts: [ { - type: TokenTypes.Text, + type: TokenTypes.Template, + partOf: TokenTypes.Text, value: "${children}", range: [5, 16], loc: { start: { line: 1, column: 5 }, end: { line: 1, column: 16 }, }, - isTemplate: true, }, ], }, diff --git a/src/tokenizer/__tests__/__output__/templates-script-content.ts b/src/tokenizer/__tests__/__output__/templates-script-content.ts index 93f96eb..9c02cb1 100644 --- a/src/tokenizer/__tests__/__output__/templates-script-content.ts +++ b/src/tokenizer/__tests__/__output__/templates-script-content.ts @@ -28,16 +28,18 @@ const OUTPUT: AnyToken[] = [ start: { line: 1, column: 8 }, end: { line: 1, column: 18 }, }, - templates: [ + parts: [ { - type: TokenTypes.ScriptTagContent, + type: TokenTypes.Template, value: "${content}", range: [8, 18], loc: { start: { line: 1, column: 8 }, end: { line: 1, column: 18 }, }, - isTemplate: true, + partOf: TokenTypes.ScriptTagContent, + open: undefined, + close: undefined, }, ], }, diff --git a/src/tokenizer/__tests__/__output__/templates-style-content.ts b/src/tokenizer/__tests__/__output__/templates-style-content.ts index 57724ae..c69e396 100644 --- a/src/tokenizer/__tests__/__output__/templates-style-content.ts +++ b/src/tokenizer/__tests__/__output__/templates-style-content.ts @@ -28,16 +28,16 @@ const OUTPUT: AnyToken[] = [ start: { line: 1, column: 7 }, end: { line: 1, column: 17 }, }, - templates: [ + parts: [ { - type: TokenTypes.StyleTagContent, + type: TokenTypes.Template, value: "${content}", range: [7, 17], loc: { start: { line: 1, column: 7 }, end: { line: 1, column: 17 }, }, - isTemplate: true, + partOf: TokenTypes.StyleTagContent, }, ], }, diff --git a/src/tokenizer/__tests__/__output__/void-tags.ts b/src/tokenizer/__tests__/__output__/void-tags.ts index b6b1341..c823574 100644 --- a/src/tokenizer/__tests__/__output__/void-tags.ts +++ b/src/tokenizer/__tests__/__output__/void-tags.ts @@ -46,7 +46,7 @@ const OUTPUT: AnyToken[] = [ column: 0, }, }, - templates: [], + parts: [], }, { type: TokenTypes.OpenTagStart, diff --git a/src/tokenizer/__tests__/tokenize.spec.ts b/src/tokenizer/__tests__/tokenize.spec.ts index 6819226..b6d4454 100644 --- a/src/tokenizer/__tests__/tokenize.spec.ts +++ b/src/tokenizer/__tests__/tokenize.spec.ts @@ -21,6 +21,7 @@ import SVG from "./__output__/svg"; import ATTRIBUTES_MULTILINE_CRLF from "./__output__/attributes-multiline-crlf"; import ATTRIBUTES_BARE_WRONG_QUOTE from "./__output__/attributes-bare-wrong-quote"; import TEMPLATE_ATTRIBUTES_KEY from "./__output__/templates-attributes-key"; +import TEMPLATE_ATTRIBUTES_KEY_WRAPPER from "./__output__/templates-attributes-key-wrapper"; import TEMPLATE_ATTRIBUTES_VALUE_BARE from "./__output__/templates-attributes-value-bare"; import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED from "./__output__/templates-attributes-value-wrapped"; import TEMPLATE_ATTRIBUTES_VALUE_WRAPPED_2 from "./__output__/templates-attributes-value-wrapped-2"; @@ -31,7 +32,7 @@ import TEMPLATE_STYLE_CONTENT from "./__output__/templates-style-content"; import TEMPLATE_CONTENT_END from "./__output__/templates-content-end"; import { defaultTokenAdapter } from "../../token-adapter"; -import { Range } from "../../types"; +import { Range, TemplateInfo } from "../../types"; describe("tokenize", () => { test.each([ @@ -99,6 +100,18 @@ describe("tokenize", () => { null, [[5, 11]] as Range[], ], + [ + "Template Attributes Key (wrapper)", + "templates-attributes-key.html", + TEMPLATE_ATTRIBUTES_KEY_WRAPPER, + null, + [ + { + open: [5, 7], + close: [10, 11], + }, + ] as TemplateInfo[], + ], [ "Template Attributes Value Bare", "templates-attributes-value-bare.html", @@ -165,7 +178,7 @@ describe("tokenize", () => { input, output, process: null | ((html: string) => string) = null, - ranges: null | Range[] + ranges: null | TemplateInfo[] ) => { const inputPath = path.join(__dirname, "__input__", input); let html = fs.readFileSync(inputPath, "utf-8"); diff --git a/src/tokenizer/chars-buffer.ts b/src/tokenizer/chars-buffer.ts index 0d7f229..535d9bc 100644 --- a/src/tokenizer/chars-buffer.ts +++ b/src/tokenizer/chars-buffer.ts @@ -27,7 +27,7 @@ export class CharsBuffer { return this.charsBuffer.some((char) => char.isTemplate); } - public getTemplates() { + public getParts() { return [...this.charsBuffer]; } diff --git a/src/tokenizer/chars.ts b/src/tokenizer/chars.ts index 28fae7d..5f428c3 100644 --- a/src/tokenizer/chars.ts +++ b/src/tokenizer/chars.ts @@ -1,11 +1,25 @@ import { Range } from "../types"; +export enum CharsType { + HTML = "HTML", + OpenTemplate = "OpenTemplate", + Template = "Template", + CloseTemplate = "CloseTemplate", +} + export class Chars { + public isTemplate: boolean; constructor( + public type: CharsType, public value: string, public range: Range, - public isTemplate: boolean - ) {} + public wrapper?: { + open: Range; + close: Range; + } + ) { + this.isTemplate = type !== CharsType.HTML; + } public concat(chars: Chars): void { this.value += chars.value; diff --git a/src/tokenizer/handlers/attribute-key.ts b/src/tokenizer/handlers/attribute-key.ts index 8cd3a0e..dda5e86 100644 --- a/src/tokenizer/handlers/attribute-key.ts +++ b/src/tokenizer/handlers/attribute-key.ts @@ -1,9 +1,8 @@ import { TokenizerContextTypes } from "../../constants"; import { TokenTypes } from "../../constants/token-types"; -import { calculateTokenPosition, isWhitespace } from "../../utils"; +import { calculateTokenPosition, isWhitespace, createParts } from "../../utils"; import type { TokenizerState } from "../../types"; import { CharsBuffer } from "../chars-buffer"; -import { createTemplates } from "../../utils/create-templates"; export function parse(chars: CharsBuffer, state: TokenizerState) { if (isKeyBreak(chars)) { @@ -28,7 +27,7 @@ function parseKeyEnd(state: TokenizerState) { value: state.accumulatedContent.value(), range: position.range, loc: position.loc, - templates: createTemplates(state, TokenTypes.AttributeKey), + parts: createParts(state, TokenTypes.AttributeKey), }); state.accumulatedContent.clear(); diff --git a/src/tokenizer/handlers/attribute-value-bare.ts b/src/tokenizer/handlers/attribute-value-bare.ts index 7bcd1f0..ccf0105 100644 --- a/src/tokenizer/handlers/attribute-value-bare.ts +++ b/src/tokenizer/handlers/attribute-value-bare.ts @@ -1,8 +1,7 @@ import { TokenizerContextTypes, TokenTypes } from "../../constants"; -import { calculateTokenPosition, isWhitespace } from "../../utils"; +import { calculateTokenPosition, isWhitespace, createParts } from "../../utils"; import type { TokenizerState } from "../../types"; import { CharsBuffer } from "../chars-buffer"; -import { createTemplates } from "../../utils/create-templates"; export function parseValueEnd(state: TokenizerState) { const position = calculateTokenPosition(state, { keepBuffer: false }); @@ -12,7 +11,7 @@ export function parseValueEnd(state: TokenizerState) { value: state.accumulatedContent.value(), range: position.range, loc: position.loc, - templates: createTemplates(state, TokenTypes.AttributeValue), + parts: createParts(state, TokenTypes.AttributeValue), }); state.accumulatedContent.clear(); diff --git a/src/tokenizer/handlers/attribute-value-wrapped.ts b/src/tokenizer/handlers/attribute-value-wrapped.ts index 08dac10..09d4211 100644 --- a/src/tokenizer/handlers/attribute-value-wrapped.ts +++ b/src/tokenizer/handlers/attribute-value-wrapped.ts @@ -1,8 +1,7 @@ import { TokenizerContextTypes, TokenTypes } from "../../constants"; -import { calculateTokenPosition } from "../../utils"; +import { calculateTokenPosition, createParts } from "../../utils"; import type { Range, TokenizerState } from "../../types"; import { CharsBuffer } from "../chars-buffer"; -import { createTemplates } from "../../utils/create-templates"; export function parse(chars: CharsBuffer, state: TokenizerState) { const wrapperChar = @@ -26,7 +25,7 @@ function parseWrapper(state: TokenizerState) { value: state.accumulatedContent.value(), range: position.range, loc: position.loc, - templates: createTemplates(state, TokenTypes.AttributeValue), + parts: createParts(state, TokenTypes.AttributeValue), }); const range: Range = [endWrapperPosition, endWrapperPosition + 1]; diff --git a/src/tokenizer/handlers/comment-content.ts b/src/tokenizer/handlers/comment-content.ts index 8da09b2..16d76ca 100644 --- a/src/tokenizer/handlers/comment-content.ts +++ b/src/tokenizer/handlers/comment-content.ts @@ -1,8 +1,7 @@ import { TokenizerContextTypes, TokenTypes } from "../../constants"; -import { calculateTokenPosition } from "../../utils"; +import { calculateTokenPosition, createParts } from "../../utils"; import type { Range, TokenizerState } from "../../types"; import { CharsBuffer } from "../chars-buffer"; -import { createTemplates } from "../../utils/create-templates"; const COMMENT_END = "-->"; @@ -34,7 +33,7 @@ function parseCommentClose(state: TokenizerState) { value: state.accumulatedContent.value(), range: position.range, loc: position.loc, - templates: createTemplates(state, TokenTypes.CommentContent), + parts: createParts(state, TokenTypes.CommentContent), }); state.tokens.push({ type: TokenTypes.CommentClose, diff --git a/src/tokenizer/handlers/data.ts b/src/tokenizer/handlers/data.ts index fcd271c..2d6f847 100644 --- a/src/tokenizer/handlers/data.ts +++ b/src/tokenizer/handlers/data.ts @@ -1,8 +1,7 @@ import { TokenizerContextTypes, TokenTypes } from "../../constants"; -import { calculateTokenPosition } from "../../utils"; +import { calculateTokenPosition, createParts } from "../../utils"; import { Range, AnyToken, TokenizerState } from "../../types"; import { CharsBuffer } from "../chars-buffer"; -import { createTemplates } from "../../utils/create-templates"; const COMMENT_START = "