Skip to content

Commit 90f5418

Browse files
committed
fix: cache replaced placeholders
1 parent d73e931 commit 90f5418

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/source-helper.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ class PlaceholderSubstituter {
7676
}
7777
}
7878

79+
const kText = Symbol('kText')
80+
7981
class StandardTemplateContext /* implements TemplateContext */ {
82+
private [kText]: string | undefined = undefined
83+
8084
constructor(
8185
public readonly typescript: typeof ts,
8286
public readonly fileName: string,
@@ -113,13 +117,16 @@ class StandardTemplateContext /* implements TemplateContext */ {
113117

114118
// @memoize
115119
public get text(): string {
116-
return this.typescript.isTemplateExpression(this.node)
117-
? PlaceholderSubstituter.replacePlaceholders(
118-
this.typescript,
119-
this.templateSettings,
120-
this.node,
121-
)
122-
: this.node.text
120+
return (
121+
this[kText] ||
122+
(this[kText] = this.typescript.isTemplateExpression(this.node)
123+
? PlaceholderSubstituter.replacePlaceholders(
124+
this.typescript,
125+
this.templateSettings,
126+
this.node,
127+
)
128+
: this.node.text)
129+
)
123130
}
124131

125132
// @memoize

0 commit comments

Comments
 (0)