chrome-devtools-frontend 1.0.996044 → 1.0.997598

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 (33) hide show
  1. package/AUTHORS +2 -0
  2. package/front_end/core/i18n/locales/en-US.json +102 -0
  3. package/front_end/core/i18n/locales/en-XL.json +102 -0
  4. package/front_end/core/root/Runtime.ts +5 -0
  5. package/front_end/core/sdk/CSSMatchedStyles.ts +158 -33
  6. package/front_end/core/sdk/CSSMetadata.ts +1 -8
  7. package/front_end/core/sdk/DebuggerModel.ts +1 -1
  8. package/front_end/core/sdk/NetworkManager.ts +1 -2
  9. package/front_end/generated/InspectorBackendCommands.js +33 -3
  10. package/front_end/generated/protocol.ts +47 -24
  11. package/front_end/models/bindings/BreakpointManager.ts +12 -3
  12. package/front_end/models/issues_manager/DeprecationIssue.ts +281 -24
  13. package/front_end/panels/changes/ChangesView.ts +25 -10
  14. package/front_end/panels/css_overview/cssOverview.css +4 -0
  15. package/front_end/panels/elements/ElementsPanel.ts +7 -6
  16. package/front_end/panels/elements/StylesSidebarPane.ts +55 -21
  17. package/front_end/panels/elements/components/adornerSettingsPane.css +5 -0
  18. package/front_end/panels/elements/stylesSectionTree.css +5 -4
  19. package/front_end/panels/elements/stylesSidebarPane.css +1 -1
  20. package/front_end/panels/profiler/HeapSnapshotGridNodes.ts +1 -0
  21. package/front_end/panels/sources/DebuggerPlugin.ts +6 -2
  22. package/front_end/panels/sources/SourcesPanel.ts +22 -6
  23. package/front_end/panels/sources/sources-legacy.ts +1 -1
  24. package/front_end/panels/sources/sources-meta.ts +61 -7
  25. package/front_end/ui/components/diff_view/diffView.css +2 -0
  26. package/front_end/ui/components/tree_outline/TreeOutline.ts +18 -7
  27. package/front_end/ui/legacy/SplitWidget.ts +17 -7
  28. package/front_end/ui/legacy/Toolbar.ts +5 -0
  29. package/front_end/ui/legacy/softDropDownButton.css +4 -0
  30. package/package.json +1 -1
  31. package/scripts/eslint_rules/lib/inline_type_imports.js +158 -0
  32. package/scripts/eslint_rules/tests/inline_type_imports_test.js +106 -0
  33. package/scripts/javascript_natives/index.js +1 -2
