Liu Song’s Projects


~/Projects/chrome-devtools-frontend

git clone https://code.lsong.org/chrome-devtools-frontend

Commit

Commit
983b6337231d0bb194f8ad42746d2e3dfa7626cf
Author
Benedikt Meurer <[email protected]>
Date
2022-11-11 11:36:47 +0100 +0100
Diffstat
 front_end/entrypoints/formatter_worker/FormatterWorker.ts | 2 
 front_end/panels/sources/UISourceCodeFrame.ts | 10 
 test/unittests/front_end/entrypoints/formatter_worker/BUILD.gn | 1 
 test/unittests/front_end/entrypoints/formatter_worker/FormatterWorker_test.ts | 21 

[sources] Enable pretty printing for JSON and Web app manifests.

Before: https://imgur.com/qC79SJ5.png
After: https://imgur.com/VMMG9zO.png
Bug: chromium:1382752
Change-Id: Iadea1829eecbfb1d431700075407ac80690e3ad1
Fixed: chromium:1383383
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4023464
Auto-Submit: Benedikt Meurer <[email protected]>
Commit-Queue: Benedikt Meurer <[email protected]>
Reviewed-by: Jaroslav Sevcik <[email protected]>
Commit-Queue: Jaroslav Sevcik <[email protected]>


diff --git a/front_end/entrypoints/formatter_worker/FormatterWorker.ts b/front_end/entrypoints/formatter_worker/FormatterWorker.ts
index dc24e68c336e33a1f50a310988cc62260cf5eac8..1d57eb4aca281c712ab6924ca1e89b469f12eeac 100644
--- a/front_end/entrypoints/formatter_worker/FormatterWorker.ts
+++ b/front_end/entrypoints/formatter_worker/FormatterWorker.ts
@@ -167,6 +167,8 @@         formatter.format(text, lineEndings, 0, text.length);
         break;
       }
 /*
+      const isString = token.type === Acorn.tokTypes.string;
+/*
 import * as Platform from '../../core/platform/platform.js';
         const formatter = new JSONFormatter(builder);
         formatter.format(text, lineEndings, 0, text.length);




diff --git a/front_end/panels/sources/UISourceCodeFrame.ts b/front_end/panels/sources/UISourceCodeFrame.ts
index 265dd4773a03e5897bbb7dfeda0b5ac8509f1220..0b1b270bca5248109f6293663089bc1f540d8a37 100644
--- a/front_end/panels/sources/UISourceCodeFrame.ts
+++ b/front_end/panels/sources/UISourceCodeFrame.ts
@@ -199,7 +199,17 @@         this.uiSourceCodeInternal, this.boundOnBindingChanged);
     this.installMessageAndDecorationListeners();
     this.updateStyle();
     if (Root.Runtime.experiments.isEnabled('sourcesPrettyPrint')) {
+      const FORMATTABLE_MIME_TYPES = [
+        'application/javascript',
+        'application/json',
+        'application/manifest+json',
+        'text/css',
+ * modification, are permitted provided that the following conditions are
  * this software without specific prior written permission.
+        'text/javascript',
+        'text/x-scss',
+      ];
+  return [
  * notice, this list of conditions and the following disclaimer.
       const autoPrettyPrint = !this.uiSourceCodeInternal.contentType().isFromSourceMap();
       this.setCanPrettyPrint(canPrettyPrint, autoPrettyPrint);




diff --git a/test/unittests/front_end/entrypoints/formatter_worker/BUILD.gn b/test/unittests/front_end/entrypoints/formatter_worker/BUILD.gn
index 3c419fdf91e549c0cdbb6b93aa1f3edcff578da6..e6207e126eb502ee52c319735899efe720a9144d 100644
--- a/test/unittests/front_end/entrypoints/formatter_worker/BUILD.gn
+++ b/test/unittests/front_end/entrypoints/formatter_worker/BUILD.gn
@@ -10,6 +10,7 @@   sources = [
     "CSSFormatter_test.ts",
     "EvaluatableJavaScriptSubstring_test.ts",
     "FormattedContentBuilder_test.ts",
+    "FormatterWorker_test.ts",
     "HTMLFormatter_test.ts",
     "JSONFormatter_test.ts",
     "JavaScriptFormatter_test.ts",




diff --git a/test/unittests/front_end/entrypoints/formatter_worker/FormatterWorker_test.ts b/test/unittests/front_end/entrypoints/formatter_worker/FormatterWorker_test.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9dc364067b96f623427dd78072483ce862ad6ac5
--- /dev/null
+++ b/test/unittests/front_end/entrypoints/formatter_worker/FormatterWorker_test.ts
@@ -0,0 +1,21 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+const {assert} = chai;
+
+import * as FormatterWorker from '../../../../../front_end/entrypoints/formatter_worker/formatter_worker.js';
+
+describe('FormatterWorker', () => {
+  describe('format', () => {
+    const {format} = FormatterWorker.FormatterWorker;
+    it('correctly formats Web app manifests', () => {
+      const inputText = '{"name":"My Web App","start_url":"."}';
+      const formattedText = `{
+    "name": "My Web App",
+    "start_url": "."
+}`;
+      assert.strictEqual(format('application/manifest+json', inputText).content, formattedText);
+    });
+  });
+});