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

[CLEANUP beta] Only register View AST Transforms when legacy enabled #11797

Merged
merged 1 commit into from Jul 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/ember-htmlbars/tests/compat/controller_keyword_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ import EmberComponent from 'ember-views/views/component';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import compile from 'ember-template-compiler/system/compile';

import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';

let component;

QUnit.module('ember-htmlbars: compat - controller keyword (use as a path)', {
setup() {
registerAstPlugin(TransformEachIntoCollection);
registerAstPlugin(DeprecateViewAndControllerPaths);

component = null;
},
teardown() {
runDestroy(component);

removeAstPlugin(TransformEachIntoCollection);
removeAstPlugin(DeprecateViewAndControllerPaths);
}
});

Expand Down
6 changes: 6 additions & 0 deletions packages/ember-htmlbars/tests/compat/view_helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import compile from 'ember-template-compiler/system/compile';
import Registry from 'container/registry';

import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import DeprecateViewHelper from 'ember-template-compiler/plugins/deprecate-view-helper';

let component, registry, container;

QUnit.module('ember-htmlbars: compat - view helper', {
setup() {
registerAstPlugin(DeprecateViewHelper);

registry = new Registry();
container = registry.container();
},
teardown() {
runDestroy(component);
runDestroy(container);
removeAstPlugin(DeprecateViewHelper);
registry = container = component = null;
}
});
Expand Down
5 changes: 5 additions & 0 deletions packages/ember-htmlbars/tests/compat/view_keyword_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import EmberComponent from 'ember-views/views/component';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import compile from 'ember-template-compiler/system/compile';

import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';

let component;

QUnit.module('ember-htmlbars: compat - view keyword (use as a path)', {
setup() {
registerAstPlugin(DeprecateViewAndControllerPaths);
component = null;
},
teardown() {
runDestroy(component);
removeAstPlugin(DeprecateViewAndControllerPaths);
}
});

Expand Down
7 changes: 7 additions & 0 deletions packages/ember-htmlbars/tests/helpers/each_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import compile from 'ember-template-compiler/system/compile';
import { deprecation as eachDeprecation } from 'ember-htmlbars/helpers/each';

import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';


var people, view, registry, container;
var template, templateMyView, MyView, MyEmptyView, templateMyEmptyView;
Expand Down Expand Up @@ -85,6 +88,8 @@ QUnit.module('the #each helper [DEPRECATED]', {
setup() {
Ember.lookup = lookup = { Ember: Ember };

registerAstPlugin(TransformEachIntoCollection);

template = compile('{{#each view.people}}{{name}}{{/each}}');
people = A([{ name: 'Steve Holt' }, { name: 'Annabelle' }]);

Expand Down Expand Up @@ -123,6 +128,8 @@ QUnit.module('the #each helper [DEPRECATED]', {
registry = container = view = null;

Ember.lookup = originalLookup;

removeAstPlugin(TransformEachIntoCollection);
}
});

Expand Down
15 changes: 15 additions & 0 deletions packages/ember-htmlbars/tests/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import plugins, { registerPlugin } from 'ember-template-compiler/plugins';

function registerAstPlugin(plugin) {
registerPlugin('ast', plugin);
}

function removeAstPlugin(plugin) {
const index = plugins['ast'].indexOf(plugin);
plugins['ast'].splice(index, 1);
}

export {
registerAstPlugin,
removeAstPlugin
};
14 changes: 9 additions & 5 deletions packages/ember-template-compiler/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import compile from 'ember-template-compiler/system/compile';
import template from 'ember-template-compiler/system/template';
import { registerPlugin } from 'ember-template-compiler/plugins';

import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';
import TransformOldBindingSyntax from 'ember-template-compiler/plugins/transform-old-binding-syntax';
import TransformOldClassBindingSyntax from 'ember-template-compiler/plugins/transform-old-class-binding-syntax';
import TransformItemClass from 'ember-template-compiler/plugins/transform-item-class';
import TransformComponentAttrsIntoMut from 'ember-template-compiler/plugins/transform-component-attrs-into-mut';
import TransformComponentCurlyToReadonly from 'ember-template-compiler/plugins/transform-component-curly-to-readonly';
import TransformAngleBracketComponents from 'ember-template-compiler/plugins/transform-angle-bracket-components';
import TransformInputOnToOnEvent from 'ember-template-compiler/plugins/transform-input-on-to-onEvent';
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';
import TransformTopLevelComponents from 'ember-template-compiler/plugins/transform-top-level-components';
import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';
import DeprecateViewAndControllerPaths from 'ember-template-compiler/plugins/deprecate-view-and-controller-paths';
import DeprecateViewHelper from 'ember-template-compiler/plugins/deprecate-view-helper';

// used for adding Ember.Handlebars.compile for backwards compat
import 'ember-template-compiler/compat';

registerPlugin('ast', TransformEachIntoCollection);
registerPlugin('ast', TransformOldBindingSyntax);
registerPlugin('ast', TransformOldClassBindingSyntax);
registerPlugin('ast', TransformItemClass);
Expand All @@ -28,8 +27,13 @@ registerPlugin('ast', TransformComponentCurlyToReadonly);
registerPlugin('ast', TransformAngleBracketComponents);
registerPlugin('ast', TransformInputOnToOnEvent);
registerPlugin('ast', TransformTopLevelComponents);
registerPlugin('ast', DeprecateViewAndControllerPaths);
registerPlugin('ast', DeprecateViewHelper);

if (_Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT) {
registerPlugin('ast', TransformEachIntoCollection);
registerPlugin('ast', DeprecateViewAndControllerPaths);
registerPlugin('ast', DeprecateViewHelper);
}


export {
_Ember,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { compile } from 'ember-template-compiler';

QUnit.module('ember-template-compiler: transform-each-into-collection');
import { registerAstPlugin, removeAstPlugin } from 'ember-htmlbars/tests/utils';
import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';

QUnit.module('ember-template-compiler: transform-each-into-collection', {
setup() {
registerAstPlugin(TransformEachIntoCollection);
},
teardown() {
removeAstPlugin(TransformEachIntoCollection);
}
});

let deprecatedAttrs = ['itemController', 'itemView', 'itemViewClass', 'tagName', 'emptyView', 'emptyViewClass'];

Expand Down
10 changes: 10 additions & 0 deletions packages/ember/tests/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Ember from 'ember-metal/core';
import EmberHandlebars from 'ember-htmlbars/compat';
import EmberView from 'ember-views/views/view';

import plugins, { registerPlugin } from 'ember-template-compiler/plugins';
import TransformEachIntoCollection from 'ember-template-compiler/plugins/transform-each-into-collection';

/*
In Ember 1.x, controllers subtly affect things like template scope
and action targets in exciting and often inscrutable ways. This test
Expand All @@ -14,8 +17,13 @@ import EmberView from 'ember-views/views/view';
var compile = EmberHandlebars.compile;
var App, $fixture, templates;

let originalAstPlugins;

QUnit.module('Template scoping examples', {
setup() {
originalAstPlugins = plugins['ast'].slice(0);
registerPlugin('ast', TransformEachIntoCollection);

Ember.run(function() {
templates = Ember.TEMPLATES;
App = Ember.Application.create({
Expand All @@ -42,6 +50,8 @@ QUnit.module('Template scoping examples', {
App = null;

Ember.TEMPLATES = {};

plugins['ast'] = originalAstPlugins;
}
});

Expand Down