Skip to content

Commit

Permalink
fix: binary expression in template need quote
Browse files Browse the repository at this point in the history
  • Loading branch information
meixg committed Nov 13, 2019
1 parent f899861 commit 66b1215
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,14 @@ export function emitFile(

function emitTemplateSpan(node: ts.TemplateSpan) {
writeSpace();
let needQuote = !ts.isIdentifier(node.expression);
if (needQuote) {
writePunctuation("(");
}
emitExpression(node.expression);
if (needQuote) {
writePunctuation(")");
}
emit(node.literal);
}

Expand Down
3 changes: 3 additions & 0 deletions test/features/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
$b = "123";
$c = "0" . $b . "45'6'\"789\"";
$s = "1" . $b . "2" . $b . "3" . $b . "4";
$sa = "111";
$i = 123;
$sa . "_" . ($i ? "a" : "b") . "_" . ($i + 2) . "_" . ("1" . $b . "2" . $b . "3" . $b . "4");
4 changes: 4 additions & 0 deletions test/features/template.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const b = `123`;
const c = `0${b}45'6'"789"`;
const s = `1${b}2${b}3${b}4`;

let sa = '111';
let i = 123;
sa + `_${i ? 'a' : 'b'}_${i + 2}_${`1${b}2${b}3${b}4`}`;

0 comments on commit 66b1215

Please sign in to comment.