-
-
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 #12018 from rwjblue/deprecate-block-crap
[BUGFIX release] Deprecate `{{unbound` block and multi param usage.
- Loading branch information
Showing
6 changed files
with
97 additions
and
3 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
50 changes: 50 additions & 0 deletions
50
packages/ember-template-compiler/lib/plugins/deprecate-unbound-block-and-multi-param.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,50 @@ | ||
import Ember from 'ember-metal/core'; | ||
import calculateLocationDisplay from 'ember-template-compiler/system/calculate-location-display'; | ||
|
||
function DeprecateUnboundBlockAndMultiParam(options) { | ||
// set later within HTMLBars to the syntax package | ||
this.syntax = null; | ||
this.options = options || {}; | ||
} | ||
|
||
DeprecateUnboundBlockAndMultiParam.prototype.transform = function(ast) { | ||
const pluginContext = this; | ||
const walker = new pluginContext.syntax.Walker(); | ||
const moduleName = pluginContext.options.moduleName; | ||
|
||
walker.visit(ast, function(node) { | ||
|
||
if (pluginContext.isBlockUsage(node)) { | ||
let moduleInfo = calculateLocationDisplay(moduleName, node.loc); | ||
|
||
Ember.deprecate( | ||
`Using the {{unbound}} helper with a block ${moduleInfo}is deprecated and will be removed in 2.0.0.`, | ||
false, | ||
{ id: 'ember-template-compiler.unbound-block', until: '2.0.0' } | ||
); | ||
} else if (pluginContext.hasMultipleParams(node)) { | ||
let moduleInfo = calculateLocationDisplay(moduleName, node.loc); | ||
|
||
Ember.deprecate( | ||
`Using the {{unbound}} helper with multiple params ${moduleInfo}is deprecated and will be removed in 2.0.0. Please refactor to nested helper usage.`, | ||
false, | ||
{ id: 'ember-template-compiler.unbound-multiple-params', until: '2.0.0' } | ||
); | ||
} | ||
}); | ||
|
||
return ast; | ||
}; | ||
|
||
DeprecateUnboundBlockAndMultiParam.prototype.isBlockUsage = function(node) { | ||
return node.type === 'BlockStatement' && | ||
node.path.original === 'unbound'; | ||
}; | ||
|
||
DeprecateUnboundBlockAndMultiParam.prototype.hasMultipleParams = function(node) { | ||
return (node.type === 'BlockStatement' || node.type === 'MustacheStatement') && | ||
node.path.original === 'unbound' && | ||
node.params.length > 1; | ||
}; | ||
|
||
export default DeprecateUnboundBlockAndMultiParam; |
33 changes: 33 additions & 0 deletions
33
...es/ember-template-compiler/tests/plugins/deprecate-unbound-block-and-multi-params-test.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,33 @@ | ||
import { compile } from 'ember-template-compiler'; | ||
|
||
QUnit.module('ember-template-compiler: deprecate-unbound-block-and-multi-params'); | ||
|
||
QUnit.test('Using `{{unbound}}` with a block issues a deprecation', function() { | ||
expect(1); | ||
|
||
expectDeprecation(function() { | ||
compile('{{#unbound "foo"}}{{/unbound}}', { | ||
moduleName: 'foo/bar/baz' | ||
}); | ||
}, `Using the {{unbound}} helper with a block ('foo/bar/baz' @ L1:C0) is deprecated and will be removed in 2.0.0.`); | ||
}); | ||
|
||
QUnit.test('Using `{{unbound}}` with multiple params issues a deprecation', function() { | ||
expect(1); | ||
|
||
expectDeprecation(function() { | ||
compile('{{unbound foo bar}}', { | ||
moduleName: 'foo/bar/baz' | ||
}); | ||
}, `Using the {{unbound}} helper with multiple params ('foo/bar/baz' @ L1:C0) is deprecated and will be removed in 2.0.0. Please refactor to nested helper usage.`); | ||
}); | ||
|
||
QUnit.test('Using `{{unbound}}` with a single param is not deprecated', function() { | ||
expect(1); | ||
|
||
compile('{{unbound foo}}', { | ||
moduleName: 'foo/bar/baz' | ||
}); | ||
|
||
ok(true, 'no deprecations or assertions'); | ||
}); |