def _GetJsModuleImports(self):
this_module_path = _GetWebUiModulePath(self.module)
this_module_is_shared = bool(this_module_path
and _IsSharedModulePath(this_module_path))
imports = dict()
def strip_prefix(s, prefix):
if s.startswith(prefix):
return s[len(prefix):]
return s
# 你的修復函數,確保使用 2 個空格縮進
def sanitize_path(p):
p = strip_prefix(p, _CHROME_SCHEME_PREFIX)
p = strip_prefix(p, _SHARED_MODULE_PREFIX)
p = p.replace('\\', '/')
while '//' in p:
p = p.replace('//', '/')
if p.startswith('/'):
p = p[1:]
return p
for spec, kind in self.module.imported_kinds.items():
assert this_module_path is not None
base_path = _GetWebUiModulePath(kind.module)
assert base_path is not None
import_path = '{}{}-webui.js'.format(base_path,
os.path.basename(kind.module.path))
import_module_is_shared = _IsSharedModulePath(import_path)
if this_module_is_shared:
assert import_module_is_shared, \
'Shared WebUI module "{}" cannot depend on non-shared WebUI ' \
'module "{}"'.format(self.module.path, kind.module.path)
import_module_is_in_chrome_resources = _IsAbsoluteChromeResourcesPath(
import_path)
use_absolute_path = import_module_is_in_chrome_resources and not \
import_module_is_shared
use_relative_path = not use_absolute_path and \
import_module_is_shared == this_module_is_shared
if use_relative_path:
path_to_relativize = sanitize_path(import_path)
start_path = sanitize_path(this_module_path)
import_path = urllib.request.pathname2url(
os.path.relpath(path_to_relativize, start_path))
if (not import_path.startswith('.')
and not import_path.startswith('/')):
import_path = './' + import_path
else:
# 這裡是原本報錯的 655 行,現在確保它與 if 對齊
import_path = strip_prefix(import_path, _CHROME_SCHEME_PREFIX)
if import_path not in imports:
imports[import_path] = []
imports[import_path].append(kind)
return imports