Skip to content

Commit

Permalink
fix: template string compare issue
Browse files Browse the repository at this point in the history
  • Loading branch information
An0nie committed Apr 27, 2023
1 parent 3f9dc03 commit 9309106
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/javascript/JavascriptParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions test/JavascriptParser.unittest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9309106

Please sign in to comment.