Пример #1
0
function processComponentInitializationAssertions(component, props) {
  assert(`classNameBindings must not have spaces in them: ${component.toString()}`, (() => {
    let { classNameBindings } = component;
    for (let i = 0; i < classNameBindings.length; i++) {
      let binding = classNameBindings[i];
      if (binding.split(' ').length > 1) {
        return false;
      }
    }
    return true;
  })());

  assert('You cannot use `classNameBindings` on a tag-less component: ' + component.toString(), (() => {
    let { classNameBindings, tagName } = component;
    return tagName !== '' || !classNameBindings || classNameBindings.length === 0;
  })());

  assert('You cannot use `elementId` on a tag-less component: ' + component.toString(), (() => {
    let { elementId, tagName } = component;
    return tagName !== '' || props.id === elementId || (!elementId && elementId !== '');
  })());

  assert('You cannot use `attributeBindings` on a tag-less component: ' + component.toString(), (() => {
    let { attributeBindings, tagName } = component;
    return tagName !== '' || !attributeBindings || attributeBindings.length === 0;
  })());
}
Пример #2
0
  compute() {
    // TODO: Figure out how to extract this because it's nearly identical to
    // DynamicComponentReference::compute(). The only differences besides
    // currying are in the assertion messages.
    let { args, defRef, env, symbolTable, lastDefinition, lastName } = this;
    let nameOrDef = defRef.value();
    let definition = null;

    if (nameOrDef && nameOrDef === lastName) {
      return lastDefinition;
    }

    this.lastName = nameOrDef;

    if (typeof nameOrDef === 'string') {
      definition = env.getComponentDefinition([nameOrDef], symbolTable);
      assert(`The component helper cannot be used without a valid component name. You used "${nameOrDef}" via (component "${nameOrDef}")`, definition);
    } else if (isComponentDefinition(nameOrDef)) {
      definition = nameOrDef;
    } else {
      assert(
        `You cannot create a component from ${nameOrDef} using the {{component}} helper`,
        nameOrDef
      );
      return null;
    }

    let newDef = createCurriedDefinition(definition, args);

    this.lastDefinition = newDef;

    return newDef;
  }
Пример #3
0
QUnit.test('Ember.assert does not throw if second argument is an object', function() {
  expect(1);
  let Igor = EmberObject.extend();

  emberAssert('is truthy', Igor);
  emberAssert('is truthy', Igor.create());

  ok(true, 'assertions were not thrown');
});
Пример #4
0
QUnit.test('Ember.assert does not throw if second argument is truthy', function() {
  expect(1);

  emberAssert('Assertion is thrown', true);
  emberAssert('Assertion is thrown', '1');
  emberAssert('Assertion is thrown', 1);

  ok(true, 'assertions were not thrown');
});
Пример #5
0
 run(() => {
   let args = this.getActionArgs();
   let payload = {
     args,
     target
   };
   if (typeof actionName[INVOKE] === 'function') {
     flaggedInstrument('interaction.ember-action', payload, () => {
       actionName[INVOKE].apply(actionName, args);
     });
     return;
   }
   if (typeof actionName === 'function') {
     flaggedInstrument('interaction.ember-action', payload, () => {
       actionName.apply(target, args);
     });
     return;
   }
   payload.name = actionName;
   if (target.send) {
     flaggedInstrument('interaction.ember-action', payload, () => {
       target.send.apply(target, [actionName, ...args]);
     });
   } else {
     assert(
       `The action '${actionName}' did not exist on ${target}`,
       typeof target[actionName] === 'function'
     );
     flaggedInstrument('interaction.ember-action', payload, () => {
       target[actionName].apply(target, args);
     });
   }
 });
Пример #6
0
QUnit.test('Ember.assert does not throw if second argument is a function', function(assert) {
  assert.expect(1);

  emberAssert('Assertion is thrown', () => true);

  ok(true, 'assertions were not thrown');
});
Пример #7
0
  lookupHelper(nameParts, symbolTable) {
    assert('The first argument passed into `lookupHelper` should be an array', Array.isArray(nameParts));

    let name = nameParts[0];
    let helper = this.builtInHelpers[name];

    if (helper) {
      return helper;
    }

    let blockMeta = symbolTable.getMeta();
    let owner = blockMeta.owner;
    let options = blockMeta.moduleName && { source: `template:${blockMeta.moduleName}` } || {};

    helper = owner.lookup(`helper:${name}`, options) || owner.lookup(`helper:${name}`);

    // TODO: try to unify this into a consistent protocol to avoid wasteful closure allocations
    if (helper.isHelperInstance) {
      return (vm, args) => SimpleHelperReference.create(helper.compute, args);
    } else if (helper.isHelperFactory) {
      return (vm, args) => ClassBasedHelperReference.create(helper, vm, args);
    } else {
      throw new Error(`${nameParts} is not a helper`);
    }
  }
