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

wip(uts): compiler

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