提交 521b922e 编写于 作者: fxy060608's avatar fxy060608

wip(uts): compiler

上级 312fc516
......@@ -24,6 +24,7 @@ const DEFAULT_KEYS = [
'QUICKAPP_WEBVIEW_UNION',
'VUE2',
'VUE3',
'WEB',
] as const
const preVueContext = Object.create(null)
......@@ -75,6 +76,8 @@ export function initPreContext(
defaultContext.MP = true
} else if (platform.startsWith('quickapp-webview')) {
defaultContext.QUICKAPP_WEBVIEW = true
} else if (platform === 'h5') {
defaultContext.WEB = true
}
if (userPreContext) {
......
......@@ -148,7 +148,7 @@ export function resolveUtsModule(
platform
)
// App平台仅支持 uts
if (platform === 'app-android' || platform === 'app-ios') {
if (platform === 'app-android') {
return resolveUtsFile(platformDir, ['.uts'])
}
return resolveUtsFile(platformDir)
......
......@@ -3617,7 +3617,7 @@ function stacktracey(stacktrace, opts) {
return parseSourceMapContent(consumer, {
line,
column,
});
}, !!opts.withSourceContent);
});
}
});
......@@ -3625,7 +3625,7 @@ function stacktracey(stacktrace, opts) {
try {
return _getSourceMapContent(file, fileName, fileRelative).then((sourceMapContent) => {
if (sourceMapContent) {
const { source, sourcePath, sourceLine, sourceColumn, fileName = '', } = sourceMapContent;
const { source, sourcePath, sourceLine, sourceColumn, sourceContent, fileName = '', } = sourceMapContent;
stack.items[index] = Object.assign({}, item, {
file: source,
line: sourceLine,
......@@ -3635,6 +3635,7 @@ function stacktracey(stacktrace, opts) {
fileName,
thirdParty: isThirdParty(sourcePath),
parsed: true,
sourceContent,
});
/**
* 以 .js 结尾
......@@ -3739,7 +3740,7 @@ function getSourceMapContent(sourcemapUrl) {
return '';
}
}
function parseSourceMapContent(consumer, obj) {
function parseSourceMapContent(consumer, obj, withSourceContent) {
// source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
const { source, line: sourceLine, column: sourceColumn, } = consumer.originalPositionFor(obj);
if (source) {
......@@ -3752,6 +3753,9 @@ function parseSourceMapContent(consumer, obj) {
sourceLine: sourceLine === null ? 0 : sourceLine,
sourceColumn: sourceColumn === null ? 0 : sourceColumn,
fileName,
sourceContent: withSourceContent
? consumer.sourceContentFor(source) || ''
: '',
};
}
}
......
......@@ -3611,7 +3611,7 @@ function stacktracey(stacktrace, opts) {
return parseSourceMapContent(consumer, {
line,
column,
});
}, !!opts.withSourceContent);
});
}
});
......@@ -3619,7 +3619,7 @@ function stacktracey(stacktrace, opts) {
try {
return _getSourceMapContent(file, fileName, fileRelative).then((sourceMapContent) => {
if (sourceMapContent) {
const { source, sourcePath, sourceLine, sourceColumn, fileName = '', } = sourceMapContent;
const { source, sourcePath, sourceLine, sourceColumn, sourceContent, fileName = '', } = sourceMapContent;
stack.items[index] = Object.assign({}, item, {
file: source,
line: sourceLine,
......@@ -3629,6 +3629,7 @@ function stacktracey(stacktrace, opts) {
fileName,
thirdParty: isThirdParty(sourcePath),
parsed: true,
sourceContent,
});
/**
* 以 .js 结尾
......@@ -3733,7 +3734,7 @@ function getSourceMapContent(sourcemapUrl) {
return '';
}
}
function parseSourceMapContent(consumer, obj) {
function parseSourceMapContent(consumer, obj, withSourceContent) {
// source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
const { source, line: sourceLine, column: sourceColumn, } = consumer.originalPositionFor(obj);
if (source) {
......@@ -3746,6 +3747,9 @@ function parseSourceMapContent(consumer, obj) {
sourceLine: sourceLine === null ? 0 : sourceLine,
sourceColumn: sourceColumn === null ? 0 : sourceColumn,
fileName,
sourceContent: withSourceContent
? consumer.sourceContentFor(source) || ''
: '',
};
}
}
......
......@@ -25,6 +25,7 @@ const sourcemapCatch: Record<string, string | Promise<string>> = {}
type StacktraceyItems = StackTracey.Entry & {
errMsg?: string
sourceContent?: string
}
type Stacktracey = {
items: StacktraceyItems[]
......@@ -74,6 +75,7 @@ interface StacktraceyPreset {
interface StacktraceyOptions {
preset: StacktraceyPreset
withSourceContent?: boolean
}
export function stacktracey(
......@@ -106,10 +108,14 @@ export function stacktracey(
.then((content) => {
if (content) {
return getConsumer(content).then((consumer) => {
return parseSourceMapContent(consumer, {
line,
column,
})
return parseSourceMapContent(
consumer,
{
line,
column,
},
!!opts.withSourceContent
)
})
}
})
......@@ -124,6 +130,7 @@ export function stacktracey(
sourcePath,
sourceLine,
sourceColumn,
sourceContent,
fileName = '',
} = sourceMapContent
......@@ -136,6 +143,7 @@ export function stacktracey(
fileName,
thirdParty: isThirdParty(sourcePath),
parsed: true,
sourceContent,
})
/**
......@@ -258,11 +266,13 @@ type SourceMapContent = {
sourcePath: string
sourceLine: number
sourceColumn: number
fileName: string | undefined
sourceContent?: string
fileName?: string
}
function parseSourceMapContent(
consumer: BasicSourceMapConsumer | IndexedSourceMapConsumer,
obj: Position
obj: Position,
withSourceContent: boolean
): SourceMapContent | undefined {
// source -> 'uni-app:///node_modules/@sentry/browser/esm/helpers.js'
const {
......@@ -281,6 +291,9 @@ function parseSourceMapContent(
sourceLine: sourceLine === null ? 0 : sourceLine,
sourceColumn: sourceColumn === null ? 0 : sourceColumn,
fileName,
sourceContent: withSourceContent
? consumer.sourceContentFor(source) || ''
: '',
}
}
}
......
......@@ -28,6 +28,10 @@ export function uniUtsV1Plugin(): Plugin {
if (opts && opts.ssr) {
return
}
// 目前仅支持app-android
if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
return
}
const { filename } = parseVueRequest(id)
if (path.extname(filename) !== '.uts') {
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册