Пример #8
0
Registry.prototype.expandLocalLookup = function Registry_expandLocalLookup(fullName, options) {
  if (this.resolver && this.resolver.expandLocalLookup) {
    assert('fullName must be a proper full name', this.validateFullName(fullName));
    assert('options.source must be provided to expandLocalLookup', options && options.source);
    assert('options.source must be a proper full name', this.validateFullName(options.source));

    let normalizedFullName = this.normalize(fullName);
    let normalizedSource = this.normalize(options.source);

    return expandLocalLookup(this, normalizedFullName, normalizedSource);
  } else if (this.fallback) {
    return this.fallback.expandLocalLookup(fullName, options);
  } else {
    return null;
  }
};
Пример #9
0
  initializer: function(initializer) {
    // If this is the first initializer being added to a subclass, we are going to reopen the class
    // to make sure we have a new `initializers` object, which extends from the parent class' using
    // prototypal inheritance. Without this, attempting to add initializers to the subclass would
    // pollute the parent class as well as other subclasses.
    if (this.superclass.initializers !== undefined && this.superclass.initializers === this.initializers) {
      this.reopenClass({
        initializers: create(this.initializers)
      });
    }

    Ember.assert("The initializer '" + initializer.name + "' has already been registered", !this.initializers[initializer.name]);
    Ember.assert("An initializer cannot be registered without an initialize function", canInvoke(initializer, 'initialize'));

    this.initializers[initializer.name] = initializer;
  },
Пример #10
0
  advanceReadiness: function() {
    Ember.assert("You must call advanceReadiness on an instance of Ember.Application", this instanceof Application);
    this._readinessDeferrals--;

    if (this._readinessDeferrals === 0) {
      run.once(this, this.didBecomeReady);
    }
  },
Пример #11
0
  return function(initializer) {
    // If this is the first initializer being added to a subclass, we are going to reopen the class
    // to make sure we have a new `initializers` object, which extends from the parent class' using
    // prototypal inheritance. Without this, attempting to add initializers to the subclass would
    // pollute the parent class as well as other subclasses.
    if (this.superclass[bucketName] !== undefined && this.superclass[bucketName] === this[bucketName]) {
      var attrs = {};
      attrs[bucketName] = create(this[bucketName]);
      this.reopenClass(attrs);
    }

    Ember.assert("The " + humanName + " '" + initializer.name + "' has already been registered", !this[bucketName][initializer.name]);
    Ember.assert("An " + humanName + " cannot be registered without an initialize function", canInvoke(initializer, 'initialize'));
    Ember.assert("An " + humanName + " cannot be registered without a name property", initializer.name !== undefined);

    this[bucketName][initializer.name] = initializer;
  };
Пример #12
0
    this._runInitializer('initializers', function(name, initializer) {
      Ember.assert("No application initializer named '" + name + "'", !!initializer);

      if (Ember.FEATURES.isEnabled("ember-application-initializer-context")) {
        initializer.initialize(registry, App);
      } else {
        var ref = initializer.initialize;
        ref(registry, App);
      }
    });
Пример #13
0
  hasModifier(nameParts) {
    assert('The first argument passed into `hasModifier` should be an array', Array.isArray(nameParts));

    // modifiers are not allowed to include a dot in their invocation
    if (nameParts.length > 1) {
      return false;
    }

    return !!this.builtInModifiers[nameParts[0]];
  }
Пример #14
0
function addObserverForContentKey(content, keyName, proxy, idx, loc) {
  while (--loc >= idx) {
    let item = objectAt(content, loc);
    if (item) {
      assert('When using @each to observe the array ' + content + ', the array must return an object', typeof item === 'object');
      _addBeforeObserver(item, keyName, proxy, 'contentKeyWillChange');
      addObserver(item, keyName, proxy, 'contentKeyDidChange');
    }
  }
}
Пример #15
0
  lookupModifier(nameParts) {
    assert('The first argument passed into `lookupModifier` should be an array', Array.isArray(nameParts));

    let modifier = this.builtInModifiers[nameParts[0]];

    if (modifier) {
      return modifier;
    } else {
      throw new Error(`${nameParts} is not a modifier`);
    }
  }
