From b727fc9a4d8bfd4cf7c8128479cd15aa642be71f Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 2 Apr 2024 12:24:45 -0400 Subject: [PATCH] making types more strict --- packages/compat/src/resolver-transform.ts | 52 ++++++++++++----------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/compat/src/resolver-transform.ts b/packages/compat/src/resolver-transform.ts index 17bf3312f..7d160333c 100644 --- a/packages/compat/src/resolver-transform.ts +++ b/packages/compat/src/resolver-transform.ts @@ -114,25 +114,25 @@ const builtInKeywords: Record = { interface ComponentResolution { type: 'component'; specifier: string; + importedName: string; yieldsComponents: Required['yieldsSafeComponents']; yieldsArguments: Required['yieldsArguments']; argumentsAreComponents: string[]; - nameHint?: string; - namedImport?: string; + nameHint: string; } type HelperResolution = { type: 'helper'; - nameHint?: string; - namedImport?: string; + nameHint: string; specifier: string; + importedName: string; }; type ModifierResolution = { type: 'modifier'; specifier: string; - nameHint?: string; - namedImport?: string; + importedName: string; + nameHint: string; }; type ResolutionResult = ComponentResolution | HelperResolution | ModifierResolution; @@ -186,14 +186,9 @@ class TemplateResolver implements ASTPlugin { case 'component': case 'modifier': case 'helper': { - let name = this.env.meta.jsutils.bindImport( - resolution.specifier, - resolution.namedImport ?? 'default', - parentPath, - { - nameHint: resolution.nameHint, - } - ); + let name = this.env.meta.jsutils.bindImport(resolution.specifier, resolution.importedName, parentPath, { + nameHint: resolution.nameHint, + }); setter(parentPath.node, this.env.syntax.builders.path(name)); return; } @@ -407,14 +402,15 @@ class TemplateResolver implements ASTPlugin { const builtIn = builtInKeywords[name]; if (builtIn?.importableComponent) { - let [namedImport, specifier] = builtIn.importableComponent; + let [importedName, specifier] = builtIn.importableComponent; return { type: 'component', specifier, + importedName, yieldsComponents: [], yieldsArguments: [], argumentsAreComponents: [], - namedImport, + nameHint: importedName, }; } @@ -429,6 +425,7 @@ class TemplateResolver implements ASTPlugin { return { type: 'component', specifier: `#embroider_compat/components/${name}`, + importedName: 'default', yieldsComponents: componentRules ? componentRules.yieldsSafeComponents : [], yieldsArguments: componentRules ? componentRules.yieldsArguments : [], argumentsAreComponents: componentRules ? componentRules.argumentsAreComponents : [], @@ -488,11 +485,12 @@ class TemplateResolver implements ASTPlugin { const builtIn = builtInKeywords[path]; if (builtIn?.importableHelper) { - let [namedImport, specifier] = builtIn.importableHelper; + let [importedName, specifier] = builtIn.importableHelper; return { type: 'helper', specifier, - namedImport, + importedName, + nameHint: importedName, }; } @@ -503,6 +501,7 @@ class TemplateResolver implements ASTPlugin { return { type: 'helper', specifier: `#embroider_compat/helpers/${path}`, + importedName: 'default', nameHint: this.nameHint(path), }; } @@ -571,23 +570,25 @@ class TemplateResolver implements ASTPlugin { let builtIn = builtInKeywords[path]; if (builtIn?.importableComponent) { - let [namedImport, specifier] = builtIn.importableComponent; + let [importedName, specifier] = builtIn.importableComponent; return { type: 'component', specifier, + importedName, yieldsComponents: [], yieldsArguments: [], argumentsAreComponents: [], - namedImport, + nameHint: importedName, }; } if (builtIn?.importableHelper) { - let [namedImport, specifier] = builtIn.importableHelper; + let [importedName, specifier] = builtIn.importableHelper; return { type: 'helper', specifier, - namedImport, + importedName, + nameHint: importedName, }; } @@ -642,6 +643,7 @@ class TemplateResolver implements ASTPlugin { return { type: 'component', specifier: `#embroider_compat/ambiguous/${path}`, + importedName: 'default', yieldsComponents: componentRules ? componentRules.yieldsSafeComponents : [], yieldsArguments: componentRules ? componentRules.yieldsArguments : [], argumentsAreComponents: componentRules ? componentRules.argumentsAreComponents : [], @@ -656,11 +658,12 @@ class TemplateResolver implements ASTPlugin { const builtIn = builtInKeywords[path]; if (builtIn?.importableModifier) { - let [namedImport, specifier] = builtIn.importableModifier; + let [importedName, specifier] = builtIn.importableModifier; return { type: 'modifier', specifier, - namedImport, + importedName, + nameHint: importedName, }; } @@ -671,6 +674,7 @@ class TemplateResolver implements ASTPlugin { return { type: 'modifier', specifier: `#embroider_compat/modifiers/${path}`, + importedName: 'default', nameHint: this.nameHint(path), }; }