Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly render function expression inside simplified expression sta…
- Loading branch information
1 parent
0a46310
commit 14a17af
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
test/function/samples/function-expressions-simplified-to-statement/_config.js
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,3 @@ | ||
module.exports = { | ||
description: 'correctly handles function expressions which are simplified to statements' | ||
}; |
58 changes: 58 additions & 0 deletions
58
test/function/samples/function-expressions-simplified-to-statement/main.js
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,58 @@ | ||
var value; | ||
|
||
// conditional expression | ||
function foo(){ | ||
value = 'foo'; | ||
} | ||
|
||
true ? function foo(x){ | ||
value = x; | ||
}("consequent") : 2; | ||
|
||
assert.equal(value, 'consequent'); | ||
|
||
foo("incorrect"); | ||
|
||
assert.equal(value, 'foo'); | ||
|
||
false ? null: function foo(x){ | ||
value = x; | ||
}("alternate"); | ||
|
||
assert.equal(value, 'alternate'); | ||
|
||
// logical expression | ||
function bar(){ | ||
value = 'bar'; | ||
} | ||
|
||
true && function bar(x){ | ||
value = x; | ||
}("and"); | ||
|
||
assert.equal(value, 'and'); | ||
|
||
bar("incorrect"); | ||
|
||
assert.equal(value, 'bar'); | ||
|
||
false || function bar(x){ | ||
value = x; | ||
}("or"); | ||
|
||
assert.equal(value, 'or'); | ||
|
||
// sequence expression | ||
function baz(){ | ||
value = 'baz'; | ||
} | ||
|
||
0, function baz(x){ | ||
value = x; | ||
}("comma"); | ||
|
||
assert.equal(value, 'comma'); | ||
|
||
baz("incorrect"); | ||
|
||
assert.equal(value, 'baz'); |