Пример #16
0
export function inlineUnless(vm, { positional }) {
  switch (positional.length) {
    case 2: return ConditionalHelperReference.create(positional.at(0), null, positional.at(1));
    case 3: return ConditionalHelperReference.create(positional.at(0), positional.at(2), positional.at(1));
    default:
      assert(
        'The inline form of the `unless` helper expects two or three arguments, e.g. ' +
        '`{{unless isFirstLogin "Welcome back!"}}`.'
      );
  }
}
Пример #17
0
export function inlineIf(vm, { positional }) {
  switch (positional.length) {
    case 2: return ConditionalHelperReference.create(positional.at(0), positional.at(1), null);
    case 3: return ConditionalHelperReference.create(positional.at(0), positional.at(1), positional.at(2));
    default:
      assert(
        'The inline form of the `if` helper expects two or three arguments, e.g. ' +
        '`{{if trialExpired "Expired" expiryDate}}`.'
      );
  }
}
Пример #18
0
function validateAction(component, actionName) {
  if (actionName && actionName[MUTABLE_CELL]) {
    actionName = actionName.value;
  }

  assert(
    `The default action was triggered on the component ${component.toString()}, but the action name (${actionName}) was not a string.`,
    isNone(actionName) || typeof actionName === 'string' || typeof actionName === 'function'
  );
  return actionName;
}
Пример #19
0
  static create(env, args, templates, symbolTable) {
    assert(
      'You can only pass a single argument to the {{mount}} helper, e.g. {{mount "chat-engine"}}.',
      args.positional.length === 1 && args.named.length === 0
    );

    assert(
      'The first argument of {{mount}} must be quoted, e.g. {{mount "chat-engine"}}.',
      args.positional.at(0).type === 'value' && typeof args.positional.at(0).inner() === 'string'
    );

    let name = args.positional.at(0).inner();

    assert(
      `You used \`{{mount '${name}'}}\`, but the engine '${name}' can not be found.`,
      env.owner.hasRegistration(`engine:${name}`)
    );

    let definition = new MountDefinition(name, env);

    return new MountSyntax(definition, symbolTable);
  }
Пример #20
0
  runInDebug(() => {
    if (!named || !positional || !positional.length) {
      return;
    }

    let paramType = typeof positionalParamsDefinition;

    if (paramType === 'string') {
      assert(`You cannot specify positional parameters and the hash argument \`${positionalParamsDefinition}\`.`, !named.has(positionalParamsDefinition));
    } else {
      if (positional.length < positionalParamsDefinition.length) {
        positionalParamsDefinition = positionalParamsDefinition.slice(0, positional.length);
      }

      for (let i = 0; i < positionalParamsDefinition.length; i++) {
        let name = positionalParamsDefinition[i];

        assert(
          `You cannot specify both a positional param (at position ${i}) and the hash argument \`${name}\`.`,
          !named.has(name)
        );
      }
    }
  });
Пример #21
0
    this._runInitializer('initializers', (name, initializer) => {
      assert('No application initializer named \'' + name + '\'', !!initializer);
      if (initializer.initialize.length === 2) {
        deprecate('The `initialize` method for Application initializer \'' + name + '\' should take only one argument - `App`, an instance of an `Application`.',
                  false,
                  {
                    id: 'ember-application.app-initializer-initialize-arguments',
                    until: '3.0.0',
                    url: 'http://emberjs.com/deprecations/v2.x/#toc_initializer-arity'
                  });

        initializer.initialize(this.__registry__, this);
      } else {
        initializer.initialize(this);
      }
    });
Пример #22
0
  value() {
    let { env, nameRef, symbolTable } = this;
    let nameOrDef = nameRef.value();

    if (typeof nameOrDef === 'string') {
      let definition = env.getComponentDefinition([nameOrDef], symbolTable);

      assert(`Could not find component named "${nameOrDef}" (no component or template with that name was found)`, definition);

      return definition;
    } else if (isComponentDefinition(nameOrDef)) {
      return nameOrDef;
    } else {
      return null;
    }
  }
