fix: template string compare issue

This commit is contained in:
An0nie 2023-04-27 13:30:37 +02:00
parent 3f9dc033a8
commit 9309106146
2 changed files with 15 additions and 5 deletions

View File

@ -545,11 +545,13 @@ class JavascriptParser extends Parser {
const rightSuffix = getSuffix(right.parts);
const lenPrefix = Math.min(leftPrefix.length, rightPrefix.length);
const lenSuffix = Math.min(leftSuffix.length, rightSuffix.length);
if (
leftPrefix.slice(0, lenPrefix) !==
rightPrefix.slice(0, lenPrefix) ||
leftSuffix.slice(-lenSuffix) !== rightSuffix.slice(-lenSuffix)
) {
const prefixMismatch =
lenPrefix > 0 &&
leftPrefix.slice(0, lenPrefix) !== rightPrefix.slice(0, lenPrefix);
const suffixMismatch =
lenSuffix > 0 &&
leftSuffix.slice(-lenSuffix) !== rightSuffix.slice(-lenSuffix);
if (prefixMismatch || suffixMismatch) {
return res
.setBoolean(!eql)
.setSideEffects(

View File

@ -541,6 +541,14 @@ describe("JavascriptParser", () => {
"`start${'str'}mid${obj2}end`":
// eslint-disable-next-line no-template-curly-in-string
"template=[start${'str'}mid string=startstrmid],[end string=end]",
// eslint-disable-next-line no-template-curly-in-string
"`a${x}` === `b${x}`": "bool=false",
// eslint-disable-next-line no-template-curly-in-string
"`${x}a` === `${x}b`": "bool=false",
// eslint-disable-next-line no-template-curly-in-string
"`${a}${b}` === `a${b}`": "",
// eslint-disable-next-line no-template-curly-in-string
"`${a}${b}` === `${a}b`": "",
"'abc'.slice(1)": "string=bc",
"'abcdef'.slice(2, 5)": "string=cde",
"'abcdef'.substring(2, 3)": "string=c",