chrome-devtools-frontend 1.0.1013367 → 1.0.1014853
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/.eslintignore +1 -0
- package/docs/workflows.md +28 -0
- package/front_end/core/i18n/locales/en-US.json +7 -1
- package/front_end/core/i18n/locales/en-XL.json +7 -1
- package/front_end/core/sdk/SourceMap.ts +88 -27
- package/front_end/models/issues_manager/DeprecationIssue.ts +24 -2
- package/front_end/models/javascript_metadata/DOMPinnedProperties.ts +4243 -0
- package/front_end/models/source_map_scopes/NamesResolver.ts +134 -36
- package/front_end/models/workspace/UISourceCode.ts +1 -1
- package/front_end/panels/lighthouse/LighthouseStartView.ts +1 -0
- package/front_end/panels/sources/TabbedEditorContainer.ts +16 -4
- package/front_end/ui/components/linear_memory_inspector/ValueInterpreterDisplay.ts +6 -6
- package/front_end/ui/components/linear_memory_inspector/valueInterpreterDisplay.css +8 -0
- package/package.json +1 -1
- package/scripts/devtools_paths.js +1 -1
- package/scripts/eslint_rules/lib/check_component_naming.js +14 -6
- package/scripts/eslint_rules/tests/check_component_naming_test.js +23 -0
- package/scripts/webidl-properties/config.js +345 -0
- package/scripts/webidl-properties/get-props.js +150 -0
- package/scripts/webidl-properties/index.js +90 -0
- package/scripts/webidl-properties/package.json +9 -0
- package/scripts/webidl-properties/tests.js +162 -0
- package/scripts/webidl-properties/util.js +81 -0
@@ -17,14 +17,17 @@ interface CachedScopeMap {
|
|
17
17
|
const scopeToCachedIdentifiersMap = new WeakMap<SDK.DebuggerModel.ScopeChainEntry, CachedScopeMap>();
|
18
18
|
const cachedMapByCallFrame = new WeakMap<SDK.DebuggerModel.CallFrame, Map<string, string>>();
|
19
19
|
|
20
|
-
export class
|
20
|
+
export class IdentifierPositions {
|
21
21
|
name: string;
|
22
|
-
lineNumber: number;
|
23
|
-
|
24
|
-
constructor(name: string, lineNumber: number, columnNumber: number) {
|
22
|
+
positions: {lineNumber: number, columnNumber: number}[];
|
23
|
+
|
24
|
+
constructor(name: string, positions: {lineNumber: number, columnNumber: number}[] = []) {
|
25
25
|
this.name = name;
|
26
|
-
this.
|
27
|
-
|
26
|
+
this.positions = positions;
|
27
|
+
}
|
28
|
+
|
29
|
+
addPosition(lineNumber: number, columnNumber: number): void {
|
30
|
+
this.positions.push({lineNumber, columnNumber});
|
28
31
|
}
|
29
32
|
}
|
30
33
|
|
@@ -66,7 +69,7 @@ const computeScopeTree = async function(functionScope: SDK.DebuggerModel.ScopeCh
|
|
66
69
|
|
67
70
|
export const scopeIdentifiers = async function(
|
68
71
|
functionScope: SDK.DebuggerModel.ScopeChainEntry|null, scope: SDK.DebuggerModel.ScopeChainEntry): Promise<{
|
69
|
-
freeVariables:
|
72
|
+
freeVariables: IdentifierPositions[], boundVariables: IdentifierPositions[],
|
70
73
|
}|null> {
|
71
74
|
if (!functionScope) {
|
72
75
|
return null;
|
@@ -132,24 +135,33 @@ export const scopeIdentifiers = async function(
|
|
132
135
|
continue;
|
133
136
|
}
|
134
137
|
|
138
|
+
const identifier = new IdentifierPositions(variable.name);
|
135
139
|
for (const offset of variable.offsets) {
|
136
140
|
const start = offset + slide;
|
137
141
|
cursor.resetTo(start);
|
138
|
-
|
142
|
+
identifier.addPosition(cursor.lineNumber(), cursor.columnNumber());
|
139
143
|
}
|
144
|
+
boundVariables.push(identifier);
|
140
145
|
}
|
141
146
|
|
142
147
|
// Compute free variables by collecting all the ancestor variables that are used in |containingScope|.
|
143
148
|
const freeVariables = [];
|
144
149
|
for (const ancestor of ancestorScopes) {
|
145
150
|
for (const ancestorVariable of ancestor.variables) {
|
151
|
+
let identifier = null;
|
146
152
|
for (const offset of ancestorVariable.offsets) {
|
147
153
|
if (offset >= containingScope.start && offset < containingScope.end) {
|
154
|
+
if (!identifier) {
|
155
|
+
identifier = new IdentifierPositions(ancestorVariable.name);
|
156
|
+
}
|
148
157
|
const start = offset + slide;
|
149
158
|
cursor.resetTo(start);
|
150
|
-
|
159
|
+
identifier.addPosition(cursor.lineNumber(), cursor.columnNumber());
|
151
160
|
}
|
152
161
|
}
|
162
|
+
if (identifier) {
|
163
|
+
freeVariables.push(identifier);
|
164
|
+
}
|
153
165
|
}
|
154
166
|
}
|
155
167
|
return {boundVariables, freeVariables};
|
@@ -162,6 +174,15 @@ export const scopeIdentifiers = async function(
|
|
162
174
|
}
|
163
175
|
};
|
164
176
|
|
177
|
+
const identifierAndPunctuationRegExp = /^\s*([A-Za-z_$][A-Za-z_$0-9]*)\s*([.;,]?)\s*$/;
|
178
|
+
|
179
|
+
const enum Punctuation {
|
180
|
+
None = 0,
|
181
|
+
Comma = 1,
|
182
|
+
Dot = 2,
|
183
|
+
Semicolon = 3,
|
184
|
+
}
|
185
|
+
|
165
186
|
const resolveScope =
|
166
187
|
async(scope: SDK.DebuggerModel
|
167
188
|
.ScopeChainEntry): Promise<{variableMapping: Map<string, string>, thisMapping: string | null}> => {
|
@@ -170,8 +191,6 @@ const resolveScope =
|
|
170
191
|
const sourceMap = Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().sourceMapForScript(script);
|
171
192
|
|
172
193
|
if (!cachedScopeMap || cachedScopeMap.sourceMap !== sourceMap) {
|
173
|
-
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
175
194
|
// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
|
176
195
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
177
196
|
const identifiersPromise =
|
@@ -187,17 +206,33 @@ const resolveScope =
|
|
187
206
|
// missing identifier names from SourceMap ranges.
|
188
207
|
const promises: Promise<void>[] = [];
|
189
208
|
|
190
|
-
const resolveEntry = (id:
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
209
|
+
const resolveEntry = (id: IdentifierPositions, handler: (sourceName: string) => void): void => {
|
210
|
+
// First see if we have a source map entry with a name for the identifier.
|
211
|
+
for (const position of id.positions) {
|
212
|
+
const entry = sourceMap.findEntry(position.lineNumber, position.columnNumber);
|
213
|
+
if (entry && entry.name) {
|
214
|
+
handler(entry.name);
|
215
|
+
return;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
// If there is no entry with the name field, try to infer the name from the source positions.
|
219
|
+
async function resolvePosition(): Promise<void> {
|
220
|
+
if (!sourceMap) {
|
221
|
+
return;
|
222
|
+
}
|
223
|
+
// Let us find the first non-empty mapping of |id| and return that. Ideally, we would
|
224
|
+
// try to compute all the mappings and only use the mapping if all the non-empty
|
225
|
+
// mappings agree. However, that can be expensive for identifiers with many uses,
|
226
|
+
// so we iterate sequentially, stopping at the first non-empty mapping.
|
227
|
+
for (const position of id.positions) {
|
228
|
+
const sourceName = await resolveSourceName(script, sourceMap, id.name, position, textCache);
|
196
229
|
if (sourceName) {
|
197
230
|
handler(sourceName);
|
231
|
+
return;
|
198
232
|
}
|
199
|
-
}
|
233
|
+
}
|
200
234
|
}
|
235
|
+
promises.push(resolvePosition());
|
201
236
|
};
|
202
237
|
|
203
238
|
const functionScope = findFunctionScope();
|
@@ -229,35 +264,98 @@ const resolveScope =
|
|
229
264
|
return await cachedScopeMap.mappingPromise;
|
230
265
|
|
231
266
|
async function resolveSourceName(
|
232
|
-
script: SDK.Script.Script, sourceMap: SDK.SourceMap.SourceMap,
|
267
|
+
script: SDK.Script.Script, sourceMap: SDK.SourceMap.SourceMap, name: string,
|
268
|
+
position: {lineNumber: number, columnNumber: number},
|
233
269
|
textCache: Map<string, TextUtils.Text.Text>): Promise<string|null> {
|
234
|
-
const
|
235
|
-
|
236
|
-
if (!startEntry || !endEntry || !startEntry.sourceURL || startEntry.sourceURL !== endEntry.sourceURL ||
|
237
|
-
!startEntry.sourceLineNumber || !startEntry.sourceColumnNumber || !endEntry.sourceLineNumber ||
|
238
|
-
!endEntry.sourceColumnNumber) {
|
270
|
+
const ranges = sourceMap.findEntryRanges(position.lineNumber, position.columnNumber);
|
271
|
+
if (!ranges) {
|
239
272
|
return null;
|
240
273
|
}
|
241
|
-
|
242
|
-
|
243
|
-
endEntry.sourceColumnNumber);
|
274
|
+
// Extract the underlying text from the compiled code's range and make sure that
|
275
|
+
// it starts with the identifier |name|.
|
244
276
|
const uiSourceCode =
|
245
277
|
Bindings.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().uiSourceCodeForSourceMapSourceURL(
|
246
|
-
script.debuggerModel,
|
278
|
+
script.debuggerModel, ranges.sourceURL, script.isContentScript());
|
247
279
|
if (!uiSourceCode) {
|
248
280
|
return null;
|
249
281
|
}
|
250
|
-
const
|
251
|
-
if (!
|
282
|
+
const compiledText = getTextFor((await script.requestContent()).content);
|
283
|
+
if (!compiledText) {
|
284
|
+
return null;
|
285
|
+
}
|
286
|
+
const compiledToken = compiledText.extract(ranges.range);
|
287
|
+
const parsedCompiledToken = extractIdentifier(compiledToken);
|
288
|
+
if (!parsedCompiledToken) {
|
289
|
+
return null;
|
290
|
+
}
|
291
|
+
const {name: compiledName, punctuation: compiledPunctuation} = parsedCompiledToken;
|
292
|
+
if (compiledName !== name) {
|
293
|
+
return null;
|
294
|
+
}
|
295
|
+
|
296
|
+
// Extract the mapped name from the source code range and ensure that the punctuation
|
297
|
+
// matches the one from the compiled code.
|
298
|
+
const sourceText = getTextFor((await uiSourceCode.requestContent()).content);
|
299
|
+
if (!sourceText) {
|
252
300
|
return null;
|
253
301
|
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
302
|
+
const sourceToken = sourceText.extract(ranges.sourceRange);
|
303
|
+
const parsedSourceToken = extractIdentifier(sourceToken);
|
304
|
+
if (!parsedSourceToken) {
|
305
|
+
return null;
|
306
|
+
}
|
307
|
+
const {name: sourceName, punctuation: sourcePunctuation} = parsedSourceToken;
|
308
|
+
// Accept the source name if it is followed by the same punctuation.
|
309
|
+
if (compiledPunctuation === sourcePunctuation) {
|
310
|
+
return sourceName;
|
311
|
+
}
|
312
|
+
// Let us also allow semicolons into commas since that it is a common transformation.
|
313
|
+
if (compiledPunctuation === Punctuation.Comma && sourcePunctuation === Punctuation.Semicolon) {
|
314
|
+
return sourceName;
|
315
|
+
}
|
316
|
+
|
317
|
+
return null;
|
318
|
+
|
319
|
+
function extractIdentifier(token: string): {name: string, punctuation: Punctuation}|null {
|
320
|
+
const match = token.match(identifierAndPunctuationRegExp);
|
321
|
+
if (!match) {
|
322
|
+
return null;
|
323
|
+
}
|
324
|
+
|
325
|
+
const name = match[1];
|
326
|
+
let punctuation: Punctuation|null = null;
|
327
|
+
switch (match[2]) {
|
328
|
+
case '.':
|
329
|
+
punctuation = Punctuation.Dot;
|
330
|
+
break;
|
331
|
+
case ',':
|
332
|
+
punctuation = Punctuation.Comma;
|
333
|
+
break;
|
334
|
+
case ';':
|
335
|
+
punctuation = Punctuation.Semicolon;
|
336
|
+
break;
|
337
|
+
case '':
|
338
|
+
punctuation = Punctuation.None;
|
339
|
+
break;
|
340
|
+
default:
|
341
|
+
console.error(`Name token parsing error: unexpected token "${match[2]}"`);
|
342
|
+
return null;
|
343
|
+
}
|
344
|
+
|
345
|
+
return {name, punctuation};
|
346
|
+
}
|
347
|
+
|
348
|
+
function getTextFor(content: string|null): TextUtils.Text.Text|null {
|
349
|
+
if (!content) {
|
350
|
+
return null;
|
351
|
+
}
|
352
|
+
let text = textCache.get(content);
|
353
|
+
if (!text) {
|
354
|
+
text = new TextUtils.Text.Text(content);
|
355
|
+
textCache.set(content, text);
|
356
|
+
}
|
357
|
+
return text;
|
258
358
|
}
|
259
|
-
const originalIdentifier = text.extract(sourceTextRange).trim();
|
260
|
-
return /[a-zA-Z0-9_$]+/.test(originalIdentifier) ? originalIdentifier : null;
|
261
359
|
}
|
262
360
|
|
263
361
|
function findFunctionScope(): SDK.DebuggerModel.ScopeChainEntry|null {
|
@@ -131,7 +131,7 @@ export class UISourceCode extends Common.ObjectWrapper.ObjectWrapper<EventTypes>
|
|
131
131
|
// DevTools UI to be the same script. For now this is just the url but this
|
132
132
|
// is likely to change in the future.
|
133
133
|
canononicalScriptId(): string {
|
134
|
-
return this.urlInternal
|
134
|
+
return `${this.contentTypeInternal.name()},${this.urlInternal}`;
|
135
135
|
}
|
136
136
|
|
137
137
|
parentURL(): Platform.DevToolsPath.UrlString {
|
@@ -73,7 +73,8 @@ export class TabbedEditorContainer extends Common.ObjectWrapper.ObjectWrapper<Ev
|
|
73
73
|
private readonly files: Map<string, Workspace.UISourceCode.UISourceCode>;
|
74
74
|
private readonly previouslyViewedFilesSetting: Common.Settings.Setting<SerializedHistoryItem[]>;
|
75
75
|
private readonly history: History;
|
76
|
-
private readonly uriToUISourceCode: Map<
|
76
|
+
private readonly uriToUISourceCode: Map<Platform.DevToolsPath.UrlString, Workspace.UISourceCode.UISourceCode>;
|
77
|
+
private readonly idToUISourceCode: Map<string, Workspace.UISourceCode.UISourceCode>;
|
77
78
|
private currentFileInternal!: Workspace.UISourceCode.UISourceCode|null;
|
78
79
|
private currentView!: UI.Widget.Widget|null;
|
79
80
|
private scrollTimer?: number;
|
@@ -104,6 +105,7 @@ export class TabbedEditorContainer extends Common.ObjectWrapper.ObjectWrapper<Ev
|
|
104
105
|
this.previouslyViewedFilesSetting = setting;
|
105
106
|
this.history = History.fromObject(this.previouslyViewedFilesSetting.get());
|
106
107
|
this.uriToUISourceCode = new Map();
|
108
|
+
this.idToUISourceCode = new Map();
|
107
109
|
}
|
108
110
|
|
109
111
|
private onBindingCreated(event: Common.EventTarget.EventTargetEvent<Persistence.Persistence.PersistenceBinding>):
|
@@ -356,12 +358,13 @@ export class TabbedEditorContainer extends Common.ObjectWrapper.ObjectWrapper<Ev
|
|
356
358
|
private canonicalUISourceCode(uiSourceCode: Workspace.UISourceCode.UISourceCode):
|
357
359
|
Workspace.UISourceCode.UISourceCode {
|
358
360
|
// Check if we have already a UISourceCode for this url
|
359
|
-
const existingSourceCode = this.
|
361
|
+
const existingSourceCode = this.idToUISourceCode.get(uiSourceCode.canononicalScriptId());
|
360
362
|
if (existingSourceCode) {
|
361
363
|
// Ignore incoming uiSourceCode, we already have this file.
|
362
364
|
return existingSourceCode;
|
363
365
|
}
|
364
|
-
this.
|
366
|
+
this.idToUISourceCode.set(uiSourceCode.canononicalScriptId(), uiSourceCode);
|
367
|
+
this.uriToUISourceCode.set(uiSourceCode.url(), uiSourceCode);
|
365
368
|
return uiSourceCode;
|
366
369
|
}
|
367
370
|
|
@@ -420,6 +423,9 @@ export class TabbedEditorContainer extends Common.ObjectWrapper.ObjectWrapper<Ev
|
|
420
423
|
if (this.uriToUISourceCode.get(uiSourceCode.url()) === uiSourceCode) {
|
421
424
|
this.uriToUISourceCode.delete(uiSourceCode.url());
|
422
425
|
}
|
426
|
+
if (this.idToUISourceCode.get(uiSourceCode.canononicalScriptId()) === uiSourceCode) {
|
427
|
+
this.idToUISourceCode.delete(uiSourceCode.canononicalScriptId());
|
428
|
+
}
|
423
429
|
}
|
424
430
|
this.tabbedPane.closeTabs(tabIds);
|
425
431
|
}
|
@@ -591,7 +597,13 @@ export class TabbedEditorContainer extends Common.ObjectWrapper.ObjectWrapper<Ev
|
|
591
597
|
this.uriToUISourceCode.delete(k);
|
592
598
|
}
|
593
599
|
}
|
594
|
-
//
|
600
|
+
// Remove from map under old id if it has changed.
|
601
|
+
for (const [k, v] of this.idToUISourceCode) {
|
602
|
+
if (v === uiSourceCode && k !== v.canononicalScriptId()) {
|
603
|
+
this.idToUISourceCode.delete(k);
|
604
|
+
}
|
605
|
+
}
|
606
|
+
// Ensure it is mapped under current url and id.
|
595
607
|
this.canonicalUISourceCode(uiSourceCode);
|
596
608
|
}
|
597
609
|
|
@@ -153,10 +153,10 @@ export class ValueInterpreterDisplay extends HTMLElement {
|
|
153
153
|
// Disabled until https://crbug.com/1079231 is fixed.
|
154
154
|
// clang-format off
|
155
155
|
return html`
|
156
|
-
<span class="value-type-cell-no-mode value-type-cell">${i18n.i18n.lockedString(type)}</span>
|
156
|
+
<span class="value-type-cell-no-mode value-type-cell selectable-text">${i18n.i18n.lockedString(type)}</span>
|
157
157
|
<div class="value-type-cell">
|
158
158
|
<div class="value-type-value-with-link" data-value="true">
|
159
|
-
<span>${unsignedValue}</span>
|
159
|
+
<span class="selectable-text">${unsignedValue}</span>
|
160
160
|
${
|
161
161
|
html`
|
162
162
|
<button class="jump-to-button" data-jump="true" title=${buttonTitle} ?disabled=${jumpDisabled}
|
@@ -179,7 +179,7 @@ export class ValueInterpreterDisplay extends HTMLElement {
|
|
179
179
|
// Disabled until https://crbug.com/1079231 is fixed.
|
180
180
|
// clang-format off
|
181
181
|
return html`
|
182
|
-
<span class="value-type-cell">${i18n.i18n.lockedString(type)}</span>
|
182
|
+
<span class="value-type-cell selectable-text">${i18n.i18n.lockedString(type)}</span>
|
183
183
|
<div>
|
184
184
|
<select title=${i18nString(UIStrings.changeValueTypeMode)}
|
185
185
|
data-mode-settings="true"
|
@@ -206,7 +206,7 @@ export class ValueInterpreterDisplay extends HTMLElement {
|
|
206
206
|
const showSignedAndUnsigned =
|
207
207
|
signedValue !== unsignedValue && mode !== ValueTypeMode.Hexadecimal && mode !== ValueTypeMode.Octal;
|
208
208
|
|
209
|
-
const unsignedRendered = html`<span class="value-type-cell" title=${
|
209
|
+
const unsignedRendered = html`<span class="value-type-cell selectable-text" title=${
|
210
210
|
i18nString(UIStrings.unsignedValue)} data-value="true">${unsignedValue}</span>`;
|
211
211
|
if (!showSignedAndUnsigned) {
|
212
212
|
return unsignedRendered;
|
@@ -214,8 +214,8 @@ export class ValueInterpreterDisplay extends HTMLElement {
|
|
214
214
|
|
215
215
|
// Some values are too long to show in one line, we're putting them into the next line.
|
216
216
|
const showInMultipleLines = type === ValueType.Int32 || type === ValueType.Int64;
|
217
|
-
const signedRendered =
|
218
|
-
|
217
|
+
const signedRendered = html`<span class="selectable-text" data-value="true" title=${
|
218
|
+
i18nString(UIStrings.signedValue)}>${signedValue}</span>`;
|
219
219
|
|
220
220
|
if (showInMultipleLines) {
|
221
221
|
return html`
|
package/package.json
CHANGED
@@ -51,7 +51,7 @@ function isInChromiumDirectory() {
|
|
51
51
|
const normalizedPath = PATH_TO_EXECUTED_FILE.split(path.sep).join('/');
|
52
52
|
const devtoolsPath = 'src/third_party/devtools-frontend';
|
53
53
|
const isInChromium = normalizedPath.includes(devtoolsPath);
|
54
|
-
const potentialChromiumDir = PATH_TO_EXECUTED_FILE.substring(0,
|
54
|
+
const potentialChromiumDir = PATH_TO_EXECUTED_FILE.substring(0, normalizedPath.indexOf(devtoolsPath));
|
55
55
|
const result = {isInChromium, chromiumDirectory: potentialChromiumDir};
|
56
56
|
_lookUpCaches.set('chromium', result);
|
57
57
|
return result;
|
@@ -19,6 +19,7 @@ module.exports = {
|
|
19
19
|
noDefineCall: 'Could not find a defineComponent() call for the component {{ tagName }}.',
|
20
20
|
defineCallNonLiteral: 'defineComponent() first argument must be a string literal.',
|
21
21
|
staticLiteralInvalid: 'static readonly litTagName must use a literal string, with no interpolation.',
|
22
|
+
duplicateStaticLitTagName: 'found a duplicated litTagName: {{ tagName }}',
|
22
23
|
litTagNameNotLiteral:
|
23
24
|
'litTagName must be defined as a string passed in as LitHtml.literal`component-name`, but no tagged template was found.',
|
24
25
|
staticLiteralNotReadonly: 'static litTagName must be readonly.'
|
@@ -90,8 +91,9 @@ module.exports = {
|
|
90
91
|
});
|
91
92
|
}
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
// Map of litTagName to the class node.
|
95
|
+
/** @type {Map<string, any}>} */
|
96
|
+
const componentClassDefinitionLitTagNameNodes = new Map();
|
95
97
|
|
96
98
|
/** @type {Set<string>} */
|
97
99
|
const defineComponentCallsFound = new Set();
|
@@ -147,8 +149,15 @@ module.exports = {
|
|
147
149
|
// Grab the name of the component, e.g:
|
148
150
|
// LitHtml.literal`devtools-foo` will pull "devtools-foo" out.
|
149
151
|
const componentTagName = componentTagNameNode.value.quasi.quasis[0].value.cooked;
|
150
|
-
|
151
|
-
|
152
|
+
|
153
|
+
// Now we ensure that we haven't found this tag name before. If we
|
154
|
+
// have, we have two components with the same litTagName property,
|
155
|
+
// which is an error.
|
156
|
+
if (componentClassDefinitionLitTagNameNodes.has(componentTagName)) {
|
157
|
+
context.report({node: componentClassDefinition, messageId: 'duplicateStaticLitTagName', data: {tagName: componentTagName}});
|
158
|
+
}
|
159
|
+
|
160
|
+
componentClassDefinitionLitTagNameNodes.set(componentTagName, componentClassDefinition);
|
152
161
|
}
|
153
162
|
|
154
163
|
// Find all defineComponent() calls and store the arguments to them.
|
@@ -177,8 +186,7 @@ module.exports = {
|
|
177
186
|
}
|
178
187
|
}
|
179
188
|
|
180
|
-
for (const
|
181
|
-
const {tagName, classNode} = foundComponentClass;
|
189
|
+
for (const [tagName, classNode] of componentClassDefinitionLitTagNameNodes) {
|
182
190
|
// Check that each tagName has a matching entry in both other places we expect it.
|
183
191
|
if (!defineComponentCallsFound.has(tagName)) {
|
184
192
|
context.report({node: classNode, messageId: 'noDefineCall', data: {tagName}});
|
@@ -233,5 +233,28 @@ ruleTester.run('check_component_naming', rule, {
|
|
233
233
|
filename: 'front_end/ui/components/Foo.ts',
|
234
234
|
errors: [{messageId: 'noDefineCall', data: {tagName: 'devtools-bar'}}]
|
235
235
|
},
|
236
|
+
{
|
237
|
+
// Multiple components in one file is valid.
|
238
|
+
// But here devtools-foo is fine, but devtools-bar has the wrong static tag name
|
239
|
+
code: `export class Foo extends HTMLElement {
|
240
|
+
static readonly litTagName = LitHtml.literal\`devtools-foo\`
|
241
|
+
}
|
242
|
+
|
243
|
+
export class Bar extends HTMLElement {
|
244
|
+
static readonly litTagName = LitHtml.literal\`devtools-foo\`
|
245
|
+
}
|
246
|
+
|
247
|
+
ComponentHelpers.CustomElements.defineComponent('devtools-foo', Foo);
|
248
|
+
ComponentHelpers.CustomElements.defineComponent('devtools-bar', Foo);
|
249
|
+
|
250
|
+
declare global {
|
251
|
+
interface HTMLElementTagNameMap {
|
252
|
+
'devtools-foo': Foo
|
253
|
+
'devtools-bar': Bar
|
254
|
+
}
|
255
|
+
}`,
|
256
|
+
filename: 'front_end/ui/components/Foo.ts',
|
257
|
+
errors: [{messageId: 'duplicateStaticLitTagName', data: {tagName: 'devtools-foo'}}]
|
258
|
+
},
|
236
259
|
]
|
237
260
|
});
|