Skip to content

Commit

Permalink
chore: upgrade deps, docs, lint, tsconfig. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
morganney committed Jun 18, 2024
1 parent c13245d commit 91b1947
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 33 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

Walk an AST from SWC and visit each node type.

> [!WARNING]
> Not production ready, lots of AST nodes missing.
## Requirements

- AST is as defined by [`@swc/types`](https://github.com/swc-project/swc/tree/main/packages/types).
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ coverage:
status:
project:
default:
target: 80.0
target: 90.0
threshold: 0.5
patch:
default:
Expand Down
11 changes: 11 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export default tseslint.config(
'no-console': 'error',
'@typescript-eslint/no-use-before-define': 'error',
'@typescript-eslint/no-duplicate-type-constituents': 'error',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
Expand Down Expand Up @@ -59,6 +65,11 @@ export default tseslint.config(
},
{
files: ['test/*'],
languageOptions: {
parserOptions: {
project: './test/tsconfig.json',
},
},
rules: {
'@typescript-eslint/no-floating-promises': 'off',
},
Expand Down
34 changes: 15 additions & 19 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swc-walk",
"version": "1.0.0-alpha.1",
"version": "1.0.0-rc.0",
"description": "Walk an AST from SWC and visit each node type.",
"main": "dist/esm/walk.js",
"type": "module",
Expand Down Expand Up @@ -67,12 +67,11 @@
"@eslint/js": "^9.4.0",
"@knighted/duel": "^2.0.0-rc.1",
"@knighted/dump": "^1.0.3",
"@knighted/reparse": "^2.0.0",
"@stylistic/eslint-plugin-js": "^2.1.0",
"@swc/core": "^1.6.1",
"@swc/types": "^0.1.8",
"@types/node": "^20.13.0",
"c8": "^10.0.0",
"c8": "^10.1.2",
"eslint": "^9.4.0",
"eslint-plugin-n": "^17.8.1",
"prettier": "^3.3.0",
Expand Down
8 changes: 8 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": false,
"noEmit": true
},
"include": ["*.ts"]
}
4 changes: 3 additions & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { mock } from 'node:test'
import assert from 'node:assert'

import { parseSync, type ParseOptions } from '@swc/core'

import { simple } from '../src/walk.js'
import { BaseVisitor } from '../src/baseVisitor.js'

Expand Down Expand Up @@ -47,7 +49,7 @@ export function expect(options: Test & { method: ReturnType<typeof mock.method>
assert.equal(
options.method.mock.callCount(),
times,
`Expected ${options.type} to be called ${times.toString()} times, but was called ${options.method.mock.callCount().toString()} times.`,
`Expected ${options.type} to be called ${times} times, but was called ${options.method.mock.callCount().toString()} times.`,
)
},
}
Expand Down
13 changes: 8 additions & 5 deletions test/walk.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'

import { reparseSync } from '@knighted/reparse'
import { parseSync } from '@swc/core'

import { simple } from '../src/walk.js'

Expand All @@ -15,7 +15,8 @@ const state: WalkState = {

describe('swc-walk', () => {
it('walks an swc ast', () => {
const ast = reparseSync(`
const ast = parseSync(
`
let foo = bar = <baz>(p: baz): baz => {return p}
const [a, b]: [number, number] = [1,2]
const arrow = (arg: string) => {
Expand All @@ -27,7 +28,9 @@ describe('swc-walk', () => {
return 'foo'
}
}
`)
`,
{ syntax: 'typescript' },
)

simple<WalkState>(
ast,
Expand Down Expand Up @@ -62,7 +65,7 @@ describe('swc-walk', () => {

let typeParameterDeclarationNodes = 0

simple(reparseSync(`type SetInputText = Dispatch<SetStateAction<string>>`), {
simple(parseSync(`type SetInputText = Dispatch<SetStateAction<string>>`, { syntax: 'typescript' }), {
TsTypeAliasDeclaration(node) {
assert.equal(node.type, 'TsTypeAliasDeclaration')
},
Expand All @@ -79,7 +82,7 @@ describe('swc-walk', () => {

let tsTypeParameterNodes = 0

simple(reparseSync('interface List<T extends S> extends U, V { items: T[] }'), {
simple(parseSync('interface List<T extends S> extends U, V { items: T[] }', { syntax: 'typescript' }), {
TsArrayType(node) {
assert.equal(node.type, 'TsArrayType')
},
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"outDir": "dist",
"target": "ESNext"
},
"include": ["src", "test", "eslint.config.js"]
"include": ["src"]
}

0 comments on commit 91b1947

Please sign in to comment.