Skip to content

Commit 177f425

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[dartdevc] Fix violations of library_prefix lint
Rename the library prefix used in imports from `JS` to `js_ast`. Create more of a distinction between: * `JS` the library. Now named `js_ast`. * `js` the const instance of a JSBuilder. * `JS` the helper to inline javascript in the SDK patches and runtime libraries. Ignore the lint in the js_ast directory to avoid additional diffs for the eventual un-forking of the package. Cleanup a few unused imports. Issue #37218 Change-Id: I039c1048876d9d9ad424fbec3ad555d300845a3d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106160 Reviewed-by: Nate Bosch <nbosch@google.com> Reviewed-by: Mark Zhou <markzipan@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
1 parent 047bacc commit 177f425

11 files changed

Lines changed: 1368 additions & 1280 deletions

File tree

pkg/dev_compiler/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ linter:
2424
- empty_catches
2525
- empty_constructor_bodies
2626
- library_names
27+
- library_prefixes
2728
- no_duplicate_case_values
2829
- null_closures
2930
- prefer_contains

pkg/dev_compiler/lib/src/analyzer/code_generator.dart

Lines changed: 638 additions & 595 deletions
Large diffs are not rendered by default.

pkg/dev_compiler/lib/src/analyzer/module_compiler.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import 'package:args/args.dart' show ArgParser, ArgResults;
1515
import 'package:path/path.dart' as path;
1616
import 'package:source_maps/source_maps.dart';
1717

18-
import '../compiler/js_names.dart' as JS;
18+
import '../compiler/js_names.dart' as js_ast;
1919
import '../compiler/module_builder.dart'
2020
show transformModuleFormat, ModuleFormat;
2121
import '../compiler/shared_command.dart';
2222
import '../compiler/shared_compiler.dart';
23-
import '../js_ast/js_ast.dart' as JS;
23+
import '../js_ast/js_ast.dart' as js_ast;
2424
import '../js_ast/js_ast.dart' show js;
2525
import '../js_ast/source_map_printer.dart' show SourceMapPrintingContext;
2626
import 'code_generator.dart' show CodeGenerator;
@@ -95,7 +95,7 @@ JSModuleFile compileWithAnalyzer(
9595
}
9696
}
9797

