OLD | NEW |
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 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 import '../js/js_ast.dart'; | 7 import '../js/js_ast.dart'; |
| 8 import '../options.dart'; |
8 | 9 |
9 /// Unique instance for temporary variables. Will be renamed consistently | 10 /// Unique instance for temporary variables. Will be renamed consistently |
10 /// across the entire file. Different instances will be named differently | 11 /// across the entire file. Different instances will be named differently |
11 /// even if they have the same name, this makes it safe to use in code | 12 /// even if they have the same name, this makes it safe to use in code |
12 /// generation without needing global knowledge. See [JSNamer]. | 13 /// generation without needing global knowledge. See [JSNamer]. |
13 /// | 14 /// |
14 // TODO(jmesserly): move into js_ast? add a boolean to Identifier? | 15 // TODO(jmesserly): move into js_ast? add a boolean to Identifier? |
15 class TemporaryId extends Identifier { | 16 class TemporaryId extends Identifier { |
16 TemporaryId(String name) : super(name); | 17 TemporaryId(String name) : super(name); |
17 } | 18 } |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 case "private": | 277 case "private": |
277 case "protected": | 278 case "protected": |
278 case "public": | 279 case "public": |
279 case "static": | 280 case "static": |
280 case "yield": | 281 case "yield": |
281 return strictMode; | 282 return strictMode; |
282 } | 283 } |
283 return false; | 284 return false; |
284 } | 285 } |
285 | 286 |
286 /// Returns true for invalid static field names in strict mode. | 287 /// Returns true for invalid static field names in strict mode or for some |
| 288 /// transpilers (e.g. when doing ES6->ES5 lowering with the Closure Compiler). |
287 /// In particular, "caller" "callee" and "arguments" cannot be used. | 289 /// In particular, "caller" "callee" and "arguments" cannot be used. |
288 bool invalidStaticFieldName(String name) { | 290 bool invalidStaticFieldName(String name, CodegenOptions options) { |
289 switch (name) { | 291 switch (name) { |
290 case "arguments": | 292 case "arguments": |
291 case "caller": | 293 case "caller": |
292 case "callee": | 294 case "callee": |
293 return true; | 295 return true; |
| 296 // Workarounds for Closure: |
| 297 // (see https://github.com/google/closure-compiler/issues/1460) |
| 298 case "name": |
| 299 case "length": |
| 300 return options.closure; |
294 } | 301 } |
295 return false; | 302 return false; |
296 } | 303 } |
OLD | NEW |