| Index: pkg/compiler/lib/src/js_backend/minify_namer.dart
|
| diff --git a/pkg/compiler/lib/src/js_backend/minify_namer.dart b/pkg/compiler/lib/src/js_backend/minify_namer.dart
|
| index b3a7fb61389c3ec5a6e6cf8cd7abd03a73a08240..4641afdd5fe6fd5cbfe1bb187b86c03eb3060a83 100644
|
| --- a/pkg/compiler/lib/src/js_backend/minify_namer.dart
|
| +++ b/pkg/compiler/lib/src/js_backend/minify_namer.dart
|
| @@ -26,17 +26,14 @@ class MinifyNamer extends Namer {
|
|
|
| _FieldNamingRegistry fieldRegistry;
|
|
|
| - /// You can pass an invalid identifier to this and unlike its non-minifying
|
| - /// counterpart it will never return the proposedName as the new fresh name.
|
| - ///
|
| - /// [sanitizeForNatives] and [sanitizeForAnnotations] are ignored because the
|
| - /// minified names will always avoid clashing with annotated names or natives.
|
| + // You can pass an invalid identifier to this and unlike its non-minifying
|
| + // counterpart it will never return the proposedName as the new fresh name.
|
| String getFreshName(String proposedName,
|
| Set<String> usedNames,
|
| Map<String, String> suggestedNames,
|
| - {bool sanitizeForNatives, bool sanitizeForAnnotations}) {
|
| - String freshName;
|
| - String suggestion = suggestedNames[proposedName];
|
| + {bool ensureSafe: true}) {
|
| + var freshName;
|
| + var suggestion = suggestedNames[proposedName];
|
| if (suggestion != null && !usedNames.contains(suggestion)) {
|
| freshName = suggestion;
|
| } else {
|
| @@ -47,20 +44,18 @@ class MinifyNamer extends Namer {
|
| return freshName;
|
| }
|
|
|
| - String getClosureVariableName(String _, int id) {
|
| + String getClosureVariableName(String name, int id) {
|
| if (id < ALPHABET_CHARACTERS) {
|
| return new String.fromCharCodes([_letterNumber(id)]);
|
| }
|
| - // Fall back to a slightly longer name.
|
| - String basename = _disambiguateMember(null, 'closure');
|
| - return '${basename}_$id';
|
| + return "${getMappedInstanceName('closure')}_$id";
|
| }
|
|
|
| // From issue 7554. These should not be used on objects (as instance
|
| // variables) because they clash with names from the DOM. However, it is
|
| // OK to use them as fields, as we only access fields directly if we know
|
| // the receiver type.
|
| - static const List<String> _reservedNativeProperties = const <String>[
|
| + static const _reservedNativeProperties = const <String>[
|
| 'Q', 'a', 'b', 'c', 'd', 'e', 'f', 'r', 'x', 'y', 'z',
|
| // 2-letter:
|
| 'ch', 'cx', 'cy', 'db', 'dx', 'dy', 'fr', 'fx', 'fy', 'go', 'id', 'k1',
|
| @@ -85,11 +80,9 @@ class MinifyNamer extends Namer {
|
| 'Text', 'time', 'type', 'view', 'warn', 'wrap', 'ZERO'];
|
|
|
| void reserveBackendNames() {
|
| - for (String name in _reservedNativeProperties) {
|
| + for (var name in _reservedNativeProperties) {
|
| if (name.length < 2) {
|
| - // Ensure the 1-letter names are disambiguated to the same name.
|
| - String disambiguatedName = name;
|
| - reservePublicMemberName(name, disambiguatedName);
|
| + instanceNameMap[name] = name;
|
| }
|
| usedInstanceNames.add(name);
|
| // Getter and setter names are autogenerated by prepending 'g' and 's' to
|
| @@ -173,12 +166,12 @@ class MinifyNamer extends Namer {
|
| // in a predictable order determined by the proposed name. This is in order
|
| // to make the renamer stable: small changes in the input should nornally
|
| // result in relatively small changes in the output.
|
| - for (int n = 1; n <= 3; n++) {
|
| + for (var n = 1; n <= 3; n++) {
|
| int h = hash;
|
| while (h > 10) {
|
| - List<int> codes = <int>[_letterNumber(h)];
|
| + var codes = <int>[_letterNumber(h)];
|
| int h2 = h ~/ ALPHABET_CHARACTERS;
|
| - for (int i = 1; i < n; i++) {
|
| + for (var i = 1; i < n; i++) {
|
| codes.add(_alphaNumericNumber(h2));
|
| h2 ~/= ALPHANUMERIC_CHARACTERS;
|
| }
|
| @@ -220,9 +213,9 @@ class MinifyNamer extends Namer {
|
| /// If we can't find a hash based name in the three-letter space, then base
|
| /// the name on a letter and a counter.
|
| String _badName(int hash, Set<String> usedNames) {
|
| - String startLetter = new String.fromCharCodes([_letterNumber(hash)]);
|
| - String name;
|
| - int i = 0;
|
| + var startLetter = new String.fromCharCodes([_letterNumber(hash)]);
|
| + var name;
|
| + var i = 0;
|
| do {
|
| name = "$startLetter${i++}";
|
| } while (usedNames.contains(name));
|
| @@ -298,7 +291,8 @@ class _FieldNamingRegistry {
|
| nameStore.add(MinifyNamer._reservedNativeProperties[count]);
|
| } else {
|
| nameStore.add(namer.getFreshName("field$count",
|
| - namer.usedInstanceNames, namer.suggestedInstanceNames));
|
| + namer.usedInstanceNames, namer.suggestedInstanceNames,
|
| + ensureSafe: true));
|
| }
|
| }
|
|
|
| @@ -428,7 +422,7 @@ class _MixinFieldNamingScope extends _FieldNamingScope {
|
| : super.inherit(container, superScope, registry);
|
|
|
| String _nextName() {
|
| - String proposed = super._nextName();
|
| + var proposed = super._nextName();
|
| return proposed + r'$';
|
| }
|
| }
|
|
|