Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Oct 10, 2022
1 parent a83ab2c commit 685d10c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils/parseAssertions.ts
Expand Up @@ -19,7 +19,7 @@ export function getAssertionsFromImportExpression(node: ImportExpression): Recor
const key = getPropertyKey(property);
if (
typeof key === 'string' &&
typeof ((property as Property).value as Literal)?.value === 'string'
typeof ((property as Property).value as Literal).value === 'string'
) {
return [key, ((property as Property).value as Literal).value] as [string, string];
}
Expand All @@ -34,9 +34,10 @@ export function getAssertionsFromImportExpression(node: ImportExpression): Recor

const getPropertyKey = (
property: Property | SpreadElement | ImportAttribute
): LiteralValue | undefined =>
((property as Property | ImportAttribute).key as Identifier).name ||
((property as Property | ImportAttribute).key as Literal).value;
): LiteralValue | undefined => {
const key = (property as Property | ImportAttribute).key;
return key && ((key as Identifier).name || (key as Literal).value);
};

export function getAssertionsFromImportExportDeclaration(
assertions: ImportAttribute[] | undefined
Expand Down
@@ -0,0 +1,7 @@
module.exports = {
description: 'handles special shapes of assertions',
expectedWarnings: 'UNRESOLVED_IMPORT',
options: {
external: () => true
}
};
@@ -0,0 +1,4 @@
import('external-a', { assert: { type: 'json' } });
import('external-b');
import('external-c');
import('external-d');
4 changes: 4 additions & 0 deletions test/form/samples/import-assertions/assertion-shapes/main.js
@@ -0,0 +1,4 @@
import('external-a', { 'assert': { 'type': 'json', foo: 1, ...{} } });
import('external-b', { assert: {} });
import('external-c', { ...{} });
import('external-d', {});

0 comments on commit 685d10c

Please sign in to comment.