Skip to content

Commit

Permalink
fix(compiler): address when a home module cannot be found (#4521)
Browse files Browse the repository at this point in the history
  • Loading branch information
alicewriteswrongs committed Jun 28, 2023
1 parent af9639c commit 06eaa8f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
33 changes: 33 additions & 0 deletions src/compiler/transformers/test/parse-props.spec.ts
Expand Up @@ -34,6 +34,39 @@ describe('parse props', () => {
expect(t.cmp?.hasProp).toBe(true);
});

it('should correctly parse a prop with an unresolved type', () => {
const t = transpileModule(`
@Component({tag: 'cmp-a'})
export class CmpA {
@Prop() val?: Foo;
}
`);
expect(getStaticGetter(t.outputText, 'properties')).toEqual({
val: {
attribute: 'val',
complexType: {
references: {
Foo: {
id: 'global::Foo',
location: 'global',
},
},
resolved: 'Foo',
original: 'Foo',
},
docs: {
text: '',
tags: [],
},
mutable: false,
optional: true,
reflect: false,
required: false,
type: 'any',
},
});
});

it('prop required', () => {
const t = transpileModule(`
@Component({tag: 'cmp-a'})
Expand Down
26 changes: 14 additions & 12 deletions src/compiler/transformers/transform-utils.ts
Expand Up @@ -519,18 +519,20 @@ const getTypeReferenceLocation = (
const compilerHost = ts.createCompilerHost(options);
const importHomeModule = getHomeModule(sourceFile, localImportPath, options, compilerHost, program);

const importName = namedImportBindings.elements.find((nbe) => nbe.name.getText() === typeName).name;
const originalTypeName = getOriginalTypeName(importName, checker);

const typeDecl = findTypeWithName(importHomeModule, originalTypeName);
type = checker.getTypeAtLocation(typeDecl);

const id = addToLibrary(type, originalTypeName, checker, normalizePath(importHomeModule.fileName, false));
return {
location: 'import',
path: localImportPath,
id,
};
if (importHomeModule) {
const importName = namedImportBindings.elements.find((nbe) => nbe.name.getText() === typeName).name;
const originalTypeName = getOriginalTypeName(importName, checker);

const typeDecl = findTypeWithName(importHomeModule, originalTypeName);
type = checker.getTypeAtLocation(typeDecl);

const id = addToLibrary(type, originalTypeName, checker, normalizePath(importHomeModule.fileName, false));
return {
location: 'import',
path: localImportPath,
id,
};
}
}

// Loop through all top level exports to find if any reference to the type for 'local' reference location
Expand Down

0 comments on commit 06eaa8f

Please sign in to comment.