-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11418 from bantic/deprecate-ember-view-select
[BUGFIX beta] Deprecate {{view "string"}} and special case {{view "select"}}
- 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