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

wip(uts): compiler

上级 d2694b7c
......@@ -10,20 +10,7 @@ at uni_modules/test-uts1/utssdk/index.uts:2:10
4 |
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 50s"
FAILURE: Build failed with an exception."
`;
exports[`code-frame-uts android 2`] = `
......@@ -36,18 +23,27 @@ at utssdk/test2/index.uts:2:10
4 |
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'.
> Compilation error. See log for more details
FAILURE: Build failed with an exception."
`;
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
exports[`code-frame-uts ios 1`] = `
"CompileSwift normal armv7 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS')
error: cannot convert return expression of type 'Int' to return type 'String'
at uni_modules/test-uts1/utssdk/app-ios/index.uts:2:10
1 | export function test(): string {
2 | return 1;
| ^
3 | }
4 |
* Get more help at https://help.gradle.org
BUILD FAILED in 50s"
CompileSwift normal arm64 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS')
error: cannot convert return expression of type 'Int' to return type 'String'
at uni_modules/test-uts1/utssdk/app-ios/index.uts:2:10
1 | export function test(): string {
2 | return 1;
| ^
3 | }
4 |
"
`;
import path from 'path'
const {
generateCodeFrameWithAndroidStacktrace,
generateCodeFrameWithKotlinStacktrace,
generateCodeFrameWithSwiftStacktrace,
} = require('../dist/uni-stacktracey.cjs.js')
const utsProjectDir = path.resolve(__dirname, '../test/uts')
......@@ -9,52 +10,41 @@ const utsProjectDir = path.resolve(__dirname, '../test/uts')
describe('code-frame-uts', () => {
test('android', async () => {
expect(
await generateCodeFrameWithAndroidStacktrace(androidUniModulesError, {
await generateCodeFrameWithKotlinStacktrace(androidUniModulesError, {
name: 'uni_modules/test-uts1',
inputDir: '/Users/fxy/DCloud/test-uts',
outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'),
})
).toMatchSnapshot()
expect(
await generateCodeFrameWithAndroidStacktrace(androidUtssdkError, {
await generateCodeFrameWithKotlinStacktrace(androidUtssdkError, {
name: 'utssdk/test2',
inputDir: '/Users/fxy/DCloud/test-uts',
outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'),
})
).toMatchSnapshot()
})
test('ios', async () => {
expect(
await generateCodeFrameWithSwiftStacktrace(iosUniModulesError, {
name: 'uni_modules/test-uts1',
inputDir: '/Users/fxy/DCloud/test-uts',
outputDir: path.resolve(utsProjectDir, 'unpackage/dist/dev/app-plus'),
})
).toMatchSnapshot()
})
})
const androidUniModulesError = `e: uni_modules/test-uts1/utssdk/app-android/index.kt: (8, 12): The integer literal does not conform to the expected type String
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 50s`
FAILURE: Build failed with an exception.`
const androidUtssdkError = `e: utssdk/test2/app-android/index.kt: (8, 12): The integer literal does not conform to the expected type String
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':uni_modules:test-uts1:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
FAILURE: Build failed with an exception.`
* Get more help at https://help.gradle.org
const iosUniModulesError = `CompileSwift normal armv7 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS')
uni_modules/test-uts1/utssdk/app-ios/src/index.swift:3:12: error: cannot convert return expression of type 'Int' to return type 'String'
BUILD FAILED in 50s`
CompileSwift normal arm64 uni_modules/test-uts1/utssdk/app-ios/src/index.swift (in target 'uni_modules_test_uts1' from project 'UTS')
uni_modules/test-uts1/utssdk/app-ios/src/index.swift:3:12: error: cannot convert return expression of type 'Int' to return type 'String'`
......@@ -3712,13 +3712,20 @@ function resolveSourceMapPath(sourceMapFilename, name, outputDir) {
const is_uni_modules = path__default["default"].basename(path__default["default"].dirname(name)) === 'uni_modules';
return path__default["default"].resolve(outputDir, '../.sourcemap/app', name, is_uni_modules ? 'utssdk' : '', sourceMapFilename);
}
function generateCodeFrameWithAndroidStacktrace(stacktrace, { name, inputDir, outputDir }) {
function generateCodeFrameWithKotlinStacktrace(stacktrace, { name, inputDir, outputDir }) {
const sourceMapFilename = resolveSourceMapPath('app-android/index.kt.map', name, outputDir);
return generateCodeFrameWithStacktrace(stacktrace, /e:\s+(.*):\s+\(([0-9]+),\s+([0-9]+)\):\s+(.*)/g, {
sourceRoot: inputDir,
sourceMapFilename,
});
}
function generateCodeFrameWithSwiftStacktrace(stacktrace, { name, inputDir, outputDir }) {
const sourceMapFilename = resolveSourceMapPath('app-ios/index.swift.map', name, outputDir);
return generateCodeFrameWithStacktrace(stacktrace, /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, {
sourceRoot: inputDir,
sourceMapFilename,
});
}
function generateCodeFrameWithStacktrace(stacktrace, regexp, { sourceRoot, sourceMapFilename, }) {
return new Promise((resolve) => {
initConsumer(sourceMapFilename).then((consumer) => {
......@@ -4070,8 +4077,9 @@ ${_stack.errMsg}`;
exports.SourceMapConsumer = SourceMapConsumer;
exports.generateCodeFrame = generateCodeFrame;
exports.generateCodeFrameSourceMapConsumer = generateCodeFrameSourceMapConsumer;
exports.generateCodeFrameWithAndroidStacktrace = generateCodeFrameWithAndroidStacktrace;
exports.generateCodeFrameWithKotlinStacktrace = generateCodeFrameWithKotlinStacktrace;
exports.generateCodeFrameWithSourceMapPath = generateCodeFrameWithSourceMapPath;
exports.generateCodeFrameWithSwiftStacktrace = generateCodeFrameWithSwiftStacktrace;
exports.stacktracey = stacktracey;
exports.uniStracktraceyPreset = uniStracktraceyPreset;
exports.utsStracktraceyPreset = utsStracktraceyPreset;
......@@ -3695,13 +3695,20 @@ function resolveSourceMapPath(sourceMapFilename, name, outputDir) {
const is_uni_modules = path.basename(path.dirname(name)) === 'uni_modules';
return path.resolve(outputDir, '../.sourcemap/app', name, is_uni_modules ? 'utssdk' : '', sourceMapFilename);
}
function generateCodeFrameWithAndroidStacktrace(stacktrace, { name, inputDir, outputDir }) {
function generateCodeFrameWithKotlinStacktrace(stacktrace, { name, inputDir, outputDir }) {
const sourceMapFilename = resolveSourceMapPath('app-android/index.kt.map', name, outputDir);
return generateCodeFrameWithStacktrace(stacktrace, /e:\s+(.*):\s+\(([0-9]+),\s+([0-9]+)\):\s+(.*)/g, {
sourceRoot: inputDir,
sourceMapFilename,
});
}
function generateCodeFrameWithSwiftStacktrace(stacktrace, { name, inputDir, outputDir }) {
const sourceMapFilename = resolveSourceMapPath('app-ios/index.swift.map', name, outputDir);
return generateCodeFrameWithStacktrace(stacktrace, /(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g, {
sourceRoot: inputDir,
sourceMapFilename,
});
}
function generateCodeFrameWithStacktrace(stacktrace, regexp, { sourceRoot, sourceMapFilename, }) {
return new Promise((resolve) => {
initConsumer(sourceMapFilename).then((consumer) => {
......@@ -4060,4 +4067,4 @@ ${_stack.errMsg}`;
};
}
export { SourceMapConsumer, generateCodeFrame, generateCodeFrameSourceMapConsumer, generateCodeFrameWithAndroidStacktrace, generateCodeFrameWithSourceMapPath, stacktracey, uniStracktraceyPreset, utsStracktraceyPreset };
export { SourceMapConsumer, generateCodeFrame, generateCodeFrameSourceMapConsumer, generateCodeFrameWithKotlinStacktrace, generateCodeFrameWithSourceMapPath, generateCodeFrameWithSwiftStacktrace, stacktracey, uniStracktraceyPreset, utsStracktraceyPreset };
......@@ -14,7 +14,8 @@ export {
generateCodeFrame,
generateCodeFrameSourceMapConsumer,
generateCodeFrameWithSourceMapPath,
generateCodeFrameWithAndroidStacktrace,
generateCodeFrameWithKotlinStacktrace,
generateCodeFrameWithSwiftStacktrace,
} from './utils'
// @ts-ignore
if (__PLATFORM_WEB__) {
......
......@@ -185,7 +185,7 @@ function resolveSourceMapPath(
)
}
export function generateCodeFrameWithAndroidStacktrace(
export function generateCodeFrameWithKotlinStacktrace(
stacktrace: string,
{ name, inputDir, outputDir }: GenerateCodeFrameWithStacktraceOptions
) {
......@@ -204,6 +204,25 @@ export function generateCodeFrameWithAndroidStacktrace(
)
}
export function generateCodeFrameWithSwiftStacktrace(
stacktrace: string,
{ name, inputDir, outputDir }: GenerateCodeFrameWithStacktraceOptions
) {
const sourceMapFilename = resolveSourceMapPath(
'app-ios/index.swift.map',
name,
outputDir
)
return generateCodeFrameWithStacktrace(
stacktrace,
/(.*):([0-9]+):([0-9]+):\s+error:\s+(.*)/g,
{
sourceRoot: inputDir,
sourceMapFilename,
}
)
}
function generateCodeFrameWithStacktrace(
stacktrace: string,
regexp: RegExp,
......
{"version":3,"sources":["/Users/fxy/DCloud/test-uts/uni_modules/test-uts1/utssdk/app-ios/index.uts"],"sourcesContent":["export function test(): string {\n return 1;\n}\n"],"names":[],"mappings":";AAAO,KAAS,UAAQ,MAAM,CAAC;IAC7B,OAAO,CAAC;AACV;;;;mCAFwB,MAAM;eAAd"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test/app-android/index.uts"],"sourcesContent":["export function test(): string {\n return 2;\n}\n"],"names":[],"mappings":";;;;;;AAAO,IAAS,QAAQ,MAAM,CAAC;IAC7B,OAAO,CAAC;AACV"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test/app-android/index.uts"],"sourcesContent":["export function test(): number {\n return 2.0.toFloat();\n}\n"],"names":[],"mappings":";;;;;;AAAO,IAAS,QAAQ,MAAM,CAAC;IAC7B,OAAO,GAAG,CAAC,OAAO;AACpB"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test/app-ios/index.uts"],"sourcesContent":["export function test(): number {\n return 1;\n}\n"],"names":[],"mappings":";AAAO,KAAS,UAAQ,QAAM,CAAC;IAC7B,OAAO,CAAC;AACV;;;;mCAFwB,QAAM;eAAd"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/DCloud/test-uts/utssdk/test2/index.uts"],"sourcesContent":["export function test(): string {\n return 2;\n}\n"],"names":[],"mappings":";AAAO,KAAS,UAAQ,MAAM,CAAC;IAC7B,OAAO,CAAC;AACV;;;;mCAFwB,MAAM;eAAd"}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册