98-
JS.Program jsProgram;
98+
js_ast.Program jsProgram;
9999
if (options.unsafeForceCompile || !errors.hasFatalErrors) {
100100
var codeGenerator = CodeGenerator(
101101
driver,
@@ -227,7 +227,7 @@ class JSModuleFile {
227227

228228
/// The AST that will be used to generate the [code] and [sourceMap] for this
229229
/// module.
230-
final JS.Program moduleTree;
230+
final js_ast.Program moduleTree;
231231

232232
/// The compiler options used to generate this module.
233233
final CompilerOptions options;
@@ -256,20 +256,21 @@ class JSModuleFile {
256256
// TODO(jmesserly): this should match our old logic, but I'm not sure we are
257257
// correctly handling the pointer from the .js file to the .map file.
258258
JSModuleCode getCode(ModuleFormat format, String jsUrl, String mapUrl) {
259-
var opts = JS.JavaScriptPrintingOptions(
259+
var opts = js_ast.JavaScriptPrintingOptions(
260260
allowKeywordsInProperties: true, allowSingleLineIfStatements: true);
261-
JS.SimpleJavaScriptPrintingContext printer;
261+
js_ast.SimpleJavaScriptPrintingContext printer;
262262
SourceMapBuilder sourceMap;
263263
if (options.sourceMap) {
264264
var sourceMapContext = SourceMapPrintingContext();
265265
sourceMap = sourceMapContext.sourceMap;
266266
printer = sourceMapContext;
267267
} else {
268-
printer = JS.SimpleJavaScriptPrintingContext();
268+
printer = js_ast.SimpleJavaScriptPrintingContext();
269269
}
270270

271271
var tree = transformModuleFormat(format, moduleTree);
272-
tree.accept(JS.Printer(opts, printer, localNamer: JS.TemporaryNamer(tree)));
272+
tree.accept(
273+
js_ast.Printer(opts, printer, localNamer: js_ast.TemporaryNamer(tree)));
273274

274275
Map builtMap;
275276
if (options.sourceMap && sourceMap != null) {

pkg/dev_compiler/lib/src/analyzer/property_model.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import 'package:analyzer/dart/element/element.dart';
88
import 'package:analyzer/dart/element/type.dart' show InterfaceType;
99
import 'package:analyzer/src/dart/element/element.dart' show FieldElementImpl;
1010

11-
import '../compiler/js_names.dart' as JS;
12-
import '../js_ast/js_ast.dart' as JS;
11+
import '../compiler/js_names.dart' as js_ast;
1312
import 'element_helpers.dart';
1413
import 'extension_types.dart';
1514

@@ -176,7 +175,7 @@ class ClassPropertyModel {
176175
/// pair in JavaScript.
177176
///
178177
/// The value property stores the symbol used for the field's storage slot.
179-
final virtualFields = <FieldElement, JS.TemporaryId>{};
178+
final virtualFields = <FieldElement, js_ast.TemporaryId>{};
180179

181180
/// The set of inherited getters, used because JS getters/setters are paired,
182181
/// so if we're generating a setter we may need to emit a getter that calls
@@ -250,7 +249,7 @@ class ClassPropertyModel {
250249
covariantParameters != null &&
251250
covariantParameters.contains(setter.parameters[0]) &&
252251
covariantPrivateMembers.contains(setter)) {
253-
virtualFields[field] = JS.TemporaryId(name);
252+
virtualFields[field] = js_ast.TemporaryId(name);
254253
}
255254
}
256255
}

pkg/dev_compiler/lib/src/analyzer/type_utilities.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:collection';
6+
67
import 'package:analyzer/dart/element/element.dart';
78
import 'package:analyzer/src/dart/element/member.dart' show TypeParameterMember;
89
import 'package:analyzer/dart/element/type.dart';
910

1011
import '../analyzer/element_helpers.dart';
11-
import '../compiler/js_names.dart' as JS;
12-
import '../js_ast/js_ast.dart' as JS;
12+
import '../compiler/js_names.dart' as js_ast;
13+
import '../js_ast/js_ast.dart' as js_ast;
1314
import '../js_ast/js_ast.dart' show js;
1415

1516
Set<TypeParameterElement> freeTypeParameters(DartType t) {
@@ -54,11 +55,11 @@ class _CacheTable {
5455
// Use a LinkedHashMap to maintain key insertion order so the generated code
5556
// is stable under slight perturbation. (If this is not good enough we could
5657
// sort by name to canonicalize order.)
57-
final _names = LinkedHashMap<DartType, JS.TemporaryId>(
58+
final _names = LinkedHashMap<DartType, js_ast.TemporaryId>(
5859
equals: typesAreEqual, hashCode: typeHashCode);
5960
Iterable<DartType> get keys => _names.keys.toList();
6061

61-
JS.Statement _dischargeType(DartType type) {
62+
js_ast.Statement _dischargeType(DartType type) {
6263
var name = _names.remove(type);
6364
if (name != null) {
6465
return js.statement('let #;', [name]);
@@ -69,8 +70,8 @@ class _CacheTable {
6970
/// Emit a list of statements declaring the cache variables for
7071
/// types tracked by this table. If [typeFilter] is given,
7172
/// only emit the types listed in the filter.
72-
List<JS.Statement> discharge([Iterable<DartType> typeFilter]) {
73-
var decls = <JS.Statement>[];
73+
List<js_ast.Statement> discharge([Iterable<DartType> typeFilter]) {
74+
var decls = <js_ast.Statement>[];
7475
var types = typeFilter ?? keys;
7576
for (var t in types) {
7677
var stmt = _dischargeType(t);
@@ -119,26 +120,26 @@ class _CacheTable {
119120

120121
/// Heuristically choose a good name for the cache and generator
121122
/// variables.
122-
JS.TemporaryId chooseTypeName(DartType type) {
123-
return JS.TemporaryId(_typeString(type));
123+
js_ast.TemporaryId chooseTypeName(DartType type) {
124+
return js_ast.TemporaryId(_typeString(type));
124125
}
125126
}
126127

127128
/// _GeneratorTable tracks types which have been
128129
/// named and hoisted.
129130
class _GeneratorTable extends _CacheTable {
130-
final _defs = LinkedHashMap<DartType, JS.Expression>(
131+
final _defs = LinkedHashMap<DartType, js_ast.Expression>(
131132
equals: typesAreEqual, hashCode: typeHashCode);
132133

133-
final JS.Identifier _runtimeModule;
134+
final js_ast.Identifier _runtimeModule;
134135

135136
_GeneratorTable(this._runtimeModule);
136137

137138
@override
138-
JS.Statement _dischargeType(DartType t) {
139+
js_ast.Statement _dischargeType(DartType t) {
139140
var name = _names.remove(t);
140141
if (name != null) {
141-
JS.Expression init = _defs.remove(t);
142+
js_ast.Expression init = _defs.remove(t);
142143
assert(init != null);
143144
return js.statement('let # = () => ((# = #.constFn(#))());',
144145
[name, name, _runtimeModule, init]);
@@ -149,7 +150,7 @@ class _GeneratorTable extends _CacheTable {
149150
/// If [type] does not already have a generator name chosen for it,
150151
/// assign it one, using [typeRep] as the initializer for it.
151152
/// Emit the generator name.
152-
JS.TemporaryId _nameType(DartType type, JS.Expression typeRep) {
153+
js_ast.TemporaryId _nameType(DartType type, js_ast.Expression typeRep) {
153154
var temp = _names[type];
154155
if (temp == null) {
155156
_names[type] = temp = chooseTypeName(type);
@@ -169,12 +170,12 @@ class TypeTable {
169170
/// parameter.
170171
final _scopeDependencies = <TypeParameterElement, List<DartType>>{};
171172

172-
TypeTable(JS.Identifier runtime) : _generators = _GeneratorTable(runtime);
173+
TypeTable(js_ast.Identifier runtime) : _generators = _GeneratorTable(runtime);
173174

174175
/// Emit a list of statements declaring the cache variables and generator
175176
/// definitions tracked by the table. If [formals] is present, only
176177
/// emit the definitions which depend on the formals.
177-
List<JS.Statement> discharge([List<TypeParameterElement> formals]) {
178+
List<js_ast.Statement> discharge([List<TypeParameterElement> formals]) {
178179
var filter = formals?.expand((p) => _scopeDependencies[p] ?? <DartType>[]);
179180
var stmts = [_generators].expand((c) => c.discharge(filter)).toList();
180181
formals?.forEach(_scopeDependencies.remove);
@@ -205,7 +206,8 @@ class TypeTable {
205206
/// Given a type [type], and a JS expression [typeRep] which implements it,
206207
/// add the type and its representation to the table, returning an
207208
/// expression which implements the type (but which caches the value).
208-
JS.Expression nameType(ParameterizedType type, JS.Expression typeRep) {
209+
js_ast.Expression nameType(
210+
ParameterizedType type, js_ast.Expression typeRep) {
209211
if (!_generators.isNamed(type) && recordScopeDependencies(type)) {
210212
return typeRep;
211213
}
@@ -223,10 +225,11 @@ class TypeTable {
223225
/// should be a function that is invoked to compute the type, rather than the
224226
/// type itself. This allows better integration with `lazyFn`, avoiding an
225227
/// extra level of indirection.
226-
JS.Expression nameFunctionType(FunctionType type, JS.Expression typeRep,
228+
js_ast.Expression nameFunctionType(
229+
FunctionType type, js_ast.Expression typeRep,
227230
{bool lazy = false}) {
228231
if (!_generators.isNamed(type) && recordScopeDependencies(type)) {
229-
return lazy ? JS.ArrowFun([], typeRep) : typeRep;
232+
return lazy ? js_ast.ArrowFun([], typeRep) : typeRep;
230233
}
231234

232235
var name = _generators._nameType(type, typeRep);

0 commit comments

Comments
 (0)