MCPcopy Create free account
hub / github.com/nodejs/node / pull_dependencies

Method pull_dependencies

deps/v8/third_party/jinja2/compiler.py:538–579  ·  view source on GitHub ↗

Find all filter and test names used in the template and assign them to variables in the compiled namespace. Checking that the names are registered with the environment is done when compiling the Filter and Test nodes. If the node is in an If or CondExpr node, the chec

(self, nodes: t.Iterable[nodes.Node])

Source from the content-addressed store, hash-verified

536 self.visit(node.dyn_kwargs, frame)
537
538 def pull_dependencies(self, nodes: t.Iterable[nodes.Node]) -> None:
539 """Find all filter and test names used in the template and
540 assign them to variables in the compiled namespace. Checking
541 that the names are registered with the environment is done when
542 compiling the Filter and Test nodes. If the node is in an If or
543 CondExpr node, the check is done at runtime instead.
544
545 .. versionchanged:: 3.0
546 Filters and tests in If and CondExpr nodes are checked at
547 runtime instead of compile time.
548 """
549 visitor = DependencyFinderVisitor()
550
551 for node in nodes:
552 visitor.visit(node)
553
554 for id_map, names, dependency in (self.filters, visitor.filters, "filters"), (
555 self.tests,
556 visitor.tests,
557 "tests",
558 ):
559 for name in sorted(names):
560 if name not in id_map:
561 id_map[name] = self.temporary_identifier()
562
563 # add check during runtime that dependencies used inside of executed
564 # blocks are defined, as this step may be skipped during compile time
565 self.writeline("try:")
566 self.indent()
567 self.writeline(f"{id_map[name]} = environment.{dependency}[{name!r}]")
568 self.outdent()
569 self.writeline("except KeyError:")
570 self.indent()
571 self.writeline("@internalcode")
572 self.writeline(f"def {id_map[name]}(*unused):")
573 self.indent()
574 self.writeline(
575 f'raise TemplateRuntimeError("No {dependency[:-1]}'
576 f' named {name!r} found.")'
577 )
578 self.outdent()
579 self.outdent()
580
581 def enter_frame(self, frame: Frame) -> None:
582 undefs = []

Callers 1

visit_TemplateMethod · 0.95

Calls 7

temporary_identifierMethod · 0.95
writelineMethod · 0.95
indentMethod · 0.95
outdentMethod · 0.95
sortedFunction · 0.85
visitMethod · 0.45

Tested by

no test coverage detected