How to use the @aurelia/runtime.Unary function in @aurelia/runtime

To help you get started, we’ve selected a few @aurelia/runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
// concatenation of Primary and Member+CallExpression
  // This forms the group Precedence.LeftHandSide
  // used only for testing complex Unary expressions
  const SimpleIsLeftHandSideList: [string, IsLeftHandSide][] = [
    ...PrimaryList,
    ...SimpleLeftHandSideList
  ];

  // parseUnaryExpression (this is actually at the top in the parser due to the order in which expressions must be parsed)
  const SimpleUnaryList: [string, Unary][] = [
    [`!$1`, new Unary('!', new AccessScope('$1'))],
    [`-$2`, new Unary('-', new AccessScope('$2'))],
    [`+$3`, new Unary('+', new AccessScope('$3'))],
    [`void $4`, new Unary('void', new AccessScope('$4'))],
    [`typeof $5`, new Unary('typeof', new AccessScope('$5'))]
  ];
  // concatenation of Unary + LeftHandSide
  // This forms the group Precedence.LeftHandSide and includes Precedence.Unary
  const SimpleIsUnaryList: [string, IsUnary][] = [
    ...SimpleIsLeftHandSideList,
    ...SimpleUnaryList
  ];

  // This forms the group Precedence.Multiplicative
  const SimpleMultiplicativeList: [string, Binary][] = [
    [`$6*$7`, new Binary('*', new AccessScope('$6'), new AccessScope('$7'))],
    [`$8%$9`, new Binary('%', new AccessScope('$8'), new AccessScope('$9'))],
    [`$10/$11`, new Binary('/', new AccessScope('$10'), new AccessScope('$11'))]
  ];
  const SimpleIsMultiplicativeList: [string, IsBinary][] = [
    ...SimpleIsUnaryList,
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
describe('performs \'typeof\'', function () {
    const tests: { expr: Unary; expected: string }[] = [
      { expr: new Unary('typeof', new PrimitiveLiteral('foo')), expected: 'string' },
      { expr: new Unary('typeof', new PrimitiveLiteral(1)), expected: 'number' },
      { expr: new Unary('typeof', $null), expected: 'object' },
      { expr: new Unary('typeof', $undefined), expected: 'undefined' },
      { expr: new Unary('typeof', $true), expected: 'boolean' },
      { expr: new Unary('typeof', $false), expected: 'boolean' },
      { expr: new Unary('typeof', $arr), expected: 'object' },
      { expr: new Unary('typeof', $obj), expected: 'object' },
      { expr: new Unary('typeof', $this), expected: 'object' },
      { expr: new Unary('typeof', $parent), expected: 'undefined' },
      { expr: new Unary('typeof', new AccessScope('foo', 0)), expected: 'undefined' }
    ];
    const scope: IScope = createScopeForTest({});

    for (const { expr, expected } of tests) {
      it(expr.toString(), function () {
        expect(expr.evaluate(LF.none, scope, null)).to.equal(expected);
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
describe('performs \'void\'', function () {
    const tests: { expr: Unary }[] = [
      { expr: new Unary('void', new PrimitiveLiteral('foo')) },
      { expr: new Unary('void', new PrimitiveLiteral(1)) },
      { expr: new Unary('void', $null) },
      { expr: new Unary('void', $undefined) },
      { expr: new Unary('void', $true) },
      { expr: new Unary('void', $false) },
      { expr: new Unary('void', $arr) },
      { expr: new Unary('void', $obj) },
      { expr: new Unary('void', $this) },
      { expr: new Unary('void', $parent) },
      { expr: new Unary('void', new AccessScope('foo', 0)) }
    ];
    let scope: IScope = createScopeForTest({});

    for (const { expr } of tests) {
      it(expr.toString(), function () {
        expect(expr.evaluate(LF.none, scope, null)).to.equal(undefined);
      });
    }
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
describe('performs \'typeof\'', function () {
    const tests: { expr: Unary; expected: string }[] = [
      { expr: new Unary('typeof', new PrimitiveLiteral('foo')), expected: 'string' },
      { expr: new Unary('typeof', new PrimitiveLiteral(1)), expected: 'number' },
      { expr: new Unary('typeof', $null), expected: 'object' },
      { expr: new Unary('typeof', $undefined), expected: 'undefined' },
      { expr: new Unary('typeof', $true), expected: 'boolean' },
      { expr: new Unary('typeof', $false), expected: 'boolean' },
      { expr: new Unary('typeof', $arr), expected: 'object' },
      { expr: new Unary('typeof', $obj), expected: 'object' },
      { expr: new Unary('typeof', $this), expected: 'object' },
      { expr: new Unary('typeof', $parent), expected: 'undefined' },
      { expr: new Unary('typeof', new AccessScope('foo', 0)), expected: 'undefined' }
    ];
    const scope: IScope = createScopeForTest({});

    for (const { expr, expected } of tests) {
      it(expr.toString(), function () {
        expect(expr.evaluate(LF.none, scope, null)).to.equal(expected);
      });
    }
  });
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('isPureLiteral', function () {
    expect(isPureLiteral(new AccessThis()                )).to.equal(false);
    expect(isPureLiteral(new AccessScope('')             )).to.equal(false);
    expect(isPureLiteral(new ArrayLiteral([])            )).to.equal(true);
    expect(isPureLiteral(new ObjectLiteral([], [])       )).to.equal(true);
    expect(isPureLiteral(new PrimitiveLiteral('')        )).to.equal(true);
    expect(isPureLiteral(new Template([])                )).to.equal(true);
    expect(isPureLiteral(new Unary('!', e)               )).to.equal(false);
    expect(isPureLiteral(new CallScope('!', [])          )).to.equal(false);
    expect(isPureLiteral(new CallMember(e, '', [])       )).to.equal(false);
    expect(isPureLiteral(new CallFunction(e, [])         )).to.equal(false);
    expect(isPureLiteral(new AccessMember(e, '')         )).to.equal(false);
    expect(isPureLiteral(new AccessKeyed(e, e)           )).to.equal(false);
    expect(isPureLiteral(new TaggedTemplate([], [], e)   )).to.equal(false);
    expect(isPureLiteral(new Binary('+', e, e)           )).to.equal(false);
    expect(isPureLiteral(new Conditional(e, e, e)        )).to.equal(false);
    expect(isPureLiteral(new Assign(e, e)                )).to.equal(false);
    expect(isPureLiteral(new ValueConverter(e, '', [])   )).to.equal(false);
    expect(isPureLiteral(new BindingBehavior(e, '', [])  )).to.equal(false);
    expect(isPureLiteral(new HtmlLiteral([])             )).to.equal(false);
    expect(isPureLiteral(new ArrayBindingPattern([])     )).to.equal(false);
    expect(isPureLiteral(new ObjectBindingPattern([], []))).to.equal(false);
    expect(isPureLiteral(new BindingIdentifier('')       )).to.equal(false);
    expect(isPureLiteral(new ForOfStatement(e, e)        )).to.equal(false);
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('isResource', function () {
    expect(isResource(new AccessThis()                )).to.equal(false);
    expect(isResource(new AccessScope('')             )).to.equal(false);
    expect(isResource(new ArrayLiteral([])            )).to.equal(false);
    expect(isResource(new ObjectLiteral([], [])       )).to.equal(false);
    expect(isResource(new PrimitiveLiteral('')        )).to.equal(false);
    expect(isResource(new Template([])                )).to.equal(false);
    expect(isResource(new Unary('!', e)               )).to.equal(false);
    expect(isResource(new CallScope('!', [])          )).to.equal(false);
    expect(isResource(new CallMember(e, '', [])       )).to.equal(false);
    expect(isResource(new CallFunction(e, [])         )).to.equal(false);
    expect(isResource(new AccessMember(e, '')         )).to.equal(false);
    expect(isResource(new AccessKeyed(e, e)           )).to.equal(false);
    expect(isResource(new TaggedTemplate([], [], e)   )).to.equal(false);
    expect(isResource(new Binary('+', e, e)           )).to.equal(false);
    expect(isResource(new Conditional(e, e, e)        )).to.equal(false);
    expect(isResource(new Assign(e, e)                )).to.equal(false);
    expect(isResource(new ValueConverter(e, '', [])   )).to.equal(true);
    expect(isResource(new BindingBehavior(e, '', [])  )).to.equal(true);
    expect(isResource(new HtmlLiteral([])             )).to.equal(false);
    expect(isResource(new ArrayBindingPattern([])     )).to.equal(false);
    expect(isResource(new ObjectBindingPattern([], []))).to.equal(false);
    expect(isResource(new BindingIdentifier('')       )).to.equal(false);
    expect(isResource(new ForOfStatement(e, e)        )).to.equal(false);
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
describe('performs \'void\'', function () {
    const tests: { expr: Unary }[] = [
      { expr: new Unary('void', new PrimitiveLiteral('foo')) },
      { expr: new Unary('void', new PrimitiveLiteral(1)) },
      { expr: new Unary('void', $null) },
      { expr: new Unary('void', $undefined) },
      { expr: new Unary('void', $true) },
      { expr: new Unary('void', $false) },
      { expr: new Unary('void', $arr) },
      { expr: new Unary('void', $obj) },
      { expr: new Unary('void', $this) },
      { expr: new Unary('void', $parent) },
      { expr: new Unary('void', new AccessScope('foo', 0)) }
    ];
    let scope: IScope = createScopeForTest({});

    for (const { expr } of tests) {
      it(expr.toString(), function () {
        expect(expr.evaluate(LF.none, scope, null)).to.equal(undefined);
      });
    }

    it('void foo()', function () {
      let fooCalled = false;
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('hasAncestor', function () {
    expect(hasAncestor(new AccessThis()                )).to.equal(true);
    expect(hasAncestor(new AccessScope('')             )).to.equal(true);
    expect(hasAncestor(new ArrayLiteral([])            )).to.equal(false);
    expect(hasAncestor(new ObjectLiteral([], [])       )).to.equal(false);
    expect(hasAncestor(new PrimitiveLiteral('')        )).to.equal(false);
    expect(hasAncestor(new Template([])                )).to.equal(false);
    expect(hasAncestor(new Unary('!', e)               )).to.equal(false);
    expect(hasAncestor(new CallScope('!', [])          )).to.equal(true);
    expect(hasAncestor(new CallMember(e, '', [])       )).to.equal(false);
    expect(hasAncestor(new CallFunction(e, [])         )).to.equal(false);
    expect(hasAncestor(new AccessMember(e, '')         )).to.equal(false);
    expect(hasAncestor(new AccessKeyed(e, e)           )).to.equal(false);
    expect(hasAncestor(new TaggedTemplate([], [], e)   )).to.equal(false);
    expect(hasAncestor(new Binary('+', e, e)           )).to.equal(false);
    expect(hasAncestor(new Conditional(e, e, e)        )).to.equal(false);
    expect(hasAncestor(new Assign(e, e)                )).to.equal(false);
    expect(hasAncestor(new ValueConverter(e, '', [])   )).to.equal(false);
    expect(hasAncestor(new BindingBehavior(e, '', [])  )).to.equal(false);
    expect(hasAncestor(new HtmlLiteral([])             )).to.equal(false);
    expect(hasAncestor(new ArrayBindingPattern([])     )).to.equal(false);
    expect(hasAncestor(new ObjectBindingPattern([], []))).to.equal(false);
    expect(hasAncestor(new BindingIdentifier('')       )).to.equal(false);
    expect(hasAncestor(new ForOfStatement(e, e)        )).to.equal(false);
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('isLeftHandSide', function () {
    expect(isLeftHandSide(new AccessThis()                )).to.equal(true);
    expect(isLeftHandSide(new AccessScope('')             )).to.equal(true);
    expect(isLeftHandSide(new ArrayLiteral([])            )).to.equal(true);
    expect(isLeftHandSide(new ObjectLiteral([], [])       )).to.equal(true);
    expect(isLeftHandSide(new PrimitiveLiteral('')        )).to.equal(true);
    expect(isLeftHandSide(new Template([])                )).to.equal(true);
    expect(isLeftHandSide(new Unary('!', e)               )).to.equal(false);
    expect(isLeftHandSide(new CallScope('!', [])          )).to.equal(true);
    expect(isLeftHandSide(new CallMember(e, '', [])       )).to.equal(true);
    expect(isLeftHandSide(new CallFunction(e, [])         )).to.equal(true);
    expect(isLeftHandSide(new AccessMember(e, '')         )).to.equal(true);
    expect(isLeftHandSide(new AccessKeyed(e, e)           )).to.equal(true);
    expect(isLeftHandSide(new TaggedTemplate([], [], e)   )).to.equal(true);
    expect(isLeftHandSide(new Binary('+', e, e)           )).to.equal(false);
    expect(isLeftHandSide(new Conditional(e, e, e)        )).to.equal(false);
    expect(isLeftHandSide(new Assign(e, e)                )).to.equal(false);
    expect(isLeftHandSide(new ValueConverter(e, '', [])   )).to.equal(false);
    expect(isLeftHandSide(new BindingBehavior(e, '', [])  )).to.equal(false);
    expect(isLeftHandSide(new HtmlLiteral([])             )).to.equal(false);
    expect(isLeftHandSide(new ArrayBindingPattern([])     )).to.equal(false);
    expect(isLeftHandSide(new ObjectBindingPattern([], []))).to.equal(false);
    expect(isLeftHandSide(new BindingIdentifier('')       )).to.equal(false);
    expect(isLeftHandSide(new ForOfStatement(e, e)        )).to.equal(false);
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('hasBind', function () {
    expect(hasBind(new AccessThis()                )).to.equal(false);
    expect(hasBind(new AccessScope('')             )).to.equal(false);
    expect(hasBind(new ArrayLiteral([])            )).to.equal(false);
    expect(hasBind(new ObjectLiteral([], [])       )).to.equal(false);
    expect(hasBind(new PrimitiveLiteral('')        )).to.equal(false);
    expect(hasBind(new Template([])                )).to.equal(false);
    expect(hasBind(new Unary('!', e)               )).to.equal(false);
    expect(hasBind(new CallScope('!', [])          )).to.equal(false);
    expect(hasBind(new CallMember(e, '', [])       )).to.equal(false);
    expect(hasBind(new CallFunction(e, [])         )).to.equal(false);
    expect(hasBind(new AccessMember(e, '')         )).to.equal(false);
    expect(hasBind(new AccessKeyed(e, e)           )).to.equal(false);
    expect(hasBind(new TaggedTemplate([], [], e)   )).to.equal(false);
    expect(hasBind(new Binary('+', e, e)           )).to.equal(false);
    expect(hasBind(new Conditional(e, e, e)        )).to.equal(false);
    expect(hasBind(new Assign(e, e)                )).to.equal(false);
    expect(hasBind(new ValueConverter(e, '', [])   )).to.equal(false);
    expect(hasBind(new BindingBehavior(e, '', [])  )).to.equal(true);
    expect(hasBind(new HtmlLiteral([])             )).to.equal(false);
    expect(hasBind(new ArrayBindingPattern([])     )).to.equal(false);
    expect(hasBind(new ObjectBindingPattern([], []))).to.equal(false);
    expect(hasBind(new BindingIdentifier('')       )).to.equal(false);
    expect(hasBind(new ForOfStatement(e, e)        )).to.equal(true);