format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

View File

@ -3,7 +3,7 @@
const _default = require('./default.cjs');
const atrulePrelude = {
getNode: _default
getNode: _default,
};
module.exports = atrulePrelude;

View File

@ -2,75 +2,79 @@
const types = require('../../tokenizer/types.cjs');
const NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
const ASTERISK = 0x002A; // U+002A ASTERISK (*)
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
const U = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
const NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
const ASTERISK = 0x002a; // U+002A ASTERISK (*)
const PLUSSIGN = 0x002b; // U+002B PLUS SIGN (+)
const HYPHENMINUS = 0x002d; // U+002D HYPHEN-MINUS (-)
const SOLIDUS = 0x002f; // U+002F SOLIDUS (/)
const U = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
function defaultRecognizer(context) {
switch (this.tokenType) {
case types.Hash:
return this.Hash();
switch (this.tokenType) {
case types.Hash:
return this.Hash();
case types.Comma:
return this.Operator();
case types.Comma:
return this.Operator();
case types.LeftParenthesis:
return this.Parentheses(this.readSequence, context.recognizer);
case types.LeftParenthesis:
return this.Parentheses(this.readSequence, context.recognizer);
case types.LeftSquareBracket:
return this.Brackets(this.readSequence, context.recognizer);
case types.LeftSquareBracket:
return this.Brackets(this.readSequence, context.recognizer);
case types.String:
return this.String();
case types.String:
return this.String();
case types.Dimension:
return this.Dimension();
case types.Dimension:
return this.Dimension();
case types.Percentage:
return this.Percentage();
case types.Percentage:
return this.Percentage();
case types.Number:
return this.Number();
case types.Number:
return this.Number();
case types.Function:
return this.cmpStr(this.tokenStart, this.tokenEnd, 'url(')
? this.Url()
: this.Function(this.readSequence, context.recognizer);
case types.Function:
return this.cmpStr(this.tokenStart, this.tokenEnd, 'url(') ?
this.Url()
: this.Function(this.readSequence, context.recognizer);
case types.Url:
return this.Url();
case types.Url:
return this.Url();
case types.Ident:
// check for unicode range, it should start with u+ or U+
if (this.cmpChar(this.tokenStart, U) &&
this.cmpChar(this.tokenStart + 1, PLUSSIGN)) {
return this.UnicodeRange();
} else {
return this.Identifier();
}
case types.Ident:
// check for unicode range, it should start with u+ or U+
if (
this.cmpChar(this.tokenStart, U) &&
this.cmpChar(this.tokenStart + 1, PLUSSIGN)
) {
return this.UnicodeRange();
} else {
return this.Identifier();
}
case types.Delim: {
const code = this.charCodeAt(this.tokenStart);
case types.Delim: {
const code = this.charCodeAt(this.tokenStart);
if (code === SOLIDUS ||
code === ASTERISK ||
code === PLUSSIGN ||
code === HYPHENMINUS) {
return this.Operator(); // TODO: replace with Delim
}
if (
code === SOLIDUS ||
code === ASTERISK ||
code === PLUSSIGN ||
code === HYPHENMINUS
) {
return this.Operator(); // TODO: replace with Delim
}
// TODO: produce a node with Delim node type
// TODO: produce a node with Delim node type
if (code === NUMBERSIGN) {
this.error('Hex or identifier is expected', this.tokenStart + 1);
}
if (code === NUMBERSIGN) {
this.error('Hex or identifier is expected', this.tokenStart + 1);
}
break;
}
break;
}
}
}
module.exports = defaultRecognizer;

View File

@ -4,8 +4,6 @@ const atrulePrelude = require('./atrulePrelude.cjs');
const selector = require('./selector.cjs');
const value = require('./value.cjs');
exports.AtrulePrelude = atrulePrelude;
exports.Selector = selector;
exports.Value = value;

View File

@ -2,83 +2,88 @@
const types = require('../../tokenizer/types.cjs');
const NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
const ASTERISK = 0x002A; // U+002A ASTERISK (*)
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
const FULLSTOP = 0x002E; // U+002E FULL STOP (.)
const GREATERTHANSIGN = 0x003E; // U+003E GREATER-THAN SIGN (>)
const VERTICALLINE = 0x007C; // U+007C VERTICAL LINE (|)
const TILDE = 0x007E; // U+007E TILDE (~)
const NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
const ASTERISK = 0x002a; // U+002A ASTERISK (*)
const PLUSSIGN = 0x002b; // U+002B PLUS SIGN (+)
const SOLIDUS = 0x002f; // U+002F SOLIDUS (/)
const FULLSTOP = 0x002e; // U+002E FULL STOP (.)
const GREATERTHANSIGN = 0x003e; // U+003E GREATER-THAN SIGN (>)
const VERTICALLINE = 0x007c; // U+007C VERTICAL LINE (|)
const TILDE = 0x007e; // U+007E TILDE (~)
function onWhiteSpace(next, children) {
if (children.last !== null && children.last.type !== 'Combinator' &&
next !== null && next.type !== 'Combinator') {
children.push({ // FIXME: this.Combinator() should be used instead
type: 'Combinator',
loc: null,
name: ' '
});
}
if (
children.last !== null &&
children.last.type !== 'Combinator' &&
next !== null &&
next.type !== 'Combinator'
) {
children.push({
// FIXME: this.Combinator() should be used instead
type: 'Combinator',
loc: null,
name: ' ',
});
}
}
function getNode() {
switch (this.tokenType) {
case types.LeftSquareBracket:
return this.AttributeSelector();
switch (this.tokenType) {
case types.LeftSquareBracket:
return this.AttributeSelector();
case types.Hash:
return this.IdSelector();
case types.Hash:
return this.IdSelector();
case types.Colon:
if (this.lookupType(1) === types.Colon) {
return this.PseudoElementSelector();
} else {
return this.PseudoClassSelector();
}
case types.Colon:
if (this.lookupType(1) === types.Colon) {
return this.PseudoElementSelector();
} else {
return this.PseudoClassSelector();
}
case types.Ident:
return this.TypeSelector();
case types.Ident:
return this.TypeSelector();
case types.Number:
case types.Percentage:
return this.Percentage();
case types.Number:
case types.Percentage:
return this.Percentage();
case types.Dimension:
// throws when .123ident
if (this.charCodeAt(this.tokenStart) === FULLSTOP) {
this.error('Identifier is expected', this.tokenStart + 1);
}
break;
case types.Dimension:
// throws when .123ident
if (this.charCodeAt(this.tokenStart) === FULLSTOP) {
this.error('Identifier is expected', this.tokenStart + 1);
}
break;
case types.Delim: {
const code = this.charCodeAt(this.tokenStart);
case types.Delim: {
const code = this.charCodeAt(this.tokenStart);
switch (code) {
case PLUSSIGN:
case GREATERTHANSIGN:
case TILDE:
case SOLIDUS: // /deep/
return this.Combinator();
switch (code) {
case PLUSSIGN:
case GREATERTHANSIGN:
case TILDE:
case SOLIDUS: // /deep/
return this.Combinator();
case FULLSTOP:
return this.ClassSelector();
case FULLSTOP:
return this.ClassSelector();
case ASTERISK:
case VERTICALLINE:
return this.TypeSelector();
case ASTERISK:
case VERTICALLINE:
return this.TypeSelector();
case NUMBERSIGN:
return this.IdSelector();
}
case NUMBERSIGN:
return this.IdSelector();
}
break;
}
break;
}
}
}
const Selector = {
onWhiteSpace,
getNode
onWhiteSpace,
getNode,
};
module.exports = Selector;

View File

@ -5,25 +5,26 @@ const expression = require('../function/expression.cjs');
const _var = require('../function/var.cjs');
function isPlusMinusOperator(node) {
return (
node !== null &&
node.type === 'Operator' &&
(node.value[node.value.length - 1] === '-' || node.value[node.value.length - 1] === '+')
);
return (
node !== null &&
node.type === 'Operator' &&
(node.value[node.value.length - 1] === '-' ||
node.value[node.value.length - 1] === '+')
);
}
const value = {
getNode: _default,
onWhiteSpace(next, children) {
if (isPlusMinusOperator(next)) {
next.value = ' ' + next.value;
}
if (isPlusMinusOperator(children.last)) {
children.last.value += ' ';
}
},
'expression': expression,
'var': _var
getNode: _default,
onWhiteSpace(next, children) {
if (isPlusMinusOperator(next)) {
next.value = ' ' + next.value;
}
if (isPlusMinusOperator(children.last)) {
children.last.value += ' ';
}
},
expression: expression,
var: _var,
};
module.exports = value;