@@ -0,0 +1,158 @@
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ 'use strict';
5
+
6
+ module.exports = {
7
+ meta: {
8
+ type: 'problem',
9
+
10
+ docs: {
11
+ description: 'Inline type imports.',
12
+ category: 'Possible Errors',
13
+ },
14
+ fixable: 'code',
15
+ messages: {
16
+ inlineTypeImport: 'Type imports must be imported in the same import statement as values, using the type keyword',
17
+ convertTypeImport: 'Type imports must use the type modifier on each item, not on the overall import statement',
18
+ },
19
+ schema: [] // no options
20
+ },
21
+ create: function(context) {
22
+ // Stores any type imports (import type {} from ...).
23
+ // The key is the literal import path ("../foo.js");
24
+ const typeImports = new Map();
25
+ // Stores any value imports (import {} from ...).
26
+ // The key is the literal import path ("../foo.js");
27
+ const valueImports = new Map();
28
+
29
+ // Takes the node that represents an import ("Foo", "Foo as Bar") and
30
+ // return the literal text.
31
+ function getTextForImportSpecifier(specifier) {
32
+ // import {Foo as Bar} from 'foo';
33
+ // Foo = imported name
34
+ // Bar = local name
35
+ const localName = specifier.local.name;
36
+ const importedName = specifier.imported.name;
37
+ if (localName === importedName) {
38
+ // No `X as Y`, so just use either name.
39
+ return localName;
40
+ }
41
+ return `${importedName} as ${localName}`;
42
+ }
43
+
44
+ function mergeImports(fixer, typeImportNode, valueImportNode) {
45
+ // Get all the references from the type import node that we need to add to the value import node.
46
+ const typeImportSpecifiers = typeImportNode.specifiers.map(spec => {
47
+ return getTextForImportSpecifier(spec);
48
+ });
49
+
50
+ // Find the last value specifier, which we will then insert the type imports to.
51
+ const lastValueSpecifier = valueImportNode.specifiers[valueImportNode.specifiers.length - 1];
52
+
53
+ // Remember that we don't need to concern ourselves with indentation: in
54
+ // PRESUBMIT clang-format runs _after_ ESLint, so we can let Clang tidy
55
+ // up any rough edges.
56
+ const textToImport = ', ' +
57
+ typeImportSpecifiers
58
+ .map(spec => `type ${spec}`)
59
+ .join(', ');
60
+
61
+ return [
62
+ // Remove the type import
63
+ fixer.remove(typeImportNode),
64
+ // Add the type imports to the existing import
65
+ fixer.insertTextAfter(lastValueSpecifier, textToImport)
66
+ ];
67
+ }
68
+
69
+ function inlineTypeImportKeyword(fixer, typeImportNode) {
70
+ // We need to remove the " type" text after "import".
71
+ const importStart = typeImportNode.range[0];
72
+ const typeImportStart = importStart + 6; // 6 here = length of "import"
73
+ const typeImportEnd = typeImportStart + 5; // 5 here = length of "type" + 1 to remove the space after it.
74
+
75
+ const addTypeToSpecifiersFixers = typeImportNode.specifiers.map(spec => {
76
+ const newText = getTextForImportSpecifier(spec);
77
+
78
+ return fixer.replaceText(spec, `type ${newText}`);
79
+ });
80
+
81
+ return [
82
+ ...addTypeToSpecifiersFixers,
83
+ fixer.removeRange([typeImportStart, typeImportEnd]),
84
+ ];
85
+ }
86
+
87
+ return {
88
+ ImportDeclaration(node) {
89
+ // Note that we only care about named imports: import {} from 'foo.js'.
90
+ // This is because:
91
+ // 1: if we have `import type * as SDK from '../` that means we know we
92
+ // aren't using `SDK` for any values, otherwise we wouldn't have the
93
+ // `type` modifier.
94
+ // 2: similarly, `import type Foo from './foo'` follows (1). We also
95
+ // don't use this pattern in DevTools, but even if we did we don't have
96
+ // to worry about it.
97
+ // 3: Any side-effect imports (import './foo.js') are irrelevant.
98
+
99
+ if (!node.specifiers || node.specifiers.length < 1) {
100
+ // import './foo.js';
101
+ return;
102
+ }
103
+
104
+ if (node.specifiers[0].type === 'ImportDefaultSpecifier') {
105
+ // import Foo from './foo.js';
106
+ return;
107
+ }
108
+
109
+ if (node.specifiers[0].type === 'ImportNamespaceSpecifier') {
110
+ // import * as Foo from './foo.js';
111
+ return;
112
+ }
113
+
114
+ // Store the import
115
+ const importFilePath = node.source.value;
116
+ if (node.importKind === 'type') {
117
+ typeImports.set(importFilePath, node);
118
+ } else if (node.importKind === 'value') {
119
+ valueImports.set(importFilePath, node);
120
+ }
121
+ },
122
+ 'Program:exit'() {
123
+ // Loop over the type imports and see if there are any matching value
124
+ // imports.
125
+ // Looping this way means if there are any value imports without a
126
+ // matching type import, we leave them alone.
127
+ for (const [typeImportFilePath, typeImportNode] of typeImports) {
128
+ const valueImportNodeForFilePath = valueImports.get(typeImportFilePath);
129
+ if (valueImportNodeForFilePath) {
130
+ // If we've got here, we have two imports for the same file-path, one
131
+ // for types, and one for values, so let's merge them.
132
+ context.report({
133
+ node: typeImportNode,
134
+ messageId: 'inlineTypeImport',
135
+ fix(fixer) {
136
+ return mergeImports(fixer, typeImportNode, valueImportNodeForFilePath);
137
+ }
138
+ });
139
+ continue;
140
+ }
141
+
142
+ // At this point we have just a type import and no matching file
143
+ // import, but we still want to convert the import so that each
144
+ // imported reference uses the type modifier:
145
+ // BEFORE: import type {A, B} from '...';
146
+ // AFTER: import {type A, type B} from '...';
147
+ context.report({
148
+ node: typeImportNode,
149
+ messageId: 'convertTypeImport',
150
+ fix(fixer) {
151
+ return inlineTypeImportKeyword(fixer, typeImportNode);
152
+ }
153
+ });
154
+ }
155
+ },
156
+ };
157
+ }
158
+ };
@@ -0,0 +1,106 @@
1
+ // Copyright 2022 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ 'use strict';
5
+
6
+ const rule = require('../lib/inline_type_imports.js');
7
+ const ruleTester = new (require('eslint').RuleTester)({
8
+ parserOptions: {ecmaVersion: 9, sourceType: 'module'},
9
+ parser: require.resolve('@typescript-eslint/parser'),
10
+ });
11
+
12
+ ruleTester.run('inline_type_imports', rule, {
13
+ valid: [
14
+ {
15
+ code: 'import \'./foo.js\'',
16
+ },
17
+ {
18
+ code: 'import type * as Foo from \'./foo.js\'',
19
+ },
20
+ {
21
+ code: 'import * as Foo from \'./foo.js\'',
22
+ },
23
+ {
24
+ code: 'import Foo from \'./foo.js\'',
25
+ },
26
+ {
27
+ code: 'import type Foo from \'./foo.js\'',
28
+ },
29
+ {
30
+ code: 'import {type Foo} from \'./foo.js\'',
31
+ },
32
+ {
33
+ code: 'import {type Foo as Foo2} from \'./foo.js\'',
34
+ },
35
+ {
36
+ code: 'import {SomeValue, type Foo as Foo2} from \'./foo.js\'',
37
+ },
38
+ {
39
+ code: 'import {type Bar, type Foo as Foo2} from \'./foo.js\'',
40
+ },
41
+ ],
42
+ invalid: [
43
+ {
44
+ code: `import type {AType} from './foo.js';
45
+ import {AValue} from './foo.js';`,
46
+ output: `
47
+ import {AValue, type AType} from './foo.js';`,
48
+ filename: 'front_end/components/test.ts',
49
+ errors: [{messageId: 'inlineTypeImport'}],
50
+ },
51
+ {
52
+ code: `import type {AType} from './foo.js';
53
+ import {AValue} from './foo.js';
54
+ import type {Foo} from './blah.js'`,
55
+ output: `
56
+ import {AValue, type AType} from './foo.js';
57
+ import {type Foo} from './blah.js'`,
58
+ filename: 'front_end/components/test.ts',
59
+ errors: [{messageId: 'inlineTypeImport'}, {messageId: 'convertTypeImport'}],
60
+ },
61
+ {
62
+ code: `import type {AType} from './foo.js';
63
+ import {AValue} from './foo.js';
64
+ import {Foo} from './blah.js'`,
65
+ output: `
66
+ import {AValue, type AType} from './foo.js';
67
+ import {Foo} from './blah.js'`,
68
+ filename: 'front_end/components/test.ts',
69
+ errors: [{messageId: 'inlineTypeImport'}],
70
+ },
71
+ {
72
+ code: 'import type {AType} from \'./foo.js\';',
73
+ output: 'import {type AType} from \'./foo.js\';',
74
+ filename: 'front_end/components/test.ts',
75
+ errors: [{messageId: 'convertTypeImport'}],
76
+ },
77
+ {
78
+ code: 'import type {Foo as Bar} from \'./foo.js\';',
79
+ output: 'import {type Foo as Bar} from \'./foo.js\';',
80
+ filename: 'front_end/components/test.ts',
81
+ errors: [{messageId: 'convertTypeImport'}],
82
+ },
83
+ {
84
+ code: `import {SomeValue} from './foo.js';
85
+ import type {Foo as Bar} from './foo.js';`,
86
+ output: 'import {SomeValue, type Foo as Bar} from \'./foo.js\';\n',
87
+ filename: 'front_end/components/test.ts',
88
+ errors: [{messageId: 'inlineTypeImport'}],
89
+ },
90
+ {
91
+ code: `import {SomeValue} from './foo.js';
92
+ import type {Foo as Bar, Baz} from './foo.js';`,
93
+ output: 'import {SomeValue, type Foo as Bar, type Baz} from \'./foo.js\';\n',
94
+ filename: 'front_end/components/test.ts',
95
+ errors: [{messageId: 'inlineTypeImport'}],
96
+ },
97
+ {
98
+ code: `import type {SomeValue} from './baz.js';
99
+ import type {Foo as Bar, Baz} from './foo.js';`,
100
+ output: `import {type SomeValue} from './baz.js';
101
+ import {type Foo as Bar, type Baz} from './foo.js';`,
102
+ filename: 'front_end/components/test.ts',
103
+ errors: [{messageId: 'convertTypeImport'}, {messageId: 'convertTypeImport'}],
104
+ },
105
+ ]
106
+ });
@@ -4,7 +4,6 @@
4
4
 
5
5
  import * as fs from 'fs';
6
6
  import glob from 'glob';
7
- import * as path from 'path';
8
7
  import ts from 'typescript';
9
8
  import * as WebIDL2 from 'webidl2';
10
9
 
@@ -45,7 +44,7 @@ for (const file of files) {
45
44
  if (file.includes('testing')) {
46
45
  continue;
47
46
  }
48
- const data = fs.readFileSync(path.join(process.env.PWD, file), 'utf8');
47
+ const data = fs.readFileSync(file, 'utf8');
49
48
  const lines = data.split('\n');
50
49
  const newLines = [];
51
50
  for (const line of lines) {