@@ -54,6 +54,10 @@ import {
5454} from "../common/parser-options"
5555import sortedIndexBy from "lodash/sortedIndexBy"
5656import sortedLastIndexBy from "lodash/sortedLastIndexBy"
57+ import type {
58+ CustomTemplateTokenizer ,
59+ CustomTemplateTokenizerConstructor ,
60+ } from "./custom-tokenizer"
5761
5862const DIRECTIVE_NAME = / ^ (?: v - | [ . : @ # ] ) .* [ ^ . : @ # ] $ / u
5963const DT_DD = / ^ d [ d t ] $ / u
@@ -167,7 +171,7 @@ function propagateEndLocation(node: VDocumentFragment | VElement): void {
167171 * This is not following to the HTML spec completely because Vue.js template spec is pretty different to HTML.
168172 */
169173export class Parser {
170- private tokenizer : IntermediateTokenizer
174+ private tokenizer : IntermediateTokenizer | CustomTemplateTokenizer
171175 private locationCalculator : LocationCalculatorForHtml
172176 private baseParserOptions : ParserOptions
173177 private isSFC : boolean
@@ -480,12 +484,17 @@ export class Parser {
480484 /**
481485 * Process the given template text token with a configured template tokenizer, based on language.
482486 * @param token The template text token to process.
483- * @param lang The template language the text token should be parsed as .
487+ * @param templateTokenizerOption The template tokenizer option .
484488 */
485- private processTemplateText ( token : Text , lang : string ) : void {
486- // eslint-disable-next-line @typescript-eslint/no-require-imports
487- const TemplateTokenizer = require ( this . baseParserOptions
488- . templateTokenizer ! [ lang ] )
489+ private processTemplateText (
490+ token : Text ,
491+ templateTokenizerOption : string | CustomTemplateTokenizerConstructor ,
492+ ) : void {
493+ const TemplateTokenizer : CustomTemplateTokenizerConstructor =
494+ typeof templateTokenizerOption === "function"
495+ ? templateTokenizerOption
496+ : // eslint-disable-next-line @typescript-eslint/no-require-imports
497+ require ( templateTokenizerOption )
489498 const templateTokenizer = new TemplateTokenizer (
490499 token . value ,
491500 this . text ,
@@ -696,13 +705,13 @@ export class Parser {
696705 ( a ) => a . key . name === "lang" ,
697706 )
698707 const lang = ( langAttribute ?. value as VLiteral ) ?. value
699- if (
700- lang &&
701- lang !== "html" &&
702- this . baseParserOptions . templateTokenizer ?. [ lang ]
703- ) {
704- this . processTemplateText ( token , lang )
705- return
708+ if ( lang && lang !== "html" ) {
709+ const templateTokenizerOption =
710+ this . baseParserOptions . templateTokenizer ?. [ lang ]
711+ if ( templateTokenizerOption ) {
712+ this . processTemplateText ( token , templateTokenizerOption )
713+ return
714+ }
706715 }
707716 }
708717 parent . children . push ( {
0 commit comments