| 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 library dev_compiler.src.codegen.js_codegen; | 5 library dev_compiler.src.codegen.js_codegen; |
| 6 | 6 |
| 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; | 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
| 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 var dartxImport = | 205 var dartxImport = |
| 206 js.statement("let # = #.dartx;", [_dartxVar, _runtimeLibVar]); | 206 js.statement("let # = #.dartx;", [_dartxVar, _runtimeLibVar]); |
| 207 | 207 |
| 208 var module = js.call("function(#) { 'use strict'; #; #; }", | 208 var module = js.call("function(#) { 'use strict'; #; #; }", |
| 209 [params, dartxImport, _moduleItems]); | 209 [params, dartxImport, _moduleItems]); |
| 210 | 210 |
| 211 var program = <JS.Statement>[ | 211 var program = <JS.Statement>[ |
| 212 js.statement("dart_library.library(#, #, #, #, #)", [ | 212 js.statement("dart_library.library(#, #, #, #, #)", [ |
| 213 js.string(jsPath, "'"), | 213 js.string(jsPath, "'"), |
| 214 jsDefaultValue != null ? jsDefaultValue : new JS.LiteralNull(), | 214 jsDefaultValue ?? new JS.LiteralNull(), |
| 215 js.commentExpression( | 215 js.commentExpression( |
| 216 "Imports", new JS.ArrayInitializer(imports, multiline: true)), | 216 "Imports", new JS.ArrayInitializer(imports, multiline: true)), |
| 217 js.commentExpression("Lazy imports", | 217 js.commentExpression("Lazy imports", |
| 218 new JS.ArrayInitializer(lazyImports, multiline: true)), | 218 new JS.ArrayInitializer(lazyImports, multiline: true)), |
| 219 module | 219 module |
| 220 ]) | 220 ]) |
| 221 ]; | 221 ]; |
| 222 | 222 |
| 223 return new JS.Program(program); | 223 return new JS.Program(program); |
| 224 } | 224 } |
| (...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1852 | 1852 |
| 1853 _lazyFields.add(field); | 1853 _lazyFields.add(field); |
| 1854 | 1854 |
| 1855 return _statement(body); | 1855 return _statement(body); |
| 1856 } | 1856 } |
| 1857 | 1857 |
| 1858 JS.Expression _visitInitializer(VariableDeclaration node) { | 1858 JS.Expression _visitInitializer(VariableDeclaration node) { |
| 1859 var value = _visit(node.initializer); | 1859 var value = _visit(node.initializer); |
| 1860 // explicitly initialize to null, to avoid getting `undefined`. | 1860 // explicitly initialize to null, to avoid getting `undefined`. |
| 1861 // TODO(jmesserly): do this only for vars that aren't definitely assigned. | 1861 // TODO(jmesserly): do this only for vars that aren't definitely assigned. |
| 1862 return value != null ? value : new JS.LiteralNull(); | 1862 return value ?? new JS.LiteralNull(); |
| 1863 } | 1863 } |
| 1864 | 1864 |
| 1865 void _flushLazyFields(List<JS.Statement> body) { | 1865 void _flushLazyFields(List<JS.Statement> body) { |
| 1866 if (_lazyFields.isEmpty) return; | 1866 if (_lazyFields.isEmpty) return; |
| 1867 body.add(_emitLazyFields(_lazyFields)); | 1867 body.add(_emitLazyFields(_lazyFields)); |
| 1868 _lazyFields.clear(); | 1868 _lazyFields.clear(); |
| 1869 } | 1869 } |
| 1870 | 1870 |
| 1871 JS.Statement _emitLazyFields(List<VariableDeclaration> fields) { | 1871 JS.Statement _emitLazyFields(List<VariableDeclaration> fields) { |
| 1872 var methods = []; | 1872 var methods = []; |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2540 new JS.Yield(js.call('#.moveNext()', iter)), | 2540 new JS.Yield(js.call('#.moveNext()', iter)), |
| 2541 init, | 2541 init, |
| 2542 _visit(node.body), | 2542 _visit(node.body), |
| 2543 new JS.Yield(js.call('#.cancel()', iter)) | 2543 new JS.Yield(js.call('#.cancel()', iter)) |
| 2544 ]); | 2544 ]); |
| 2545 } | 2545 } |
| 2546 | 2546 |
| 2547 @override | 2547 @override |
| 2548 visitBreakStatement(BreakStatement node) { | 2548 visitBreakStatement(BreakStatement node) { |
| 2549 var label = node.label; | 2549 var label = node.label; |
| 2550 return new JS.Break(label != null ? label.name : null); | 2550 return new JS.Break(label?.name); |
| 2551 } | 2551 } |
| 2552 | 2552 |
| 2553 @override | 2553 @override |
| 2554 visitContinueStatement(ContinueStatement node) { | 2554 visitContinueStatement(ContinueStatement node) { |
| 2555 var label = node.label; | 2555 var label = node.label; |
| 2556 return new JS.Continue(label != null ? label.name : null); | 2556 return new JS.Continue(label?.name); |
| 2557 } | 2557 } |
| 2558 | 2558 |
| 2559 @override | 2559 @override |
| 2560 visitTryStatement(TryStatement node) { | 2560 visitTryStatement(TryStatement node) { |
| 2561 return new JS.Try(_visit(node.body), _visitCatch(node.catchClauses), | 2561 return new JS.Try(_visit(node.body), _visitCatch(node.catchClauses), |
| 2562 _visit(node.finallyBlock)); | 2562 _visit(node.finallyBlock)); |
| 2563 } | 2563 } |
| 2564 | 2564 |
| 2565 _visitCatch(NodeList<CatchClause> clauses) { | 2565 _visitCatch(NodeList<CatchClause> clauses) { |
| 2566 if (clauses == null || clauses.isEmpty) return null; | 2566 if (clauses == null || clauses.isEmpty) return null; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2979 | 2979 |
| 2980 /// A special kind of element created by the compiler, signifying a temporary | 2980 /// A special kind of element created by the compiler, signifying a temporary |
| 2981 /// variable. These objects use instance equality, and should be shared | 2981 /// variable. These objects use instance equality, and should be shared |
| 2982 /// everywhere in the tree where they are treated as the same variable. | 2982 /// everywhere in the tree where they are treated as the same variable. |
| 2983 class TemporaryVariableElement extends LocalVariableElementImpl { | 2983 class TemporaryVariableElement extends LocalVariableElementImpl { |
| 2984 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); | 2984 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); |
| 2985 | 2985 |
| 2986 int get hashCode => identityHashCode(this); | 2986 int get hashCode => identityHashCode(this); |
| 2987 bool operator ==(Object other) => identical(this, other); | 2987 bool operator ==(Object other) => identical(this, other); |
| 2988 } | 2988 } |
| OLD | NEW |