Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
((container, extraProps) => {
const currentModule = resolveModule(
modulePath,
this.sandbox.modules,
this.sandbox.directories
);
return render(
,
setCurrentModuleFromPath = (path: string) => {
try {
const module = resolveModule(
path,
this.props.sandbox.modules,
this.props.sandbox.directories
);
this.setCurrentModule(module.id);
} catch (e) {
/* Ignore */
}
};
openedModels.forEach(fileModel => {
const path = fileModel.resource.path;
if (!path.startsWith('/sandbox') || !fileModel.isDirty()) {
return;
}
const module = resolveModule(
path.replace(/^\/sandbox/, ''),
this.sandbox.modules,
this.sandbox.directories
);
if (
module &&
this.props.isModuleSynced(module.shortid) &&
fileModel.isDirty
) {
// Do a revert to remove the dirty state and get the code from the FS, since in Cerebral
// we're already synced
fileModel.revert();
}
});
};
return model.onDidChangeContent(e => {
if (this.isApplyingOperation) {
return;
}
const { path } = model.uri;
try {
const module = resolveModule(
path.replace(/^\/sandbox/, ''),
sandbox.modules,
sandbox.directories
);
this.onChangeCallback({
moduleShortid: module.shortid,
title: module.title,
code: model.getValue(),
event: e,
model,
});
} catch (err) {
// This can throw when a file is deleted and you add new code to it. When
// saving it a new file is created
}
state.editor.errors.forEach(error => {
try {
const module = resolveModule(
error.path,
state.editor.currentSandbox.modules,
state.editor.currentSandbox.directories
);
module.errors = [];
} catch (e) {
// Module doesn't exist anymore
}
});
newErrors.forEach(error => {
getPrettierConfig = () => {
try {
const module = resolveModule(
'/.prettierrc',
this.sandbox.modules,
this.sandbox.directories
);
const parsedCode = JSON.parse(module.code || '');
return parsedCode;
} catch (e) {
return this.settings.prettierConfig || DEFAULT_PRETTIER_CONFIG;
}
};
model => {
if (this.modelListeners[model.uri.path] === undefined) {
let module: Module;
try {
module = resolveModule(
model.uri.path.replace(/^\/sandbox/, ''),
this.sandbox.modules,
this.sandbox.directories
);
} catch (e) {
return;
}
const listener = model.onDidChangeContent(e => {
const path = model.uri.path;
try {
const module = resolveModule(
path.replace(/^\/sandbox/, ''),
this.sandbox.modules,
this.sandbox.directories
);
private getPrettierConfig = () => {
try {
const sandbox = this.options.getCurrentSandbox();
const module = resolveModule(
'/.prettierrc',
sandbox.modules,
sandbox.directories
);
return JSON.parse(module.code || '');
} catch (e) {
return this.settings.prettierConfig || DEFAULT_PRETTIER_CONFIG;
}
};
}
private getPrettierConfig = () => {
try {
const sandbox = this.options.getCurrentSandbox();
const module = resolveModule(
'/.prettierrc',
sandbox.modules,
sandbox.directories
);
return JSON.parse(module.code || '');
} catch (e) {
return this.settings.prettierConfig || DEFAULT_PRETTIER_CONFIG;
}
};
newCorrections.forEach(correction => {
const module = resolveModule(
correction.path,
state.editor.currentSandbox.modules,
state.editor.currentSandbox.directories
);
module.corrections.push(correction);
});
state.editor.corrections = newCorrections;