@@ -23,15 +23,14 @@ import 'package:analyzer/src/summary/summarize_elements.dart'
23
23
show PackageBundleAssembler;
24
24
import 'package:analyzer/src/task/strong/ast_properties.dart'
25
25
show isDynamicInvoke, setIsDynamicInvoke;
26
- import 'package:source_maps/source_maps.dart' ;
27
26
import 'package:path/path.dart' show separator;
28
27
29
28
import '../closure/closure_annotator.dart' show ClosureAnnotator;
30
29
import '../js_ast/js_ast.dart' as JS;
31
30
import '../js_ast/js_ast.dart' show js;
32
31
import 'ast_builder.dart' show AstBuilder;
33
32
import 'compiler.dart'
34
- show BuildUnit, CompilerOptions, JSModuleFile, ModuleFormat ;
33
+ show BuildUnit, CompilerOptions, JSModuleFile;
35
34
import 'element_helpers.dart' ;
36
35
import 'element_loader.dart' show ElementLoader;
37
36
import 'extension_types.dart' show ExtensionTypeSet;
@@ -40,12 +39,10 @@ import 'js_interop.dart';
40
39
import 'js_metalet.dart' as JS;
41
40
import 'js_names.dart' as JS;
42
41
import 'js_typeref_codegen.dart' show JsTypeRefCodegen;
43
- import 'module_builder.dart'
44
- show LegacyModuleBuilder, NodeModuleBuilder, pathToJSIdentifier;
42
+ import 'module_builder.dart' show pathToJSIdentifier;
45
43
import 'nullable_type_inference.dart' show NullableTypeInference;
46
44
import 'reify_coercions.dart' show CoercionReifier;
47
45
import 'side_effect_analysis.dart' show ConstFieldVisitor, isStateless;
48
- import 'source_map_printer.dart' show SourceMapPrintingContext;
49
46
import 'type_utilities.dart' ;
50
47
51
48
class CodeGenerator extends GeneralizingAstVisitor
@@ -173,46 +170,21 @@ class CodeGenerator extends GeneralizingAstVisitor
173
170
_libraryRoot = '$_libraryRoot ${separator }' ;
174
171
}
175
172
176
- var jsTree = _emitModule (compilationUnits);
177
- var codeAndSourceMap = _writeJSText (unit, jsTree );
173
+ var module = _emitModule (compilationUnits);
174
+ var dartApiSummary = _summarizeModule (compilationUnits );
178
175
179
- List <int > summary;
180
- if (options.summarizeApi) {
181
- var assembler = new PackageBundleAssembler ();
182
- compilationUnits
183
- .map ((u) => u.element.library)
184
- .toSet ()
185
- .forEach (assembler.serializeLibraryElement);
186
- summary = assembler.assemble ().toBuffer ();
187
- }
188
-
189
- return new JSModuleFile (
190
- unit.name, errors, codeAndSourceMap.e0, codeAndSourceMap.e1, summary);
176
+ return new JSModuleFile (unit.name, errors, options, module, dartApiSummary);
191
177
}
192
178
193
- Tuple2 <String , Map > _writeJSText (BuildUnit unit, JS .Program jsTree) {
194
- var opts = new JS .JavaScriptPrintingOptions (
195
- emitTypes: options.closure,
196
- allowKeywordsInProperties: true ,
197
- allowSingleLineIfStatements: true );
198
- JS .SimpleJavaScriptPrintingContext printer;
199
- SourceMapBuilder sourceMap;
200
- if (options.sourceMap) {
201
- var sourceMapContext = new SourceMapPrintingContext ();
202
- sourceMap = sourceMapContext.sourceMap;
203
- printer = sourceMapContext;
204
- } else {
205
- printer = new JS .SimpleJavaScriptPrintingContext ();
206
- }
207
-
208
- jsTree.accept (new JS .Printer (opts, printer,
209
- localNamer: new JS .TemporaryNamer (jsTree)));
179
+ List <int > _summarizeModule (List <CompilationUnit > compilationUnits) {
180
+ if (! options.summarizeApi) return null ;
210
181
211
- if (options.sourceMap && options.sourceMapComment) {
212
- printer.emit ('\n //# sourceMappingURL=${unit .name }.js.map\n ' );
213
- }
214
-
215
- return new Tuple2 (printer.getText (), sourceMap? .build (unit.name + '.js' ));
182
+ var assembler = new PackageBundleAssembler ();
183
+ compilationUnits
184
+ .map ((u) => u.element.library)
185
+ .toSet ()
186
+ .forEach (assembler.serializeLibraryElement);
187
+ return assembler.assemble ().toBuffer ();
216
188
}
217
189
218
190
JS .Program _emitModule (List <CompilationUnit > compilationUnits) {
@@ -284,18 +256,7 @@ class CodeGenerator extends GeneralizingAstVisitor
284
256
_copyAndFlattenBlocks (items, _moduleItems);
285
257
286
258
// Build the module.
287
- var module = new JS .Program (items, name: _buildUnit.name);
288
-
289
- // Optional: lower module format. Otherwise just return it.
290
- switch (options.moduleFormat) {
291
- case ModuleFormat .legacy:
292
- return new LegacyModuleBuilder ().build (module);
293
- case ModuleFormat .node:
294
- return new NodeModuleBuilder ().build (module);
295
- case ModuleFormat .es6:
296
- return module;
297
- }
298
- return null ; // unreachable. It is here to suppress a bogus Analyzer message
259
+ return new JS .Program (items, name: _buildUnit.name);
299
260
}
300
261
301
262
List <String > _getJSName (Element e) {
@@ -1750,6 +1711,7 @@ class CodeGenerator extends GeneralizingAstVisitor
1750
1711
var e = js.call ('() => #' , o);
1751
1712
return new JS .Property (_propertyName (name), e);
1752
1713
}
1714
+
1753
1715
var sigFields = < JS .Property > [];
1754
1716
if (! tCtors.isEmpty) sigFields.add (build ('constructors' , tCtors));
1755
1717
if (! tMethods.isEmpty) sigFields.add (build ('methods' , tMethods));
@@ -3262,8 +3224,12 @@ class CodeGenerator extends GeneralizingAstVisitor
3262
3224
var vars = < JS .MetaLetVariable , JS .Expression > {};
3263
3225
var l = _visit (_bindValue (vars, 'l' , target));
3264
3226
jsTarget = new JS .MetaLet (vars, [
3265
- js.call ('(#[(#[dart._extensionType]) ? dartx[#] : #])' ,
3266
- [l, l, memberName, memberName,])
3227
+ js.call ('(#[(#[dart._extensionType]) ? dartx[#] : #])' , [
3228
+ l,
3229
+ l,
3230
+ memberName,
3231
+ memberName,
3232
+ ])
3267
3233
]);
3268
3234
if (typeArgs != null ) jsTarget = new JS .Call (jsTarget, typeArgs);
3269
3235
return new JS .Call (jsTarget, args);
@@ -3806,6 +3772,7 @@ class CodeGenerator extends GeneralizingAstVisitor
3806
3772
var args = _visit (argumentList) as List <JS .Expression >;
3807
3773
return isFactory ? new JS .Call (ctor, args) : new JS .New (ctor, args);
3808
3774
}
3775
+
3809
3776
if (element != null && _isObjectLiteral (element.enclosingElement)) {
3810
3777
return _emitObjectLiteral (argumentList);
3811
3778
}
@@ -4047,6 +4014,7 @@ class CodeGenerator extends GeneralizingAstVisitor
4047
4014
}
4048
4015
return null ;
4049
4016
}
4017
+
4050
4018
if (expr is SimpleIdentifier ) {
4051
4019
return finishIdentifier (expr);
4052
4020
} else if (expr is PrefixedIdentifier && ! expr.isDeferred) {
@@ -4134,6 +4102,7 @@ class CodeGenerator extends GeneralizingAstVisitor
4134
4102
if (value != null ) return value.bitLength;
4135
4103
return MAX ;
4136
4104
}
4105
+
4137
4106
return bitWidth (expr, 0 ) < 32 ;
4138
4107
}
4139
4108
@@ -4924,6 +4893,7 @@ class CodeGenerator extends GeneralizingAstVisitor
4924
4893
var name = js.string (node.components.join ('.' ), "'" );
4925
4894
return js.call ('#.new(#)' , [_emitType (types.symbolType), name]);
4926
4895
}
4896
+
4927
4897
return _emitConst (emitSymbol);
4928
4898
}
4929
4899
@@ -4952,6 +4922,7 @@ class CodeGenerator extends GeneralizingAstVisitor
4952
4922
}
4953
4923
return list;
4954
4924
}
4925
+
4955
4926
if (isConst) return _cacheConst (emitList);
4956
4927
return emitList ();
4957
4928
}
@@ -4990,6 +4961,7 @@ class CodeGenerator extends GeneralizingAstVisitor
4990
4961
}
4991
4962
return js.call ('dart.map(#, #)' , [mapArguments, types]);
4992
4963
}
4964
+
4993
4965
if (node.constKeyword != null ) return _emitConst (emitMap);
4994
4966
return emitMap ();
4995
4967
}
@@ -5066,6 +5038,7 @@ class CodeGenerator extends GeneralizingAstVisitor
5066
5038
JS .Expression finish (JS .Expression result) {
5067
5039
return annotate (result, node);
5068
5040
}
5041
+
5069
5042
if (node is PrefixExpression && node.operator .lexeme == '!' ) {
5070
5043
return finish (js.call ('!#' , _visitTest (node.operand)));
5071
5044
}
@@ -5077,6 +5050,7 @@ class CodeGenerator extends GeneralizingAstVisitor
5077
5050
return finish (js.call (code,
5078
5051
[_visitTest (node.leftOperand), _visitTest (node.rightOperand)]));
5079
5052
}
5053
+
5080
5054
var op = node.operator .type.lexeme;
5081
5055
if (op == '&&' ) return shortCircuit ('# && #' );
5082
5056
if (op == '||' ) return shortCircuit ('# || #' );
@@ -5141,7 +5115,7 @@ class CodeGenerator extends GeneralizingAstVisitor
5141
5115
/// x.get('hi')
5142
5116
/// x.set('hi', 123)
5143
5117
///
5144
- /// This follows the same pattern as EcmaScript 6 Map:
5118
+ /// This follows the same pattern as ECMAScript 6 Map:
5145
5119
/// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map>
5146
5120
///
5147
5121
/// Unary minus looks like: `x['unary-']()` . Note that [unary] must be passed
@@ -5294,8 +5268,16 @@ class CodeGenerator extends GeneralizingAstVisitor
5294
5268
/// within the file.
5295
5269
///
5296
5270
/// If the value is null, the entire file is whitelisted.
5271
+ ///
5272
+ // TODO(jmesserly): why is this here, and what can we do to remove it?
5273
+ //
5274
+ // Hard coded lists are completely unnecessary -- if a feature is needed,
5275
+ // metadata, type system features, or command line options are the right way
5276
+ // to express it.
5277
+ //
5278
+ // As it is this is completely unsound and unmaintainable.
5297
5279
static Map <String , List <String >> _uncheckedWhitelist = {
5298
- 'dom_renderer.dart' : ['moveNodesAfterSibling' , ],
5280
+ 'dom_renderer.dart' : ['moveNodesAfterSibling' ],
5299
5281
'template_ref.dart' : ['createEmbeddedView' ],
5300
5282
'ng_class.dart' : ['_applyIterableChanges' ],
5301
5283
'ng_for.dart' : ['_bulkRemove' , '_bulkInsert' ],
@@ -5335,7 +5317,8 @@ class CodeGenerator extends GeneralizingAstVisitor
5335
5317
}
5336
5318
}
5337
5319
5338
- /// Choose a canonical name from the library element.
5320
+ /// Choose a canonical name from the [library] element.
5321
+ ///
5339
5322
/// This never uses the library's name (the identifier in the `library`
5340
5323
/// declaration) as it doesn't have any meaningful rules enforced.
5341
5324
String jsLibraryName (String libraryRoot, LibraryElement library) {
0 commit comments