Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual decaf source #3

Open
wants to merge 5 commits into
base: machine-decaf
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions Gruntfile.coffee

This file was deleted.

11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"name": "selector-kit",
"version": "0.0.0",
"description": "A barebones toolkit for CSS selector parsing and matching.",
"main": "./lib/selector-kit",
"main": "./src/selector-kit",
"scripts": {
"prepublish": "grunt clean lint coffee",
"test": "grunt test"
"test": "jasmine-focused --captureExceptions --coffee spec/"
},
"repository": {
"type": "git",
Expand All @@ -21,12 +20,6 @@
"devDependencies": {
"coffee-script": "^1.7.0",
"jasmine-focused": "^1.0.4",
"grunt-contrib-coffee": "^0.9.0",
"grunt-cli": "^0.1.8",
"grunt": "^0.4.1",
"grunt-shell": "^0.2.2",
"grunt-coffeelint": "^0.0.6",
"rimraf": "^2.2.2",
"coffee-cache": "^0.2.0",
"temp": "^0.6.0"
}
Expand Down
5 changes: 3 additions & 2 deletions src/selector-kit.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
module.exports =
{Selector: require('./selector')};
module.exports = {
Selector: require("./selector.js")
};
51 changes: 20 additions & 31 deletions src/selector.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS205: Consider reworking code to avoid use of IIFEs
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
let Selector;
const slick = require('atom-slick');
const slick = require("atom-slick");

let indexCounter = 0;

module.exports =
(Selector = class Selector {
class Selector {
// Public: Creates one or more {Selector} objects.
//
// This method will return more than one `Selector` object when the string
Expand All @@ -24,35 +15,33 @@ module.exports =
//
// Returns an {Array} or {Selector} objects.
static create(selectorString, options) {
return (() => {
const result = [];
for (let selectorAst of Array.from(slick.parse(selectorString))) {
for (let selectorComponent of Array.from(selectorAst)) { this.parsePseudoSelectors(selectorComponent); }
result.push(new (this)(selectorAst, options));
const result = [];
for (let selectorAst of Array.from(slick.parse(selectorString))) {
for (let selectorComponent of Array.from(selectorAst)) {
this.parsePseudoSelectors(selectorComponent);
}
return result;
})();
result.push(new (this)(selectorAst, options));
}
return result;
}

static parsePseudoSelectors(selectorComponent) {
if (selectorComponent.pseudos == null) { return; }
return (() => {
const result = [];
for (let pseudoClass of Array.from(selectorComponent.pseudos)) {
if (pseudoClass.name === 'not') {
if (selectorComponent.notSelectors == null) { selectorComponent.notSelectors = []; }
result.push(selectorComponent.notSelectors.push(...Array.from(this.create(pseudoClass.value) || [])));
} else {
result.push(console.warn(`Unsupported pseudo-selector: ${pseudoClass.name}`));
}
const result = [];
for (let pseudoClass of selectorComponent.pseudos) {
if (pseudoClass.name === "not") {
if (selectorComponent.notSelectors == null) { selectorComponent.notSelectors = []; }
result.push(selectorComponent.notSelectors.push(...Array.from(this.create(pseudoClass.value) || [])));
} else {
result.push(console.warn(`Unsupported pseudo-selector: ${pseudoClass.name}`));
}
return result;
})();
}
return result;
}

constructor(selector, options) {
this.selector = selector;
const priority = (options != null ? options.priority : undefined) != null ? (options != null ? options.priority : undefined) : 0;
const priority = options?.priority ?? 0;
this.specificity = this.calculateSpecificity();
this.index = priority + indexCounter++;
}
Expand Down Expand Up @@ -171,4 +160,4 @@ module.exports =

return (a * 100) + (b * 10) + (c * 1);
}
});
}
Loading