wip: relay compiler-core warnings in compiler-sfc with codeframe
This commit is contained in:
parent
7f93c76b96
commit
c32760147c
@ -18,7 +18,7 @@ import {
|
|||||||
transformSrcset,
|
transformSrcset,
|
||||||
createSrcsetTransformWithOptions
|
createSrcsetTransformWithOptions
|
||||||
} from './templateTransformSrcset'
|
} from './templateTransformSrcset'
|
||||||
import { isObject } from '@vue/shared'
|
import { generateCodeFrame, isObject } from '@vue/shared'
|
||||||
import * as CompilerDOM from '@vue/compiler-dom'
|
import * as CompilerDOM from '@vue/compiler-dom'
|
||||||
import * as CompilerSSR from '@vue/compiler-ssr'
|
import * as CompilerSSR from '@vue/compiler-ssr'
|
||||||
import consolidate from 'consolidate'
|
import consolidate from 'consolidate'
|
||||||
@ -170,6 +170,7 @@ function doCompileTemplate({
|
|||||||
transformAssetUrls
|
transformAssetUrls
|
||||||
}: SFCTemplateCompileOptions): SFCTemplateCompileResults {
|
}: SFCTemplateCompileOptions): SFCTemplateCompileResults {
|
||||||
const errors: CompilerError[] = []
|
const errors: CompilerError[] = []
|
||||||
|
const warnings: CompilerError[] = []
|
||||||
|
|
||||||
let nodeTransforms: NodeTransform[] = []
|
let nodeTransforms: NodeTransform[] = []
|
||||||
if (isObject(transformAssetUrls)) {
|
if (isObject(transformAssetUrls)) {
|
||||||
@ -211,7 +212,8 @@ function doCompileTemplate({
|
|||||||
nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
|
nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
|
||||||
filename,
|
filename,
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
onError: e => errors.push(e)
|
onError: e => errors.push(e),
|
||||||
|
onWarn: w => warnings.push(w)
|
||||||
})
|
})
|
||||||
|
|
||||||
// inMap should be the map produced by ./parse.ts which is a simple line-only
|
// inMap should be the map produced by ./parse.ts which is a simple line-only
|
||||||
@ -226,7 +228,19 @@ function doCompileTemplate({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { code, ast, preamble, source, errors, tips: [], map }
|
const tips = warnings.map(w => {
|
||||||
|
let msg = w.message
|
||||||
|
if (w.loc) {
|
||||||
|
msg += `\n${generateCodeFrame(
|
||||||
|
source,
|
||||||
|
w.loc.start.offset,
|
||||||
|
w.loc.end.offset
|
||||||
|
)}`
|
||||||
|
}
|
||||||
|
return msg
|
||||||
|
})
|
||||||
|
|
||||||
|
return { code, ast, preamble, source, errors, tips, map }
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapLines(oldMap: RawSourceMap, newMap: RawSourceMap): RawSourceMap {
|
function mapLines(oldMap: RawSourceMap, newMap: RawSourceMap): RawSourceMap {
|
||||||
|
Loading…
Reference in New Issue
Block a user