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

Side by Side Diff: lib/src/compiler/module_builder.dart

Issue 1917863005: Qualify library names in packages (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 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
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 import 'package:path/path.dart' as path; 5 import 'package:path/path.dart' as path;
6 6
7 import '../js_ast/js_ast.dart'; 7 import '../js_ast/js_ast.dart';
8 import 'js_names.dart'; 8 import 'js_names.dart';
9 9
10 /// Base class for compiling ES6 modules into various ES5 module patterns. 10 /// Base class for compiling ES6 modules into various ES5 module patterns.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // This extra level of indirection should be unnecessary. 143 // This extra level of indirection should be unnecessary.
144 var block = 144 var block =
145 js.statement("(function() { 'use strict'; #; })()", [statements]); 145 js.statement("(function() { 'use strict'; #; })()", [statements]);
146 146
147 return new Program([block]); 147 return new Program([block]);
148 } 148 }
149 } 149 }
150 150
151 /// Escape [name] to make it into a valid identifier. 151 /// Escape [name] to make it into a valid identifier.
152 String pathToJSIdentifier(String name) { 152 String pathToJSIdentifier(String name) {
153 name = path.basenameWithoutExtension(name); 153 name = path.withoutExtension(name);
Jennifer Messerly 2016/04/26 22:59:33 hmmm, this change seems bad for absolute paths, ar
154 if (name.length == 0) return r'$'; 154 if (name.length == 0) return r'$';
155 155
156 // Escape any invalid characters 156 // Escape any invalid characters
157 StringBuffer buffer = null; 157 StringBuffer buffer = null;
158 for (int i = 0; i < name.length; i++) { 158 for (int i = 0; i < name.length; i++) {
159 var ch = name[i]; 159 var ch = name[i];
160 var needsEscape = ch == r'$' || _invalidCharInIdentifier.hasMatch(ch); 160 var needsEscape = ch == r'$' || _invalidCharInIdentifier.hasMatch(ch);
161 if (needsEscape && buffer == null) { 161 if (needsEscape && buffer == null) {
162 buffer = new StringBuffer(name.substring(0, i)); 162 buffer = new StringBuffer(name.substring(0, i));
163 } 163 }
164 if (buffer != null) { 164 if (buffer != null) {
165 buffer.write(needsEscape ? '\$${ch.codeUnits.join("")}' : ch); 165 buffer.write(needsEscape ? '\$${ch.codeUnits.join("")}' : ch);
166 } 166 }
167 } 167 }
168 168
169 var result = buffer != null ? '$buffer' : name; 169 var result = buffer != null ? '$buffer' : name;
170 // Ensure the identifier first character is not numeric and that the whole 170 // Ensure the identifier first character is not numeric and that the whole
171 // identifier is not a keyword. 171 // identifier is not a keyword.
172 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { 172 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) {
173 return '\$$result'; 173 return '\$$result';
174 } 174 }
175 return result; 175 return result;
176 } 176 }
177 177
178 // Invalid characters for identifiers, which would need to be escaped. 178 // Invalid characters for identifiers, which would need to be escaped.
179 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); 179 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698