Fix: use meta parser
This commit is contained in:
parent
918e47b1ed
commit
1f2d116aae
|
@ -1,4 +1,4 @@
|
|||
/* global importScripts workerUtil CSSLint require usercssMeta */
|
||||
/* global importScripts workerUtil CSSLint require metaParser */
|
||||
'use strict';
|
||||
|
||||
importScripts('/js/worker-util.js');
|
||||
|
@ -15,12 +15,17 @@ createAPI({
|
|||
return require('stylelint').lint({code, config});
|
||||
},
|
||||
metalint: code => {
|
||||
loadScript('/vendor/usercss-meta/usercss-meta.min.js');
|
||||
const result = usercssMeta.parse(code, {allowErrors: true, unknownKey: 'throw'});
|
||||
loadScript(
|
||||
'/vendor/usercss-meta/usercss-meta.min.js',
|
||||
'/vendor-overwrites/colorpicker/colorconverter.js',
|
||||
'/js/meta-parser.js'
|
||||
);
|
||||
const result = metaParser.lint(code);
|
||||
// extract needed info
|
||||
result.errors = result.errors.map(err =>
|
||||
({
|
||||
code: err.code,
|
||||
args: err.args,
|
||||
message: err.message,
|
||||
index: err.index
|
||||
})
|
||||
|
|
|
@ -29,7 +29,7 @@ function createMetaCompiler(cm) {
|
|||
({
|
||||
from: cm.posFromIndex((err.index || 0) + match.index),
|
||||
to: cm.posFromIndex((err.index || 0) + match.index),
|
||||
message: err.message,
|
||||
message: err.code && chrome.i18n.getMessage(`meta_${err.code}`, err.args) || err.message,
|
||||
severity: err.code === 'unknownMeta' ? 'warning' : 'error'
|
||||
})
|
||||
);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
var metaParser = (() => {
|
||||
const {createParser, ParseError} = usercssMeta;
|
||||
const PREPROCESSORS = new Set(['default', 'uso', 'stylus', 'less']);
|
||||
const parser = createParser({
|
||||
const options = {
|
||||
validateKey: {
|
||||
preprocessor: state => {
|
||||
if (!PREPROCESSORS.has(state.value)) {
|
||||
|
@ -38,8 +38,14 @@ var metaParser = (() => {
|
|||
state.value = colorConverter.format(color, 'rgb');
|
||||
}
|
||||
}
|
||||
});
|
||||
return {parse, nullifyInvalidVars};
|
||||
};
|
||||
const parser = createParser(options);
|
||||
const looseParser = createParser(Object.assign({}, options, {allowErrors: true, unknownKey: 'throw'}));
|
||||
return {
|
||||
parse,
|
||||
lint,
|
||||
nullifyInvalidVars
|
||||
};
|
||||
|
||||
function parse(text, indexOffset) {
|
||||
try {
|
||||
|
@ -52,6 +58,10 @@ var metaParser = (() => {
|
|||
}
|
||||
}
|
||||
|
||||
function lint(text) {
|
||||
return looseParser.parse(text);
|
||||
}
|
||||
|
||||
function nullifyInvalidVars(vars) {
|
||||
for (const va of Object.values(vars)) {
|
||||
if (va.value === null) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user