Skip to content

Commit

Permalink
code fmt and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Jul 23, 2024
1 parent 5b964c4 commit b4c7e17
Show file tree
Hide file tree
Showing 12 changed files with 5,124 additions and 3,185 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
indent_style = space
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: test
on:
push:
branches:
- 'main'
- 'master'
pull_request:
workflow_dispatch:

defaults:
run:
shell: bash

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
# Test node 14/16/18/20/22 on ubuntu
# Test node 20 on macos/windows
# Enable annotations only for node 20 + ubuntu
matrix:
os: [ubuntu-latest]
node: [16, 18, 20, 22]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: npm ci
run: npm ci

- name: test
run: npm run test
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2016 David Clark
Copyright © CSSTools Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 18 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module.exports = function resolveNestedSelector(selector, node) {
var parent = node.parent;
var parentIsNestAtRule = parent.type === 'atrule' && parent.name === 'nest';
var parent = node.parent;
var parentIsNestAtRule = parent.type === 'atrule' && parent.name === 'nest';

if (parent.type === 'root') return [selector];
if (parent.type !== 'rule' && !parentIsNestAtRule) return resolveNestedSelector(selector, parent);
if (parent.type === 'root') return [selector];
if (parent.type !== 'rule' && !parentIsNestAtRule) return resolveNestedSelector(selector, parent);

var parentSelectors = (parentIsNestAtRule)
? parent.params.split(',').map(function(s) { return s.trim(); })
: parent.selectors;
var parentSelectors = (parentIsNestAtRule)
? parent.params.split(',').map(function(s) { return s.trim(); })
: parent.selectors;

var resolvedSelectors = parentSelectors.reduce(function(result, parentSelector) {
if (selector.indexOf('&') !== -1) {
var newlyResolvedSelectors = resolveNestedSelector(parentSelector, parent).map(function(resolvedParentSelector) {
return selector.replace(/&/g, resolvedParentSelector);
});
return result.concat(newlyResolvedSelectors);
}
var resolvedSelectors = parentSelectors.reduce(function(result, parentSelector) {
if (selector.indexOf('&') !== -1) {
var newlyResolvedSelectors = resolveNestedSelector(parentSelector, parent).map(function(resolvedParentSelector) {
return selector.replace(/&/g, resolvedParentSelector);
});
return result.concat(newlyResolvedSelectors);
}

var combinedSelector = [ parentSelector, selector ].join(' ');
return result.concat(resolveNestedSelector(combinedSelector, parent));
}, []);
var combinedSelector = [ parentSelector, selector ].join(' ');
return result.concat(resolveNestedSelector(combinedSelector, parent));
}, []);

return resolvedSelectors;
return resolvedSelectors;
}
Loading

0 comments on commit b4c7e17

Please sign in to comment.