Skip to content

Commit

Permalink
fix(core): find imports in export type statements
Browse files Browse the repository at this point in the history
The "analyzeSourceFiles" functionality which automatically detects deps
does not currently file "import" requests in statements using the
relatively new `export type ... from "..."` syntax. This is happening
because the scanner does not find an asterick or curly-bracket after
the `export` keyword, so it strips that export statement from the
code.
  • Loading branch information
spalger committed Dec 20, 2022
1 parent e12922b commit d65c336
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/nx/src/utils/strip-source-code.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import('./module.ts')`;
} from './a';
export { B } from './b';
export type { B } from './b';
export { C as D } from './c';
Expand All @@ -58,6 +59,7 @@ export {
A
} from './a'
export { B } from './b'
export type { B } from './b'
export { C as D } from './c'`;

expect(stripSourceCode(scanner, input)).toEqual(expected);
Expand Down
5 changes: 3 additions & 2 deletions packages/nx/src/utils/strip-source-code.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Scanner } from 'typescript';

let SyntaxKind;
let SyntaxKind: typeof import('typescript').SyntaxKind;
export function stripSourceCode(scanner: Scanner, contents: string): string {
if (!SyntaxKind) {
SyntaxKind = require('typescript').SyntaxKind;
Expand Down Expand Up @@ -68,7 +68,8 @@ export function stripSourceCode(scanner: Scanner, contents: string): string {
}
if (
token === SyntaxKind.OpenBraceToken ||
token === SyntaxKind.AsteriskToken
token === SyntaxKind.AsteriskToken ||
token === SyntaxKind.TypeKeyword
) {
start = potentialStart;
}
Expand Down

0 comments on commit d65c336

Please sign in to comment.