Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const languages = require('./languages');

const constants = {
ESCAPED_CHAR_REGEX: /^\\./,
QUOTED_STRING_REGEX: /^(['"`])((?:\\.|[^\1])+?)(\1)/,
QUOTED_STRING_REGEX:/^(['"`])((?:|[^\1])+?)(\1)/,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after QUOTED_STRING_REGEX:

And I think the + should be inside, after the closing angle bracket ((?:[^\1]+)?) and remove the |

NEWLINE_REGEX: /^\r*\n/
};

Expand Down
7 changes: 7 additions & 0 deletions test/JavaScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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\';');
Expand Down
18 changes: 18 additions & 0 deletions test/expected/strip-quoted-sting-match.less
Original file line number Diff line number Diff line change
@@ -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"
}
24 changes: 24 additions & 0 deletions test/fixtures/quoted-sting-match.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.@{var}-handle:after {
content: "Content At quoted String comments";
content: "";
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something bothers me about that file :D Why it has duplicate stuff? At least we can make it with different classes and different comments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to replicate multiple scenarios. Will modify :)

/* 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"
}