-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: better coverage for
un-if-statement
- Loading branch information
Showing
2 changed files
with
171 additions
and
45 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
packages/unminify/src/transformations/__tests__/un-if-statement.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import transform from '../un-if-statement' | ||
import { defineInlineTest } from './test-utils' | ||
|
||
const inlineTest = defineInlineTest(transform) | ||
|
||
inlineTest('nested ternary expression', | ||
` | ||
a ? b() : c ? d() : e() | ||
`, | ||
` | ||
if (a) { | ||
b(); | ||
} | ||
if (c) { | ||
d(); | ||
} | ||
e() | ||
`, | ||
) | ||
|
||
inlineTest('nested logical expression', | ||
` | ||
x == 'a' || x == 'b' || x == 'c' && x == 'd' | ||
`, | ||
` | ||
x == 'a' || x == 'b' || x == 'c' && x == 'd' | ||
`, | ||
) | ||
|
||
// inlineTest('return simple logical expression', | ||
// ` | ||
// return x == 'a' || x == 'b' || x == 'c' && x == 'd' | ||
// `, | ||
// ` | ||
// if (!) | ||
// `, | ||
// ) | ||
|
||
inlineTest('simple ternary expression', | ||
` | ||
x ? a() : b() | ||
`, | ||
` | ||
if (x) { | ||
a(); | ||
} else { | ||
b(); | ||
} | ||
`, | ||
) | ||
|
||
inlineTest('simple logical expression', | ||
` | ||
x && a(); | ||
x || b(); | ||
x ?? c(); | ||
`, | ||
` | ||
if (x) { | ||
a(); | ||
}; | ||
if (!x) { | ||
b(); | ||
}; | ||
if (x == null) { | ||
c(); | ||
}; | ||
`, | ||
) | ||
|
||
inlineTest('should not transform if statement', | ||
` | ||
var foo = x && a(); | ||
bar = x || a(); | ||
if (x && a()) { | ||
b(); | ||
} | ||
arr.push(x && a()); | ||
arr.push({ prop: x && a() }); | ||
function fn() { | ||
return x ? a() : b() | ||
} | ||
function fn2(p = x && a()) { | ||
return p && b(); | ||
} | ||
`, | ||
` | ||
var foo = x && a(); | ||
bar = x || a(); | ||
if (x && a()) { | ||
b(); | ||
} | ||
arr.push(x && a()); | ||
arr.push({ prop: x && a() }); | ||
function fn() { | ||
return x ? a() : b() | ||
} | ||
function fn2(p = x && a()) { | ||
return p && b(); | ||
} | ||
`, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters