Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.warnings.forEach(warning => {
console.warn(warning.message); // eslint-disable-line no-console
dispatch(
actions.correction.show(warning.message, {
line: warning.lineNumber,
column: warning.columnNumber,
path: warning.path,
source: warning.source,
severity: warning.severity || 'warning',
})
);
});
}
}
try {
dispatch({
type: 'eval-result',
error,
result: transformJSON(result),
});
} catch (e) {
console.error(e);
}
}
}
}
listen(handleMessage);
sendReady();
setupHistoryListeners();
setupConsole();
if (process.env.NODE_ENV === 'test' || isStandalone) {
// We need to fetch the sandbox ourselves...
const id = getId();
window
.fetch(host + `/api/v1/sandboxes/${id}`)
.then(res => res.json())
.then(res => camelizeKeys(res))
.then(x => {
const mainModule = findMainModule(
x.data.modules,
x.data.directories,
async function compile({
sandboxId,
modules,
entry,
externalResources,
dependencies,
hasActions,
isModuleView = false,
template,
}) {
const startTime = Date.now();
try {
clearErrorTransformers();
initializeErrorTransformers();
unmount(manager && manager.webpackHMR);
} catch (e) {
console.error(e);
}
actionsEnabled = hasActions;
handleExternalResources(externalResources);
try {
const { manifest, isNewCombination } = await loadDependencies(dependencies);
if (isNewCombination && !firstLoad) {
// Just reset the whole manager if it's a new combination
manager = null;
}
async function compile({
sandboxId,
modules,
directories,
module,
changedModule,
externalResources,
dependencies,
hasActions,
isModuleView = false,
template,
}) {
try {
clearErrorTransformers();
initializeErrorTransformers();
unmount();
} catch (e) {
console.error(e);
}
actionsEnabled = hasActions;
handleExternalResources(externalResources);
try {
// We convert the modules to a format the manager understands
const managerModules = modules.map(m => ({
path: getModulePath(modules, directories, m.id),
code: m.code,
}));
this.warnings.forEach(warning => {
console.warn(warning.message); // eslint-disable-line no-console
dispatch(
actions.correction.show(warning.message, {
line: warning.lineNumber,
column: warning.columnNumber,
path: warning.path,
source: warning.source,
severity: warning.severity || 'warning',
})
);
});
}
this.warnings.forEach(warning => {
console.warn(warning.message); // eslint-disable-line no-console
dispatch(
actions.correction.show(warning.message, {
line: warning.lineNumber,
column: warning.columnNumber,
path: warning.path,
source: warning.source,
severity: 'warning',
})
);
});
}
if (!tModule && relevantFrame) {
const fileName =
relevantFrame._originalFileName || relevantFrame.fileName || '';
tModule = manager.resolveTranspiledModule(
fileName.replace(location.origin, ''),
'/'
);
}
if (!tModule) {
return;
}
try {
const transformation = transformError(
errRef.error,
tModule,
manager.getTranspiledModules()
);
if (transformation) {
const newError = new Error(transformation.name || errRef.error.name);
newError.message = transformation.message;
newError.suggestions = transformation.suggestions;
newError.originalName = errRef.error.name;
newError.originalMessage = errRef.error.message;
errRef.error = newError;
}
} catch (ex) {
/* just catch */
console.error(ex);
if (!tModule && relevantFrame) {
const fileName =
relevantFrame._originalFileName || relevantFrame.fileName || '';
tModule = manager.resolveTranspiledModule(
fileName.replace(location.origin, ''),
'/'
);
}
if (!tModule) {
return;
}
try {
const transformation = transformError(
errRef.error,
tModule,
manager.getTranspiledModules()
);
if (transformation) {
errRef.error.originalName = errRef.error.name;
errRef.error.originalMessage = errRef.error.message;
errRef.error.name = transformation.name || errRef.error.name;
errRef.error.message = transformation.message;
errRef.error.suggestions = transformation.suggestions;
}
} catch (ex) {
/* just catch */
console.error(ex);
if (!initializedResizeListener) {
initializeResizeListener();
}
// Testing
const ttt = Date.now();
const testRunner = manager.testRunner;
try {
testRunner.initialize();
testRunner.findTests(modules);
await testRunner.runTests();
const aggregatedResults = testRunner.reportResults();
debug(`Test Evaluation time: ${Date.now() - ttt}ms`);
dispatch({
type: 'test-result',
result: Encode(aggregatedResults),
});
// End - Testing
} catch (error) {
dispatch({
type: 'test-result',
error: testRunner.reportError(error),
});
}
debug(`Total time: ${Date.now() - startTime}ms`);
dispatch({
type: 'success',
});
const { data } = newMessage;
if (data) {
if (data.type === 'error') {
const reconstructedError = parseWorkerError(data.error);
this.runCallbacks(callbacks, reconstructedError);
}
if (data.type === 'warning') {
loaderContext.emitWarning(data.warning);
return;
}
if (data.type === 'clear-warnings') {
dispatch(actions.correction.clear(data.path, data.source));
}
if (data.type === 'resolve-async-transpiled-module') {
// This one is to add an asynchronous transpiled module
const { id, path, options } = data;
try {
const tModule = await loaderContext.resolveTranspiledModuleAsync(
path,
options
);
worker.postMessage({
type: 'resolve-async-transpiled-module-response',
id,
found: true,