Skip to content

Commit

Permalink
feat: support parsing indented syntax (with some minor limitations) (#13
Browse files Browse the repository at this point in the history
)

In particular: code will always be the empty string, and the lines
can not be calculated.
  • Loading branch information
wkillerud authored Jul 7, 2024
1 parent f5bf51f commit 0f62d60
Show file tree
Hide file tree
Showing 11 changed files with 1,007 additions and 87 deletions.
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

0 comments on commit 0f62d60

Please sign in to comment.