Skip to content
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

Expressions don't pass through when they are optional properties #12

Open
avin-kavish opened this issue Aug 23, 2022 · 1 comment
Open

Comments

@avin-kavish
Copy link

avin-kavish commented Aug 23, 2022

class SomeA {
  foo(expr?: Expression<() => number>) {}

  bar(expr?: Expression<() => number>) {
    this.foo(expr)
  }
}

new SomeA().bar(() => 10)

foo method gets identifier as the expression. Without the question mark, works as expected.

@Hookyns
Copy link
Owner

Hookyns commented Aug 24, 2022

It works as expected. Can you create a repro?

EDIT:
Hmm.. I'm wordering... You have both the tst-expression and the tst-reflect installed, right? Maybe they have some conflict..
/EDIT

What I tried:

import {
	Expression,
	assertExpression,
	assertArrowFunctionExpression,
	assertNumericLiteral
} from "tst-expression";

class SomeA {
	foo(expr?: Expression<() => number>) {
		if (!expr) {
			return;
		}
		
		assertExpression(expr);
		assertArrowFunctionExpression(expr.expression);
		
		console.log("# parameters:", expr.expression.parameters.length);
		
		assertNumericLiteral(expr.expression.body);
		console.log("number in body:", Number(expr.expression.body.text));
	}

	bar(expr?: Expression<() => number>) {
		this.foo(expr)
	}
}

new SomeA().bar(() => 10);

Transpiled code:

import {assertExpression, assertArrowFunctionExpression, assertNumericLiteral} from "tst-expression";

class SomeA {
    foo(expr) {
        if (!expr) {
            return;
        }
        assertExpression(expr);
        assertArrowFunctionExpression(expr.expression);
        console.log("# parameters:", expr.expression.parameters.length);
        assertNumericLiteral(expr.expression.body);
        console.log("number in body:", Number(expr.expression.body.text));
    }

    bar(expr) {
        this.foo(expr);
    }
}

new SomeA().bar({
    compiled: () => 10,
    context: {},
    expression: {
        "flags": 256,
        "kind": 212,
        "locals": {},
        "parameters": [],
        "body": {
            "flags": 0,
            "kind": 8,
            "text": "10",
            "numericLiteralFlags": 0
        },
        "equalsGreaterThanToken": {
            "flags": 0,
            "kind": 38
        },
        "endFlowNode": {"flags": 2}
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants