Skip to content

Commit 32bd65a

Browse files
authored
support ExtendScript parser quirks (#5648)
closes #1144
1 parent 318206d commit 32bd65a

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,9 @@ can pass additional arguments that control the code output:
930930
}
931931
```
932932

933+
- `extendscript` (default: `false`) — enable workarounds for Adobe ExtendScript
934+
bugs
935+
933936
- `galio` (default: `false`) — enable workarounds for ANT Galio bugs
934937

935938
- `indent_level` (default: `4`) — indent by specified number of spaces or the
@@ -1446,3 +1449,17 @@ To allow for better optimizations, the compiler makes various assumptions:
14461449
// Actual: TypeError: invalid assignment to const 'f'
14471450
```
14481451
UglifyJS may modify the input which in turn may suppress those errors.
1452+
- Adobe ExtendScript will give incorrect results with the following:
1453+
```javascript
1454+
alert(true ? "PASS" : false ? "FAIL" : null);
1455+
// Expected: "PASS"
1456+
// Actual: "FAIL"
1457+
```
1458+
UglifyJS may modify the input which in turn may suppress those errors.
1459+
- Adobe ExtendScript will give incorrect results with the following:
1460+
```javascript
1461+
alert(42 ? null ? "FAIL" : "PASS" : "FAIL");
1462+
// Expected: "PASS"
1463+
// Actual: SyntaxError: Expected: :
1464+
```
1465+
UglifyJS may modify the input which in turn may suppress those errors.

lib/output.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function OutputStream(options) {
5555
beautify : false,
5656
braces : false,
5757
comments : false,
58+
extendscript : false,
5859
galio : false,
5960
ie : false,
6061
indent_level : 4,
@@ -700,6 +701,7 @@ function OutputStream(options) {
700701
if (p instanceof AST_Class) return true;
701702
// (x++)[y]
702703
// (typeof x).y
704+
// https://github.com/mishoo/UglifyJS/issues/115
703705
if (p instanceof AST_PropAccess) return p.expression === this;
704706
// (~x)`foo`
705707
if (p instanceof AST_Template) return p.tag === this;
@@ -875,7 +877,9 @@ function OutputStream(options) {
875877
return needs_parens_assign_cond(this, output);
876878
});
877879
PARENS(AST_Conditional, function(output) {
878-
return needs_parens_assign_cond(this, output);
880+
return needs_parens_assign_cond(this, output)
881+
// https://github.com/mishoo/UglifyJS/issues/1144
882+
|| output.option("extendscript") && output.parent() instanceof AST_Conditional;
879883
});
880884
PARENS(AST_Yield, function(output) {
881885
return needs_parens_assign_cond(this, output);

test/compress/conditionals.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,52 @@ trivial_boolean_ternary_expressions : {
11761176
}
11771177
}
11781178

1179+
extendscript_1: {
1180+
beautify = {
1181+
extendscript: true,
1182+
}
1183+
input: {
1184+
var alert = console.log;
1185+
function f(a, b) {
1186+
return a ? b ? "foo" : "bar" : "baz";
1187+
}
1188+
alert(f());
1189+
alert(f(42));
1190+
alert(f(null, true));
1191+
alert(f([], {}));
1192+
}
1193+
expect_exact: 'var alert=console.log;function f(a,b){return a?(b?"foo":"bar"):"baz"}alert(f());alert(f(42));alert(f(null,true));alert(f([],{}));'
1194+
expect_stdout: [
1195+
"baz",
1196+
"bar",
1197+
"baz",
1198+
"foo",
1199+
]
1200+
}
1201+
1202+
extendscript_2: {
1203+
beautify = {
1204+
extendscript: true,
1205+
}
1206+
input: {
1207+
var alert = console.log;
1208+
function f(a, b) {
1209+
return a ? "foo" : b ? "bar" : "baz";
1210+
}
1211+
alert(f());
1212+
alert(f(42));
1213+
alert(f(null, true));
1214+
alert(f([], {}));
1215+
}
1216+
expect_exact: 'var alert=console.log;function f(a,b){return a?"foo":(b?"bar":"baz")}alert(f());alert(f(42));alert(f(null,true));alert(f([],{}));'
1217+
expect_stdout: [
1218+
"baz",
1219+
"foo",
1220+
"bar",
1221+
"foo",
1222+
]
1223+
}
1224+
11791225
issue_1154: {
11801226
options = {
11811227
booleans: true,

0 commit comments

Comments
 (0)