Skip to content

Commit

Permalink
Classes (#2813)
Browse files Browse the repository at this point in the history
* use classes in errors

* use classes in lib/renderer

* use classes in lib/arguments

* remove double initializer

* use classes in lib/nodes/atblock

* fix constructor jsdoc in wrong place

* convert atrule and subclasses to use classes

* use classes in lib/node

* use classes in lib/nodes/boolean

* use classes in lib/nodes/ident

* use classes in lib/nodes/expression

* fix getter typed as function

* use classes in lib/nodes/rgba

* use classes in lib/nodes/call

* use classes in lib/nodes/group

* use classes in lib/nodes/literal

* use class in lib/nodes/selector

* use class in lib/nodes/block

* use class in lib/nodes/property

* use class in lib/nodes/unit

* use class in lib/nodes/binop

* use class in lib/nodes/function

* use class in lib/nodes/string

* use class in lib/nodes/import

* fix expression getters written as functions

* use class in lib/nodes/param

* use class in lib/nodes/if

* use class in lib/nodes/ternary

* use class in lib/nodes/each

* use class in lib/nodes/unaryop

* use class in lib/nodes/object

* use class in lib/nodes/extend

* use classes in lib/nodes/hsla

* fix hsla/rgba fromRGBA/fromHSLA static constructors

* fix trying to initialize boolean without `new`

* use class in lib/nodes/member

* use class in lib/nodes/comment

* use class in lib/nodes/namespace

* use class in lib/nodes/query-list

* use class in lib/nodes/query

* use class in lib/nodes/feature

* fix CoercionError not calling super

* fix trying to construct a class without `new`

* use class in lib/nodes/charset

* use class in lib/nodes/null

* use class in lib/nodes/return

* fix events not getting exported

* use class in lib/nodes/root

* use class in lib/stack

* use classes in `Visitor` and it's subclasses

* use classes in lib/visitor/deps-resolver

* use classes in lib/lexer

* use class in selector parser

* use classes in Converter

* use classes in MemoryCache

* use classes in FSCache

* use classes in NullCache

* use classes in lib/functions/image

* use classes in lib/token

* use class in lib/stack/scope

* use class in lib/stack/frame

* use class in lib/parser

* use `super.method()`

instead of `Node.prototype.method.call(this, ...args)`

* use `Object.setPrototypeOf` instead of `__proto__`

* use static method instead of initialisor (for node v10-12)

* use getters to use alias

property assignment doesn't work on node v10-12

* added deno tests

* downgrade `@adobe/css-tools` to 4.2.0 for node v10 compat
  • Loading branch information
vixalien committed Aug 30, 2023
1 parent 00ca9fe commit 50b0a33
Show file tree
Hide file tree
Showing 63 changed files with 7,672 additions and 7,789 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -96,3 +96,23 @@ jobs:
run: npm install
- name: Run nyc
run: npx nyc@latest npm run test

deno_tests:
name: 'Test stylus on ${{matrix.os}} with latest stable deno'
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
# Pull repo to test machine
- uses: actions/checkout@v3
# Configures the deno version used on GitHub-hosted runners
- uses: denoland/setup-deno@v1
with:
# Run with latest stable Deno
deno-version: v1.x
- name: Print deno version
# Output useful info for debugging.
run: deno --version
- name: Run Test
run: deno run -A deno/test.ts
33 changes: 33 additions & 0 deletions deno/test.ts
@@ -0,0 +1,33 @@
import Mocha from "mocha";

import fs from "node:fs";
import path from "node:path";
import process from "node:process";

globalThis.process = process;

const mocha = new Mocha({
bail: true,
checkLeaks: true,
require: ["chai"],
reporter: "dot",
});

const testDirs = ["test/", "test/middleware/"];

testDirs.forEach((testDir) => {
fs
.readdirSync(testDir)
.filter(function (file) {
if (testDir === "test/" && file === "deno.js") return false;

return file.slice(-3) === ".js";
})
.forEach(function (file) {
mocha.addFile(path.join(testDir, file));
});
});

mocha.run(function (failures) {
process.exitCode = failures ? 1 : 0;
});
122 changes: 63 additions & 59 deletions lib/cache/fs.js
Expand Up @@ -8,73 +8,77 @@ var crypto = require('crypto')
, version = require('../../package').version
, nodes = require('../nodes');

var FSCache = module.exports = function(options) {
options = options || {};
this._location = options['cache location'] || '.styl-cache';
if (!fs.existsSync(this._location)) fs.mkdirSync(this._location);
};
module.exports = class FSCache {
constructor(options) {
options = options || {};
this._location = options['cache location'] || '.styl-cache';
if (!fs.existsSync(this._location)) fs.mkdirSync(this._location);
}

/**
* Set cache item with given `key` to `value`.
*
* @param {String} key
* @param {Object} value
* @api private
*/

FSCache.prototype.set = function(key, value) {
fs.writeFileSync(join(this._location, key), JSON.stringify(value));
};
/**
* Set cache item with given `key` to `value`.
*
* @param {String} key
* @param {Object} value
* @api private
*/

/**
* Get cache item with given `key`.
*
* @param {String} key
* @return {Object}
* @api private
*/
set(key, value) {
fs.writeFileSync(join(this._location, key), JSON.stringify(value));
};

FSCache.prototype.get = function(key) {
var data = fs.readFileSync(join(this._location, key), 'utf-8');
return JSON.parse(data, FSCache.fromJSON);
};
/**
* Get cache item with given `key`.
*
* @param {String} key
* @return {Object}
* @api private
*/

/**
* Check if cache has given `key`.
*
* @param {String} key
* @return {Boolean}
* @api private
*/
get(key) {
var data = fs.readFileSync(join(this._location, key), 'utf-8');
return JSON.parse(data, FSCache.fromJSON);
};

FSCache.prototype.has = function(key) {
return fs.existsSync(join(this._location, key));
};
/**
* Check if cache has given `key`.
*
* @param {String} key
* @return {Boolean}
* @api private
*/

/**
* Generate key for the source `str` with `options`.
*
* @param {String} str
* @param {Object} options
* @return {String}
* @api private
*/
has(key) {
return fs.existsSync(join(this._location, key));
};

FSCache.prototype.key = function(str, options) {
var hash = crypto.createHash('sha1');
hash.update(str + version + options.prefix);
return hash.digest('hex');
};
/**
* Generate key for the source `str` with `options`.
*
* @param {String} str
* @param {Object} options
* @return {String}
* @api private
*/

/**
* JSON to Stylus nodes converter.
*
* @api private
*/
key(str, options) {
var hash = crypto.createHash('sha1');
hash.update(str + version + options.prefix);
return hash.digest('hex');
};

/**
* JSON to Stylus nodes converter.
*
* @api private
*/

static fromJSON(key, val) {
if (val && val.__type) {
Object.setPrototypeOf(val, nodes[val.__type].prototype);
}
return val;
};

FSCache.fromJSON = function(key, val) {
if (val && val.__type) {
val.__proto__ = nodes[val.__type].prototype;
}
return val;
};

0 comments on commit 50b0a33

Please sign in to comment.