Skip to content

Commit ff415e3

Browse files
committed
feat(compiler-sfc): default script lang
1 parent f3e4f03 commit ff415e3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/compiler-sfc/src/parse.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export interface SFCParseOptions {
2222
pad?: boolean | 'line' | 'space'
2323
ignoreEmpty?: boolean
2424
compiler?: TemplateCompiler
25+
26+
defaultScriptLang?: string
27+
defaultScriptSetupLang?: string
2528
}
2629

2730
export interface SFCBlock {
@@ -95,7 +98,9 @@ export function parse(
9598
sourceRoot = '',
9699
pad = false,
97100
ignoreEmpty = true,
98-
compiler = CompilerDOM
101+
compiler = CompilerDOM,
102+
defaultScriptLang,
103+
defaultScriptSetupLang
99104
}: SFCParseOptions = {}
100105
): SFCParseResult {
101106
const sourceKey =
@@ -190,6 +195,14 @@ export function parse(
190195
case 'script':
191196
const scriptBlock = createBlock(node, source, pad) as SFCScriptBlock
192197
const isSetup = !!scriptBlock.attrs.setup
198+
if (isSetup && defaultScriptSetupLang) {
199+
scriptBlock.lang ??= defaultScriptSetupLang
200+
}
201+
202+
if (defaultScriptLang) {
203+
scriptBlock.lang ??= defaultScriptLang
204+
}
205+
193206
if (isSetup && !descriptor.scriptSetup) {
194207
descriptor.scriptSetup = scriptBlock
195208
break

0 commit comments

Comments
 (0)