Skip to content

Commit

Permalink
refactor: update
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Nov 5, 2024
1 parent c1bec18 commit cd94158
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/language-core/lib/parsers/vueCompilerOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as ts from 'typescript';
import { Sfc, VueCompilerOptions } from '../types';
import type { Sfc, VueCompilerOptions } from '../types';

export function parseCompilerOptions(
const syntaxReg = /^\/\*\*\s*@vue\$(?<key>.+) (?<value>.+)\s*\*\/$/;

export function parseVueCompilerOptions(
ts: typeof import('typescript'),
sfc: Sfc
): Partial<VueCompilerOptions> | undefined {
Expand Down Expand Up @@ -29,7 +31,7 @@ export function parseCompilerOptions(
.map(range => {
try {
const text = ast.text.slice(range.pos, range.end)
const match = text.match(/^\/\*\*\s*@vue\$(?<key>.+) (?<value>.+)\s*\*\/$/);
const match = text.match(syntaxReg);
if (match) {
const { key, value } = match.groups ?? {};
return [key, JSON.parse(value)] as const;
Expand Down
4 changes: 2 additions & 2 deletions packages/language-core/lib/plugins/vue-tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { generateScript } from '../codegen/script';
import { generateTemplate } from '../codegen/template';
import { parseScriptRanges } from '../parsers/scriptRanges';
import { parseScriptSetupRanges } from '../parsers/scriptSetupRanges';
import { parseCompilerOptions } from '../parsers/vueCompilerOptions';
import { parseVueCompilerOptions } from '../parsers/vueCompilerOptions';
import type { Code, Sfc, VueLanguagePlugin } from '../types';
import { resolveVueCompilerOptions } from '../utils/ts';

Expand Down Expand Up @@ -80,7 +80,7 @@ function createTsx(
: 'js';
});
const vueCompilerOptions = computed(() => {
const options = parseCompilerOptions(ts, _sfc);
const options = parseVueCompilerOptions(ts, _sfc);
return options
? resolveVueCompilerOptions(options, ctx.vueCompilerOptions)
: ctx.vueCompilerOptions;
Expand Down

0 comments on commit cd94158

Please sign in to comment.