diff --git a/src/tokenizer/tokenize.ts b/src/tokenizer/tokenize.ts index ad8ab63..bd121a8 100644 --- a/src/tokenizer/tokenize.ts +++ b/src/tokenizer/tokenize.ts @@ -74,6 +74,7 @@ export function tokenize( templateRanges: templateRanges || [], decisionBuffer: new CharsBuffer(), accumulatedContent: new CharsBuffer(), + tokenAdapter, sourceCode: new SourceCode(source, templateRanges || []), tokens: { push(token: AnyToken) { diff --git a/src/types/tokenizer-state.ts b/src/types/tokenizer-state.ts index a9f2e09..96f0404 100644 --- a/src/types/tokenizer-state.ts +++ b/src/types/tokenizer-state.ts @@ -4,6 +4,7 @@ import { CharsBuffer } from "../tokenizer/chars-buffer"; import { SourceCode } from "../tokenizer/source-code"; import { Range } from "./range"; import { AnyToken } from "./token"; +import { TokenAdapter } from "./token-adapter"; type ContextParams = { [TokenizerContextTypes.AttributeValueWrapped]?: { @@ -26,8 +27,8 @@ export type TokenizerState = { contextParams: ContextParams; decisionBuffer: CharsBuffer; accumulatedContent: CharsBuffer; - // pointer: CharPointer; templateRanges: Range[]; + tokenAdapter: TokenAdapter; sourceCode: SourceCode; tokens: { push(token: AnyToken): void; diff --git a/src/utils/create-templates.ts b/src/utils/create-templates.ts index 6f2dd0c..d8d22de 100644 --- a/src/utils/create-templates.ts +++ b/src/utils/create-templates.ts @@ -6,12 +6,19 @@ export function createTemplates( type: T ): TemplatableToken[] { return state.mode === "template" && state.accumulatedContent.hasTemplate() - ? state.accumulatedContent.getTemplates().map((chars) => ({ - type: type, - range: chars.range, - loc: state.sourceCode.getLocationOf(chars.range), - isTemplate: chars.isTemplate, - value: chars.value, - })) + ? state.accumulatedContent.getTemplates().map((chars) => { + const token = { + type: type, + range: chars.range, + loc: state.sourceCode.getLocationOf(chars.range), + isTemplate: chars.isTemplate, + value: chars.value, + }; + return { + ...token, + range: state.tokenAdapter.finalizeRange(token), + loc: state.tokenAdapter.finalizeLocation(token), + }; + }) : []; }