-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep fparens #1371
Keep fparens #1371
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ function OutputStream(options) { | |
quote_style : 0, | ||
keep_quoted_props: false, | ||
wrap_iife : false, | ||
keep_fparens : false | ||
}, true); | ||
|
||
// Convert comment option to RegExp if neccessary and set up comments filter | ||
|
@@ -558,6 +559,14 @@ function OutputStream(options) { | |
return true; | ||
} | ||
|
||
// If option is on then keep wrapping parenthesises | ||
if (output.option('keep_fparens')) { | ||
if (this.start && this.start instanceof AST_Token && this.start.value === '(' && | ||
this.end && this.end instanceof AST_Token && this.end.value === ')') { | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent by 4 |
||
} | ||
} | ||
|
||
if (output.option('wrap_iife')) { | ||
var p = output.parent(); | ||
return p instanceof AST_Call && p.expression === this; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var assert = require("assert"); | ||
var uglify = require("../../"); | ||
|
||
describe("Keep wrapping parentheses", function() { | ||
it("Should keep wrapping parentheses if keep-fparens option is turned on", function() { | ||
var originalCode = "define(\"module\",(function() {module.exports = 42;}));"; | ||
var expectedCode = "define(\"module\",(function(){module.exports=42}));"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use outer single quoted string to avoid need for escaping |
||
var result = uglify.minify(originalCode, { | ||
output: { | ||
keep_fparens: true | ||
}, | ||
fromString: true | ||
}); | ||
assert.strictEqual(result.code, expectedCode); | ||
}); | ||
|
||
it("Should strip wrapping parentheses if keep-fparens option is turned off or not set", function() { | ||
var originalCode = "define(\"module\",(function() {module.exports = 42;}));"; | ||
var expectedCode = "define(\"module\",function(){module.exports=42});"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use outer single quoted string to avoid need for escaping |
||
var result = uglify.minify(originalCode, { | ||
fromString: true | ||
}); | ||
assert.strictEqual(result.code, expectedCode); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add trailing comma