aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/css-tree/lib/syntax/node/AttributeSelector.js
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
commit76cb9c2a39d477a64824a985ade40507e3bbade1 (patch)
tree41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/css-tree/lib/syntax/node/AttributeSelector.js
parent819a39a21ac992b1393244a4c283bbb125208c69 (diff)
downloadneko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/css-tree/lib/syntax/node/AttributeSelector.js')
-rw-r--r--vanilla/node_modules/css-tree/lib/syntax/node/AttributeSelector.js147
1 files changed, 147 insertions, 0 deletions
diff --git a/vanilla/node_modules/css-tree/lib/syntax/node/AttributeSelector.js b/vanilla/node_modules/css-tree/lib/syntax/node/AttributeSelector.js
new file mode 100644
index 0000000..8578dad
--- /dev/null
+++ b/vanilla/node_modules/css-tree/lib/syntax/node/AttributeSelector.js
@@ -0,0 +1,147 @@
+import {
+ Ident,
+ String as StringToken,
+ Delim,
+ LeftSquareBracket,
+ RightSquareBracket
+} from '../../tokenizer/index.js';
+
+const DOLLARSIGN = 0x0024; // U+0024 DOLLAR SIGN ($)
+const ASTERISK = 0x002A; // U+002A ASTERISK (*)
+const EQUALSSIGN = 0x003D; // U+003D EQUALS SIGN (=)
+const CIRCUMFLEXACCENT = 0x005E; // U+005E (^)
+const VERTICALLINE = 0x007C; // U+007C VERTICAL LINE (|)
+const TILDE = 0x007E; // U+007E TILDE (~)
+
+function getAttributeName() {
+ if (this.eof) {
+ this.error('Unexpected end of input');
+ }
+
+ const start = this.tokenStart;
+ let expectIdent = false;
+
+ if (this.isDelim(ASTERISK)) {
+ expectIdent = true;
+ this.next();
+ } else if (!this.isDelim(VERTICALLINE)) {
+ this.eat(Ident);
+ }
+
+ if (this.isDelim(VERTICALLINE)) {
+ if (this.charCodeAt(this.tokenStart + 1) !== EQUALSSIGN) {
+ this.next();
+ this.eat(Ident);
+ } else if (expectIdent) {
+ this.error('Identifier is expected', this.tokenEnd);
+ }
+ } else if (expectIdent) {
+ this.error('Vertical line is expected');
+ }
+
+ return {
+ type: 'Identifier',
+ loc: this.getLocation(start, this.tokenStart),
+ name: this.substrToCursor(start)
+ };
+}
+
+function getOperator() {
+ const start = this.tokenStart;
+ const code = this.charCodeAt(start);
+
+ if (code !== EQUALSSIGN && // =
+ code !== TILDE && // ~=
+ code !== CIRCUMFLEXACCENT && // ^=
+ code !== DOLLARSIGN && // $=
+ code !== ASTERISK && // *=
+ code !== VERTICALLINE // |=
+ ) {
+ this.error('Attribute selector (=, ~=, ^=, $=, *=, |=) is expected');
+ }
+
+ this.next();
+
+ if (code !== EQUALSSIGN) {
+ if (!this.isDelim(EQUALSSIGN)) {
+ this.error('Equal sign is expected');
+ }
+
+ this.next();
+ }
+
+ return this.substrToCursor(start);
+}
+
+// '[' <wq-name> ']'
+// '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'
+export const name = 'AttributeSelector';
+export const structure = {
+ name: 'Identifier',
+ matcher: [String, null],
+ value: ['String', 'Identifier', null],
+ flags: [String, null]
+};
+
+export function parse() {
+ const start = this.tokenStart;
+ let name;
+ let matcher = null;
+ let value = null;
+ let flags = null;
+
+ this.eat(LeftSquareBracket);
+ this.skipSC();
+
+ name = getAttributeName.call(this);
+ this.skipSC();
+
+ if (this.tokenType !== RightSquareBracket) {
+ // avoid case `[name i]`
+ if (this.tokenType !== Ident) {
+ matcher = getOperator.call(this);
+
+ this.skipSC();
+
+ value = this.tokenType === StringToken
+ ? this.String()
+ : this.Identifier();
+
+ this.skipSC();
+ }
+
+ // attribute flags
+ if (this.tokenType === Ident) {
+ flags = this.consume(Ident);
+
+ this.skipSC();
+ }
+ }
+
+ this.eat(RightSquareBracket);
+
+ return {
+ type: 'AttributeSelector',
+ loc: this.getLocation(start, this.tokenStart),
+ name,
+ matcher,
+ value,
+ flags
+ };
+}
+
+export function generate(node) {
+ this.token(Delim, '[');
+ this.node(node.name);
+
+ if (node.matcher !== null) {
+ this.tokenize(node.matcher);
+ this.node(node.value);
+ }
+
+ if (node.flags !== null) {
+ this.token(Ident, node.flags);
+ }
+
+ this.token(Delim, ']');
+}