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

feat: support parsing indented syntax (with some minor limitations) #13

Merged
merged 5 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# scss-sassdoc-parser

A more lightweight parser for SassDoc.

More or less a thin wrapper around `scss-comment-parser`, but with all SassDoc annotations and TypeScript definitions built in.
A lightweight parser for SassDoc.

## Usage

Expand Down Expand Up @@ -56,6 +54,40 @@ const singlePathResult = await doParse("_helpers.scss");
const arrayOfPathsResult = await doParse(["_mixins.scss", "_functions.scss"]);
```

### Indented syntax

The parser can handle indented syntax with a caveat:

- The `context` field will not include accurate `code` or `line` fields.

```js
import { parseSync } from "scss-sassdoc-parser";

const result = parseSync(
`
/// Converts a value to the given unit
/// @param {Number} $value - Value to add unit to
/// @param {String} $unit - String representation of the unit
/// @return {Number} - $value expressed in $unit
@function to-length($value, $unit)
$units: (
"px": 1px,
"rem": 1rem,
"%": 1%,
"em": 1em,
)

@if not index(map-keys($units), $unit)
$_: log("Invalid unit #{$unit}.")

@return $value * map.get($units, $unit)
`,
);
```

## Output

The result from the `parse` function is an array of [`ParseResult` (type definitions)](/src/types.ts#L87). Check out the [snapshot tests](/src/sassdoc-parser.test.ts) for some example outputs.
The result from the `parse` function is an array of [`ParseResult` (type definitions)](/src/types.ts#L87). Check out the snapshot for some example outputs:

- [Example output for SCSS](/src/sassdoc-parser.test.ts)
- [Example output for indented](/src/sassdoc-parser-indented.test.ts)
124 changes: 98 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"engines": {
"node": ">=20"
},
"description": "A more lightweight parser for SassDoc in SCSS files, with TypeScript definitions.",
"description": "A more lightweight parser for SassDoc, with TypeScript definitions.",
"keywords": [
"sassdoc",
"scss",
Expand Down Expand Up @@ -60,6 +60,6 @@
"vitest": "^1.0.0"
},
"dependencies": {
"scss-comment-parser": "^0.8.4"
"cdocparser": "0.15.0"
}
}
4 changes: 2 additions & 2 deletions src/annotation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import annotations from "./annotations/index.js";
import type {
Annotation as ScssCommentParserAnnotation,
ParseResult as ScssCommentParserParseResult,
} from "scss-comment-parser";
import annotations from "./annotations/index.js";
} from "./sass-comment-parser.js";

export type BuiltInAnnotationNames =
| "access"
Expand Down
Loading