Skip to content

Commit

Permalink
fix: cache replaced placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Mar 23, 2021
1 parent d73e931 commit 90f5418
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/source-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ class PlaceholderSubstituter {
}
}

const kText = Symbol('kText')

class StandardTemplateContext /* implements TemplateContext */ {
private [kText]: string | undefined = undefined

constructor(
public readonly typescript: typeof ts,
public readonly fileName: string,
Expand Down Expand Up @@ -113,13 +117,16 @@ class StandardTemplateContext /* implements TemplateContext */ {

// @memoize
public get text(): string {
return this.typescript.isTemplateExpression(this.node)
? PlaceholderSubstituter.replacePlaceholders(
this.typescript,
this.templateSettings,
this.node,
)
: this.node.text
return (
this[kText] ||
(this[kText] = this.typescript.isTemplateExpression(this.node)
? PlaceholderSubstituter.replacePlaceholders(
this.typescript,
this.templateSettings,
this.node,
)
: this.node.text)
)
}

// @memoize
Expand Down

0 comments on commit 90f5418

Please sign in to comment.