Skip to content

Commit eebfa28

Browse files
committed
Do not include types in JS blueprints
For the fallback case, where Ember's blueprints are being executed by a version of Ember CLI earlier than 4.3.0, the emitted blueprints *must not* include any TypeScript types, since the CLI will not be able to remove the types. Accordingly: 1. Return a boolean flag from the `maybePolyfillTypeScriptBlueprints` helper, indicating whether the blueprint is in a mode where it can reliably *emit* types. 2. Use that new helper in the component blueprint so that it can avoid emitting a signature type, and specifically can avoid emitting it as a type parameter on the class or function default export.
1 parent 8f9528e commit eebfa28

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

blueprints/-maybe-polyfill-typescript-blueprints.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ function canEmitTypeScript() {
88
}
99

1010
module.exports = function (context) {
11-
if (canEmitTypeScript()) {
11+
let canUseTypeScript = canEmitTypeScript();
12+
if (canUseTypeScript) {
1213
typescriptBlueprintPolyfill(context);
1314
} else {
1415
// Use the plain old JS templates from before
1516
context.path = context.path.replace('blueprints', 'blueprints-js');
1617
}
18+
return canUseTypeScript;
1719
};

blueprints/component/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ module.exports = {
5353
},
5454
],
5555

56+
/**
57+
Flag to let us correctly handle the case where we are running against a
58+
version of Ember CLI which does not support TS-based emit, and where we
59+
therefore *must* not emit a `defaultExport` local which includes a type
60+
parameter in the exported function call or class definition.
61+
*/
62+
_isUsingTS: false,
63+
5664
init() {
5765
this._super && this._super.init.apply(this, arguments);
58-
maybePolyfillTypeScriptBlueprints(this);
66+
this._isUsingTS = maybePolyfillTypeScriptBlueprints(this);
5967
let isOctane = has('octane');
6068

6169
this.availableOptions.forEach((option) => {
@@ -264,13 +272,21 @@ module.exports = {
264272
break;
265273
case '@glimmer/component':
266274
importComponent = `import Component from '@glimmer/component';`;
267-
componentSignature = signatureFor(classifiedModuleName);
268-
defaultExport = `class ${classifiedModuleName}Component extends Component<${classifiedModuleName}Signature> {}`;
275+
if (this._isUsingTS) {
276+
componentSignature = signatureFor(classifiedModuleName);
277+
defaultExport = `class ${classifiedModuleName}Component extends Component<${classifiedModuleName}Signature> {}`;
278+
} else {
279+
defaultExport = `class ${classifiedModuleName}Component extends Component {}`;
280+
}
269281
break;
270282
case '@ember/component/template-only':
271283
importComponent = `import templateOnly from '@ember/component/template-only';`;
272-
componentSignature = signatureFor(classifiedModuleName);
273-
defaultExport = `templateOnly<${classifiedModuleName}Signature>();`;
284+
if (this._isUsingTS) {
285+
componentSignature = signatureFor(classifiedModuleName);
286+
defaultExport = `templateOnly<${classifiedModuleName}Signature>();`;
287+
} else {
288+
defaultExport = `templateOnly();`;
289+
}
274290
break;
275291
}
276292

0 commit comments

Comments
 (0)