Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript): normalize emittedFiles to prevent unrecoginized token #1377

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/typescript/src/index.ts
Expand Up @@ -69,7 +69,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
if (parsedOptions.options.composite || parsedOptions.options.incremental) {
tsCache.cacheCode(fileName, data);
}
emittedFiles.set(fileName, data);
emittedFiles.set(fileName.toLowerCase(), data);
},
status(diagnostic) {
watchProgramHelper.handleStatus(diagnostic);
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript/src/outputFile.ts
Expand Up @@ -41,8 +41,8 @@ export function getEmittedFile(
): string | undefined {
let code: string | undefined;
if (fileName) {
if (emittedFiles.has(fileName)) {
code = emittedFiles.get(fileName);
if (emittedFiles.has(fileName.toLowerCase())) {
code = emittedFiles.get(fileName.toLowerCase());
} else {
code = tsCache.getCached(fileName);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/test/fixtures/caseTest/Main.ts
@@ -0,0 +1,3 @@
const answer = 42;
// eslint-disable-next-line no-console
console.log(`the answer is ${answer}`);
1 change: 1 addition & 0 deletions packages/typescript/test/fixtures/caseTest/tsconfig.json
@@ -0,0 +1 @@
{}
24 changes: 24 additions & 0 deletions packages/typescript/test/test.js
Expand Up @@ -1346,3 +1346,27 @@ test.serial('noForceEmit option defers to tsconfig.json for noEmit', async (t) =
const originalCode = fs.readFileSync(path.join(__dirname, input), 'utf8');
t.is(output[0].code, originalCode);
});

test.serial('incorrect file case still compiles', async (t) => {
const warnings = [];
const bundle = await rollup({
input: 'fixtures/caseTest/Main.ts',
plugins: [typescript({ tsconfig: 'fixtures/caseTest/tsconfig.json', target: 'es5' })],
onwarn(warning) {
warnings.push(warning);
}
});
// generate a single output bundle, in which case, declaration files were not correctly emitted
const output = await getCode(
bundle,
{ format: 'es', file: 'fixtures/caseTest/dist/Main.js' },
true
);

t.deepEqual(
output.map((out) => out.fileName),
// no `main.d.ts`, main.js is passed through
['Main.js']
);
t.is(warnings.length, 0);
});