MCPcopy
hub / github.com/midrender/revideo / resolveGlsl

Function resolveGlsl

packages/vite-plugin/src/partials/webgl.ts:75–121  ·  view source on GitHub ↗
(
  context: ResolutionContext,
  id: string,
  code: string,
)

Source from the content-addressed store, hash-verified

73}
74
75async function resolveGlsl(
76 context: ResolutionContext,
77 id: string,
78 code: string,
79): Promise<SourceNode> {
80 const lines = code.split(/\r?\n/);
81 const source = new SourceNode(1, 0, '', '');
82
83 if (context.fileStack.includes(id)) {
84 throw new Error(
85 `Circular dependency detected: ${context.fileStack.join(' -> ')}`,
86 );
87 }
88
89 context.fileStack.push(id);
90
91 const sourceMapId = path.posix.relative(context.rootDir, id);
92 for (let i = 0; i < lines.length; i++) {
93 const line = lines[i];
94 const match = line.match(INCLUDE_REGEX);
95 if (match) {
96 const childId = await context.resolve(match[1], id);
97 if (!childId) {
98 continue;
99 }
100
101 const childSourceMapId = path.posix.relative(context.rootDir, childId);
102 if (context.includeMap.has(childSourceMapId)) {
103 continue;
104 }
105
106 context.includeMap.set(childSourceMapId, [sourceMapId, i + 1]);
107 context.watchFile(childId);
108 const childCode = await fs.promises.readFile(childId, 'utf-8');
109 source.add(await resolveGlsl(context, childId, childCode));
110 } else {
111 let j = 0;
112 for (; j < line.length; j++) {
113 source.add(new SourceNode(i + 1, j, sourceMapId, line[j]));
114 }
115 source.add(new SourceNode(i + 1, j, sourceMapId, '\n'));
116 }
117 }
118 context.fileStack.pop();
119
120 return source;
121}

Callers 1

transformFunction · 0.85

Calls 4

addMethod · 0.95
includesMethod · 0.80
setMethod · 0.65
splitMethod · 0.45

Tested by

no test coverage detected