Skip to content

Commit

Permalink
fix: Resolve runtime error with CommonJS module imports from 'typescr…
Browse files Browse the repository at this point in the history
…ipt'

Fixes #58
  • Loading branch information
pmpak committed Nov 18, 2024
1 parent 59ba643 commit 719f746
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/utils/ast-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ import pkg, {
StringLiteral,
SourceFile,
PropertyDeclaration,
PropertyAccessExpression,
isPropertyAccessExpression,
isCallExpression
PropertyAccessExpression
} from 'typescript';
const { SyntaxKind, isStringLiteralLike, isArrayLiteralExpression, isBinaryExpression, isConditionalExpression } = pkg;

// Importing non-type members from 'typescript' this way to prevent runtime errors such as:
// `SyntaxError: Named export 'isCallExpression' not found. The requested module 'typescript' is a CommonJS module,
// which may not support all module.exports as named exports.`
const {
isArrayLiteralExpression,
isBinaryExpression,
isCallExpression,
isConditionalExpression,
isPropertyAccessExpression,
isStringLiteralLike,
SyntaxKind
} = pkg;

export function getAST(source: string, fileName = ''): SourceFile {
const supportedScriptTypes: Record<string, ScriptKind> = {
Expand Down

0 comments on commit 719f746

Please sign in to comment.