2017-12-26 20:39:52 +00:00
|
|
|
/* global parserlib CSSLint parseMozFormat */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
self.importScripts('./parserlib.js');
|
|
|
|
parserlib.css.Tokens[parserlib.css.Tokens.COMMENT].hide = false;
|
|
|
|
|
2018-01-06 06:48:56 +00:00
|
|
|
self.onmessage = ({data}) => {
|
|
|
|
|
|
|
|
const {action = 'run'} = data;
|
2017-12-26 20:39:52 +00:00
|
|
|
|
|
|
|
if (action === 'parse') {
|
|
|
|
if (!self.parseMozFormat) self.importScripts('/js/moz-parser.js');
|
2018-01-06 06:48:56 +00:00
|
|
|
self.postMessage(parseMozFormat(data));
|
2017-12-26 20:39:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-01-06 06:48:56 +00:00
|
|
|
|
2017-12-26 20:39:52 +00:00
|
|
|
if (!self.CSSLint) self.importScripts('./csslint.js');
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case 'getAllRuleIds':
|
|
|
|
// the functions are non-tranferable and we need only an id
|
|
|
|
self.postMessage(CSSLint.getRules().map(rule => rule.id));
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'getAllRuleInfos':
|
|
|
|
// the functions are non-tranferable
|
|
|
|
self.postMessage(CSSLint.getRules().map(rule => JSON.parse(JSON.stringify(rule))));
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'run': {
|
2018-01-06 06:48:56 +00:00
|
|
|
const {code, config} = data;
|
2017-12-26 20:39:52 +00:00
|
|
|
const results = CSSLint.verify(code, config).messages
|
|
|
|
//.filter(m => !m.message.includes('/*[[') && !m.message.includes(']]*/'))
|
|
|
|
.map(m => Object.assign(m, {rule: {id: m.rule.id}}));
|
|
|
|
self.postMessage(results);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|