Skip to content

Commit

Permalink
fix: regular analysis of System.register may get stuck (jspm#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiansheng committed Dec 4, 2024
1 parent dfce0ab commit 6dd1f6f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/trace/analysis.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import babel from '@babel/core'
import { JspmError } from "../common/err.js";
import { getIntegrity } from "../common/integrity.js";

Expand Down Expand Up @@ -32,7 +33,8 @@ export async function createEsmAnalysis(
source: string,
url: string
): Promise<Analysis> { // Change the return type to Promise<Analysis>
if (!imports.length && registerRegEx.test(source))
const coolSource = babel.transformSync(source, {comments: false}).code;
if (!imports.length && registerRegEx.test(coolSource))
return createSystemAnalysis(source, imports, url);
const deps: string[] = [];
const dynamicDeps: string[] = [];
Expand Down Expand Up @@ -75,7 +77,8 @@ export async function createSystemAnalysis(
imports: string[],
url: string
): Promise<Analysis> {
const [, , , rawDeps, , , contextId] = source.match(registerRegEx) || [];
const coolSource = babel.transformSync(source, {comments: false}).code;
const [, , , rawDeps, , , contextId] = coolSource.match(registerRegEx) || [];
if (!rawDeps) return createEsmAnalysis(imports, source, url);
const deps = JSON.parse(rawDeps.replace(/'/g, '"'));
const dynamicDeps: string[] = [];
Expand Down

0 comments on commit 6dd1f6f

Please sign in to comment.