def is_matching_submodule(prev_submodule, new_submodule):
    """Match two npm submodules based on package name or location."""

    if 'package_name' in prev_submodule and 'package_name' in new_submodule:
        return prev_submodule['package_name'] == new_submodule['package_name']

    assert 'package_location' in prev_submodule
    assert 'package_location' in new_submodule

    return (prev_submodule['package_location'] ==
            new_submodule['package_location'])