chrome-devtools-frontend 1.0.951864 → 1.0.952284
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.
- package/front_end/.eslintrc.js +6 -0
- package/front_end/entrypoints/formatter_worker/AcornTokenizer.ts +36 -36
- package/front_end/entrypoints/formatter_worker/CSSFormatter.ts +53 -53
- package/front_end/entrypoints/formatter_worker/ESTreeWalker.ts +11 -11
- package/front_end/entrypoints/formatter_worker/FormattedContentBuilder.ts +43 -43
- package/front_end/entrypoints/formatter_worker/HTMLFormatter.ts +106 -105
- package/front_end/entrypoints/formatter_worker/JavaScriptFormatter.ts +26 -26
- package/front_end/entrypoints/heap_snapshot_worker/AllocationProfile.ts +50 -55
- package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts +200 -200
- package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshotLoader.ts +84 -83
- package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshotWorkerDispatcher.ts +15 -15
- package/front_end/entrypoints/inspector_main/InspectorMain.ts +21 -21
- package/front_end/entrypoints/main/ExecutionContextSelector.ts +30 -30
- package/front_end/entrypoints/main/MainImpl.ts +12 -12
- package/front_end/entrypoints/node_app/NodeConnectionsPanel.ts +33 -33
- package/front_end/entrypoints/node_app/NodeMain.ts +35 -35
- package/front_end/generated/InspectorBackendCommands.js +5 -1
- package/front_end/generated/protocol.d.ts +16 -0
- package/front_end/models/issues_manager/ContentSecurityPolicyIssue.ts +6 -6
- package/front_end/models/issues_manager/ContrastCheckTrigger.ts +15 -15
- package/front_end/models/issues_manager/CorsIssue.ts +9 -9
- package/front_end/models/issues_manager/CrossOriginEmbedderPolicyIssue.ts +5 -5
- package/front_end/models/issues_manager/DeprecationIssue.ts +7 -7
- package/front_end/models/issues_manager/GenericIssue.ts +5 -5
- package/front_end/models/issues_manager/HeavyAdIssue.ts +5 -5
- package/front_end/models/issues_manager/Issue.ts +10 -10
- package/front_end/models/issues_manager/IssueResolver.ts +11 -10
- package/front_end/models/issues_manager/IssuesManager.ts +56 -56
- package/front_end/models/issues_manager/LowTextContrastIssue.ts +4 -4
- package/front_end/models/issues_manager/MixedContentIssue.ts +7 -7
- package/front_end/models/issues_manager/NavigatorUserAgentIssue.ts +7 -7
- package/front_end/models/issues_manager/QuirksModeIssue.ts +4 -4
- package/front_end/models/issues_manager/SameSiteCookieIssue.ts +16 -16
- package/front_end/models/issues_manager/SharedArrayBufferIssue.ts +5 -5
- package/front_end/models/issues_manager/SourceFrameIssuesManager.ts +32 -31
- package/front_end/models/issues_manager/TrustedWebActivityIssue.ts +5 -5
- package/front_end/models/issues_manager/WasmCrossOriginModuleSharingIssue.ts +5 -5
- package/front_end/panels/application/components/BackForwardCacheView.ts +33 -33
- package/front_end/panels/application/components/EndpointsGrid.ts +12 -12
- package/front_end/panels/application/components/FrameDetailsView.ts +108 -110
- package/front_end/panels/application/components/OriginTrialTreeView.ts +45 -45
- package/front_end/panels/application/components/PermissionsPolicySection.ts +19 -19
- package/front_end/panels/application/components/ReportsGrid.ts +30 -30
- package/front_end/panels/application/components/StackTrace.ts +48 -47
- package/front_end/panels/application/components/TrustTokensView.ts +31 -31
- package/front_end/panels/css_overview/CSSOverviewCompletedView.ts +41 -52
- package/front_end/panels/css_overview/CSSOverviewController.ts +2 -2
- package/front_end/panels/css_overview/CSSOverviewPanel.ts +18 -27
- package/front_end/panels/css_overview/CSSOverviewProcessingView.ts +2 -2
- package/front_end/panels/css_overview/CSSOverviewSidebarPanel.ts +6 -6
- package/front_end/panels/css_overview/components/CSSOverviewStartView.ts +4 -4
- package/front_end/panels/elements/components/AccessibilityTreeNode.ts +17 -17
- package/front_end/panels/elements/components/AdornerManager.ts +21 -21
- package/front_end/panels/elements/components/AdornerSettingsPane.ts +14 -14
- package/front_end/panels/elements/components/CSSQuery.ts +16 -16
- package/front_end/panels/elements/components/ComputedStyleProperty.ts +14 -14
- package/front_end/panels/elements/components/ComputedStyleTrace.ts +15 -15
- package/front_end/panels/elements/components/ElementsBreadcrumbs.ts +78 -78
- package/front_end/panels/elements/components/ElementsPanelLink.ts +16 -16
- package/front_end/panels/elements/components/LayoutPane.ts +47 -47
- package/front_end/panels/elements/components/NodeText.ts +18 -18
- package/front_end/panels/elements/components/QueryContainer.ts +40 -40
- package/front_end/panels/elements/components/StylePropertyEditor.ts +18 -18
- package/front_end/panels/emulation/components/DeviceSizeInputElement.ts +4 -4
- package/front_end/panels/issues/AffectedBlockedByResponseView.ts +4 -4
- package/front_end/panels/issues/AffectedCookiesView.ts +4 -5
- package/front_end/panels/issues/AffectedDirectivesView.ts +19 -19
- package/front_end/panels/issues/AffectedDocumentsInQuirksModeView.ts +7 -8
- package/front_end/panels/issues/AffectedElementsView.ts +4 -4
- package/front_end/panels/issues/AffectedElementsWithLowContrastView.ts +7 -8
- package/front_end/panels/issues/AffectedHeavyAdView.ts +8 -8
- package/front_end/panels/issues/AffectedResourcesView.ts +25 -26
- package/front_end/panels/issues/AffectedSharedArrayBufferIssueDetailsView.ts +8 -8
- package/front_end/panels/issues/AffectedSourcesView.ts +4 -4
- package/front_end/panels/issues/AffectedTrustedWebActivityIssueDetailsView.ts +4 -4
- package/front_end/panels/issues/AttributionReportingIssueDetailsView.ts +17 -17
- package/front_end/panels/issues/CSPViolationsListView.ts +22 -23
- package/front_end/panels/issues/CSPViolationsView.ts +17 -17
- package/front_end/panels/issues/ComboBoxOfCheckBoxes.ts +13 -13
- package/front_end/panels/issues/CorsIssueDetailsView.ts +23 -23
- package/front_end/panels/issues/GenericIssueDetailsView.ts +4 -4
- package/front_end/panels/issues/HiddenIssuesRow.ts +7 -7
- package/front_end/panels/issues/IssueAggregator.ts +95 -95
- package/front_end/panels/issues/IssueKindView.ts +14 -14
- package/front_end/panels/issues/IssueView.ts +98 -98
- package/front_end/panels/issues/IssuesPane.ts +102 -102
- package/front_end/panels/issues/WasmCrossOriginModuleSharingAffectedResourcesView.ts +5 -5
- package/front_end/panels/issues/components/HideIssuesMenu.ts +10 -10
- package/front_end/panels/media/PlayerListView.ts +160 -97
- package/front_end/panels/media/PlayerMessagesView.ts +1 -0
- package/front_end/panels/media/playerListView.css +58 -0
- package/front_end/panels/network/NetworkLogView.ts +2 -6
- package/front_end/panels/network/NetworkWaterfallColumn.ts +2 -4
- package/front_end/panels/network/components/RequestTrustTokensView.ts +40 -40
- package/front_end/panels/network/components/WebBundleInfoView.ts +9 -9
- package/front_end/panels/performance_monitor/PerformanceMonitor.ts +6 -12
- package/front_end/panels/settings/components/SyncSection.ts +14 -14
- package/front_end/panels/settings/emulation/components/UserAgentClientHintsForm.ts +96 -96
- package/front_end/panels/sources/BreakpointEditDialog.ts +4 -3
- package/front_end/panels/timeline/components/WebVitalsLane.ts +77 -76
- package/front_end/panels/timeline/components/WebVitalsTimeline.ts +133 -133
- package/front_end/panels/timeline/components/WebVitalsTooltip.ts +9 -9
- package/front_end/panels/webauthn/WebauthnPane.ts +203 -205
- package/front_end/ui/components/adorners/Adorner.ts +2 -2
- package/front_end/ui/components/buttons/Button.ts +9 -9
- package/front_end/ui/components/data_grid/DataGrid.ts +62 -62
- package/front_end/ui/components/data_grid/DataGridController.ts +22 -22
- package/front_end/ui/components/diff_view/DiffView.ts +6 -6
- package/front_end/ui/components/expandable_list/ExpandableList.ts +5 -5
- package/front_end/ui/components/icon_button/Icon.ts +4 -4
- package/front_end/ui/components/icon_button/IconButton.ts +4 -4
- package/front_end/ui/components/issue_counter/IssueCounter.ts +3 -3
- package/front_end/ui/components/issue_counter/IssueLinkIcon.ts +11 -11
- package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspector.ts +50 -50
- package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorController.ts +6 -6
- package/front_end/ui/components/linear_memory_inspector/LinearMemoryInspectorPane.ts +4 -4
- package/front_end/ui/components/linear_memory_inspector/LinearMemoryNavigator.ts +12 -12
- package/front_end/ui/components/linear_memory_inspector/LinearMemoryValueInterpreter.ts +11 -11
- package/front_end/ui/components/linear_memory_inspector/LinearMemoryViewer.ts +40 -39
- package/front_end/ui/components/linear_memory_inspector/ValueInterpreterDisplay.ts +18 -18
- package/front_end/ui/components/linear_memory_inspector/ValueInterpreterSettings.ts +6 -6
- package/front_end/ui/components/linkifier/LinkifierImpl.ts +4 -4
- package/front_end/ui/components/markdown_view/MarkdownImage.ts +5 -5
- package/front_end/ui/components/markdown_view/MarkdownLink.ts +2 -2
- package/front_end/ui/components/markdown_view/MarkdownView.ts +4 -4
- package/front_end/ui/components/panel_feedback/FeedbackButton.ts +2 -2
- package/front_end/ui/components/panel_feedback/PanelFeedback.ts +2 -2
- package/front_end/ui/components/panel_feedback/PreviewToggle.ts +4 -4
- package/front_end/ui/components/render_coordinator/RenderCoordinator.ts +22 -22
- package/front_end/ui/components/report_view/ReportView.ts +16 -16
- package/front_end/ui/components/request_link_icon/RequestLinkIcon.ts +14 -14
- package/front_end/ui/components/settings/SettingCheckbox.ts +5 -5
- package/front_end/ui/components/survey_link/SurveyLink.ts +8 -8
- package/front_end/ui/components/text_editor/TextEditor.ts +9 -9
- package/front_end/ui/components/text_prompt/TextPrompt.ts +18 -18
- package/front_end/ui/components/tree_outline/TreeOutline.ts +69 -70
- package/front_end/ui/legacy/themeColors.css +2 -0
- package/front_end/ui/legacy/theme_support/theme_support_impl.ts +12 -0
- package/package.json +1 -1
- package/scripts/eslint_rules/lib/use_private_class_members.js +41 -0
- package/scripts/eslint_rules/tests/use_private_class_members_test.js +62 -0
- package/scripts/migration/class-fields/migrate.js +2 -3
- package/scripts/migration/class-fields/migrate.sh +1 -3
- package/scripts/migration/class-fields/package.json +1 -1
package/front_end/.eslintrc.js
CHANGED
|
@@ -34,28 +34,28 @@ export type TokenOrComment = Acorn.Token|Acorn.Comment;
|
|
|
34
34
|
* out whether the next token should be the preceding comment or not.
|
|
35
35
|
*/
|
|
36
36
|
export class AcornTokenizer {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
readonly #content: string;
|
|
38
|
+
readonly #comments: Acorn.Comment[];
|
|
39
|
+
#tokenizer: {
|
|
40
40
|
getToken(): Acorn.Token,
|
|
41
41
|
[Symbol.iterator](): Iterator<Acorn.Token>,
|
|
42
42
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
#textCursor: TextUtils.TextCursor.TextCursor;
|
|
44
|
+
#tokenLineStartInternal: number;
|
|
45
|
+
#tokenLineEndInternal: number;
|
|
46
|
+
#tokenColumnStartInternal: number;
|
|
47
|
+
#bufferedToken?: TokenOrComment;
|
|
48
48
|
|
|
49
49
|
constructor(content: string) {
|
|
50
|
-
this
|
|
51
|
-
this
|
|
52
|
-
this
|
|
53
|
-
Acorn.tokenizer(this
|
|
54
|
-
const contentLineEndings = Platform.StringUtilities.findLineEndingIndexes(this
|
|
55
|
-
this
|
|
56
|
-
this
|
|
57
|
-
this
|
|
58
|
-
this
|
|
50
|
+
this.#content = content;
|
|
51
|
+
this.#comments = [];
|
|
52
|
+
this.#tokenizer =
|
|
53
|
+
Acorn.tokenizer(this.#content, {onComment: this.#comments, ecmaVersion: ECMA_VERSION, allowHashBang: true});
|
|
54
|
+
const contentLineEndings = Platform.StringUtilities.findLineEndingIndexes(this.#content);
|
|
55
|
+
this.#textCursor = new TextUtils.TextCursor.TextCursor(contentLineEndings);
|
|
56
|
+
this.#tokenLineStartInternal = 0;
|
|
57
|
+
this.#tokenLineEndInternal = 0;
|
|
58
|
+
this.#tokenColumnStartInternal = 0;
|
|
59
59
|
// If the first "token" should be a comment, we don't want to shift
|
|
60
60
|
// the comment from the array (which happens in `nextTokenInternal`).
|
|
61
61
|
// Therefore, we should bail out from retrieving the token if this
|
|
@@ -65,7 +65,7 @@ export class AcornTokenizer {
|
|
|
65
65
|
// themselves. In that case, we first retrieve the actual token, before
|
|
66
66
|
// we see the comment itself. In that case, we should proceed and
|
|
67
67
|
// initialize `bufferedToken` as normal, to allow us to fix the reordering.
|
|
68
|
-
if (this
|
|
68
|
+
if (this.#comments.length === 0) {
|
|
69
69
|
this.nextTokenInternal();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -95,20 +95,20 @@ export class AcornTokenizer {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
private nextTokenInternal(): TokenOrComment|undefined {
|
|
98
|
-
if (this
|
|
99
|
-
const nextComment = this
|
|
98
|
+
if (this.#comments.length) {
|
|
99
|
+
const nextComment = this.#comments.shift();
|
|
100
100
|
// If this was the last comment to process, we need to make
|
|
101
101
|
// sure to update our `bufferedToken` to become the actual
|
|
102
102
|
// token. This only happens when we are processing the very
|
|
103
103
|
// first comment of a file (usually a hashbang comment)
|
|
104
104
|
// in which case we don't have to fix the reordering of tokens.
|
|
105
|
-
if (!this
|
|
106
|
-
this
|
|
105
|
+
if (!this.#bufferedToken && this.#comments.length === 0) {
|
|
106
|
+
this.#bufferedToken = this.#tokenizer.getToken();
|
|
107
107
|
}
|
|
108
108
|
return nextComment;
|
|
109
109
|
}
|
|
110
|
-
const token = this
|
|
111
|
-
this
|
|
110
|
+
const token = this.#bufferedToken;
|
|
111
|
+
this.#bufferedToken = this.#tokenizer.getToken();
|
|
112
112
|
return token;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -118,35 +118,35 @@ export class AcornTokenizer {
|
|
|
118
118
|
return null;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
this
|
|
122
|
-
this
|
|
123
|
-
this
|
|
121
|
+
this.#textCursor.advance(token.start);
|
|
122
|
+
this.#tokenLineStartInternal = this.#textCursor.lineNumber();
|
|
123
|
+
this.#tokenColumnStartInternal = this.#textCursor.columnNumber();
|
|
124
124
|
|
|
125
|
-
this
|
|
126
|
-
this
|
|
125
|
+
this.#textCursor.advance(token.end);
|
|
126
|
+
this.#tokenLineEndInternal = this.#textCursor.lineNumber();
|
|
127
127
|
return token;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
peekToken(): TokenOrComment|null {
|
|
131
|
-
if (this
|
|
132
|
-
return this
|
|
131
|
+
if (this.#comments.length) {
|
|
132
|
+
return this.#comments[0];
|
|
133
133
|
}
|
|
134
|
-
if (!this
|
|
134
|
+
if (!this.#bufferedToken) {
|
|
135
135
|
return null;
|
|
136
136
|
}
|
|
137
|
-
return this
|
|
137
|
+
return this.#bufferedToken.type !== Acorn.tokTypes.eof ? this.#bufferedToken : null;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
tokenLineStart(): number {
|
|
141
|
-
return this
|
|
141
|
+
return this.#tokenLineStartInternal;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
tokenLineEnd(): number {
|
|
145
|
-
return this
|
|
145
|
+
return this.#tokenLineEndInternal;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
tokenColumnStart(): number {
|
|
149
|
-
return this
|
|
149
|
+
return this.#tokenColumnStartInternal;
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
@@ -40,21 +40,21 @@ const cssTrimEnd = (tokenValue: string): string => {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export class CSSFormatter {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
readonly #builder: FormattedContentBuilder;
|
|
44
|
+
#toOffset!: number;
|
|
45
|
+
#fromOffset!: number;
|
|
46
|
+
#lineEndings!: number[];
|
|
47
|
+
#lastLine: number;
|
|
48
|
+
#state: {
|
|
49
49
|
eatWhitespace: (boolean|undefined),
|
|
50
50
|
seenProperty: (boolean|undefined),
|
|
51
51
|
inPropertyValue: (boolean|undefined),
|
|
52
52
|
afterClosingBrace: (boolean|undefined),
|
|
53
53
|
};
|
|
54
54
|
constructor(builder: FormattedContentBuilder) {
|
|
55
|
-
this
|
|
56
|
-
this
|
|
57
|
-
this
|
|
55
|
+
this.#builder = builder;
|
|
56
|
+
this.#lastLine = -1;
|
|
57
|
+
this.#state = {
|
|
58
58
|
eatWhitespace: undefined,
|
|
59
59
|
seenProperty: undefined,
|
|
60
60
|
inPropertyValue: undefined,
|
|
@@ -63,84 +63,84 @@ export class CSSFormatter {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
format(text: string, lineEndings: number[], fromOffset: number, toOffset: number): void {
|
|
66
|
-
this
|
|
67
|
-
this
|
|
68
|
-
this
|
|
69
|
-
this
|
|
66
|
+
this.#lineEndings = lineEndings;
|
|
67
|
+
this.#fromOffset = fromOffset;
|
|
68
|
+
this.#toOffset = toOffset;
|
|
69
|
+
this.#state = {
|
|
70
70
|
eatWhitespace: undefined,
|
|
71
71
|
seenProperty: undefined,
|
|
72
72
|
inPropertyValue: undefined,
|
|
73
73
|
afterClosingBrace: undefined,
|
|
74
74
|
};
|
|
75
|
-
this
|
|
75
|
+
this.#lastLine = -1;
|
|
76
76
|
const tokenize = createTokenizer('text/css');
|
|
77
|
-
const oldEnforce = this
|
|
78
|
-
tokenize(text.substring(this
|
|
79
|
-
this
|
|
77
|
+
const oldEnforce = this.#builder.setEnforceSpaceBetweenWords(false);
|
|
78
|
+
tokenize(text.substring(this.#fromOffset, this.#toOffset), this.tokenCallback.bind(this));
|
|
79
|
+
this.#builder.setEnforceSpaceBetweenWords(oldEnforce);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
private tokenCallback(token: string, type: string|null, startPosition: number): void {
|
|
83
|
-
startPosition += this
|
|
84
|
-
const startLine =
|
|
85
|
-
|
|
86
|
-
if (startLine !== this
|
|
87
|
-
this
|
|
83
|
+
startPosition += this.#fromOffset;
|
|
84
|
+
const startLine = Platform.ArrayUtilities.lowerBound(
|
|
85
|
+
this.#lineEndings, startPosition, Platform.ArrayUtilities.DEFAULT_COMPARATOR);
|
|
86
|
+
if (startLine !== this.#lastLine) {
|
|
87
|
+
this.#state.eatWhitespace = true;
|
|
88
88
|
}
|
|
89
|
-
if (type && (/^property/.test(type) || /^variable-2/.test(type)) && !this
|
|
90
|
-
this
|
|
89
|
+
if (type && (/^property/.test(type) || /^variable-2/.test(type)) && !this.#state.inPropertyValue) {
|
|
90
|
+
this.#state.seenProperty = true;
|
|
91
91
|
}
|
|
92
|
-
this
|
|
92
|
+
this.#lastLine = startLine;
|
|
93
93
|
// https://drafts.csswg.org/css-syntax/#whitespace
|
|
94
94
|
const isWhitespace = /^(?:\r?\n|[\t\f\r ])+$/.test(token);
|
|
95
95
|
if (isWhitespace) {
|
|
96
|
-
if (!this
|
|
97
|
-
this
|
|
96
|
+
if (!this.#state.eatWhitespace) {
|
|
97
|
+
this.#builder.addSoftSpace();
|
|
98
98
|
}
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
this
|
|
101
|
+
this.#state.eatWhitespace = false;
|
|
102
102
|
if (token === '\n') {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
if (token !== '}') {
|
|
107
|
-
if (this
|
|
108
|
-
this
|
|
107
|
+
if (this.#state.afterClosingBrace) {
|
|
108
|
+
this.#builder.addNewLine(true);
|
|
109
109
|
}
|
|
110
|
-
this
|
|
110
|
+
this.#state.afterClosingBrace = false;
|
|
111
111
|
}
|
|
112
112
|
if (token === '}') {
|
|
113
|
-
if (this
|
|
114
|
-
this
|
|
113
|
+
if (this.#state.inPropertyValue) {
|
|
114
|
+
this.#builder.addNewLine();
|
|
115
115
|
}
|
|
116
|
-
this
|
|
117
|
-
this
|
|
118
|
-
this
|
|
119
|
-
} else if (token === ':' && !this
|
|
120
|
-
this
|
|
121
|
-
this
|
|
122
|
-
this
|
|
123
|
-
this
|
|
124
|
-
this
|
|
116
|
+
this.#builder.decreaseNestingLevel();
|
|
117
|
+
this.#state.afterClosingBrace = true;
|
|
118
|
+
this.#state.inPropertyValue = false;
|
|
119
|
+
} else if (token === ':' && !this.#state.inPropertyValue && this.#state.seenProperty) {
|
|
120
|
+
this.#builder.addToken(token, startPosition);
|
|
121
|
+
this.#builder.addSoftSpace();
|
|
122
|
+
this.#state.eatWhitespace = true;
|
|
123
|
+
this.#state.inPropertyValue = true;
|
|
124
|
+
this.#state.seenProperty = false;
|
|
125
125
|
return;
|
|
126
126
|
} else if (token === '{') {
|
|
127
|
-
this
|
|
128
|
-
this
|
|
129
|
-
this
|
|
130
|
-
this
|
|
127
|
+
this.#builder.addSoftSpace();
|
|
128
|
+
this.#builder.addToken(token, startPosition);
|
|
129
|
+
this.#builder.addNewLine();
|
|
130
|
+
this.#builder.increaseNestingLevel();
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
this
|
|
134
|
+
this.#builder.addToken(cssTrimEnd(token), startPosition);
|
|
135
135
|
|
|
136
|
-
if (type === 'comment' && !this
|
|
137
|
-
this
|
|
136
|
+
if (type === 'comment' && !this.#state.inPropertyValue && !this.#state.seenProperty) {
|
|
137
|
+
this.#builder.addNewLine();
|
|
138
138
|
}
|
|
139
|
-
if (token === ';' && this
|
|
140
|
-
this
|
|
141
|
-
this
|
|
139
|
+
if (token === ';' && this.#state.inPropertyValue) {
|
|
140
|
+
this.#state.inPropertyValue = false;
|
|
141
|
+
this.#builder.addNewLine();
|
|
142
142
|
} else if (token === '}') {
|
|
143
|
-
this
|
|
143
|
+
this.#builder.addNewLine();
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
}
|
|
@@ -7,16 +7,16 @@ import type * as Acorn from '../../third_party/acorn/acorn.js';
|
|
|
7
7
|
const SkipSubTreeObject: Object = {};
|
|
8
8
|
|
|
9
9
|
export class ESTreeWalker {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
readonly #beforeVisit: (arg0: Acorn.ESTree.Node) => (Object | undefined);
|
|
11
|
+
readonly #afterVisit: Function;
|
|
12
|
+
#walkNulls: boolean;
|
|
13
13
|
|
|
14
14
|
constructor(
|
|
15
15
|
beforeVisit: (arg0: Acorn.ESTree.Node) => (Object | undefined),
|
|
16
16
|
afterVisit?: ((arg0: Acorn.ESTree.Node) => void)) {
|
|
17
|
-
this
|
|
18
|
-
this
|
|
19
|
-
this
|
|
17
|
+
this.#beforeVisit = beforeVisit;
|
|
18
|
+
this.#afterVisit = afterVisit || function(): void {};
|
|
19
|
+
this.#walkNulls = false;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
|
|
@@ -26,7 +26,7 @@ export class ESTreeWalker {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
setWalkNulls(value: boolean): void {
|
|
29
|
-
this
|
|
29
|
+
this.#walkNulls = value;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
walk(ast: Acorn.ESTree.Node): void {
|
|
@@ -34,7 +34,7 @@ export class ESTreeWalker {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
private innerWalk(node: Acorn.ESTree.Node, parent: Acorn.ESTree.Node|null): void {
|
|
37
|
-
if (!node && parent && this
|
|
37
|
+
if (!node && parent && this.#walkNulls) {
|
|
38
38
|
const result = ({raw: 'null', value: null, parent: null} as Acorn.ESTree.SimpleLiteral);
|
|
39
39
|
// Otherwise Closure can't handle the definition
|
|
40
40
|
result.type = 'Literal';
|
|
@@ -47,8 +47,8 @@ export class ESTreeWalker {
|
|
|
47
47
|
}
|
|
48
48
|
node.parent = parent;
|
|
49
49
|
|
|
50
|
-
if (this
|
|
51
|
-
this
|
|
50
|
+
if (this.#beforeVisit.call(null, node) === ESTreeWalker.SkipSubtree) {
|
|
51
|
+
this.#afterVisit.call(null, node);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -82,7 +82,7 @@ export class ESTreeWalker {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
this
|
|
85
|
+
this.#afterVisit.call(null, node);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
private walkArray(nodeArray: Acorn.ESTree.Node[], parentNode: Acorn.ESTree.Node|null): void {
|
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
// found in the LICENSE file.
|
|
4
4
|
|
|
5
5
|
export class FormattedContentBuilder {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,14 +20,14 @@ export class FormattedContentBuilder {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
setEnforceSpaceBetweenWords(value: boolean): boolean {
|
|
23
|
-
const oldValue = this
|
|
24
|
-
this
|
|
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
|
|
30
|
-
if (this
|
|
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
|
|
|
@@ -39,91 +39,91 @@ export class FormattedContentBuilder {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
addSoftSpace(): void {
|
|
42
|
-
if (!this
|
|
43
|
-
this
|
|
42
|
+
if (!this.#hardSpaces) {
|
|
43
|
+
this.#softSpace = true;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
addHardSpace(): void {
|
|
48
|
-
this
|
|
49
|
-
++this
|
|
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
|
|
54
|
+
if (!this.#formattedContentLength) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
if (noSquash) {
|
|
58
|
-
++this
|
|
58
|
+
++this.#newLines;
|
|
59
59
|
} else {
|
|
60
|
-
this
|
|
60
|
+
this.#newLines = this.#newLines || 1;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
increaseNestingLevel(): void {
|
|
65
|
-
this
|
|
65
|
+
this.#nestingLevel += 1;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
decreaseNestingLevel(): void {
|
|
69
|
-
if (this
|
|
70
|
-
this
|
|
69
|
+
if (this.#nestingLevel > 0) {
|
|
70
|
+
this.#nestingLevel -= 1;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
content(): string {
|
|
75
|
-
return this
|
|
75
|
+
return this.#formattedContent.join('') + (this.#newLines ? '\n' : '');
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
private appendFormatting(): void {
|
|
79
|
-
if (this
|
|
80
|
-
for (let i = 0; i < this
|
|
79
|
+
if (this.#newLines) {
|
|
80
|
+
for (let i = 0; i < this.#newLines; ++i) {
|
|
81
81
|
this.addText('\n');
|
|
82
82
|
}
|
|
83
83
|
this.addText(this.indent());
|
|
84
|
-
} else if (this
|
|
84
|
+
} else if (this.#softSpace) {
|
|
85
85
|
this.addText(' ');
|
|
86
86
|
}
|
|
87
|
-
if (this
|
|
88
|
-
for (let i = 0; i < this
|
|
87
|
+
if (this.#hardSpaces) {
|
|
88
|
+
for (let i = 0; i < this.#hardSpaces; ++i) {
|
|
89
89
|
this.addText(' ');
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
this
|
|
93
|
-
this
|
|
94
|
-
this
|
|
92
|
+
this.#newLines = 0;
|
|
93
|
+
this.#softSpace = false;
|
|
94
|
+
this.#hardSpaces = 0;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
private indent(): string {
|
|
98
|
-
const cachedValue = this
|
|
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
|
|
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
|
|
110
|
-
this
|
|
109
|
+
if (this.#nestingLevel <= 20) {
|
|
110
|
+
this.#cachedIndents.set(this.#nestingLevel, fullIndent);
|
|
111
111
|
}
|
|
112
112
|
return fullIndent;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
private addText(text: string): void {
|
|
116
|
-
this
|
|
117
|
-
this
|
|
116
|
+
this.#formattedContent.push(text);
|
|
117
|
+
this.#formattedContentLength += text.length;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
private addMappingIfNeeded(originalPosition: number): void {
|
|
121
|
-
if (originalPosition - this
|
|
121
|
+
if (originalPosition - this.#lastOriginalPosition === this.#formattedContentLength - this.#lastFormattedPosition) {
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
this.mapping.original.push(originalPosition);
|
|
125
|
-
this
|
|
126
|
-
this.mapping.formatted.push(this
|
|
127
|
-
this
|
|
125
|
+
this.#lastOriginalPosition = originalPosition;
|
|
126
|
+
this.mapping.formatted.push(this.#formattedContentLength);
|
|
127
|
+
this.#lastFormattedPosition = this.#formattedContentLength;
|
|
128
128
|
}
|
|
129
129
|
}
|