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

Add a couple APIs, do some general repo cleanup #25

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
12 changes: 0 additions & 12 deletions .clang-format

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
strategy:
# We support Node Current, LTS, and Maintenance. See
# https://nodejs.org/en/about/releases/ for release schedule.
#
# We test all supported Node versions on Linux, and the oldest and newest
# on macOS/Windows.
matrix:
include:
- node: 18
os: ubuntu-22.04
- node: 18
os: macos-12
- node: 18
os: windows-2022
- node: 20
os: ubuntu-22.04
- node: 20
os: macos-12
- node: 20
os: windows-2022

# Allow all matrix configurations to complete, instead of cancelling as
# soon as one fails. Useful because we often have different kinds of
# failures depending on the OS.
fail-fast: false

runs-on: ${{ matrix.os }}

env:
WIREIT_LOGGER: "quiet-ci"

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- uses: google/wireit@setup-github-actions-caching/v1
- run: npm ci
- run: npm test
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
/dist/
/node_modules/
/.wireit/
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


<!--
PRs should document their user-visible changes (if any) in the
Unreleased section, uncommenting the header as necessary.
-->

## Unreleased

- Add a `getChildren` API as a more specific method similar to `iterateOverAst` that only gets the direct children of a node.
- Add a `getNodesAtLocation` API to get the nodes whose ranges contain a given location.

## [0.1.0] - 2017-07-18

* Added ranges to AST nodes, which specify offsets into the source code for the
- Added ranges to AST nodes, which specify offsets into the source code for the
start and end of AST.
* Added the `iterateOverAst` method, which returns an iterable over every
- Added the `iterateOverAst` method, which returns an iterable over every
node in an AST.
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ fast and flexible CSS parsing and transformation is a critical feature.

### Goals

- Feasibility of being used in conjunction with Polymer or Polymer
Designer.
- Parse CSS loosely and flexibly. This parser is not spec-compliant, however
it will parse all spec-compliant CSS.
- Parse CSS quickly and efficiently. This parser is a suitable tool to aide in
the design and implementation of runtime transformations.
- Graceful error recovery. Malformed CSS will be parsed by this
parser as closely as possible to the way a browser would parse it.
- Feasibility of being used in conjunction with Polymer or Polymer
Designer.
- Parse CSS loosely and flexibly. This parser is not spec-compliant, however
it will parse all spec-compliant CSS.
- Parse CSS quickly and efficiently. This parser is a suitable tool to aide in
the design and implementation of runtime transformations.
- Graceful error recovery. Malformed CSS will be parsed by this
parser as closely as possible to the way a browser would parse it.

### Installing

Expand Down Expand Up @@ -50,7 +50,6 @@ const ast = parser.parse(css);
```js
/* Step 1: Inherit from NodeFactory */
class CustomNodeFactory extends shadyCss.NodeFactory {

/*
* Step 2: Implement a custom node factory method. Here we override the
* default factory for Expression nodes
Expand Down Expand Up @@ -89,13 +88,12 @@ from parsed CSS.
```js
/* Step 1: Inherit from Stringifier. */
class CustomStringifier extends shadyCss.Stringifier {

/**
* Step 2: Implement a stringification method named after the type of the node
* you are interested in stringifying. In this case, we are implementing
* stringification for the Darken Expression nodes we implemented parsing for
* above.
*/
* Step 2: Implement a stringification method named after the type of the node
* you are interested in stringifying. In this case, we are implementing
* stringification for the Darken Expression nodes we implemented parsing for
* above.
*/
darkenExpression(darkenExpression) {
// For the sake of brevity, please assume that the darken function returns
// a darker version of the color parameter:
Expand All @@ -117,6 +115,7 @@ const css = stringifier.stringify(ast);
--nog: blue;
}
```

```js
{
"type": 1, /* stylesheet */
Expand Down Expand Up @@ -151,6 +150,7 @@ ruleset {
};
}
```

```js
{
"type": 1, /* stylesheet */
Expand Down Expand Up @@ -185,9 +185,10 @@ ruleset {

```css
.title {
@apply(--my-toolbar-title-theme);
@apply (--my-toolbar-title-theme);
}
```

```js
{
"type": 1, /* stylesheet */
Expand Down Expand Up @@ -222,6 +223,7 @@ ruleset {
};
}
```

```js
{
"type": 1, /* stylesheet */
Expand Down Expand Up @@ -258,9 +260,11 @@ ruleset {
/* before */
body {
margin: 0;
padding: 0px
padding: 0px;
}
```

<!-- prettier-ignore -->
```css
/* after */
body{margin:0;padding:0px;}
Expand All @@ -278,6 +282,8 @@ body{margin:0;padding:0px;}

@charset 'foo';
```

<!-- prettier-ignore -->
```css
/* after */
@import url('foo.css');@font-face{font-family:foo;}@charset 'foo';
Expand All @@ -296,9 +302,11 @@ body{margin:0;padding:0px;}

#target {
gak: var(--qux);
@apply(--foo);
@apply (--foo);
}
```

<!-- prettier-ignore -->
```css
/* after */
:root{--qux:vim;--foo:{bar:baz;};}#target{gak:var(--qux);@apply (--foo);}
Expand Down
Loading
Loading