Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 16, 2020
1 parent 20f79f1 commit e2faa2d
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,21 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
if (preprocessLang) {
preprocessOptions =
preprocessOptions[preprocessLang] || preprocessOptions

if (
['scss', 'sass'].includes(preprocessLang) &&
!preprocessOptions.includePaths
) {
preprocessOptions = {
includePaths: ['node_modules'],
...preprocessOptions,
}
// include node_modules for imports by default
switch (preprocessLang) {
case 'scss':
case 'sass':
preprocessOptions = {
includePaths: ['node_modules'],
...preprocessOptions,
}
break
case 'less':
case 'stylus':
preprocessOptions = {
paths: ['node_modules'],
...preprocessOptions,
}
}
} else {
preprocessOptions = {}
Expand Down Expand Up @@ -368,20 +374,14 @@ function getDescriptor(id: string) {
throw new Error(`${id} is not parsed yet`)
}

function parseSFC(
code: string,
id: string,
sourceRoot: string
): { descriptor: SFCDescriptor; errors: CompilerError[] } {
function parseSFC(code: string, id: string, sourceRoot: string) {
const { descriptor, errors } = parse(code, {
sourceMap: true,
filename: id,
sourceRoot: sourceRoot,
})

cache.set(id, descriptor)

return { descriptor, errors }
return { descriptor, errors: errors }
}

function transformVueSFC(
Expand Down Expand Up @@ -558,21 +558,33 @@ function getCustomBlock(
return code
}

function createRollupError(id: string, error: CompilerError): RollupError {
return {
id,
plugin: 'vue',
pluginCode: String(error.code),
message: error.message,
frame: error.loc!.source,
parserError: error,
loc: error.loc
? {
file: id,
line: error.loc.start.line,
column: error.loc.start.column,
}
: undefined,
function createRollupError(
id: string,
error: CompilerError | SyntaxError
): RollupError {
if ('code' in error) {
return {
id,
plugin: 'vue',
pluginCode: String(error.code),
message: error.message,
frame: error.loc!.source,
parserError: error,
loc: error.loc
? {
file: id,
line: error.loc.start.line,
column: error.loc.start.column,
}
: undefined,
}
} else {
return {
id,
plugin: 'vue',
message: error.message,
parserError: error,
}
}
}

Expand Down

0 comments on commit e2faa2d

Please sign in to comment.