Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent ASI errors for conditional expressions (#3035)
* Prevent ASI errors for conditional expressions * Prevent ASI errors for logical and sequence expressions, also check for throw statements
- Loading branch information
1 parent
44a23bb
commit 288069e
Showing
11 changed files
with
124 additions
and
15 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
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
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
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
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
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
4 changes: 4 additions & 0 deletions
4
test/form/samples/keep-tree-shaking-comments-no-asi/_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,4 @@ | ||
module.exports = { | ||
description: | ||
'always keep leading comments when tree-shaking and no automatic semicolons are inserted' | ||
}; |
14 changes: 14 additions & 0 deletions
14
test/form/samples/keep-tree-shaking-comments-no-asi/_expected.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,14 @@ | ||
console.log( | ||
/* keep me */ | ||
'expected'); | ||
|
||
console.log( | ||
/* keep me */ | ||
'expected' ); | ||
|
||
console.log( | ||
/* keep me */ | ||
'expected'); | ||
|
||
console.log((/* keep me */ | ||
'expected')); |
17 changes: 17 additions & 0 deletions
17
test/form/samples/keep-tree-shaking-comments-no-asi/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,17 @@ | ||
console.log(false ? | ||
'unexpected' : | ||
/* keep me */ | ||
'expected'); | ||
|
||
console.log(true ? | ||
/* keep me */ | ||
'expected' : | ||
'unexpected'); | ||
|
||
console.log(true && | ||
/* keep me */ | ||
'expected'); | ||
|
||
console.log((true, | ||
/* keep me */ | ||
'expected')); |
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,6 @@ | ||
module.exports = { | ||
description: 'prevent automatic semicolon insertion from changing behaviour when tree-shaking', | ||
options: { | ||
treeshake: { tryCatchDeoptimization: false } | ||
} | ||
}; |
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,42 @@ | ||
function test1() { | ||
return true ? | ||
/* kept */ | ||
|
||
'expected' : | ||
'unexpected'; | ||
} | ||
assert.strictEqual(test1(), 'expected'); | ||
|
||
function test2() { | ||
return false ? | ||
'unexpected' : | ||
/* kept */ | ||
|
||
'expected'; | ||
} | ||
assert.strictEqual(test2(), 'expected'); | ||
|
||
function test3() { | ||
return true && | ||
/* kept */ | ||
|
||
'expected'; | ||
} | ||
assert.strictEqual(test3(), 'expected'); | ||
|
||
function test4() { | ||
return 'removed', | ||
/* kept */ | ||
|
||
'expected'; | ||
} | ||
assert.strictEqual(test4(), 'expected'); | ||
|
||
try { | ||
throw true ? | ||
|
||
new Error('expected') : | ||
null; | ||
} catch (err) { | ||
assert.strictEqual(err.message, 'expected'); | ||
} |