Skip to content

Commit 32faaad

Browse files
committed
refactor(language-core): overload wrapWith to use in more sources
1 parent 4669a54 commit 32faaad

File tree

18 files changed

+105
-75
lines changed

18 files changed

+105
-75
lines changed

packages/language-core/lib/codegen/script/scriptSetup.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { camelize } from '@vue/shared';
22
import type { ScriptSetupRanges } from '../../parsers/scriptSetupRanges';
33
import type { Code, Sfc, TextRange } from '../../types';
44
import { codeFeatures } from '../codeFeatures';
5-
import { combineLastMapping, endOfLine, generateSfcBlockSection, newLine } from '../utils';
5+
import { endOfLine, generateSfcBlockSection, newLine } from '../utils';
66
import { generateCamelized } from '../utils/camelized';
7+
import { wrapWith } from '../utils/wrapWith';
78
import { generateComponent, generateEmitsOption } from './component';
89
import { generateComponentSelf } from './componentSelf';
910
import type { ScriptCodegenContext } from './context';
@@ -215,9 +216,13 @@ function* generateSetupFunction(
215216
`])`
216217
] : [
217218
` as __VLS_StyleModules[`,
218-
['', scriptSetup.name, exp.start, codeFeatures.verification],
219-
`'$style'`,
220-
['', scriptSetup.name, exp.end, combineLastMapping],
219+
...wrapWith(
220+
exp.start,
221+
exp.end,
222+
scriptSetup.name,
223+
codeFeatures.verification,
224+
`'$style'`
225+
),
221226
`])`
222227
],
223228
callExp.end,
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Code } from '../../types';
22
import { codeFeatures } from '../codeFeatures';
3-
import { newLine } from '../utils';
3+
import { combineLastMapping, newLine } from '../utils';
4+
import { wrapWith } from '../utils/wrapWith';
45

