Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: lib/src/utils.dart

Issue 1111893002: small refactor: use JS.* prefix for our other JS extensions (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/codegen/js_printer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Holds a couple utility functions used at various places in the system. 5 /// Holds a couple utility functions used at various places in the system.
6 library dev_compiler.src.utils; 6 library dev_compiler.src.utils;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 13 matching lines...) Expand all
24 import 'package:analyzer/src/generated/element.dart'; 24 import 'package:analyzer/src/generated/element.dart';
25 import 'package:analyzer/src/generated/engine.dart' 25 import 'package:analyzer/src/generated/engine.dart'
26 show ParseDartTask, AnalysisContext; 26 show ParseDartTask, AnalysisContext;
27 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; 27 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
28 import 'package:analyzer/src/generated/source.dart' show Source; 28 import 'package:analyzer/src/generated/source.dart' show Source;
29 import 'package:analyzer/analyzer.dart' show parseDirectives; 29 import 'package:analyzer/analyzer.dart' show parseDirectives;
30 import 'package:crypto/crypto.dart' show CryptoUtils, MD5; 30 import 'package:crypto/crypto.dart' show CryptoUtils, MD5;
31 import 'package:source_span/source_span.dart'; 31 import 'package:source_span/source_span.dart';
32 import 'package:yaml/yaml.dart'; 32 import 'package:yaml/yaml.dart';
33 33
34 import 'codegen/js_names.dart' show invalidJSVariableName; 34 import 'codegen/js_names.dart' show invalidVariableName;
35 35
36 bool isDartPrivateLibrary(LibraryElement library) { 36 bool isDartPrivateLibrary(LibraryElement library) {
37 var uri = library.source.uri; 37 var uri = library.source.uri;
38 if (uri.scheme != "dart") return false; 38 if (uri.scheme != "dart") return false;
39 return Identifier.isPrivateName(uri.path); 39 return Identifier.isPrivateName(uri.path);
40 } 40 }
41 41
42 /// Choose a canonical name from the library element. This is safe to use as a 42 /// Choose a canonical name from the library element. This is safe to use as a
43 /// namespace in JS and Dart code generation. This never uses the library's 43 /// namespace in JS and Dart code generation. This never uses the library's
44 /// name (the identifier in the `library` declaration) as it doesn't have any 44 /// name (the identifier in the `library` declaration) as it doesn't have any
(...skipping 17 matching lines...) Expand all
62 buffer = new StringBuffer(name.substring(0, i)); 62 buffer = new StringBuffer(name.substring(0, i));
63 } 63 }
64 if (buffer != null) { 64 if (buffer != null) {
65 buffer.write(needsEscape ? '\$${ch.codeUnits.join("")}' : ch); 65 buffer.write(needsEscape ? '\$${ch.codeUnits.join("")}' : ch);
66 } 66 }
67 } 67 }
68 68
69 var result = buffer != null ? '$buffer' : name; 69 var result = buffer != null ? '$buffer' : name;
70 // Ensure the identifier first character is not numeric and that the whole 70 // Ensure the identifier first character is not numeric and that the whole
71 // identifier is not a keyword. 71 // identifier is not a keyword.
72 if (result.startsWith(new RegExp('[0-9]')) || invalidJSVariableName(result)) { 72 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) {
73 return '\$$result'; 73 return '\$$result';
74 } 74 }
75 return result; 75 return result;
76 } 76 }
77 77
78 // Invalid characters for identifiers, which would need to be escaped. 78 // Invalid characters for identifiers, which would need to be escaped.
79 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); 79 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]');
80 80
81 /// Returns all libraries transitively imported or exported from [start]. 81 /// Returns all libraries transitively imported or exported from [start].
82 Iterable<LibraryElement> reachableLibraries(LibraryElement start) { 82 Iterable<LibraryElement> reachableLibraries(LibraryElement start) {
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 }); 417 });
418 // Add getters. 418 // Add getters.
419 element.accessors 419 element.accessors
420 .where((member) => !member.isStatic && member.isGetter) 420 .where((member) => !member.isStatic && member.isGetter)
421 .forEach((member) { 421 .forEach((member) {
422 map[member.name] = member.type.returnType; 422 map[member.name] = member.type.returnType;
423 }); 423 });
424 } 424 }
425 return map; 425 return map;
426 } 426 }
OLDNEW
« no previous file with comments | « lib/src/codegen/js_printer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698