MCPcopy Index your code
hub / github.com/CoderLine/alphaTab / getWorkerType

Function getWorkerType

packages/vite/src/importMetaPlugin.ts:73–107  ·  view source on GitHub ↗
(code: string, match: RegExpExecArray)

Source from the content-addressed store, hash-verified

71}
72
73function getWorkerType(code: string, match: RegExpExecArray): AlphaTabWorkerTypes {
74 if (match[1].includes('.addModule')) {
75 return AlphaTabWorkerTypes.AudioWorklet;
76 }
77
78 const endOfMatch = match.indices![0]![1];
79
80 const startOfOptions = code.indexOf('{', endOfMatch);
81 if (startOfOptions === -1) {
82 return AlphaTabWorkerTypes.WorkerClassic;
83 }
84
85 const endOfOptions = code.indexOf('}', endOfMatch);
86 if (endOfOptions === -1) {
87 return AlphaTabWorkerTypes.WorkerClassic;
88 }
89
90 const endOfWorkerCreate = code.indexOf(')', endOfMatch);
91 if (startOfOptions > endOfWorkerCreate || endOfOptions > endOfWorkerCreate) {
92 return AlphaTabWorkerTypes.WorkerClassic;
93 }
94
95 let workerOptions: string | null | { type: string } = code.slice(startOfOptions, endOfOptions + 1);
96 try {
97 workerOptions = evalValue(workerOptions);
98 } catch {
99 return AlphaTabWorkerTypes.WorkerClassic;
100 }
101
102 if (typeof workerOptions === 'object' && workerOptions?.type === 'module') {
103 return AlphaTabWorkerTypes.WorkerModule;
104 }
105
106 return AlphaTabWorkerTypes.WorkerClassic;
107}
108
109/**
110 * @public

Callers 1

transformFunction · 0.85

Calls 4

evalValueFunction · 0.90
includesMethod · 0.80
indexOfMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected