Skip to content

Commit

Permalink
update typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Dec 25, 2024
1 parent e81e834 commit 5a54818
Show file tree
Hide file tree
Showing 34 changed files with 1,669 additions and 1,157 deletions.
2,645 changes: 1,579 additions & 1,066 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@
"build:watch": "tsc --watch",
"test:ts": "vitest --dir src --run",
"test:watch": "vitest --dir src",
"test:gui": "vitest --dir src --ui",
"test": "npm run test:ts",
"format": "prettier src --write"
},
"dependencies": {
"fast-deep-equal": "^3.1.3",
"picocolors": "^1.0.0"
"picocolors": "^1.1.1"
},
"devDependencies": {
"@types/node": "^20.11.30",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"@vitest/ui": "^1.4.0",
"vite": "^5.2.6",
"vitest": "^1.4.0",
"typescript": "^5.4.3"
"@types/node": "^22.10.2",
"prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^4.1.0",
"vite": "^6.0.5",
"vitest": "^2.1.8",
"typescript": "^5.7.2"
},
"license": "GPL-3.0-or-later"
}
2 changes: 1 addition & 1 deletion src/errors/ParsingError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Span } from "../span/index.js"
import { Span } from "../span/index.ts"

export class ParsingError extends Error {
constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./InternalError.js"
export * from "./ParsingError.js"
export * from "./InternalError.ts"
export * from "./ParsingError.ts"
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./errors/index.js"
export * from "./match/index.js"
export * from "./parser/index.js"
export * from "./pattern-exp/index.js"
export * from "./sexp/index.js"
export * from "./span/index.js"
export * from "./errors/index.ts"
export * from "./match/index.ts"
export * from "./parser/index.ts"
export * from "./pattern-exp/index.ts"
export * from "./sexp/index.ts"
export * from "./span/index.ts"
4 changes: 2 additions & 2 deletions src/lexer/Lexer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "vitest"
import { Lexer } from "../lexer/index.js"
import { Token } from "../token/index.js"
import { Lexer } from "../lexer/index.ts"
import { Token } from "../token/index.ts"

const lexer = new Lexer({
quotes: [
Expand Down
6 changes: 3 additions & 3 deletions src/lexer/Lexer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ParserConfig, type ParserOptions } from "../parser/index.js"
import { Token } from "../token/index.js"
import { Lexing } from "./Lexing.js"
import { ParserConfig, type ParserOptions } from "../parser/index.ts"
import { Token } from "../token/index.ts"
import { Lexing } from "./Lexing.ts"

export class Lexer {
config: ParserConfig
Expand Down
10 changes: 5 additions & 5 deletions src/lexer/Lexing.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { InternalError, ParsingError } from "../errors/index.js"
import { Lexer } from "../lexer/index.js"
import { Position } from "../position/index.js"
import { Span } from "../span/index.js"
import { Token, type TokenKind } from "../token/index.js"
import { InternalError, ParsingError } from "../errors/index.ts"
import { Lexer } from "../lexer/index.ts"
import { Position } from "../position/index.ts"
import { Span } from "../span/index.ts"
import { Token, type TokenKind } from "../token/index.ts"

export class Lexing implements Iterator<Token> {
position = Position.init()
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Lexer.js"
export * from "./Lexer.ts"
2 changes: 1 addition & 1 deletion src/match/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./match.js"
export * from "./match.ts"
10 changes: 5 additions & 5 deletions src/match/match.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ParsingError } from "../errors/index.js"
import { evaluate, type PatternExp } from "../pattern-exp/index.js"
import { formatPattern, matchPattern, type Pattern } from "../pattern/index.js"
import { formatSexp, type Sexp } from "../sexp/index.js"
import { Span } from "../span/index.js"
import { ParsingError } from "../errors/index.ts"
import { evaluate, type PatternExp } from "../pattern-exp/index.ts"
import { formatPattern, matchPattern, type Pattern } from "../pattern/index.ts"
import { formatSexp, type Sexp } from "../sexp/index.ts"
import { Span } from "../span/index.ts"

export function matchSymbol(sexp: Sexp): string {
if (sexp.kind !== "Sym") {
Expand Down
12 changes: 6 additions & 6 deletions src/parser/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ParsingError } from "../errors/index.js"
import { Lexer } from "../lexer/index.js"
import { ParserConfig, type ParserOptions } from "../parser/index.js"
import { type Sexp } from "../sexp/index.js"
import { Token } from "../token/index.js"
import { Parsing } from "./Parsing.js"
import { ParsingError } from "../errors/index.ts"
import { Lexer } from "../lexer/index.ts"
import { ParserConfig, type ParserOptions } from "../parser/index.ts"
import { type Sexp } from "../sexp/index.ts"
import { Token } from "../token/index.ts"
import { Parsing } from "./Parsing.ts"

export class Parser {
lexer: Lexer
Expand Down
2 changes: 1 addition & 1 deletion src/parser/ParserConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InternalError } from "../errors/index.js"
import { InternalError } from "../errors/index.ts"

export interface ParserOptions {
quotes: Array<{ mark: string; symbol: string }>
Expand Down
14 changes: 7 additions & 7 deletions src/parser/Parsing.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { InternalError, ParsingError } from "../errors/index.js"
import { Parser } from "../parser/index.js"
import { Position } from "../position/index.js"
import * as Sexps from "../sexp/index.js"
import { type Sexp } from "../sexp/index.js"
import { Span } from "../span/index.js"
import { Token } from "../token/index.js"
import { InternalError, ParsingError } from "../errors/index.ts"
import { Parser } from "../parser/index.ts"
import { Position } from "../position/index.ts"
import * as Sexps from "../sexp/index.ts"
import { type Sexp } from "../sexp/index.ts"
import { Span } from "../span/index.ts"
import { Token } from "../token/index.ts"

type Result = { sexp: Sexp; remain: Array<Token> }

Expand Down
4 changes: 2 additions & 2 deletions src/parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./Parser.js"
export * from "./ParserConfig.js"
export * from "./Parser.ts"
export * from "./ParserConfig.ts"
10 changes: 5 additions & 5 deletions src/parser/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expect, test } from "vitest"
import { ParsingError } from "../errors/index.js"
import { Parser } from "../parser/index.js"
import { ParsingError } from "../errors/index.ts"
import { Parser } from "../parser/index.ts"
import {
cons,
evaluate,
list,
str,
v,
type PatternExp,
} from "../pattern-exp/index.js"
import { matchPatternOrFail } from "../pattern/index.js"
import { type Sexp } from "../sexp/index.js"
} from "../pattern-exp/index.ts"
import { matchPatternOrFail } from "../pattern/index.ts"
import { type Sexp } from "../sexp/index.ts"

const parser = new Parser({
quotes: [
Expand Down
8 changes: 4 additions & 4 deletions src/pattern-exp/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InternalError } from "../errors/index.js"
import { type PatternExp } from "../pattern-exp/index.js"
import * as Patterns from "../pattern/index.js"
import { type Pattern } from "../pattern/index.js"
import { InternalError } from "../errors/index.ts"
import { type PatternExp } from "../pattern-exp/index.ts"
import * as Patterns from "../pattern/index.ts"
import { type Pattern } from "../pattern/index.ts"

export function evaluate(exp: PatternExp): Pattern {
if (typeof exp === "number") {
Expand Down
4 changes: 2 additions & 2 deletions src/pattern-exp/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./PatternExp.js"
export * from "./evaluate.js"
export * from "./PatternExp.ts"
export * from "./evaluate.ts"
6 changes: 3 additions & 3 deletions src/pattern/Pattern.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ParsingError } from "../errors/index.js"
import { type Sexp } from "../sexp/index.js"
import { equal } from "../utils/equal.js"
import { ParsingError } from "../errors/index.ts"
import { type Sexp } from "../sexp/index.ts"
import { equal } from "../utils/equal.ts"

export type Pattern = Var | Cons | Null | Num | Str | Sym

Expand Down
2 changes: 1 addition & 1 deletion src/pattern/formatPattern.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unfoldFormatCons, type Pattern } from "../pattern/index.js"
import { unfoldFormatCons, type Pattern } from "../pattern/index.ts"

export function formatPattern(pattern: Pattern): string {
switch (pattern.kind) {
Expand Down
8 changes: 4 additions & 4 deletions src/pattern/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./Pattern.js"
export * from "./formatPattern.js"
export * from "./matchPattern.js"
export * from "./unfoldFormatCons.js"
export * from "./Pattern.ts"
export * from "./formatPattern.ts"
export * from "./matchPattern.ts"
export * from "./unfoldFormatCons.ts"
8 changes: 4 additions & 4 deletions src/pattern/matchPattern.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ParsingError } from "../errors/index.js"
import { type Pattern } from "../pattern/index.js"
import { type Sexp } from "../sexp/index.js"
import { equal } from "../utils/equal.js"
import { ParsingError } from "../errors/index.ts"
import { type Pattern } from "../pattern/index.ts"
import { type Sexp } from "../sexp/index.ts"
import { equal } from "../utils/equal.ts"

export function matchPatternOrFail(
pattern: Pattern,
Expand Down
2 changes: 1 addition & 1 deletion src/pattern/unfoldFormatCons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatPattern, type Pattern } from "../pattern/index.js"
import { formatPattern, type Pattern } from "../pattern/index.ts"

export function unfoldFormatCons(pattern: Pattern): {
heads: Array<string>
Expand Down
2 changes: 1 addition & 1 deletion src/position/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Position.js"
export * from "./Position.ts"
2 changes: 1 addition & 1 deletion src/sexp/Sexp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Span } from "../span/index.js"
import { Span } from "../span/index.ts"

export type Sexp = Cons | Null | Num | Str | Sym

Expand Down
2 changes: 1 addition & 1 deletion src/sexp/formatSexp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unfoldFormatCons, type Sexp } from "../sexp/index.js"
import { unfoldFormatCons, type Sexp } from "../sexp/index.ts"

export function formatSexp(sexp: Sexp): string {
switch (sexp.kind) {
Expand Down
6 changes: 3 additions & 3 deletions src/sexp/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./Sexp.js"
export * from "./formatSexp.js"
export * from "./unfoldFormatCons.js"
export * from "./Sexp.ts"
export * from "./formatSexp.ts"
export * from "./unfoldFormatCons.ts"
2 changes: 1 addition & 1 deletion src/sexp/unfoldFormatCons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatSexp, type Sexp } from "../sexp/index.js"
import { formatSexp, type Sexp } from "../sexp/index.ts"

export function unfoldFormatCons(sexp: Sexp): {
heads: Array<string>
Expand Down
8 changes: 4 additions & 4 deletions src/span/Span.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Position } from "../position/index.js"
import { color, type ColorMode } from "../utils/color.js"
import { intervalOverlap } from "../utils/interval.js"
import { isBrowser } from "../utils/isBrowser.js"
import { Position } from "../position/index.ts"
import { color, type ColorMode } from "../utils/color.ts"
import { intervalOverlap } from "../utils/interval.ts"
import { isBrowser } from "../utils/isBrowser.ts"

export class Span {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/span/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Span.js"
export * from "./Span.ts"
2 changes: 1 addition & 1 deletion src/token/Token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Span } from "../span/index.js"
import { Span } from "../span/index.ts"

export type TokenKind =
| "Symbol"
Expand Down
2 changes: 1 addition & 1 deletion src/token/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./Token.js"
export * from "./Token.ts"
2 changes: 1 addition & 1 deletion src/utils/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { equal } from "./equal.js"
import { equal } from "./equal.ts"

export function assert(value: any): void {
if (!value) {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"compilerOptions": {
"lib": ["esnext", "dom"],
"module": "node16",
"target": "es6",
"target": "es2017",
"strict": true,
"verbatimModuleSyntax": true,
"rewriteRelativeImportExtensions": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
Expand Down

0 comments on commit 5a54818

Please sign in to comment.