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

Side by Side Diff: frog/world.dart

Issue 8763001: Fix names with '$' to not conflict with operators or internal helpers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merged again Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « frog/value.dart ('k') | tests/language/src/NamingTest.dart » ('j') | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** The one true [World]. */ 5 /** The one true [World]. */
6 World world; 6 World world;
7 7
8 /** 8 /**
9 * Experimental phase to enable await, only set when using the 9 * Experimental phase to enable await, only set when using the
10 * await/awaitc.dart entrypoint. 10 * await/awaitc.dart entrypoint.
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 var ret = new DefinedType(name, corelib, null, isClass); 222 var ret = new DefinedType(name, corelib, null, isClass);
223 corelib.types[name] = ret; 223 corelib.types[name] = ret;
224 return ret; 224 return ret;
225 } 225 }
226 226
227 // TODO(jimhug): Can this just be a const Set? 227 // TODO(jimhug): Can this just be a const Set?
228 Set<String> _jsKeywords; 228 Set<String> _jsKeywords;
229 229
230 /** Ensures that identifiers are legal in the generated JS. */ 230 /** Ensures that identifiers are legal in the generated JS. */
231 String toJsIdentifier(String name) { 231 String toJsIdentifier(String name) {
232 if (name == null) return null;
232 if (_jsKeywords == null) { 233 if (_jsKeywords == null) {
233 // TODO(jmesserly): this doesn't work if I write "new Set<String>.from" 234 // TODO(jmesserly): this doesn't work if I write "new Set<String>.from"
234 // List of JS reserved words. 235 // List of JS reserved words.
235 _jsKeywords = new Set.from([ 236 _jsKeywords = new Set.from([
236 'break', 'case', 'catch', 'continue', 'debugger', 'default', 237 'break', 'case', 'catch', 'continue', 'debugger', 'default',
237 'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 238 'delete', 'do', 'else', 'finally', 'for', 'function', 'if',
238 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 239 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw',
239 'try', 'typeof', 'var', 'void', 'while', 'with', 240 'try', 'typeof', 'var', 'void', 'while', 'with',
240 'class', 'enum', 'export', 'extends', 'import', 'super', 241 'class', 'enum', 'export', 'extends', 'import', 'super',
241 'implements', 'interface', 'let', 'package', 'private', 242 'implements', 'interface', 'let', 'package', 'private',
242 'protected', 'public', 'static', 'yield', 243 'protected', 'public', 'static', 'yield',
243 'native']); 244 'native']);
244 } 245 }
245 if (_jsKeywords.contains(name)) { 246 if (_jsKeywords.contains(name)) {
246 return name + '_'; 247 return name + '_';
247 } else { 248 } else {
248 // regexs here? Is it worth checking all names - or just libraries? 249 // regexs for better perf?
249 return name; 250 return name.replaceAll(@'$', @'$$').replaceAll(':', @'$');
250 } 251 }
251 } 252 }
252 253
253 bool compile() { 254 bool compile() {
254 // TODO(jimhug): Must have called setOptions - better errors. 255 // TODO(jimhug): Must have called setOptions - better errors.
255 if (options.dartScript == null) { 256 if (options.dartScript == null) {
256 fatal('no script provided to compile'); 257 fatal('no script provided to compile');
257 return false; 258 return false;
258 } 259 }
259 260
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 451
451 withTiming(String name, f()) { 452 withTiming(String name, f()) {
452 final sw = new Stopwatch(); 453 final sw = new Stopwatch();
453 sw.start(); 454 sw.start();
454 var result = f(); 455 var result = f();
455 sw.stop(); 456 sw.stop();
456 info('$name in ${sw.elapsedInMs()}msec'); 457 info('$name in ${sw.elapsedInMs()}msec');
457 return result; 458 return result;
458 } 459 }
459 } 460 }
OLDNEW
« no previous file with comments | « frog/value.dart ('k') | tests/language/src/NamingTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698