chrome-devtools-frontend 1.0.951410 → 1.0.952713

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/config/gni/devtools_grd_files.gni +3 -0
  2. package/extension-api/ExtensionAPI.d.ts +1 -1
  3. package/front_end/.eslintrc.js +6 -0
  4. package/front_end/Tests.js +10 -0
  5. package/front_end/core/common/App.ts +0 -3
  6. package/front_end/core/common/AppProvider.ts +0 -3
  7. package/front_end/core/common/JavaScriptMetaData.ts +0 -3
  8. package/front_end/core/common/QueryParamHandler.ts +0 -3
  9. package/front_end/core/common/Runnable.ts +0 -3
  10. package/front_end/core/common/SimpleHistoryManager.ts +0 -3
  11. package/front_end/core/host/UserMetrics.ts +2 -1
  12. package/front_end/core/i18n/locales/en-US.json +3 -0
  13. package/front_end/core/i18n/locales/en-XL.json +3 -0
  14. package/front_end/core/root/Runtime.ts +4 -12
  15. package/front_end/core/sdk/OverlayPersistentHighlighter.ts +0 -12
  16. package/front_end/core/sdk/PageResourceLoader.ts +2 -1
  17. package/front_end/core/sdk/TracingManager.ts +0 -3
  18. package/front_end/entrypoints/formatter_worker/AcornTokenizer.ts +39 -39
  19. package/front_end/entrypoints/formatter_worker/CSSFormatter.ts +54 -54
  20. package/front_end/entrypoints/formatter_worker/ESTreeWalker.ts +20 -20
  21. package/front_end/entrypoints/formatter_worker/FormattedContentBuilder.ts +54 -54
  22. package/front_end/entrypoints/formatter_worker/HTMLFormatter.ts +145 -144
  23. package/front_end/entrypoints/formatter_worker/JavaScriptFormatter.ts +40 -40
  24. package/front_end/entrypoints/heap_snapshot_worker/AllocationProfile.ts +64 -69
  25. package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts +203 -203
  26. package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshotLoader.ts +109 -108
  27. package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshotWorkerDispatcher.ts +17 -17
  28. package/front_end/entrypoints/inspector_main/InspectorMain.ts +30 -30
  29. package/front_end/entrypoints/inspector_main/RenderingOptions.ts +25 -25
  30. package/front_end/entrypoints/main/ExecutionContextSelector.ts +52 -55
  31. package/front_end/entrypoints/main/MainImpl.ts +49 -49
  32. package/front_end/entrypoints/node_app/NodeConnectionsPanel.ts +43 -43
  33. package/front_end/entrypoints/node_app/NodeMain.ts +38 -38
  34. package/front_end/generated/InspectorBackendCommands.js +5 -1
  35. package/front_end/generated/protocol.d.ts +16 -0
  36. package/front_end/legacy/legacy-defs.d.ts +0 -21
  37. package/front_end/models/bindings/CSSWorkspaceBinding.ts +0 -3
  38. package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +0 -3
  39. package/front_end/models/bindings/FileUtils.ts +0 -3
  40. package/front_end/models/extensions/ExtensionAPI.ts +2 -1
  41. package/front_end/models/extensions/ExtensionTraceProvider.ts +0 -3
  42. package/front_end/models/heap_snapshot_model/HeapSnapshotModel.ts +1 -1
  43. package/front_end/models/issues_manager/ClientHintIssue.ts +95 -0
  44. package/front_end/models/issues_manager/ContentSecurityPolicyIssue.ts +6 -6
  45. package/front_end/models/issues_manager/ContrastCheckTrigger.ts +15 -15
  46. package/front_end/models/issues_manager/CorsIssue.ts +9 -9
  47. package/front_end/models/issues_manager/CrossOriginEmbedderPolicyIssue.ts +5 -5
  48. package/front_end/models/issues_manager/DeprecationIssue.ts +7 -7
  49. package/front_end/models/issues_manager/GenericIssue.ts +5 -5
  50. package/front_end/models/issues_manager/HeavyAdIssue.ts +5 -5
  51. package/front_end/models/issues_manager/Issue.ts +10 -10
  52. package/front_end/models/issues_manager/IssueResolver.ts +11 -10
  53. package/front_end/models/issues_manager/IssuesManager.ts +61 -56
  54. package/front_end/models/issues_manager/LowTextContrastIssue.ts +4 -4
  55. package/front_end/models/issues_manager/MixedContentIssue.ts +7 -7
  56. package/front_end/models/issues_manager/NavigatorUserAgentIssue.ts +7 -7
  57. package/front_end/models/issues_manager/QuirksModeIssue.ts +4 -4
  58. package/front_end/models/issues_manager/SameSiteCookieIssue.ts +16 -16
  59. package/front_end/models/issues_manager/SharedArrayBufferIssue.ts +5 -5
  60. package/front_end/models/issues_manager/SourceFrameIssuesManager.ts +32 -31
  61. package/front_end/models/issues_manager/TrustedWebActivityIssue.ts +5 -5
  62. package/front_end/models/issues_manager/WasmCrossOriginModuleSharingIssue.ts +5 -5
  63. package/front_end/models/issues_manager/descriptions/clientHintMetaTagAllowListInvalidOrigin.md +4 -0
  64. package/front_end/models/issues_manager/descriptions/clientHintMetaTagModifiedHTML.md +4 -0
  65. package/front_end/models/issues_manager/issues_manager.ts +2 -0
  66. package/front_end/models/timeline_model/TimelineModel.ts +1 -1
  67. package/front_end/panels/application/components/BackForwardCacheView.ts +33 -33
  68. package/front_end/panels/application/components/EndpointsGrid.ts +12 -12
  69. package/front_end/panels/application/components/FrameDetailsView.ts +108 -110
  70. package/front_end/panels/application/components/OriginTrialTreeView.ts +45 -45
  71. package/front_end/panels/application/components/PermissionsPolicySection.ts +19 -19
  72. package/front_end/panels/application/components/ReportsGrid.ts +30 -30
  73. package/front_end/panels/application/components/StackTrace.ts +48 -47
  74. package/front_end/panels/application/components/TrustTokensView.ts +31 -31
  75. package/front_end/panels/console/ConsoleView.ts +1 -1
  76. package/front_end/panels/console/ConsoleViewMessage.ts +1 -25
  77. package/front_end/panels/console/consoleView.css +5 -0
  78. package/front_end/panels/css_overview/CSSOverviewCompletedView.ts +41 -52
  79. package/front_end/panels/css_overview/CSSOverviewController.ts +2 -2
  80. package/front_end/panels/css_overview/CSSOverviewPanel.ts +18 -27
  81. package/front_end/panels/css_overview/CSSOverviewProcessingView.ts +2 -2
  82. package/front_end/panels/css_overview/CSSOverviewSidebarPanel.ts +6 -6
  83. package/front_end/panels/css_overview/components/CSSOverviewStartView.ts +4 -4
  84. package/front_end/panels/elements/ElementsTreeElement.ts +2 -6
  85. package/front_end/panels/elements/components/AccessibilityTreeNode.ts +17 -17
  86. package/front_end/panels/elements/components/AdornerManager.ts +21 -21
  87. package/front_end/panels/elements/components/AdornerSettingsPane.ts +14 -14
  88. package/front_end/panels/elements/components/CSSQuery.ts +16 -16
  89. package/front_end/panels/elements/components/ComputedStyleProperty.ts +14 -14
  90. package/front_end/panels/elements/components/ComputedStyleTrace.ts +15 -15
  91. package/front_end/panels/elements/components/ElementsBreadcrumbs.ts +78 -78
  92. package/front_end/panels/elements/components/ElementsPanelLink.ts +16 -16
  93. package/front_end/panels/elements/components/LayoutPane.ts +47 -47
  94. package/front_end/panels/elements/components/NodeText.ts +18 -18
  95. package/front_end/panels/elements/components/QueryContainer.ts +40 -40
  96. package/front_end/panels/elements/components/StylePropertyEditor.ts +18 -18
  97. package/front_end/panels/emulation/components/DeviceSizeInputElement.ts +4 -4
  98. package/front_end/panels/event_listeners/EventListenersUtils.ts +2 -1
  99. package/front_end/panels/issues/AffectedBlockedByResponseView.ts +4 -4
  100. package/front_end/panels/issues/AffectedCookiesView.ts +4 -5
  101. package/front_end/panels/issues/AffectedDirectivesView.ts +19 -19
  102. package/front_end/panels/issues/AffectedDocumentsInQuirksModeView.ts +7 -8
  103. package/front_end/panels/issues/AffectedElementsView.ts +4 -4
  104. package/front_end/panels/issues/AffectedElementsWithLowContrastView.ts +7 -8
  105. package/front_end/panels/issues/AffectedHeavyAdView.ts +8 -8
  106. package/front_end/panels/issues/AffectedResourcesView.ts +25 -26
  107. package/front_end/panels/issues/AffectedSharedArrayBufferIssueDetailsView.ts +8 -8
  108. package/front_end/panels/issues/AffectedSourcesView.ts +4 -4
  109. package/front_end/panels/issues/AffectedTrustedWebActivityIssueDetailsView.ts +4 -4
  110. package/front_end/panels/issues/AttributionReportingIssueDetailsView.ts +17 -17
  111. package/front_end/panels/issues/CSPViolationsListView.ts +22 -23
  112. package/front_end/panels/issues/CSPViolationsView.ts +17 -17
  113. package/front_end/panels/issues/ComboBoxOfCheckBoxes.ts +13 -13
  114. package/front_end/panels/issues/CorsIssueDetailsView.ts +23 -23
  115. package/front_end/panels/issues/GenericIssueDetailsView.ts +4 -4
  116. package/front_end/panels/issues/HiddenIssuesRow.ts +7 -7
  117. package/front_end/panels/issues/IssueAggregator.ts +95 -95
  118. package/front_end/panels/issues/IssueKindView.ts +14 -14
  119. package/front_end/panels/issues/IssueView.ts +98 -98
  120. package/front_end/panels/issues/IssuesPane.ts +102 -102
  121. package/front_end/panels/issues/WasmCrossOriginModuleSharingAffectedResourcesView.ts +5 -5
  122. package/front_end/panels/issues/components/HideIssuesMenu.ts +10 -10
  123. package/front_end/panels/media/PlayerListView.ts +160 -97
  124. package/front_end/panels/media/PlayerMessagesView.ts +1 -0
  125. package/front_end/panels/media/playerListView.css +58 -0
  126. package/front_end/panels/network/NetworkLogView.ts +2 -6
  127. package/front_end/panels/network/NetworkWaterfallColumn.ts +2 -4
  128. package/front_end/panels/network/components/RequestTrustTokensView.ts +40 -40
  129. package/front_end/panels/network/components/WebBundleInfoView.ts +9 -9
  130. package/front_end/panels/performance_monitor/PerformanceMonitor.ts +92 -37
  131. package/front_end/panels/performance_monitor/performanceMonitor.css +32 -0
  132. package/front_end/panels/protocol_monitor/ProtocolMonitor.ts +2 -2
  133. package/front_end/panels/search/SearchConfig.ts +0 -6
  134. package/front_end/panels/settings/KeybindsSettingsTab.ts +4 -0
  135. package/front_end/panels/settings/components/SyncSection.ts +14 -14
  136. package/front_end/panels/settings/emulation/components/UserAgentClientHintsForm.ts +96 -96
  137. package/front_end/panels/sources/BreakpointEditDialog.ts +4 -3
  138. package/front_end/panels/sources/NavigatorView.ts +3 -9
  139. package/front_end/panels/sources/SourceMapNamesResolver.ts +3 -3
  140. package/front_end/panels/sources/SourcesPanel.ts +1 -3
  141. package/front_end/panels/sources/SourcesView.ts +0 -3
  142. package/front_end/panels/sources/TabbedEditorContainer.ts +0 -3
  143. package/front_end/panels/timeline/TimelineFlameChartView.ts +1 -1
  144. package/front_end/panels/timeline/TimelineLoader.ts +0 -3
  145. package/front_end/panels/timeline/TimelineTreeView.ts +1 -1
  146. package/front_end/panels/timeline/components/WebVitalsLane.ts +77 -76
  147. package/front_end/panels/timeline/components/WebVitalsTimeline.ts +133 -133
  148. package/front_end/panels/timeline/components/WebVitalsTooltip.ts +9 -9
  149. package/front_end/panels/webauthn/WebauthnPane.ts +203 -205
  150. package/front_end/third_party/codemirror.next/bundle.ts +3 -3
  151. package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
  152. package/front_end/third_party/codemirror.next/chunk/markdown.js +2 -1
  153. package/front_end/third_party/codemirror.next/codemirror.next.d.ts +10 -1
  154. package/front_end/third_party/codemirror.next/codemirror.next.js +2 -1
  155. package/front_end/third_party/codemirror.next/package.json +3 -3
  156. package/front_end/third_party/diff/DiffWrapper.ts +7 -0
  157. package/front_end/ui/components/adorners/Adorner.ts +2 -2
  158. package/front_end/ui/components/buttons/Button.ts +9 -9
  159. package/front_end/ui/components/data_grid/DataGrid.ts +64 -64
  160. package/front_end/ui/components/data_grid/DataGridController.ts +22 -22
  161. package/front_end/ui/components/data_grid/DataGridUtils.ts +3 -0
  162. package/front_end/ui/components/diff_view/DiffView.ts +6 -6
  163. package/front_end/ui/components/expandable_list/ExpandableList.ts +5 -5
  164. package/front_end/ui/components/icon_button/Icon.ts +4 -4
  165. package/front_end/ui/components/icon_button/IconButton.ts +4 -4
  166. package/front_end/ui/components/issue_counter/IssueCounter.ts +3 -3
  167. package/front_end/ui/components/issue_counter/IssueLinkIcon.ts +11 -11
  168. package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspector.ts +50 -50
  169. package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorController.ts +6 -6
  170. package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorPane.ts +4 -4
  171. package/front_end/ui/components/linear_memory_inspector/LinearMemoryNavigator.ts +12 -12
  172. package/front_end/ui/components/linear_memory_inspector/LinearMemoryValueInterpreter.ts +11 -11
  173. package/front_end/ui/components/linear_memory_inspector/LinearMemoryViewer.ts +40 -39
  174. package/front_end/ui/components/linear_memory_inspector/ValueInterpreterDisplay.ts +18 -18
  175. package/front_end/ui/components/linear_memory_inspector/ValueInterpreterSettings.ts +6 -6
  176. package/front_end/ui/components/linkifier/LinkifierImpl.ts +4 -4
  177. package/front_end/ui/components/markdown_view/MarkdownImage.ts +5 -5
  178. package/front_end/ui/components/markdown_view/MarkdownLink.ts +2 -2
  179. package/front_end/ui/components/markdown_view/MarkdownView.ts +4 -4
  180. package/front_end/ui/components/panel_feedback/FeedbackButton.ts +2 -2
  181. package/front_end/ui/components/panel_feedback/PanelFeedback.ts +2 -2
  182. package/front_end/ui/components/panel_feedback/PreviewToggle.ts +4 -4
  183. package/front_end/ui/components/render_coordinator/RenderCoordinator.ts +22 -22
  184. package/front_end/ui/components/report_view/ReportView.ts +16 -16
  185. package/front_end/ui/components/request_link_icon/RequestLinkIcon.ts +14 -14
  186. package/front_end/ui/components/settings/SettingCheckbox.ts +5 -5
  187. package/front_end/ui/components/survey_link/SurveyLink.ts +8 -8
  188. package/front_end/ui/components/text_editor/TextEditor.ts +9 -9
  189. package/front_end/ui/components/text_editor/cursor_tooltip.ts +7 -1
  190. package/front_end/ui/components/text_prompt/TextPrompt.ts +18 -18
  191. package/front_end/ui/components/tree_outline/TreeOutline.ts +69 -70
  192. package/front_end/ui/legacy/ContextFlavorListener.ts +0 -4
  193. package/front_end/ui/legacy/SearchableView.ts +13 -4
  194. package/front_end/ui/legacy/SuggestBox.ts +0 -3
  195. package/front_end/ui/legacy/components/data_grid/DataGrid.ts +6 -6
  196. package/front_end/ui/legacy/components/perf_ui/FlameChart.ts +0 -3
  197. package/front_end/ui/legacy/components/source_frame/JSONView.ts +1 -1
  198. package/front_end/ui/legacy/components/source_frame/SourceFrame.ts +13 -12
  199. package/front_end/ui/legacy/components/source_frame/XMLView.ts +2 -2
  200. package/front_end/ui/legacy/themeColors.css +2 -0
  201. package/front_end/ui/legacy/theme_support/theme_support_impl.ts +34 -7
  202. package/package.json +1 -1
  203. package/scripts/eslint_rules/lib/use_private_class_members.js +41 -0
  204. package/scripts/eslint_rules/tests/use_private_class_members_test.js +62 -0
  205. package/scripts/migration/class-fields/migrate.js +2 -3
  206. package/scripts/migration/class-fields/migrate.sh +1 -3
  207. package/scripts/migration/class-fields/package.json +1 -1
  208. package/config/gni/all_devtools_files.gni +0 -255
  209. package/scripts/build/devtools_file_hashes.py +0 -82
  210. package/scripts/devtools_run/devtools_run_cli +0 -49
  211. package/scripts/devtools_run/package.json +0 -13
  212. package/scripts/unzip.py +0 -20
  213. package/scripts/visualize_deps/jquery_svg.html +0 -57
  214. package/scripts/visualize_deps/run_visualize.js +0 -119
