Skip to content
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

Improve comments support #674

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions packages/babel-minify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,50 @@ module.exports = function babelMinify(
input,
// Minify options passed to minifyPreset
// defaults are handled in preset
options = {},
minifyOpts = {},
// overrides and other options
{
minified = true,
inputSourceMap = null,
sourceMaps = false,
comments = /^\**!|@preserve|@license|@cc_on/,

// to override the default babelCore used
babel = babelCore,

// to override the default minify preset used
minifyPreset = babelPresetMinify
minifyPreset = babelPresetMinify,

filename,
filenameRelative
} = {}
) {
return babel.transform(input, {
minified,
babelrc: false,
presets: [[minifyPreset, options]],
comments: false,
inputSourceMap,
ast: false,

presets: [[minifyPreset, minifyOpts]],

sourceMaps,
minified
inputSourceMap,

shouldPrintComment(contents) {
return shouldPrintComment(contents, comments);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work right now. Looks like a babel bug ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we haven't upgraded babel version for quite sometime right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's a babel-generator option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It is. I'm not sure why this function is not called at all.

},

filename,
filenameRelative
});
};

function shouldPrintComment(contents, predicate) {
switch (typeof predicate) {
case "function":
return predicate(contents);
case "object":
return predicate.test(contents);
default:
return !!predicate;
}
}
2 changes: 1 addition & 1 deletion packages/gulp-babel-minify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function gulpBabelMinify(
{
babel = babelCore,
minifyPreset = babelPresetMinify,
comments = /preserve|licen(s|c)e/
comments = /^\*\*\!|@preserve|@license|@cc_on/
} = {}
) {
return through2.obj(function(file, enc, callback) {
Expand Down