Repository: 4ian/GDevelop
File: newIDE/app/src/EventsSheet/ParameterFields/VariableField.js (JavaScript)

Code before:
import { LineStackLayout } from '../../UI/Layout';
import GlobalVariableIcon from '../../UI/CustomSvgIcons/GlobalVariable';
import SceneVariableIcon from '../../UI/CustomSvgIcons/SceneVariable';
import ObjectVariableIcon from '../../UI/CustomSvgIcons/ObjectVariable';
import LocalVariableIcon from '../../UI/CustomSvgIcons/LocalVariable';
import PropertyIcon from '../../UI/CustomSvgIcons/Settings';
import ParameterIcon from '../../UI/CustomSvgIcons/Parameter';
import { ProjectScopedContainersAccessor } from '../../InstructionOrExpression/EventsScope';
import Link from '../../UI/Link';
import Add from '../../UI/CustomSvgIcons/Add';

const gd: libGDevelop = global.gd;

export type VariableDialogOpeningProps = {
  variableName: string,
  shouldCreate: boolean,
};

type Props = {
  ...ParameterFieldProps,
  isObjectVariable: boolean,
  variablesContainers: Array<gdVariablesContainer>,
  getVariableSourceFromVariableName: (
    variableRootName: string,
    projectScopedContainers: gdProjectScopedContainers
  ) => VariablesContainer_SourceType,
  enumerateVariables: () => Array<EnumeratedVariable>,
  forceDeclaration?: boolean,
  onOpenDialog: (VariableDialogOpeningProps => void) | null,
};

type VariableNameQuickAnalyzeResult = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;

export type VariableFieldInterface = {|
  ...ParameterFieldInterface,
  updateAutocompletions: () => void,
|};

export const VariableNameQuickAnalyzeResults = {
  OK: 0,
  WRONG_QUOTE: 1,
  WRONG_SPACE: 2,
  WRONG_EXPRESSION: 3,
  UNDECLARED_VARIABLE: 4,
  NAME_COLLISION_WITH_OBJECT: 5,
  PARAMETER_WITH_CHILD: 6,
  PROPERTY_WITH_CHILD: 7,
};

export const getRootVariableName = (name: string): string => {
  const dotPosition = name.indexOf('.');

Review comment (suggestion):
Let's call this:

```suggestion
  getVariableSourceFromIdentifierName: (
    identifierName: string,
    projectScopedContainers: gdProjectScopedContainers
  ) => VariablesContainer_SourceType,
```

to emphasis that we don't know if it's a variable name, a property name or a parameter name, and it could be a mix.

Code after:
import { LineStackLayout } from '../../UI/Layout';
import GlobalVariableIcon from '../../UI/CustomSvgIcons/GlobalVariable';
import SceneVariableIcon from '../../UI/CustomSvgIcons/SceneVariable';
import ObjectVariableIcon from '../../UI/CustomSvgIcons/ObjectVariable';
import LocalVariableIcon from '../../UI/CustomSvgIcons/LocalVariable';
import PropertyIcon from '../../UI/CustomSvgIcons/Settings';
import ParameterIcon from '../../UI/CustomSvgIcons/Parameter';
import { ProjectScopedContainersAccessor } from '../../InstructionOrExpression/EventsScope';
import Link from '../../UI/Link';
import Add from '../../UI/CustomSvgIcons/Add';

const gd: libGDevelop = global.gd;

export type VariableDialogOpeningProps = {
  variableName: string,
  shouldCreate: boolean,
};

type Props = {
  ...ParameterFieldProps,
  isObjectVariable: boolean,
  variablesContainers: Array<gdVariablesContainer>,
  getVariableSourceFromIdentifier: (
    identifier: string,
    projectScopedContainers: gdProjectScopedContainers
  ) => VariablesContainer_SourceType,
  enumerateVariables: () => Array<EnumeratedVariable>,
  forceDeclaration?: boolean,
  onOpenDialog: (VariableDialogOpeningProps => void) | null,
};

type VariableNameQuickAnalyzeResult = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;

export type VariableFieldInterface = {|
  ...ParameterFieldInterface,
  updateAutocompletions: () => void,
|};

export const VariableNameQuickAnalyzeResults = {
  OK: 0,
  WRONG_QUOTE: 1,
  WRONG_SPACE: 2,
  WRONG_EXPRESSION: 3,
  UNDECLARED_VARIABLE: 4,
  NAME_COLLISION_WITH_OBJECT: 5,
  PARAMETER_WITH_CHILD: 6,
  PROPERTY_WITH_CHILD: 7,
};

export const getRootVariableName = (name: string): string => {
  const dotPosition = name.indexOf('.');