Move csslint-loader to background
This commit is contained in:
parent
ca05a15219
commit
b4113d1a61
41
background/csslint-loader.js
Normal file
41
background/csslint-loader.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/* global importScripts parserlib CSSLint parseMozFormat */
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const CSSLINT_PATH = '/vendor-overwrites/csslint/';
|
||||||
|
importScripts(CSSLINT_PATH + 'parserlib.js');
|
||||||
|
|
||||||
|
parserlib.css.Tokens[parserlib.css.Tokens.COMMENT].hide = false;
|
||||||
|
|
||||||
|
self.onmessage = ({data}) => {
|
||||||
|
|
||||||
|
const {action = 'run'} = data;
|
||||||
|
|
||||||
|
if (action === 'parse') {
|
||||||
|
if (!self.parseMozFormat) self.importScripts('/js/moz-parser.js');
|
||||||
|
self.postMessage(parseMozFormat(data));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!self.CSSLint) self.importScripts(CSSLINT_PATH + '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': {
|
||||||
|
const {code, config} = data;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -599,7 +599,7 @@ var usercss = (() => {
|
||||||
|
|
||||||
function invokeWorker(message) {
|
function invokeWorker(message) {
|
||||||
if (!worker.queue) {
|
if (!worker.queue) {
|
||||||
worker.instance = new Worker('/edit/csslint-loader.js');
|
worker.instance = new Worker('/background/csslint-loader.js');
|
||||||
worker.queue = [];
|
worker.queue = [];
|
||||||
worker.instance.onmessage = ({data}) => {
|
worker.instance.onmessage = ({data}) => {
|
||||||
worker.queue.shift().resolve(data.__ERROR__ ? Promise.reject(data.__ERROR__) : data);
|
worker.queue.shift().resolve(data.__ERROR__ ? Promise.reject(data.__ERROR__) : data);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user