-
-
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 #19691 from mixonic/mixonic/asset-named
Add build assertion against `{{outlet named}}`
- Loading branch information
Showing
4 changed files
with
66 additions
and
140 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
37 changes: 37 additions & 0 deletions
37
packages/ember-template-compiler/lib/plugins/assert-against-named-outlets.ts
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,37 @@ | ||
import { assert } from '@ember/debug'; | ||
import { AST, ASTPlugin } from '@glimmer/syntax'; | ||
import calculateLocationDisplay from '../system/calculate-location-display'; | ||
import { EmberASTPluginEnvironment } from '../types'; | ||
|
||
/** | ||
@module ember | ||
*/ | ||
|
||
/** | ||
Prevents usage of named outlets, a legacy concept in Ember removed in 4.0. | ||
@private | ||
@class AssertAgainstNamedOutlets | ||
*/ | ||
export default function assertAgainstNamedOutlets(env: EmberASTPluginEnvironment): ASTPlugin { | ||
let moduleName = env.meta?.moduleName; | ||
|
||
return { | ||
name: 'assert-against-named-outlets', | ||
|
||
visitor: { | ||
MustacheStatement(node: AST.MustacheStatement) { | ||
if ( | ||
node.path.type === 'PathExpression' && | ||
node.path.original === 'outlet' && | ||
node.params[0] | ||
) { | ||
let sourceInformation = calculateLocationDisplay(moduleName, node.loc); | ||
assert( | ||
`Named outlets were removed in Ember 4.0. See https://deprecations.emberjs.com/v3.x#toc_route-render-template for guidance on alternative APIs for named outlet use cases. ${sourceInformation}` | ||
); | ||
} | ||
}, | ||
}, | ||
}; | ||
} |
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
26 changes: 26 additions & 0 deletions
26
packages/ember-template-compiler/tests/plugins/assert-against-named-outlets-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,26 @@ | ||
import { compile } from '../../index'; | ||
import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; | ||
|
||
moduleFor( | ||
'ember-template-compiler: assert-against-named-outlets', | ||
class extends AbstractTestCase { | ||
[`named outlets are asserted against`]() { | ||
expectAssertion(() => { | ||
compile(`{{outlet 'foo'}}`, { | ||
moduleName: 'baz/foo-bar', | ||
}); | ||
}, `Named outlets were removed in Ember 4.0. See https://deprecations.emberjs.com/v3.x#toc_route-render-template for guidance on alternative APIs for named outlet use cases. ('baz/foo-bar' @ L1:C5) `); | ||
|
||
expectAssertion(() => { | ||
compile(`{{outlet foo}}`, { | ||
moduleName: 'baz/foo-bar', | ||
}); | ||
}, `Named outlets were removed in Ember 4.0. See https://deprecations.emberjs.com/v3.x#toc_route-render-template for guidance on alternative APIs for named outlet use cases. ('baz/foo-bar' @ L1:C5) `); | ||
|
||
// No assertion | ||
compile(`{{outlet}}`, { | ||
moduleName: 'baz/foo-bar', | ||
}); | ||
} | ||
} | ||
); |