239
}
240
};
241
242
+export type FindSourceMapURLCallback = (fileName: string) => null | string;
243
+
244
export type Response = {
245
_bundlerConfig: SSRModuleMap,
246
_moduleLoading: ModuleLoading,
257
_buffer: Array<Uint8Array>, // chunks received so far as part of this row
258
_tempRefs: void | TemporaryReferenceSet, // the set temporary references can be resolved from
259
_debugRootTask?: null | ConsoleTask, // DEV-only
260
+ _debugFindSourceMapURL?: void | FindSourceMapURLCallback, // DEV-only
261
};
262
263
function readChunk<T>(chunk: SomeChunk<T>): T {
699
console,
700
getTaskName(type),
701
);
699
- const callStack = buildFakeCallStack(stack, createTaskFn);
702
+ const callStack = buildFakeCallStack(response, stack, createTaskFn);
703
// This owner should ideally have already been initialized to avoid getting
704
// user stack frames on the stack.
705
const ownerTask =
1143
encodeFormAction: void | EncodeFormActionCallback,
1144
nonce: void | string,
1145
temporaryReferences: void | TemporaryReferenceSet,
1146
+ findSourceMapURL: void | FindSourceMapURLCallback,
1147
): Response {
1148
const chunks: Map<number, SomeChunk<any>> = new Map();
1149
const response: Response = {
1170
// TODO: Make this string configurable.
1171
response._debugRootTask = (console: any).createTask('"use server"');
1172
}
1173
+ if (__DEV__) {
1174
+ response._debugFindSourceMapURL = findSourceMapURL;
1175
+ }
1176
// Don't inline this call because it causes closure to outline the call above.
1177
response._fromJSON = createFromJSONCallback(response);
1178
return response;
1680
function createFakeFunction<T>(
1681
name: string,
1682
filename: string,
1683
+ sourceMap: null | string,
1684
line: number,
1685
col: number,
1686
): FakeFunction<T> {
1705
'_()\n';
1706
}
1707
1700
- if (filename) {
1708
+ if (sourceMap) {
1709
+ code += '//# sourceMappingURL=' + sourceMap;
1710
+ } else if (filename) {
1711
code += '//# sourceURL=' + filename;
1712
}
1713
1730
return fn;
1731
}
1732
1733
+// This matches either of these V8 formats.
1734
+// at name (filename:0:0)
1735
+// at filename:0:0
1736
+// at async filename:0:0
1737
const frameRegExp =
1724
- /^ {3} at (?:(.+) \(([^\)]+):(\d+):(\d+)\)|([^\)]+):(\d+):(\d+))$/;
1738
+ /^ {3} at (?:(.+) \(([^\)]+):(\d+):(\d+)\)|(?:async )?([^\)]+):(\d+):(\d+))$/;
1739
1726
-function buildFakeCallStack<T>(stack: string, innerCall: () => T): () => T {
1740
+function buildFakeCallStack<T>(
1741
+ response: Response,
1742
+ stack: string,
1743
+ innerCall: () => T,
1744
+): () => T {
1745
const frames = stack.split('\n');
1746
let callStack = innerCall;
1747
for (let i = 0; i < frames.length; i++) {
1757
const filename = parsed[2] || parsed[5] || '';
1758
const line = +(parsed[3] || parsed[6]);
1759
const col = +(parsed[4] || parsed[7]);
1742
- fn = createFakeFunction(name, filename, line, col);
1760
+ const sourceMap = response._debugFindSourceMapURL
1761
+ ? response._debugFindSourceMapURL(filename)
1762
+ : null;
1763
+ fn = createFakeFunction(name, filename, sourceMap, line, col);
1764
+ // TODO: This cache should technically live on the response since the _debugFindSourceMapURL
1765
+ // function is an input and can vary by response.
1766
+ fakeFunctionCache.set(frame, fn);
1767
}
1768
callStack = fn.bind(null, callStack);
1769
}
1794
console,
1795
getServerComponentTaskName(componentInfo),
1796
);
1773
- const callStack = buildFakeCallStack(stack, createTaskFn);
1797
+ const callStack = buildFakeCallStack(response, stack, createTaskFn);
1798
1799
if (ownerTask === null) {
1800
const rootTask = response._debugRootTask;
1856
return;
1857
}
1858
const callStack = buildFakeCallStack(
1859
+ response,
1860
stackTrace,
1861
printToConsole.bind(null, methodName, args, env),
1862
);