Skip to content

Commit 2580755

Browse files
committed
refactor: extract Snippet union types to break import cycle
1 parent eabe839 commit 2580755

6 files changed

Lines changed: 77 additions & 60 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ All notable changes to the **ES7+ React/Redux/React-Native snippets** extension
44

55
## [Unreleased]
66

7-
## [5.0.0-rc.1] - 2026-04-28
7+
## [5.0.0] - 2026-04-28
88

9-
First release under the **r5n** publisher with full React 17–19 support and a new tooling stack.
9+
First release under the **r5n** publisher (`r5n.es-js-snippets`) with full React 17–19 support and a new tooling stack.
1010

1111
### Added
1212

@@ -45,10 +45,6 @@ First release under the **r5n** publisher with full React 17–19 support and a
4545
- Babel/Jest ESLint plugins and `@babel/eslint-parser` (unused — repo has no test suite or `.js` source files).
4646
- Legacy `@babel/cli`, `@babel/preset-typescript` devDependencies.
4747

48-
### Known issues
49-
50-
- Circular dependency between `src/helpers/parseSnippetToBody.ts` and `src/helpers/generateSnippets.ts` (type-only import of `Snippet`). Currently surfaced as a lint warning; will be fixed before `5.0.0` GA by extracting shared types to `src/types.ts`.
51-
5248
## [4.4.0] - 2020-12-18
5349

5450
- Enable extension after startup finish to respect and parse snippets on settings change.