@@ -3,16 +3,16 @@
3
3
  // found in the LICENSE file.
4
4
 
5
5
  export class FormattedContentBuilder {
6
- private lastOriginalPosition = 0;
7
- private formattedContent: string[] = [];
8
- private formattedContentLength = 0;
9
- private lastFormattedPosition = 0;
10
- private nestingLevel = 0;
11
- private newLines = 0;
12
- private enforceSpaceBetweenWords = true;
13
- private softSpace = false;
14
- private hardSpaces = 0;
15
- private cachedIndents = new Map<number, string>();
6
+ #lastOriginalPosition = 0;
7
+ #formattedContent: string[] = [];
8
+ #formattedContentLength = 0;
9
+ #lastFormattedPosition = 0;
10
+ #nestingLevel = 0;
11
+ #newLines = 0;
12
+ #enforceSpaceBetweenWords = true;
13
+ #softSpace = false;
14
+ #hardSpaces = 0;
15
+ #cachedIndents = new Map<number, string>();
16
16
 
17
17
  mapping = {original: [0], formatted: [0]};
18
18
 
@@ -20,110 +20,110 @@ export class FormattedContentBuilder {
20
20
  }
21
21
 
22
22
  setEnforceSpaceBetweenWords(value: boolean): boolean {
23
- const oldValue = this.enforceSpaceBetweenWords;
24
- this.enforceSpaceBetweenWords = value;
23
+ const oldValue = this.#enforceSpaceBetweenWords;
24
+ this.#enforceSpaceBetweenWords = value;
25
25
  return oldValue;
26
26
  }
27
27
 
28
28
  addToken(token: string, offset: number): void {
29
- const last = this.formattedContent[this.formattedContent.length - 1];
30
- if (this.enforceSpaceBetweenWords && last && /\w/.test(last[last.length - 1]) && /\w/.test(token)) {
29
+ const last = this.#formattedContent[this.#formattedContent.length - 1];
30
+ if (this.#enforceSpaceBetweenWords && last && /\w/.test(last[last.length - 1]) && /\w/.test(token)) {
31
31
  this.addSoftSpace();
32
32
  }
33
33
 
34
- this.appendFormatting();
34
+ this.#appendFormatting();
35
35
 
36
36
  // Insert token.
37
- this.addMappingIfNeeded(offset);
38
- this.addText(token);
37
+ this.#addMappingIfNeeded(offset);
38
+ this.#addText(token);
39
39
  }
40
40
 
41
41
  addSoftSpace(): void {
42
- if (!this.hardSpaces) {
43
- this.softSpace = true;
42
+ if (!this.#hardSpaces) {
43
+ this.#softSpace = true;
44
44
  }
45
45
  }
46
46
 
47
47
  addHardSpace(): void {
48
- this.softSpace = false;
49
- ++this.hardSpaces;
48
+ this.#softSpace = false;
49
+ ++this.#hardSpaces;
50
50
  }
51
51
 
52
52
  addNewLine(noSquash?: boolean): void {
53
53
  // Avoid leading newlines.
54
- if (!this.formattedContentLength) {
54
+ if (!this.#formattedContentLength) {
55
55
  return;
56
56
  }
57
57
  if (noSquash) {
58
- ++this.newLines;
58
+ ++this.#newLines;
59
59
  } else {
60
- this.newLines = this.newLines || 1;
60
+ this.#newLines = this.#newLines || 1;
61
61
  }
62
62
  }
63
63
 
64
64
  increaseNestingLevel(): void {
65
- this.nestingLevel += 1;
65
+ this.#nestingLevel += 1;
66
66
  }
67
67
 
68
68
  decreaseNestingLevel(): void {
69
- if (this.nestingLevel > 0) {
70
- this.nestingLevel -= 1;
69
+ if (this.#nestingLevel > 0) {
70
+ this.#nestingLevel -= 1;
71
71
  }
72
72
  }
73
73
 
74
74
  content(): string {
75
- return this.formattedContent.join('') + (this.newLines ? '\n' : '');
75
+ return this.#formattedContent.join('') + (this.#newLines ? '\n' : '');
76
76
  }
77
77
 
78
- private appendFormatting(): void {
79
- if (this.newLines) {
80
- for (let i = 0; i < this.newLines; ++i) {
81
- this.addText('\n');
78
+ #appendFormatting(): void {
79
+ if (this.#newLines) {
80
+ for (let i = 0; i < this.#newLines; ++i) {
81
+ this.#addText('\n');
82
82
  }
83
- this.addText(this.indent());
84
- } else if (this.softSpace) {
85
- this.addText(' ');
83
+ this.#addText(this.#indent());
84
+ } else if (this.#softSpace) {
85
+ this.#addText(' ');
86
86
  }
87
- if (this.hardSpaces) {
88
- for (let i = 0; i < this.hardSpaces; ++i) {
89
- this.addText(' ');
87
+ if (this.#hardSpaces) {
88
+ for (let i = 0; i < this.#hardSpaces; ++i) {
89
+ this.#addText(' ');
90
90
  }
91
91
  }
92
- this.newLines = 0;
93
- this.softSpace = false;
94
- this.hardSpaces = 0;
92
+ this.#newLines = 0;
93
+ this.#softSpace = false;
94
+ this.#hardSpaces = 0;
95
95
  }
96
96
 
97
- private indent(): string {
98
- const cachedValue = this.cachedIndents.get(this.nestingLevel);
97
+ #indent(): string {
98
+ const cachedValue = this.#cachedIndents.get(this.#nestingLevel);
99
99
  if (cachedValue) {
100
100
  return cachedValue;
101
101
  }
102
102
 
103
103
  let fullIndent = '';
104
- for (let i = 0; i < this.nestingLevel; ++i) {
104
+ for (let i = 0; i < this.#nestingLevel; ++i) {
105
105
  fullIndent += this.indentString;
106
106
  }
107
107
 
108
108
  // Cache a maximum of 20 nesting level indents.
109
- if (this.nestingLevel <= 20) {
110
- this.cachedIndents.set(this.nestingLevel, fullIndent);
109
+ if (this.#nestingLevel <= 20) {
110
+ this.#cachedIndents.set(this.#nestingLevel, fullIndent);
111
111
  }
112
112
  return fullIndent;
113
113
  }
114
114
 
115
- private addText(text: string): void {
116
- this.formattedContent.push(text);
117
- this.formattedContentLength += text.length;
115
+ #addText(text: string): void {
116
+ this.#formattedContent.push(text);
117
+ this.#formattedContentLength += text.length;
118
118
  }
119
119
 
120
- private addMappingIfNeeded(originalPosition: number): void {
121
- if (originalPosition - this.lastOriginalPosition === this.formattedContentLength - this.lastFormattedPosition) {
120
+ #addMappingIfNeeded(originalPosition: number): void {
121
+ if (originalPosition - this.#lastOriginalPosition === this.#formattedContentLength - this.#lastFormattedPosition) {
122
122
  return;
123
123
  }
124
124
  this.mapping.original.push(originalPosition);
125
- this.lastOriginalPosition = originalPosition;
126
- this.mapping.formatted.push(this.formattedContentLength);
127
- this.lastFormattedPosition = this.formattedContentLength;
125
+ this.#lastOriginalPosition = originalPosition;
126
+ this.mapping.formatted.push(this.#formattedContentLength);
127
+ this.#lastFormattedPosition = this.#formattedContentLength;
128
128
  }
129
129
  }
@@ -10,107 +10,107 @@ import {AbortTokenization, createTokenizer} from './FormatterWorker.js';
10
10
  import {JavaScriptFormatter} from './JavaScriptFormatter.js';
11
11
 
12
12
  export class HTMLFormatter {
13
- private readonly builder: FormattedContentBuilder;
14
- private readonly jsFormatter: JavaScriptFormatter;
15
- private readonly cssFormatter: CSSFormatter;
16
- private text?: string;
17
- private lineEndings?: number[];
18
- private model?: HTMLModel;
13
+ readonly #builder: FormattedContentBuilder;
14
+ readonly #jsFormatter: JavaScriptFormatter;
15
+ readonly #cssFormatter: CSSFormatter;
16
+ #text?: string;
17
+ #lineEndings?: number[];
18
+ #model?: HTMLModel;
19
19
 
20
20
  constructor(builder: FormattedContentBuilder) {
21
- this.builder = builder;
22
- this.jsFormatter = new JavaScriptFormatter(builder);
23
- this.cssFormatter = new CSSFormatter(builder);
21
+ this.#builder = builder;
22
+ this.#jsFormatter = new JavaScriptFormatter(builder);
23
+ this.#cssFormatter = new CSSFormatter(builder);
24
24
  }
25
25
 
26
26
  format(text: string, lineEndings: number[]): void {
27
- this.text = text;
28
- this.lineEndings = lineEndings;
29
- this.model = new HTMLModel(text);
30
- this.walk(this.model.document());
27
+ this.#text = text;
28
+ this.#lineEndings = lineEndings;
29
+ this.#model = new HTMLModel(text);
30
+ this.#walk(this.#model.document());
31
31
  }
32
32
 
33
- private formatTokensTill(element: FormatterElement, offset: number): void {
34
- if (!this.model) {
33
+ #formatTokensTill(element: FormatterElement, offset: number): void {
34
+ if (!this.#model) {
35
35
  return;
36
36
  }
37
37
 
38
- let nextToken = this.model.peekToken();
38
+ let nextToken = this.#model.peekToken();
39
39
  while (nextToken && nextToken.startOffset < offset) {
40
- const token = (this.model.nextToken() as Token);
41
- this.formatToken(element, token);
42
- nextToken = this.model.peekToken();
40
+ const token = (this.#model.nextToken() as Token);
41
+ this.#formatToken(element, token);
42
+ nextToken = this.#model.peekToken();
43
43
  }
44
44
  }
45
45
 
46
- private walk(element: FormatterElement): void {
46
+ #walk(element: FormatterElement): void {
47
47
  if (!element.openTag || !element.closeTag) {
48
48
  throw new Error('Element is missing open or close tag');
49
49
  }
50
50
 
51
51
  if (element.parent) {
52
- this.formatTokensTill(element.parent, element.openTag.startOffset);
52
+ this.#formatTokensTill(element.parent, element.openTag.startOffset);
53
53
  }
54
- this.beforeOpenTag(element);
55
- this.formatTokensTill(element, element.openTag.endOffset);
56
- this.afterOpenTag(element);
54
+ this.#beforeOpenTag(element);
55
+ this.#formatTokensTill(element, element.openTag.endOffset);
56
+ this.#afterOpenTag(element);
57
57
  for (let i = 0; i < element.children.length; ++i) {
58
- this.walk(element.children[i]);
58
+ this.#walk(element.children[i]);
59
59
  }
60
60
 
61
- this.formatTokensTill(element, element.closeTag.startOffset);
62
- this.beforeCloseTag(element);
63
- this.formatTokensTill(element, element.closeTag.endOffset);
64
- this.afterCloseTag(element);
61
+ this.#formatTokensTill(element, element.closeTag.startOffset);
62
+ this.#beforeCloseTag(element);
63
+ this.#formatTokensTill(element, element.closeTag.endOffset);
64
+ this.#afterCloseTag(element);
65
65
  }
66
66
 
67
- private beforeOpenTag(element: FormatterElement): void {
68
- if (!this.model) {
67
+ #beforeOpenTag(element: FormatterElement): void {
68
+ if (!this.#model) {
69
69
  return;
70
70
  }
71
71
 
72
- if (!element.children.length || element === this.model.document()) {
72
+ if (!element.children.length || element === this.#model.document()) {
73
73
  return;
74
74
  }
75
- this.builder.addNewLine();
75
+ this.#builder.addNewLine();
76
76
  }
77
77
 
78
- private afterOpenTag(element: FormatterElement): void {
79
- if (!this.model) {
78
+ #afterOpenTag(element: FormatterElement): void {
79
+ if (!this.#model) {
80
80
  return;
81
81
  }
82
82
 
83
- if (!element.children.length || element === this.model.document()) {
83
+ if (!element.children.length || element === this.#model.document()) {
84
84
  return;
85
85
  }
86
- this.builder.increaseNestingLevel();
87
- this.builder.addNewLine();
86
+ this.#builder.increaseNestingLevel();
87
+ this.#builder.addNewLine();
88
88
  }
89
89
 
90
- private beforeCloseTag(element: FormatterElement): void {
91
- if (!this.model) {
90
+ #beforeCloseTag(element: FormatterElement): void {
91
+ if (!this.#model) {
92
92
  return;
93
93
  }
94
94
 
95
- if (!element.children.length || element === this.model.document()) {
95
+ if (!element.children.length || element === this.#model.document()) {
96
96
  return;
97
97
  }
98
- this.builder.decreaseNestingLevel();
99
- this.builder.addNewLine();
98
+ this.#builder.decreaseNestingLevel();
99
+ this.#builder.addNewLine();
100
100
  }
101
101
 
102
- private afterCloseTag(_element: FormatterElement): void {
103
- this.builder.addNewLine();
102
+ #afterCloseTag(_element: FormatterElement): void {
103
+ this.#builder.addNewLine();
104
104
  }
105
105
 
106
- private formatToken(element: FormatterElement, token: Token): void {
106
+ #formatToken(element: FormatterElement, token: Token): void {
107
107
  if (Platform.StringUtilities.isWhitespace(token.value)) {
108
108
  return;
109
109
  }
110
110
  if (hasTokenInSet(token.type, 'comment') || hasTokenInSet(token.type, 'meta')) {
111
- this.builder.addNewLine();
112
- this.builder.addToken(token.value.trim(), token.startOffset);
113
- this.builder.addNewLine();
111
+ this.#builder.addNewLine();
112
+ this.#builder.addToken(token.value.trim(), token.startOffset);
113
+ this.#builder.addNewLine();
114
114
  return;
115
115
  }
116
116
 
@@ -121,33 +121,33 @@ export class HTMLFormatter {
121
121
  const isBodyToken =
122
122
  element.openTag.endOffset <= token.startOffset && token.startOffset < element.closeTag.startOffset;
123
123
  if (isBodyToken && element.name === 'style') {
124
- this.builder.addNewLine();
125
- this.builder.increaseNestingLevel();
126
- this.cssFormatter.format(this.text || '', this.lineEndings || [], token.startOffset, token.endOffset);
127
- this.builder.decreaseNestingLevel();
124
+ this.#builder.addNewLine();
125
+ this.#builder.increaseNestingLevel();
126
+ this.#cssFormatter.format(this.#text || '', this.#lineEndings || [], token.startOffset, token.endOffset);
127
+ this.#builder.decreaseNestingLevel();
128
128
  return;
129
129
  }
130
130
  if (isBodyToken && element.name === 'script') {
131
- this.builder.addNewLine();
132
- this.builder.increaseNestingLevel();
133
- if (this.scriptTagIsJavaScript(element)) {
134
- this.jsFormatter.format(this.text || '', this.lineEndings || [], token.startOffset, token.endOffset);
131
+ this.#builder.addNewLine();
132
+ this.#builder.increaseNestingLevel();
133
+ if (this.#scriptTagIsJavaScript(element)) {
134
+ this.#jsFormatter.format(this.#text || '', this.#lineEndings || [], token.startOffset, token.endOffset);
135
135
  } else {
136
- this.builder.addToken(token.value, token.startOffset);
137
- this.builder.addNewLine();
136
+ this.#builder.addToken(token.value, token.startOffset);
137
+ this.#builder.addNewLine();
138
138
  }
139
- this.builder.decreaseNestingLevel();
139
+ this.#builder.decreaseNestingLevel();
140
140
  return;
141
141
  }
142
142
 
143
143
  if (!isBodyToken && hasTokenInSet(token.type, 'attribute')) {
144
- this.builder.addSoftSpace();
144
+ this.#builder.addSoftSpace();
145
145
  }
146
146
 
147
- this.builder.addToken(token.value, token.startOffset);
147
+ this.#builder.addToken(token.value, token.startOffset);
148
148
  }
149
149
 
150
- private scriptTagIsJavaScript(element: FormatterElement): boolean {
150
+ #scriptTagIsJavaScript(element: FormatterElement): boolean {
151
151
  if (!element.openTag) {
152
152
  return true;
153
153
  }
@@ -200,37 +200,37 @@ function hasTokenInSet(tokenTypes: Set<string>, type: string): boolean {
200
200
  }
201
201
 
202
202
  export class HTMLModel {
203
- private state: ParseState;
204
- private readonly documentInternal: FormatterElement;
205
- private stack: FormatterElement[];
206
- private readonly tokens: Token[];
207
- private tokenIndex: number;
208
- private attributes: Map<string, string>;
209
- private attributeName: string;
210
- private tagName: string;
211
- private isOpenTag: boolean;
212
- private tagStartOffset?: number|null;
213
- private tagEndOffset?: number|null;
203
+ #state: ParseState;
204
+ readonly #documentInternal: FormatterElement;
205
+ #stack: FormatterElement[];
206
+ readonly #tokens: Token[];
207
+ #tokenIndex: number;
208
+ #attributes: Map<string, string>;
209
+ #attributeName: string;
210
+ #tagName: string;
211
+ #isOpenTag: boolean;
212
+ #tagStartOffset?: number|null;
213
+ #tagEndOffset?: number|null;
214
214
 
215
215
  constructor(text: string) {
216
- this.state = ParseState.Initial;
217
- this.documentInternal = new FormatterElement('document');
218
- this.documentInternal.openTag = new Tag('document', 0, 0, new Map(), true, false);
219
- this.documentInternal.closeTag = new Tag('document', text.length, text.length, new Map(), false, false);
216
+ this.#state = ParseState.Initial;
217
+ this.#documentInternal = new FormatterElement('document');
218
+ this.#documentInternal.openTag = new Tag('document', 0, 0, new Map(), true, false);
219
+ this.#documentInternal.closeTag = new Tag('document', text.length, text.length, new Map(), false, false);
220
220
 
221
- this.stack = [this.documentInternal];
221
+ this.#stack = [this.#documentInternal];
222
222
 
223
- this.tokens = [];
224
- this.tokenIndex = 0;
225
- this.build(text);
223
+ this.#tokens = [];
224
+ this.#tokenIndex = 0;
225
+ this.#build(text);
226
226
 
227
- this.attributes = new Map();
228
- this.attributeName = '';
229
- this.tagName = '';
230
- this.isOpenTag = false;
227
+ this.#attributes = new Map();
228
+ this.#attributeName = '';
229
+ this.#tagName = '';
230
+ this.#isOpenTag = false;
231
231
  }
232
232
 
233
- private build(text: string): void {
233
+ #build(text: string): void {
234
234
  const tokenizer = createTokenizer('text/html');
235
235
  let lastOffset = 0;
236
236
  const lowerCaseText = text.toLowerCase();
@@ -240,7 +240,7 @@ export class HTMLModel {
240
240
  if (lastOffset >= text.length) {
241
241
  break;
242
242
  }
243
- const element = this.stack[this.stack.length - 1];
243
+ const element = this.#stack[this.#stack.length - 1];
244
244
  if (!element) {
245
245
  break;
246
246
  }
@@ -257,16 +257,16 @@ export class HTMLModel {
257
257
  const tokenStart = element.openTag.endOffset;
258
258
  const tokenEnd = lastOffset;
259
259
  const tokenValue = text.substring(tokenStart, tokenEnd);
260
- this.tokens.push(new Token(tokenValue, new Set(), tokenStart, tokenEnd));
260
+ this.#tokens.push(new Token(tokenValue, new Set(), tokenStart, tokenEnd));
261
261
  }
262
262
 
263
- while (this.stack.length > 1) {
264
- const element = this.stack[this.stack.length - 1];
263
+ while (this.#stack.length > 1) {
264
+ const element = this.#stack[this.#stack.length - 1];
265
265
  if (!element) {
266
266
  break;
267
267
  }
268
268
 
269
- this.popElement(new Tag(element.name, text.length, text.length, new Map(), false, false));
269
+ this.#popElement(new Tag(element.name, text.length, text.length, new Map(), false, false));
270
270
  }
271
271
 
272
272
  function processToken(
@@ -278,10 +278,10 @@ export class HTMLModel {
278
278
 
279
279
  const tokenType = type ? new Set<string>(type.split(' ')) : new Set<string>();
280
280
  const token = new Token(tokenValue, tokenType, tokenStart, tokenEnd);
281
- this.tokens.push(token);
282
- this.updateDOM(token);
281
+ this.#tokens.push(token);
282
+ this.#updateDOM(token);
283
283
 
284
- const element = this.stack[this.stack.length - 1];
284
+ const element = this.#stack[this.#stack.length - 1];
285
285
  if (element && (element.name === 'script' || element.name === 'style') && element.openTag &&
286
286
  element.openTag.endOffset === lastOffset) {
287
287
  return AbortTokenization;
@@ -291,124 +291,125 @@ export class HTMLModel {
291
291
  }
292
292
  }
293
293
 
294
- private updateDOM(token: Token): void {
294
+ #updateDOM(token: Token): void {
295
295
  const value = token.value;
296
296
  const type = token.type;
297
- switch (this.state) {
297
+ switch (this.#state) {
298
298
  case ParseState.Initial:
299
299
  if (hasTokenInSet(type, 'bracket') && (value === '<' || value === '</')) {
300
- this.onStartTag(token);
301
- this.state = ParseState.Tag;
300
+ this.#onStartTag(token);
301
+ this.#state = ParseState.Tag;
302
302
  }
303
303
  return;
304
304
  case ParseState.Tag:
305
305
  if (hasTokenInSet(type, 'tag') && !hasTokenInSet(type, 'bracket')) {
306
- this.tagName = value.trim().toLowerCase();
306
+ this.#tagName = value.trim().toLowerCase();
307
307
  } else if (hasTokenInSet(type, 'attribute')) {
308
- this.attributeName = value.trim().toLowerCase();
309
- this.attributes.set(this.attributeName, '');
310
- this.state = ParseState.AttributeName;
308
+ this.#attributeName = value.trim().toLowerCase();
309
+ this.#attributes.set(this.#attributeName, '');
310
+ this.#state = ParseState.AttributeName;
311
311
  } else if (hasTokenInSet(type, 'bracket') && (value === '>' || value === '/>')) {
312
- this.onEndTag(token);
313
- this.state = ParseState.Initial;
312
+ this.#onEndTag(token);
313
+ this.#state = ParseState.Initial;
314
314
  }
315
315
  return;
316
316
  case ParseState.AttributeName:
317
317
  if (!type.size && value === '=') {
318
- this.state = ParseState.AttributeValue;
318
+ this.#state = ParseState.AttributeValue;
319
319
  } else if (hasTokenInSet(type, 'bracket') && (value === '>' || value === '/>')) {
320
- this.onEndTag(token);
321
- this.state = ParseState.Initial;
320
+ this.#onEndTag(token);
321
+ this.#state = ParseState.Initial;
322
322
  }
323
323
  return;
324
324
  case ParseState.AttributeValue:
325
325
  if (hasTokenInSet(type, 'string')) {
326
- this.attributes.set(this.attributeName, value);
327
- this.state = ParseState.Tag;
326
+ this.#attributes.set(this.#attributeName, value);
327
+ this.#state = ParseState.Tag;
328
328
  } else if (hasTokenInSet(type, 'bracket') && (value === '>' || value === '/>')) {
329
- this.onEndTag(token);
330
- this.state = ParseState.Initial;
329
+ this.#onEndTag(token);
330
+ this.#state = ParseState.Initial;
331
331
  }
332
332
  return;
333
333
  }
334
334
  }
335
335
 
336
- private onStartTag(token: Token): void {
337
- this.tagName = '';
338
- this.tagStartOffset = token.startOffset;
339
- this.tagEndOffset = null;
340
- this.attributes = new Map();
341
- this.attributeName = '';
342
- this.isOpenTag = token.value === '<';
336
+ #onStartTag(token: Token): void {
337
+ this.#tagName = '';
338
+ this.#tagStartOffset = token.startOffset;
339
+ this.#tagEndOffset = null;
340
+ this.#attributes = new Map();
341
+ this.#attributeName = '';
342
+ this.#isOpenTag = token.value === '<';
343
343
  }
344
344
 
345
- private onEndTag(token: Token): void {
346
- this.tagEndOffset = token.endOffset;
347
- const selfClosingTag = token.value === '/>' || SelfClosingTags.has(this.tagName);
345
+ #onEndTag(token: Token): void {
346
+ this.#tagEndOffset = token.endOffset;
347
+ const selfClosingTag = token.value === '/>' || SelfClosingTags.has(this.#tagName);
348
348
  const tag = new Tag(
349
- this.tagName, this.tagStartOffset || 0, this.tagEndOffset, this.attributes, this.isOpenTag, selfClosingTag);
350
- this.onTagComplete(tag);
349
+ this.#tagName, this.#tagStartOffset || 0, this.#tagEndOffset, this.#attributes, this.#isOpenTag,
350
+ selfClosingTag);
351
+ this.#onTagComplete(tag);
351
352
  }
352
353
 
353
- private onTagComplete(tag: Tag): void {
354
+ #onTagComplete(tag: Tag): void {
354
355
  if (tag.isOpenTag) {
355
- const topElement = this.stack[this.stack.length - 1];
356
+ const topElement = this.#stack[this.#stack.length - 1];
356
357
  if (topElement) {
357
358
  const tagSet = AutoClosingTags.get(topElement.name);
358
- if (topElement !== this.documentInternal && topElement.openTag && topElement.openTag.selfClosingTag) {
359
- this.popElement(autocloseTag(topElement, topElement.openTag.endOffset));
359
+ if (topElement !== this.#documentInternal && topElement.openTag && topElement.openTag.selfClosingTag) {
360
+ this.#popElement(autocloseTag(topElement, topElement.openTag.endOffset));
360
361
  } else if (tagSet && tagSet.has(tag.name)) {
361
- this.popElement(autocloseTag(topElement, tag.startOffset));
362
+ this.#popElement(autocloseTag(topElement, tag.startOffset));
362
363
  }
363
- this.pushElement(tag);
364
+ this.#pushElement(tag);
364
365
  }
365
366
  return;
366
367
  }
367
368
 
368
- let lastTag = this.stack[this.stack.length - 1];
369
- while (this.stack.length > 1 && lastTag && lastTag.name !== tag.name) {
370
- this.popElement(autocloseTag(lastTag, tag.startOffset));
371
- lastTag = this.stack[this.stack.length - 1];
369
+ let lastTag = this.#stack[this.#stack.length - 1];
370
+ while (this.#stack.length > 1 && lastTag && lastTag.name !== tag.name) {
371
+ this.#popElement(autocloseTag(lastTag, tag.startOffset));
372
+ lastTag = this.#stack[this.#stack.length - 1];
372
373
  }
373
- if (this.stack.length === 1) {
374
+ if (this.#stack.length === 1) {
374
375
  return;
375
376
  }
376
- this.popElement(tag);
377
+ this.#popElement(tag);
377
378
 
378
379
  function autocloseTag(element: FormatterElement, offset: number): Tag {
379
380
  return new Tag(element.name, offset, offset, new Map(), false, false);
380
381
  }
381
382
  }
382
383
 
383
- private popElement(closeTag: Tag): void {
384
- const element = this.stack.pop();
384
+ #popElement(closeTag: Tag): void {
385
+ const element = this.#stack.pop();
385
386
  if (!element) {
386
387
  return;
387
388
  }
388
389
  element.closeTag = closeTag;
389
390
  }
390
391
 
391
- private pushElement(openTag: Tag): void {
392
- const topElement = this.stack[this.stack.length - 1];
392
+ #pushElement(openTag: Tag): void {
393
+ const topElement = this.#stack[this.#stack.length - 1];
393
394
  const newElement = new FormatterElement(openTag.name);
394
395
  if (topElement) {
395
396
  newElement.parent = topElement;
396
397
  topElement.children.push(newElement);
397
398
  }
398
399
  newElement.openTag = openTag;
399
- this.stack.push(newElement);
400
+ this.#stack.push(newElement);
400
401
  }
401
402
 
402
403
  peekToken(): Token|null {
403
- return this.tokenIndex < this.tokens.length ? this.tokens[this.tokenIndex] : null;
404
+ return this.#tokenIndex < this.#tokens.length ? this.#tokens[this.#tokenIndex] : null;
404
405
  }
405
406
 
406
407
  nextToken(): Token|null {
407
- return this.tokens[this.tokenIndex++];
408
+ return this.#tokens[this.#tokenIndex++];
408
409
  }
409
410
 
410
411
  document(): FormatterElement {
411
- return this.documentInternal;
412
+ return this.#documentInternal;
412
413
  }
413
414
  }
414
415