feat: simple compiler for wcsc module

This commit is contained in:
msojocs 2024-07-07 15:52:35 +08:00
parent 194d0151f6
commit 685d6e10c0
7 changed files with 563 additions and 10 deletions

View File

@ -17,6 +17,11 @@ namespace wcc_options
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("Failed to get '" + std::string(property_name) + "' property").c_str(), v8::NewStringType::kNormal).ToLocalChecked());
return false;
}
if (value->IsUndefined())
{
out_value = false;
return true;
}
if (!value->IsBoolean())
{
isolate->ThrowException(v8::String::NewFromUtf8(isolate, ("The '" + std::string(property_name) + "' property must be a boolean").c_str(), v8::NewStringType::kNormal).ToLocalChecked());

View File

@ -36,13 +36,18 @@ int compile(Isolate *isolate, WCSCOptions &options, Local<Value> &result,
v77[options.files[i]] = options.contents[i];
}
std::string v76 = "./app.wxss";
std::vector<std::string> v72;
std::string v75;
for (int i=0; i<options.pageCount; i++) {
v72.push_back(options.files[i]);
}
if (options.lazyload) {
// 懒加载
std::string v96;
std::string v94, v75;
std::string v94;
WXSS::XCompiler lt(v77, options.debug, v75);
// lt.offset_136.erase()
// lt.offset_136.erase()
@ -50,10 +55,6 @@ int compile(Isolate *isolate, WCSCOptions &options, Local<Value> &result,
v96.assign(lt.offset_8);
std::map<std::string, std::string> v92;
if (!lt.offset_0) {
std::vector<std::string> v72;
for (int i=0; i<options.pageCount; i++) {
v72.push_back(options.files[i]);
}
int ret = lt.GetCommHead(v72, v94, true, v76);
if (ret) {
fprintf(stderr, "ERR: GetCommHead ret %d", ret);
@ -113,6 +114,13 @@ int compile(Isolate *isolate, WCSCOptions &options, Local<Value> &result,
return 1;
} else {
// 普通
std::string v88;
int ret = WXSS::NewLintAndParseCSSList(v77, v72, v88, errMsg, 0, options.debug, v75, v76);
if (ret)
{
return 1;
}
result = String::NewFromUtf8(isolate, v88.c_str(), NewStringType::kNormal).ToLocalChecked();
}
return 0;
}

View File

@ -295,6 +295,7 @@ int main(int argc, const char **argv) {
// main - 40
if (v36)
{
// lazyload
goto LABEL_102;
}
int v25 = WXSS::NewLintAndParseCSSList(v77, v72, v88, errMsg, 0, v37, v75, v76);

View File

@ -34,7 +34,8 @@ const wcscNative = (optionsPath: string, projectPath: string, outputPath: string
if (0 === n) {
let result = Buffer.concat(spwanData).toString();
result = result.split('---------------result------------------\n')[1]
if (result[0] === '{')
const options = JSON.parse(fs.readFileSync(optionsPath).toString())
if (options.lazyloadConfig || options.lazyload)
result = JSON.parse(result);
resolve(result);
} else {

View File

@ -25,8 +25,8 @@ describe("wcc - module", function () {
const w = await windows.wcc(p);
const n = await linux.wcc(p, '');
console.log('windows:', typeof w)
console.log('linux:', typeof n)
// console.log('windows:', typeof w)
// console.log('linux:', typeof n)
assert.equal(typeof n, typeof w);
if (typeof w == 'string')

File diff suppressed because one or more lines are too long

View File

@ -24,9 +24,49 @@ describe("wcsc - module", function () {
} catch (error) {}
const w = await windows.wcsc(p);
console.log('windows:', typeof w)
// console.log('windows:', typeof w)
const n = await linux.wcsc(p, storagePath);
// console.log('linux:', typeof n)
assert.equal(typeof n, typeof w);
if (typeof w == 'string')
{
fs.writeFileSync(
`${storagePath}/wine-output.json`,
w
);
fs.writeFileSync(
`${storagePath}/node-output.json`,
n as string
);
assert.equal(n, w);
}
else
{
fs.writeFileSync(
`${storagePath}/wine-output.json`,
JSON.stringify(w, null, 4)
);
fs.writeFileSync(
`${storagePath}/node-output.json`,
JSON.stringify(n, null, 4)
);
assert.deepEqual(n, w);
}
});
it("初次加载2", async function () {
const p = path.resolve(__dirname, './data/1720337273873-wcsc-options.json')
const storagePath = path.resolve(
__dirname,
`miniprogram-demo/${this.test?.title}`
);
try {
fs.mkdirSync(storagePath, { recursive: true });
} catch (error) {}
const w = await windows.wcsc(p);
// console.log('windows:', typeof w)
const n = await linux.wcsc(p, '');
console.log('linux:', typeof n)
// console.log('linux:', typeof n)
assert.equal(typeof n, typeof w);
if (typeof w == 'string')