diff --git a/lib/parse.js b/lib/parse.js index 1097ba3..d334e9d 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -5,7 +5,7 @@ const languages = require('./languages'); const constants = { ESCAPED_CHAR_REGEX: /^\\./, - QUOTED_STRING_REGEX: /^(['"`])((?:\\.|[^\1])+?)(\1)/, + QUOTED_STRING_REGEX:/^(['"`])((?:|[^\1])+?)(\1)/, NEWLINE_REGEX: /^\r*\n/ }; diff --git a/test/JavaScript.js b/test/JavaScript.js index c2a3cea..ba8cb2a 100644 --- a/test/JavaScript.js +++ b/test/JavaScript.js @@ -16,6 +16,13 @@ const tests = path.join.bind(path, __dirname); const read = src => fs.readFileSync(src, 'utf-8').replace(/\r*\n/g, '\n');; describe('JavaScript comments', () => { + it('should work on comments which has quotes', () => { + const file = read(tests('fixtures/quoted-sting-match.less')); + const generated = strip(file, {language : 'less'}); + const stripped = read(tests('expected/strip-quoted-sting-match.less')); + assert.strictEqual(stripped, generated); + }); + it('should strip all comments', () => { const actual = strip("'foo'; // this is a comment\n/* me too */ var abc = 'xyz';"); assert.strictEqual(actual, '\'foo\'; \n var abc = \'xyz\';'); diff --git a/test/expected/strip-quoted-sting-match.less b/test/expected/strip-quoted-sting-match.less new file mode 100644 index 0000000..3c7d534 --- /dev/null +++ b/test/expected/strip-quoted-sting-match.less @@ -0,0 +1,18 @@ +.@{var}-handle:after { + content: "Content At quoted String comments"; + content: ""; +} + + +.@{var}-handle:after{ + content : "Content After quoted String comments" +} + +.@{var}-handle:after { + content: "Content At quoted String comments"; +} + + +.@{var}-handle:after{ + content : "Content After quoted String comments" +} \ No newline at end of file diff --git a/test/fixtures/quoted-sting-match.less b/test/fixtures/quoted-sting-match.less new file mode 100644 index 0000000..0d42cdc --- /dev/null +++ b/test/fixtures/quoted-sting-match.less @@ -0,0 +1,24 @@ +.@{var}-handle:after { + content: "Content At quoted String comments"; + content: ""; +} + +/* Comments without Quoted String; + */ +/*@import "Comments with Quoted String";*/ + +.@{var}-handle:after{ + content : "Content After quoted String comments" +} + +.@{var}-handle:after { + content: "Content At quoted String comments"; +} + +/* Comments without Quoted String; + */ +/*@import "Comments with Quoted String";*/ + +.@{var}-handle:after{ + content : "Content After quoted String comments" +} \ No newline at end of file