Skip to content

Commit 78f752b

Browse files
pezeyndu13
authored andcommitted
fix the expr check in tmp vars
1 parent 69f9ea3 commit 78f752b

File tree

10 files changed

+71
-12
lines changed

10 files changed

+71
-12
lines changed

lib/semantic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ class TypeChecker {
16851685
}
16861686

16871687
if (isTmpVariable(id.type)) {
1688+
this.visitExpr(id, env);
16881689
return;
16891690
}
16901691

@@ -2345,7 +2346,6 @@ class TypeChecker {
23452346
if (ast.left.type === 'static_or_instance_call') {
23462347
const id = ast.left.id;
23472348
this.checkId(id, env);
2348-
23492349
if (env.local.hasDefined(id.lexeme) || isTmpVariable(id.type)) {
23502350
ast.left.type = 'instance_call';
23512351
this.visitInstanceCall(ast, env);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@darabonba/parser",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"main": "index.js",
55
"directories": {
66
"lib": "lib",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"alibabacloud:OSS:*": "libraries/alibabacloud-OSS-0.0.1"
3+
}

test/fixtures/tmp_var_call/Darafile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
{
2-
}
2+
"libraries": {
3+
"OSS": "alibabacloud:OSS:*"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "OSS",
3+
"main": "./oss.dara"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
model Config {
2+
accessKeyId: string
3+
};
4+
5+
init(config: Config);
6+
7+
function getAccessKeyId(): string;
8+
9+
static function accessKeyId(): string;

test/fixtures/tmp_var_call/main.dara

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import OSS;
2+
13
init(){
4+
var config = new OSS.Config{};
5+
var oss = new OSS(config);
26
var arr = 'str.abc'.split('.');
7+
var arr2 = `str.${OSS.accessKeyId()}.${oss.getAccessKeyId()}.abc`.split('.');
38
var str = ['1','2','3'].join('.');
49
var num = 1.parseLong();
510
var en = {

test/import.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ function callOSS(): string {
254254
expect(function () {
255255
readAndParse('fixtures/import_module_model/undefined_model.dara');
256256
}).to.throwException(function (e) {
257-
console.log(e);
258257
expect(e).to.be.a(SyntaxError);
259258
expect(e.message).to.be(`the model "ConfigX" is undefined in module "OSS"`);
260259
});

test/parser.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6053,7 +6053,6 @@ describe('parser', function () {
60536053
}
60546054
`, '__filename');
60556055
}).to.throwException(function(e) {
6056-
console.log(e);
60576056
expect(e).to.be.a(SyntaxError);
60586057
expect(e.message).to.be('Unexpected token: Word: `catch`. expect valid expression');
60596058
});
@@ -9898,7 +9897,6 @@ describe('parser', function () {
98989897
var str = 'tmpVar'.empty();
98999898
}
99009899
`, '__filename');
9901-
console.log('%j', ast);
99029900
const expr = ast.moduleBody.nodes[0].initBody.stmts[0].expr;
99039901
expect(expr).to.be.eql({
99049902
'type': 'call',

test/semantic.test.js

+44-6
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,6 @@ describe('semantic', function () {
30793079
30803080
}`, '__filename');
30813081
}).to.throwError(function(e) {
3082-
console.log(e);
30833082
expect(e).to.be.an(SyntaxError);
30843083
expect(e.message).to.be('the property "statusCode" is undefined in model "Error"');
30853084
});
@@ -4691,7 +4690,6 @@ describe('semantic', function () {
46914690

46924691
it('used exceptions should ok', function () {
46934692
let ast = readAndParse('fixtures/module_exception_used/main.dara');
4694-
console.log(ast.usedExternException);
46954693
expect(ast.usedExternException.get('OSS').has('Err1')).to.be(true);
46964694
expect(ast.usedExternException.get('OSS').has('Config')).to.be(false);
46974695

@@ -7692,8 +7690,48 @@ init() {
76927690
});
76937691

76947692
it('use tmp variable method call shoule be ok', function(){
7695-
expect(function () {
7696-
readAndParse('fixtures/tmp_var_call/main.dara');
7697-
}).to.not.throwException();
7693+
const ast = readAndParse('fixtures/tmp_var_call/main.dara');
7694+
let tStrAst = ast.moduleBody.nodes[0].initBody.stmts[3];
7695+
expect(tStrAst.expr.left.id.elements[1].expr.left).to.be.eql({
7696+
'type': 'static_call',
7697+
'id': {
7698+
'tag': 2,
7699+
'loc': loc(7, 21, 7, 24),
7700+
'lexeme': 'OSS',
7701+
'index': 41,
7702+
'type': 'module'
7703+
},
7704+
'propertyPath': [
7705+
{
7706+
'tag': 2,
7707+
'loc': loc(7, 25, 7, 36),
7708+
'lexeme': 'accessKeyId',
7709+
'index': 43
7710+
}
7711+
]
7712+
});
7713+
7714+
expect(tStrAst.expr.left.id.elements[3].expr.left).to.be.eql({
7715+
'type': 'instance_call',
7716+
'id': {
7717+
'tag': 2,
7718+
'loc': loc(7, 42, 7, 45),
7719+
'lexeme': 'oss',
7720+
'index': 47,
7721+
'type': 'variable',
7722+
'moduleType': {
7723+
'type': 'module',
7724+
'name': 'OSS'
7725+
}
7726+
},
7727+
'propertyPath': [
7728+
{
7729+
'tag': 2,
7730+
'loc': loc(7, 46, 7, 60),
7731+
'lexeme': 'getAccessKeyId',
7732+
'index': 49
7733+
}
7734+
]
7735+
});
76987736
});
7699-
});
7737+
});

0 commit comments

Comments
 (0)