Skip to content

Commit 2545d01

Browse files
committed
fix slow typing
1 parent 4b1160e commit 2545d01

File tree

8 files changed

+61
-44
lines changed

8 files changed

+61
-44
lines changed

src/block/node/BlankNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createNodeParser } from "./creator";
22
import { createPlainNode } from "./PlainNode";
33

4+
import type { NodeParser } from "./index";
45
import type { BlankNode, PlainNode } from "./type";
56
import type { NodeCreator } from "./creator";
67

@@ -17,7 +18,7 @@ const createBlankNode: NodeCreator<BlankNode | PlainNode> = (raw, opts) =>
1718
},
1819
];
1920

20-
export const BlankNodeParser = createNodeParser(createBlankNode, {
21+
export const BlankNodeParser: NodeParser = createNodeParser(createBlankNode, {
2122
parseOnNested: false,
2223
parseOnQuoted: true,
2324
patterns: [blankRegExp],

src/block/node/CodeNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createNodeParser } from "./creator";
22
import { createPlainNode } from "./PlainNode";
33

4+
import type { NodeParser } from "./index";
45
import type { CodeNode, PlainNode } from "./type";
56
import type { NodeCreator } from "./creator";
67

@@ -17,7 +18,7 @@ const createCodeNode: NodeCreator<CodeNode | PlainNode> = (raw, opts) =>
1718
},
1819
];
1920

20-
export const CodeNodeParser = createNodeParser(createCodeNode, {
21+
export const CodeNodeParser: NodeParser = createNodeParser(createCodeNode, {
2122
parseOnNested: false,
2223
parseOnQuoted: true,
2324
patterns: [codeRegExp],

src/block/node/CommandLineNode.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createNodeParser } from "./creator";
22
import { createPlainNode } from "./PlainNode";
33

4+
import type { NodeParser } from "./index";
45
import type { CommandLineNode, PlainNode } from "./type";
56
import type { NodeCreator } from "./creator";
67

@@ -27,8 +28,11 @@ const createCommandLineNode: NodeCreator<CommandLineNode | PlainNode> = (
2728
];
2829
};
2930

30-
export const CommandLineNodeParser = createNodeParser(createCommandLineNode, {
31-
parseOnNested: false,
32-
parseOnQuoted: false,
33-
patterns: [commandLineRegExp],
34-
});
31+
export const CommandLineNodeParser: NodeParser = createNodeParser(
32+
createCommandLineNode,
33+
{
34+
parseOnNested: false,
35+
parseOnQuoted: false,
36+
patterns: [commandLineRegExp],
37+
}
38+
);

src/block/node/DecorationNode.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { convertToNodes } from "./index";
22
import { createNodeParser } from "./creator";
33
import { createPlainNode } from "./PlainNode";
44

5+
import type { NodeParser } from "./index";
56
import type { DecorationNode, PlainNode } from "./type";
67
import type { NodeCreator } from "./creator";
78

@@ -74,8 +75,11 @@ const createDecorationNode: NodeCreator<DecorationNode | PlainNode> = (
7475
];
7576
};
7677

77-
export const DecorationNodeParser = createNodeParser(createDecorationNode, {
78-
parseOnNested: false,
79-
parseOnQuoted: true,
80-
patterns: [decorationRegExp],
81-
});
78+
export const DecorationNodeParser: NodeParser = createNodeParser(
79+
createDecorationNode,
80+
{
81+
parseOnNested: false,
82+
parseOnQuoted: true,
83+
patterns: [decorationRegExp],
84+
}
85+
);

src/block/node/ExternalLinkNode.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createNodeParser } from "./creator";
22
import { createPlainNode } from "./PlainNode";
33

4+
import type { NodeParser } from "./index";
45
import type { NodeCreator } from "./creator";
56
import type { LinkNode, PlainNode } from "./type";
67

@@ -43,13 +44,16 @@ const createExternalLinkNode: NodeCreator<LinkNode | PlainNode> = (
4344
];
4445
};
4546

