Skip to content

Fix env builtin #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Env extends Builtin {
const key = args[0];
this.generator.emit(`${this.module }[`);
this.generator.visitExpr(key);
this.generator.emit('];');
this.generator.emit(']');
}

set(args){
Expand All @@ -59,7 +59,6 @@ class Env extends Builtin {
this.generator.emit('] = ');
const value = args[1];
this.generator.visitExpr(value);
this.generator.emit(';');
}
}

Expand Down
10 changes: 6 additions & 4 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,9 @@ Client.main(process.argv.slice(2));`);
const models = [...usedModels.get(aliasId)];
if (models.length > 0) {
this.emit(`, $${inner}`, level);
}
if(inner !== aliasId) {
this.emit(` as $${aliasId}`);
if(inner !== aliasId) {
this.emit(` as $${aliasId}`);
}
}
this.emit(' }');
} else {
Expand Down Expand Up @@ -1165,7 +1165,7 @@ Client.main(process.argv.slice(2));`);
continue;
}
if(fieldName === 'name') {
this.emit(`this.name = "${exceptionName}Error";\n`, level);
continue;
}
this.emit(`this.${fieldName} = map.${fieldName};\n`, level);
}
Expand All @@ -1179,6 +1179,8 @@ Client.main(process.argv.slice(2));`);
this.emit(`\n`);
this.emit(`constructor(map?: { [key: string]: any }) {\n`, level + 1);
this.emit(`super(map);\n`, level + 2);
this.emit(`this.name = "${exceptionName}Error";\n`, level + 2);
this.emit(`Object.setPrototypeOf(this, ${exceptionName}Error.prototype);\n`, level + 2);
this.visitEcxceptionConstrutor(exceptionBody, exceptionName, level + 2);
this.emit(`}\n`, level + 1);
this.emit('}\n\n', level);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"dependencies": {
"@darabonba/annotation-parser": "^1.0.0",
"@darabonba/parser": "^2.0.5"
"@darabonba/parser": "^2.1.3"
},
"devDependencies": {
"eslint": "^6.5.1",
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/builtin/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export default class Client {
}

static async envTest(args: string[]): Promise<void> {
let es = process.env["TEST"];;
let ma = process.env["TEST"] = es + "test";;
let es = process.env["TEST"];
let ma = process.env["TEST"] = es + "test";
}

static async fileTest(args: string[]): Promise<void> {
Expand Down Expand Up @@ -116,8 +116,8 @@ export default class Client {
}

static async logerTest(args: string[]): Promise<void> {
console.info(`test:${args[0]}`);
console.log("test");
console.info("test");
console.warn("test");
console.debug("test");
console.error("test");
Expand Down Expand Up @@ -323,7 +323,7 @@ export default class Client {

}

$dara.sleep(a);
await $dara.sleep(a);
let defaultVal = args[0] || args[1];
if (defaultVal === b) {
return ;
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/builtin/main.dara
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static async function jsonTest(args: [string]): void {
}

static async function logerTest(args: [string]): void {
$Logger.info(`test:${args[0]}`);
$Logger.log("test");
$Logger.info("test");
$Logger.warning("test");
$Logger.debug("test");
$Logger.error("test");
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/complex/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ export class Err1Error extends $dara.BaseError {

constructor(map?: { [key: string]: any }) {
super(map);
this.name = "Err1Error";
Object.setPrototypeOf(this, Err1Error.prototype);
this.data = map.data;
}
}
Expand All @@ -224,6 +226,8 @@ export class Err2Error extends $dara.BaseError {

constructor(map?: { [key: string]: any }) {
super(map);
this.name = "Err2Error";
Object.setPrototypeOf(this, Err2Error.prototype);
this.accessErrMessage = map.accessErrMessage;
}
}
Expand Down
Loading