Skip to content

Commit

Permalink
DRY up regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Feb 13, 2016
1 parent d900d28 commit 5e04c42
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/scopeify.js
Expand Up @@ -2,10 +2,12 @@

var fileScoper = require('./scoped-name');

var classRegex =
/(\.)(?!\d)([^\s\.,{\[>+~#:]*)(?![^{]*})(?!(?:[^*/]|\*[^/]|\/[^*])*\*+\/)/g;
var keyframesRegex =
/(@\S*keyframes\s*)([^{\s]*)(?!(?:[^*/]|\*[^/]|\/[^*])*\*+\/)/g;
var findClasses = /(\.)(?!\d)([^\s\.,{\[>+~#:]*)(?![^{]*})/.source;
var findKeyframes = /(@\S*keyframes\s*)([^{\s]*)/.source;
var ignoreComments = /(?!(?:[^*/]|\*[^/]|\/[^*])*\*+\/)/.source;

var classRegex = new RegExp(findClasses + ignoreComments, 'g');
var keyframesRegex = new RegExp(findKeyframes + ignoreComments, 'g');

module.exports = scopify;

Expand Down Expand Up @@ -48,7 +50,7 @@ function replaceAnimations(result) {

if (unscoped.length) {
var regexStr = '((?:animation|animation-name)\\s*:[^};]*)('
+ unscoped.join('|') + ')(?!(?:[^*/]|\\*[^/]|\\/[^*])*\\*+\\/)';
+ unscoped.join('|') + ')' + ignoreComments;
var regex = new RegExp(regexStr, 'g');
console.log(regex);

Expand Down

0 comments on commit 5e04c42

Please sign in to comment.