Comparing version 0.8.0 to 0.8.1
@@ -123,2 +123,10 @@ 'use strict'; | ||
var end = code.indexOf('-->', idx + 4); | ||
var keep = optSafe && code.substr(idx + 4, 3) === '[if'; | ||
if (keep) { | ||
if (end >= 0) { | ||
s += code.substr(idx, end - idx + 3); | ||
} else { | ||
s += code.substr(idx, len - idx); | ||
} | ||
} | ||
if (end < 0) { | ||
@@ -132,30 +140,32 @@ break; | ||
} | ||
var parts = comment.split(EOL); | ||
if (optSpace) { | ||
for (var k = 0; k < parts.length - 1; k++) { | ||
s += EOL; | ||
if (!keep) { | ||
var parts = comment.split(EOL); | ||
if (optSpace) { | ||
for (var k = 0; k < parts.length - 1; k++) { | ||
s += EOL; | ||
} | ||
} | ||
} | ||
var lb = code.indexOf(EOL, idx + 1); | ||
if (lb > idx) { | ||
var gapIdx = lb - 1; | ||
while ((code[gapIdx] === ' ' || code[gapIdx] === '\t') && --gapIdx > idx); | ||
if (gapIdx === idx) { | ||
if (emptyLine && !optSpace) { | ||
idx = lb + EOL.length - 1; // last symbol of the line break; | ||
trim(); | ||
var lb = code.indexOf(EOL, idx + 1); | ||
if (lb > idx) { | ||
var gapIdx = lb - 1; | ||
while ((code[gapIdx] === ' ' || code[gapIdx] === '\t') && --gapIdx > idx); | ||
if (gapIdx === idx) { | ||
if (emptyLine && !optSpace) { | ||
idx = lb + EOL.length - 1; // last symbol of the line break; | ||
trim(); | ||
} | ||
} else { | ||
if (optSpace) { | ||
s += utils.getSpaces(parts[parts.length - 1].length); | ||
} | ||
} | ||
} else { | ||
if (optSpace) { | ||
s += utils.getSpaces(parts[parts.length - 1].length); | ||
var gapIdx = idx + 1; | ||
while ((code[gapIdx] === ' ' || code[gapIdx] === '\t') && ++gapIdx < len); | ||
if (gapIdx < len) { | ||
s += utils.getSpaces(parts[parts.length - 1].length); | ||
} | ||
} | ||
} | ||
} else { | ||
if (optSpace) { | ||
var gapIdx = idx + 1; | ||
while ((code[gapIdx] === ' ' || code[gapIdx] === '\t') && ++gapIdx < len); | ||
if (gapIdx < len) { | ||
s += utils.getSpaces(parts[parts.length - 1].length); | ||
} | ||
} | ||
} | ||
@@ -162,0 +172,0 @@ continue; |
{ | ||
"name": "decomment", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Removes comments from JSON, JavaScript, CSS, HTML, etc.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -73,3 +73,5 @@ decomment | ||
* `false (default)` - remove all multi-line comments | ||
* `true` - keep multi-line comments that start with `/*!` | ||
* `true` - keep special multi-line comments that begin with: | ||
- `<!--[if` - for conditional comments in HTML | ||
- `/*!` - for everything else (other than HTML) | ||
@@ -85,4 +87,2 @@ Example: | ||
NOTE: This option has no effect when processing HTML. | ||
##### options.space ⇒ Boolean | ||
@@ -89,0 +89,0 @@ |
@@ -118,2 +118,24 @@ 'use strict'; | ||
}); | ||
describe("HTML-IE", function () { | ||
describe("Safe", function () { | ||
it("must keep all IE comments", function () { | ||
expect(decomment("<!--[iftext<![endif]-->", {safe: true})).toBe("<!--[iftext<![endif]-->"); | ||
expect(decomment("<!--[iftext", {safe: true})).toBe("<!--[iftext"); | ||
expect(decomment("<!--[if" + LB + "text" + LB + "<![endif]-->", {safe: true})).toBe("<!--[if" + LB + "text" + LB + "<![endif]-->"); | ||
}); | ||
}); | ||
describe("Not Safe", function () { | ||
it("must delete all IE comments", function () { | ||
expect(decomment("<!--[if IE]>text<![endif]-->")).toBe(""); | ||
expect(decomment("<!--[if IE]>text")).toBe(""); | ||
expect(decomment("<!--[if IE]>" + LB + "text" + LB + "<![endif]-->")).toBe(""); | ||
expect(decomment.html(" prefix " + LB + "<!--[if IE]>" + LB + "text" + LB + "<![endif]-->" + " suffix ")).toBe(" prefix " + LB + " suffix "); | ||
}); | ||
}); | ||
}); |
@@ -57,2 +57,9 @@ 'use strict'; | ||
describe("starting comments suffixed by spaces", function () { | ||
it("must remove comment and spaces", function () { | ||
expect(decomment(" //hello " + LB + "next")).toBe("next"); | ||
expect(decomment(" \t //hello \t " + LB + "next")).toBe("next"); | ||
}); | ||
}); | ||
describe("with line-break suffix", function () { | ||
@@ -59,0 +66,0 @@ var out = decomment("//" + LB); |
49669
1007