champollion.parser.js_file

champollion.parser.js_file.fetch_environment(file_path, file_id, module_id)[source]

Return file environment dictionary from file_path.

file_id represent the identifier of the file.

module_id represent the identifier of the module.

Update the environment if available and return it as-is if the file is not readable.

The environment is in the form of:

{
    "id": "module/test/index.js",
    "module_id": "module.test",
    "name": "index.js",
    "path": "/path/to/module/test/index.js",
    "content": "'use strict'\n\n...",
    "description": "File description",
    "export": {
        "module.test.exported_element": {
            "id": "module.test.exported_element",
            "module": "module.test.from_module",
            "description": "An exported element",
            ...
        },
        ...
    },
    "import": {
        "module.test.imported_element": {
            "id": "module.test.imported_element",
            "module": "module.test.from_module",
            ...
        },
        ...
    },
    "class": {
        "class_id": {
            "id": "class_id",
            "module_id": "module_id"
            "description": "A class."
            ...
        },
        ...
    },
    "data": {
        "data_id": {
            "id": "data_id",
            "module_id": "module_id",
            "description": "A variable."
            ...
        },
        ...
    },
    "function": {
        "function_id": {
            "id": "function_id",
            "module_id": "module_id",
            "description": "A function."
            ...
        },
        ...
    }
}
champollion.parser.js_file.fetch_file_description(content)[source]

Return file description from content.

The description must be in a docstring which should be defined at the very beginning of the file. It can only be preceded by one line comments.

It must be in the form of:

/**
 * File description.
 *
 * A detailed description of the file.
 *
 */

Return None if no description is available.

champollion.parser.js_file.update_from_exported_elements(environment, export_environment)[source]

Update environment with exported elements from export_environment.

For instance, the element environment might not be exported, but an exported element is found that can be linked to this element.

// Element in the environment
function doSomething(arg1, arg2) {
    console.log("Hello World")
}

// Element in the export environment
export {doSomething};

In the example above, the function doSomething is previously fetched without the exported attribute, so it will be added to it.

The entry will then be removed from the export_environment.

Warning

Both input environments are mutated.

champollion.parser.js_file.fetch_import_environment(content, module_id)[source]

Return import environment dictionary from content.

module_id represent the identifier of the module.

The environment is in the form of:

{
    "module.test.imported_element": {
        "id": "module.test.imported_element",
        "module": "module.test.from_module",
        "name": "imported_element",
        "alias": None,
        "partial": False
    },
    ...
}
champollion.parser.js_file.fetch_export_environment(content, module_id)[source]

Return export environment dictionary from content.

module_id represent the identifier of the module.

The environment is in the form of:

{
    "module.test.exported_element": {
        "id": "module.test.exported_element",
        "module": "module.test.from_module",
        "name": "exported_element",
        "alias": None,
        "partial": True,
        "description": None,
        "default": False,
        "line_number": 5,
    },
    ...
}