How to use the @aurelia/runtime.PrimitiveLiteral 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 / jit / dist / index.es6.js View on Github external
result = parseObjectLiteralExpression(state, bindingType);
                access = 0 /* Reset */;
                break;
            case 540713 /* TemplateTail */:
                result = new Template([state.tokenValue]);
                state.assignable = false;
                nextToken(state);
                access = 0 /* Reset */;
                break;
            case 540714 /* TemplateContinuation */:
                result = parseTemplate(state, access, bindingType, result, false);
                access = 0 /* Reset */;
                break;
            case 4096 /* StringLiteral */:
            case 8192 /* NumericLiteral */:
                result = new PrimitiveLiteral(state.tokenValue);
                state.assignable = false;
                nextToken(state);
                access = 0 /* Reset */;
                break;
            case 2050 /* NullKeyword */:
            case 2051 /* UndefinedKeyword */:
            case 2049 /* TrueKeyword */:
            case 2048 /* FalseKeyword */:
                result = TokenValues[state.currentToken & 63 /* Type */];
                state.assignable = false;
                nextToken(state);
                access = 0 /* Reset */;
                break;
            default:
                if (state.index >= state.length) {
                    if (Profiler.enabled) {
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('adds numbers', function () {
    let expression = new Binary('+', new PrimitiveLiteral(1), new PrimitiveLiteral(2));
    let scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal(3);

    expression = new Binary('+', new PrimitiveLiteral(1), $null);
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal(1);

    expression = new Binary('+', $null, new PrimitiveLiteral(2));
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal(2);

    expression = new Binary('+', new PrimitiveLiteral(1), $undefined);
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.be.NaN;

    expression = new Binary('+', $undefined, new PrimitiveLiteral(2));
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('concats strings', function () {
    let expression = new Binary('+', new PrimitiveLiteral('a'), new PrimitiveLiteral('b'));
    let scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal('ab');

    expression = new Binary('+', new PrimitiveLiteral('a'), $null);
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal('anull');

    expression = new Binary('+', $null, new PrimitiveLiteral('b'));
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal('nullb');

    expression = new Binary('+', new PrimitiveLiteral('a'), $undefined);
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal('aundefined');

    expression = new Binary('+', $undefined, new PrimitiveLiteral('b'));
    scope = createScopeForTest({});
    expect(expression.evaluate(LF.none, scope, null)).to.equal('undefinedb');
  });
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
it('isAssignable', function () {
    expect(isAssignable(new AccessThis()                )).to.equal(false);
    expect(isAssignable(new AccessScope('')             )).to.equal(true);
    expect(isAssignable(new ArrayLiteral([])            )).to.equal(false);
    expect(isAssignable(new ObjectLiteral([], [])       )).to.equal(false);
    expect(isAssignable(new PrimitiveLiteral('')        )).to.equal(false);
    expect(isAssignable(new Template([])                )).to.equal(false);
    expect(isAssignable(new Unary('!', e)               )).to.equal(false);
    expect(isAssignable(new CallScope('!', [])          )).to.equal(false);
    expect(isAssignable(new CallMember(e, '', [])       )).to.equal(false);
    expect(isAssignable(new CallFunction(e, [])         )).to.equal(false);
    expect(isAssignable(new AccessMember(e, '')         )).to.equal(true);
    expect(isAssignable(new AccessKeyed(e, e)           )).to.equal(true);
    expect(isAssignable(new TaggedTemplate([], [], e)   )).to.equal(false);
    expect(isAssignable(new Binary('+', e, e)           )).to.equal(false);
    expect(isAssignable(new Conditional(e, e, e)        )).to.equal(false);
    expect(isAssignable(new Assign(e, e)                )).to.equal(true);
    expect(isAssignable(new ValueConverter(e, '', [])   )).to.equal(false);
    expect(isAssignable(new BindingBehavior(e, '', [])  )).to.equal(false);
    expect(isAssignable(new HtmlLiteral([])             )).to.equal(false);
    expect(isAssignable(new ArrayBindingPattern([])     )).to.equal(false);
    expect(isAssignable(new ObjectBindingPattern([], []))).to.equal(false);
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
const $parent = AccessThis.$parent;

function throwsOn(expr: TExpr, method: keyof TExpr, msg: string, ...args: any[]): void {
  let err = null;
  try {
    (expr as any)[method](...args);
  } catch (e) {
    err = e;
  }
  expect(err).not.to.equal(null);
  if (msg && msg.length) {
    expect(err.message).to.contain(msg);
  }
}

const $num1 = new PrimitiveLiteral(1);
const $str1 = new PrimitiveLiteral('1');

describe('AST', function () {

  const AccessThisList: [string, AccessThis][] = [
    [`$this`,             $this],
    [`$parent`,           $parent],
    [`$parent.$parent`,   new AccessThis(2)]
  ];
  const AccessScopeList: [string, AccessScope][] = [
    ...AccessThisList.map(([input, expr]) => [`${input}.a`, new AccessScope('a', expr.ancestor)] as [string, any]),
    [`$this.$parent`,     new AccessScope('$parent')],
    [`$parent.$this`,     new AccessScope('$this', 1)],
    [`a`,                 new AccessScope('a')]
  ];
  const StringLiteralList: [string, PrimitiveLiteral][] = [
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
function throwsOn(expr: TExpr, method: keyof TExpr, msg: string, ...args: any[]): void {
  let err = null;
  try {
    (expr as any)[method](...args);
  } catch (e) {
    err = e;
  }
  expect(err).not.to.equal(null);
  if (msg && msg.length) {
    expect(err.message).to.contain(msg);
  }
}

const $num1 = new PrimitiveLiteral(1);
const $str1 = new PrimitiveLiteral('1');

describe('AST', function () {

  const AccessThisList: [string, AccessThis][] = [
    [`$this`,             $this],
    [`$parent`,           $parent],
    [`$parent.$parent`,   new AccessThis(2)]
  ];
  const AccessScopeList: [string, AccessScope][] = [
    ...AccessThisList.map(([input, expr]) => [`${input}.a`, new AccessScope('a', expr.ancestor)] as [string, any]),
    [`$this.$parent`,     new AccessScope('$parent')],
    [`$parent.$this`,     new AccessScope('$this', 1)],
    [`a`,                 new AccessScope('a')]
  ];
  const StringLiteralList: [string, PrimitiveLiteral][] = [
    [`''`,                PrimitiveLiteral.$empty]
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
describe('LiteralTemplate', function () {
  const tests: { expr: Template | TaggedTemplate; expected: string; ctx: any }[] = [
    { expr: $tpl, expected: '', ctx: {} },
    { expr: new Template(['foo']), expected: 'foo', ctx: {} },
    { expr: new Template(['foo', 'baz'], [new PrimitiveLiteral('bar')]), expected: 'foobarbaz', ctx: {} },
    {
      expr: new Template(
        ['a', 'c', 'e', 'g'],
        [new PrimitiveLiteral('b'), new PrimitiveLiteral('d'), new PrimitiveLiteral('f')]
      ),
      expected: 'abcdefg',
      ctx: {}
    },
    {
      expr: new Template(['a', 'c', 'e'], [new AccessScope('b', 0), new AccessScope('d', 0)]),
      expected: 'a1c2e',
      ctx: { b: 1, d: 2 }
    },
    { expr: new TaggedTemplate(
      [''], [],
      new AccessScope('foo', 0)),
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
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);
    expect(isPureLiteral(new Interpolation([])           )).to.equal(false);

    expect(isPureLiteral(new ArrayLiteral([]))).to.equal(true);
    expect(isPureLiteral(new ArrayLiteral([new PrimitiveLiteral('')]))).to.equal(true);
    expect(isPureLiteral(new ArrayLiteral([new AccessScope('a')]))).to.equal(false);

    expect(isPureLiteral(new ObjectLiteral([], []))).to.equal(true);
    expect(isPureLiteral(new ObjectLiteral(['a'], [new PrimitiveLiteral('1')]))).to.equal(true);
    expect(isPureLiteral(new ObjectLiteral(['a'], [new AccessScope('a')]))).to.equal(false);

    expect(isPureLiteral(new Template([]))).to.equal(true);
    expect(isPureLiteral(new Template(['']))).to.equal(true);
    expect(isPureLiteral(new Template(['', ''], [new PrimitiveLiteral('1')]))).to.equal(true);
    expect(isPureLiteral(new Template(['', ''], [new AccessScope('a')]))).to.equal(false);
  });
});
github aurelia / aurelia / packages / __tests__ / runtime / ast.spec.ts View on Github external
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);
    expect(isPureLiteral(new Interpolation([])           )).to.equal(false);

    expect(isPureLiteral(new ArrayLiteral([]))).to.equal(true);
    expect(isPureLiteral(new ArrayLiteral([new PrimitiveLiteral('')]))).to.equal(true);
    expect(isPureLiteral(new ArrayLiteral([new AccessScope('a')]))).to.equal(false);

    expect(isPureLiteral(new ObjectLiteral([], []))).to.equal(true);
    expect(isPureLiteral(new ObjectLiteral(['a'], [new PrimitiveLiteral('1')]))).to.equal(true);
    expect(isPureLiteral(new ObjectLiteral(['a'], [new AccessScope('a')]))).to.equal(false);

    expect(isPureLiteral(new Template([]))).to.equal(true);
    expect(isPureLiteral(new Template(['']))).to.equal(true);
    expect(isPureLiteral(new Template(['', ''], [new PrimitiveLiteral('1')]))).to.equal(true);
    expect(isPureLiteral(new Template(['', ''], [new AccessScope('a')]))).to.equal(false);
  });
});
github aurelia / aurelia / packages / validation / src / implementation / validation-message-parser.ts View on Github external
public parse(message: string): IExpression {
    if (this.cache[message] !== undefined) {
      return this.cache[message];
    }

    const interpolation = this.parser.parse(message, BindingType.Interpolation);
    if (interpolation === null) {
      return new PrimitiveLiteral(message);
    }
    MessageExpressionValidator.validate(interpolation, message);

    this.cache[message] = interpolation;

    return interpolation;
  }
}