import { DataTree, DataTreeEntity } from "entities/DataTree/dataTreeFactory"; import { getEntityNameAndPropertyPath, isAction, isATriggerPath, isJSAction, isWidget, } from "workers/evaluationUtils"; import { Position } from "codemirror"; import { EvaluationError, extraLibraries, isDynamicValue, isPathADynamicBinding, PropertyEvaluationErrorType, } from "utils/DynamicBindingUtils"; import { JSHINT as jshint, LintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last } from "lodash"; import { EvaluationScripts, EvaluationScriptType, ScriptTemplate, } from "workers/evaluate"; import { getLintErrorMessage, getLintSeverity, } from "components/editorComponents/CodeEditor/lintHelpers"; import { ECMA_VERSION } from "@shared/ast"; import { IGNORED_LINT_ERRORS, SUPPORTED_WEB_APIS, } from "components/editorComponents/CodeEditor/constants"; export const pathRequiresLinting = ( dataTree: DataTree, entity: DataTreeEntity, fullPropertyPath: string, ): boolean => { const { propertyPath } = getEntityNameAndPropertyPath(fullPropertyPath); const unEvalPropertyValue = (get( dataTree, fullPropertyPath, ) as unknown) as string; if (isATriggerPath(entity, propertyPath)) { return isDynamicValue(unEvalPropertyValue); } const isADynamicBindingPath = (isAction(entity) || isWidget(entity) || isJSAction(entity)) && isPathADynamicBinding(entity, propertyPath); const requiresLinting = isADynamicBindingPath && (isDynamicValue(unEvalPropertyValue) || (isJSAction(entity) && propertyPath === "body")); return requiresLinting; }; // Removes "export default" statement from js Object export const getJSToLint = ( entity: DataTreeEntity, snippet: string, propertyPath: string, ) => { return entity && isJSAction(entity) && propertyPath === "body" ? snippet.replace(/export default/g, "") : snippet; }; export const getPositionInEvaluationScript = ( type: EvaluationScriptType, ): Position => { const script = EvaluationScripts[type]; const index = script.indexOf(ScriptTemplate); const substr = script.slice(0, index !== -1 ? index : 0); const lines = substr.split("\n"); const lastLine = last(lines) || ""; return { line: lines.length, ch: lastLine.length }; }; const EvaluationScriptPositions: Record = {}; function getEvaluationScriptPosition(scriptType: EvaluationScriptType) { if (isEmpty(EvaluationScriptPositions)) { // We are computing position of <