diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index 7d67ff9..5f9dfbb 100644
--- a/core/lib/Drupal/Core/Template/TwigExtension.php
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -170,7 +170,8 @@ public function getFilters() {
 
       // Replace twig's escape filter with our own.
       new \Twig_SimpleFilter('drupal_escape', [$this, 'escapeFilter'], array('needs_environment' => TRUE, 'is_safe_callback' => 'twig_escape_filter_is_safe')),
-
+      // Remove html comments from a string
+      new \Twig_SimpleFilter('remove_html_comments', [$this, 'removeHtmlComments']),
       // Implements safe joining.
       // @todo Make that the default for |join? Upstream issue:
       //   https://github.com/fabpot/Twig/issues/1420
@@ -393,6 +394,20 @@ public function attachLibrary($library) {
   public function escapePlaceholder($env, $string) {
     return '<em class="placeholder">' . $this->escapeFilter($env, $string) . '</em>';
   }
+  
+  /**
+   * Removes html comments from string.
+   * Example: A string which has value  <!-- Start DEBUG --> ABCD <!-- End DEBUG -->
+   * will be returned the output ABCD after using the the following function.
+   * @param string $string
+   *   A string, which have html comments.
+   * @return string
+   *   A string, which have no html comments.
+   */
+  public function removeHtmlComments($string) {
+    $output = preg_replace('/<!--(.|\s)*?-->/', '', $string);
+    $output = str_replace(array("\n", "\r"), '', $output);
+    return $output;
+  }
 
   /**
    * Overrides twig_escape_filter().