Skip to content

Commit

Permalink
feat: add extends detection (#243) (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
woldtwerk authored Aug 23, 2023
1 parent 03751ba commit 7ffb068
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"eslint": "8.47.0",
"h3": "^1.8.0",
"jquery": "^3.7.0",
"lit": "^2.8.0",
"typescript": "^5.1.6",
"unbuild": "^1.2.1",
"vitest": "^0.34.2",
Expand Down
39 changes: 39 additions & 0 deletions pnpm-lock.yaml

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

8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const excludeRE = [
export const importAsRE = /^.*\sas\s+/
export const separatorRE = /[,[\]{}\n]|\bimport\b/g

/** | |
* destructing case&ternary non-call | id |
* ↓ ↓ ↓ | |*/
export const matchRE = /(^|\.\.\.|(?:\bcase|\?)\s+|[^\w_$\/)])([\w_$]+)\s*(?=[.()[\]}:;?+\-*&|`<>,\n]|\b(?:instanceof|in)\b|$)/g
/** | |
* destructing case&ternary non-call inheritance | id |
* ↓ ↓ ↓ | |*/
export const matchRE = /(^|\.\.\.|(?:\bcase|\?)\s+|[^\w_$\/)]|(?:\bextends)\s+)([\w_$]+)\s*(?=[.()[\]}}:;?+\-*&|`<>,\n]|\b(?:instanceof|in)\b|$|(?<=extends\s+\w+)\s+{)/g

const regexRE = /\/[^\s]*?(?<!\\)(?<!\[[^\]]*)\/[gimsuy]*/g

Expand Down
4 changes: 4 additions & 0 deletions test/cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ describe('cases', () => {
}
]
},
{
from: 'lit',
imports: ['LitElement']
},
{
from: 'three',
imports: [['*', 'THREE']]
Expand Down
2 changes: 2 additions & 0 deletions test/cases/positive/extends.output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { LitElement } from 'lit';
class MyElement extends LitElement {}
1 change: 1 addition & 0 deletions test/cases/positive/extends.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class MyElement extends LitElement {}

0 comments on commit 7ffb068

Please sign in to comment.