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

Classes #2813

Merged
merged 68 commits into from
Aug 30, 2023
Merged

Classes #2813

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5be8c16
use classes in errors
vixalien Aug 14, 2023
42377e5
use classes in lib/renderer
vixalien Aug 14, 2023
47171ec
use classes in lib/arguments
vixalien Aug 14, 2023
ff47681
remove double initializer
vixalien Aug 14, 2023
2515a6b
use classes in lib/nodes/atblock
vixalien Aug 14, 2023
9e245ba
fix constructor jsdoc in wrong place
vixalien Aug 14, 2023
595d075
convert atrule and subclasses to use classes
vixalien Aug 14, 2023
beb344c
use classes in lib/node
vixalien Aug 14, 2023
06196cf
use classes in lib/nodes/boolean
vixalien Aug 14, 2023
bee5a15
use classes in lib/nodes/ident
vixalien Aug 14, 2023
eb2bd03
use classes in lib/nodes/expression
vixalien Aug 14, 2023
a17ed5a
fix getter typed as function
vixalien Aug 14, 2023
3da652b
use classes in lib/nodes/rgba
vixalien Aug 14, 2023
cb3916e
use classes in lib/nodes/call
vixalien Aug 14, 2023
f3bf083
use classes in lib/nodes/group
vixalien Aug 14, 2023
7a9bd09
use classes in lib/nodes/literal
vixalien Aug 14, 2023
0d9bab9
use class in lib/nodes/selector
vixalien Aug 14, 2023
ba6b8d4
use class in lib/nodes/block
vixalien Aug 14, 2023
897db88
use class in lib/nodes/property
vixalien Aug 14, 2023
5eaab94
use class in lib/nodes/unit
vixalien Aug 14, 2023
c14d66a
use class in lib/nodes/binop
vixalien Aug 14, 2023
b606e17
use class in lib/nodes/function
vixalien Aug 14, 2023
0f896c0
use class in lib/nodes/string
vixalien Aug 14, 2023
1737910
use class in lib/nodes/import
vixalien Aug 14, 2023
7a0b780
fix expression getters written as functions
vixalien Aug 14, 2023
dbe78d2
use class in lib/nodes/param
vixalien Aug 14, 2023
54f52af
use class in lib/nodes/if
vixalien Aug 14, 2023
d70087b
use class in lib/nodes/ternary
vixalien Aug 14, 2023
aa02fab
use class in lib/nodes/each
vixalien Aug 14, 2023
affb57a
use class in lib/nodes/unaryop
vixalien Aug 14, 2023
20a3613
use class in lib/nodes/object
vixalien Aug 14, 2023
679a6c5
use class in lib/nodes/extend
vixalien Aug 14, 2023
6254849
use classes in lib/nodes/hsla
vixalien Aug 14, 2023
0420dd1
fix hsla/rgba fromRGBA/fromHSLA static constructors
vixalien Aug 14, 2023
12a40a7
fix trying to initialize boolean without `new`
vixalien Aug 14, 2023
07fced1
use class in lib/nodes/member
vixalien Aug 14, 2023
aa054f6
use class in lib/nodes/comment
vixalien Aug 14, 2023
a6208d0
use class in lib/nodes/namespace
vixalien Aug 14, 2023
a6a67ba
use class in lib/nodes/query-list
vixalien Aug 14, 2023
c695092
use class in lib/nodes/query
vixalien Aug 14, 2023
f0b449c
use class in lib/nodes/feature
vixalien Aug 14, 2023
be7d750
fix CoercionError not calling super
vixalien Aug 14, 2023
e49b52e
fix trying to construct a class without `new`
vixalien Aug 14, 2023
51ca019
use class in lib/nodes/charset
vixalien Aug 14, 2023
5d91fe5
use class in lib/nodes/null
vixalien Aug 14, 2023
f2deee0
use class in lib/nodes/return
vixalien Aug 14, 2023
707ea78
fix events not getting exported
vixalien Aug 14, 2023
194068e
use class in lib/nodes/root
vixalien Aug 14, 2023
d6093f9
use class in lib/stack
vixalien Aug 14, 2023
1be1353
use classes in `Visitor` and it's subclasses
vixalien Aug 14, 2023
252e645
use classes in lib/visitor/deps-resolver
vixalien Aug 14, 2023
3590e2f
use classes in lib/lexer
vixalien Aug 14, 2023
3b7a165
use class in selector parser
vixalien Aug 14, 2023
e05efc4
use classes in Converter
vixalien Aug 14, 2023
09c5e92
use classes in MemoryCache
vixalien Aug 14, 2023
f6d594f
use classes in FSCache
vixalien Aug 14, 2023
c82b727
use classes in NullCache
vixalien Aug 14, 2023
5157af5
use classes in lib/functions/image
vixalien Aug 14, 2023
cda150c
use classes in lib/token
vixalien Aug 14, 2023
a1f1fb5
use class in lib/stack/scope
vixalien Aug 14, 2023
c7f74df
use class in lib/stack/frame
vixalien Aug 14, 2023
8d98456
use class in lib/parser
vixalien Aug 14, 2023
8b9d84e
use `super.method()`
vixalien Aug 14, 2023
b9b1ee7
use `Object.setPrototypeOf` instead of `__proto__`
vixalien Aug 14, 2023
b89f435
use static method instead of initialisor (for node v10-12)
vixalien Aug 14, 2023
19292d6
use getters to use alias
vixalien Aug 14, 2023
13770b5
added deno tests
vixalien Aug 14, 2023
9610e4e
downgrade `@adobe/css-tools` to 4.2.0 for node v10 compat
vixalien Aug 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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;
};