walker.visit(ast, function(node) {
    if (validate(node)) {

      var removedParams = node.params.splice(0, 2);
      var keyword = removedParams[0].original;
      let moduleInfo;

      if (node.type === 'BlockStatement') {
        moduleInfo = calculateLocationDisplay(moduleName, node.program.loc);

        if (node.program.blockParams.length) {
          throw new Error('You cannot use keyword (`{{#each foo in bar}}`) and block params (`{{#each bar as |foo|}}`) at the same time ' + moduleInfo + '.');
        }

        node.program.blockParams = [keyword];
      } else {
        moduleInfo = calculateLocationDisplay(moduleName, node.loc);

        node.hash.pairs.push(b.pair(
          'keyword',
          b.string(keyword)
        ));
      }

      Ember.deprecate(
        `Using the '{{#each item in model}}' form of the {{#each}} helper ${moduleInfo}is deprecated. ` +
          `Please use the block param form instead ('{{#each model as |item|}}').`,
        false,
        { url: 'http://emberjs.com/guides/deprecations/#toc_code-in-code-syntax-for-code-each-code' }
      );
    }
  });
Ejemplo n.º 2
0
function assertHelper(moduleName, node) {
  let moduleInfo = calculateLocationDisplay(moduleName, node.loc);
  let singular = node.params[0].original;
  let plural = node.params[2].original;

  assert(`Using {{#each ${singular} in ${plural}}} ${moduleInfo}is no longer supported in Ember 2.0+, please use {{#each ${plural} as |${singular}|}}`);
}
  walker.visit(ast, node => {
    if (!validate(node)) { return; }

    for (let i = 0; i < node.hash.pairs.length; i++) {
      let pair = node.hash.pairs[i];
      let { key, value } = pair;

      var sourceInformation = calculateLocationDisplay(moduleName, pair.loc);

      if (key === 'classBinding') { return; }

      assert(`Setting 'attributeBindings' via template helpers is not allowed ${sourceInformation}`, key !== 'attributeBindings');

      if (key.substr(-7) === 'Binding') {
        let newKey = key.slice(0, -7);

        deprecate(
          `You're using legacy binding syntax: ${key}=${exprToString(value)} ${sourceInformation}. Please replace with ${newKey}=${value.original}`,
          false,
          { id: 'ember-template-compiler.transform-old-binding-syntax', until: '3.0.0' }
        );

        pair.key = newKey;
        if (value.type === 'StringLiteral') {
          pair.value = b.path(value.original);
        }
      }
    }
  });
  walker.visit(ast, function(node) {
    if (pluginContext.validate(node)) {
      let action = hashPairForKey(node.hash, 'action');
      let on = hashPairForKey(node.hash, 'on');
      let onEvent = hashPairForKey(node.hash, 'onEvent');
      let normalizedOn = on || onEvent;
      let moduleInfo = calculateLocationDisplay(moduleName, node.loc);

      if (normalizedOn && normalizedOn.value.type !== 'StringLiteral') {
        deprecate(
          `Using a dynamic value for '#{normalizedOn.key}=' with the '{{input}}' helper ${moduleInfo}is deprecated.`,
          false,
          { id: 'ember-template-compiler.transform-input-on-to-onEvent.dynamic-value', until: '3.0.0' }
        );

        normalizedOn.key = 'onEvent';
        return; // exit early, as we cannot transform further
      }

      removeFromHash(node.hash, normalizedOn);
      removeFromHash(node.hash, action);

      if (!action) {
        deprecate(
          `Using '{{input ${normalizedOn.key}="${normalizedOn.value.value}" ...}}' without specifying an action ${moduleInfo}will do nothing.`,
          false,
          { id: 'ember-template-compiler.transform-input-on-to-onEvent.no-action', until: '3.0.0' }
        );

        return; // exit early, if no action was available there is nothing to do
      }


      let specifiedOn = normalizedOn ? `${normalizedOn.key}="${normalizedOn.value.value}" ` : '';
      if (normalizedOn && normalizedOn.value.value === 'keyPress') {
        // using `keyPress` in the root of the component will
        // clobber the keyPress event handler
        normalizedOn.value.value = 'key-press';
      }

      let expected = `${normalizedOn ? normalizedOn.value.value : 'enter'}="${action.value.original}"`;

      deprecate(
        `Using '{{input ${specifiedOn}action="${action.value.original}"}}' ${moduleInfo}is deprecated. Please use '{{input ${expected}}}' instead.`,
        false,
        { id: 'ember-template-compiler.transform-input-on-to-onEvent.normalized-on', until: '3.0.0' }
      );
      if (!normalizedOn) {
        normalizedOn = b.pair('onEvent', b.string('enter'));
      }

      node.hash.pairs.push(b.pair(
        normalizedOn.value.value,
        action.value
      ));
    }
  });
