forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX beta] Deprecate {{view "string"}} and special case {{view "se…
…lect"}} Use a template-compiler plugin to detect `{{view "string"}}` at compile-time and issue a deprecation with location information. Has a special case deprecation when the string === "select". Removes a test from the view helper tests that was checking for the deprecation at runtime (and removes the associated code in the ember-htmlbars package's `keywords/view`). Note: This does not catch a deprecation when the path is not a string, e.g., `{{view view.someProperty}}`, however emberjs#11401 would catch and issue a deprecation message for that case (at runtime). Also a few changes to deprecations: * document `id` param to `Ember.deprecate` * include deprecation id in log/error message * Use dot-namespaced deprecation ids (more similar to how `instrument` works and paves the way to in the future changing deprecation log levels by paths ie `"view.*"`) * globally silence view-related deprecations in tests to avoid overflowing travis ci's log * update ember-dev dep in bower (pr: emberjs/ember-dev#153) to `a064f0cd2f4c225ffd023b63d4cb31a79db04aaf` * change the view-and-controller-path template compiler plugin to always deprecate `{{controller}}` * change the view-and-controller-path template compiler plugin to skip deprecating `{{view}}` when `Ember.ENV._ENABLE_LEGACY_VIW_SUPPORT` is true refs emberjs#11377
- Loading branch information
Showing
9 changed files
with
152 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import EmberComponent from "ember-views/views/component"; | ||
import EmberView from "ember-views/views/view"; | ||
import EmberSelectView from "ember-views/views/select"; | ||
import { runAppend, runDestroy } from "ember-runtime/tests/utils"; | ||
import compile from "ember-template-compiler/system/compile"; | ||
import Registry from "container/registry"; | ||
|
||
let component, registry, container; | ||
|
||
QUnit.module('ember-htmlbars: compat - view helper', { | ||
setup() { | ||
registry = new Registry(); | ||
container = registry.container(); | ||
}, | ||
teardown() { | ||
runDestroy(component); | ||
runDestroy(container); | ||
registry = container = component = null; | ||
} | ||
}); | ||
|
||
QUnit.test('using the view helper with a string (inline form) is deprecated [DEPRECATED]', function(assert) { | ||
const ViewClass = EmberView.extend({ | ||
template: compile('fooView') | ||
}); | ||
registry.register('view:foo', ViewClass); | ||
|
||
expectDeprecation(function() { | ||
component = EmberComponent.extend({ | ||
layout: compile("{{view 'foo'}}"), | ||
container | ||
}).create(); | ||
|
||
runAppend(component); | ||
}, /Using the `{{view "string"}}` helper is deprecated/); | ||
|
||
assert.equal(component.$().text(), 'fooView', 'view helper is still rendered'); | ||
}); | ||
|
||
QUnit.test('using the view helper with a string (block form) is deprecated [DEPRECATED]', function(assert) { | ||
const ViewClass = EmberView.extend({ | ||
template: compile('Foo says: {{yield}}') | ||
}); | ||
registry.register('view:foo', ViewClass); | ||
|
||
expectDeprecation(function() { | ||
component = EmberComponent.extend({ | ||
layout: compile("{{#view 'foo'}}I am foo{{/view}}"), | ||
container | ||
}).create(); | ||
|
||
runAppend(component); | ||
}, /Using the `{{view "string"}}` helper is deprecated/); | ||
|
||
assert.equal(component.$().text(), 'Foo says: I am foo', 'view helper is still rendered'); | ||
}); | ||
|
||
QUnit.test('using the view helper with string "select" has its own deprecation message [DEPRECATED]', function(assert) { | ||
registry.register('view:select', EmberSelectView); | ||
|
||
expectDeprecation(function() { | ||
component = EmberComponent.extend({ | ||
layout: compile("{{view 'select'}}"), | ||
container | ||
}).create(); | ||
|
||
runAppend(component); | ||
}, /Using `{{view "select"}}` is deprecated/); | ||
|
||
assert.ok(!!component.$('select').length, 'still renders select'); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/ember-template-compiler/lib/plugins/deprecate-view-helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Ember from "ember-metal/core"; | ||
import calculateLocationDisplay from "ember-template-compiler/system/calculate-location-display"; | ||
|
||
function DeprecateViewHelper(options) { | ||
// set later within HTMLBars to the syntax package | ||
this.syntax = null; | ||
this.options = options || {}; | ||
} | ||
|
||
/** | ||
@private | ||
@method transform | ||
@param {AST} ast The AST to be transformed. | ||
*/ | ||
DeprecateViewHelper.prototype.transform = function DeprecateViewHelper_transform(ast) { | ||
if (!!Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT) { | ||
return ast; | ||
} | ||
var walker = new this.syntax.Walker(); | ||
var moduleName = this.options && this.options.moduleName; | ||
|
||
walker.visit(ast, function(node) { | ||
if (!validate(node)) { return; } | ||
|
||
deprecateHelper(moduleName, node); | ||
}); | ||
|
||
return ast; | ||
}; | ||
|
||
function deprecateHelper(moduleName, node) { | ||
const paramValue = node.params.length && node.params[0].value; | ||
|
||
if (!paramValue) { | ||
return; | ||
} else if (paramValue === 'select') { | ||
deprecateSelect(moduleName, node); | ||
} else { | ||
Ember.deprecate(`Using the \`{{view "string"}}\` helper is deprecated. ${calculateLocationDisplay(moduleName, node.loc)}`, false, { url: 'http://emberjs.com/deprecations/v1.x#toc_ember-view', id: 'view.helper' }); | ||
} | ||
} | ||
|
||
function deprecateSelect(moduleName, node) { | ||
Ember.deprecate(`Using \`{{view "select"}}\` is deprecated. ${calculateLocationDisplay(moduleName, node.loc)}`, false, { url: 'http://emberjs.com/deprecations/v1.x#toc_ember-select', id: 'view.helper.select' }); | ||
} | ||
|
||
function validate(node) { | ||
return (node.type === 'MustacheStatement' || node.type === 'BlockStatement') && | ||
(node.path.parts[0] === 'view'); | ||
} | ||
|
||
export default DeprecateViewHelper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters