-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/knip/fixtures/exports-special-characters/exports.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export const $dollar = '$'; | ||
export const dollar$ = '$$'; | ||
export const _underscore = '_'; | ||
|
||
export class DollarMembers { | ||
$member: string; | ||
member$: string; | ||
$method: () => string; | ||
method$: () => string; | ||
} | ||
|
||
export class $Dollar {} | ||
|
||
export type $DollarType = string; | ||
|
||
export enum Characters { | ||
' ' = ' ', | ||
'-' = '-', | ||
',' = ',', | ||
':' = ':', | ||
'?' = '?', | ||
'.' = '.', | ||
'(' = '(', | ||
')' = ')', | ||
'[' = '[', | ||
']' = ']', | ||
'{' = '{', | ||
'}' = '}', | ||
'@' = '@', | ||
'*' = '*', | ||
'/' = '/', | ||
'\\' = '\\', | ||
'+' = '+', | ||
'|' = '|', | ||
$ = '$', | ||
Slash = '/', | ||
Space = ' ', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type Characters, DollarMembers } from './exports'; | ||
|
||
type Ref = Characters; | ||
|
||
const instance = new DollarMembers(); |
6 changes: 6 additions & 0 deletions
6
packages/knip/fixtures/exports-special-characters/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@fixtures/exports-special-characters", | ||
"knip": { | ||
"include": ["classMembers"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { test } from 'bun:test'; | ||
import assert from 'node:assert/strict'; | ||
import { main } from '../src/index.js'; | ||
import { resolve } from '../src/util/path.js'; | ||
import baseArguments from './helpers/baseArguments.js'; | ||
import baseCounters from './helpers/baseCounters.js'; | ||
|
||
const cwd = resolve('fixtures/exports-special-characters'); | ||
|
||
test('Handle special characters in named exports and members', async () => { | ||
const { issues, counters } = await main({ | ||
...baseArguments, | ||
cwd, | ||
}); | ||
|
||
assert(issues.exports['exports.ts']['$dollar']); | ||
assert(issues.exports['exports.ts']['dollar$']); | ||
assert(issues.exports['exports.ts']['_underscore']); | ||
assert(issues.exports['exports.ts']['$Dollar']); | ||
|
||
assert(issues.types['exports.ts']['$DollarType']); | ||
|
||
assert(issues.classMembers['exports.ts']['$member']); | ||
assert(issues.classMembers['exports.ts']['member$']); | ||
assert(issues.classMembers['exports.ts']['$method']); | ||
assert(issues.classMembers['exports.ts']['method$']); | ||
|
||
assert(issues.enumMembers['exports.ts']['-']); | ||
assert(issues.enumMembers['exports.ts'][',']); | ||
assert(issues.enumMembers['exports.ts'][':']); | ||
assert(issues.enumMembers['exports.ts']['?']); | ||
assert(issues.enumMembers['exports.ts']['.']); | ||
assert(issues.enumMembers['exports.ts']['(']); | ||
assert(issues.enumMembers['exports.ts'][')']); | ||
assert(issues.enumMembers['exports.ts']['[']); | ||
assert(issues.enumMembers['exports.ts'][']']); | ||
assert(issues.enumMembers['exports.ts']['{']); | ||
assert(issues.enumMembers['exports.ts']['}']); | ||
assert(issues.enumMembers['exports.ts']['@']); | ||
assert(issues.enumMembers['exports.ts']['*']); | ||
assert(issues.enumMembers['exports.ts']['/']); | ||
assert(issues.enumMembers['exports.ts']['\\\\']); | ||
assert(issues.enumMembers['exports.ts']['+']); | ||
assert(issues.enumMembers['exports.ts']['|']); | ||
assert(issues.enumMembers['exports.ts']['$']); | ||
assert(issues.enumMembers['exports.ts']['Slash']); | ||
assert(issues.enumMembers['exports.ts']['Space']); | ||
|
||
assert.deepEqual(counters, { | ||
...baseCounters, | ||
classMembers: 4, | ||
enumMembers: 20, | ||
exports: 4, | ||
types: 1, | ||
processed: 2, | ||
total: 2, | ||
}); | ||
}); |