Skip to content

Commit

Permalink
refactor(language-core): remove unnecessary conditionWrapWith
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Dec 18, 2024
1 parent 9daef54 commit ed3e333
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
11 changes: 4 additions & 7 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { toString } from 'muggle-string';
import type { Code, VueCodeInformation, VueCompilerOptions } from '../../types';
import { hyphenateAttr, hyphenateTag } from '../../utils/shared';
import { createVBindShorthandInlayHintInfo } from '../inlayHints';
import { conditionWrapWith, newLine, variableNameRegex, wrapWith } from '../utils';
import { newLine, variableNameRegex, wrapWith } from '../utils';
import { generateCamelized } from '../utils/camelized';
import { generateUnicode } from '../utils/unicode';
import type { TemplateCodegenContext } from './context';
Expand Down Expand Up @@ -116,8 +116,7 @@ export function* generateElementProps(
if (shouldSpread) {
yield `...{ `;
}
const codes = conditionWrapWith(
enableCodeFeatures,
const codes = wrapWith(
prop.loc.start.offset,
prop.loc.end.offset,
ctx.codeFeatures.verification,
Expand Down Expand Up @@ -203,8 +202,7 @@ export function* generateElementProps(
if (shouldSpread) {
yield `...{ `;
}
const codes = conditionWrapWith(
enableCodeFeatures,
const codes = wrapWith(
prop.loc.start.offset,
prop.loc.end.offset,
ctx.codeFeatures.verification,
Expand Down Expand Up @@ -242,8 +240,7 @@ export function* generateElementProps(
&& !prop.arg
&& prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
) {
const codes = conditionWrapWith(
enableCodeFeatures,
const codes = wrapWith(
prop.exp.loc.start.offset,
prop.exp.loc.end.offset,
ctx.codeFeatures.verification,
Expand Down
15 changes: 0 additions & 15 deletions packages/language-core/lib/codegen/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@ export const endOfLine = `;${newLine}`;
export const combineLastMapping: VueCodeInformation = { __combineLastMapping: true };
export const variableNameRegex = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;

export function* conditionWrapWith(
condition: boolean,
startOffset: number,
endOffset: number,
features: VueCodeInformation,
...wrapCodes: Code[]
): Generator<Code> {
if (condition) {
yield* wrapWith(startOffset, endOffset, features, ...wrapCodes);
}
else {
yield* wrapCodes;
}
}

export function* wrapWith(
startOffset: number,
endOffset: number,
Expand Down

0 comments on commit ed3e333

Please sign in to comment.