Repository navigation
feat(extract): add EJS (.ejs) template extractor - #4338
nothariharan wants to merge 1 commit into
Conversation
EJS views sat in CODE_EXTENSIONS with no extractor, so an Express/Node app's templates were counted as code and contributed nothing (the Graphify-Labs#1689 warning). A .ejs file is HTML with <% %> scriptlets and inline <script> blocks, so feeding the whole file to the JS grammar made it one top-level ERROR. Add extract_ejs: mask the template down to its JS regions (code-tag and <script> bodies), parse them with the TS grammar, and add the two relationships no JS grammar can see - dynamic import('./X') and the EJS <%- include('partial') %> composition edge, resolved to the real partial file. Wire .ejs into the dispatch, the jsts language family, the JS resolve/cache sets, and the hook source extensions.
|
Thanks for the pull request, @nothariharan. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 3 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; no formal proof of the changed code.
Graphify review — findings
Adds an extract_ejs extractor that masks templates down to their scriptlet and inline <script> JavaScript, keeping line numbers intact and substituting a placeholder for output tags inside scripts. The masked code goes through the TS grammar, so .ejs views yield real imports, functions and classes instead of one top-level parse error. Regex passes add dynamic import() edges and <%- include('partial') %> includes edges, which resolve through the JS resolver (now aware of .ejs/index.ejs) and fall back to a stub node when the partial can't be found, so the edge is never dropped.
Worth a look
- Global JS resolution now prefers .ejs over .js/index.js —
graphify/extractors/resolution.py:35· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
- Trailing
-%>/_%>close modifiers are kept as JS —graphify/extract.py:2783· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
- Multiline EJS output tag in script becomes multiple placeholder expressions —
graphify/extract.py· Escalate · medium- agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3082 functions depend on the 548 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 854 callers, 51 callees - worse:
_extract_generic()— 20 callers, 35 callees - new:
extract_ejs()— 10 callers, 9 callees - worse:
_normalize_ts_import_types()— 10 callers, 6 callees - worse:
_load_tsconfig_base_url()— 7 callers, 3 callees
Verification — 3082 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 3005 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
199 of 368 test file(s) selected (54%) via static blast radius.
tests/test_affected_cli.py— impacttests/test_agents_platform.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_cache.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cloud_cta.py— impacttests/test_cobol_extractor.py— impacttests/test_codebuddy.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_devin.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_ejs_extractor.py— impact, changed-testtests/test_elixir_defdelegate.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_keyword_def_calls.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_erlang_extractor.py— impacttests/test_explain_cli.py— impacttests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_cli.py— impacttests/test_extract_path_memo.py— impact- … and 149 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
· 1 grounded finding(s) anchored inline below; 4 more finding(s) on lines outside this diff (see the check run).
| result.setdefault("edges", []).append(edge) | ||
|
|
||
|
|
||
| def extract_ejs(path: Path) -> dict: |
There was a problem hiding this comment.
extract_ejs()
fans out to 9 callees (efferent coupling); 10 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
|
Shipped in v0.9.88, just released to PyPI as |
What does this PR do?
Fixes #3811 (same gap as #2511).
.ejsis inCODE_EXTENSIONSbut had no AST extractor, so an Express/Node app'sserver-rendered views were counted as code and contributed nothing to the graph
(the
#1689"no AST extractor" warning). They are not dumb HTML: they carry<% %>scriptlets (includingrequire/import), inline<script>blocks, and<%- include('partials/_page-header') %>composition.Adds
extract_ejs. A.ejsfile fed whole to the JS grammar is one top-levelERROR that loses every symbol (the
.sveltelesson of #3928), so the extractormasks the template down to the JavaScript it can actually read — the bodies of
code tags (
<% %>/<%_ %>) and of JS<script>blocks — and parses them withthe TS grammar, the same strategy
.svelte/.vue/.astrouse. Outputexpressions (
<%= %>/<%- %>), comments (<%# %>) and markup are blanked whilepreserving line numbers; an output tag inside a
<script>body is replaced by alength-preserving
0so the surrounding statement still parses.Two regex passes then add what no JS grammar can see: dynamic
import('./X')calls written in a scriptlet, and the EJS
<%- include('partial') %>compositionedge an Express view graph is built on, resolved to the real partial
.ejsfile..ejsis wired into_DISPATCH, thejstslanguage family, the JSresolve/cache sets, and the hook source extensions.
Type of change
Verification & Invariants
.ejsno longer trips the#1689warning; it produces nodes and edges.source_locationstill points at the original lines.relative hit is stamped with
target_file(no absolute-path ghost stub,Absolute-path node ids on 0.9.25 for in-root relative import targets (residual of #1899 Variant B; ghost duplicates + dangling endpoints) #2195), and an unresolved bare/views-root include keeps a stub so the edge is
never dropped.
How was this tested?
The one failing test on this base (
test_unmapped_at_alias_resolution.py::test_3357...)also fails on
upstream/v8without this change (host VCS-root interference); it isunrelated.
Graphify-specific checklist
ambient state dependencies like ENV variables).
Limitations
%>sits inside a JS string literal(
<% const s = "%>"; %>) is a known limitation of the tag scanner.