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

[BUGFIX lts] Ensure Component Lookup Is Well Formed #19336

Merged
merged 2 commits into from
Jan 14, 2021
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-template-compiler/lib/system/compile-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EMBER_STRICT_MODE } from '@ember/canary-features';
import { assert } from '@ember/debug';
import { assign } from '@ember/polyfills';
import { PrecompileOptions } from '@glimmer/compiler';
import { AST, ASTPlugin, ASTPluginEnvironment, Syntax } from '@glimmer/syntax';
Expand All @@ -8,6 +9,10 @@ import COMPONENT_NAME_SIMPLE_DASHERIZE_CACHE from './dasherize-component-name';

let USER_PLUGINS: PluginFunc[] = [];

function malformedComponentLookup(string: string) {
return string.indexOf('::') === -1 && string.indexOf(':') > -1;
}

export default function compileOptions(
_options: Partial<EmberPrecompileOptions> = {}
): PrecompileOptions {
Expand All @@ -16,6 +21,11 @@ export default function compileOptions(
_options,
{
customizeComponentName(tagname: string): string {
assert(
`You tried to invoke a component named <${tagname} /> in "${_options.moduleName}", but that is not a valid name for a component. Did you mean to use the "::" syntax for nested components?`,
!malformedComponentLookup(tagname)
);

return COMPONENT_NAME_SIMPLE_DASHERIZE_CACHE.get(tagname);
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ moduleFor(
assert.notEqual(compileOptions(), compileOptions());
}

['@test customizeComponentName asserts name is well formed'](assert) {
let options = compileOptions({ moduleName: 'test.js' });

expectAssertion(() => {
options.customizeComponentName('Foo:Bar');
}, /You tried to invoke a component named <Foo:Bar \/> in "test.js", but that is not a valid name for a component. Did you mean to use the "::" syntax for nested components\?/);

assert.ok(options.customizeComponentName('Foo::Bar'));
}

['@test has default AST plugins in resolution mode'](assert) {
assert.expect(RESOLUTION_MODE_TRANSFORMS.length);

Expand Down