Skip to content

Commit 21ab584

Browse files
committed
feat(lexer): Lexer
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent fc3c16c commit 21ab584

21 files changed

+1375
-6
lines changed

.codecov.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ ignore:
8888
- src/types/
8989

9090
profiling:
91-
critical_files_paths: []
91+
critical_files_paths:
92+
- src/lexer.ts

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
**/*config.*.timestamp*
99
**/.DS_Store
1010
**/.temp/
11+
**/__tests__/benchmark.json
1112
**/__tests__/report.*
13+
**/__tests__/typecheck.json
1214
**/coverage/
1315
**/dist/
1416
**/node_modules/

.eslintrc.cjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
*/
1111
const config = {
1212
extends: ['./.eslintrc.base.cjs'],
13-
overrides: [...require('./.eslintrc.base.cjs').overrides],
13+
overrides: [
14+
...require('./.eslintrc.base.cjs').overrides,
15+
{
16+
files: ['__fixtures__/dbl-linear.ts'],
17+
rules: {
18+
'@typescript-eslint/require-await': 0
19+
}
20+
}
21+
],
1422
root: true
1523
}
1624

.github/infrastructure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ repository:
172172
automated_security_fixes: true
173173
default_branch: main
174174
delete_branch_on_merge: true
175-
description: unified compliant file parser for docast
175+
description: docast utility for parsing docblocks
176176
has_issues: true
177177
has_projects: true
178178
has_wiki: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ yarn-error.log*
4747
**/*config.*.timestamp*
4848
**/__tests__/benchmark.json
4949
**/__tests__/report.*
50+
**/__tests__/typecheck.json
5051
**/coverage/
5152
**/tsconfig*temp.json
5253
*.lcov

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![github release](https://img.shields.io/github/v/release/flex-development/docast-util-from-docs.svg?include_prereleases&sort=semver)](https://github.com/flex-development/docast-util-from-docs/releases/latest)
44
[![npm](https://img.shields.io/npm/v/@flex-development/docast-util-from-docs.svg)](https://npmjs.com/package/@flex-development/docast-util-from-docs)
5-
[![codecov](https://codecov.io/gh/flex-development/docast-util-from-docs/branch/main/graph/badge.svg?token=R2TPEBGWXB)](https://codecov.io/gh/flex-development/docast-util-from-docs)
5+
[![codecov](https://codecov.io/gh/flex-development/docast-util-from-docs/graph/badge.svg?token=um87Ekggjn)](https://codecov.io/gh/flex-development/docast-util-from-docs)
66
[![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
77
[![license](https://img.shields.io/github/license/flex-development/docast-util-from-docs.svg)](LICENSE.md)
88
[![conventional commits](https://img.shields.io/badge/-conventional%20commits-fe5196?logo=conventional-commits&logoColor=ffffff)](https://conventionalcommits.org/)

__fixtures__/.gitkeep

Whitespace-only changes.

__fixtures__/dbl-linear.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @file Fixtures - dblLinear
3+
* @module fixtures/dblLinear
4+
* @see https://codewars.com/kata/5672682212c8ecf83e000050
5+
*/
6+
7+
/**
8+
* Consider a sequence `u` where `u` is defined as follows:
9+
*
10+
* 1. The number `u(0) = 1` is the first one in `u`
11+
* 2. For each `x` in `u`, `y = 2x + 1` and `z = 3x + 1` must be in `u` too
12+
* 3. There are no other numbers in `u`
13+
*
14+
* Given an index, `n`, the function returns the element at `u(n)`.
15+
*
16+
* @async
17+
*
18+
* @example
19+
* await dblLinear(0) // 1
20+
* @example
21+
* await dblLinear(10) // 22
22+
* @example
23+
* await dblLinear(100) // 447
24+
* @example
25+
* await dblLinear(7687) // 111718
26+
*
27+
* @param {number} n - Index of element to get
28+
* @return {Promise<number>} Element at `u(n)`
29+
*/
30+
async function dblLinear(n: number): Promise<number> {
31+
/** @const {number[]} u - Sequence */
32+
const u: number[] = [1]
33+
34+
/** @var {number} j - Index of x in {@linkcode u} used to calculate y */
35+
let j: number = 0
36+
37+
/** @var {number} k - Index of x in {@linkcode u} used to calculate z */
38+
let k: number = 0
39+
40+
/*
41+
* build sequence up to index n (inclusive)
42+
*/
43+
for (let i = 1; i <= n; i++) {
44+
/** @const {number} y - `y` */
45+
const y: number = 2 * u[j]! + 1
46+
47+
/** @const {number} z - `z` */
48+
const z: number = 3 * u[k]! + 1
49+
50+
/* set sequence value to smallest value in [y, z] */
51+
u[i] = Math.min(y, z)
52+
53+
// increase of index of x used to calculate y by 1
54+
if (u[i] === y) j++
55+
56+
// increase of index of x used to calculate z by 1
57+
if (u[i] === z) k++
58+
}
59+
60+
return u[n]!
61+
}
62+
63+
export default dblLinear

__fixtures__/detect-syntax.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @file Fixtures - detectSyntax
3+
* @module fixtures/detectSyntax
4+
*/
5+
6+
import { hasCJSSyntax, hasESMSyntax } from '@flex-development/mlly'
7+
8+
/**
9+
* Detects if `code` contains CommonJS syntax, ESM syntax, or a mixture of both.
10+
*
11+
* Ignores matches in comments.
12+
*
13+
* @see {@linkcode hasCJSSyntax}
14+
* @see {@linkcode hasESMSyntax}
15+
*
16+
* @example
17+
* import { detectSyntax } from '@flex-development/mlly'
18+
*
19+
* console.debug(detectSyntax('export default {}'))
20+
*
21+
* @param {string} code - Code to evaluate
22+
* @return {{ cjs: boolean; esm: boolean; mixed: boolean }} Detection result
23+
*/
24+
const detectSyntax = (
25+
code: string
26+
): { cjs: boolean; esm: boolean; mixed: boolean } => {
27+
/**
28+
* CommonJS syntax check.
29+
*
30+
* @const {boolean} cjs
31+
*/
32+
const cjs: boolean = hasCJSSyntax(code)
33+
34+
/**
35+
* ESM syntax check.
36+
*
37+
* @const {boolean} esm
38+
*/
39+
const esm: boolean = hasESMSyntax(code)
40+
41+
return { cjs, esm, mixed: cjs && esm }
42+
}
43+
44+
export default detectSyntax

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"fix:dedupe": "yarn dedupe --strategy=highest",
6464
"fix:format": "dprint fmt",
6565
"fix:lint": "yarn check:lint --cache --fix",
66-
"postinstall": "[ -f ./node_modules/.bin/husky ] && chmod +x .husky/* && husky install || exit 0",
66+
"postinstall": "[ -f ./node_modules/.bin/husky ] && chmod +x .husky/* && husky || exit 0",
6767
"postpack": "toggle-scripts +postinstall",
6868
"postpublish": "toggle-scripts +prepack",
6969
"prepack": "toggle-scripts -postinstall && yarn build",

0 commit comments

Comments
 (0)