PromucFlow_constructor/app/shared/ast/src/utils.ts
Favour Ohanekwu d6fbdb15b9
feat: Linting in entity properties and methods (#16171)
* Initial commit

* Remove arrow function params from identifiers

* Remove invalid identifiers from extracted identifiers

* Remove invalid identifiers which are derived from function params and variable declarations

* Fix typo error

* Correctly remove invalid identifiers

* Remove invalid names from identifier list

* fix build failure

* Add Promise to list of unacceptable entity name

* Keep track of unreferenced identifiers in bindings

* Add Global scope object names as unusable entity names

* Keep track of unreferenced identifiers

* Prevent traversal of data tree for addition of new paths and entities

* Sync linting in trigger fields

* Support linting of invalid properties

* Fix linting reactivity bug in trigger field

* Remove unused objects

* Fix conflict in merging

* Lint jsobject body for function change

* Remove unused map from tests

* Code cleanup

* Modify jest tests

* Update jest tests

* Fix cypress tests

* Code cleanup

* Support  linting of multiple bindings

* Set squiggle line as long as invalid property length

* Add jest tests

* Minor code refactor

* Move ast to shared repo

* Rename confusing identifiers

* Improve naming of functions and their return values

* move shared widget validation utils and constants to shared folder

* Add jest test for invalid entity names

* Add cypress tests

* Modify test comment

* Extend list of dedicated worker scope identifiers

* Resolve code review comments

* Resolve review comments

* Annonate code where necessary

* Code refactor

* Improve worker global scope object

* Code refactor

* Fix merge conflict

* Code refactor

* Minor bug fix

* Redundant commit to retrigger vercel build

* Add null checks to dependecy chain
2022-09-17 18:40:28 +01:00

20 lines
820 B
TypeScript

import unescapeJS from 'unescape-js';
const beginsWithLineBreakRegex = /^\s+|\s+$/;
export function sanitizeScript(js: string, evaluationVersion: number) {
// We remove any line breaks from the beginning of the script because that
// makes the final function invalid. We also unescape any escaped characters
// so that eval can happen
const trimmedJS = js.replace(beginsWithLineBreakRegex, '');
return evaluationVersion > 1 ? trimmedJS : unescapeJS(trimmedJS);
}
// For the times when you need to know if something truly an object like { a: 1, b: 2}
// typeof, lodash.isObject and others will return false positives for things like array, null, etc
export const isTrueObject = (
item: unknown
): item is Record<string, unknown> => {
return Object.prototype.toString.call(item) === '[object Object]';
};