Skip to content

Commit

Permalink
fix: pass compilerOptions to sfc parse
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 30, 2023
1 parent 071f30d commit 82f047d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/descriptorCache.ts
@@ -1,5 +1,5 @@
import * as fs from 'fs'
import type { SFCDescriptor } from 'vue/compiler-sfc'
import type { CompilerOptions, SFCDescriptor } from 'vue/compiler-sfc'
import { compiler } from './compiler'

const { parse } = compiler
Expand All @@ -9,7 +9,10 @@ export function setDescriptor(filename: string, entry: SFCDescriptor) {
descriptorCache.set(cleanQuery(filename), entry)
}

export function getDescriptor(filename: string): SFCDescriptor {
export function getDescriptor(
filename: string,
compilerOptions?: CompilerOptions
): SFCDescriptor {
filename = cleanQuery(filename)
if (descriptorCache.has(filename)) {
return descriptorCache.get(filename)!
Expand All @@ -24,6 +27,7 @@ export function getDescriptor(filename: string): SFCDescriptor {
const { descriptor } = parse(source, {
filename,
sourceMap: true,
templateParseOptions: compilerOptions,
})
descriptorCache.set(filename, descriptor)
return descriptor
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Expand Up @@ -116,6 +116,7 @@ export default function loader(
const { descriptor, errors } = parse(source, {
filename,
sourceMap,
templateParseOptions: options.compilerOptions,
})

const asCustomElement =
Expand Down Expand Up @@ -363,7 +364,9 @@ export default function loader(
if (!propsToAttach.length) {
code += `\n\nconst __exports__ = script;`
} else {
code += `\n\nimport exportComponent from ${stringifyRequest(exportHelperPath)}`
code += `\n\nimport exportComponent from ${stringifyRequest(
exportHelperPath
)}`
code += `\nconst __exports__ = /*#__PURE__*/exportComponent(script, [${propsToAttach
.map(([key, val]) => `['${key}',${val}]`)
.join(',')}])`
Expand Down
5 changes: 4 additions & 1 deletion src/templateLoader.ts
Expand Up @@ -27,7 +27,10 @@ const TemplateLoader: LoaderDefinitionFunction = function (source, inMap: any) {
loaderContext.mode === 'production' || process.env.NODE_ENV === 'production'
const query = qs.parse(loaderContext.resourceQuery.slice(1))
const scopeId = query.id as string
const descriptor = getDescriptor(loaderContext.resourcePath)
const descriptor = getDescriptor(
loaderContext.resourcePath,
options.compilerOptions
)
const script = resolveScript(
descriptor,
query.id as string,
Expand Down

0 comments on commit 82f047d

Please sign in to comment.