package.json

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
{
22
"name": "es-js-snippets",
3-
"displayName": "ES7+ React/Redux/React-Native snippets",
4-
"version": "5.0.0-rc.1",
5-
"description": "Extensions for React, React-Native and Redux in JS/TS with ES7+ syntax. Customizable.",
3+
"displayName": "ES JS Snippets",
4+
"version": "5.0.0",
5+
"description": "Customizable code snippets for React 17–19, React Native, Redux Toolkit, React Router v6, and modern JavaScript/TypeScript. Components, hooks, imports, prop-types, tests — searchable via Cmd+Shift+R.",
66
"categories": [
77
"Snippets"
88
],
99
"keywords": [
10-
"customizable",
11-
"javascript",
10+
"react snippets",
11+
"react native snippets",
12+
"redux snippets",
13+
"javascript snippets",
14+
"typescript snippets",
15+
"es7 snippets",
1216
"react",
1317
"react-native",
18+
"react-hooks",
19+
"react-router",
1420
"redux",
21+
"redux-toolkit",
22+
"rtk-query",
23+
"javascript",
24+
"typescript",
25+
"jsx",
26+
"tsx",
1527
"snippets",
16-
"typescript"
28+
"hooks",
29+
"es2022",
30+
"es7",
31+
"customizable",
32+
"productivity"
1733
],
1834
"homepage": "https://github.com/r5n/vscode-react-javascript-snippets#readme",
1935
"bugs": {

src/helpers/generateSnippets.ts

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import path from 'path';
22
import { window } from 'vscode';
33

4-
import componentsSnippets, {
5-
ComponentsSnippet,
6-
} from '../sourceSnippets/components';
7-
import consoleSnippets, { ConsoleSnippet } from '../sourceSnippets/console';
8-
import hooksSnippets, { HooksSnippet } from '../sourceSnippets/hooks';
9-
import importsSnippets, { ImportsSnippet } from '../sourceSnippets/imports';
10-
import othersSnippets, { OthersSnippet } from '../sourceSnippets/others';
11-
import propTypesSnippets, {
12-
PropTypesSnippet,
13-
} from '../sourceSnippets/propTypes';
14-
import reactNativeSnippets, {
15-
ReactNativeSnippet,
16-
} from '../sourceSnippets/reactNative';
17-
import reduxSnippets, { ReduxSnippet } from '../sourceSnippets/redux';
18-
import testsSnippets, { TestsSnippet } from '../sourceSnippets/tests';
19-
import typescriptSnippets, {
20-
TypescriptSnippet,
21-
} from '../sourceSnippets/typescript';
4+
import componentsSnippets from '../sourceSnippets/components';
5+
import consoleSnippets from '../sourceSnippets/console';
6+
import hooksSnippets from '../sourceSnippets/hooks';
7+
import importsSnippets from '../sourceSnippets/imports';
8+
import othersSnippets from '../sourceSnippets/others';
9+
import propTypesSnippets from '../sourceSnippets/propTypes';
10+
import reactNativeSnippets from '../sourceSnippets/reactNative';
11+
import reduxSnippets from '../sourceSnippets/redux';
12+
import testsSnippets from '../sourceSnippets/tests';
13+
import typescriptSnippets from '../sourceSnippets/typescript';
14+
import { Snippets } from '../snippetTypes';
2215
import { writeFile } from 'fs/promises';
2316

2417
import extensionConfig from './extensionConfig';
@@ -49,34 +42,6 @@ const validateLanguageScopes = (scopes: string) => {
4942
return valid.length > 0 ? valid.join(',') : VALID_LANGUAGE_SCOPES.join(',');
5043
};
5144

52-
export type SnippetKeys =
53-
| OthersSnippet['key']
54-
| HooksSnippet['key']
55-
| ImportsSnippet['key']
56-
| ReactNativeSnippet['key']
57-
| TypescriptSnippet['key']
58-
| ReduxSnippet['key']
59-
| ComponentsSnippet['key']
60-
| ConsoleSnippet['key']
61-
| PropTypesSnippet['key']
62-
| TestsSnippet['key'];
63-
64-
export type Snippet =
65-
| OthersSnippet
66-
| HooksSnippet
67-
| ImportsSnippet
68-
| ReactNativeSnippet
69-
| TypescriptSnippet
70-
| ReduxSnippet
71-
| ComponentsSnippet
72-
| ConsoleSnippet
73-
| PropTypesSnippet
74-
| TestsSnippet;
75-
76-
export type Snippets = {
77-
[key in SnippetKeys]: Snippet;
78-
};
79-
8045
const getSnippets = () => {
8146
const { typescript, languageScopes: rawScopes } = extensionConfig();
8247
const languageScopes = validateLanguageScopes(rawScopes);

src/helpers/parseSnippetToBody.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { Snippet } from '../snippetTypes';
2+
13
import extensionConfig from './extensionConfig';
2-
import { Snippet } from './generateSnippets';
34
import replaceOrRemoveReactImport from './replaceOrRemoveReactImport';
45

56
const parseSnippetToBody = (snippet: Snippet) => {

src/helpers/snippetSearch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { commands, SnippetString, window } from 'vscode';
33

44
import { readFile } from 'fs/promises';
55

6+
import { Snippet } from '../snippetTypes';
7+
68
import { parseSnippet } from './formatters';
7-
import { Snippet } from './generateSnippets';
89

910
const snippetSearch = async () => {
1011
const { showQuickPick, activeTextEditor } = window;

src/snippetTypes.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ComponentsSnippet } from './sourceSnippets/components';
2+
import { ConsoleSnippet } from './sourceSnippets/console';
3+
import { HooksSnippet } from './sourceSnippets/hooks';
4+
import { ImportsSnippet } from './sourceSnippets/imports';
5+
import { OthersSnippet } from './sourceSnippets/others';
6+
import { PropTypesSnippet } from './sourceSnippets/propTypes';
7+
import { ReactNativeSnippet } from './sourceSnippets/reactNative';
8+
import { ReduxSnippet } from './sourceSnippets/redux';
9+
import { TestsSnippet } from './sourceSnippets/tests';
10+
import { TypescriptSnippet } from './sourceSnippets/typescript';
11+
12+
export type SnippetKeys =
13+
| OthersSnippet['key']
14+
| HooksSnippet['key']
15+
| ImportsSnippet['key']
16+
| ReactNativeSnippet['key']
17+
| TypescriptSnippet['key']
18+
| ReduxSnippet['key']
19+
| ComponentsSnippet['key']
20+
| ConsoleSnippet['key']
21+
| PropTypesSnippet['key']
22+
| TestsSnippet['key'];
23+
24+
export type Snippet =
25+
| OthersSnippet
26+
| HooksSnippet
27+
| ImportsSnippet
28+
| ReactNativeSnippet
29+
| TypescriptSnippet
30+
| ReduxSnippet
31+
| ComponentsSnippet
32+
| ConsoleSnippet
33+
| PropTypesSnippet
34+
| TestsSnippet;
35+
36+
export type Snippets = {
37+
[key in SnippetKeys]: Snippet;
38+
};

0 commit comments

Comments
 (0)