Пример #23
0
function errorFor(reason) {
  if (!reason) return;

  if (reason.errorThrown) {
    return unwrapErrorThrown(reason);
  }

  if (reason.name === 'UnrecognizedURLError') {
    assert(`The URL '${reason.message}' did not match any routes in your application`, false);
    return;
  }

  if (reason.name === 'TransitionAborted') {
    return;
  }

  return reason;
}
Пример #24
0
  create(element, args, dynamicScope, dom) {
    let { named, positional } = args;
    let implicitTarget;
    let actionName;
    let actionNameRef;
    if (positional.length > 1) {
      implicitTarget = positional.at(0);
      actionNameRef = positional.at(1);

      if (actionNameRef[INVOKE]) {
        actionName = actionNameRef;
      } else {
        let actionLabel = actionNameRef._propertyKey;
        actionName = actionNameRef.value();

        assert(
          'You specified a quoteless path, `' + actionLabel + '`, to the ' +
            '{{action}} helper which did not resolve to an action name (a ' +
            'string). Perhaps you meant to use a quoted actionName? (e.g. ' +
            '{{action "' + actionLabel + '"}}).',
          typeof actionName === 'string' || typeof actionName === 'function'
        );
      }
    }

    let actionArgs = [];
    // The first two arguments are (1) `this` and (2) the action name.
    // Everything else is a param.
    for (let i = 2; i < positional.length; i++) {
      actionArgs.push(positional.at(i));
    }

    let actionId = uuid();
    return new ActionState(
      element,
      actionId,
      actionName,
      actionArgs,
      named,
      positional,
      implicitTarget,
      dom
    );
  }
Пример #25
0
  hasHelper(nameParts, symbolTable) {
    assert('The first argument passed into `hasHelper` should be an array', Array.isArray(nameParts));

    // helpers are not allowed to include a dot in their invocation
    if (nameParts.length > 1) {
      return false;
    }

    let name = nameParts[0];

    if (this.builtInHelpers[name]) {
      return true;
    }

    let blockMeta = symbolTable.getMeta();
    let owner = blockMeta.owner;
    let options = { source: `template:${blockMeta.moduleName}` };

    return owner.hasRegistration(`helper:${name}`, options) ||
      owner.hasRegistration(`helper:${name}`);
  }
Пример #26
0
  Container.prototype.factoryFor = function _factoryFor(fullName, options = {}) {
    let normalizedName = this.registry.normalize(fullName);
    assert('fullName must be a proper full name', this.registry.validateFullName(normalizedName));

    if (options.source) {
      normalizedName = this.registry.expandLocalLookup(fullName, options);
      // if expandLocalLookup returns falsey, we do not support local lookup
      if (!normalizedName) { return; }
    }

    let factory = this.registry.resolve(normalizedName);

    if (factory === undefined) { return; }

    let manager = new FactoryManager(this, factory, fullName, normalizedName);

    runInDebug(() => {
      manager = wrapManagerInDeprecationProxy(manager);
    });

    return manager;
  };
Пример #27
0
  constructor(root, env, template, self, parentElement, dynamicScope) {
    assert(`You cannot render \`${self.value()}\` without a template.`, template);

    this.id = getViewId(root);
    this.env = env;
    this.root = root;
    this.result = undefined;
    this.shouldReflush = false;
    this.destroyed = false;
    this._removing = false;

    let options = this.options = {
      alwaysRevalidate: false
    };

    this.render = () => {
      let result = this.result = template.render(self, parentElement, dynamicScope);

      // override .render function after initial render
      this.render = () => {
        result.rerender(options);
      };
    };
  }
Пример #28
0
 graph.topsort(function (vertex) {
   var initializer = vertex.value;
   Ember.assert("No application initializer named '"+vertex.name+"'", initializer);
   initializer(container, namespace);
 });
Пример #29
0
 deferReadiness: function() {
   Ember.assert("You must call deferReadiness on an instance of Ember.Application", this instanceof Application);
   Ember.assert("You cannot defer readiness since the `ready()` hook has already been called.", this._readinessDeferrals > 0);
   this._readinessDeferrals++;
 },
Пример #30
0
    @public
  */
  namespace: null,

  init() {
    this._parseNameCache = dictionary(null);
  },
  normalize(fullName) {
    var [
      type,
      name
    ] = fullName.split(':', 2);

    assert(
      'Tried to normalize a container name without a colon (:) in it. ' +
      'You probably tried to lookup a name that did not contain a type, ' +
      'a colon, and a name. A proper lookup name would be `view:post`.',
      fullName.split(':').length === 2
    );

    if (type !== 'template') {
      var result = name;

      if (result.indexOf('.') > -1) {
        result = result.replace(/\.(.)/g, function(m) {
          return m.charAt(1).toUpperCase();
        });
      }

      if (name.indexOf('_') > -1) {
        result = result.replace(/_(.)/g, function(m) {
          return m.charAt(1).toUpperCase();