chrome-devtools-frontend 1.0.971727 → 1.0.972361

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.
@@ -118,15 +118,13 @@ async function start(method: string, params: any): Promise<unknown> {
118
118
  if (method === 'snapshot') {
119
119
  // @ts-expect-error https://github.com/GoogleChrome/lighthouse/issues/11628
120
120
  return await self.runLighthouseSnapshot({
121
- url,
122
121
  config,
123
122
  page: puppeteerConnection.page,
124
123
  });
125
124
  }
126
125
 
127
126
  // @ts-expect-error https://github.com/GoogleChrome/lighthouse/issues/11628
128
- return await self.runLighthouseNavigation({
129
- url,
127
+ return await self.runLighthouseNavigation(url, {
130
128
  config,
131
129
  page: puppeteerConnection.page,
132
130
  });
@@ -123,24 +123,10 @@ export class CSSWorkspaceBinding implements SDK.TargetManager.SDKModelObserver<S
123
123
 
124
124
  propertyUILocation(cssProperty: SDK.CSSProperty.CSSProperty, forName: boolean): Workspace.UISourceCode.UILocation
125
125
  |null {
126
- const style = cssProperty.ownerStyle;
127
- if (!style || style.type !== SDK.CSSStyleDeclaration.Type.Regular || !style.styleSheetId) {
128
- return null;
129
- }
130
- const header = style.cssModel().styleSheetHeaderForId(style.styleSheetId);
131
- if (!header) {
126
+ const rawLocation = this.propertyRawLocation(cssProperty, forName);
127
+ if (!rawLocation) {
132
128
  return null;
133
129
  }
134
-
135
- const range = forName ? cssProperty.nameRange() : cssProperty.valueRange();
136
- if (!range) {
137
- return null;
138
- }
139
-
140
- const lineNumber = range.startLine;
141
- const columnNumber = range.startColumn;
142
- const rawLocation = new SDK.CSSModel.CSSLocation(
143
- header, header.lineNumberInSource(lineNumber), header.columnNumberInSource(lineNumber, columnNumber));
144
130
  return this.rawLocationToUILocation(rawLocation);
145
131
  }
146
132
 
@@ -13,6 +13,11 @@ interface DiffRequestOptions {
13
13
  shouldFormatDiff: boolean;
14
14
  }
15
15
 
16
+ interface DiffResponse {
17
+ diff: Diff.Diff.DiffArray;
18
+ formattedCurrentMapping?: FormatterModule.ScriptFormatter.FormatterSourceMapping;
19
+ }
20
+
16
21
  export class WorkspaceDiffImpl extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
17
22
  private readonly uiSourceCodeDiffs: WeakMap<Workspace.UISourceCode.UISourceCode, UISourceCodeDiff>;
18
23
  private readonly loadingUISourceCodes:
@@ -35,7 +40,7 @@ export class WorkspaceDiffImpl extends Common.ObjectWrapper.ObjectWrapper<EventT
35
40
  }
36
41
 
37
42
  requestDiff(uiSourceCode: Workspace.UISourceCode.UISourceCode, diffRequestOptions: DiffRequestOptions):
38
- Promise<Diff.Diff.DiffArray|null> {
43
+ Promise<DiffResponse|null> {
39
44
  return this.uiSourceCodeDiff(uiSourceCode).requestDiff(diffRequestOptions);
40
45
  }
41
46
 
@@ -185,7 +190,7 @@ export type EventTypes = {
185
190
 
186
191
  export class UISourceCodeDiff extends Common.ObjectWrapper.ObjectWrapper<UISourceCodeDiffEventTypes> {
187
192
  private uiSourceCode: Workspace.UISourceCode.UISourceCode;
188
- private requestDiffPromise: Promise<Diff.Diff.DiffArray|null>|null;
193
+ private requestDiffPromise: Promise<DiffResponse|null>|null;
189
194
  private pendingChanges: number|null;
190
195
  dispose: boolean;
191
196
  constructor(uiSourceCode: Workspace.UISourceCode.UISourceCode) {
@@ -218,7 +223,7 @@ export class UISourceCodeDiff extends Common.ObjectWrapper.ObjectWrapper<UISourc
218
223
  }
219
224
  }
220
225
 
221
- requestDiff(diffRequestOptions: DiffRequestOptions): Promise<Diff.Diff.DiffArray|null> {
226
+ requestDiff(diffRequestOptions: DiffRequestOptions): Promise<DiffResponse|null> {
222
227
  if (!this.requestDiffPromise) {
223
228
  this.requestDiffPromise = this.innerRequestDiff(diffRequestOptions);
224
229
  }
@@ -237,7 +242,7 @@ export class UISourceCodeDiff extends Common.ObjectWrapper.ObjectWrapper<UISourc
237
242
  return content.content || ('error' in content && content.error) || '';
238
243
  }
239
244
 
240
- private async innerRequestDiff({shouldFormatDiff}: DiffRequestOptions): Promise<Diff.Diff.DiffArray|null> {
245
+ private async innerRequestDiff({shouldFormatDiff}: DiffRequestOptions): Promise<DiffResponse|null> {
241
246
  if (this.dispose) {
242
247
  return null;
243
248
  }
@@ -270,15 +275,22 @@ export class UISourceCodeDiff extends Common.ObjectWrapper.ObjectWrapper<UISourc
270
275
  if (current === null || baseline === null) {
271
276
  return null;
272
277
  }
278
+ let formattedCurrentMapping;
273
279
  if (shouldFormatDiff) {
274
280
  baseline = (await FormatterModule.ScriptFormatter.format(
275
281
  this.uiSourceCode.contentType(), this.uiSourceCode.mimeType(), baseline))
276
282
  .formattedContent;
277
- current = (await FormatterModule.ScriptFormatter.format(
278
- this.uiSourceCode.contentType(), this.uiSourceCode.mimeType(), current))
279
- .formattedContent;
283
+ const formatCurrentResult = await FormatterModule.ScriptFormatter.format(
284
+ this.uiSourceCode.contentType(), this.uiSourceCode.mimeType(), current);
285
+ current = formatCurrentResult.formattedContent;
286
+ formattedCurrentMapping = formatCurrentResult.formattedMapping;
280
287
  }
281
- return Diff.Diff.DiffWrapper.lineDiff(baseline.split(/\r\n|\n|\r/), current.split(/\r\n|\n|\r/));
288
+ const reNewline = /\r\n?|\n/;
289
+ const diff = Diff.Diff.DiffWrapper.lineDiff(baseline.split(reNewline), current.split(reNewline));
290
+ return {
291
+ diff,
292
+ formattedCurrentMapping,
293
+ };
282
294
  }
283
295
  }
284
296
 
@@ -173,7 +173,7 @@ export class ChangesView extends UI.Widget.VBox {
173
173
  }
174
174
 
175
175
  if (!this.selectedUISourceCode) {
176
- this.renderDiffRows(null);
176
+ this.renderDiffRows();
177
177
  return;
178
178
  }
179
179
  const uiSourceCode = this.selectedUISourceCode;
@@ -181,12 +181,12 @@ export class ChangesView extends UI.Widget.VBox {
181
181
  this.hideDiff(i18nString(UIStrings.binaryData));
182
182
  return;
183
183
  }
184
- const diff = await this.workspaceDiff.requestDiff(
184
+ const diffResponse = await this.workspaceDiff.requestDiff(
185
185
  uiSourceCode, {shouldFormatDiff: Root.Runtime.experiments.isEnabled('preciseChanges')});
186
186
  if (this.selectedUISourceCode !== uiSourceCode) {
187
187
  return;
188
188
  }
189
- this.renderDiffRows(diff);
189
+ this.renderDiffRows(diffResponse?.diff);
190
190
  }
191
191
 
192
192
  private hideDiff(message: string): void {
@@ -197,7 +197,7 @@ export class ChangesView extends UI.Widget.VBox {
197
197
  this.emptyWidget.showWidget();
198
198
  }
199
199
 
200
- private renderDiffRows(diff: Diff.Diff.DiffArray|null): void {
200
+ private renderDiffRows(diff?: Diff.Diff.DiffArray): void {
201
201
  if (!diff || (diff.length === 1 && diff[0][0] === Diff.Diff.Operation.Equal)) {
202
202
  this.hideDiff(i18nString(UIStrings.noChanges));
203
203
  } else {
@@ -1043,16 +1043,22 @@ export class StylesSidebarPane extends Common.ObjectWrapper.eventMixin<EventType
1043
1043
  if (!url) {
1044
1044
  return false;
1045
1045
  }
1046
- const changedLines = this.#urlToChangeTracker.get(url)?.changedLines;
1047
- if (!changedLines) {
1046
+ const changeTracker = this.#urlToChangeTracker.get(url);
1047
+ if (!changeTracker) {
1048
1048
  return false;
1049
1049
  }
1050
+ const {changedLines, formattedCurrentMapping} = changeTracker;
1050
1051
  const uiLocation = Bindings.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().propertyUILocation(property, true);
1051
1052
  if (!uiLocation) {
1052
1053
  return false;
1053
1054
  }
1054
- // UILocation's lineNumber starts at 0, but changedLines start at 1.
1055
- return changedLines.has(uiLocation.lineNumber + 1);
1055
+ if (!formattedCurrentMapping) {
1056
+ // UILocation's lineNumber starts at 0, but changedLines start at 1.
1057
+ return changedLines.has(uiLocation.lineNumber + 1);
1058
+ }
1059
+ const formattedLineNumber =
1060
+ formattedCurrentMapping.originalToFormatted(uiLocation.lineNumber, uiLocation.columnNumber)[0];
1061
+ return changedLines.has(formattedLineNumber + 1);
1056
1062
  }
1057
1063
 
1058
1064
  private async refreshChangedLines(uiSourceCode: Workspace.UISourceCode.UISourceCode): Promise<void> {
@@ -1060,28 +1066,33 @@ export class StylesSidebarPane extends Common.ObjectWrapper.eventMixin<EventType
1060
1066
  if (!changeTracker) {
1061
1067
  return;
1062
1068
  }
1063
- const diff = await WorkspaceDiff.WorkspaceDiff.workspaceDiff().requestDiff(uiSourceCode, {shouldFormatDiff: true});
1069
+ const diffResponse =
1070
+ await WorkspaceDiff.WorkspaceDiff.workspaceDiff().requestDiff(uiSourceCode, {shouldFormatDiff: true});
1064
1071
  const changedLines = new Set<number>();
1065
- if (diff && diff.length > 0) {
1066
- const {rows} = DiffView.DiffView.buildDiffRows(diff);
1067
- for (const row of rows) {
1068
- if (row.type === DiffView.DiffView.RowType.Addition) {
1069
- changedLines.add(row.currentLineNumber);
1070
- }
1072
+ changeTracker.changedLines = changedLines;
1073
+ if (!diffResponse) {
1074
+ return;
1075
+ }
1076
+ const {diff, formattedCurrentMapping} = diffResponse;
1077
+ const {rows} = DiffView.DiffView.buildDiffRows(diff);
1078
+ for (const row of rows) {
1079
+ if (row.type === DiffView.DiffView.RowType.Addition) {
1080
+ changedLines.add(row.currentLineNumber);
1071
1081
  }
1072
1082
  }
1073
- changeTracker.changedLines = changedLines;
1083
+ changeTracker.formattedCurrentMapping = formattedCurrentMapping;
1074
1084
  }
1075
1085
 
1076
1086
  private async getFormattedChanges(): Promise<string> {
1077
1087
  let allChanges = '';
1078
1088
  for (const [url, {uiSourceCode}] of this.#urlToChangeTracker) {
1079
- const diff =
1089
+ const diffResponse =
1080
1090
  await WorkspaceDiff.WorkspaceDiff.workspaceDiff().requestDiff(uiSourceCode, {shouldFormatDiff: true});
1081
- if (!diff || diff.length < 2) {
1091
+ // Diff array with real diff will contain at least 2 lines.
1092
+ if (!diffResponse || diffResponse?.diff.length < 2) {
1082
1093
  continue;
1083
1094
  }
1084
- const changes = await formatCSSChangesFromDiff(diff);
1095
+ const changes = await formatCSSChangesFromDiff(diffResponse.diff);
1085
1096
  if (changes.length > 0) {
1086
1097
  allChanges += `/* ${escapeUrlAsCssComment(url)} */\n\n${changes}\n\n`;
1087
1098
  }
@@ -1231,6 +1242,7 @@ type ChangeTracker = {
1231
1242
  uiSourceCode: Workspace.UISourceCode.UISourceCode,
1232
1243
  changedLines: Set<number>,
1233
1244
  diffChangeCallback: () => Promise<void>,
1245
+ formattedCurrentMapping?: Formatter.ScriptFormatter.FormatterSourceMapping,
1234
1246
  };
1235
1247
 
1236
1248
  export async function formatCSSChangesFromDiff(diff: Diff.Diff.DiffArray): Promise<string> {
@@ -400,7 +400,9 @@ export class NavigatorView extends UI.Widget.VBox implements SDK.TargetManager.O
400
400
 
401
401
  const removedFrame = (event.data.frame as SDK.ResourceTreeModel.ResourceTreeFrame | null);
402
402
  const node = Array.from(this.uiSourceCodeNodes.get(uiSourceCode)).find(node => node.frame() === removedFrame);
403
- this.removeUISourceCodeNode((node as NavigatorUISourceCodeTreeNode));
403
+ if (node) {
404
+ this.removeUISourceCodeNode(node);
405
+ }
404
406
  }
405
407
 
406
408
  private acceptsUISourceCode(uiSourceCode: Workspace.UISourceCode.UISourceCode): boolean {