Skip to content

Commit

Permalink
Fix: "Got unexpected undefined" error when using a re-exported type (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Dec 19, 2021
1 parent 931ecd5 commit 8823770
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 1 deletion.
@@ -0,0 +1,4 @@
type fuga = "fuga";
export type Baz = `${fuga}`;

//# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
export type bar = 'bar';
@@ -0,0 +1 @@
export type fuga = "fuga";
@@ -0,0 +1,2 @@
export * from "./bar";
export * from "./fuga";
@@ -0,0 +1,2 @@
import { fuga } from './hoge';
export type Baz = `${fuga}`
@@ -0,0 +1,6 @@
{
"name": "ts-types-re-exporting-aggregating",
"private": true,
"main": "dist/main.js",
"types": "dist/types.d.ts"
}
27 changes: 27 additions & 0 deletions packages/core/integration-tests/test/ts-types.js
Expand Up @@ -361,4 +361,31 @@ describe('typescript types', function () {
);
assert.equal(dist, expected);
});

it('should handle re-exporting aggregating correctly', async function () {
await bundle(
path.join(
__dirname,
'/integration/ts-types/re-exporting-aggregating/index.ts',
),
);

let dist = (
await outputFS.readFile(
path.join(
__dirname,
'/integration/ts-types/re-exporting-aggregating/dist/types.d.ts',
),
'utf8',
)
).replace(/\r\n/g, '\n');
let expected = await inputFS.readFile(
path.join(
__dirname,
'/integration/ts-types/re-exporting-aggregating/expected.d.ts',
),
'utf8',
);
assert.equal(dist, expected);
});
});
5 changes: 4 additions & 1 deletion packages/transformers/typescript-types/src/TSModuleGraph.js
Expand Up @@ -143,10 +143,13 @@ export class TSModuleGraph {
if (e.name === name) {
return this.getExport(module, e);
} else if (e.specifier) {
return this.resolveExport(
const m = this.resolveExport(
nullthrows(this.getModule(e.specifier)),
name,
);
if (m) {
return m;
}
}
}
}
Expand Down

0 comments on commit 8823770

Please sign in to comment.