Skip to content

Commit 71ab4fc

Browse files
authored
Merge pull request #100 from epilande/preserve-comments
Preserve comments that begin with "/*!"
2 parents 856419b + 7f0ffb8 commit 71ab4fc

File tree

5 files changed

+21
-34
lines changed

5 files changed

+21
-34
lines changed

src/minify/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makePlaceholder, splitByPlaceholders } from '../css/placeholderUtils'
22

3-
const makeMultilineCommentRegex = newlinePattern => new RegExp('\\/\\*(.|' + newlinePattern + ')*?\\*\\/', 'g')
3+
const makeMultilineCommentRegex = newlinePattern => new RegExp('\\/\\*[^!](.|' + newlinePattern + ')*?\\*\\/', 'g')
44
const lineCommentStart = /\/\//g
55
const symbolRegex = /(\s*[;:{},]\s*)/g
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
injectGlobal([["", glob, "\nhtml,body{margin:100000px;padding:", test, ";}@media (max-width:999px){html,body{margin:0;}}.root{width:100%;}"]]);
1+
injectGlobal([["", glob, "\n/*! preserve comment */html,body{margin:100000px;padding:", test, ";}@media (max-width:999px){html,body{margin:0;}}.root{width:100%;}"]]);

test/fixtures/18-preprocess-inject-global/before.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
injectGlobal`
22
${glob}
33
4+
// comment
5+
/* comment */
6+
/*! preserve comment */
7+
48
html, body {
59
margin: 100000px;
610
padding: ${test};

test/minify/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ describe('minify utils', () => {
6161
expect(actual).toBe(expected)
6262
expect(actual).toBe(minifyCooked(input))
6363
})
64+
65+
it('Preserves multi-line comments starting with /*!', () => {
66+
const input = 'this is a /*! dont ignore me please */ test/* but you can ignore me */'
67+
const expected = 'this is a /*! dont ignore me please */ test'
68+
const actual = minifyRaw(input)
69+
70+
expect(actual).toBe(expected)
71+
expect(actual).toBe(minifyCooked(input))
72+
})
6473
})
6574

6675
describe('minifyRaw', () => {

yarn.lock

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,7 @@ babel-register@^6.24.0:
629629
mkdirp "^0.5.1"
630630
source-map-support "^0.4.2"
631631

632-
babel-runtime@^6.18.0, babel-runtime@^6.22.0:
633-
version "6.23.0"
634-
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b"
635-
dependencies:
636-
core-js "^2.4.0"
637-
regenerator-runtime "^0.10.0"
638-
639-
babel-runtime@^6.26.0:
632+
babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0:
640633
version "6.26.0"
641634
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
642635
dependencies:
@@ -667,16 +660,7 @@ babel-traverse@^6.18.0, babel-traverse@^6.22.0, babel-traverse@^6.23.0, babel-tr
667660
invariant "^2.2.0"
668661
lodash "^4.2.0"
669662

670-
babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.22.0, babel-types@^6.23.0:
671-
version "6.23.0"
672-
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.23.0.tgz#bb17179d7538bad38cd0c9e115d340f77e7e9acf"
673-
dependencies:
674-
babel-runtime "^6.22.0"
675-
esutils "^2.0.2"
676-
lodash "^4.2.0"
677-
to-fast-properties "^1.0.1"
678-
679-
babel-types@^6.26.0:
663+
babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.22.0, babel-types@^6.23.0, babel-types@^6.26.0:
680664
version "6.26.0"
681665
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497"
682666
dependencies:
@@ -2382,13 +2366,7 @@ right-align@^0.1.1:
23822366
dependencies:
23832367
align-text "^0.1.1"
23842368

2385-
rimraf@2, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.5.1, rimraf@^2.6.1:
2386-
version "2.6.1"
2387-
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
2388-
dependencies:
2389-
glob "^7.0.5"
2390-
2391-
rimraf@^2.6.2:
2369+
rimraf@2, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.5.1, rimraf@^2.6.1, rimraf@^2.6.2:
23922370
version "2.6.2"
23932371
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
23942372
dependencies:
@@ -2534,9 +2512,9 @@ strip-json-comments@~2.0.1:
25342512
version "2.0.1"
25352513
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
25362514

2537-
stylis@3.x:
2538-
version "3.3.2"
2539-
resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.3.2.tgz#95ef285836e98243f8b8f64a9a72706ea6c893ea"
2515+
stylis@^3.4.0:
2516+
version "3.4.0"
2517+
resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.4.0.tgz#55c6530ebceeca5976d54fb4adc67578afee828d"
25402518

25412519
supports-color@^2.0.0:
25422520
version "2.0.0"
@@ -2591,10 +2569,6 @@ [email protected]:
25912569
version "1.0.4"
25922570
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"
25932571

2594-
to-fast-properties@^1.0.1:
2595-
version "1.0.2"
2596-
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.2.tgz#f3f5c0c3ba7299a7ef99427e44633257ade43320"
2597-
25982572
to-fast-properties@^1.0.3:
25992573
version "1.0.3"
26002574
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"

0 commit comments

Comments
 (0)