46-
export const ExternalLinkNodeParser = createNodeParser(createExternalLinkNode, {
47-
parseOnNested: true,
48-
parseOnQuoted: true,
49-
patterns: [
50-
hrefFirstUrlRegExp,
51-
contentFirstUrlRegExp,
52-
bracketedUrlRegExp,
53-
httpRegExp,
54-
],
55-
});
47+
export const ExternalLinkNodeParser: NodeParser = createNodeParser(
48+
createExternalLinkNode,
49+
{
50+
parseOnNested: true,
51+
parseOnQuoted: true,
52+
patterns: [
53+
hrefFirstUrlRegExp,
54+
contentFirstUrlRegExp,
55+
bracketedUrlRegExp,
56+
httpRegExp,
57+
],
58+
}
59+
);

src/block/node/PlainNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createNodeParser } from "./creator";
22

3+
import type { NodeParser } from "./index";
34
import type { PlainNode } from "./type";
45
import type { NodeCreator } from "./creator";
56

@@ -11,7 +12,7 @@ export const createPlainNode: NodeCreator<PlainNode> = (raw) => [
1112
},
1213
];
1314

14-
export const PlainNodeParser = createNodeParser(createPlainNode, {
15+
export const PlainNodeParser: NodeParser = createNodeParser(createPlainNode, {
1516
parseOnNested: true,
1617
parseOnQuoted: true,
1718
patterns: [/^()(.*)()$/],

src/block/node/StrongNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { convertToNodes } from "./index";
22
import { createNodeParser } from "./creator";
33
import { createPlainNode } from "./PlainNode";
44

5+
import type { NodeParser } from "./index";
56
import type { PlainNode, StrongNode } from "./type";
67
import type { NodeCreator } from "./creator";
78

@@ -21,7 +22,7 @@ const createStrongNode: NodeCreator<StrongNode | PlainNode> = (raw, opts) =>
2122
},
2223
];
2324

24-
export const StrongNodeParser = createNodeParser(createStrongNode, {
25+
export const StrongNodeParser: NodeParser = createNodeParser(createStrongNode, {
2526
parseOnNested: false,
2627
parseOnQuoted: true,
2728
patterns: [strongRegExp],

src/block/node/index.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,24 @@ const combineNodeParsers =
4646
() => PlainNodeParser(text, opts)
4747
)();
4848

49-
export const convertToNodes = combineNodeParsers(
50-
FalsyEliminator,
51-
QuoteNodeParser,
52-
HelpfeelNodeParser,
53-
CodeNodeParser,
54-
CommandLineNodeParser,
55-
FormulaNodeParser,
56-
BlankNodeParser,
57-
DecorationNodeParser,
58-
StrongImageNodeParser,
59-
StrongIconNodeParser,
60-
StrongNodeParser,
61-
ImageNodeParser,
62-
ExternalLinkNodeParser,
63-
IconNodeParser,
64-
GoogleMapNodeParser,
65-
InternalLinkNodeParser,
66-
HashTagNodeParser,
67-
NumberListNodeParser
68-
);
49+
export const convertToNodes: ReturnType<typeof combineNodeParsers> =
50+
combineNodeParsers(
51+
FalsyEliminator,
52+
QuoteNodeParser,
53+
HelpfeelNodeParser,
54+
CodeNodeParser,
55+
CommandLineNodeParser,
56+
FormulaNodeParser,
57+
BlankNodeParser,
58+
DecorationNodeParser,
59+
StrongImageNodeParser,
60+
StrongIconNodeParser,
61+
StrongNodeParser,
62+
ImageNodeParser,
63+
ExternalLinkNodeParser,
64+
IconNodeParser,
65+
GoogleMapNodeParser,
66+
InternalLinkNodeParser,
67+
HashTagNodeParser,
68+
NumberListNodeParser
69+
);

0 commit comments

Comments
 (0)