Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: remove _replace_ext in lib.bzl #684

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove _replace_ext in lib.bzl
dzbarsky committed Sep 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 069094da514ba437f0e28472800e0c226aff2b4d
15 changes: 6 additions & 9 deletions ts/private/ts_lib.bzl
Original file line number Diff line number Diff line change
@@ -180,11 +180,11 @@ def _is_typings_src(src):
return src.endswith(".d.ts") or src.endswith(".d.mts") or src.endswith(".d.cts")

def _is_js_src(src, allow_js, resolve_json_module):
if src.endswith(".js") or src.endswith(".jsx") or src.endswith(".mjs") or src.endswith(".cjs"):
return allow_js
if allow_js and (src.endswith(".js") or src.endswith(".jsx") or src.endswith(".mjs") or src.endswith(".cjs")):
return True

if src.endswith(".json"):
return resolve_json_module
if resolve_json_module and src.endswith(".json"):
return True

return False

@@ -194,10 +194,6 @@ def _is_ts_src(src, allow_js, resolve_json_module):

return _is_js_src(src, allow_js, resolve_json_module)

def _replace_ext(f, ext_map, default_ext):
cur_ext = f[f.rindex("."):]
return ext_map.get(cur_ext, default_ext)

def _to_out_path(f, out_dir, root_dir):
f = f[f.find(":") + 1:]
if root_dir:
@@ -211,7 +207,8 @@ def _to_js_out_paths(srcs, out_dir, root_dir, allow_js, resolve_json_module, ext
for f in srcs:
if _is_ts_src(f, allow_js, resolve_json_module):
out = _to_out_path(f, out_dir, root_dir)
out = out[:out.rindex(".")] + _replace_ext(out, ext_map, default_ext)
ext_idx = out.rindex(".")
out = out[:ext_idx] + ext_map.get(out[ext_idx:], default_ext)

# Don't declare outputs that collide with inputs
# for example, a.js -> a.js