Skip to content

Commit 230b0b5

Browse files
committed
fix: ignore string that are part of a binary expression like x + '...'
1 parent 62be68d commit 230b0b5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/source-helper.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,40 +219,44 @@ export class StandardTemplateSourceHelper implements TemplateSourceHelper {
219219
return undefined
220220
}
221221

222-
if (this.typescript.isTaggedTemplateExpression(node)) {
222+
const { typescript: ts } = this
223+
224+
if (ts.isTaggedTemplateExpression(node)) {
223225
return this.getValidTemplateNode(node.template)
224226
}
225227

226228
// TODO if templateSettings.enableForStringWithSubstitutions
227-
if (this.typescript.isTemplateHead(node) || this.typescript.isTemplateSpan(node)) {
229+
if (ts.isTemplateHead(node) || ts.isTemplateSpan(node)) {
228230
return this.getValidTemplateNode(node.parent)
229231
}
230232

231-
if (this.typescript.isTemplateMiddle(node) || this.typescript.isTemplateTail(node)) {
233+
if (ts.isTemplateMiddle(node) || ts.isTemplateTail(node)) {
232234
return this.getValidTemplateNode(node.parent)
233235
}
234236

235237
// TODO Identifier, TemplateHead, TemplateMiddle, TemplateTail
236238
// export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral;
237239
// export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral;
238240
if (
239-
!(
240-
this.typescript.isStringLiteralLike(node) ||
241-
this.typescript.isTemplateLiteral(node) ||
242-
this.typescript.isTemplateExpression(node)
243-
)
241+
!(ts.isStringLiteralLike(node) || ts.isTemplateLiteral(node) || ts.isTemplateExpression(node))
244242
) {
245243
return undefined
246244
}
247245

246+
// Ignore strings that are part of an expression
247+
// x + '...'
248+
if (ts.isStringLiteralLike(node) && ts.isBinaryExpression(node.parent)) {
249+
return undefined
250+
}
251+
248252
let currentNode: ts.Node = node
249253

250-
while (currentNode && !this.typescript.isSourceFile(currentNode)) {
254+
while (currentNode && !ts.isSourceFile(currentNode)) {
251255
if (match(currentNode, this.sourceMatchers)) {
252256
return node
253257
}
254258

255-
if (this.typescript.isCallLikeExpression(currentNode)) {
259+
if (ts.isCallLikeExpression(currentNode)) {
256260
return undefined
257261
}
258262

0 commit comments

Comments
 (0)