Skip to content

Custom template tokenizers #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
don't call the custom tokinzer on root text nodes if we are already p…
…rocessing a custom template lang
  • Loading branch information
rashfael committed Mar 27, 2022
commit 3567b121594ea2fd15e710ba9af3672a1f5b6e6e
6 changes: 6 additions & 0 deletions src/html/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class Parser {
private vPreElement: VElement | null
private postProcessesForScript: ((parserOptions: ParserOptions) => void)[] =
[]
private isUsingCustomTokenizer: boolean

/**
* The source code text.
Expand Down Expand Up @@ -269,6 +270,8 @@ export class Parser {
this.vPreElement = null

this.postProcessesForScript = []

this.isUsingCustomTokenizer = false
}

/**
Expand Down Expand Up @@ -483,6 +486,7 @@ export class Parser {
* @param lang The template language the text token should be parsed as.
*/
private processTemplateText(token: Text, lang: string): void {
this.isUsingCustomTokenizer = true
// eslint-disable-next-line @typescript-eslint/no-require-imports
const TemplateTokenizer = require(this.baseParserOptions
.templateTokenizer![lang])
Expand Down Expand Up @@ -517,6 +521,7 @@ export class Parser {
this.tokenizer.tokens.splice(index, count, ...templateTokenizer.tokens)
this.tokenizer.comments.push(...templateTokenizer.comments)
this.tokenizer.errors.push(...templateTokenizer.errors)
this.isUsingCustomTokenizer = false
}

/**
Expand Down Expand Up @@ -687,6 +692,7 @@ export class Parser {
debug("[html] Text %j", token)
const parent = this.currentNode
if (
!this.isUsingCustomTokenizer &&
token.value &&
parent.type === "VElement" &&
parent.name === "template"
Expand Down