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

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

Issue 2701963002: Enable DDC output to run on v8/d8 using ES6 modules (Closed)
Patch Set: Created 3 years, 10 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:args/args.dart' show ArgParser, ArgResults; 5 import 'package:args/args.dart' show ArgParser, ArgResults;
6 import 'package:path/path.dart' as path; 6 import 'package:path/path.dart' as path;
7 7
8 import '../js_ast/js_ast.dart'; 8 import '../js_ast/js_ast.dart';
9 import 'js_names.dart'; 9 import 'js_names.dart';
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 "Imports", new ArrayInitializer(importNames, multiline: true)), 205 "Imports", new ArrayInitializer(importNames, multiline: true)),
206 resultModule 206 resultModule
207 ]); 207 ]);
208 return new Program(<ModuleItem>[moduleDef]); 208 return new Program(<ModuleItem>[moduleDef]);
209 } 209 }
210 } 210 }
211 211
212 /// Generates CommonJS modules (used by Node.js). 212 /// Generates CommonJS modules (used by Node.js).
213 class CommonJSModuleBuilder extends _ModuleBuilder { 213 class CommonJSModuleBuilder extends _ModuleBuilder {
214 Program build(Program module) { 214 Program build(Program module) {
215 var importStatements = <Statement>[]; 215 var importStatements = [js.statement("'use strict';"),];
216 216
217 // Collect imports/exports/statements. 217 // Collect imports/exports/statements.
218 visitProgram(module); 218 visitProgram(module);
219 219
220 for (var import in imports) { 220 for (var import in imports) {
221 // TODO(jmesserly): we could use destructuring here. 221 // TODO(jmesserly): we could use destructuring here.
222 var moduleVar = 222 var moduleVar =
223 new TemporaryId(pathToJSIdentifier(import.from.valueWithoutQuotes)); 223 new TemporaryId(pathToJSIdentifier(import.from.valueWithoutQuotes));
224 importStatements 224 importStatements
225 .add(js.statement('const # = require(#);', [moduleVar, import.from])); 225 .add(js.statement('const # = require(#);', [moduleVar, import.from]));
(...skipping 16 matching lines...) Expand all
242 var names = export.exportedNames; 242 var names = export.exportedNames;
243 // export * is not emitted by the compiler, so we don't handle it here. 243 // export * is not emitted by the compiler, so we don't handle it here.
244 assert(names != null); 244 assert(names != null);
245 for (var name in names) { 245 for (var name in names) {
246 statements 246 statements
247 .add(js.statement('#.# = #;', [exportsVar, name.name, name])); 247 .add(js.statement('#.# = #;', [exportsVar, name.name, name]));
248 } 248 }
249 } 249 }
250 } 250 }
251 251
252 // TODO(vsm): See https://github.com/dart-lang/sdk/issues/27309 252 return new Program(statements);
253 // This extra level of indirection should be unnecessary.
254 var block =
255 js.statement("(function() { 'use strict'; #; })()", [statements]);
256
257 return new Program([block]);
258 } 253 }
259 } 254 }
260 255
261 /// Generates AMD modules (used in browsers with RequireJS). 256 /// Generates AMD modules (used in browsers with RequireJS).
262 class AmdModuleBuilder extends _ModuleBuilder { 257 class AmdModuleBuilder extends _ModuleBuilder {
263 final bool singleOutFile; 258 final bool singleOutFile;
264 259
265 AmdModuleBuilder({this.singleOutFile: false}); 260 AmdModuleBuilder({this.singleOutFile: false});
266 261
267 Program build(Program module) { 262 Program build(Program module) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 // Ensure the identifier first character is not numeric and that the whole 340 // Ensure the identifier first character is not numeric and that the whole
346 // identifier is not a keyword. 341 // identifier is not a keyword.
347 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) { 342 if (result.startsWith(new RegExp('[0-9]')) || invalidVariableName(result)) {
348 return '\$$result'; 343 return '\$$result';
349 } 344 }
350 return result; 345 return result;
351 } 346 }
352 347
353 // Invalid characters for identifiers, which would need to be escaped. 348 // Invalid characters for identifiers, which would need to be escaped.
354 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]'); 349 final _invalidCharInIdentifier = new RegExp(r'[^A-Za-z_$0-9]');
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/js_names.dart ('k') | pkg/dev_compiler/test/codegen_expected/node_modules.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698