diff --git a/Gruntfile.coffee b/Gruntfile.coffee deleted file mode 100644 index cc89bac..0000000 --- a/Gruntfile.coffee +++ /dev/null @@ -1,41 +0,0 @@ -module.exports = (grunt) -> - grunt.initConfig - pkg: grunt.file.readJSON('package.json') - - coffee: - glob_to_multiple: - expand: true - cwd: 'src' - src: ['**/*.coffee'] - dest: 'lib' - ext: '.js' - - coffeelint: - options: - no_empty_param_list: - level: 'error' - max_line_length: - level: 'ignore' - indentation: - level: 'ignore' - - src: ['src/*.coffee'] - test: ['spec/*.coffee'] - gruntfile: ['Gruntfile.coffee'] - - shell: - test: - command: 'jasmine-focused --captureExceptions --coffee spec/' - options: - stdout: true - stderr: true - failOnError: true - - grunt.loadNpmTasks('grunt-contrib-coffee') - grunt.loadNpmTasks('grunt-shell') - grunt.loadNpmTasks('grunt-coffeelint') - - grunt.registerTask 'clean', -> require('rimraf').sync('lib') - grunt.registerTask('lint', ['coffeelint']) - grunt.registerTask('default', ['coffee', 'lint']) - grunt.registerTask('test', ['coffee', 'lint', 'shell:test']) diff --git a/package.json b/package.json index e21d6d8..7469337 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } diff --git a/src/selector-kit.js b/src/selector-kit.js index 06f9512..129b176 100644 --- a/src/selector-kit.js +++ b/src/selector-kit.js @@ -1,2 +1,3 @@ -module.exports = - {Selector: require('./selector')}; +module.exports = { + Selector: require("./selector.js") +}; diff --git a/src/selector.js b/src/selector.js index 3c0a99c..33b6bcb 100644 --- a/src/selector.js +++ b/src/selector.js @@ -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 @@ -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++; } @@ -171,4 +160,4 @@ module.exports = return (a * 100) + (b * 10) + (c * 1); } -}); +}