Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,16 @@ function isNoFalsePositive(diag: Diagnostic, doc: Document): boolean {
return true;
}

// TypeScript transpiles `export enum A` to `export var A`, which the compiler will warn about.
// TypeScript transpiles `export enum A` and `export namespace A` to `export var A`,
// which the compiler will warn about.
// Silence this edge case. We extract the property from the message and don't use the position
// because that position could be wrong when source mapping trips up.
const unusedExportName = diag.message.substring(
diag.message.indexOf("'") + 1,
diag.message.lastIndexOf("'")
);
const hasExportedEnumWithThatName = new RegExp(
`\\bexport\\s+?enum\\s+?${unusedExportName}\\b`
`\\bexport\\s+?(enum|namespace)\\s+?${unusedExportName}\\b`
).test(doc.getText());
return !hasExportedEnumWithThatName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,35 @@ describe('SveltePlugin#getDiagnostics', () => {
).toEqual([]);
});

it('filter out false positive warning (export namespace)', async () => {
(
await expectDiagnosticsFor({
docText:
'<script context="module">export namespace foo { export function bar() {} }</script>',
getTranspiled: () => ({
getOriginalPosition: (pos: Position) => {
return pos;
}
}),
getCompiled: () =>
Promise.resolve({
stats: {
warnings: [
{
start: { line: 1, column: 43 },
end: { line: 1, column: 46 },
message:
"Component has unused export property 'foo'. If it is for external reference only, please consider using `export const foo`",
code: 'unused-export-let'
}
]
}
}),
config: {}
})
).toEqual([]);
});

it('filter out warnings', async () => {
(
await expectDiagnosticsFor({
Expand Down