revert d405bc64 - obsolete since stylus-lang 0.54.7

This commit is contained in:
tophf 2020-11-10 20:32:50 +03:00
parent eb70e5a2aa
commit 3a8f47f4db
3 changed files with 3 additions and 18 deletions

View File

@ -37,7 +37,7 @@ function compileUsercss(preprocessor, code, vars) {
const builder = getUsercssCompiler(preprocessor); const builder = getUsercssCompiler(preprocessor);
vars = simpleVars(vars); vars = simpleVars(vars);
return Promise.resolve(builder.preprocess ? builder.preprocess(code, vars) : code) return Promise.resolve(builder.preprocess ? builder.preprocess(code, vars) : code)
.then(code => parseMozFormat({code, emptyDocument: preprocessor === 'stylus'})) .then(code => parseMozFormat({code}))
.then(({sections, errors}) => { .then(({sections, errors}) => {
if (builder.postprocess) { if (builder.postprocess) {
builder.postprocess(sections, vars); builder.postprocess(sections, vars);

View File

@ -7,12 +7,10 @@
* Puts the global comments into the following section to minimize the amount of global sections. * Puts the global comments into the following section to minimize the amount of global sections.
* Doesn't move the comment with ==UserStyle== inside. * Doesn't move the comment with ==UserStyle== inside.
* @param {string} code * @param {string} code
* @param {boolean} emptyDocument - https://github.com/stylus/stylus/issues/2415,
* TODO: update stylus-lang and remove emptyDocument everywhere
* @param {number} styleId - used to preserve parserCache on subsequent runs over the same style * @param {number} styleId - used to preserve parserCache on subsequent runs over the same style
* @returns {{sections: Array, errors: Array}} * @returns {{sections: Array, errors: Array}}
*/ */
function parseMozFormat({code, emptyDocument, styleId}) { function parseMozFormat({code, styleId}) {
const CssToProperty = { const CssToProperty = {
'url': 'urls', 'url': 'urls',
'url-prefix': 'urlPrefixes', 'url-prefix': 'urlPrefixes',
@ -20,7 +18,7 @@ function parseMozFormat({code, emptyDocument, styleId}) {
'regexp': 'regexps', 'regexp': 'regexps',
}; };
const hasSingleEscapes = /([^\\]|^)\\([^\\]|$)/; const hasSingleEscapes = /([^\\]|^)\\([^\\]|$)/;
const parser = new parserlib.css.Parser({starHack: true, emptyDocument}); const parser = new parserlib.css.Parser({starHack: true});
const sectionStack = [{code: '', start: 0}]; const sectionStack = [{code: '', start: 0}];
const errors = []; const errors = [];
const sections = []; const sections = [];
@ -72,13 +70,6 @@ function parseMozFormat({code, emptyDocument, styleId}) {
doAddSection(section); doAddSection(section);
}); });
parser.addListener('emptydocument', e => {
const token = parser._tokenStream._token;
const section = sectionStack[sectionStack.length - 1];
section.code += mozStyle.slice(section.start, e.offset);
section.start = token.offset + token.value.length;
});
parser.addListener('endstylesheet', () => { parser.addListener('endstylesheet', () => {
// add nonclosed outer sections (either broken or the last global one) // add nonclosed outer sections (either broken or the last global one)
const lastSection = sectionStack[sectionStack.length - 1]; const lastSection = sectionStack[sectionStack.length - 1];

View File

@ -4006,7 +4006,6 @@ self.parserlib = (() => {
* @param {Boolean} [options.starHack] - allows IE6 star hack * @param {Boolean} [options.starHack] - allows IE6 star hack
* @param {Boolean} [options.underscoreHack] - interprets leading underscores as IE6-7 for known properties * @param {Boolean} [options.underscoreHack] - interprets leading underscores as IE6-7 for known properties
* @param {Boolean} [options.ieFilters] - accepts IE < 8 filters instead of throwing syntax errors * @param {Boolean} [options.ieFilters] - accepts IE < 8 filters instead of throwing syntax errors
* @param {Boolean} [options.emptyDocument] - accepts @document without {} block produced by stylus-lang
*/ */
constructor(options) { constructor(options) {
super(); super();
@ -4437,11 +4436,6 @@ self.parserlib = (() => {
this._ws(); this._ws();
functions.push(this._documentFunction() || stream.LT(1)); functions.push(this._documentFunction() || stream.LT(1));
} while (stream.match(Tokens.COMMA)); } while (stream.match(Tokens.COMMA));
this._ws();
if (this.options.emptyDocument && stream.peek() !== Tokens.LBRACE) {
this.fire({type: 'emptydocument', functions, prefix}, start);
return;
}
for (const fn of functions) { for (const fn of functions) {
if ((fn.type !== 'function' || !/^(url(-prefix)?|domain|regexp)$/i.test(fn.name)) && if ((fn.type !== 'function' || !/^(url(-prefix)?|domain|regexp)$/i.test(fn.name)) &&
fn.type !== 'uri') { fn.type !== 'uri') {