uglify-save-license.js 901 B

12345678910111213141516171819202122232425262728293031323334
  1. // uglify-save-license.js v0.4.1
  2. // Copyright (c) 2013 - 2014 Shinnosuke Watanabe
  3. // Licensed uder the MIT license
  4. 'use strict';
  5. var licenseRegexp = /@preserve|@cc_on|\bMIT\b|\bMPL\b|\bGPL\b|\bBSD\b|\bISCL\b|\(c\)|License|Copyright/mi;
  6. // number of line where license comment appeared last
  7. var prevCommentLine = 0;
  8. // name of the file minified last
  9. var prevFile = '';
  10. module.exports = function saveLicense(node, comment) {
  11. if (comment.file !== prevFile) {
  12. prevCommentLine = 0;
  13. }
  14. var isLicense = licenseRegexp.test(comment.value) ||
  15. (comment.type === 'comment2' &&
  16. comment.value.charAt(0) === '!') ||
  17. comment.line === 1 ||
  18. comment.line === prevCommentLine + 1;
  19. if (isLicense) {
  20. prevCommentLine = comment.line;
  21. } else {
  22. prevCommentLine = 0;
  23. }
  24. prevFile = comment.file;
  25. return isLicense;
  26. };