Ejemplo n.º 5
0
function assertHelper(moduleName, node) {
  const paramValue = node.params.length && node.params[0].value;

  if (!paramValue) {
    return;
  } else {
    assert(
      `Using the \`{{view "string"}}\` helper is removed in 2.0. ${calculateLocationDisplay(moduleName, node.loc)}`,
      Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT,
      { id: 'view.helper', until: '2.0.0' }
    );
  }
}
function deprecatePath(moduleName, node, path) {
  Ember.deprecate(`Using \`{{${path && path.type === 'PathExpression' && path.parts[0]}}}\` or any path based on it ${calculateLocationDisplay(moduleName, node.loc)}has been deprecated.`, function deprecatePath_test() {
    let noDeprecate = true;

    const viewKeyword = path && path.type === 'PathExpression' && path.parts && path.parts[0];
    if (viewKeyword === 'view') {
      noDeprecate = Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT;
    } else if (viewKeyword === 'controller') {
      noDeprecate = false;
    }

    return noDeprecate;
  }, { url: 'http://emberjs.com/deprecations/v1.x#toc_view-and-controller-template-keywords', id: (path.parts && path.parts[0] === 'view' ? 'view.keyword.view' : 'view.keyword.controller'), until: '2.0.0' });
}
Ejemplo n.º 7
0
    each(node.hash.pairs, function(pair) {
      let { key, value } = pair;

      var sourceInformation = calculateLocationDisplay(moduleName, pair.loc);

      if (key === 'classBinding') { return; }

      Ember.assert(`Setting 'attributeBindings' via template helpers is not allowed ${sourceInformation}`, key !== 'attributeBindings');

      if (key.substr(-7) === 'Binding') {
        let newKey = key.slice(0, -7);

        Ember.deprecate(`You're using legacy binding syntax: ${key}=${exprToString(value)} ${sourceInformation}. Please replace with ${newKey}=${value.original}`);

        pair.key = newKey;
        if (value.type === 'StringLiteral') {
          pair.value = b.path(value.original);
        }
      }
    });
Ejemplo n.º 8
0
  walker.visit(ast, function(node) {
    if (pluginContext.validate(node)) {

      if (node.program && node.program.blockParams.length) {
        throw new Error('You cannot use keyword (`{{with foo as bar}}`) and block params (`{{with foo as |bar|}}`) at the same time.');
      }

      let moduleInfo = calculateLocationDisplay(moduleName, node.program.loc);

      Ember.deprecate(
        "Using {{with}} without block syntax " + moduleInfo + "is deprecated. " +
        "Please use standard block form (`{{#with foo as |bar|}}`) " +
        "instead.",
        false,
        { url: "http://emberjs.com/deprecations/v1.x/#toc_code-as-code-sytnax-for-code-with-code" }
      );

      var removedParams = node.params.splice(1, 2);
      var keyword = removedParams[1].original;
      node.program.blockParams = [keyword];
    }
  });
  walker.visit(ast, function(node) {
    let legacyHashKey = validate(node);
    if (!legacyHashKey) { return; }

    let moduleInfo = calculateLocationDisplay(moduleName, legacyHashKey.loc);

    Ember.deprecate(
      `Using '${legacyHashKey.key}' with '{{each}}' ${moduleInfo}is deprecated.  Please refactor to a component.`
    );

    let list = node.params.shift();
    node.path = b.path('collection');

    node.params.unshift(b.string('-legacy-each'));

    let pair = b.pair('content', list);
    pair.loc = list.loc;

    node.hash.pairs.push(pair);

    //pair = b.pair('dataSource', list);
    //node.hash.pairs.push(pair);
  });
function assertMessage(moduleName, node) {
  let path = node.original;
  let source = calculateLocationDisplay(moduleName, node.loc);

  return `'${path}' is not a valid path. ${source}`;
}