56
export function* generateClassProperty(
67
styleIndex: number,
@@ -9,26 +10,20 @@ export function* generateClassProperty(
910
propertyType: string
1011
): Generator<Code> {
1112
yield `${newLine} & { `;
12-
yield [
13-
'',
14-
'style_' + styleIndex,
13+
yield* wrapWith(
1514
offset,
16-
codeFeatures.navigation,
17-
];
18-
yield `'`;
19-
yield [
20-
classNameWithDot.slice(1),
21-
'style_' + styleIndex,
22-
offset + 1,
23-
codeFeatures.navigation,
24-
];
25-
yield `'`;
26-
yield [
27-
'',
28-
'style_' + styleIndex,
2915
offset + classNameWithDot.length,
16+
'style_' + styleIndex,
3017
codeFeatures.navigation,
31-
];
18+
`'`,
19+
[
20+
classNameWithDot.slice(1),
21+
'style_' + styleIndex,
22+
offset + 1,
23+
combineLastMapping
24+
],
25+
`'`
26+
);
3227
yield `: ${propertyType}`;
3328
yield ` }`;
3429
}

packages/language-core/lib/codegen/template/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type * as CompilerDOM from '@vue/compiler-dom';
22
import type { Code, VueCodeInformation } from '../../types';
33
import { codeFeatures } from '../codeFeatures';
44
import { InlayHintInfo } from '../inlayHints';
5-
import { endOfLine, newLine, wrapWith } from '../utils';
5+
import { endOfLine, newLine } from '../utils';
6+
import { wrapWith } from '../utils/wrapWith';
67
import type { TemplateCodegenOptions } from './index';
78

89
export type TemplateCodegenContext = ReturnType<typeof createTemplateCodegenContext>;

packages/language-core/lib/codegen/template/element.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { camelize, capitalize } from '@vue/shared';
33
import type { Code, VueCodeInformation } from '../../types';
44
import { getSlotsPropertyName, hyphenateTag } from '../../utils/shared';
55
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
6-
import { endOfLine, identifierRegex, newLine, normalizeAttributeValue, wrapWith } from '../utils';
6+
import { endOfLine, identifierRegex, newLine, normalizeAttributeValue } from '../utils';
77
import { generateCamelized } from '../utils/camelized';
8+
import { wrapWith } from '../utils/wrapWith';
89
import type { TemplateCodegenContext } from './context';
910
import { generateElementChildren } from './elementChildren';
1011
import { generateElementDirectives } from './elementDirectives';

packages/language-core/lib/codegen/template/elementDirectives.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { camelize } from '@vue/shared';
33
import type { Code } from '../../types';
44
import { hyphenateAttr } from '../../utils/shared';
55
import { codeFeatures } from '../codeFeatures';
6-
import { endOfLine, wrapWith } from '../utils';
6+
import { endOfLine } from '../utils';
77
import { generateCamelized } from '../utils/camelized';
88
import { generateStringLiteralKey } from '../utils/stringLiteralKey';
9+
import { wrapWith } from '../utils/wrapWith';
910
import type { TemplateCodegenContext } from './context';
1011
import { generatePropExp } from './elementProps';
1112
import type { TemplateCodegenOptions } from './index';

packages/language-core/lib/codegen/template/elementEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as CompilerDOM from '@vue/compiler-dom';
22
import { camelize, capitalize } from '@vue/shared';
33
import type * as ts from 'typescript';
44
import type { Code } from '../../types';
5-
import { combineLastMapping, createTsAst, endOfLine, identifierRegex, newLine, wrapWith } from '../utils';
5+
import { combineLastMapping, createTsAst, endOfLine, identifierRegex, newLine } from '../utils';
66
import { generateCamelized } from '../utils/camelized';
7+
import { wrapWith } from '../utils/wrapWith';
78
import type { TemplateCodegenContext } from './context';
89
import type { TemplateCodegenOptions } from './index';
910
import { generateInterpolation } from './interpolation';
@@ -81,7 +82,6 @@ export function* generateEventArg(
8182
start + name.length,
8283
features,
8384
`'`,
84-
['', 'template', start, combineLastMapping],
8585
directive,
8686
...generateCamelized(
8787
capitalize(name),

packages/language-core/lib/codegen/template/elementProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import type { Code, VueCodeInformation, VueCompilerOptions } from '../../types';
66
import { hyphenateAttr, hyphenateTag } from '../../utils/shared';
77
import { codeFeatures } from '../codeFeatures';
88
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
9-
import { identifierRegex, newLine, wrapWith } from '../utils';
9+
import { identifierRegex, newLine } from '../utils';
1010
import { generateCamelized } from '../utils/camelized';
1111
import { generateUnicode } from '../utils/unicode';
12+
import { wrapWith } from '../utils/wrapWith';
1213
import type { TemplateCodegenContext } from './context';
1314
import { generateModifiers } from './elementDirectives';
1415
import { generateEventArg, generateEventExpression } from './elementEvents';

packages/language-core/lib/codegen/template/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as CompilerDOM from '@vue/compiler-dom';
22
import type * as ts from 'typescript';
33
import type { Code, Sfc, VueCompilerOptions } from '../../types';
44
import { getSlotsPropertyName } from '../../utils/shared';
5-
import { endOfLine, newLine, wrapWith } from '../utils';
5+
import { endOfLine, newLine } from '../utils';
6+
import { wrapWith } from '../utils/wrapWith';
67
import { TemplateCodegenContext, createTemplateCodegenContext } from './context';
78
import { generateObjectProperty } from './objectProperty';
89
import { generateStyleScopedClassReferences } from './styleScopedClasses';

packages/language-core/lib/codegen/template/objectProperty.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { camelize } from '@vue/shared';
22
import type { Code, VueCodeInformation } from '../../types';
3-
import { combineLastMapping, identifierRegex, wrapWith } from '../utils';
3+
import { combineLastMapping, identifierRegex } from '../utils';
44
import { generateCamelized } from '../utils/camelized';
55
import { generateStringLiteralKey } from '../utils/stringLiteralKey';
6+
import { wrapWith } from '../utils/wrapWith';
67
import type { TemplateCodegenContext } from './context';
78
import type { TemplateCodegenOptions } from './index';
89
import { generateInterpolation } from './interpolation';

packages/language-core/lib/codegen/template/slotOutlet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as CompilerDOM from '@vue/compiler-dom';
22
import type { Code } from '../../types';
33
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
4-
import { endOfLine, newLine, wrapWith } from '../utils';
4+
import { endOfLine, newLine } from '../utils';
5+
import { wrapWith } from '../utils/wrapWith';
56
import type { TemplateCodegenContext } from './context';
67
import { generateElementChildren } from './elementChildren';
78
import { generateElementProps, generatePropExp } from './elementProps';

0 commit comments

Comments
 (0)