Skip to content

Commit 3c84d82

Browse files
committed
Work work
1 parent 7155351 commit 3c84d82

File tree

7 files changed

+111
-7
lines changed

7 files changed

+111
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<% if (componentClass === '@glimmer/component') {%>import Component from '@glimmer/component';
2+
3+
<%= componentSignature %>
4+
export default class <%= classifiedModuleName %> extends Component<<%= classifiedModuleName %>Signature> {
5+
<template>
6+
{{yield}}
7+
</template>
8+
}<%} else {%>import type { TOC } from '@ember/component/template-only';
9+
10+
<%= componentSignature %>
111
<template>
212
{{yield}}
3-
</template>
13+
</template> satisfies TOC<<%= classifiedModuleName %>Signature>;<%}%>

blueprints/component/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const chalk = require('chalk');
44
const stringUtil = require('ember-cli-string-utils');
55
const getPathOption = require('ember-cli-get-component-path-option');
66
const normalizeEntityName = require('ember-cli-normalize-entity-name');
7+
const SilentError = require('silent-error');
78
const { generateComponentSignature } = require('../-utils');
89

910
const typescriptBlueprintPolyfill = require('ember-cli-typescript-blueprint-polyfill');
@@ -69,6 +70,18 @@ module.exports = {
6970
options.componentClass = '';
7071
}
7172

73+
if (options.componentAuthoringFormat === 'strict') {
74+
if (options.componentClass === '@ember/component') {
75+
throw new SilentError(
76+
'The "@ember/component" component class cannot be used in combination with the "--strict" flag'
77+
);
78+
}
79+
80+
if (options.componentClass === '') {
81+
options.componentClass = '@ember/component/template-only';
82+
}
83+
}
84+
7285
return this._super.install.apply(this, arguments);
7386
},
7487

@@ -193,6 +206,7 @@ module.exports = {
193206
}
194207

195208
return {
209+
classifiedModuleName,
196210
importTemplate,
197211
importComponent,
198212
componentSignature,

node-tests/blueprints/component-test.js

+42-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
44
const setupTestHooks = blueprintHelpers.setupTestHooks;
55
const emberNew = blueprintHelpers.emberNew;
6+
const emberGenerate = blueprintHelpers.emberGenerate;
67
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
78
const modifyPackages = blueprintHelpers.modifyPackages;
89

@@ -27,11 +28,6 @@ const templateOnlyContents = `import templateOnly from '@ember/component/templat
2728
export default templateOnly();
2829
`;
2930

30-
const templateTagContents = `<template>
31-
{{yield}}
32-
</template>
33-
`;
34-
3531
describe('Blueprint: component', function () {
3632
setupTestHooks(this);
3733

@@ -278,9 +274,49 @@ describe('Blueprint: component', function () {
278274

279275
it('component foo --strict', function () {
280276
return emberGenerateDestroy(['component', 'foo', '--strict'], (_file) => {
281-
expect(_file('app/components/foo.gjs')).to.equal(templateTagContents);
277+
expect(_file('app/components/foo.gjs')).to.equal(
278+
fixture('component/template-only-component.gjs')
279+
);
280+
});
281+
});
282+
283+
it('component foo --strict --component-class=@glimmer/component', function () {
284+
return emberGenerateDestroy(
285+
['component', 'foo', '--strict', '--component-class=@glimmer/component'],
286+
(_file) => {
287+
expect(_file('app/components/foo.gjs')).to.equal(
288+
fixture('component/glimmer-component.gjs')
289+
);
290+
}
291+
);
292+
});
293+
294+
it('component foo --strict --component-class=@ember/component', async function () {
295+
await expect(
296+
emberGenerate(['component', 'foo', '--strict', '--component-class=@ember/component'])
297+
).to.be.rejectedWith(
298+
'The "@ember/component" component class cannot be used in combination with the "--strict" flag'
299+
);
300+
});
301+
302+
it('component foo --strict --typescript', function () {
303+
return emberGenerateDestroy(['component', 'foo', '--strict', '--typescript'], (_file) => {
304+
expect(_file('app/components/foo.gts')).to.equal(
305+
fixture('component/template-only-component.gts')
306+
);
282307
});
283308
});
309+
310+
it('component foo --strict --component-class=@glimmer/component --typescript', function () {
311+
return emberGenerateDestroy(
312+
['component', 'foo', '--strict', '--component-class=@glimmer/component', '--typescript'],
313+
(_file) => {
314+
expect(_file('app/components/foo.gts')).to.equal(
315+
fixture('component/glimmer-component.gts')
316+
);
317+
}
318+
);
319+
});
284320
});
285321

286322
describe('in addon', function () {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Component from '@glimmer/component';
2+
3+
export default class Foo extends Component {
4+
<template>
5+
{{yield}}
6+
</template>
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Component from '@glimmer/component';
2+
3+
export interface FooSignature {
4+
// The arguments accepted by the component
5+
Args: {};
6+
// Any blocks yielded by the component
7+
Blocks: {
8+
default: []
9+
};
10+
// The element to which `...attributes` is applied in the component template
11+
Element: null;
12+
}
13+
14+
export default class Foo extends Component<FooSignature> {
15+
<template>
16+
{{yield}}
17+
</template>
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
{{yield}}
3+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { TOC } from '@ember/component/template-only';
2+
3+
export interface FooSignature {
4+
// The arguments accepted by the component
5+
Args: {};
6+
// Any blocks yielded by the component
7+
Blocks: {
8+
default: []
9+
};
10+
// The element to which `...attributes` is applied in the component template
11+
Element: null;
12+
}
13+
14+
<template>
15+
{{yield}}
16+
</template> satisfies TOC<FooSignature>;

0 commit comments

Comments
 (0)