Skip to content

Commit

Permalink
fix: ignore string that are part of a binary expression like x + '...'
Browse files Browse the repository at this point in the history
  • Loading branch information
sastan committed Mar 22, 2021
1 parent 62be68d commit 230b0b5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/source-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,44 @@ export class StandardTemplateSourceHelper implements TemplateSourceHelper {
return undefined
}

if (this.typescript.isTaggedTemplateExpression(node)) {
const { typescript: ts } = this

if (ts.isTaggedTemplateExpression(node)) {
return this.getValidTemplateNode(node.template)
}

// TODO if templateSettings.enableForStringWithSubstitutions
if (this.typescript.isTemplateHead(node) || this.typescript.isTemplateSpan(node)) {
if (ts.isTemplateHead(node) || ts.isTemplateSpan(node)) {
return this.getValidTemplateNode(node.parent)
}

if (this.typescript.isTemplateMiddle(node) || this.typescript.isTemplateTail(node)) {
if (ts.isTemplateMiddle(node) || ts.isTemplateTail(node)) {
return this.getValidTemplateNode(node.parent)
}

// TODO Identifier, TemplateHead, TemplateMiddle, TemplateTail
// export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral;
// export type PropertyNameLiteral = Identifier | StringLiteralLike | NumericLiteral;
if (
!(
this.typescript.isStringLiteralLike(node) ||
this.typescript.isTemplateLiteral(node) ||
this.typescript.isTemplateExpression(node)
)
!(ts.isStringLiteralLike(node) || ts.isTemplateLiteral(node) || ts.isTemplateExpression(node))
) {
return undefined
}

// Ignore strings that are part of an expression
// x + '...'
if (ts.isStringLiteralLike(node) && ts.isBinaryExpression(node.parent)) {
return undefined
}

let currentNode: ts.Node = node

while (currentNode && !this.typescript.isSourceFile(currentNode)) {
while (currentNode && !ts.isSourceFile(currentNode)) {
if (match(currentNode, this.sourceMatchers)) {
return node
}

if (this.typescript.isCallLikeExpression(currentNode)) {
if (ts.isCallLikeExpression(currentNode)) {
return undefined
}

Expand Down

0 comments on commit 230b0b5

Please sign in to comment.