Skip to content

Commit

Permalink
Preserve @copyright comments as part of "some" default (#1153)
Browse files Browse the repository at this point in the history
* preserve @copyright comments with "some" default, fixes  #1151

* update relevant README notes for #1151 fix
  • Loading branch information
natevw committed Feb 26, 2022
1 parent 2662736 commit 000dcff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions README.md
Expand Up @@ -127,8 +127,8 @@ a double dash to prevent input files being used as option arguments:
as JSON to STDOUT respectively.
--comments [filter] Preserve copyright comments in the output. By
default this works like Google Closure, keeping
JSDoc-style comments that contain "@license" or
"@preserve". You can optionally pass one of the
JSDoc-style comments that contain e.g. "@license",
or start with "!". You can optionally pass one of the
following arguments to this flag:
- "all" to keep all comments
- `false` to omit comments in the output
Expand Down Expand Up @@ -989,8 +989,8 @@ as "output options".
statement.

- `comments` (default `"some"`) -- by default it keeps JSDoc-style comments
that contain "@license", "@preserve" or start with `!`, pass `true` or
`"all"` to preserve all comments, `false` to omit comments in the output,
that contain "@license", "@copyright", "@preserve" or start with `!`, pass `true`
or `"all"` to preserve all comments, `false` to omit comments in the output,
a regular expression string (e.g. `/^!/`) or a function.

- `ecma` (default `5`) -- set desired EcmaScript standard version for output.
Expand Down Expand Up @@ -1062,9 +1062,9 @@ as "output options".
### Keeping copyright notices or other comments

You can pass `--comments` to retain certain comments in the output. By
default it will keep JSDoc-style comments that contain "@preserve",
"@license" or "@cc_on" (conditional compilation for IE). You can pass
`--comments all` to keep all the comments, or a valid JavaScript regexp to
default it will keep comments starting with "!" and JSDoc-style comments that
contain "@preserve", "@copyright", "@license" or "@cc_on" (conditional compilation for IE).
You can pass `--comments all` to keep all the comments, or a valid JavaScript regexp to
keep only comments that match this regexp. For example `--comments /^!/`
will keep comments like `/*! Copyright Notice */`.

Expand Down
2 changes: 1 addition & 1 deletion lib/output.js
Expand Up @@ -172,7 +172,7 @@ function is_some_comments(comment) {
// multiline comment
return (
(comment.type === "comment2" || comment.type === "comment1")
&& /@preserve|@lic|@cc_on|^\**!/i.test(comment.value)
&& /@preserve|@copyright|@lic|@cc_on|^\**!/i.test(comment.value)
);
}

Expand Down
2 changes: 2 additions & 0 deletions test/compress/comments.js
Expand Up @@ -29,13 +29,15 @@ preserve_comments_by_default: {
/**! foo */
/*! foo */
/* lost */
/* @copyright …info… */
}
expect_exact: [
"var foo={};",
"/* @license */",
"// @lic",
"/**! foo */",
"/*! foo */",
"/* @copyright …info… */",
]
}

Expand Down

0 comments on commit 000dcff

Please sign in to comment.