Skip to content

Commit

Permalink
making types more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Apr 2, 2024
1 parent 8bde7b9 commit b727fc9
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions packages/compat/src/resolver-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,25 @@ const builtInKeywords: Record<string, BuiltIn | undefined> = {
interface ComponentResolution {
type: 'component';
specifier: string;
importedName: string;
yieldsComponents: Required<ComponentRules>['yieldsSafeComponents'];
yieldsArguments: Required<ComponentRules>['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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
};
}

Expand All @@ -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 : [],
Expand Down Expand Up @@ -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,
};
}

Expand All @@ -503,6 +501,7 @@ class TemplateResolver implements ASTPlugin {
return {
type: 'helper',
specifier: `#embroider_compat/helpers/${path}`,
importedName: 'default',
nameHint: this.nameHint(path),
};
}
Expand Down Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -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 : [],
Expand All @@ -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,
};
}

Expand All @@ -671,6 +674,7 @@ class TemplateResolver implements ASTPlugin {
return {
type: 'modifier',
specifier: `#embroider_compat/modifiers/${path}`,
importedName: 'default',
nameHint: this.nameHint(path),
};
}
Expand Down

0 comments on commit b727fc9

Please sign in to comment.